001: /*
002: Copyright (C) 2003 Together
003:
004: This library is free software; you can redistribute it and/or
005: modify it under the terms of the GNU Lesser General Public
006: License as published by the Free Software Foundation; either
007: version 2.1 of the License, or (at your option) any later version.
008:
009: This library is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: Lesser General Public License for more details.
013:
014: You should have received a copy of the GNU Lesser General Public
015: License along with this library; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package org.enhydra.xml;
020:
021: import org.w3c.dom.Attr;
022: import org.w3c.dom.DOMException;
023: import org.w3c.dom.Document;
024: import org.w3c.dom.Element;
025: import org.w3c.dom.NamedNodeMap;
026: import org.w3c.dom.Node;
027: import org.w3c.dom.NodeList;
028: import org.w3c.dom.TypeInfo;
029: import org.w3c.dom.UserDataHandler;
030:
031: /**
032: * @author Tweety
033: *
034: * A class representing a node in a meta-data tree, which implements
035: * the <a href="../../../../api/org/w3c/dom/Attr.html">
036: *
037: * <p> Namespaces are ignored in this implementation. The terms "tag
038: * name" and "node name" are always considered to be synonymous.
039: *
040: * @version 1.0
041: */
042: public class AttrImpl extends NodeImpl implements Attr {
043:
044: /**
045: * If this attribute was explicitly given a value in the original
046: * document, this is <code>true</code>; otherwise, it is
047: * <code>false</code>.
048: */
049: boolean specified = true;
050:
051: /**
052: * Document owner.
053: */
054: Element owner;
055:
056: /**
057: * Attribute name.
058: */
059: String name;
060:
061: /**
062: * Attribute value.
063: */
064: String value;
065:
066: /**
067: * Constructs an empty <code>AttrImpl</code>.
068: *
069: * @param owner document owner.
070: * @param name node name.
071: * @param value node value.
072: */
073: public AttrImpl(Element owner, String name, String value) {
074: this .owner = owner;
075: this .name = name;
076: this .value = value;
077: }
078:
079: /**
080: * Constructs a <code>AttrImpl</code> from the given node.
081: *
082: * @param attr , as a <code>AttrImpl</code>.
083: */
084: public AttrImpl(Attr attr) {
085: this .owner = attr.getOwnerElement();
086: this .name = attr.getName();
087: this .value = attr.getValue();
088: }
089:
090: /**
091: * Returns the attribute name associated with this node.
092: *
093: * @return the attribute name, as a <code>String</code>.
094: */
095: public String getName() {
096: return name;
097: }
098:
099: /**
100: * Returns the name associated with this node.
101: *
102: * @return the name, as a <code>String</code>.
103: */
104: public String getNodeName() {
105: return name;
106: }
107:
108: /**
109: * Returns the node type.
110: *
111: * @return the <code>ATTRIBUTE_NODE</code> node type.
112: */
113: public short getNodeType() {
114: return ATTRIBUTE_NODE;
115: }
116:
117: /**
118: * If this attribute was explicitly given a value in the original
119: * document, this is <code>true</code>; otherwise, it is
120: * <code>false</code>. Note that the implementation is in charge of this
121: * attribute, not the user. If the user changes the value of the
122: * attribute (even if it ends up having the same value as the default
123: * value) then the <code>specified</code> flag is automatically flipped
124: * to <code>true</code>. To re-specify the attribute as the default
125: * value from the DTD, the user must delete the attribute. The
126: * implementation will then make a new attribute available with
127: * <code>specified</code> set to <code>false</code> and the default
128: * value (if one exists).
129: * <br>In summary: If the attribute has an assigned value in the document
130: * then <code>specified</code> is <code>true</code>, and the value is
131: * the assigned value.If the attribute has no assigned value in the
132: * document and has a default value in the DTD, then
133: * <code>specified</code> is <code>false</code>, and the value is the
134: * default value in the DTD.If the attribute has no assigned value in
135: * the document and has a value of #IMPLIED in the DTD, then the
136: * attribute does not appear in the structure model of the document.If
137: * the <code>ownerElement</code> attribute is <code>null</code> (i.e.
138: * because it was just created or was set to <code>null</code> by the
139: * various removal and cloning operations) <code>specified</code> is
140: * <code>true</code>.
141: *
142: * @return always <code>true</code>.
143: */
144: public boolean getSpecified() {
145: return specified;
146: }
147:
148: /**
149: * Returns the value associated with this attributes.
150: *
151: * @return the node attributes, as a <code>String</code>.
152: */
153: public String getValue() {
154: return value;
155: }
156:
157: /**
158: * Returns the value associated with this node.
159: *
160: * @return the node value, as a <code>String</code>.
161: */
162: public String getNodeValue() {
163: return value;
164: }
165:
166: /**
167: * Sets the value of this attribute to the given one.
168: *
169: * @param value the new attribute value, as a <code>String</code>.
170: */
171: public void setValue(String value) {
172: this .value = value;
173: }
174:
175: /**
176: * Sets the value of this node to the given one.
177: *
178: * @param value is value of the node
179: */
180: public void setNodeValue(String value) {
181: this .value = value;
182: }
183:
184: /**
185: * Returns the owner of this attribute.
186: *
187: * @return the attribute owner node.
188: */
189: public Element getOwnerElement() {
190: return owner;
191: }
192:
193: /* METHODS FROM INTERFACE IN JDK1.5 */
194:
195: public TypeInfo getSchemaTypeInfo() {
196: // TODO Auto-generated method stub
197: return null;
198: }
199:
200: public boolean isId() {
201: // TODO Auto-generated method stub
202: return false;
203: }
204:
205: protected void initNodeImplChildren(Node node) {
206: // TODO Auto-generated method stub
207: super .initNodeImplChildren(node);
208: }
209:
210: protected Node newElementInstance(Node node) {
211: // TODO Auto-generated method stub
212: return super .newElementInstance(node);
213: }
214:
215: protected Node newTextInstance(Node node) {
216: // TODO Auto-generated method stub
217: return super .newTextInstance(node);
218: }
219:
220: protected Node newCommentInstance(Node node) {
221: // TODO Auto-generated method stub
222: return super .newCommentInstance(node);
223: }
224:
225: protected Node newDefaultInstance(Node node) {
226: // TODO Auto-generated method stub
227: return super .newDefaultInstance(node);
228: }
229:
230: protected void checkNode(Node node) throws DOMException {
231: // TODO Auto-generated method stub
232: super .checkNode(node);
233: }
234:
235: public Node getParentNode() {
236: // TODO Auto-generated method stub
237: return super .getParentNode();
238: }
239:
240: public NodeList getChildNodes() {
241: // TODO Auto-generated method stub
242: return super .getChildNodes();
243: }
244:
245: public Node getFirstChild() {
246: // TODO Auto-generated method stub
247: return super .getFirstChild();
248: }
249:
250: public Node getLastChild() {
251: // TODO Auto-generated method stub
252: return super .getLastChild();
253: }
254:
255: public Node getPreviousSibling() {
256: // TODO Auto-generated method stub
257: return super .getPreviousSibling();
258: }
259:
260: public Node getNextSibling() {
261: // TODO Auto-generated method stub
262: return super .getNextSibling();
263: }
264:
265: public Document getOwnerDocument() {
266: // TODO Auto-generated method stub
267: return super .getOwnerDocument();
268: }
269:
270: public Node insertBefore(Node newChild, Node refChild) {
271: // TODO Auto-generated method stub
272: return super .insertBefore(newChild, refChild);
273: }
274:
275: public Node replaceChild(Node newChild, Node oldChild) {
276: // TODO Auto-generated method stub
277: return super .replaceChild(newChild, oldChild);
278: }
279:
280: public Node removeChild(Node oldChild) {
281: // TODO Auto-generated method stub
282: return super .removeChild(oldChild);
283: }
284:
285: public Node appendChild(Node newChild) {
286: // TODO Auto-generated method stub
287: return super .appendChild(newChild);
288: }
289:
290: public boolean hasChildNodes() {
291: // TODO Auto-generated method stub
292: return super .hasChildNodes();
293: }
294:
295: public Node cloneNode(boolean deep) {
296: // TODO Auto-generated method stub
297: return super .cloneNode(deep);
298: }
299:
300: public void normalize() {
301: // TODO Auto-generated method stub
302: super .normalize();
303: }
304:
305: public boolean isSupported(String feature, String version) {
306: // TODO Auto-generated method stub
307: return super .isSupported(feature, version);
308: }
309:
310: public String getNamespaceURI() throws DOMException {
311: // TODO Auto-generated method stub
312: return super .getNamespaceURI();
313: }
314:
315: public String getPrefix() {
316: // TODO Auto-generated method stub
317: return super .getPrefix();
318: }
319:
320: public void setPrefix(String prefix) {
321: // TODO Auto-generated method stub
322: super .setPrefix(prefix);
323: }
324:
325: public String getLocalName() {
326: // TODO Auto-generated method stub
327: return super .getLocalName();
328: }
329:
330: public NamedNodeMap getAttributes() {
331: // TODO Auto-generated method stub
332: return super .getAttributes();
333: }
334:
335: public boolean hasAttributes() {
336: // TODO Auto-generated method stub
337: return super .hasAttributes();
338: }
339:
340: public int getLength() {
341: // TODO Auto-generated method stub
342: return super .getLength();
343: }
344:
345: public Node item(int index) {
346: // TODO Auto-generated method stub
347: return super .item(index);
348: }
349:
350: public String toString() {
351: // TODO Auto-generated method stub
352: return super .toString();
353: }
354:
355: public String toString(String tab) {
356: // TODO Auto-generated method stub
357: return super .toString(tab);
358: }
359:
360: protected void beginToString(StringBuffer sb, Indent indent) {
361: // TODO Auto-generated method stub
362: super .beginToString(sb, indent);
363: }
364:
365: protected void endToString(StringBuffer sb, Indent indent) {
366: // TODO Auto-generated method stub
367: super .endToString(sb, indent);
368: }
369:
370: public short compareDocumentPosition(Node other)
371: throws DOMException {
372: // TODO Auto-generated method stub
373: return super .compareDocumentPosition(other);
374: }
375:
376: public String getBaseURI() {
377: // TODO Auto-generated method stub
378: return super .getBaseURI();
379: }
380:
381: public Object getFeature(String feature, String version) {
382: // TODO Auto-generated method stub
383: return super .getFeature(feature, version);
384: }
385:
386: public String getTextContent() throws DOMException {
387: // TODO Auto-generated method stub
388: return super .getTextContent();
389: }
390:
391: public Object getUserData(String key) {
392: // TODO Auto-generated method stub
393: return super .getUserData(key);
394: }
395:
396: public boolean isDefaultNamespace(String namespaceURI) {
397: // TODO Auto-generated method stub
398: return super .isDefaultNamespace(namespaceURI);
399: }
400:
401: public boolean isEqualNode(Node arg) {
402: // TODO Auto-generated method stub
403: return super .isEqualNode(arg);
404: }
405:
406: public boolean isSameNode(Node other) {
407: // TODO Auto-generated method stub
408: return super .isSameNode(other);
409: }
410:
411: public String lookupNamespaceURI(String prefix) {
412: // TODO Auto-generated method stub
413: return super .lookupNamespaceURI(prefix);
414: }
415:
416: public String lookupPrefix(String namespaceURI) {
417: // TODO Auto-generated method stub
418: return super .lookupPrefix(namespaceURI);
419: }
420:
421: public void setTextContent(String textContent) throws DOMException {
422: // TODO Auto-generated method stub
423: super .setTextContent(textContent);
424: }
425:
426: public Object setUserData(String key, Object data,
427: UserDataHandler handler) {
428: // TODO Auto-generated method stub
429: return super.setUserData(key, data, handler);
430: }
431: }
|