KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > xml > dom > DOMExceptionImpl


1 /**
2  * org/ozone-db/xml/dom/DOMExceptionImpl.java
3  *
4  * The contents of this file are subject to the OpenXML Public
5  * License Version 1.0; you may not use this file except in compliance
6  * with the License. You may obtain a copy of the License at
7  * http://www.openxml.org/license.html
8  *
9  * THIS SOFTWARE IS DISTRIBUTED ON AN "AS IS" BASIS WITHOUT WARRANTY
10  * OF ANY KIND, EITHER EXPRESSED OR IMPLIED. THE INITIAL DEVELOPER
11  * AND ALL CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES AS A
12  * RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
13  * DERIVATIVES. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
14  * RIGHTS AND LIMITATIONS UNDER THE LICENSE.
15  *
16  * The Initial Developer of this code under the License is Assaf Arkin.
17  * Portions created by Assaf Arkin are Copyright (C) 1998, 1999.
18  * All Rights Reserved.
19  */

20
21 /**
22  * Changes for Persistent DOM running with ozone are
23  * Copyright 1999 by SMB GmbH. All rights reserved.
24  */

25
26 package org.ozoneDB.xml.dom;
27
28 import org.w3c.dom.*;
29
30
31 /**
32  * Implements {@link org.w3c.dom.DOMException} for throwing a {@link
33  * java.lang.RuntimeException}. Message specified as one of several predefined
34  * error codes plus an optional description string. {@link #getMessage} returns
35  * textual description of error code.
36  * <P>
37  * See {@link org.w3c.dom.DOMException} for list of supported error codes.
38  *
39  *
40  * @version $Revision: 1.1 $ $Date: 2003/11/02 17:26:14 $
41  * @author <a HREF="mailto:arkin@trendline.co.il">Assaf Arkin</a>
42  * @see org.w3c.dom.DOMException
43  */

44 public final class DOMExceptionImpl extends DOMException {
45     
46     public final static short PDOM_ERR = 11;
47     
48     
49     /**
50      * Create new {@link org.w3c.dom.DOMException} with specified code.
51      * Message will contain textual description of code.
52      *
53      * @param code {@link org.w3c.dom.DOMException} error code
54      */

55     public DOMExceptionImpl( short code ) {
56         this( code, null );
57     }
58     
59     
60     /**
61      * Create new {@link org.w3c.dom.DOMException} with specified code and message. Message will contain
62      * textual description of code and optional message text.
63      *
64      * @param code {@link org.w3c.dom.DOMException} error code
65      * @param message Optional message text
66      */

67     public DOMExceptionImpl( short code, String JavaDoc message ) {
68         super( code, makeMessage( code, message ) );
69     }
70     
71     
72     public String JavaDoc toString() {
73         return "DOMException(" + super.code + "): " + getMessage();
74     }
75     
76     
77     /**
78      * Construct message based on textual description of message code and message
79      * text. Static method is used by constructor.
80      *
81      *
82      * @param code {@link org.w3c.dom.DOMException} error code
83      * @param message Optional message text
84      * @return Description of error code containing optional message text
85      */

86     private static String JavaDoc makeMessage( short code, String JavaDoc message ) {
87         String JavaDoc codeText;
88         
89         switch (code) {
90         case INDEX_SIZE_ERR:
91             codeText = "Index or size is negative or greater than the allowed value.";
92             break;
93         case HIERARCHY_REQUEST_ERR:
94             codeText = "Node is inserted somewhere it doesn't belong.";
95             break;
96         case WRONG_DOCUMENT_ERR:
97             codeText = "Node is used in a different document than the one that created it.";
98             break;
99         case INVALID_CHARACTER_ERR:
100             codeText = "An invalid character is specified, such as in a name.";
101             break;
102         case NO_DATA_ALLOWED_ERR:
103             codeText = "Node does not support data.";
104             break;
105         case NO_MODIFICATION_ALLOWED_ERR:
106             codeText = "Attempt made to modify an pbject where modification not allowed.";
107             break;
108         case NOT_FOUND_ERR:
109             codeText = "Attempt to reference a node in a context where it does not exist.";
110             break;
111         case NOT_SUPPORTED_ERR:
112             codeText = "Implementation does not support the type of object requested.";
113             break;
114         case INUSE_ATTRIBUTE_ERR:
115             codeText = "An attempt to add an attribute that is already inuse elsewhere.";
116             break;
117         default:
118             codeText = "Exception reason is unspecified.";
119             break;
120         }
121         codeText = "DOMException: " + codeText + " (code " + code + ")";
122         if (message != null && message.length() > 0) {
123             codeText = codeText + "\n" + message;
124         }
125         return codeText;
126     }
127     
128 }
129
Popular Tags