KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > 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.xml;
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 java.io.IOException JavaDoc;
37
38 public class QAttr extends QNode implements Attr JavaDoc {
39   QName _name;
40   private String JavaDoc _value;
41   private boolean _specified = true;
42
43   public QAttr(String JavaDoc name)
44   {
45     _name = new QName(name);
46   }
47
48   public QAttr(QName name)
49   {
50     _name = name;
51   }
52
53   protected QAttr(QName name, String JavaDoc value)
54   {
55     _name = name;
56     _value = value;
57   }
58
59   protected QAttr(QDocument owner, QName name)
60   {
61     super(owner);
62
63     _name = name;
64   }
65
66   public Element JavaDoc getOwnerElement()
67   {
68     return (Element JavaDoc) getParentNode();
69   }
70
71   public short getNodeType()
72   {
73     return ATTRIBUTE_NODE;
74   }
75
76   /**
77    * Returns the full QName.
78    */

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