KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > xerces > dom > CoreDOMImplementationImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package org.enhydra.apache.xerces.dom;
59
60 import org.w3c.dom.DOMException JavaDoc;
61 import org.w3c.dom.DOMImplementation JavaDoc;
62 import org.w3c.dom.Document JavaDoc;
63 import org.w3c.dom.DocumentType JavaDoc;
64 import org.w3c.dom.Element JavaDoc;
65
66 /**
67  * The DOMImplementation class is description of a particular
68  * implementation of the Document Object Model. As such its data is
69  * static, shared by all instances of this implementation.
70  * <P>
71  * The DOM API requires that it be a real object rather than static
72  * methods. However, there's nothing that says it can't be a singleton,
73  * so that's how I've implemented it.
74  * <P>
75  * This particular class, along with CoreDocumentImpl, only supports the DOM
76  * Core. Optional modules are supported by the more complete DOMImplementation
77  * class along with DocumentImpl.
78  *
79  * @version
80  * @since PR-DOM-Level-1-19980818.
81  */

82 public class CoreDOMImplementationImpl
83     implements DOMImplementation JavaDoc {
84
85     //
86
// Data
87
//
88

89     // static
90

91     /** Dom implementation singleton. */
92     static CoreDOMImplementationImpl singleton =
93         new CoreDOMImplementationImpl();
94
95     //
96
// DOMImplementation methods
97
//
98

99     /**
100      * Test if the DOM implementation supports a specific "feature" --
101      * currently meaning language and level thereof.
102      *
103      * @param feature The package name of the feature to test.
104      * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
105      * At this writing, org.enhydra.apache.xerces.dom supports only XML.
106      *
107      * @param version The version number of the feature being tested.
108      * This is interpreted as "Version of the DOM API supported for the
109      * specified Feature", and in Level 1 should be "1.0"
110      *
111      * @returns true iff this implementation is compatable with the
112      * specified feature and version.
113      */

114     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
115
116         // Currently, we support only XML Level 1 version 1.0
117
boolean anyVersion = version == null || version.length() == 0;
118         return
119             (feature.equalsIgnoreCase("Core")
120             && (anyVersion
121         || version.equals("1.0")
122         || version.equals("2.0")))
123          || (feature.equalsIgnoreCase("XML")
124             && (anyVersion
125         || version.equals("1.0")
126         || version.equals("2.0")))
127             ;
128
129     } // hasFeature(String,String):boolean
130

131     //
132
// Public methods
133
//
134

135     /** NON-DOM: Obtain and return the single shared object */
136     public static DOMImplementation JavaDoc getDOMImplementation() {
137         return singleton;
138     }
139     
140     /**
141      * Introduced in DOM Level 2. <p>
142      *
143      * Creates an empty DocumentType node.
144      *
145      * @param qualifiedName The qualified name of the document type to be created.
146      * @param publicID The document type public identifier.
147      * @param systemID The document type system identifier.
148      * @since WD-DOM-Level-2-19990923
149      */

150     public DocumentType JavaDoc createDocumentType(String JavaDoc qualifiedName,
151                                                  String JavaDoc publicID,
152                                                  String JavaDoc systemID)
153     {
154         if (!CoreDocumentImpl.isXMLName(qualifiedName)) {
155             throw new DOMException JavaDoc(DOMException.INVALID_CHARACTER_ERR,
156                                        "DOM002 Illegal character");
157         }
158         int index = qualifiedName.indexOf(':');
159         int lastIndex = qualifiedName.lastIndexOf(':');
160         // it is an error for NCName to have more than one ':'
161
if (index == 0 || index == qualifiedName.length() - 1 || lastIndex!=index) {
162         throw new DOMException JavaDoc(DOMException.NAMESPACE_ERR,
163                        "DOM003 Namespace error");
164     }
165         return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
166     }
167     /**
168      * Introduced in DOM Level 2. <p>
169      *
170      * Creates an XML Document object of the specified type with its document
171      * element.
172      *
173      * @param namespaceURI The namespace URI of the document
174      * element to create, or null.
175      * @param qualifiedName The qualified name of the document
176      * element to create.
177      * @param doctype The type of document to be created or null.<p>
178      *
179      * When doctype is not null, its
180      * Node.ownerDocument attribute is set to
181      * the document being created.
182      * @return Document A new Document object.
183      * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has
184      * already been used with a different document.
185      * @since WD-DOM-Level-2-19990923
186      */

187     public Document JavaDoc createDocument(String JavaDoc namespaceURI,
188                                              String JavaDoc qualifiedName,
189                                              DocumentType JavaDoc doctype)
190                                              throws DOMException JavaDoc
191     {
192         if (doctype != null && doctype.getOwnerDocument() != null) {
193             throw new DOMException JavaDoc(DOMException.WRONG_DOCUMENT_ERR,
194                                    "DOM005 Wrong document");
195         }
196         CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
197         Element JavaDoc e = doc.createElementNS( namespaceURI, qualifiedName);
198         doc.appendChild(e);
199         return doc;
200     }
201
202
203     /* (non-Javadoc)
204      * @see org.w3c.dom.DOMImplementation#getFeature(java.lang.String, java.lang.String)
205      */

206     public Object JavaDoc getFeature(String JavaDoc feature, String JavaDoc version) {
207         // TODO Auto-generated method stub
208
return null;
209     }
210
211 } // class DOMImplementationImpl
212
Popular Tags