001: /**
002: * org/ozone-db/xml/dom/DOMExceptionImpl.java
003: *
004: * The contents of this file are subject to the OpenXML Public
005: * License Version 1.0; you may not use this file except in compliance
006: * with the License. You may obtain a copy of the License at
007: * http://www.openxml.org/license.html
008: *
009: * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
010: * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
011: * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
012: * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
013: * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
014: * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
015: *
016: * The Initial Developer of this code under the License is Assaf Arkin.
017: * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
018: * All Rights Reserved.
019: */
020:
021: /**
022: * Changes for Persistent DOM running with ozone are
023: * Copyright 1999 by SMB GmbH. All rights reserved.
024: */package org.ozoneDB.xml.dom;
025:
026: import org.w3c.dom.*;
027:
028: /**
029: * Implements {@link org.w3c.dom.DOMException} for throwing a {@link
030: * java.lang.RuntimeException}. Message specified as one of several predefined
031: * error codes plus an optional description string. {@link #getMessage} returns
032: * textual description of error code.
033: * <P>
034: * See {@link org.w3c.dom.DOMException} for list of supported error codes.
035: *
036: *
037: * @version $Revision: 1.1 $ $Date: 2001/12/18 11:03:24 $
038: * @author <a href="mailto:arkin@trendline.co.il">Assaf Arkin</a>
039: * @see org.w3c.dom.DOMException
040: */
041: public final class DOMExceptionImpl extends DOMException {
042:
043: public final static short PDOM_ERR = 11;
044:
045: /**
046: * Create new {@link org.w3c.dom.DOMException} with specified code.
047: * Message will contain textual description of code.
048: *
049: * @param code {@link org.w3c.dom.DOMException} error code
050: */
051: public DOMExceptionImpl(short code) {
052: this (code, null);
053: }
054:
055: /**
056: * Create new {@link org.w3c.dom.DOMException} with specified code and message. Message will contain
057: * textual description of code and optional message text.
058: *
059: * @param code {@link org.w3c.dom.DOMException} error code
060: * @param message Optional message text
061: */
062: public DOMExceptionImpl(short code, String message) {
063: super (code, makeMessage(code, message));
064: }
065:
066: public String toString() {
067: return "DOMException(" + super .code + "): " + getMessage();
068: }
069:
070: /**
071: * Construct message based on textual description of message code and message
072: * text. Static method is used by constructor.
073: *
074: *
075: * @param code {@link org.w3c.dom.DOMException} error code
076: * @param message Optional message text
077: * @return Description of error code containing optional message text
078: */
079: private static String makeMessage(short code, String message) {
080: String codeText;
081:
082: switch (code) {
083: case INDEX_SIZE_ERR:
084: codeText = "Index or size is negative or greater than the allowed value.";
085: break;
086: case HIERARCHY_REQUEST_ERR:
087: codeText = "Node is inserted somewhere it doesn't belong.";
088: break;
089: case WRONG_DOCUMENT_ERR:
090: codeText = "Node is used in a different document than the one that created it.";
091: break;
092: case INVALID_CHARACTER_ERR:
093: codeText = "An invalid character is specified, such as in a name.";
094: break;
095: case NO_DATA_ALLOWED_ERR:
096: codeText = "Node does not support data.";
097: break;
098: case NO_MODIFICATION_ALLOWED_ERR:
099: codeText = "Attempt made to modify an pbject where modification not allowed.";
100: break;
101: case NOT_FOUND_ERR:
102: codeText = "Attempt to reference a node in a context where it does not exist.";
103: break;
104: case NOT_SUPPORTED_ERR:
105: codeText = "Implementation does not support the type of object requested.";
106: break;
107: case INUSE_ATTRIBUTE_ERR:
108: codeText = "An attempt to add an attribute that is already inuse elsewhere.";
109: break;
110: default:
111: codeText = "Exception reason is unspecified.";
112: break;
113: }
114: codeText = "DOMException: " + codeText + " (code " + code + ")";
115: if (message != null && message.length() > 0) {
116: codeText = codeText + "\n" + message;
117: }
118: return codeText;
119: }
120:
121: }
|