~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/DeferredAttrImpl.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
/*
 
19
 * WARNING: because java doesn't support multi-inheritance some code is
 
20
 * duplicated. If you're changing this file you probably want to change
 
21
 * DeferredAttrNSImpl.java at the same time.
 
22
 */
 
23
 
 
24
package org.apache.xerces.dom;
 
25
 
 
26
/**
 
27
 * Attribute represents an XML-style attribute of an
 
28
 * Element. Typically, the allowable values are controlled by its
 
29
 * declaration in the Document Type Definition (DTD) governing this
 
30
 * kind of document.
 
31
 * <P>
 
32
 * If the attribute has not been explicitly assigned a value, but has
 
33
 * been declared in the DTD, it will exist and have that default. Only
 
34
 * if neither the document nor the DTD specifies a value will the
 
35
 * Attribute really be considered absent and have no value; in that
 
36
 * case, querying the attribute will return null.
 
37
 * <P>
 
38
 * Attributes may have multiple children that contain their data. (XML
 
39
 * allows attributes to contain entity references, and tokenized
 
40
 * attribute types such as NMTOKENS may have a child for each token.)
 
41
 * For convenience, the Attribute object's getValue() method returns
 
42
 * the string version of the attribute's value.
 
43
 * <P>
 
44
 * Attributes are not children of the Elements they belong to, in the
 
45
 * usual sense, and have no valid Parent reference. However, the spec
 
46
 * says they _do_ belong to a specific Element, and an INUSE exception
 
47
 * is to be thrown if the user attempts to explicitly share them
 
48
 * between elements.
 
49
 * <P>
 
50
 * Note that Elements do not permit attributes to appear to be shared
 
51
 * (see the INUSE exception), so this object's mutability is
 
52
 * officially not an issue.
 
53
 * <P>
 
54
 * DeferredAttrImpl inherits from AttrImpl which does not support
 
55
 * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does.
 
56
 * @see DeferredAttrNSImpl
 
57
 *
 
58
 * @xerces.internal 
 
59
 *
 
60
 * @author Andy Clark, IBM
 
61
 * @author Arnaud  Le Hors, IBM
 
62
 * @version $Id: DeferredAttrImpl.java,v 1.2 2009/12/10 03:18:32 matthewoliver Exp $
 
63
 * @since  PR-DOM-Level-1-19980818.
 
64
 */
 
65
public final class DeferredAttrImpl
 
66
    extends AttrImpl
 
67
    implements DeferredNode {
 
68
 
 
69
    //
 
70
    // Constants
 
71
    //
 
72
 
 
73
    /** Serialization version. */
 
74
    static final long serialVersionUID = 6903232312469148636L;
 
75
 
 
76
    //
 
77
    // Data
 
78
    //
 
79
 
 
80
    /** Node index. */
 
81
    protected transient int fNodeIndex;
 
82
 
 
83
    //
 
84
    // Constructors
 
85
    //
 
86
 
 
87
    /**
 
88
     * This is the deferred constructor. Only the fNodeIndex is given here.
 
89
     * All other data, can be requested from the ownerDocument via the index.
 
90
     */
 
91
    DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
 
92
        super(ownerDocument, null);
 
93
 
 
94
        fNodeIndex = nodeIndex;
 
95
        needsSyncData(true);
 
96
        needsSyncChildren(true);
 
97
 
 
98
    } // <init>(DeferredDocumentImpl,int)
 
99
 
 
100
    //
 
101
    // DeferredNode methods
 
102
    //
 
103
 
 
104
    /** Returns the node index. */
 
105
    public int getNodeIndex() {
 
106
        return fNodeIndex;
 
107
    }
 
108
 
 
109
    //
 
110
    // Protected methods
 
111
    //
 
112
 
 
113
    /** Synchronizes the data (name and value) for fast nodes. */
 
114
    protected void synchronizeData() {
 
115
 
 
116
        // no need to sync in the future
 
117
        needsSyncData(false);
 
118
 
 
119
        // fluff data
 
120
        DeferredDocumentImpl ownerDocument =
 
121
            (DeferredDocumentImpl) ownerDocument();
 
122
        name = ownerDocument.getNodeName(fNodeIndex);
 
123
        int extra = ownerDocument.getNodeExtra(fNodeIndex);
 
124
        isSpecified((extra & SPECIFIED) != 0);
 
125
        isIdAttribute((extra & ID) != 0);
 
126
 
 
127
        int extraNode = ownerDocument.getLastChild(fNodeIndex);
 
128
        type = ownerDocument.getTypeInfo(extraNode);        
 
129
    } // synchronizeData()
 
130
 
 
131
    /**
 
132
     * Synchronizes the node's children with the internal structure.
 
133
     * Fluffing the children at once solves a lot of work to keep
 
134
     * the two structures in sync. The problem gets worse when
 
135
     * editing the tree -- this makes it a lot easier.
 
136
     */
 
137
    protected void synchronizeChildren() {
 
138
        DeferredDocumentImpl ownerDocument =
 
139
            (DeferredDocumentImpl) ownerDocument();
 
140
        ownerDocument.synchronizeChildren(this, fNodeIndex);
 
141
    } // synchronizeChildren()
 
142
 
 
143
} // class DeferredAttrImpl