001: /*
002: * The Apache Software License, Version 1.1
003: *
004: *
005: * Copyright (c) 1999,2000 The Apache Software Foundation. All rights
006: * reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * 1. Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * 2. Redistributions in binary form must reproduce the above copyright
016: * notice, this list of conditions and the following disclaimer in
017: * the documentation and/or other materials provided with the
018: * distribution.
019: *
020: * 3. The end-user documentation included with the redistribution,
021: * if any, must include the following acknowledgment:
022: * "This product includes software developed by the
023: * Apache Software Foundation (http://www.apache.org/)."
024: * Alternately, this acknowledgment may appear in the software itself,
025: * if and wherever such third-party acknowledgments normally appear.
026: *
027: * 4. The names "Xerces" and "Apache Software Foundation" must
028: * not be used to endorse or promote products derived from this
029: * software without prior written permission. For written
030: * permission, please contact apache@apache.org.
031: *
032: * 5. Products derived from this software may not be called "Apache",
033: * nor may "Apache" appear in their name, without prior written
034: * permission of the Apache Software Foundation.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: * ====================================================================
049: *
050: * This software consists of voluntary contributions made by many
051: * individuals on behalf of the Apache Software Foundation and was
052: * originally based on software copyright (c) 1999, International
053: * Business Machines, Inc., http://www.apache.org. For more
054: * information on the Apache Software Foundation, please see
055: * <http://www.apache.org/>.
056: */
057: package org.apache.wml.dom;
058:
059: import java.io.*;
060: import java.util.*;
061: import java.lang.reflect.*;
062: import org.w3c.dom.*;
063: import org.w3c.dom.html.*;
064: import org.apache.xerces.dom.DocumentImpl;
065: import org.apache.xerces.dom.NodeImpl;
066: import org.apache.xerces.dom.AttrImpl;
067: import org.w3c.dom.DOMException;
068: import org.apache.wml.*;
069:
070: /**
071: * @version $Id: WMLDocumentImpl.java,v 1.2 2000/10/04 11:19:26 jeffreyr Exp $
072: * @author <a href="mailto:david@topware.com.tw">David Li</a>
073: */
074:
075: public class WMLDocumentImpl extends DocumentImpl implements
076: WMLDocument {
077:
078: private static Hashtable _elementTypesWML;
079: private static final Class[] _elemClassSigWML = new Class[] {
080: WMLDocumentImpl.class, String.class };
081:
082: public Element createElement(String tagName) throws DOMException {
083: Class elemClass;
084: Constructor cnst;
085:
086: elemClass = (Class) _elementTypesWML.get(tagName);
087: if (elemClass != null) {
088: try {
089: cnst = elemClass.getConstructor(_elemClassSigWML);
090: return (Element) cnst.newInstance(new Object[] { this ,
091: tagName });
092: } catch (Exception except) {
093: Throwable thrw;
094:
095: if (except instanceof java.lang.reflect.InvocationTargetException)
096: thrw = ((java.lang.reflect.InvocationTargetException) except)
097: .getTargetException();
098: else
099: thrw = except;
100:
101: System.out.println("Exception "
102: + thrw.getClass().getName());
103: System.out.println(thrw.getMessage());
104:
105: throw new IllegalStateException(
106: "Tag '"
107: + tagName
108: + "' associated with an Element class that failed to construct.");
109: }
110: }
111: return new WMLElementImpl(this , tagName);
112: }
113:
114: static {
115: _elementTypesWML = new Hashtable();
116: _elementTypesWML.put("b", WMLBElementImpl.class);
117: _elementTypesWML.put("noop", WMLNoopElementImpl.class);
118: _elementTypesWML.put("a", WMLAElementImpl.class);
119: _elementTypesWML.put("setvar", WMLSetvarElementImpl.class);
120: _elementTypesWML.put("access", WMLAccessElementImpl.class);
121: _elementTypesWML.put("strong", WMLStrongElementImpl.class);
122: _elementTypesWML
123: .put("postfield", WMLPostfieldElementImpl.class);
124: _elementTypesWML.put("do", WMLDoElementImpl.class);
125: _elementTypesWML.put("wml", WMLWmlElementImpl.class);
126: _elementTypesWML.put("tr", WMLTrElementImpl.class);
127: _elementTypesWML.put("go", WMLGoElementImpl.class);
128: _elementTypesWML.put("big", WMLBigElementImpl.class);
129: _elementTypesWML.put("anchor", WMLAnchorElementImpl.class);
130: _elementTypesWML.put("timer", WMLTimerElementImpl.class);
131: _elementTypesWML.put("small", WMLSmallElementImpl.class);
132: _elementTypesWML.put("optgroup", WMLOptgroupElementImpl.class);
133: _elementTypesWML.put("head", WMLHeadElementImpl.class);
134: _elementTypesWML.put("td", WMLTdElementImpl.class);
135: _elementTypesWML.put("fieldset", WMLFieldsetElementImpl.class);
136: _elementTypesWML.put("img", WMLImgElementImpl.class);
137: _elementTypesWML.put("refresh", WMLRefreshElementImpl.class);
138: _elementTypesWML.put("onevent", WMLOneventElementImpl.class);
139: _elementTypesWML.put("input", WMLInputElementImpl.class);
140: _elementTypesWML.put("prev", WMLPrevElementImpl.class);
141: _elementTypesWML.put("table", WMLTableElementImpl.class);
142: _elementTypesWML.put("meta", WMLMetaElementImpl.class);
143: _elementTypesWML.put("template", WMLTemplateElementImpl.class);
144: _elementTypesWML.put("br", WMLBrElementImpl.class);
145: _elementTypesWML.put("option", WMLOptionElementImpl.class);
146: _elementTypesWML.put("u", WMLUElementImpl.class);
147: _elementTypesWML.put("p", WMLPElementImpl.class);
148: _elementTypesWML.put("select", WMLSelectElementImpl.class);
149: _elementTypesWML.put("em", WMLEmElementImpl.class);
150: _elementTypesWML.put("i", WMLIElementImpl.class);
151: _elementTypesWML.put("card", WMLCardElementImpl.class);
152: }
153:
154: /* DOM level 2 */
155: public WMLDocumentImpl(DocumentType doctype) {
156: super (doctype, false);
157: }
158: }
|