KickJava   Java API By Example, From Geeks To Geeks.

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


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  * The DOMImplementation class is description of a particular
27  * implementation of the Document Object Model. As such its data is
28  * static, shared by all instances of this implementation.
29  * <P>
30  * The DOM API requires that it be a real object rather than static
31  * methods. However, there's nothing that says it can't be a singleton,
32  * so that's how I've implemented it.
33  *
34  * @xerces.internal
35  *
36  * @version $Id: PSVIDOMImplementationImpl.java,v 1.6 2004/10/05 17:12:51 mrglavas Exp $
37  * @since PR-DOM-Level-1-19980818.
38  */

39 public class PSVIDOMImplementationImpl extends CoreDOMImplementationImpl {
40
41     //
42
// Data
43
//
44

45     // static
46

47     /** Dom implementation singleton. */
48     static PSVIDOMImplementationImpl singleton = new PSVIDOMImplementationImpl();
49
50     //
51
// Public methods
52
//
53

54     /** NON-DOM: Obtain and return the single shared object */
55     public static DOMImplementation JavaDoc getDOMImplementation() {
56         return singleton;
57     }
58
59     //
60
// DOMImplementation methods
61
//
62

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

78     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
79         return super.hasFeature(feature, version) ||
80                feature.equalsIgnoreCase("psvi");
81     } // hasFeature(String,String):boolean
82

83     /**
84      * Introduced in DOM Level 2. <p>
85      *
86      * Creates an XML Document object of the specified type with its document
87      * element.
88      *
89      * @param namespaceURI The namespace URI of the document
90      * element to create, or null.
91      * @param qualifiedName The qualified name of the document
92      * element to create.
93      * @param doctype The type of document to be created or null.<p>
94      *
95      * When doctype is not null, its
96      * Node.ownerDocument attribute is set to
97      * the document being created.
98      * @return Document A new Document object.
99      * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has
100      * already been used with a different document.
101      * @since WD-DOM-Level-2-19990923
102      */

103     public Document JavaDoc createDocument(String JavaDoc namespaceURI,
104                                              String JavaDoc qualifiedName,
105                                              DocumentType JavaDoc doctype)
106                                              throws DOMException JavaDoc
107     {
108         if (doctype != null && doctype.getOwnerDocument() != null) {
109             throw new DOMException JavaDoc(DOMException.WRONG_DOCUMENT_ERR,
110                                    DOMMessageFormatter.formatMessage(
111                                    DOMMessageFormatter.XML_DOMAIN,
112                                    "WRONG_DOCUMENT_ERR", null));
113         }
114         DocumentImpl doc = new PSVIDocumentImpl(doctype);
115         Element JavaDoc e = doc.createElementNS( namespaceURI, qualifiedName);
116         doc.appendChild(e);
117         return doc;
118     }
119     
120
121 } // class DOMImplementationImpl
122
Popular Tags