1/*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5/*
6 * Licensed to the Apache Software Foundation (ASF) under one or more
7 * contributor license agreements.  See the NOTICE file distributed with
8 * this work for additional information regarding copyright ownership.
9 * The ASF licenses this file to You under the Apache License, Version 2.0
10 * (the "License"); you may not use this file except in compliance with
11 * the License.  You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22package com.sun.org.apache.xerces.internal.dom;
23
24import org.w3c.dom.DOMException;
25import org.w3c.dom.DOMImplementation;
26import org.w3c.dom.Document;
27import org.w3c.dom.DocumentType;
28import org.w3c.dom.Element;
29
30/**
31 * The DOMImplementation class is description of a particular
32 * implementation of the Document Object Model. As such its data is
33 * static, shared by all instances of this implementation.
34 * <P>
35 * The DOM API requires that it be a real object rather than static
36 * methods. However, there's nothing that says it can't be a singleton,
37 * so that's how I've implemented it.
38 *
39 * @xerces.internal
40 *
41 * @since  PR-DOM-Level-1-19980818.
42 */
43public class PSVIDOMImplementationImpl extends CoreDOMImplementationImpl {
44
45    //
46    // Data
47    //
48
49    // static
50
51    /** Dom implementation singleton. */
52    static PSVIDOMImplementationImpl singleton = new PSVIDOMImplementationImpl();
53
54    //
55    // Public methods
56    //
57
58    /** NON-DOM: Obtain and return the single shared object */
59    public static DOMImplementation 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, com.sun.org.apache.xerces.internal.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 specified
80     * feature and version.
81     */
82    public boolean hasFeature(String feature, String version) {
83        return super.hasFeature(feature, version) ||
84               feature.equalsIgnoreCase("psvi");
85    } // hasFeature(String,String):boolean
86
87    /**
88     * Introduced in DOM Level 2. <p>
89     *
90     * Creates an XML Document object of the specified type with its document
91     * element.
92     *
93     * @param namespaceURI     The namespace URI of the document
94     *                         element to create, or null.
95     * @param qualifiedName    The qualified name of the document
96     *                         element to create.
97     * @param doctype          The type of document to be created or null.<p>
98     *
99     *                         When doctype is not null, its
100     *                         Node.ownerDocument attribute is set to
101     *                         the document being created.
102     * @return Document        A new Document object.
103     * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
104     *                         already been used with a different document.
105     * @since WD-DOM-Level-2-19990923
106     */
107    public Document           createDocument(String namespaceURI,
108                                             String qualifiedName,
109                                             DocumentType doctype)
110                                             throws DOMException
111    {
112        if (doctype != null && doctype.getOwnerDocument() != null) {
113            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
114                                   DOMMessageFormatter.formatMessage(
115                                   DOMMessageFormatter.XML_DOMAIN,
116                                                       "WRONG_DOCUMENT_ERR", null));
117        }
118        DocumentImpl doc = new PSVIDocumentImpl(doctype);
119        Element e = doc.createElementNS( namespaceURI, qualifiedName);
120        doc.appendChild(e);
121        return doc;
122    }
123
124
125} // class DOMImplementationImpl
126