View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   // CatalogException.java - Catalog exception
6   
7   /*
8    * Copyright 2001-2004 The Apache Software Foundation or its licensors,
9    * as applicable.
10   *
11   * Licensed under the Apache License, Version 2.0 (the "License");
12   * you may not use this file except in compliance with the License.
13   * You may obtain a copy of the License at
14   *
15   *      http://www.apache.org/licenses/LICENSE-2.0
16   *
17   * Unless required by applicable law or agreed to in writing, software
18   * distributed under the License is distributed on an "AS IS" BASIS,
19   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   * See the License for the specific language governing permissions and
21   * limitations under the License.
22   */
23  
24  package com.sun.org.apache.xml.internal.resolver;
25  
26  /**
27   * Signal Catalog exception.
28   *
29   * <p>This exception is thrown if an error occurs loading a
30   * catalog file.</p>
31   *
32   * @see Catalog
33   *
34   * @author Norman Walsh
35   * <a href="mailto:Norman.Walsh@Sun.COM">Norman.Walsh@Sun.COM</a>
36   *
37   */
38  public class CatalogException extends Exception {
39    /** A wrapper around another exception */
40    public static final int WRAPPER = 1;
41    /** An invalid entry */
42    public static final int INVALID_ENTRY = 2;
43    /** An invalid entry type */
44    public static final int INVALID_ENTRY_TYPE = 3;
45    /** Could not instantiate an XML parser */
46    public static final int NO_XML_PARSER = 4;
47    /** Unknown XML format */
48    public static final int UNKNOWN_FORMAT = 5;
49    /** Unparseable XML catalog (not XML)*/
50    public static final int UNPARSEABLE = 6;
51    /** XML but parse failed */
52    public static final int PARSE_FAILED = 7;
53    /** Text catalog ended in mid-comment */
54    public static final int UNENDED_COMMENT = 8;
55  
56    /**
57     * The embedded exception if tunnelling, or null.
58     */
59    private Exception exception = null;
60    private int exceptionType = 0;
61  
62    /**
63     * Create a new CatalogException.
64     *
65     * @param type The exception type
66     * @param message The error or warning message.
67     */
68    public CatalogException (int type, String message) {
69      super(message);
70      this.exceptionType = type;
71      this.exception = null;
72    }
73  
74    /**
75     * Create a new CatalogException.
76     *
77     * @param type The exception type
78     */
79    public CatalogException (int type) {
80      super("Catalog Exception " + type);
81      this.exceptionType = type;
82      this.exception = null;
83    }
84  
85    /**
86     * Create a new CatalogException wrapping an existing exception.
87     *
88     * <p>The existing exception will be embedded in the new
89     * one, and its message will become the default message for
90     * the CatalogException.</p>
91     *
92     * @param e The exception to be wrapped in a CatalogException.
93     */
94    public CatalogException (Exception e) {
95      super();
96      this.exceptionType = WRAPPER;
97      this.exception = e;
98    }
99  
100   /**
101    * Create a new CatalogException from an existing exception.
102    *
103    * <p>The existing exception will be embedded in the new
104    * one, but the new exception will have its own message.</p>
105    *
106    * @param message The detail message.
107    * @param e The exception to be wrapped in a CatalogException.
108    */
109   public CatalogException (String message, Exception e) {
110     super(message);
111     this.exceptionType = WRAPPER;
112     this.exception = e;
113   }
114 
115   /**
116    * Return a detail message for this exception.
117    *
118    * <p>If there is an embedded exception, and if the CatalogException
119    * has no detail message of its own, this method will return
120    * the detail message from the embedded exception.</p>
121    *
122    * @return The error or warning message.
123    */
124   public String getMessage ()
125   {
126     String message = super.getMessage();
127 
128     if (message == null && exception != null) {
129       return exception.getMessage();
130     } else {
131       return message;
132     }
133   }
134 
135   /**
136    * Return the embedded exception, if any.
137    *
138    * @return The embedded exception, or null if there is none.
139    */
140   public Exception getException ()
141   {
142     return exception;
143   }
144 
145   /**
146    * Return the exception type
147    *
148    * @return The exception type
149    */
150   public int getExceptionType ()
151   {
152     return exceptionType;
153   }
154 
155   /**
156    * Override toString to pick up any embedded exception.
157    *
158    * @return A string representation of this exception.
159    */
160   public String toString ()
161   {
162     if (exception != null) {
163       return exception.toString();
164     } else {
165       return super.toString();
166     }
167   }
168 }