001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * // Copyright (c) 1998, 2007, Oracle. All rights reserved.
005: *
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common Development
009: * and Distribution License("CDDL") (collectively, the "License"). You
010: * may not use this file except in compliance with the License. You can obtain
011: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
012: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
013: * language governing permissions and limitations under the License.
014: *
015: * When distributing the software, include this License Header Notice in each
016: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
017: * Sun designates this particular file as subject to the "Classpath" exception
018: * as provided by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the License
020: * Header, with the fields enclosed by brackets [] replaced by your own
021: * identifying information: "Portions Copyrighted [year]
022: * [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * If you wish your version of this file to be governed by only the CDDL or
027: * only the GPL Version 2, indicate your decision by adding "[Contributor]
028: * elects to include this software in this distribution under the [CDDL or GPL
029: * Version 2] license." If you don't indicate a single choice of license, a
030: * recipient has the option to distribute your version of this file under
031: * either the CDDL, the GPL Version 2 or to extend the choice of license to
032: * its licensees as provided above. However, if you add GPL Version 2 code
033: * and therefore, elected the GPL Version 2 license, then the option applies
034: * only if the new code is made subject to such option by the copyright
035: * holder.
036: */
037: package oracle.toplink.essentials.platform.xml;
038:
039: import java.io.File;
040: import java.io.IOException;
041: import java.net.URL;
042: import org.xml.sax.SAXParseException;
043: import oracle.toplink.essentials.exceptions.TopLinkException;
044: import oracle.toplink.essentials.exceptions.i18n.ExceptionMessageGenerator;
045:
046: public class XMLPlatformException extends TopLinkException {
047: public static final int XML_PLATFORM_CLASS_NOT_FOUND = 27001;
048: public static final int XML_PLATFORM_COULD_NOT_INSTANTIATE = 27002;
049: public static final int XML_PLATFORM_COULD_NOT_CREATE_DOCUMENT = 27003;
050: public static final int XML_PLATFORM_INVALID_XPATH = 27004;
051: public static final int XML_PLATFORM_VALIDATION_EXCEPTION = 27005;
052: public static final int XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA = 27006;
053: public static final int XML_PLATFORM_PARSE_EXCEPTION = 27101;
054: public static final int XML_PLATFORM_PARSER_FILE_NOT_FOUND_EXCEPTION = 27102;
055: public static final int XML_PLATFORM_PARSER_SAX_PARSE_EXCEPTION = 27103;
056: public static final int XML_PLATFORM_TRANSFORM_EXCEPTION = 27201;
057: public static final int XML_PLATFORM_INVALID_TYPE = 27202;
058:
059: protected XMLPlatformException(String message) {
060: super (message);
061: }
062:
063: public static XMLPlatformException xmlPlatformClassNotFound(
064: String xmlPlatformClassName, Exception nestedException) {
065: Object[] args = { xmlPlatformClassName };
066: int errorCode = XML_PLATFORM_CLASS_NOT_FOUND;
067: XMLPlatformException exception = new XMLPlatformException(
068: ExceptionMessageGenerator.buildMessage(
069: XMLPlatformException.class, errorCode, args));
070: exception.setErrorCode(errorCode);
071: exception.setInternalException(nestedException);
072: return exception;
073: }
074:
075: public static XMLPlatformException xmlPlatformCouldNotInstantiate(
076: String xmlPlatformClassName, Exception nestedException) {
077: Object[] args = { xmlPlatformClassName };
078: int errorCode = XML_PLATFORM_COULD_NOT_INSTANTIATE;
079: XMLPlatformException exception = new XMLPlatformException(
080: ExceptionMessageGenerator.buildMessage(
081: XMLPlatformException.class, errorCode, args));
082: exception.setErrorCode(errorCode);
083: exception.setInternalException(nestedException);
084: return exception;
085: }
086:
087: public static XMLPlatformException xmlPlatformCouldNotCreateDocument(
088: Exception nestedException) {
089: Object[] args = {};
090: int errorCode = XML_PLATFORM_COULD_NOT_CREATE_DOCUMENT;
091: XMLPlatformException exception = new XMLPlatformException(
092: ExceptionMessageGenerator.buildMessage(
093: XMLPlatformException.class, errorCode, args));
094: exception.setErrorCode(errorCode);
095: return exception;
096: }
097:
098: public static XMLPlatformException xmlPlatformInvalidXPath(
099: Exception nestedException) {
100: Object[] args = {};
101: int errorCode = XML_PLATFORM_INVALID_XPATH;
102: XMLPlatformException exception = new XMLPlatformException(
103: ExceptionMessageGenerator.buildMessage(
104: XMLPlatformException.class, errorCode, args));
105: exception.setErrorCode(errorCode);
106: exception.setInternalException(nestedException);
107: return exception;
108: }
109:
110: public static XMLPlatformException xmlPlatformValidationException(
111: Exception nestedException) {
112: Object[] args = {};
113: int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION;
114: XMLPlatformException exception = new XMLPlatformException(
115: ExceptionMessageGenerator.buildMessage(
116: XMLPlatformException.class, errorCode, args));
117: exception.setErrorCode(errorCode);
118: exception.setInternalException(nestedException);
119: return exception;
120: }
121:
122: /**
123: * Takes an error messsage string
124: */
125: public static XMLPlatformException xmlPlatformValidationException(
126: String errorMessage) {
127: int errorCode = XML_PLATFORM_VALIDATION_EXCEPTION;
128: XMLPlatformException exception = new XMLPlatformException(
129: errorMessage);
130: exception.setErrorCode(errorCode);
131: return exception;
132: }
133:
134: /**
135: * Handles an invalid type setting in a schema reference.
136: *
137: * @see oracle.toplink.essentials.platform.xml.XMLSchemaReference.getType()
138: */
139: public static XMLPlatformException xmlPlatformInvalidTypeException(
140: int type) {
141: Object[] args = { new Integer(type) };
142: int errorCode = XML_PLATFORM_INVALID_TYPE;
143: XMLPlatformException exception = new XMLPlatformException(
144: ExceptionMessageGenerator.buildMessage(
145: XMLPlatformException.class, errorCode, args));
146: exception.setErrorCode(errorCode);
147: return exception;
148: }
149:
150: public static XMLPlatformException xmlPlatformParseException(
151: Exception nestedException) {
152: Object[] args = {};
153: int errorCode = XML_PLATFORM_PARSE_EXCEPTION;
154: XMLPlatformException exception = new XMLPlatformException(
155: ExceptionMessageGenerator.buildMessage(
156: XMLPlatformException.class, errorCode, args));
157: exception.setErrorCode(errorCode);
158: exception.setInternalException(nestedException);
159: return exception;
160: }
161:
162: public static XMLPlatformException xmlPlatformFileNotFoundException(
163: File file, IOException nestedException) {
164: Object[] args = { file.getAbsolutePath() };
165: int errorCode = XML_PLATFORM_PARSER_FILE_NOT_FOUND_EXCEPTION;
166: XMLPlatformException exception = new XMLPlatformException(
167: ExceptionMessageGenerator.buildMessage(
168: XMLPlatformException.class, errorCode, args));
169: exception.setErrorCode(errorCode);
170: exception.setInternalException(nestedException);
171: return exception;
172: }
173:
174: public static XMLPlatformException xmlPlatformSAXParseException(
175: SAXParseException nestedException) {
176: Object[] args = { new Integer(nestedException.getLineNumber()),
177: nestedException.getSystemId(),
178: nestedException.getMessage() };
179: int errorCode = XML_PLATFORM_PARSER_SAX_PARSE_EXCEPTION;
180: XMLPlatformException exception = new XMLPlatformException(
181: ExceptionMessageGenerator.buildMessage(
182: XMLPlatformException.class, errorCode, args));
183: exception.setErrorCode(errorCode);
184: exception.setInternalException(nestedException);
185: return exception;
186: }
187:
188: public static XMLPlatformException xmlPlatformErrorResolvingXMLSchema(
189: URL url, Exception nestedException) {
190: Object[] args = { url };
191: int errorCode = XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA;
192: XMLPlatformException exception = new XMLPlatformException(
193: ExceptionMessageGenerator.buildMessage(
194: XMLPlatformException.class, errorCode, args));
195: exception.setErrorCode(errorCode);
196: exception.setInternalException(nestedException);
197: return exception;
198: }
199:
200: public static XMLPlatformException xmlPlatformErrorResolvingXMLSchemas(
201: Object[] schemas, Exception nestedException) {
202: Object[] args = {};
203: int errorCode = XML_PLATFORM_PARSER_ERROR_RESOLVING_XML_SCHEMA;
204: XMLPlatformException exception = new XMLPlatformException(
205: ExceptionMessageGenerator.buildMessage(
206: XMLPlatformException.class, errorCode, args));
207: exception.setErrorCode(errorCode);
208: exception.setInternalException(nestedException);
209: return exception;
210: }
211:
212: public static XMLPlatformException xmlPlatformTransformException(
213: Exception nestedException) {
214: Object[] args = {};
215: int errorCode = XML_PLATFORM_TRANSFORM_EXCEPTION;
216: XMLPlatformException exception = new XMLPlatformException(
217: ExceptionMessageGenerator.buildMessage(
218: XMLPlatformException.class, errorCode, args));
219: exception.setErrorCode(errorCode);
220: exception.setInternalException(nestedException);
221: return exception;
222: }
223: }
|