KickJava   Java API By Example, From Geeks To Geeks.

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


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.CDATASection;
21 import com.google.gwt.xml.client.Comment;
22 import com.google.gwt.xml.client.DOMException;
23 import com.google.gwt.xml.client.Document;
24 import com.google.gwt.xml.client.DocumentFragment;
25 import com.google.gwt.xml.client.Element;
26 import com.google.gwt.xml.client.Node;
27 import com.google.gwt.xml.client.NodeList;
28 import com.google.gwt.xml.client.ProcessingInstruction;
29 import com.google.gwt.xml.client.Text;
30
31 /**
32  * This class wraps the native Document object.
33  */

34 class DocumentImpl extends NodeImpl implements Document {
35
36   protected DocumentImpl(JavaScriptObject o) {
37     super(o);
38   }
39
40   /**
41    * This function delegates to the native method
42    * <code>createCDATASection</code> in XMLParserImpl.
43    */

44   public CDATASection createCDATASection(String JavaDoc data) {
45     try {
46       return (CDATASection) NodeImpl.build(XMLParserImpl.createCDATASection(
47           this.getJsObject(), data));
48     } catch (JavaScriptException e) {
49       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
50     }
51   }
52
53   /**
54    * This function delegates to the native method <code>createComment</code>
55    * in XMLParserImpl.
56    */

57   public Comment createComment(String JavaDoc data) {
58     try {
59       return (Comment) NodeImpl.build(XMLParserImpl.createComment(
60           this.getJsObject(), data));
61     } catch (JavaScriptException e) {
62       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
63     }
64   }
65
66   /**
67    * This function delegates to the native method
68    * <code>createDocumentFragment</code> in XMLParserImpl.
69    */

70   public DocumentFragment createDocumentFragment() {
71     try {
72       return (DocumentFragment) NodeImpl.build(XMLParserImpl.createDocumentFragment(this.getJsObject()));
73     } catch (JavaScriptException e) {
74       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
75     }
76   }
77
78   /**
79    * This function delegates to the native method <code>createElement</code>
80    * in XMLParserImpl.
81    */

82   public Element createElement(String JavaDoc tagName) {
83     try {
84       return (Element) NodeImpl.build(XMLParserImpl.createElement(
85           this.getJsObject(), tagName));
86     } catch (JavaScriptException e) {
87       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
88     }
89   }
90
91   /**
92    * This function delegates to the native method
93    * <code>createProcessingInstruction</code> in XMLParserImpl.
94    */

95   public ProcessingInstruction createProcessingInstruction(String JavaDoc target,
96       String JavaDoc data) {
97     try {
98       return (ProcessingInstruction) NodeImpl.build(XMLParserImpl.createProcessingInstruction(
99           this.getJsObject(), target, data));
100     } catch (JavaScriptException e) {
101       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
102     }
103   }
104
105   /**
106    * This function delegates to the native method <code>createTextNode</code>
107    * in XMLParserImpl.
108    */

109   public Text createTextNode(String JavaDoc data) {
110     try {
111       return (Text) NodeImpl.build(XMLParserImpl.createTextNode(
112           this.getJsObject(), data));
113     } catch (JavaScriptException e) {
114       throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this);
115     }
116   }
117
118   /**
119    * This function delegates to the native method
120    * <code>getDocumentElement</code> in XMLParserImpl.
121    */

122   public Element getDocumentElement() {
123     return (Element) NodeImpl.build(XMLParserImpl.getDocumentElement(this.getJsObject()));
124   }
125
126   /**
127    * This function delegates to the native method <code>getElementById</code>
128    * in XMLParserImpl.
129    */

130   public Element getElementById(String JavaDoc elementId) {
131     return (Element) NodeImpl.build(XMLParserImpl.getElementById(
132         this.getJsObject(), elementId));
133   }
134
135   /**
136    * This function delegates to the native method
137    * <code>getElementsByTagName</code> in XMLParserImpl.
138    */

139   public NodeList getElementsByTagName(String JavaDoc tagName) {
140     return new NodeListImpl(XMLParserImpl.getElementsByTagName(
141         this.getJsObject(), tagName));
142   }
143
144   /**
145    * This function delegates to the native method <code>importNode</code> in
146    * XMLParserImpl.
147    */

148   public Node importNode(Node importedNode, boolean deep) {
149     try {
150       return NodeImpl.build(XMLParserImpl.importNode(this.getJsObject(),
151           ((DOMItem) importedNode).getJsObject(), deep));
152     } catch (JavaScriptException e) {
153       throw new DOMNodeException(DOMException.INVALID_STATE_ERR, e, this);
154     }
155   }
156
157   /**
158    * This method returns the string representation of this
159    * <code>DocumentImpl</code>.
160    *
161    * @return the string representation of this <code>DocumentImpl</code>.
162    * @see java.lang.Object#toString()
163    */

164   public String JavaDoc toString() {
165     StringBuffer JavaDoc b = new StringBuffer JavaDoc();
166     NodeList children = getChildNodes();
167     for (int i = 0; i < children.getLength(); i++) {
168       b.append(children.item(i).toString());
169     }
170     return b.toString();
171   }
172 }
173
Popular Tags