KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > apache > 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.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  *
75  * @version
76  * @since PR-DOM-Level-1-19980818.
77  */

78 public class DOMImplementationImpl
79     implements DOMImplementation JavaDoc {
80
81     //
82
// Data
83
//
84

85     // static
86

87     /** Dom implementation singleton. */
88     static DOMImplementationImpl singleton = new DOMImplementationImpl();
89
90     //
91
// DOMImplementation methods
92
//
93

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

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

135     //
136
// Public methods
137
//
138

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

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

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

210     public Object JavaDoc getFeature(String JavaDoc feature, String JavaDoc version) {
211         // TODO Auto-generated method stub
212
return null;
213     }
214
215 } // class DOMImplementationImpl
216
Popular Tags