001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wml.dom;
018:
019: import java.lang.reflect.Constructor;
020: import java.util.Hashtable;
021:
022: import org.apache.wml.WMLDocument;
023: import org.apache.xerces.dom.DocumentImpl;
024: import org.w3c.dom.DOMException;
025: import org.w3c.dom.DocumentType;
026: import org.w3c.dom.Element;
027:
028: /**
029: * @xerces.internal
030: * @version $Id: WMLDocumentImpl.java 447257 2006-09-18 05:40:07Z mrglavas $
031: * @author <a href="mailto:david@topware.com.tw">David Li</a>
032: */
033: public class WMLDocumentImpl extends DocumentImpl implements
034: WMLDocument {
035:
036: private static final long serialVersionUID = -6582904849512384104L;
037:
038: private static Hashtable _elementTypesWML;
039: private static final Class[] _elemClassSigWML = new Class[] {
040: WMLDocumentImpl.class, String.class };
041:
042: public Element createElement(String tagName) throws DOMException {
043: Class elemClass;
044: Constructor cnst;
045:
046: elemClass = (Class) _elementTypesWML.get(tagName);
047: if (elemClass != null) {
048: try {
049: cnst = elemClass.getConstructor(_elemClassSigWML);
050: return (Element) cnst.newInstance(new Object[] { this ,
051: tagName });
052: } catch (Exception except) {
053: Throwable thrw;
054:
055: if (except instanceof java.lang.reflect.InvocationTargetException)
056: thrw = ((java.lang.reflect.InvocationTargetException) except)
057: .getTargetException();
058: else
059: thrw = except;
060:
061: System.out.println("Exception "
062: + thrw.getClass().getName());
063: System.out.println(thrw.getMessage());
064:
065: throw new IllegalStateException(
066: "Tag '"
067: + tagName
068: + "' associated with an Element class that failed to construct.");
069: }
070: }
071: return new WMLElementImpl(this , tagName);
072: }
073:
074: static {
075: _elementTypesWML = new Hashtable();
076: _elementTypesWML.put("b", WMLBElementImpl.class);
077: _elementTypesWML.put("noop", WMLNoopElementImpl.class);
078: _elementTypesWML.put("a", WMLAElementImpl.class);
079: _elementTypesWML.put("setvar", WMLSetvarElementImpl.class);
080: _elementTypesWML.put("access", WMLAccessElementImpl.class);
081: _elementTypesWML.put("strong", WMLStrongElementImpl.class);
082: _elementTypesWML
083: .put("postfield", WMLPostfieldElementImpl.class);
084: _elementTypesWML.put("do", WMLDoElementImpl.class);
085: _elementTypesWML.put("wml", WMLWmlElementImpl.class);
086: _elementTypesWML.put("tr", WMLTrElementImpl.class);
087: _elementTypesWML.put("go", WMLGoElementImpl.class);
088: _elementTypesWML.put("big", WMLBigElementImpl.class);
089: _elementTypesWML.put("anchor", WMLAnchorElementImpl.class);
090: _elementTypesWML.put("timer", WMLTimerElementImpl.class);
091: _elementTypesWML.put("small", WMLSmallElementImpl.class);
092: _elementTypesWML.put("optgroup", WMLOptgroupElementImpl.class);
093: _elementTypesWML.put("head", WMLHeadElementImpl.class);
094: _elementTypesWML.put("td", WMLTdElementImpl.class);
095: _elementTypesWML.put("fieldset", WMLFieldsetElementImpl.class);
096: _elementTypesWML.put("img", WMLImgElementImpl.class);
097: _elementTypesWML.put("refresh", WMLRefreshElementImpl.class);
098: _elementTypesWML.put("onevent", WMLOneventElementImpl.class);
099: _elementTypesWML.put("input", WMLInputElementImpl.class);
100: _elementTypesWML.put("prev", WMLPrevElementImpl.class);
101: _elementTypesWML.put("table", WMLTableElementImpl.class);
102: _elementTypesWML.put("meta", WMLMetaElementImpl.class);
103: _elementTypesWML.put("template", WMLTemplateElementImpl.class);
104: _elementTypesWML.put("br", WMLBrElementImpl.class);
105: _elementTypesWML.put("option", WMLOptionElementImpl.class);
106: _elementTypesWML.put("u", WMLUElementImpl.class);
107: _elementTypesWML.put("p", WMLPElementImpl.class);
108: _elementTypesWML.put("select", WMLSelectElementImpl.class);
109: _elementTypesWML.put("em", WMLEmElementImpl.class);
110: _elementTypesWML.put("i", WMLIElementImpl.class);
111: _elementTypesWML.put("card", WMLCardElementImpl.class);
112: }
113:
114: /* DOM level 2 */
115: public WMLDocumentImpl(DocumentType doctype) {
116: super (doctype, false);
117: }
118: }
|