KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml2 > QAttr


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.xml2;
30
31 import org.w3c.dom.Attr JavaDoc;
32 import org.w3c.dom.Element JavaDoc;
33 import org.w3c.dom.Node JavaDoc;
34 import org.w3c.dom.TypeInfo JavaDoc;
35
36 import javax.xml.namespace.QName JavaDoc;
37 import java.io.IOException JavaDoc;
38
39 public class QAttr extends QNode implements Attr JavaDoc {
40   QName JavaDoc _name;
41   private String JavaDoc _value;
42   private boolean _specified = true;
43
44   public QAttr(String JavaDoc name)
45   {
46     _name = new QName JavaDoc(name);
47   }
48
49   public QAttr(QName JavaDoc name)
50   {
51     _name = name;
52   }
53
54   protected QAttr(QName JavaDoc name, String JavaDoc value)
55   {
56     _name = name;
57     _value = value;
58   }
59
60   protected QAttr(QDocument owner, QName JavaDoc name)
61   {
62     super(owner);
63
64     _name = name;
65   }
66
67   public Element JavaDoc getOwnerElement()
68   {
69     return (Element JavaDoc) getParentNode();
70   }
71
72   public short getNodeType()
73   {
74     return ATTRIBUTE_NODE;
75   }
76
77   /**
78    * Returns the full QName.
79    */

80   public QName JavaDoc getQName()
81   {
82     return _name;
83   }
84
85   public String JavaDoc getNodeName()
86   {
87     return _name.getLocalPart();
88   }
89
90   public boolean isId()
91   {
92     return false;
93   }
94
95   public String JavaDoc getName()
96   {
97     return _name.getLocalPart(); // XXX:
98
}
99
100   public String JavaDoc getPrefix()
101   {
102     return _name.getPrefix();
103   }
104
105   public String JavaDoc getLocalName()
106   {
107     return _name.getLocalPart();
108   }
109
110   public String JavaDoc getCanonicalName()
111   {
112     //return _name.getCanonicalName();
113
return _name.toString(); // XXX:
114
}
115
116   public String JavaDoc getNamespaceURI()
117   {
118     return _name.getNamespaceURI();
119   }
120
121   public String JavaDoc getNodeValue()
122   {
123     return _value;
124   }
125
126   public TypeInfo JavaDoc getSchemaTypeInfo()
127   {
128     return null;
129   }
130
131   public void setNodeValue(String JavaDoc value)
132   {
133     _value = value;
134   }
135
136   public String JavaDoc getValue()
137   {
138     return _value;
139   }
140
141   public void setValue(String JavaDoc value)
142   {
143     _value = value;
144   }
145
146   public boolean getSpecified()
147   {
148     return _specified;
149   }
150   
151   public void setSpecified(boolean specified)
152   {
153     _specified = specified;
154   }
155
156   Node JavaDoc importNode(QDocument owner, boolean deep)
157   {
158     QNode node = new QAttr(_name, _value);
159     node._owner = owner;
160     return node;
161   }
162
163   public void print(XmlPrinter out) throws IOException JavaDoc
164   {
165     if (! _specified)
166       return;
167
168     out.attribute(getNamespaceURI(), getLocalName(),
169                   getNodeName(), getNodeValue());
170   }
171
172   private Object JavaDoc writeReplace()
173   {
174     return new SerializedXml(this);
175   }
176
177   public String JavaDoc toString()
178   {
179     if (_value != null)
180       return "Attr[" + _name + " " + _value + "]";
181     else
182       return "Attr[" + _name + "]";
183   }
184 }
185
Popular Tags