1 /*
2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 package com.teamkonzept.dom4jb.dom;
19
20 import org.w3c.dom.Attr;
21 import org.w3c.dom.Element;
22
23 import com.teamkonzept.dom4jb.schema.AttributeDescriptor;
24
25 public class Attribute extends NamedNode implements Attr {
26
27 private final AttributeDescriptor descriptor;
28 private final Object bean;
29 private String value;
30 private boolean isInitialized;
31
32 /*** Creates new Attribute */
33 public Attribute(
34 final Document document,
35 final AttributeDescriptor descriptor,
36 final Object bean) {
37 super(document, descriptor.getName());
38 this.descriptor = descriptor;
39 this.bean = bean;
40 this.isInitialized = false;
41 }
42
43 public int getChildIndex() {
44 return -1;
45 }
46
47 /***
48 * A code representing the type of the Attribute
49 * @return <code>Node.ATTRIBUTE_NODE</code>
50 */
51 public final short getNodeType() {
52 return ATTRIBUTE_NODE;
53 }
54
55 /***
56 * If this attribute was explicitly given a value in the original
57 * document, this is <code>true</code>; otherwise, it is
58 * <code>false</code>. Note that the implementation is in charge of this
59 * attribute, not the user. If the user changes the value of the
60 * attribute (even if it ends up having the same value as the default
61 * value) then the <code>specified</code> flag is automatically flipped
62 * to <code>true</code>. To re-specify the attribute as the default
63 * value from the DTD, the user must delete the attribute. The
64 * implementation will then make a new attribute available with
65 * <code>specified</code> set to <code>false</code> and the default
66 * value (if one exists).
67 * <br>In summary: If the attribute has an assigned value in the document
68 * then <code>specified</code> is <code>true</code>, and the value is
69 * the assigned value.If the attribute has no assigned value in the
70 * document and has a default value in the DTD, then
71 * <code>specified</code> is <code>false</code>, and the value is the
72 * default value in the DTD.If the attribute has no assigned value in
73 * the document and has a value of #IMPLIED in the DTD, then the
74 * attribute does not appear in the structure model of the document.If
75 * the <code>ownerElement</code> attribute is <code>null</code> (i.e.
76 * because it was just created or was set to <code>null</code> by the
77 * various removal and cloning operations) <code>specified</code> is
78 * <code>true</code>.
79 */
80 public boolean getSpecified() {
81 // TODO - default-werte zulassen
82 return true;
83 }
84
85 /***
86 * Returns the name of this attribute.
87 */
88 public String getName() {
89 return getNodeName();
90 }
91
92 /***
93 * The <code>Element</code> node this attribute is attached to or
94 * <code>null</code> if this attribute is not in use.
95 * @since DOM Level 2
96 */
97 public Element getOwnerElement() {
98 return (Element) super.getParentNode();
99 }
100
101 /***
102 * On retrieval, the value of the attribute is returned as a string.
103 * Character and general entity references are replaced with their
104 * values. See also the method <code>getAttribute</code> on the
105 * <code>Element</code> interface.
106 * <br>On setting, this creates a <code>Text</code> node with the unparsed
107 * contents of the string. I.e. any characters that an XML processor
108 * would recognize as markup are instead treated as literal text. See
109 * also the method <code>setAttribute</code> on the <code>Element</code>
110 * interface.
111 */
112 public void setValue(final String value) {
113 throw new UnsupportedOperationException(
114 "Method setValue(String) not yet implemented.");
115 }
116
117 /***
118 * On retrieval, the value of the attribute is returned as a string.
119 * Character and general entity references are replaced with their
120 * values. See also the method <code>getAttribute</code> on the
121 * <code>Element</code> interface.
122 * <br>On setting, this creates a <code>Text</code> node with the unparsed
123 * contents of the string. I.e. any characters that an XML processor
124 * would recognize as markup are instead treated as literal text. See
125 * also the method <code>setAttribute</code> on the <code>Element</code>
126 * interface.
127 */
128 public String getValue() {
129 if (!isInitialized) {
130 value = descriptor.getValue(bean);
131 isInitialized = true;
132 }
133 return value;
134 }
135
136 /***
137 * The value of this node, depending on its type; see the table above.
138 * When it is defined to be <code>null</code>, setting it has no effect.
139 */
140 public String getNodeValue() {
141 return getValue();
142 }
143
144 /***
145 * The parent of this node. <code>Attr</code> may have not a parent.
146 */
147 public org.w3c.dom.Node getParentNode() {
148 return null;
149 }
150
151 /***
152 * @see com.teamkonzept.dom4jb.dom.Node#accept(Filter)
153 */
154 public boolean accept(final Filter filter) {
155 return filter.match((Attribute) this);
156 }
157 }
This page was automatically generated by Maven