KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > dom > DeferredAttrImpl


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

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

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

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

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

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

139     //
140
// DeferredNode methods
141
//
142

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

152     /** Synchronizes the data (name and value) for fast nodes. */
153     protected void synchronizeData() {
154
155         // no need to sync in the future
156
needsSyncData(false);
157
158         // fluff data
159
DeferredDocumentImpl ownerDocument =
160             (DeferredDocumentImpl) ownerDocument();
161         name = ownerDocument.getNodeName(fNodeIndex);
162         int extra = ownerDocument.getNodeExtra(fNodeIndex);
163         isSpecified((extra & SPECIFIED) != 0);
164         isIdAttribute((extra & ID) != 0);
165
166         int extraNode = ownerDocument.getLastChild(fNodeIndex);
167         type = ownerDocument.getTypeInfo(extraNode);
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