View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.jxpath;
18  
19  /**
20   * Thrown when a problem with configuration with the {@link JXPathContextFactory JXPathContextFactories}
21   * exists. This error will typically be thrown when the class of a
22   * factory specified in the system properties cannot be found
23   * or instantiated.
24   *
25   * @author Dmitri Plotnikov
26   * @version $Revision: 652845 $ $Date: 2008-05-02 19:46:46 +0200 (Fr, 02 Mai 2008) $
27   */
28  public class JXPathContextFactoryConfigurationError extends Error {
29  
30      /** @serial */
31      private Exception exception;
32  
33      /**
34       * Create a new <code>JXPathContextFactoryConfigurationError</code> with no
35       * detail mesage.
36       */
37       public JXPathContextFactoryConfigurationError() {
38           super();
39           this.exception = null;
40       }
41  
42      /**
43       * Create a new <code>JXPathContextFactoryConfigurationError</code> with
44       * the <code>String </code> specified as an error message.
45       *
46       * @param msg The error message for the exception.
47       */
48      public JXPathContextFactoryConfigurationError(String msg) {
49          super(msg);
50          this.exception = null;
51      }
52  
53  
54      /**
55       * Create a new <code>JXPathContextFactoryConfigurationError</code> with a
56       * given <code>Exception</code> base cause of the error.
57       *
58       * @param e The exception to be encapsulated in a
59       * JXPathContextFactoryConfigurationError.
60       */
61      public JXPathContextFactoryConfigurationError(Exception e) {
62          super(e.toString());
63          this.exception = e;
64      }
65  
66      /**
67       * Create a new <code>JXPathContextFactoryConfigurationError</code> with the
68       * given <code>Exception</code> base cause and detail message.
69       *
70       * @param e The exception to be encapsulated in a
71       * JXPathContextFactoryConfigurationError
72       * @param msg The detail message.
73       */
74      public JXPathContextFactoryConfigurationError(Exception e, String msg) {
75          super(msg);
76          this.exception = e;
77      }
78  
79  
80      /**
81       * Return the message (if any) for this error . If there is no
82       * message for the exception and there is an encapsulated
83       * exception then the message of that exception will be returned.
84       *
85       * @return The error message.
86       */
87      public String getMessage () {
88          String message = super.getMessage();
89          if (message == null && exception != null) {
90              return exception.getMessage();
91          }
92          return message;
93      }
94  
95      /**
96       * Return the actual exception (if any) that caused this exception to
97       * be raised.
98       *
99       * @return The encapsulated exception, or null if there is none.
100      */
101     public Exception getException () {
102         return exception;
103     }
104 }