KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xpath > datamodel > xerces > dom > DOMImplementationImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999, 2000 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.xquark.xpath.datamodel.xerces.dom;
59
60 import org.w3c.dom.*;
61
62 /**
63  * The DOMImplementation class is description of a particular
64  * implementation of the Document Object Model. As such its data is
65  * static, shared by all instances of this implementation.
66  * <P>
67  * The DOM API requires that it be a real object rather than static
68  * methods. However, there's nothing that says it can't be a singleton,
69  * so that's how I've implemented it.
70  *
71  * @version
72  * @since PR-DOM-Level-1-19980818.
73  */

74 public class DOMImplementationImpl
75     implements DOMImplementation {
76
77     //
78
// Data
79
//
80

81     // static
82

83     /** Dom implementation singleton. */
84     static DOMImplementationImpl singleton = new DOMImplementationImpl();
85
86     //
87
// DOMImplementation methods
88
//
89

90     /**
91      * Test if the DOM implementation supports a specific "feature" --
92      * currently meaning language and level thereof.
93      *
94      * @param feature The package name of the feature to test.
95      * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
96      * At this writing, org.xquark.dom.typed.xerces.dom supports only XML.
97      *
98      * @param version The version number of the feature being tested.
99      * This is interpreted as "Version of the DOM API supported for the
100      * specified Feature", and in Level 1 should be "1.0"
101      *
102      * @returns true iff this implementation is compatable with the
103      * specified feature and version.
104      */

105     public boolean hasFeature(String JavaDoc feature, String JavaDoc version) {
106
107         // Currently, we support only XML Level 1 version 1.0
108
boolean anyVersion = version == null || version.length() == 0;
109         return
110             (feature.equalsIgnoreCase("Core")
111             && (anyVersion
112         || version.equals("1.0")
113         || version.equals("2.0")))
114          || (feature.equalsIgnoreCase("XML")
115             && (anyVersion
116         || version.equals("1.0")
117         || version.equals("2.0")))
118          || (feature.equalsIgnoreCase("Events")
119          && (anyVersion
120          || version.equals("2.0")))
121          || (feature.equalsIgnoreCase("MutationEvents")
122          && (anyVersion
123          || version.equals("2.0")))
124          || (feature.equalsIgnoreCase("Traversal")
125          && (anyVersion
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 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 createDocumentType(String JavaDoc qualifiedName,
151                                                  String JavaDoc publicID,
152                                                  String JavaDoc systemID)
153     {
154         if (!DocumentImpl.isXMLName(qualifiedName)) {
155             throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
156                                        "DOM002 Illegal character");
157         }
158         int index = qualifiedName.indexOf(':');
159         if (index == 0 || index == qualifiedName.length() - 1) {
160         throw new DOMException(DOMException.NAMESPACE_ERR,
161                        "DOM003 Namespace error");
162     }
163         return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
164     }
165     /**
166      * Introduced in DOM Level 2. <p>
167      *
168      * Creates an XML Document object of the specified type with its document
169      * element.
170      *
171      * @param namespaceURI The namespace URI of the document
172      * element to create, or null.
173      * @param qualifiedName The qualified name of the document
174      * element to create, or null.
175      * @param doctype The type of document to be created or null.<p>
176      *
177      * When doctype is not null, its
178      * Node.ownerDocument attribute is set to
179      * the document being created.
180      * @return Document A new Document object.
181      * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has
182      * already been used with a different document.
183      * @since WD-DOM-Level-2-19990923
184      */

185     public Document createDocument(String JavaDoc namespaceURI,
186                                              String JavaDoc qualifiedName,
187                                              DocumentType doctype)
188                                              throws DOMException
189     {
190         if (doctype != null && doctype.getOwnerDocument() != null) {
191             throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
192                                    "DOM005 Wrong document");
193         }
194         DocumentImpl doc = new DocumentImpl(doctype);
195         Element e = doc.createElementNS( namespaceURI, qualifiedName);
196         doc.appendChild(e);
197         return doc;
198     }
199
200 } // class DOMImplementationImpl
201
Popular Tags