1 23 24 package org.enhydra.xml.xmlc.dom.xerces; 25 26 import org.enhydra.apache.xerces.dom.DocumentImpl; 27 import org.enhydra.apache.xerces.dom.DocumentTypeImpl; 28 import org.enhydra.xml.xmlc.XMLCError; 29 import org.enhydra.xml.xmlc.XMLObject; 30 import org.enhydra.xml.xmlc.XMLObjectLink; 31 import org.enhydra.xml.xmlc.dom.AccessorGenerator; 32 import org.enhydra.xml.xmlc.dom.DocBuilderGenerator; 33 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 34 import org.enhydra.xml.xmlc.dom.generic.GenericAccessorGenerator; 35 import org.w3c.dom.Document ; 36 import org.w3c.dom.DocumentType ; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.Node ; 39 40 41 45 public class XercesDomFactory implements XMLCDomFactory { 46 54 public class LinkedXercesDocument extends DocumentImpl 55 implements XMLObjectLink { 56 57 private XMLObject fXmlObjectLink; 58 59 60 public LinkedXercesDocument(DocumentType docType) { 61 super(docType); 62 } 63 64 65 public void setXMLObject(XMLObject xmlObject) { 66 fXmlObjectLink = xmlObject; 67 } 68 69 70 public XMLObject getXMLObject() { 71 return fXmlObjectLink; 72 } 73 } 74 75 78 private static final String IMPL_CLASS_SUFFIX = "Impl"; 79 80 83 private static final String [][] DOM_PACKAGES_DOT_MAP = { 84 {"org.enhydra.apache.xerces.dom.", "org.w3c.dom."}, 85 {"org.enhydra.apache.html.dom.", "org.w3c.dom.html."}, 86 }; 87 88 92 private static final String [][] CLASS_INTERFACE_MAP = { 93 {"org.enhydra.apache.xerces.dom.ElementNSImpl", "org.w3c.dom.Element"}, 94 {"org.enhydra.apache.xerces.dom.AttrNSImpl", "org.w3c.dom.Attr"}, 95 }; 96 97 100 public String getMIMEType() { 101 return null; 102 } 103 104 107 public String getBaseClassName() { 108 return "org.enhydra.xml.xmlc.XMLObjectImpl"; 109 } 110 111 114 public String [] getInterfaceNames() { 115 return null; 116 } 117 118 121 public String [] getElementClassNames(Element element) { 122 return null; } 124 125 128 public boolean isURLAttribute(Element element, 129 String attrName) { 130 return false; } 132 133 136 public DocumentType createDocumentType(String qualifiedName, 137 String publicId, 138 String systemId, 139 String internalSubset) { 140 DocumentTypeImpl docType = new DocumentTypeImpl(null, qualifiedName, 141 publicId, systemId); 142 docType.setInternalSubset(internalSubset); 143 return docType; 144 } 145 146 151 public Document createDocument(String namespaceURI, 152 String qualifiedName, 153 DocumentType docType) { 154 Document doc = new XercesLinkedDocument(docType); 155 doc.appendChild(doc.createElementNS(namespaceURI, qualifiedName)); 157 return doc; 158 } 159 160 163 public String nodeClassToInterface(Node node) { 164 String className = node.getClass().getName(); 165 166 for (int idx = 0; idx < CLASS_INTERFACE_MAP.length; idx++) { 168 if (className.equals(CLASS_INTERFACE_MAP[idx][0])) { 169 return CLASS_INTERFACE_MAP[idx][1]; 170 } 171 } 172 173 int packageIdx; 175 for (packageIdx = 0; packageIdx < DOM_PACKAGES_DOT_MAP.length; packageIdx++) { 176 if (className.startsWith(DOM_PACKAGES_DOT_MAP[packageIdx][0])) { 177 178 break; 179 } 180 } 181 if (packageIdx == DOM_PACKAGES_DOT_MAP.length) { 182 throw new XMLCError("Can't determine DOM interface for node of class \"" 183 + className 184 + "\" (maybe be mismatch between XMLCDomFactory DOM implementation)"); 185 } 186 187 int suffixIdx = className.lastIndexOf(IMPL_CLASS_SUFFIX); 189 if (suffixIdx < 0) { 190 throw new XMLCError("Class \"" + className 191 + "\" does not have suffix \"" + IMPL_CLASS_SUFFIX 192 + "\" (maybe be mismatch between XMLCDomFactory DOM implementation)"); 193 } 194 195 return DOM_PACKAGES_DOT_MAP[packageIdx][1] 196 + className.substring(DOM_PACKAGES_DOT_MAP[packageIdx][0].length(), 197 suffixIdx); 198 } 199 200 202 205 public AccessorGenerator createAccessorGenerator(Document document) { 206 return new GenericAccessorGenerator(); 207 } 208 209 213 public DocBuilderGenerator createDocBuilderGenerator(Document document) { 214 return new XercesDocBuilderGenerator(); 215 } 216 } 217 | Popular Tags |