Home » xmlbeans-2.5.0-src » org.apache » xmlbeans » [javadoc | source]

    1   /*   Copyright 2004 The Apache Software Foundation
    2    *
    3    *   Licensed under the Apache License, Version 2.0 (the "License");
    4    *   you may not use this file except in compliance with the License.
    5    *   You may obtain a copy of the License at
    6    *
    7    *       http://www.apache.org/licenses/LICENSE-2.0
    8    *
    9    *   Unless required by applicable law or agreed to in writing, software
   10    *   distributed under the License is distributed on an "AS IS" BASIS,
   11    *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   12    *   See the License for the specific language governing permissions and
   13    *  limitations under the License.
   14    */
   15   
   16   package org.apache.xmlbeans;
   17   
   18   import java.util.List;
   19   import java.util.Collections;
   20   import java.util.Collection;
   21   import java.util.ArrayList;
   22   
   23   /**
   24    * A checked exception that can be thrown while processing,
   25    * parsing, or compiling XML.  May contain any number of {@link XmlError}
   26    * objects.
   27    * <p>
   28    * @see XmlError
   29    * @see XmlRuntimeException
   30    */
   31   public class XmlException extends Exception
   32   {
   33       private static final long serialVersionUID = 1L;
   34       
   35       /**
   36        * Constructs an XmlException from a message.
   37        */ 
   38       public XmlException ( String m              ) { super( m );    }
   39       
   40       /**
   41        * Constructs an XmlException from a message and a cause.
   42        */ 
   43       public XmlException ( String m, Throwable t ) { super( m, t ); }
   44       
   45       /**
   46        * Constructs an XmlException from a cause.
   47        */ 
   48       public XmlException ( Throwable t           ) { super( t );    }
   49       
   50       /**
   51        * Constructs an XmlException from an {@link XmlError}.
   52        */ 
   53       public XmlException ( XmlError error )
   54       {
   55           this( error.toString(), null, error );
   56       }
   57   
   58       /**
   59        * Constructs an XmlException from a message, a cause, and an {@link XmlError}.
   60        */ 
   61       public XmlException ( String m, Throwable t, XmlError error )
   62       {
   63           this( m, t, Collections.singletonList( error ) );
   64       }
   65       
   66       /**
   67        * Constructs an XmlException from a message, a cause, and a collection of {@link XmlError XmlErrors}.
   68        */ 
   69       public XmlException ( String m, Throwable t, Collection errors )
   70       {
   71           super( m, t );
   72   
   73           if (errors != null)
   74               _errors = Collections.unmodifiableList( new ArrayList( errors ) );
   75       }
   76   
   77       /**
   78        * Constructs an XmlException from an {@link XmlRuntimeException}.
   79        */ 
   80       public XmlException ( XmlRuntimeException xmlRuntimeException )
   81       {
   82           super(
   83               xmlRuntimeException.getMessage(), xmlRuntimeException.getCause() );
   84   
   85           Collection errors = xmlRuntimeException.getErrors();
   86   
   87           if (errors != null)
   88               _errors = Collections.unmodifiableList( new ArrayList( errors ) );
   89       }
   90       
   91       /**
   92        * Returns the first {@link XmlError XmlErrors} that caused the exception, if any.
   93        */ 
   94       public XmlError getError ( )
   95       {
   96           if (_errors == null || _errors.size() == 0)
   97               return null;
   98   
   99           return (XmlError) _errors.get( 0 );
  100       }
  101       
  102       /**
  103        * Returns the collection of {@link XmlError XmlErrors} that caused the exception, if any.
  104        */ 
  105       public Collection getErrors ( )
  106       {
  107           return _errors;
  108       }
  109   
  110       private List _errors;
  111   }

Home » xmlbeans-2.5.0-src » org.apache » xmlbeans » [javadoc | source]