KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > kawa > xml > KElement


1 // Copyright (c) 2004 Per M.A. Bothner.
2
// This is free software; for terms and warranty disclaimer see ./COPYING.
3

4 package gnu.kawa.xml;
5 import gnu.xml.*;
6 /* #ifdef use:org.w3c.dom.Node */
7 // import org.w3c.dom.*;
8
/* #endif */
9
10 public class KElement extends KNode
11   /* #ifdef use:org.w3c.dom.Node */
12   // implements org.w3c.dom.Element
13
/* #endif */
14 {
15   public KElement (NodeTree seq, int ipos)
16   {
17     super(seq, ipos);
18   }
19   
20   /* #ifdef use:org.w3c.dom.Node */
21   // public short getNodeType () { return Node.ELEMENT_NODE; }
22
/* #endif */
23
24   public String JavaDoc getTagName ()
25   {
26     return sequence.getNextTypeName(ipos);
27   }
28
29   public String JavaDoc getNodeValue()
30   {
31     return null;
32   }
33
34   public boolean hasAttributes ()
35   {
36     return ((NodeTree) sequence).posHasAttributes(ipos);
37   }
38
39   public String JavaDoc getAttribute (String JavaDoc name)
40   {
41     if (name == null)
42       name = "";
43     NodeTree nodes = (NodeTree) sequence;
44     int attr = nodes.getAttribute(ipos, null, name);
45     if (attr == 0)
46       return "";
47     else
48       return KNode.getNodeValue(nodes, attr);
49   }
50
51   /* #ifdef use:org.w3c.dom.Node */
52   // /** Not implemented. */
53
// public void setAttribute (String name, String value)
54
// throws DOMException
55
// {
56
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
57
// "setAttribute not supported");
58
// }
59

60   // /** Not implemented. */
61
// public void setIdAttribute (String name, boolean isId)
62
// throws DOMException
63
// {
64
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
65
// "setIdAttribute not supported");
66
// }
67

68   // /** Not implemented. */
69
// public void setIdAttributeNS (String namespaceURI, String localName,
70
// boolean isId)
71
// throws DOMException
72
// {
73
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
74
// "setIdAttributeNS not supported");
75
// }
76

77   // /** Not implemented. */
78
// public void setIdAttributeNode (Attr idAttr, boolean isId)
79
// throws DOMException
80
// {
81
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
82
// "setIdAttributeNode not supported");
83
// }
84

85   // /** Not implemented. */
86
// public void removeAttribute (String name)
87
// throws DOMException
88
// {
89
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
90
// "removeAttribute not supported");
91
// }
92
/* #endif */
93
94   /* #ifdef JAVA5 */
95   // public KAttr
96
/* #else */
97   /* #ifdef use:org.w3c.dom.Node */
98   // public Attr
99
/* #else */
100   public KAttr
101   /* #endif */
102   /* #endif */
103   getAttributeNode (String JavaDoc name)
104   {
105     if (name == null)
106       name = "";
107     NodeTree nodes = (NodeTree) sequence;
108     int attr = nodes.getAttribute(ipos, null, name);
109     if (attr == 0)
110       return null;
111     else
112       return new KAttr(nodes, attr);
113   }
114
115   /* #ifdef use:org.w3c.dom.Node */
116   // /** Not implemented. */
117
// public Attr setAttributeNode (Attr newAttr)
118
// throws DOMException
119
// {
120
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
121
// "setAttributeNode not supported");
122
// }
123

124   // /** Not implemented. */
125
// public Attr removeAttributeNode (Attr oldAttr)
126
// throws DOMException
127
// {
128
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
129
// "removeAttributeNode not supported");
130
// }
131
/* #endif */
132
133   public String JavaDoc getAttributeNS (String JavaDoc namespaceURI, String JavaDoc localName)
134   {
135     if (namespaceURI == null)
136       namespaceURI = "";
137     if (localName == null)
138       localName = "";
139     NodeTree nodes = (NodeTree) sequence;
140     int attr = nodes.getAttribute(ipos, namespaceURI, localName);
141     if (attr == 0)
142       return "";
143     else
144       return getNodeValue(nodes, attr);
145   }
146
147   /* #ifdef use:org.w3c.dom.Node */
148   // /** Not implemented. */
149
// public void setAttributeNS (String namespaceURI, String qualifiedName,
150
// String value) throws DOMException
151
// {
152
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
153
// "setAttributeNS not supported");
154
// }
155
/* #endif */
156
157   /* #ifdef use:org.w3c.dom.Node */
158   // /** Not implemented. */
159
// public void removeAttributeNS (String namespaceURI, String localName)
160
// throws DOMException
161
// {
162
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
163
// "removeAttributeNS not supported");
164
// }
165
/* #endif */
166  
167   /* #ifdef JAVA5 */
168   // public KAttr
169
/* #else */
170   /* #ifdef use:org.w3c.dom.Node */
171   // public Attr
172
/* #else */
173   public KAttr
174   /* #endif */
175   /* #endif */
176   getAttributeNodeNS(String JavaDoc namespaceURI, String JavaDoc localName)
177   {
178     if (namespaceURI == null)
179       namespaceURI = "";
180     if (localName == null)
181       localName = "";
182     NodeTree nodes = (NodeTree) sequence;
183     int attr = nodes.getAttribute(ipos, namespaceURI, localName);
184     if (attr == 0)
185       return null;
186     else
187       return new KAttr(nodes, attr);
188   }
189
190   /** Not implemented. */
191   /* #ifdef use:org.w3c.dom.Node */
192   // public Attr setAttributeNodeNS (Attr newAttr)
193
// throws DOMException
194
// {
195
// throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
196
// "setAttributeNodeNS not supported");
197
// }
198
/* #endif */
199
200   // Not implemented yet.
201
/* #ifdef use:org.w3c.dom.Node */
202   // public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
203
// {
204
// throw new UnsupportedOperationException("getElementsByTagNameNS not implemented yet");
205
// }
206
/* #endif */
207
208   /** Not implemented yet. */
209   public boolean hasAttribute (String JavaDoc name)
210   {
211     int attr = ((NodeTree) sequence).getAttribute(ipos, null, name == null ? "" : name);
212     return attr != 0;
213   }
214
215   public boolean hasAttributeNS (String JavaDoc namespaceURI, String JavaDoc localName)
216   {
217     if (namespaceURI == null)
218       namespaceURI = "";
219     if (localName == null)
220       localName = "";
221     int attr = ((NodeTree) sequence).getAttribute(ipos, namespaceURI, localName);
222     return attr != 0;
223   }
224
225   /* #ifdef JAXP-1.3 */
226   // public TypeInfo getSchemaTypeInfo ()
227
// {
228
// return null;
229
// }
230
/* #endif JAXP-1.3 */
231 }
232
Popular Tags