jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java
author joehw
Tue, 29 Jul 2014 20:52:36 -0700
changeset 25834 aba3efbf4ec5
parent 25264 040625ce9b72
permissions -rw-r--r--
8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer. Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
     8
 * this work for additional information regarding copyright ownership.
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xerces.internal.dom;
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
import com.sun.org.apache.xerces.internal.impl.RevalidationHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xerces.internal.parsers.DOMParserImpl;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    25
import com.sun.org.apache.xerces.internal.parsers.DTDConfiguration;
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    26
import com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import com.sun.org.apache.xerces.internal.util.XMLChar;
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    28
import com.sun.org.apache.xerces.internal.utils.ObjectFactory;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.w3c.dom.DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import org.w3c.dom.DOMImplementation;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.DocumentType;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import org.w3c.dom.Element;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import org.w3c.dom.ls.LSParser;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import org.w3c.dom.ls.DOMImplementationLS;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import org.w3c.dom.ls.LSInput;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import org.w3c.dom.ls.LSOutput;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import org.w3c.dom.ls.LSSerializer;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * The DOMImplementation class is description of a particular
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * implementation of the Document Object Model. As such its data is
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * static, shared by all instances of this implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * The DOM API requires that it be a real object rather than static
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * methods. However, there's nothing that says it can't be a singleton,
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * so that's how I've implemented it.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * This particular class, along with CoreDocumentImpl, supports the DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * Core and Load/Save (Experimental). Optional modules are supported by
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * the more complete DOMImplementation class along with DocumentImpl.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * @since PR-DOM-Level-1-19980818.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
public class CoreDOMImplementationImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
        implements DOMImplementation, DOMImplementationLS {
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    // validators pool
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    private static final int SIZE = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    private RevalidationHandler validators[] = new RevalidationHandler[SIZE];
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    private RevalidationHandler dtdValidators[] = new RevalidationHandler[SIZE];
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    private int freeValidatorIndex = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    private int freeDTDValidatorIndex = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    private int currentSize = SIZE;
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    // Document and doctype counter.  Used to assign order to documents and
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    // doctypes without owners, on an demand basis.   Used for
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    // compareDocumentPosition
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    private int docAndDoctypeCounter = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
        // static
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
        /** Dom implementation singleton. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        static CoreDOMImplementationImpl singleton =
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
                new CoreDOMImplementationImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
        // Public methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
        /** NON-DOM: Obtain and return the single shared object */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
        public static DOMImplementation getDOMImplementation() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
                return singleton;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
        // DOMImplementation methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
         * Test if the DOM implementation supports a specific "feature" --
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
         * currently meaning language and level thereof.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
         * @param feature The package name of the feature to test.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
         * In Level 1, supported values are "HTML" and "XML" (case-insensitive).
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
         * At this writing, com.sun.org.apache.xerces.internal.dom supports only XML.
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
         * @param version The version number of the feature being tested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
         * This is interpreted as "Version of the DOM API supported for the
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
         * specified Feature", and in Level 1 should be "1.0"
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
         * @return true iff this implementation is compatable with the specified
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
         * feature and version.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        public boolean hasFeature(String feature, String version) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
            boolean anyVersion = version == null || version.length() == 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            // check if Xalan implementation is around and if yes report true for supporting
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
            // XPath API
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
            // if a plus sign "+" is prepended to any feature name, implementations
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
            // are considered in which the specified feature may not be directly
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
            // castable DOMImplementation.getFeature(feature, version). Without a
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            // plus, only features whose interfaces are directly castable are considered.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            if ((feature.equalsIgnoreCase("+XPath"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
                && (anyVersion || version.equals("3.0"))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                    Class xpathClass = ObjectFactory.findProviderClass(
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   121
                        "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                // Check if the DOM XPath implementation implements
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
                // the interface org.w3c.dom.XPathEvaluator
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                Class interfaces[] = xpathClass.getInterfaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                for (int i = 0; i < interfaces.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
                    if (interfaces[i].getName().equals(
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                        "org.w3c.dom.xpath.XPathEvaluator")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            if (feature.startsWith("+")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                feature = feature.substring(1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
            return (
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                feature.equalsIgnoreCase("Core")
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
                    && (anyVersion
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
                        || version.equals("1.0")
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
                        || version.equals("2.0")
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                        || version.equals("3.0")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                        || (feature.equalsIgnoreCase("XML")
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
                    && (anyVersion
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                        || version.equals("1.0")
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                        || version.equals("2.0")
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                        || version.equals("3.0")))
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                        || (feature.equalsIgnoreCase("LS")
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                    && (anyVersion || version.equals("3.0")));
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        } // hasFeature(String,String):boolean
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
         * Introduced in DOM Level 2. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
         * Creates an empty DocumentType node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
         * @param qualifiedName The qualified name of the document type to be created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
         * @param publicID The document type public identifier.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
         * @param systemID The document type system identifier.
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
         * @since WD-DOM-Level-2-19990923
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        public DocumentType createDocumentType( String qualifiedName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                                    String publicID, String systemID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                // REVISIT: this might allow creation of invalid name for DOCTYPE
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                //          xmlns prefix.
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                //          also there is no way for a user to turn off error checking.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                checkQName(qualifiedName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                return new DocumentTypeImpl(null, qualifiedName, publicID, systemID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    final void checkQName(String qname){
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        int index = qname.indexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        int lastIndex = qname.lastIndexOf(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        int length = qname.length();
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
        // it is an error for NCName to have more than one ':'
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        // check if it is valid QName [Namespace in XML production 6]
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        if (index == 0 || index == length - 1 || lastIndex != index) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
                DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
                    DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
                    "NAMESPACE_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
                    null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            throw new DOMException(DOMException.NAMESPACE_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
        int start = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
        // Namespace in XML production [6]
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
        if (index > 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
            // check that prefix is NCName
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
            if (!XMLChar.isNCNameStart(qname.charAt(start))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
                String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
                    DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                        DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                        "INVALID_CHARACTER_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
                        null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
            for (int i = 1; i < index; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
                if (!XMLChar.isNCName(qname.charAt(i))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
                    String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
                        DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
                            DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
                            "INVALID_CHARACTER_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
                            null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
                    throw new DOMException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
                        DOMException.INVALID_CHARACTER_ERR,
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
                        msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
            start = index + 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
        // check local part
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        if (!XMLChar.isNCNameStart(qname.charAt(start))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            // REVISIT: add qname parameter to the message
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
            String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
                DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                    DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
                    "INVALID_CHARACTER_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
                    null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        for (int i = start + 1; i < length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
            if (!XMLChar.isNCName(qname.charAt(i))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
                    DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
                        DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
                        "INVALID_CHARACTER_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                        null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
         * Introduced in DOM Level 2. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
         * Creates an XML Document object of the specified type with its document
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
         * element.
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
         * @param namespaceURI     The namespace URI of the document
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
         *                         element to create, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
         * @param qualifiedName    The qualified name of the document
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
         *                         element to create.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
         * @param doctype          The type of document to be created or null.<p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
         *
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
         *                         When doctype is not null, its
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
         *                         Node.ownerDocument attribute is set to
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
         *                         the document being created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
         * @return Document        A new Document object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
         * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
         *                         already been used with a different document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
         * @since WD-DOM-Level-2-19990923
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
        public Document createDocument(
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                String namespaceURI,
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                String qualifiedName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
                DocumentType doctype)
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
                throws DOMException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
                if (doctype != null && doctype.getOwnerDocument() != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                        String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
                                DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                                        DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                                        "WRONG_DOCUMENT_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                                        null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
                CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                Element e = doc.createElementNS(namespaceURI, qualifiedName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                doc.appendChild(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                return doc;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
         * DOM Level 3 WD - Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        public Object getFeature(String feature, String version) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            if (singleton.hasFeature(feature, version)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
                if ((feature.equalsIgnoreCase("+XPath"))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
                        Class xpathClass = ObjectFactory.findProviderClass(
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   287
                            "com.sun.org.apache.xpath.internal.domapi.XPathEvaluatorImpl", true);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
                        // Check if the DOM XPath implementation implements
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                        // the interface org.w3c.dom.XPathEvaluator
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
                        Class interfaces[] = xpathClass.getInterfaces();
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
                        for (int i = 0; i < interfaces.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
                            if (interfaces[i].getName().equals(
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
                                "org.w3c.dom.xpath.XPathEvaluator")) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                                return xpathClass.newInstance();
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                    } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
                    return singleton;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
        // DOM L3 LS
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
         * DOM Level 3 LS CR - Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
     * Create a new <code>LSParser</code>. The newly constructed parser may
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
     * then be configured by means of its <code>DOMConfiguration</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
     * object, and used to parse documents by means of its <code>parse</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
     *  method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
     * @param mode  The <code>mode</code> argument is either
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
     *   <code>MODE_SYNCHRONOUS</code> or <code>MODE_ASYNCHRONOUS</code>, if
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
     *   <code>mode</code> is <code>MODE_SYNCHRONOUS</code> then the
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
     *   <code>LSParser</code> that is created will operate in synchronous
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
     *   mode, if it's <code>MODE_ASYNCHRONOUS</code> then the
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
     *   <code>LSParser</code> that is created will operate in asynchronous
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
     *   mode.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
     * @param schemaType  An absolute URI representing the type of the schema
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
     *   language used during the load of a <code>Document</code> using the
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
     *   newly created <code>LSParser</code>. Note that no lexical checking
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
     *   is done on the absolute URI. In order to create a
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
     *   <code>LSParser</code> for any kind of schema types (i.e. the
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
     *   LSParser will be free to use any schema found), use the value
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
     *   <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
     * <p ><b>Note:</b>    For W3C XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
     *   , applications must use the value
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
     *   <code>"http://www.w3.org/2001/XMLSchema"</code>. For XML DTD [<a href='http://www.w3.org/TR/2000/REC-xml-20001006'>XML 1.0</a>],
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
     *   applications must use the value
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
     *   <code>"http://www.w3.org/TR/REC-xml"</code>. Other Schema languages
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
     *   are outside the scope of the W3C and therefore should recommend an
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
     *   absolute URI in order to use this method.
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
     * @return  The newly created <code>LSParser</code> object. This
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
     *   <code>LSParser</code> is either synchronous or asynchronous
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
     *   depending on the value of the <code>mode</code> argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
     * <p ><b>Note:</b>    By default, the newly created <code>LSParser</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
     *    does not contain a <code>DOMErrorHandler</code>, i.e. the value of
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
     *   the "<a href='http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030609/core.html#parameter-error-handler'>
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
     *   error-handler</a>" configuration parameter is <code>null</code>. However, implementations
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
     *   may provide a default error handler at creation time. In that case,
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
     *   the initial value of the <code>"error-handler"</code> configuration
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
     *   parameter on the new created <code>LSParser</code> contains a
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
     *   reference to the default error handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
     * @exception DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
     *    NOT_SUPPORTED_ERR: Raised if the requested mode or schema type is
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
     *   not supported.
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
        public LSParser createLSParser(short mode, String schemaType)
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
                throws DOMException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                if (mode != DOMImplementationLS.MODE_SYNCHRONOUS || (schemaType !=null &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                   !"http://www.w3.org/2001/XMLSchema".equals(schemaType) &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
                        !"http://www.w3.org/TR/REC-xml".equals(schemaType))) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                        String msg =
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                                DOMMessageFormatter.formatMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                                        DOMMessageFormatter.DOM_DOMAIN,
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
                                        "NOT_SUPPORTED_ERR",
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                                        null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
                if (schemaType != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                        && schemaType.equals("http://www.w3.org/TR/REC-xml")) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   365
                        return new DOMParserImpl(new DTDConfiguration(),
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                                schemaType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
                else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
                        // create default parser configuration validating against XMLSchemas
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   370
                        return new DOMParserImpl(new XIncludeAwareParserConfiguration(),
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
                                schemaType);
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
         * DOM Level 3 LS CR - Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
         * Create a new <code>LSSerializer</code> object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
         * @return The newly created <code>LSSerializer</code> object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
         * <p ><b>Note:</b>    By default, the newly created
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
         * <code>LSSerializer</code> has no <code>DOMErrorHandler</code>,
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
         * i.e. the value of the <code>"error-handler"</code> configuration
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
         * parameter is <code>null</code>. However, implementations may
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
         * provide a default error handler at creation time. In that case, the
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
         * initial value of the <code>"error-handler"</code> configuration
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
         * parameter on the new created <code>LSSerializer</code> contains a
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
         * reference to the default error handler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
        public LSSerializer createLSSerializer() {
25834
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   389
            try {
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   390
                Class serializerClass = ObjectFactory.findProviderClass(
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   391
                    "com.sun.org.apache.xml.internal.serializer.dom3.LSSerializerImpl",
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   392
                    ObjectFactory.findClassLoader(), true);
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   393
                return (LSSerializer) serializerClass.newInstance();
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   394
            }
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   395
            catch (Exception e) {}
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   396
            // Fall back to Xerces' deprecated serializer if
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   397
            // the Xalan based serializer is unavailable.
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   398
            return new DOMSerializerImpl();
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   399
        }
aba3efbf4ec5 8035467: Xerces Update: Move to Xalan based DOM L3 serializer. Deprecate Xerces' native serializer.
joehw
parents: 25264
diff changeset
   400
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
         * DOM Level 3 LS CR - Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
         * Create a new empty input source.
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
         * @return  The newly created input object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
        public LSInput createLSInput() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
                return new DOMInputImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
        // Protected methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
        /** NON-DOM: retrieve validator. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
        synchronized RevalidationHandler getValidator(String schemaType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
                // REVISIT: implement retrieving DTD validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
        if (schemaType == XMLGrammarDescription.XML_SCHEMA) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
            // create new validator - we should not attempt
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
            // to restrict the number of validation handlers being
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
            // requested
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            if(freeValidatorIndex < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
                return (RevalidationHandler) (ObjectFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
                            .newInstance(
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
                                "com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
                                ObjectFactory.findClassLoader(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
                                true));
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            // return first available validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            RevalidationHandler val = validators[freeValidatorIndex];
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            validators[freeValidatorIndex--] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
            return val;
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
        else if(schemaType == XMLGrammarDescription.XML_DTD) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
            if(freeDTDValidatorIndex < 0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
                return (RevalidationHandler) (ObjectFactory
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
                            .newInstance(
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                                "com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator",
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
                                ObjectFactory.findClassLoader(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
                                true));
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
            // return first available validator
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
            RevalidationHandler val = dtdValidators[freeDTDValidatorIndex];
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
            dtdValidators[freeDTDValidatorIndex--] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
            return val;
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
        /** NON-DOM: release validator */
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
        synchronized void releaseValidator(String schemaType,
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
                                         RevalidationHandler validator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
       // REVISIT: implement support for DTD validators as well
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
       if(schemaType == XMLGrammarDescription.XML_SCHEMA) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
           ++freeValidatorIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
           if (validators.length == freeValidatorIndex ){
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
                // resize size of the validators
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
                currentSize+=SIZE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
                RevalidationHandler newarray[] =  new RevalidationHandler[currentSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
                System.arraycopy(validators, 0, newarray, 0, validators.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
                validators = newarray;
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
           }
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
           validators[freeValidatorIndex]=validator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
       else if(schemaType == XMLGrammarDescription.XML_DTD) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
           ++freeDTDValidatorIndex;
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
           if (dtdValidators.length == freeDTDValidatorIndex ){
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
                // resize size of the validators
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
                currentSize+=SIZE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
                RevalidationHandler newarray[] =  new RevalidationHandler[currentSize];
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
                System.arraycopy(dtdValidators, 0, newarray, 0, dtdValidators.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
                dtdValidators = newarray;
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
           }
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
           dtdValidators[freeDTDValidatorIndex]=validator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
       /** NON-DOM:  increment document/doctype counter */
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
       protected synchronized int assignDocumentNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
            return ++docAndDoctypeCounter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
       /** NON-DOM:  increment document/doctype counter */
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
       protected synchronized int assignDocTypeNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
            return ++docAndDoctypeCounter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
    /* DOM Level 3 LS CR - Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
     * Create a new empty output destination object where
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
     * <code>LSOutput.characterStream</code>,
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
     * <code>LSOutput.byteStream</code>, <code>LSOutput.systemId</code>,
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
     * <code>LSOutput.encoding</code> are null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
     * @return  The newly created output object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
       public LSOutput createLSOutput() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
           return new DOMOutputImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
       }
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
} // class DOMImplementationImpl