KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > xml > client > impl > ElementImpl


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.xml.client.impl;
17
18 import com.google.gwt.core.client.JavaScriptException;
19 import com.google.gwt.core.client.JavaScriptObject;
20 import com.google.gwt.xml.client.Attr;
21 import com.google.gwt.xml.client.DOMException;
22 import com.google.gwt.xml.client.Element;
23 import com.google.gwt.xml.client.NodeList;
24
25 /**
26  * This method implements the Element interface.
27  */

28 class ElementImpl extends NodeImpl implements Element {
29
30   protected ElementImpl(JavaScriptObject o) {
31     super(o);
32   }
33
34   /**
35    * This function delegates to the native method <code>getAttribute</code> in
36    * XMLParserImpl.
37    */

38   public String JavaDoc getAttribute(String JavaDoc tagName) {
39     return XMLParserImpl.getAttribute(this.getJsObject(), tagName);
40   }
41
42   /**
43    * This function delegates to the native method <code>getAttributeNode</code>
44    * in XMLParserImpl.
45    */

46   public Attr getAttributeNode(String JavaDoc tagName) {
47     return (Attr) NodeImpl.build(XMLParserImpl.getAttributeNode(this
48       .getJsObject(), tagName));
49   }
50
51   /**
52    * This function delegates to the native method
53    * <code>getElementsByTagName</code> in XMLParserImpl.
54    */

55   public NodeList getElementsByTagName(String JavaDoc tagName) {
56     return new NodeListImpl(XMLParserImpl.getElementsByTagName(this
57       .getJsObject(), tagName));
58   }
59
60   /**
61    * This function delegates to the native method <code>getTagName</code> in
62    * XMLParserImpl.
63    */

64   public String JavaDoc getTagName() {
65     return XMLParserImpl.getTagName(this.getJsObject());
66   }
67
68   /**
69    * This function delegates to the native method <code>hasAttribute</code> in
70    * XMLParserImpl.
71    */

72   public boolean hasAttribute(String JavaDoc tagName) {
73     return getAttribute(tagName) != null;
74   }
75
76   /**
77    * This function delegates to the native method <code>removeAttribute</code>
78    * in XMLParserImpl.
79    */

80   public void removeAttribute(String JavaDoc name) throws DOMNodeException {
81     try {
82       XMLParserImpl.removeAttribute(this.getJsObject(), name);
83     } catch (JavaScriptException e) {
84       throw new DOMNodeException(DOMException.INVALID_MODIFICATION_ERR, e, this);
85     }
86   }
87
88   /**
89    * This function delegates to the native method <code>setAttribute</code> in
90    * XMLParserImpl.
91    */

92   public void setAttribute(String JavaDoc name, String JavaDoc value) throws DOMNodeException {
93     try {
94       XMLParserImpl.setAttribute(this.getJsObject(), name, value);
95     } catch (JavaScriptException e) {
96       throw new DOMNodeException(DOMException.INVALID_MODIFICATION_ERR, e, this);
97     }
98   }
99
100   /**
101    * This method returns the string representation of this
102    * <code>ElementImpl</code>.
103    * @return the string representation of this
104    * <code>ElementImpl</code>.
105    * @see java.lang.Object#toString()
106    */

107   public String JavaDoc toString() {
108     final StringBuffer JavaDoc b = new StringBuffer JavaDoc("<");
109     b.append(getTagName());
110     if (hasAttributes()) {
111       b.append(getAttributes().toString());
112     }
113     if (hasChildNodes()) {
114       b.append(">");
115       b.append(getChildNodes().toString());
116       b.append("</");
117       b.append(getTagName());
118       b.append(">");
119     } else {
120       b.append("/>");
121     }
122     return b.toString();
123   }
124 }
125
Popular Tags