KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 /*
59  * WARNING: because java doesn't support multi-inheritance some code is
60  * duplicated. If you're changing this file you probably want to change
61  * DeferredAttrNSImpl.java at the same time.
62  */

63
64 package org.enhydra.apache.xerces.dom;
65
66 import org.enhydra.apache.xerces.utils.StringPool;
67
68 /**
69  * Attribute represents an XML-style attribute of an
70  * Element. Typically, the allowable values are controlled by its
71  * declaration in the Document Type Definition (DTD) governing this
72  * kind of document.
73  * <P>
74  * If the attribute has not been explicitly assigned a value, but has
75  * been declared in the DTD, it will exist and have that default. Only
76  * if neither the document nor the DTD specifies a value will the
77  * Attribute really be considered absent and have no value; in that
78  * case, querying the attribute will return null.
79  * <P>
80  * Attributes may have multiple children that contain their data. (XML
81  * allows attributes to contain entity references, and tokenized
82  * attribute types such as NMTOKENS may have a child for each token.)
83  * For convenience, the Attribute object's getValue() method returns
84  * the string version of the attribute's value.
85  * <P>
86  * Attributes are not children of the Elements they belong to, in the
87  * usual sense, and have no valid Parent reference. However, the spec
88  * says they _do_ belong to a specific Element, and an INUSE exception
89  * is to be thrown if the user attempts to explicitly share them
90  * between elements.
91  * <P>
92  * Note that Elements do not permit attributes to appear to be shared
93  * (see the INUSE exception), so this object's mutability is
94  * officially not an issue.
95  * <P>
96  * DeferredAttrImpl inherits from AttrImpl which does not support
97  * Namespaces. DeferredAttrNSImpl, which inherits from AttrNSImpl, does.
98  * @see DeferredAttrNSImpl
99  *
100  *
101  * @author Andy Clark, IBM
102  * @author Arnaud Le Hors, IBM
103  * @version
104  * @since PR-DOM-Level-1-19980818.
105  */

106 public final class DeferredAttrImpl
107     extends AttrImpl
108     implements DeferredNode {
109
110     //
111
// Constants
112
//
113

114     /** Serialization version. */
115     static final long serialVersionUID = 6903232312469148636L;
116
117     //
118
// Data
119
//
120

121     /** Node index. */
122     protected transient int fNodeIndex;
123
124     //
125
// Constructors
126
//
127

128     /**
129      * This is the deferred constructor. Only the fNodeIndex is given here.
130      * All other data, can be requested from the ownerDocument via the index.
131      */

132     DeferredAttrImpl(DeferredDocumentImpl ownerDocument, int nodeIndex) {
133         super(ownerDocument, null);
134
135         fNodeIndex = nodeIndex;
136         needsSyncData(true);
137         needsSyncChildren(true);
138
139     } // <init>(DeferredDocumentImpl,int)
140

141     //
142
// DeferredNode methods
143
//
144

145     /** Returns the node index. */
146     public int getNodeIndex() {
147         return fNodeIndex;
148     }
149
150     //
151
// Protected methods
152
//
153

154     /** Synchronizes the data (name and value) for fast nodes. */
155     protected void synchronizeData() {
156
157         // no need to sync in the future
158
needsSyncData(false);
159
160         // fluff data
161
DeferredDocumentImpl ownerDocument =
162             (DeferredDocumentImpl) ownerDocument();
163         int elementTypeName = ownerDocument.getNodeName(fNodeIndex);
164         StringPool pool = ownerDocument.getStringPool();
165         name = pool.toString(elementTypeName);
166         isSpecified(ownerDocument.getNodeValue(fNodeIndex) == 1);
167
168     } // synchronizeData()
169

170     /**
171      * Synchronizes the node's children with the internal structure.
172      * Fluffing the children at once solves a lot of work to keep
173      * the two structures in sync. The problem gets worse when
174      * editing the tree -- this makes it a lot easier.
175      */

176     protected void synchronizeChildren() {
177         DeferredDocumentImpl ownerDocument =
178             (DeferredDocumentImpl) ownerDocument();
179         ownerDocument.synchronizeChildren(this, fNodeIndex);
180     } // synchronizeChildren()
181

182 } // class DeferredAttrImpl
183
Popular Tags