1 /*
2 * @(#)HashMapNode.java 1.36 02/03/21
3 *
4 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
5 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6 */
7 package org.enhydra.xml;
8
9 import org.w3c.dom.Attr;
10 import org.w3c.dom.Element;
11
12
13 /***
14 * @author Tweety
15 *
16 * A class representing a node in a meta-data tree, which implements
17 * the <a href="../../../../api/org/w3c/dom/Attr.html">
18 *
19 * <p> Namespaces are ignored in this implementation. The terms "tag
20 * name" and "node name" are always considered to be synonymous.
21 *
22 * @version 1.0
23 */
24 public class AttrImpl extends NodeImpl implements Attr {
25
26 /***
27 * If this attribute was explicitly given a value in the original
28 * document, this is <code>true</code>; otherwise, it is
29 * <code>false</code>.
30 */
31 boolean specified = true;
32
33 /***
34 * Document owner.
35 */
36 Element owner;
37
38 /***
39 * Attribute name.
40 */
41 String name;
42
43 /***
44 * Attribute value.
45 */
46 String value;
47
48
49
50 /***
51 * Constructs an empty <code>AttrImpl</code>.
52 *
53 * @param owner document owner.
54 * @param name node name.
55 * @param value node value.
56 */
57 public AttrImpl(Element owner, String name, String value) {
58 this.owner = owner;
59 this.name = name;
60 this.value = value;
61 }
62
63 /***
64 * Constructs a <code>AttrImpl</code> from the given node.
65 *
66 * @param node, as a <code>AttrImpl</code>.
67 */
68 public AttrImpl(Attr attr) {
69 this.owner = attr.getOwnerElement();
70 this.name = attr.getName();
71 this.value = attr.getValue();
72 }
73
74 /***
75 * Returns the attribute name associated with this node.
76 *
77 * @return the attribute name, as a <code>String</code>.
78 */
79 public String getName() {
80 return name;
81 }
82
83 /***
84 * Returns the name associated with this node.
85 *
86 * @return the name, as a <code>String</code>.
87 */
88 public String getNodeName() {
89 return name;
90 }
91
92 /***
93 * Returns the node type.
94 *
95 * @return the <code>ATTRIBUTE_NODE</code> node type.
96 */
97 public short getNodeType() {
98 return ATTRIBUTE_NODE;
99 }
100
101
102 /***
103 * If this attribute was explicitly given a value in the original
104 * document, this is <code>true</code>; otherwise, it is
105 * <code>false</code>. Note that the implementation is in charge of this
106 * attribute, not the user. If the user changes the value of the
107 * attribute (even if it ends up having the same value as the default
108 * value) then the <code>specified</code> flag is automatically flipped
109 * to <code>true</code>. To re-specify the attribute as the default
110 * value from the DTD, the user must delete the attribute. The
111 * implementation will then make a new attribute available with
112 * <code>specified</code> set to <code>false</code> and the default
113 * value (if one exists).
114 * <br>In summary: If the attribute has an assigned value in the document
115 * then <code>specified</code> is <code>true</code>, and the value is
116 * the assigned value.If the attribute has no assigned value in the
117 * document and has a default value in the DTD, then
118 * <code>specified</code> is <code>false</code>, and the value is the
119 * default value in the DTD.If the attribute has no assigned value in
120 * the document and has a value of #IMPLIED in the DTD, then the
121 * attribute does not appear in the structure model of the document.If
122 * the <code>ownerElement</code> attribute is <code>null</code> (i.e.
123 * because it was just created or was set to <code>null</code> by the
124 * various removal and cloning operations) <code>specified</code> is
125 * <code>true</code>.
126 *
127 * Retuns always <code>true</code>.
128 */
129 public boolean getSpecified() {
130 return specified;
131 }
132
133 /***
134 * Returns the value associated with this attributes.
135 *
136 * @return the node attributes, as a <code>String</code>.
137 */
138 public String getValue() {
139 return value;
140 }
141
142 /***
143 * Returns the value associated with this node.
144 *
145 * @return the node value, as a <code>String</code>.
146 */
147 public String getNodeValue() {
148 return value;
149 }
150
151 /***
152 * Sets the value of this attribute to the given one.
153 *
154 * @param value the new attribute value, as a <code>String</code>.
155 */
156 public void setValue(String value) {
157 this.value = value;
158 }
159
160 /***
161 * Sets the value of this node to the given one.
162 *
163 * @return the node value, as a <code>String</code>.
164 */
165 public void setNodeValue(String value) {
166 this.value = value;
167 }
168
169 /***
170 * Returns the owner of this attribute.
171 *
172 * @return the attribute owner node.
173 */
174 public Element getOwnerElement() {
175 return owner;
176 }
177 }
This page automatically generated by Maven