Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.jackrabbit.spi2dav;
 
 
ExceptionConverter...
 
 public class ExceptionConverter {
 
     // avoid instantiation
     private ExceptionConverter() {}
 
     public static RepositoryException generate(DavException davExc) {
         return generate(davExcnull);
     }
 
     public static RepositoryException generate(DavException davExcDavMethod method) {
         String name = (method == null) ? "_undefined_" : method.getName();
         int code = DavMethods.getMethodCode(name);
         return generate(davExccodename);
     }
 
     public static RepositoryException generate(DavException davExcint methodCodeString name) {
         String msg = davExc.getMessage();
         if (davExc.hasErrorCondition()) {
             try {
                 Element error = davExc.toXml(DomUtil.createDocument());
                 if (DomUtil.matches(error..)) {
                     if (DomUtil.hasChildElement(error"exception"null)) {
                         Element exc = DomUtil.getChildElement(error"exception"null);
                         if (DomUtil.hasChildElement(exc"message"null)) {
                             msg = DomUtil.getChildText(exc"message"null);
                         }
                         if (DomUtil.hasChildElement(exc"class"null)) {
                             Class<?> cl = Class.forName(DomUtil.getChildText(exc"class"null));
                             Constructor<?> excConstr = cl.getConstructor(String.class);
                             if (excConstr != null) {
                                 Object o = excConstr.newInstance(msg);
                                 if (o instanceof PathNotFoundException && methodCode == .) {
                                     // see JCR-2536
                                     return new InvalidItemStateException(msg);
                                 } else if (o instanceof RepositoryException) {
                                     return (RepositoryExceptiono;
                                 } else if (o instanceof Exception) {
                                     return new RepositoryException(msg, (Exception)o);
                                 }
                             }
                         }
                     }
                 }
             } catch (Exception e) {
                 return new RepositoryException(e);
             }
         }
 
         // make sure an exception is generated
         switch (davExc.getErrorCode()) {
             // TODO: mapping DAV_error to jcr-exception is ambiguous. to be improved
             case . :
                 switch (methodCode) {
                     case .:
                     case .:
                     case .:
                     case .:
                         // target item has probably while transient changes have
                         // been made.
                         return new InvalidItemStateException(msgdavExc);
                     default:
                        return new ItemNotFoundException(msgdavExc);
                }
            case . :
                return new LockException(msgdavExc);
            case . :
                return new ConstraintViolationException(msgdavExc);
            case . :
                return new InvalidItemStateException(msgdavExc);
            case . :
                return new LockException(msgdavExc);
            case .:
                if (methodCode > 0 && name != null) {
                    return new UnsupportedRepositoryOperationException(
                            "Missing implementation: Method "
                            + name + " could not be executed"davExc);
                } else {
                    return new UnsupportedRepositoryOperationException(
                            "Missing implementation"davExc);
                }
            default:
                return new RepositoryException(msgdavExc);
        }
    }
New to GrepCode? Check out our FAQ X