1 22 package org.enhydra.wireless.wml.dom.xerces; 23 24 import java.lang.reflect.Constructor ; 25 import java.util.Hashtable ; 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 ; 33 import org.w3c.dom.DOMImplementation ; 34 import org.w3c.dom.DocumentType ; 35 import org.w3c.dom.Element ; 36 37 public class WMLDocumentImpl extends DocumentImpl implements WMLDocument, XMLObjectLink { 38 private static Hashtable fElementTypes; 40 private static final Class [] fElemConstructorSig 41 = new Class [] {WMLDocumentImpl.class, String .class, String .class}; 42 43 47 public DOMImplementation getImplementation() { 48 return WMLDOMImplementationImpl.getDOMImplementation(); 49 } 50 51 public Element createElementNS(String namespaceURI, 52 String qualifiedName) throws DOMException { 53 int index = qualifiedName.indexOf(':'); 55 String tagName; 56 if (index < 0) { 57 tagName = qualifiedName; 58 } else { 59 tagName = qualifiedName.substring(index+1); 60 } 61 Class elemClass = (Class )fElementTypes.get(tagName); 62 if (elemClass != null) { 63 try { 64 Constructor cnst = elemClass.getConstructor(fElemConstructorSig); 65 return (Element )cnst.newInstance(new Object [] {this, namespaceURI, qualifiedName}); 66 } catch (Exception except) { 67 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 createElement(String tagName) throws DOMException { 77 return createElementNS(null, tagName); 78 } 79 80 static { 81 fElementTypes = new Hashtable (); 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 121 public WMLDocumentImpl(DocumentType doctype) { 122 super(doctype, false); 123 } 124 125 129 132 private XMLObject fXmlObjectLink; 133 134 137 public void setXMLObject(XMLObject xmlObject) { 138 fXmlObjectLink = xmlObject; 139 } 140 141 144 public XMLObject getXMLObject() { 145 return fXmlObjectLink; 146 } 147 148 } 149
| Popular Tags
|