KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > platform > xml > XMLPlatformException


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.platform.xml;
23
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.net.URL JavaDoc;
27 import org.xml.sax.SAXParseException JavaDoc;
28 import oracle.toplink.essentials.exceptions.TopLinkException;
29 import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator;
30
31 public class XMLPlatformException extends TopLinkException {
32     public static final int XML_PLATFORM_CLASS_NOT_FOUND = 27001;
33     public static final int XML_PLATFORM_COULD_NOT_INSTANTIATE = 27002;
34     public static final int XML_PLATFORM_COULD_NOT_CREATE_DOCUMENT = 27003;
35     public static final int XML_PLATFORM_INVALID_XPATH = 27004;
36     public static final int XML_PLATFORM_VALIDATION_EXCEPTION = 27005;
37     public static final int XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA = 27006;
38     public static final int XML_PLATFORM_PARSE_EXCEPTION = 27101;
39     public static final int XML_PLATFORM_PARSER_FILE_NOT_FOUND_EXCEPTION = 27102;
40     public static final int XML_PLATFORM_PARSER_SAX_PARSE_EXCEPTION = 27103;
41     public static final int XML_PLATFORM_TRANSFORM_EXCEPTION = 27201;
42     public static final int XML_PLATFORM_INVALID_TYPE = 27202;
43
44     protected XMLPlatformException(String JavaDoc message) {
45         super(message);
46     }
47
48     public static XMLPlatformException xmlPlatformClassNotFound(String JavaDoc xmlPlatformClassName, Exception JavaDoc nestedException) {
49         Object JavaDoc[] args = { xmlPlatformClassName };
50         int errorCode = XML_PLATFORM_CLASS_NOT_FOUND;
51         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
52         exception.setErrorCode(errorCode);
53         exception.setInternalException(nestedException);
54         return exception;
55     }
56
57     public static XMLPlatformException xmlPlatformCouldNotInstantiate(String JavaDoc xmlPlatformClassName, Exception JavaDoc nestedException) {
58         Object JavaDoc[] args = { xmlPlatformClassName };
59         int errorCode = XML_PLATFORM_COULD_NOT_INSTANTIATE;
60         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
61         exception.setErrorCode(errorCode);
62         exception.setInternalException(nestedException);
63         return exception;
64     }
65
66     public static XMLPlatformException xmlPlatformCouldNotCreateDocument(Exception JavaDoc nestedException) {
67         Object JavaDoc[] args = { };
68         int errorCode = XML_PLATFORM_COULD_NOT_CREATE_DOCUMENT;
69         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
70         exception.setErrorCode(errorCode);
71         return exception;
72     }
73
74     public static XMLPlatformException xmlPlatformInvalidXPath(Exception JavaDoc nestedException) {
75         Object JavaDoc[] args = { };
76         int errorCode = XML_PLATFORM_INVALID_XPATH;
77         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
78         exception.setErrorCode(errorCode);
79         exception.setInternalException(nestedException);
80         return exception;
81     }
82
83     public static XMLPlatformException xmlPlatformValidationException(Exception JavaDoc nestedException) {
84         Object JavaDoc[] args = { };
85         int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION;
86         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
87         exception.setErrorCode(errorCode);
88         exception.setInternalException(nestedException);
89         return exception;
90     }
91
92     /**
93      * Takes an error messsage string
94      */

95     public static XMLPlatformException xmlPlatformValidationException(String JavaDoc errorMessage) {
96         int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION;
97         XMLPlatformException exception = new XMLPlatformException(errorMessage);
98         exception.setErrorCode(errorCode);
99         return exception;
100     }
101
102     /**
103      * Handles an invalid type setting in a schema reference.
104      *
105      * @see oracle.toplink.essentials.platform.xml.XMLSchemaReference.getType()
106      */

107     public static XMLPlatformException xmlPlatformInvalidTypeException(int type) {
108         Object JavaDoc[] args = { new Integer JavaDoc(type) };
109         int errorCode = XML_PLATFORM_INVALID_TYPE;
110         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
111         exception.setErrorCode(errorCode);
112         return exception;
113     }
114
115     public static XMLPlatformException xmlPlatformParseException(Exception JavaDoc nestedException) {
116         Object JavaDoc[] args = { };
117         int errorCode = XML_PLATFORM_PARSE_EXCEPTION;
118         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
119         exception.setErrorCode(errorCode);
120         exception.setInternalException(nestedException);
121         return exception;
122     }
123
124     public static XMLPlatformException xmlPlatformFileNotFoundException(File JavaDoc file, IOException JavaDoc nestedException) {
125         Object JavaDoc[] args = { file.getAbsolutePath() };
126         int errorCode = XML_PLATFORM_PARSER_FILE_NOT_FOUND_EXCEPTION;
127         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
128         exception.setErrorCode(errorCode);
129         exception.setInternalException(nestedException);
130         return exception;
131     }
132
133     public static XMLPlatformException xmlPlatformSAXParseException(SAXParseException JavaDoc nestedException) {
134         Object JavaDoc[] args = { new Integer JavaDoc(nestedException.getLineNumber()), nestedException.getSystemId(), nestedException.getMessage() };
135         int errorCode = XML_PLATFORM_PARSER_SAX_PARSE_EXCEPTION;
136         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
137         exception.setErrorCode(errorCode);
138         exception.setInternalException(nestedException);
139         return exception;
140     }
141
142     public static XMLPlatformException xmlPlatformErrorResolvingXMLSchema(URL JavaDoc url, Exception JavaDoc nestedException) {
143         Object JavaDoc[] args = { url };
144         int errorCode = XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA;
145         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
146         exception.setErrorCode(errorCode);
147         exception.setInternalException(nestedException);
148         return exception;
149     }
150
151     public static XMLPlatformException xmlPlatformErrorResolvingXMLSchemas(Object JavaDoc[] schemas, Exception JavaDoc nestedException) {
152         Object JavaDoc[] args = { };
153         int errorCode = XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA;
154         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
155         exception.setErrorCode(errorCode);
156         exception.setInternalException(nestedException);
157         return exception;
158     }
159
160     public static XMLPlatformException xmlPlatformTransformException(Exception JavaDoc nestedException) {
161         Object JavaDoc[] args = { };
162         int errorCode = XML_PLATFORM_TRANSFORM_EXCEPTION;
163         XMLPlatformException exception = new XMLPlatformException(ExceptionMessageGenerator.buildMessage(XMLPlatformException.class, errorCode, args));
164         exception.setErrorCode(errorCode);
165         exception.setInternalException(nestedException);
166         return exception;
167     }
168 }
169
Popular Tags