KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > wireless > wml > dom > xerces > WMLDocumentImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Original Code is DigitalSesame
15  * Portions created by DigitalSesame are Copyright (C) 1997-2000 DigitalSesame
16  * All Rights Reserved.
17  *
18  * Contributor(s):
19  *
20  * $Id: WMLDocumentImpl.java,v 1.4 2005/01/26 08:28:45 jkjome Exp $
21  */

22 package org.enhydra.wireless.wml.dom.xerces;
23
24 import java.lang.reflect.Constructor JavaDoc;
25 import java.util.Hashtable JavaDoc;
26
27 import org.enhydra.apache.xerces.dom.DocumentImpl;
28 import org.enhydra.wireless.wml.dom.WMLDocument;
29 import org.enhydra.xml.xmlc.XMLCError;
30 import org.enhydra.xml.xmlc.XMLObject;
31 import org.enhydra.xml.xmlc.XMLObjectLink;
32 import org.w3c.dom.DOMException JavaDoc;
33 import org.w3c.dom.DOMImplementation JavaDoc;
34 import org.w3c.dom.DocumentType JavaDoc;
35 import org.w3c.dom.Element JavaDoc;
36
37 public class WMLDocumentImpl extends DocumentImpl implements WMLDocument, XMLObjectLink {
38     // FIXME: would be faster to saved Constructor object.
39
private static Hashtable JavaDoc fElementTypes;
40     private static final Class JavaDoc[] fElemConstructorSig
41         = new Class JavaDoc[] {WMLDocumentImpl.class, String JavaDoc.class, String JavaDoc.class};
42
43     /**
44      * overload in order to return the correct dom implementation for WML
45      * @see org.enhydra.apache.xerces.dom.DocumentImpl#getImplementation
46      */

47     public DOMImplementation JavaDoc getImplementation() {
48         return WMLDOMImplementationImpl.getDOMImplementation();
49     }
50
51     public Element JavaDoc createElementNS(String JavaDoc namespaceURI,
52                                    String JavaDoc qualifiedName) throws DOMException JavaDoc {
53         // FIXME: should be a common method for doing this
54
int index = qualifiedName.indexOf(':');
55         String JavaDoc tagName;
56         if (index < 0) {
57             tagName = qualifiedName;
58         } else {
59             tagName = qualifiedName.substring(index+1);
60         }
61         Class JavaDoc elemClass = (Class JavaDoc)fElementTypes.get(tagName);
62         if (elemClass != null) {
63             try {
64                 Constructor JavaDoc cnst = elemClass.getConstructor(fElemConstructorSig);
65                 return (Element JavaDoc)cnst.newInstance(new Object JavaDoc[] {this, namespaceURI, qualifiedName});
66             } catch (Exception JavaDoc except) {
67                 // Need more specific error..
68
throw new XMLCError("failed to construct element for \""
69                                     + qualifiedName + "\"", except);
70             }
71         } else {
72             return new WMLElementImpl(this, null, tagName);
73         }
74     }
75
76     public Element JavaDoc createElement(String JavaDoc tagName) throws DOMException JavaDoc {
77         return createElementNS(null, tagName);
78     }
79
80     static {
81     fElementTypes = new Hashtable JavaDoc();
82     fElementTypes.put("b", WMLBElementImpl.class);
83     fElementTypes.put("noop", WMLNoopElementImpl.class);
84     fElementTypes.put("a", WMLAElementImpl.class);
85     fElementTypes.put("setvar", WMLSetvarElementImpl.class);
86     fElementTypes.put("access", WMLAccessElementImpl.class);
87     fElementTypes.put("strong", WMLStrongElementImpl.class);
88     fElementTypes.put("postfield", WMLPostfieldElementImpl.class);
89     fElementTypes.put("do", WMLDoElementImpl.class);
90     fElementTypes.put("wml", WMLWmlElementImpl.class);
91     fElementTypes.put("tr", WMLTrElementImpl.class);
92     fElementTypes.put("go", WMLGoElementImpl.class);
93     fElementTypes.put("big", WMLBigElementImpl.class);
94     fElementTypes.put("anchor", WMLAnchorElementImpl.class);
95     fElementTypes.put("timer", WMLTimerElementImpl.class);
96     fElementTypes.put("small", WMLSmallElementImpl.class);
97     fElementTypes.put("optgroup", WMLOptgroupElementImpl.class);
98     fElementTypes.put("head", WMLHeadElementImpl.class);
99     fElementTypes.put("td", WMLTdElementImpl.class);
100     fElementTypes.put("fieldset", WMLFieldsetElementImpl.class);
101     fElementTypes.put("img", WMLImgElementImpl.class);
102     fElementTypes.put("refresh", WMLRefreshElementImpl.class);
103     fElementTypes.put("onevent", WMLOneventElementImpl.class);
104     fElementTypes.put("input", WMLInputElementImpl.class);
105     fElementTypes.put("prev", WMLPrevElementImpl.class);
106     fElementTypes.put("table", WMLTableElementImpl.class);
107     fElementTypes.put("meta", WMLMetaElementImpl.class);
108     fElementTypes.put("template", WMLTemplateElementImpl.class);
109     fElementTypes.put("br", WMLBrElementImpl.class);
110     fElementTypes.put("option", WMLOptionElementImpl.class);
111     fElementTypes.put("u", WMLUElementImpl.class);
112     fElementTypes.put("p", WMLPElementImpl.class);
113     fElementTypes.put("select", WMLSelectElementImpl.class);
114     fElementTypes.put("em", WMLEmElementImpl.class);
115     fElementTypes.put("i", WMLIElementImpl.class);
116     fElementTypes.put("card", WMLCardElementImpl.class);
117     }
118
119     
120     /* DOM level 2 */
121     public WMLDocumentImpl(DocumentType JavaDoc doctype) {
122         super(doctype, false);
123     }
124
125     //-------------------------------------------------------------------------
126
// XMLObjectLink implementation
127
//-------------------------------------------------------------------------
128

129     /**
130      * Reference to XMLObject containing this Document.
131      */

132     private XMLObject fXmlObjectLink;
133
134     /**
135      * @see XMLObjectLink#setXMLObject
136      */

137     public void setXMLObject(XMLObject xmlObject) {
138         fXmlObjectLink = xmlObject;
139     }
140
141     /**
142      * @see XMLObjectLink#getXMLObject
143      */

144     public XMLObject getXMLObject() {
145         return fXmlObjectLink;
146     }
147
148 }
149
Popular Tags