KElement.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Copyright (c) 2004 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.kawa.xml;
  4. import gnu.xml.*;
  5. /* #ifdef use:org.w3c.dom.Node */
  6. import org.w3c.dom.*;
  7. /* #endif */
  8. public class KElement extends KNode
  9. /* #ifdef use:org.w3c.dom.Node */
  10. implements org.w3c.dom.Element
  11. /* #endif */
  12. {
  13. public KElement (NodeTree seq, int ipos)
  14. {
  15. super(seq, ipos);
  16. }
  17. /* #ifdef use:org.w3c.dom.Node */
  18. public short getNodeType () { return Node.ELEMENT_NODE; }
  19. /* #endif */
  20. public String getTagName ()
  21. {
  22. return sequence.getNextTypeName(ipos);
  23. }
  24. public String getNodeValue()
  25. {
  26. return null;
  27. }
  28. public boolean hasAttributes ()
  29. {
  30. return ((NodeTree) sequence).posHasAttributes(ipos);
  31. }
  32. public String getAttribute (String name)
  33. {
  34. if (name == null)
  35. name = "";
  36. NodeTree nodes = (NodeTree) sequence;
  37. int attr = nodes.getAttribute(ipos, null, name);
  38. if (attr == 0)
  39. return "";
  40. else
  41. return KNode.getNodeValue(nodes, attr);
  42. }
  43. /* #ifdef use:org.w3c.dom.Node */
  44. /** Not implemented. */
  45. public void setAttribute (String name, String value)
  46. throws DOMException
  47. {
  48. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  49. "setAttribute not supported");
  50. }
  51. /** Not implemented. */
  52. public void setIdAttribute (String name, boolean isId)
  53. throws DOMException
  54. {
  55. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  56. "setIdAttribute not supported");
  57. }
  58. /** Not implemented. */
  59. public void setIdAttributeNS (String namespaceURI, String localName,
  60. boolean isId)
  61. throws DOMException
  62. {
  63. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  64. "setIdAttributeNS not supported");
  65. }
  66. /** Not implemented. */
  67. public void setIdAttributeNode (Attr idAttr, boolean isId)
  68. throws DOMException
  69. {
  70. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  71. "setIdAttributeNode not supported");
  72. }
  73. /** Not implemented. */
  74. public void removeAttribute (String name)
  75. throws DOMException
  76. {
  77. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  78. "removeAttribute not supported");
  79. }
  80. /* #endif */
  81. /* #ifdef JAVA5 */
  82. public KAttr
  83. /* #else */
  84. /* #ifdef use:org.w3c.dom.Node */
  85. // public Attr
  86. /* #else */
  87. // public KAttr
  88. /* #endif */
  89. /* #endif */
  90. getAttributeNode (String name)
  91. {
  92. if (name == null)
  93. name = "";
  94. NodeTree nodes = (NodeTree) sequence;
  95. int attr = nodes.getAttribute(ipos, null, name);
  96. if (attr == 0)
  97. return null;
  98. else
  99. return new KAttr(nodes, attr);
  100. }
  101. /* #ifdef use:org.w3c.dom.Node */
  102. /** Not implemented. */
  103. public Attr setAttributeNode (Attr newAttr)
  104. throws DOMException
  105. {
  106. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  107. "setAttributeNode not supported");
  108. }
  109. /** Not implemented. */
  110. public Attr removeAttributeNode (Attr oldAttr)
  111. throws DOMException
  112. {
  113. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  114. "removeAttributeNode not supported");
  115. }
  116. /* #endif */
  117. public String getAttributeNS (String namespaceURI, String localName)
  118. {
  119. if (namespaceURI == null)
  120. namespaceURI = "";
  121. if (localName == null)
  122. localName = "";
  123. NodeTree nodes = (NodeTree) sequence;
  124. int attr = nodes.getAttribute(ipos, namespaceURI, localName);
  125. if (attr == 0)
  126. return "";
  127. else
  128. return getNodeValue(nodes, attr);
  129. }
  130. /* #ifdef use:org.w3c.dom.Node */
  131. /** Not implemented. */
  132. public void setAttributeNS (String namespaceURI, String qualifiedName,
  133. String value) throws DOMException
  134. {
  135. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  136. "setAttributeNS not supported");
  137. }
  138. /* #endif */
  139. /* #ifdef use:org.w3c.dom.Node */
  140. /** Not implemented. */
  141. public void removeAttributeNS (String namespaceURI, String localName)
  142. throws DOMException
  143. {
  144. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  145. "removeAttributeNS not supported");
  146. }
  147. /* #endif */
  148. /* #ifdef JAVA5 */
  149. public KAttr
  150. /* #else */
  151. /* #ifdef use:org.w3c.dom.Node */
  152. // public Attr
  153. /* #else */
  154. // public KAttr
  155. /* #endif */
  156. /* #endif */
  157. getAttributeNodeNS(String namespaceURI, String localName)
  158. {
  159. if (namespaceURI == null)
  160. namespaceURI = "";
  161. if (localName == null)
  162. localName = "";
  163. NodeTree nodes = (NodeTree) sequence;
  164. int attr = nodes.getAttribute(ipos, namespaceURI, localName);
  165. if (attr == 0)
  166. return null;
  167. else
  168. return new KAttr(nodes, attr);
  169. }
  170. /** Not implemented. */
  171. /* #ifdef use:org.w3c.dom.Node */
  172. public Attr setAttributeNodeNS (Attr newAttr)
  173. throws DOMException
  174. {
  175. throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
  176. "setAttributeNodeNS not supported");
  177. }
  178. /* #endif */
  179. // Not implemented yet.
  180. /* #ifdef use:org.w3c.dom.Node */
  181. public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
  182. {
  183. throw new UnsupportedOperationException("getElementsByTagNameNS not implemented yet");
  184. }
  185. /* #endif */
  186. /** Not implemented yet. */
  187. public boolean hasAttribute (String name)
  188. {
  189. int attr = ((NodeTree) sequence).getAttribute(ipos, null, name == null ? "" : name);
  190. return attr != 0;
  191. }
  192. public boolean hasAttributeNS (String namespaceURI, String localName)
  193. {
  194. if (namespaceURI == null)
  195. namespaceURI = "";
  196. if (localName == null)
  197. localName = "";
  198. int attr = ((NodeTree) sequence).getAttribute(ipos, namespaceURI, localName);
  199. return attr != 0;
  200. }
  201. /* #ifdef JAXP-1.3 */
  202. public TypeInfo getSchemaTypeInfo ()
  203. {
  204. return null;
  205. }
  206. /* #endif JAXP-1.3 */
  207. }