KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > dom > DeferredAttrImpl


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 /*
18  * WARNING: because java doesn't support multi-inheritance some code is
19  * duplicated. If you're changing this file you probably want to change
20  * DeferredAttrNSImpl.java at the same time.
21  */

22
23 package org.apache.xerces.dom;
24
25 /**
26  * Attribute represents an XML-style attribute of an
27  * Element. Typically, the allowable values are controlled by its
28  * declaration in the Document Type Definition (DTD) governing this
29  * kind of document.
30  * <P>
31  * If the attribute has not been explicitly assigned a value, but has
32  * been declared in the DTD, it will exist and have that default. Only
33  * if neither the document nor the DTD specifies a value will the
34  * Attribute really be considered absent and have no value; in that
35  * case, querying the attribute will return null.
36  * <P>
37  * Attributes may have multiple children that contain their data. (XML
38  * allows attributes to contain entity references, and tokenized
39  * attribute types such as NMTOKENS may have a child for each token.)
40  * For convenience, the Attribute object's getValue() method returns
41  * the string version of the attribute's value.
42  * <P>
43  * Attributes are not children of the Elements they belong to, in the
44  * usual sense, and have no valid Parent reference. However, the spec
45  * says they _do_ belong to a specific Element, and an INUSE exception
46  * is to be thrown if the user attempts to explicitly share them
47  * between elements.
48  * <P>
49  * Note that Elements do not permit attributes to appear to be shared
50  * (see the INUSE exception), so this object's mutability is
51  * officially not an issue.
52  * <P>
53  * DeferredAttrImpl inherits from AttrImpl which does not support
54  * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does.
55  * @see DeferredAttrNSImpl
56  *
57  * @xerces.internal
58  *
59  * @author Andy Clark, IBM
60  * @author Arnaud Le Hors, IBM
61  * @version $Id: DeferredAttrImpl.java,v 1.21 2004/10/05 17:12:51 mrglavas Exp $
62  * @since PR-DOM-Level-1-19980818.
63  */

64 public final class DeferredAttrImpl
65     extends AttrImpl
66     implements DeferredNode {
67
68     //
69
// Constants
70
//
71

72     /** Serialization version. */
73     static final long serialVersionUID = 6903232312469148636L;
74
75     //
76
// Data
77
//
78

79     /** Node index. */
80     protected transient int fNodeIndex;
81
82     //
83
// Constructors
84
//
85

86     /**
87      * This is the deferred constructor. Only the fNodeIndex is given here.
88      * All other data, can be requested from the ownerDocument via the index.
89      */

90     DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
91         super(ownerDocument, null);
92
93         fNodeIndex = nodeIndex;
94         needsSyncData(true);
95         needsSyncChildren(true);
96
97     } // <init>(DeferredDocumentImpl,int)
98

99     //
100
// DeferredNode methods
101
//
102

103     /** Returns the node index. */
104     public int getNodeIndex() {
105         return fNodeIndex;
106     }
107
108     //
109
// Protected methods
110
//
111

112     /** Synchronizes the data (name and value) for fast nodes. */
113     protected void synchronizeData() {
114
115         // no need to sync in the future
116
needsSyncData(false);
117
118         // fluff data
119
DeferredDocumentImpl ownerDocument =
120             (DeferredDocumentImpl) ownerDocument();
121         name = ownerDocument.getNodeName(fNodeIndex);
122         int extra = ownerDocument.getNodeExtra(fNodeIndex);
123         isSpecified((extra & SPECIFIED) != 0);
124         isIdAttribute((extra & ID) != 0);
125
126         int extraNode = ownerDocument.getLastChild(fNodeIndex);
127         type = ownerDocument.getTypeInfo(extraNode);
128     } // synchronizeData()
129

130     /**
131      * Synchronizes the node's children with the internal structure.
132      * Fluffing the children at once solves a lot of work to keep
133      * the two structures in sync. The problem gets worse when
134      * editing the tree -- this makes it a lot easier.
135      */

136     protected void synchronizeChildren() {
137         DeferredDocumentImpl ownerDocument =
138             (DeferredDocumentImpl) ownerDocument();
139         ownerDocument.synchronizeChildren(this, fNodeIndex);
140     } // synchronizeChildren()
141

142 } // class DeferredAttrImpl
143
Popular Tags