KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > wml > dom > WMLDocumentImpl


1 /*
2  * Copyright 1999,2000,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.wml.dom;
17
18 import java.lang.reflect.Constructor JavaDoc;
19 import java.util.Hashtable JavaDoc;
20
21 import org.apache.wml.WMLDocument;
22 import org.apache.xerces.dom.DocumentImpl;
23 import org.w3c.dom.DOMException JavaDoc;
24 import org.w3c.dom.DocumentType JavaDoc;
25 import org.w3c.dom.Element JavaDoc;
26
27 /**
28  * @xerces.internal
29  * @version $Id: WMLDocumentImpl.java,v 1.6 2005/04/17 23:34:55 mrglavas Exp $
30  * @author <a HREF="mailto:david@topware.com.tw">David Li</a>
31  */

32 public class WMLDocumentImpl extends DocumentImpl implements WMLDocument {
33     
34     private static final long serialVersionUID = 3257844364091929145L;
35     
36     private static Hashtable JavaDoc _elementTypesWML;
37     private static final Class JavaDoc[] _elemClassSigWML =
38         new Class JavaDoc[] { WMLDocumentImpl.class, String JavaDoc.class };
39     
40     public Element JavaDoc createElement( String JavaDoc tagName ) throws DOMException JavaDoc
41     {
42         Class JavaDoc elemClass;
43         Constructor JavaDoc cnst;
44         
45         elemClass = (Class JavaDoc) _elementTypesWML.get( tagName );
46         if ( elemClass != null ) {
47             try {
48                 cnst = elemClass.getConstructor( _elemClassSigWML );
49                 return (Element JavaDoc) cnst.newInstance( new Object JavaDoc[] { this, tagName } );
50             } catch ( Exception JavaDoc except ) {
51                 Throwable JavaDoc thrw;
52                 
53                 if ( except instanceof java.lang.reflect.InvocationTargetException JavaDoc )
54                     thrw = ( (java.lang.reflect.InvocationTargetException JavaDoc) except ).getTargetException();
55                 else
56                     thrw = except;
57                 
58                 System.out.println( "Exception " + thrw.getClass().getName() );
59                 System.out.println( thrw.getMessage() );
60                 
61                 throw new IllegalStateException JavaDoc( "Tag '" + tagName + "' associated with an Element class that failed to construct." );
62             }
63         }
64         return new WMLElementImpl( this, tagName );
65     }
66     
67     static {
68         _elementTypesWML = new Hashtable JavaDoc();
69         _elementTypesWML.put("b", WMLBElementImpl.class);
70         _elementTypesWML.put("noop", WMLNoopElementImpl.class);
71         _elementTypesWML.put("a", WMLAElementImpl.class);
72         _elementTypesWML.put("setvar", WMLSetvarElementImpl.class);
73         _elementTypesWML.put("access", WMLAccessElementImpl.class);
74         _elementTypesWML.put("strong", WMLStrongElementImpl.class);
75         _elementTypesWML.put("postfield", WMLPostfieldElementImpl.class);
76         _elementTypesWML.put("do", WMLDoElementImpl.class);
77         _elementTypesWML.put("wml", WMLWmlElementImpl.class);
78         _elementTypesWML.put("tr", WMLTrElementImpl.class);
79         _elementTypesWML.put("go", WMLGoElementImpl.class);
80         _elementTypesWML.put("big", WMLBigElementImpl.class);
81         _elementTypesWML.put("anchor", WMLAnchorElementImpl.class);
82         _elementTypesWML.put("timer", WMLTimerElementImpl.class);
83         _elementTypesWML.put("small", WMLSmallElementImpl.class);
84         _elementTypesWML.put("optgroup", WMLOptgroupElementImpl.class);
85         _elementTypesWML.put("head", WMLHeadElementImpl.class);
86         _elementTypesWML.put("td", WMLTdElementImpl.class);
87         _elementTypesWML.put("fieldset", WMLFieldsetElementImpl.class);
88         _elementTypesWML.put("img", WMLImgElementImpl.class);
89         _elementTypesWML.put("refresh", WMLRefreshElementImpl.class);
90         _elementTypesWML.put("onevent", WMLOneventElementImpl.class);
91         _elementTypesWML.put("input", WMLInputElementImpl.class);
92         _elementTypesWML.put("prev", WMLPrevElementImpl.class);
93         _elementTypesWML.put("table", WMLTableElementImpl.class);
94         _elementTypesWML.put("meta", WMLMetaElementImpl.class);
95         _elementTypesWML.put("template", WMLTemplateElementImpl.class);
96         _elementTypesWML.put("br", WMLBrElementImpl.class);
97         _elementTypesWML.put("option", WMLOptionElementImpl.class);
98         _elementTypesWML.put("u", WMLUElementImpl.class);
99         _elementTypesWML.put("p", WMLPElementImpl.class);
100         _elementTypesWML.put("select", WMLSelectElementImpl.class);
101         _elementTypesWML.put("em", WMLEmElementImpl.class);
102         _elementTypesWML.put("i", WMLIElementImpl.class);
103         _elementTypesWML.put("card", WMLCardElementImpl.class);
104     }
105     
106     /* DOM level 2 */
107     public WMLDocumentImpl(DocumentType JavaDoc doctype) {
108         super(doctype, false);
109     }
110 }
111
Popular Tags