KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > DOMImplementationImpl


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.dom;
18
19 import org.w3c.dom.DOMException JavaDoc;
20 import org.w3c.dom.DOMImplementation JavaDoc;
21 import org.w3c.dom.Document JavaDoc;
22 import org.w3c.dom.DocumentType JavaDoc;
23 import org.w3c.dom.Element JavaDoc;
24
25
26
27 /**
28  * The DOMImplementation class is description of a particular
29  * implementation of the Document Object Model. As such its data is
30  * static, shared by all instances of this implementation.
31  * <P>
32  * The DOM API requires that it be a real object rather than static
33  * methods. However, there's nothing that says it can't be a singleton,
34  * so that's how I've implemented it.
35  *
36  * @xerces.internal
37  *
38  * @version $Id: DOMImplementationImpl.java,v 1.33 2004/10/05 17:12:49 mrglavas Exp $
39  * @since PR-DOM-Level-1-19980818.
40  */

41 public class DOMImplementationImpl extends CoreDOMImplementationImpl
42     implements DOMImplementation JavaDoc {
43
44     //
45
// Data
46
//
47

48     // static
49

50     /** Dom implementation singleton. */
51     static DOMImplementationImpl singleton = new DOMImplementationImpl();
52
53
54     //
55
// Public methods
56
//
57

58     /** NON-DOM: Obtain and return the single shared object */
59     public static DOMImplementation JavaDoc getDOMImplementation() {
60         return singleton;
61     }
62
63     //
64
// DOMImplementation methods
65
//
66

67     /**
68      * Test if the DOM implementation supports a specific "feature" --
69      * currently meaning language and level thereof.
70      *
71      * @param feature The package name of the feature to test.
72      * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
73      * At this writing, org.apache.xerces.dom supports only XML.
74      *
75      * @param version The version number of the feature being tested.
76      * This is interpreted as "Version of the DOM API supported for the
77      * specified Feature", and in Level 1 should be "1.0"
78      *
79      * @return true iff this implementation is compatable with the
80      * specified feature and version.
81      */

82     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
83
84         boolean result = super.hasFeature(feature, version);
85         if (!result) {
86             boolean anyVersion = version == null || version.length() == 0;
87             if (feature.startsWith("+")) {
88                 feature = feature.substring(1);
89             }
90             return (
91                 (feature.equalsIgnoreCase("Events")
92                     && (anyVersion || version.equals("2.0")))
93                     || (feature.equalsIgnoreCase("MutationEvents")
94                         && (anyVersion || version.equals("2.0")))
95                     || (feature.equalsIgnoreCase("Traversal")
96                         && (anyVersion || version.equals("2.0")))
97                     || (feature.equalsIgnoreCase("Range")
98                         && (anyVersion || version.equals("2.0")))
99                     || (feature.equalsIgnoreCase("MutationEvents")
100                         && (anyVersion || version.equals("2.0"))));
101         }
102         return result;
103     } // hasFeature(String,String):boolean
104

105
106
107     /**
108      * Introduced in DOM Level 2. <p>
109      *
110      * Creates an XML Document object of the specified type with its document
111      * element.
112      *
113      * @param namespaceURI The namespace URI of the document
114      * element to create, or null.
115      * @param qualifiedName The qualified name of the document
116      * element to create.
117      * @param doctype The type of document to be created or null.<p>
118      *
119      * When doctype is not null, its
120      * Node.ownerDocument attribute is set to
121      * the document being created.
122      * @return Document A new Document object.
123      * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has
124      * already been used with a different document.
125      * @since WD-DOM-Level-2-19990923
126      */

127     public Document JavaDoc createDocument(String JavaDoc namespaceURI,
128                                              String JavaDoc qualifiedName,
129                                              DocumentType JavaDoc doctype)
130                                              throws DOMException JavaDoc
131     {
132         if(namespaceURI == null && qualifiedName == null && doctype == null){
133         //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
134
//no document element
135
return new DocumentImpl();
136         }
137         else if (doctype != null && doctype.getOwnerDocument() != null) {
138             String JavaDoc msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
139             throw new DOMException JavaDoc(DOMException.WRONG_DOCUMENT_ERR, msg);
140         }
141         DocumentImpl doc = new DocumentImpl(doctype);
142         Element JavaDoc e = doc.createElementNS( namespaceURI, qualifiedName);
143         doc.appendChild(e);
144         return doc;
145     }
146
147
148 } // class DOMImplementationImpl
149
Popular Tags