~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xerces-2_9_1/src/org/apache/xerces/dom/DeferredDocumentTypeImpl.java

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
 
 
18
package org.apache.xerces.dom;
 
19
 
 
20
import org.w3c.dom.Node;
 
21
 
 
22
/**
 
23
 * This class represents a Document Type <em>declaraction</em> in
 
24
 * the document itself, <em>not</em> a Document Type Definition (DTD).
 
25
 * An XML document may (or may not) have such a reference.
 
26
 * <P>
 
27
 * DocumentType is an Extended DOM feature, used in XML documents but
 
28
 * not in HTML.
 
29
 * <P>
 
30
 * Note that Entities and Notations are no longer children of the
 
31
 * DocumentType, but are parentless nodes hung only in their
 
32
 * appropriate NamedNodeMaps.
 
33
 * <P>
 
34
 * This area is UNDERSPECIFIED IN REC-DOM-Level-1-19981001
 
35
 * Most notably, absolutely no provision was made for storing
 
36
 * and using Element and Attribute information. Nor was the linkage
 
37
 * between Entities and Entity References nailed down solidly.
 
38
 * 
 
39
 * @xerces.internal 
 
40
 *
 
41
 * @version $Id: DeferredDocumentTypeImpl.java,v 1.2 2009/12/10 03:18:32 matthewoliver Exp $
 
42
 * @since  PR-DOM-Level-1-19980818.
 
43
 */
 
44
public class DeferredDocumentTypeImpl
 
45
    extends DocumentTypeImpl
 
46
    implements DeferredNode {
 
47
 
 
48
    //
 
49
    // Constants
 
50
    //
 
51
 
 
52
    /** Serialization version. */
 
53
    static final long serialVersionUID = -2172579663227313509L;
 
54
 
 
55
    //
 
56
    // Data
 
57
    //
 
58
 
 
59
    /** Node index. */
 
60
    protected transient int fNodeIndex;
 
61
 
 
62
    //
 
63
    // Constructors
 
64
    //
 
65
 
 
66
    /**
 
67
     * This is the deferred constructor. Only the fNodeIndex is given here.
 
68
     * All other data, can be requested from the ownerDocument via the index.
 
69
     */
 
70
    DeferredDocumentTypeImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
 
71
        super(ownerDocument, null);
 
72
 
 
73
        fNodeIndex = nodeIndex;
 
74
        needsSyncData(true);
 
75
        needsSyncChildren(true);
 
76
 
 
77
    } // <init>(DeferredDocumentImpl,int)
 
78
 
 
79
    //
 
80
    // DeferredNode methods
 
81
    //
 
82
 
 
83
    /** Returns the node index. */
 
84
    public int getNodeIndex() {
 
85
        return fNodeIndex;
 
86
    }
 
87
 
 
88
    //
 
89
    // Protected methods
 
90
    //
 
91
 
 
92
    /** Synchronizes the data (name and value) for fast nodes. */
 
93
    protected void synchronizeData() {
 
94
 
 
95
        // no need to sync in the future
 
96
        needsSyncData(false);
 
97
 
 
98
        // fluff data
 
99
        DeferredDocumentImpl ownerDocument =
 
100
            (DeferredDocumentImpl)this.ownerDocument;
 
101
        name = ownerDocument.getNodeName(fNodeIndex);
 
102
 
 
103
        // public and system ids
 
104
        publicID = ownerDocument.getNodeValue(fNodeIndex);
 
105
        systemID = ownerDocument.getNodeURI(fNodeIndex);
 
106
        int extraDataIndex = ownerDocument.getNodeExtra(fNodeIndex);
 
107
        internalSubset = ownerDocument.getNodeValue(extraDataIndex);
 
108
    } // synchronizeData()
 
109
 
 
110
    /** Synchronizes the entities, notations, and elements. */
 
111
    protected void synchronizeChildren() {
 
112
        
 
113
        // we don't want to generate any event for this so turn them off
 
114
        boolean orig = ownerDocument().getMutationEvents();
 
115
        ownerDocument().setMutationEvents(false);
 
116
 
 
117
        // no need to synchronize again
 
118
        needsSyncChildren(false);
 
119
 
 
120
        // create new node maps
 
121
        DeferredDocumentImpl ownerDocument =
 
122
            (DeferredDocumentImpl)this.ownerDocument;
 
123
 
 
124
        entities  = new NamedNodeMapImpl(this);
 
125
        notations = new NamedNodeMapImpl(this);
 
126
        elements  = new NamedNodeMapImpl(this);
 
127
 
 
128
        // fill node maps
 
129
        DeferredNode last = null;
 
130
        for (int index = ownerDocument.getLastChild(fNodeIndex);
 
131
            index != -1;
 
132
            index = ownerDocument.getPrevSibling(index)) {
 
133
 
 
134
            DeferredNode node = ownerDocument.getNodeObject(index);
 
135
            int type = node.getNodeType();
 
136
            switch (type) {
 
137
 
 
138
                // internal, external, and unparsed entities
 
139
                case Node.ENTITY_NODE: {
 
140
                    entities.setNamedItem(node);
 
141
                    break;
 
142
                }
 
143
 
 
144
                // notations
 
145
                case Node.NOTATION_NODE: {
 
146
                    notations.setNamedItem(node);
 
147
                    break;
 
148
                }
 
149
 
 
150
                // element definitions
 
151
                case NodeImpl.ELEMENT_DEFINITION_NODE: {
 
152
                    elements.setNamedItem(node);
 
153
                    break;
 
154
                }
 
155
 
 
156
                // elements
 
157
                case Node.ELEMENT_NODE: {
 
158
                    if (((DocumentImpl)getOwnerDocument()).allowGrammarAccess){
 
159
                        insertBefore(node, last);
 
160
                        last = node;
 
161
                        break;
 
162
                    }
 
163
                }
 
164
 
 
165
                // NOTE: Should never get here! -Ac
 
166
                default: {
 
167
                    System.out.println("DeferredDocumentTypeImpl" +
 
168
                                       "#synchronizeInfo: " +
 
169
                                       "node.getNodeType() = " +
 
170
                                       node.getNodeType() +
 
171
                                       ", class = " +
 
172
                                       node.getClass().getName());
 
173
                }
 
174
             }
 
175
        }
 
176
 
 
177
        // set mutation events flag back to its original value
 
178
        ownerDocument().setMutationEvents(orig);
 
179
 
 
180
        // set entities and notations read_only per DOM spec
 
181
        setReadOnly(true, false);
 
182
 
 
183
    } // synchronizeChildren()
 
184
 
 
185
} // class DeferredDocumentTypeImpl