jaxp/src/com/sun/org/apache/xerces/internal/dom/NamedNodeMapImpl.java
author henryjen
Tue, 24 Jun 2014 14:07:05 -0700
changeset 25264 040625ce9b72
parent 12457 c348e06f0e82
permissions -rw-r--r--
8048021: Remove @version tag in jaxp repo Reviewed-by: joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12005
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     1
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     2
 * reserved comment block
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     4
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     5
/*
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     6
 * Copyright 1999-2002,2004,2005 The Apache Software Foundation.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     7
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    10
 * You may obtain a copy of the License at
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    11
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    13
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    18
 * limitations under the License.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    19
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    20
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    21
package com.sun.org.apache.xerces.internal.dom;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    22
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    23
import java.io.IOException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    24
import java.io.ObjectInputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    25
import java.io.ObjectOutputStream;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    26
import java.io.Serializable;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    27
import java.util.ArrayList;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    28
import java.util.List;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    29
import java.util.Vector;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    30
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    31
import org.w3c.dom.DOMException;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    32
import org.w3c.dom.NamedNodeMap;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    33
import org.w3c.dom.Node;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    34
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    35
/**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    36
 * NamedNodeMaps represent collections of Nodes that can be accessed
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    37
 * by name. Entity and Notation nodes are stored in NamedNodeMaps
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    38
 * attached to the DocumentType. Attributes are placed in a NamedNodeMap
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    39
 * attached to the elem they're related too. However, because attributes
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    40
 * require more work, such as firing mutation events, they are stored in
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    41
 * a subclass of NamedNodeMapImpl.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    42
 * <P>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    43
 * Only one Node may be stored per name; attempting to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    44
 * store another will replace the previous value.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    45
 * <P>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    46
 * NOTE: The "primary" storage key is taken from the NodeName attribute of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    47
 * node. The "secondary" storage key is the namespaceURI and localName, when
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    48
 * accessed by DOM level 2 nodes. All nodes, even DOM Level 2 nodes are stored
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    49
 * in a single Vector sorted by the primary "nodename" key.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    50
 * <P>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    51
 * NOTE: item()'s integer index does _not_ imply that the named nodes
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    52
 * must be stored in an array; that's only an access method. Note too
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    53
 * that these indices are "live"; if someone changes the map's
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    54
 * contents, the indices associated with nodes may change.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    55
 * <P>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    56
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    57
 * @xerces.internal
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    58
 *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    59
 * @since  PR-DOM-Level-1-19980818.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    60
 */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    61
public class NamedNodeMapImpl
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    62
    implements NamedNodeMap, Serializable {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    63
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    64
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    65
    // Constants
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    66
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    67
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    68
    /** Serialization version. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    69
    static final long serialVersionUID = -7039242451046758020L;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    70
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    71
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    72
    // Data
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    73
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    74
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    75
    protected short flags;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    76
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    77
    protected final static short READONLY     = 0x1<<0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    78
    protected final static short CHANGED      = 0x1<<1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    79
    protected final static short HASDEFAULTS  = 0x1<<2;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    80
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    81
    /** Nodes. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    82
    protected List nodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    83
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    84
    protected NodeImpl ownerNode; // the node this map belongs to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    85
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    86
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    87
    // Constructors
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    88
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    89
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    90
    /** Constructs a named node map. */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    91
    protected NamedNodeMapImpl(NodeImpl ownerNode) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    92
        this.ownerNode = ownerNode;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    93
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    94
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    95
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    96
    // NamedNodeMap methods
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    97
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    98
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
    99
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   100
     * Report how many nodes are currently stored in this NamedNodeMap.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   101
     * Caveat: This is a count rather than an index, so the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   102
     * highest-numbered node at any time can be accessed via
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   103
     * item(getLength()-1).
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   104
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   105
    public int getLength() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   106
        return (nodes != null) ? nodes.size() : 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   107
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   108
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   109
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   110
     * Retrieve an item from the map by 0-based index.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   111
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   112
     * @param index Which item to retrieve. Note that indices are just an
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   113
     * enumeration of the current contents; they aren't guaranteed to be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   114
     * stable, nor do they imply any promises about the order of the
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   115
     * NamedNodeMap's contents. In other words, DO NOT assume either that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   116
     * index(i) will always refer to the same entry, or that there is any
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   117
     * stable ordering of entries... and be prepared for double-reporting
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   118
     * or skips as insertion and deletion occur.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   119
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   120
     * @return the node which currenly has the specified index, or null if index
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   121
     * is greater than or equal to getLength().
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   122
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   123
    public Node item(int index) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   124
        return (nodes != null && index < nodes.size()) ?
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   125
                    (Node)(nodes.get(index)) : null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   126
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   127
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   128
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   129
     * Retrieve a node by name.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   130
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   131
     * @param name Name of a node to look up.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   132
     * @return the Node (of unspecified sub-class) stored with that name, or
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   133
     * null if no value has been assigned to that name.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   134
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   135
    public Node getNamedItem(String name) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   136
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   137
        int i = findNamePoint(name,0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   138
        return (i < 0) ? null : (Node)(nodes.get(i));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   139
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   140
    } // getNamedItem(String):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   141
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   142
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   143
     * Introduced in DOM Level 2. <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   144
     * Retrieves a node specified by local name and namespace URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   145
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   146
     * @param namespaceURI  The namespace URI of the node to retrieve.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   147
     *                      When it is null or an empty string, this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   148
     *                      method behaves like getNamedItem.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   149
     * @param localName     The local name of the node to retrieve.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   150
     * @return Node         A Node (of any type) with the specified name, or null if the specified
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   151
     *                      name did not identify any node in the map.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   152
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   153
    public Node getNamedItemNS(String namespaceURI, String localName) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   154
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   155
        int i = findNamePoint(namespaceURI, localName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   156
        return (i < 0) ? null : (Node)(nodes.get(i));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   157
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   158
    } // getNamedItemNS(String,String):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   159
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   160
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   161
     * Adds a node using its nodeName attribute.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   162
     * As the nodeName attribute is used to derive the name which the node must be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   163
     * stored under, multiple nodes of certain types (those that have a "special" string
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   164
     * value) cannot be stored as the names would clash. This is seen as preferable to
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   165
     * allowing nodes to be aliased.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   166
     * @see org.w3c.dom.NamedNodeMap#setNamedItem
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   167
     * @return If the new Node replaces an existing node the replaced Node is returned,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   168
     *      otherwise null is returned.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   169
     * @param arg
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   170
     *      A node to store in a named node map. The node will later be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   171
     *      accessible using the value of the namespaceURI and localName
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   172
     *      attribute of the node. If a node with those namespace URI and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   173
     *      local name is already present in the map, it is replaced by the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   174
     *      one.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   175
     * @exception org.w3c.dom.DOMException The exception description.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   176
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   177
    public Node setNamedItem(Node arg)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   178
    throws DOMException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   179
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   180
        CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   181
        if (ownerDocument.errorChecking) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   182
            if (isReadOnly()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   183
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   184
                throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   185
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   186
            if (arg.getOwnerDocument() != ownerDocument) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   187
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   188
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   189
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   190
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   191
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   192
        int i = findNamePoint(arg.getNodeName(),0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   193
        NodeImpl previous = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   194
        if (i >= 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   195
            previous = (NodeImpl) nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   196
            nodes.set(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   197
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   198
            i = -1 - i; // Insert point (may be end of list)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   199
            if (null == nodes) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   200
                nodes = new ArrayList(5);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   201
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   202
            nodes.add(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   203
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   204
        return previous;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   205
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   206
    } // setNamedItem(Node):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   207
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   208
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   209
     * Adds a node using its namespaceURI and localName.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   210
     * @see org.w3c.dom.NamedNodeMap#setNamedItem
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   211
     * @return If the new Node replaces an existing node the replaced Node is returned,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   212
     *      otherwise null is returned.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   213
     * @param arg A node to store in a named node map. The node will later be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   214
     *      accessible using the value of the namespaceURI and localName
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   215
     *      attribute of the node. If a node with those namespace URI and
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   216
     *      local name is already present in the map, it is replaced by the new
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   217
     *      one.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   218
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   219
    public Node setNamedItemNS(Node arg)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   220
    throws DOMException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   221
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   222
        CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   223
        if (ownerDocument.errorChecking) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   224
            if (isReadOnly()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   225
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   226
                throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   227
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   228
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   229
            if(arg.getOwnerDocument() != ownerDocument) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   230
                String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   231
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   232
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   233
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   234
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   235
        int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   236
        NodeImpl previous = null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   237
        if (i >= 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   238
            previous = (NodeImpl) nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   239
            nodes.set(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   240
        } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   241
            // If we can't find by namespaceURI, localName, then we find by
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   242
            // nodeName so we know where to insert.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   243
            i = findNamePoint(arg.getNodeName(),0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   244
            if (i >= 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   245
                previous = (NodeImpl) nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   246
                nodes.add(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   247
            } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   248
                i = -1 - i; // Insert point (may be end of list)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   249
                if (null == nodes) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   250
                    nodes = new ArrayList(5);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   251
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   252
                nodes.add(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   253
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   254
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   255
        return previous;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   256
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   257
    } // setNamedItemNS(Node):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   258
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   259
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   260
     * Removes a node specified by name.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   261
     * @param name The name of a node to remove.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   262
     * @return The node removed from the map if a node with such a name exists.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   263
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   264
    /***/
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   265
    public Node removeNamedItem(String name)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   266
        throws DOMException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   267
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   268
        if (isReadOnly()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   269
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   270
            throw
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   271
                new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   272
                msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   273
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   274
        int i = findNamePoint(name,0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   275
        if (i < 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   276
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   277
            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   278
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   279
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   280
        NodeImpl n = (NodeImpl)nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   281
        nodes.remove(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   282
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   283
        return n;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   284
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   285
    } // removeNamedItem(String):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   286
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   287
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   288
     * Introduced in DOM Level 2. <p>
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   289
     * Removes a node specified by local name and namespace URI.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   290
     * @param namespaceURI
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   291
     *                      The namespace URI of the node to remove.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   292
     *                      When it is null or an empty string, this
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   293
     *                      method behaves like removeNamedItem.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   294
     * @param name          The local name of the node to remove.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   295
     * @return Node         The node removed from the map if a node with such
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   296
     *                      a local name and namespace URI exists.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   297
     * @throws              NOT_FOUND_ERR: Raised if there is no node named
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   298
     *                      name in the map.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   299
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   300
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   301
     public Node removeNamedItemNS(String namespaceURI, String name)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   302
        throws DOMException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   303
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   304
        if (isReadOnly()) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   305
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   306
            throw
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   307
                new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   308
                msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   309
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   310
        int i = findNamePoint(namespaceURI, name);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   311
        if (i < 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   312
            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   313
            throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   314
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   315
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   316
        NodeImpl n = (NodeImpl)nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   317
        nodes.remove(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   318
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   319
        return n;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   320
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   321
    } // removeNamedItem(String):Node
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   322
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   323
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   324
    // Public methods
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   325
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   326
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   327
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   328
     * Cloning a NamedNodeMap is a DEEP OPERATION; it always clones
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   329
     * all the nodes contained in the map.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   330
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   331
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   332
    public NamedNodeMapImpl cloneMap(NodeImpl ownerNode) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   333
        NamedNodeMapImpl newmap = new NamedNodeMapImpl(ownerNode);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   334
        newmap.cloneContent(this);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   335
        return newmap;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   336
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   337
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   338
    protected void cloneContent(NamedNodeMapImpl srcmap) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   339
        List srcnodes = srcmap.nodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   340
        if (srcnodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   341
            int size = srcnodes.size();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   342
            if (size != 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   343
                if (nodes == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   344
                    nodes = new ArrayList(size);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   345
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   346
                else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   347
                    nodes.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   348
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   349
                for (int i = 0; i < size; ++i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   350
                    NodeImpl n = (NodeImpl) srcmap.nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   351
                    NodeImpl clone = (NodeImpl) n.cloneNode(true);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   352
                    clone.isSpecified(n.isSpecified());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   353
                    nodes.add(clone);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   354
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   355
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   356
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   357
    } // cloneMap():NamedNodeMapImpl
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   358
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   359
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   360
    // Package methods
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   361
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   362
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   363
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   364
     * Internal subroutine to allow read-only Nodes to make their contained
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   365
     * NamedNodeMaps readonly too. I expect that in fact the shallow
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   366
     * version of this operation will never be
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   367
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   368
     * @param readOnly boolean true to make read-only, false to permit editing.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   369
     * @param deep boolean true to pass this request along to the contained
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   370
     * nodes, false to only toggle the NamedNodeMap itself. I expect that
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   371
     * the shallow version of this operation will never be used, but I want
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   372
     * to design it in now, while I'm thinking about it.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   373
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   374
    void setReadOnly(boolean readOnly, boolean deep) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   375
        isReadOnly(readOnly);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   376
        if (deep && nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   377
            for (int i = nodes.size() - 1; i >= 0; i--) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   378
                ((NodeImpl) nodes.get(i)).setReadOnly(readOnly,deep);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   379
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   380
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   381
    } // setReadOnly(boolean,boolean)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   382
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   383
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   384
     * Internal subroutine returns this NodeNameMap's (shallow) readOnly value.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   385
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   386
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   387
    boolean getReadOnly() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   388
        return isReadOnly();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   389
    } // getReadOnly()
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   390
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   391
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   392
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   393
    // Protected methods
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   394
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   395
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   396
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   397
     * NON-DOM
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   398
     * set the ownerDocument of this node, and the attributes it contains
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   399
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   400
    protected void setOwnerDocument(CoreDocumentImpl doc) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   401
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   402
            final int size = nodes.size();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   403
            for (int i = 0; i < size; ++i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   404
                ((NodeImpl)item(i)).setOwnerDocument(doc);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   405
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   406
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   407
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   408
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   409
    final boolean isReadOnly() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   410
        return (flags & READONLY) != 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   411
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   412
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   413
    final void isReadOnly(boolean value) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   414
        flags = (short) (value ? flags | READONLY : flags & ~READONLY);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   415
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   416
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   417
    final boolean changed() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   418
        return (flags & CHANGED) != 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   419
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   420
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   421
    final void changed(boolean value) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   422
        flags = (short) (value ? flags | CHANGED : flags & ~CHANGED);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   423
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   424
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   425
    final boolean hasDefaults() {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   426
        return (flags & HASDEFAULTS) != 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   427
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   428
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   429
    final void hasDefaults(boolean value) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   430
        flags = (short) (value ? flags | HASDEFAULTS : flags & ~HASDEFAULTS);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   431
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   432
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   433
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   434
    // Private methods
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   435
    //
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   436
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   437
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   438
     * Subroutine: Locate the named item, or the point at which said item
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   439
     * should be added.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   440
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   441
     * @param name Name of a node to look up.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   442
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   443
     * @return If positive or zero, the index of the found item.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   444
     * If negative, index of the appropriate point at which to insert
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   445
     * the item, encoded as -1-index and hence reconvertable by subtracting
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   446
     * it from -1. (Encoding because I don't want to recompare the strings
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   447
     * but don't want to burn bytes on a datatype to hold a flagged value.)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   448
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   449
    protected int findNamePoint(String name, int start) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   450
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   451
        // Binary search
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   452
        int i = 0;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   453
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   454
            int first = start;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   455
            int last  = nodes.size() - 1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   456
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   457
            while (first <= last) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   458
                i = (first + last) / 2;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   459
                int test = name.compareTo(((Node)(nodes.get(i))).getNodeName());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   460
                if (test == 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   461
                    return i; // Name found
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   462
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   463
                else if (test < 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   464
                    last = i - 1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   465
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   466
                else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   467
                    first = i + 1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   468
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   469
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   470
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   471
            if (first > i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   472
                i = first;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   473
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   474
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   475
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   476
        return -1 - i; // not-found has to be encoded.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   477
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   478
    } // findNamePoint(String):int
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   479
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   480
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   481
    /** This findNamePoint is for DOM Level 2 Namespaces.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   482
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   483
    protected int findNamePoint(String namespaceURI, String name) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   484
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   485
        if (nodes == null) return -1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   486
        if (name == null) return -1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   487
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   488
        // This is a linear search through the same nodes ArrayList.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   489
        // The ArrayList is sorted on the DOM Level 1 nodename.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   490
        // The DOM Level 2 NS keys are namespaceURI and Localname,
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   491
        // so we must linear search thru it.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   492
        // In addition, to get this to work with nodes without any namespace
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   493
        // (namespaceURI and localNames are both null) we then use the nodeName
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   494
        // as a secondary key.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   495
        final int size = nodes.size();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   496
        for (int i = 0; i < size; ++i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   497
            NodeImpl a = (NodeImpl)nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   498
            String aNamespaceURI = a.getNamespaceURI();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   499
            String aLocalName = a.getLocalName();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   500
            if (namespaceURI == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   501
              if (aNamespaceURI == null
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   502
                  &&
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   503
                  (name.equals(aLocalName)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   504
                   ||
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   505
                   (aLocalName == null && name.equals(a.getNodeName()))))
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   506
                return i;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   507
            } else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   508
              if (namespaceURI.equals(aNamespaceURI)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   509
                  &&
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   510
                  name.equals(aLocalName))
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   511
                return i;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   512
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   513
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   514
        return -1;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   515
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   516
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   517
    // compare 2 nodes in the map.  If a precedes b, return true, otherwise
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   518
    // return false
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   519
    protected boolean precedes(Node a, Node b) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   520
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   521
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   522
            final int size = nodes.size();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   523
            for (int i = 0; i < size; ++i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   524
                Node n = (Node)nodes.get(i);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   525
                if (n==a) return true;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   526
                if (n==b) return false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   527
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   528
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   529
        return false;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   530
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   531
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   532
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   533
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   534
      * NON-DOM: Remove attribute at specified index
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   535
      */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   536
    protected void removeItem(int index) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   537
       if (nodes != null && index < nodes.size()){
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   538
           nodes.remove(index);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   539
       }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   540
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   541
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   542
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   543
    protected Object getItem (int index){
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   544
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   545
            return nodes.get(index);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   546
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   547
        return null;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   548
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   549
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   550
    protected int addItem (Node arg) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   551
        int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   552
        if (i >= 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   553
            nodes.set(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   554
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   555
        else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   556
            // If we can't find by namespaceURI, localName, then we find by
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   557
            // nodeName so we know where to insert.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   558
            i = findNamePoint(arg.getNodeName(),0);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   559
            if (i >= 0) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   560
                nodes.add(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   561
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   562
            else {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   563
                i = -1 - i; // Insert point (may be end of list)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   564
                if (null == nodes) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   565
                    nodes = new ArrayList(5);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   566
                }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   567
                nodes.add(i, arg);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   568
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   569
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   570
        return i;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   571
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   572
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   573
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   574
     * NON-DOM: copy content of this map into the specified ArrayList
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   575
     *
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   576
     * @param list   ArrayList to copy information into.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   577
     * @return A copy of this node named map
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   578
     */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   579
    protected ArrayList cloneMap(ArrayList list) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   580
        if (list == null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   581
            list = new ArrayList(5);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   582
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   583
        list.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   584
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   585
            final int size = nodes.size();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   586
            for (int i = 0; i < size; ++i) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   587
                list.add(nodes.get(i));
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   588
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   589
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   590
        return list;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   591
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   592
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   593
     protected int getNamedItemIndex(String namespaceURI, String localName) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   594
        return findNamePoint(namespaceURI, localName);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   595
     }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   596
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   597
    /**
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   598
      * NON-DOM remove all elements from this map
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   599
      */
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   600
    public void removeAll (){
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   601
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   602
            nodes.clear();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   603
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   604
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   605
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   606
    private void readObject(ObjectInputStream in)
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   607
        throws IOException, ClassNotFoundException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   608
        in.defaultReadObject();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   609
        if (nodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   610
            nodes = new ArrayList(nodes);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   611
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   612
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   613
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   614
    private void writeObject(ObjectOutputStream out) throws IOException {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   615
        List oldNodes = this.nodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   616
        try {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   617
            if (oldNodes != null) {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   618
                this.nodes = new Vector(oldNodes);
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   619
            }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   620
            out.defaultWriteObject();
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   621
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   622
        // If the write fails for some reason ensure
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   623
        // that we restore the original object.
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   624
        finally {
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   625
            this.nodes = oldNodes;
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   626
        }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   627
    }
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   628
a754d69d5e60 7150324: Stop using drop bundles in jaxp
ohair
parents:
diff changeset
   629
} // class NamedNodeMapImpl