KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > xslt > DefaultElementAdapter


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.views.xslt;
6
7 import org.w3c.dom.*;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.LinkedList JavaDoc;
12 import java.util.List JavaDoc;
13
14
15 /**
16  * @author <a HREF="mailto:meier@meisterbohne.de">Philipp Meier</a>
17  * Date: 14.10.2003
18  * Time: 19:01:02
19  */

20 public abstract class DefaultElementAdapter extends DefaultAdapterNode implements AdapterNode, Element {
21     //~ Instance fields ////////////////////////////////////////////////////////
22

23     private List JavaDoc adapters;
24
25     //~ Constructors ///////////////////////////////////////////////////////////
26

27     public DefaultElementAdapter(DOMAdapter rootAdapter, AdapterNode parent, String JavaDoc propertyName, Object JavaDoc value) {
28         super(rootAdapter, parent, propertyName, value);
29     }
30
31     //~ Methods ////////////////////////////////////////////////////////////////
32

33     /**
34      * ***********************************************************************************
35      * Not supported below
36      * ************************************************************************************
37      */

38
39     //
40
public void setAttribute(String JavaDoc string, String JavaDoc string1) throws DOMException {
41         operationNotSupported();
42     }
43
44     /**
45      * ***********************************************************************************
46      * No attributes, return empty attributes if asked.
47      * ************************************************************************************
48      */

49     public String JavaDoc getAttribute(String JavaDoc string) {
50         return "";
51     }
52
53     public void setAttributeNS(String JavaDoc string, String JavaDoc string1, String JavaDoc string2) throws DOMException {
54         operationNotSupported();
55     }
56
57     public String JavaDoc getAttributeNS(String JavaDoc string, String JavaDoc string1) {
58         return null;
59     }
60
61     public Attr setAttributeNode(Attr attr) throws DOMException {
62         operationNotSupported();
63
64         return null;
65     }
66
67     public Attr getAttributeNode(String JavaDoc string) {
68         return null;
69     }
70
71     public Attr setAttributeNodeNS(Attr attr) throws DOMException {
72         operationNotSupported();
73
74         return null;
75     }
76
77     public Attr getAttributeNodeNS(String JavaDoc string, String JavaDoc string1) {
78         operationNotSupported();
79
80         return null;
81     }
82
83     public NodeList getChildNodes() {
84         return getElementsByTagName("*");
85     }
86
87     public NodeList getElementsByTagName(String JavaDoc tagName) {
88         initChildrenIfNessecary();
89
90         if (tagName.equals("*")) {
91             return new CollectionNodeList(getAdapters());
92         } else {
93             LinkedList JavaDoc filteredChildren = new LinkedList JavaDoc();
94
95             for (Iterator JavaDoc i = getAdapters().iterator(); i.hasNext();) {
96                 AdapterNode adapterNode = (AdapterNode) i.next();
97
98                 if (adapterNode.getNodeName().equals(tagName)) {
99                     filteredChildren.add(adapterNode);
100                 }
101             }
102
103             return new CollectionNodeList(filteredChildren);
104         }
105     }
106
107     public NodeList getElementsByTagNameNS(String JavaDoc string, String JavaDoc string1) {
108         return null;
109     }
110
111     public Node getFirstChild() {
112         return (getChildNodes().getLength() > 0) ? getChildNodes().item(0) : null;
113     }
114
115     public Node getLastChild() {
116         return (getChildNodes().getLength() > 0) ? getChildNodes().item(getChildNodes().getLength() - 1) : null;
117     }
118
119     public Node getNextSibling(AdapterNode child) {
120         int index = getAdapters().indexOf(child);
121
122         if (index < 0) {
123             throw new RuntimeException JavaDoc(child + " is no child of " + this);
124         }
125
126         int siblingIndex = index + 1;
127         Node sibling = ((0 < siblingIndex) && (siblingIndex < getAdapters().size())) ? ((Node) getAdapters().get(siblingIndex)) : null;
128
129         return sibling;
130     }
131
132     public String JavaDoc getNodeName() {
133         return getTagName();
134     }
135
136     public short getNodeType() {
137         return Node.ELEMENT_NODE;
138     }
139
140     public String JavaDoc getTagName() {
141         return getPropertyName();
142     }
143
144     public boolean hasAttribute(String JavaDoc string) {
145         return false;
146     }
147
148     public boolean hasAttributeNS(String JavaDoc string, String JavaDoc string1) {
149         return false;
150     }
151
152     public boolean hasChildNodes() {
153         return getElementsByTagName("*").getLength() > 0;
154     }
155
156     public void removeAttribute(String JavaDoc string) throws DOMException {
157         operationNotSupported();
158     }
159
160     public void removeAttributeNS(String JavaDoc string, String JavaDoc string1) throws DOMException {
161         operationNotSupported();
162     }
163
164     public Attr removeAttributeNode(Attr attr) throws DOMException {
165         operationNotSupported();
166
167         return null;
168     }
169
170     protected List JavaDoc getAdapters() {
171         initChildrenIfNessecary();
172
173         return adapters;
174     }
175
176     protected abstract List JavaDoc buildChildrenAdapters();
177
178     protected void initChildrenIfNessecary() {
179         if (adapters == null) {
180             adapters = new ArrayList JavaDoc();
181
182             synchronized (adapters) {
183                 adapters = buildChildrenAdapters();
184             }
185         }
186     }
187     
188     
189     /* (non-Javadoc)
190      * @see org.w3c.dom.Node#getBaseURI()
191      */

192     public String JavaDoc getBaseURI() {
193         // TODO Auto-generated method stub
194
return null;
195     }
196
197     /* (non-Javadoc)
198      * @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
199      */

200     public short compareDocumentPosition(Node other) throws DOMException {
201         // TODO Auto-generated method stub
202
return 0;
203     }
204
205     /* (non-Javadoc)
206      * @see org.w3c.dom.Node#getTextContent()
207      */

208     public String JavaDoc getTextContent() throws DOMException {
209         // TODO Auto-generated method stub
210
return null;
211     }
212
213     /* (non-Javadoc)
214      * @see org.w3c.dom.Node#setTextContent(java.lang.String)
215      */

216     public void setTextContent(String JavaDoc textContent) throws DOMException {
217         // TODO Auto-generated method stub
218

219     }
220
221     /* (non-Javadoc)
222      * @see org.w3c.dom.Node#isSameNode(org.w3c.dom.Node)
223      */

224     public boolean isSameNode(Node other) {
225         // TODO Auto-generated method stub
226
return false;
227     }
228
229     /* (non-Javadoc)
230      * @see org.w3c.dom.Node#lookupPrefix(java.lang.String)
231      */

232     public String JavaDoc lookupPrefix(String JavaDoc namespaceURI) {
233         // TODO Auto-generated method stub
234
return null;
235     }
236
237     /* (non-Javadoc)
238      * @see org.w3c.dom.Node#isDefaultNamespace(java.lang.String)
239      */

240     public boolean isDefaultNamespace(String JavaDoc namespaceURI) {
241         // TODO Auto-generated method stub
242
return false;
243     }
244
245     /* (non-Javadoc)
246      * @see org.w3c.dom.Node#lookupNamespaceURI(java.lang.String)
247      */

248     public String JavaDoc lookupNamespaceURI(String JavaDoc prefix) {
249         // TODO Auto-generated method stub
250
return null;
251     }
252
253     /* (non-Javadoc)
254      * @see org.w3c.dom.Node#isEqualNode(org.w3c.dom.Node)
255      */

256     public boolean isEqualNode(Node arg) {
257         // TODO Auto-generated method stub
258
return false;
259     }
260
261     /* (non-Javadoc)
262      * @see org.w3c.dom.Node#getFeature(java.lang.String, java.lang.String)
263      */

264     public Object JavaDoc getFeature(String JavaDoc feature, String JavaDoc version) {
265         // TODO Auto-generated method stub
266
return null;
267     }
268
269     /* (non-Javadoc)
270      * @see org.w3c.dom.Node#setUserData(java.lang.String, java.lang.Object, org.w3c.dom.UserDataHandler)
271      */

272     public Object JavaDoc setUserData(String JavaDoc key, Object JavaDoc data, UserDataHandler handler) {
273         // TODO Auto-generated method stub
274
return null;
275     }
276
277     /* (non-Javadoc)
278      * @see org.w3c.dom.Node#getUserData(java.lang.String)
279      */

280     public Object JavaDoc getUserData(String JavaDoc key) {
281         // TODO Auto-generated method stub
282
return null;
283     }
284
285     /* (non-Javadoc)
286      * @see org.w3c.dom.Element#getSchemaTypeInfo()
287      */

288     public TypeInfo getSchemaTypeInfo() {
289         // TODO Auto-generated method stub
290
return null;
291     }
292
293     /* (non-Javadoc)
294      * @see org.w3c.dom.Element#setIdAttribute(java.lang.String, boolean)
295      */

296     public void setIdAttribute(String JavaDoc name, boolean isId) throws DOMException {
297         // TODO Auto-generated method stub
298

299     }
300
301     /* (non-Javadoc)
302      * @see org.w3c.dom.Element#setIdAttributeNS(java.lang.String, java.lang.String, boolean)
303      */

304     public void setIdAttributeNS(String JavaDoc namespaceURI, String JavaDoc localName, boolean isId) throws DOMException {
305         // TODO Auto-generated method stub
306

307     }
308
309     /* (non-Javadoc)
310      * @see org.w3c.dom.Element#setIdAttributeNode(org.w3c.dom.Attr, boolean)
311      */

312     public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException {
313         // TODO Auto-generated method stub
314

315     }
316
317     
318     
319     
320     
321 }
322
Popular Tags