jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/dom/DocumentTypeImpl.java
author joehw
Thu, 28 Jul 2016 22:58:41 -0700
changeset 39907 db51759e3695
parent 33349 975138b77cff
permissions -rw-r--r--
8158084: Catalog API: JAXP XML Processor Support Reviewed-by: lancea, clanger
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
/*
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     5
 * Licensed to the Apache Software Foundation (ASF) under one or more
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     6
 * contributor license agreements.  See the NOTICE file distributed with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     7
 * this work for additional information regarding copyright ownership.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     8
 * The ASF licenses this file to You under the Apache License, Version 2.0
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
     9
 * (the "License"); you may not use this file except in compliance with
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    10
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
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
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    23
import java.io.IOException;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    24
import java.io.ObjectInputStream;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    25
import java.io.ObjectOutputStream;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    26
import java.io.ObjectStreamField;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    27
import java.util.HashMap;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    28
import java.util.Hashtable;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    29
import java.util.Map;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import org.w3c.dom.DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import org.w3c.dom.DocumentType;
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
    32
import org.w3c.dom.NamedNodeMap;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.UserDataHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * This class represents a Document Type <em>declaraction</em> in
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * the document itself, <em>not</em> a Document Type Definition (DTD).
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * An XML document may (or may not) have such a reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * DocumentType is an Extended DOM feature, used in XML documents but
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * not in HTML.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * Note that Entities and Notations are no longer children of the
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * DocumentType, but are parentless nodes hung only in their
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * appropriate NamedNodeMaps.
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * <P>
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * Most notably, absolutely no provision was made for storing
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * and using Element and Attribute information. Nor was the linkage
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * between Entities and Entity References nailed down solidly.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * @author Arnaud  Le Hors, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * @author Joe Kesselman, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * @author Andy Clark, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * @since  PR-DOM-Level-1-19980818.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
public class DocumentTypeImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    extends ParentNode
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    implements DocumentType {
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    // Constants
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    /** Serialization version. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    static final long serialVersionUID = 7751299192316526485L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    /** Document type name. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    protected String name;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    /** Entities. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    protected NamedNodeMapImpl entities;
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    /** Notations. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    protected NamedNodeMapImpl notations;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    // NON-DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    /** Elements. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    protected NamedNodeMapImpl elements;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    // DOM2: support public ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    protected String publicID;
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
    // DOM2: support system ID.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    protected String systemID;
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    // DOM2: support internal subset.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    protected String internalSubset;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    /** The following are required for compareDocumentPosition
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    // Doctype number.   Doc types which have no owner may be assigned
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
    // a number, on demand, for ordering purposes for compareDocumentPosition
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    private int doctypeNumber=0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   104
    private Map<String, UserDataRecord> userData =  null;
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   105
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   106
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   107
    /**
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   108
     * @serialField name String document type name
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   109
     * @serialField entities NamedNodeMapImpl entities
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   110
     * @serialField notations NamedNodeMapImpl notations
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   111
     * @serialField elements NamedNodeMapImpl elements
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   112
     * @serialField publicID String support public ID
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   113
     * @serialField systemID String support system ID
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   114
     * @serialField internalSubset String support internal subset
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   115
     * @serialField doctypeNumber int Doctype number
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   116
     * @serialField userData Hashtable user data
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   117
     */
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   118
    private static final ObjectStreamField[] serialPersistentFields =
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   119
        new ObjectStreamField[] {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   120
            new ObjectStreamField("name", String.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   121
            new ObjectStreamField("entities", NamedNodeMapImpl.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   122
            new ObjectStreamField("notations", NamedNodeMapImpl.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   123
            new ObjectStreamField("elements", NamedNodeMapImpl.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   124
            new ObjectStreamField("publicID", String.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   125
            new ObjectStreamField("systemID", String.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   126
            new ObjectStreamField("internalSubset", String.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   127
            new ObjectStreamField("doctypeNumber", int.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   128
            new ObjectStreamField("userData", Hashtable.class),
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   129
        };
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   130
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    //
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   134
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    /** Factory method for creating a document type node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    public DocumentTypeImpl(CoreDocumentImpl ownerDocument, String name) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        super(ownerDocument);
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
        this.name = name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
        // DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
        entities  = new NamedNodeMapImpl(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
        notations = new NamedNodeMapImpl(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
        // NON-DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        elements = new NamedNodeMapImpl(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    } // <init>(CoreDocumentImpl,String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    /** Factory method for creating a document type node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    public DocumentTypeImpl(CoreDocumentImpl ownerDocument,
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
                            String qualifiedName,
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                            String publicID, String systemID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
        this(ownerDocument, qualifiedName);
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
        this.publicID = publicID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
        this.systemID = systemID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
    } // <init>(CoreDocumentImpl,String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    // DOM2: methods.
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
     * Introduced in DOM Level 2. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
     * Return the public identifier of this Document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * @since WD-DOM-Level-2-19990923
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    public String getPublicId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        return publicID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     * Introduced in DOM Level 2. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * Return the system identifier of this Document type.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     * @since WD-DOM-Level-2-19990923
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    public String getSystemId() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        return systemID;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     * NON-DOM. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     * Set the internalSubset given as a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    public void setInternalSubset(String internalSubset) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
        this.internalSubset = internalSubset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     * Introduced in DOM Level 2. <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
     * Return the internalSubset given as a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     * @since WD-DOM-Level-2-19990923
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    public String getInternalSubset() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        return internalSubset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    // Node methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
     * A short integer indicating what type of node this is. The named
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
     * constants for this value are defined in the org.w3c.dom.Node interface.
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    public short getNodeType() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        return Node.DOCUMENT_TYPE_NODE;
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
     * Returns the document type name
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
    public String getNodeName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    /** Clones the node. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
    public Node cloneNode(boolean deep) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
        DocumentTypeImpl newnode = (DocumentTypeImpl)super.cloneNode(deep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        // NamedNodeMaps must be cloned explicitly, to avoid sharing them.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
        newnode.entities  = entities.cloneMap(newnode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        newnode.notations = notations.cloneMap(newnode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        newnode.elements  = elements.cloneMap(newnode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        return newnode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    } // cloneNode(boolean):Node
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * Get Node text content
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * @since DOM Level 3
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    public String getTextContent() throws DOMException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
     * Set Node text content
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
     * @since DOM Level 3
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    public void setTextContent(String textContent)
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
        throws DOMException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
        // no-op
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
          * DOM Level 3 WD- Experimental.
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
          * Override inherited behavior from ParentNodeImpl to support deep equal.
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
          */
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    public boolean isEqualNode(Node arg) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        if (!super.isEqualNode(arg)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        DocumentTypeImpl argDocType = (DocumentTypeImpl) arg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
        //test if the following string attributes are equal: publicId,
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
        //systemId, internalSubset.
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
        if ((getPublicId() == null && argDocType.getPublicId() != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            || (getPublicId() != null && argDocType.getPublicId() == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
            || (getSystemId() == null && argDocType.getSystemId() != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
            || (getSystemId() != null && argDocType.getSystemId() == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
            || (getInternalSubset() == null
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
                && argDocType.getInternalSubset() != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
            || (getInternalSubset() != null
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
                && argDocType.getInternalSubset() == null)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        if (getPublicId() != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
            if (!getPublicId().equals(argDocType.getPublicId())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        if (getSystemId() != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
            if (!getSystemId().equals(argDocType.getSystemId())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
        if (getInternalSubset() != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            if (!getInternalSubset().equals(argDocType.getInternalSubset())) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        //test if NamedNodeMaps entities and notations are equal
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        NamedNodeMapImpl argEntities = argDocType.entities;
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
        if ((entities == null && argEntities != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
            || (entities != null && argEntities == null))
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
        if (entities != null && argEntities != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            if (entities.getLength() != argEntities.getLength())
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
            for (int index = 0; entities.item(index) != null; index++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                Node entNode1 = entities.item(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
                Node entNode2 =
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
                    argEntities.getNamedItem(entNode1.getNodeName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
                if (!((NodeImpl) entNode1).isEqualNode((NodeImpl) entNode2))
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
        NamedNodeMapImpl argNotations = argDocType.notations;
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
        if ((notations == null && argNotations != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
            || (notations != null && argNotations == null))
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
            return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
        if (notations != null && argNotations != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            if (notations.getLength() != argNotations.getLength())
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
            for (int index = 0; notations.item(index) != null; index++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
                Node noteNode1 = notations.item(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                Node noteNode2 =
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                    argNotations.getNamedItem(noteNode1.getNodeName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
                if (!((NodeImpl) noteNode1).isEqualNode((NodeImpl) noteNode2))
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
                    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    } //end isEqualNode
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
     * NON-DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
     * set the ownerDocument of this node and its children
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
    void setOwnerDocument(CoreDocumentImpl doc) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
        super.setOwnerDocument(doc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
        entities.setOwnerDocument(doc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
        notations.setOwnerDocument(doc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
        elements.setOwnerDocument(doc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
    /** NON-DOM
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        Get the number associated with this doctype.
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    */
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
    protected int getNodeNumber() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
         // If the doctype has a document owner, get the node number
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
         // relative to the owner doc
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
         if (getOwnerDocument()!=null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
            return super.getNodeNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
         // The doctype is disconnected and not associated with any document.
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
         // Assign the doctype a number relative to the implementation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
         if (doctypeNumber==0) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
            CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation();
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
            doctypeNumber = cd.assignDocTypeNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
         return doctypeNumber;
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
    // DocumentType methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
     * Name of this document type. If we loaded from a DTD, this should
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
     * be the name immediately following the DOCTYPE keyword.
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
    public String getName() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
        if (needsSyncData()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
            synchronizeData();
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
        return name;
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
    } // getName():String
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
     * Access the collection of general Entities, both external and
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
     * internal, defined in the DTD. For example, in:
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
     * <pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
     *   &lt;!doctype example SYSTEM "ex.dtd" [
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
     *     &lt;!ENTITY foo "foo"&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
     *     &lt;!ENTITY bar "bar"&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
     *     &lt;!ENTITY % baz "baz"&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
     *     ]&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
     * </pre>
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
     * The Entities map includes foo and bar, but not baz. It is promised that
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
     * only Nodes which are Entities will exist in this NamedNodeMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
     * For HTML, this will always be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
     * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
     * Note that "built in" entities such as &amp; and &lt; should be
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
     * converted to their actual characters before being placed in the DOM's
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
     * contained text, and should be converted back when the DOM is rendered
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
     * as XML or HTML, and hence DO NOT appear here.
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
    public NamedNodeMap getEntities() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
        if (needsSyncChildren()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            synchronizeChildren();
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
        return entities;
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
     * Access the collection of Notations defined in the DTD.  A
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
     * notation declares, by name, the format of an XML unparsed entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
     * or is used to formally declare a Processing Instruction target.
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
    public NamedNodeMap getNotations() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
        if (needsSyncChildren()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
            synchronizeChildren();
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
        return notations;
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
    // Public methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
     * NON-DOM: Subclassed to flip the entities' and notations' readonly switch
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
     * as well.
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
     * @see NodeImpl#setReadOnly
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
    public void setReadOnly(boolean readOnly, boolean deep) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
        if (needsSyncChildren()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
            synchronizeChildren();
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
        super.setReadOnly(readOnly, deep);
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
        // set read-only property
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
        elements.setReadOnly(readOnly, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
        entities.setReadOnly(readOnly, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
        notations.setReadOnly(readOnly, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
    } // setReadOnly(boolean,boolean)
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
     * NON-DOM: Access the collection of ElementDefinitions.
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
     * @see ElementDefinitionImpl
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
    public NamedNodeMap getElements() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
        if (needsSyncChildren()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
            synchronizeChildren();
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
        return elements;
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    public Object setUserData(String key,
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
    Object data, UserDataHandler handler) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
        if(userData == null)
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   481
            userData = new HashMap<>();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
        if (data == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
            if (userData != null) {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   484
                UserDataRecord udr = userData.remove(key);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   485
                if (udr != null) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   486
                    return udr.fData;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
        else {
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   492
            UserDataRecord udr = userData.put(key, new UserDataRecord(data, handler));
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   493
            if (udr != null) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   494
                return udr.fData;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    public Object getUserData(String key) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
        if (userData == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
        }
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   504
        UserDataRecord udr = userData.get(key);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   505
        if (udr != null) {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   506
            return udr.fData;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
        return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   511
    @Override
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   512
    protected Map<String, UserDataRecord> getUserDataRecord(){
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
        return userData;
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
33349
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   516
    /**
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   517
     * @serialData Serialized fields. Convert Map to Hashtable for backward
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   518
     * compatibility.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   519
     */
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   520
    private void writeObject(ObjectOutputStream out) throws IOException {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   521
        // Convert the HashMap to Hashtable
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   522
        Hashtable<String, UserDataRecord> ud = (userData == null)? null : new Hashtable<>(userData);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   523
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   524
        // Write serialized fields
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   525
        ObjectOutputStream.PutField pf = out.putFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   526
        pf.put("name", name);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   527
        pf.put("entities", entities);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   528
        pf.put("notations", notations);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   529
        pf.put("elements", elements);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   530
        pf.put("publicID", publicID);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   531
        pf.put("systemID", systemID);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   532
        pf.put("internalSubset", internalSubset);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   533
        pf.put("doctypeNumber", doctypeNumber);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   534
        pf.put("userData", ud);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   535
        out.writeFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   536
    }
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   537
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   538
    @SuppressWarnings("unchecked")
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   539
    private void readObject(ObjectInputStream in)
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   540
                        throws IOException, ClassNotFoundException {
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   541
        // We have to read serialized fields first.
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   542
        ObjectInputStream.GetField gf = in.readFields();
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   543
        name = (String)gf.get("name", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   544
        entities = (NamedNodeMapImpl)gf.get("entities", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   545
        notations = (NamedNodeMapImpl)gf.get("notations", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   546
        elements = (NamedNodeMapImpl)gf.get("elements", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   547
        publicID = (String)gf.get("publicID", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   548
        systemID = (String)gf.get("systemID", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   549
        internalSubset = (String)gf.get("internalSubset", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   550
        doctypeNumber = gf.get("doctypeNumber", 0);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   551
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   552
        Hashtable<String, UserDataRecord> ud =
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   553
                (Hashtable<String, UserDataRecord>)gf.get("userData", null);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   554
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   555
        //convert the Hashtable back to HashMap
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   556
        if (ud != null) userData = new HashMap<>(ud);
975138b77cff 8068842: Better JAXP data handling
joehw
parents: 25868
diff changeset
   557
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
} // class DocumentTypeImpl