1 23 24 package org.enhydra.xml.xmlc.dom.lazydom; 25 26 import org.enhydra.xml.lazydom.LazyDocument; 27 import org.enhydra.xml.lazydom.LazyDocumentType; 28 import org.enhydra.xml.lazydom.TemplateDOM; 29 import org.enhydra.xml.xmlc.XMLCError; 30 import org.enhydra.xml.xmlc.dom.AccessorGenerator; 31 import org.enhydra.xml.xmlc.dom.DocBuilderGenerator; 32 import org.enhydra.xml.xmlc.dom.XMLCDomFactory; 33 import org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory; 34 import org.w3c.dom.Document ; 35 import org.w3c.dom.DocumentType ; 36 import org.w3c.dom.Node ; 37 38 41 public class LazyDomFactory extends XercesDomFactory 42 implements XMLCDomFactory { 43 47 private static final String IMPL_CLASS_PREFIX = "Lazy"; 48 49 53 private static final String IMPL_CLASS_SUFFIX = "Impl"; 54 55 59 private static final String [][] DOM_PACKAGES_DOT_MAP = { 60 {"org.enhydra.xml.lazydom.html.", "org.w3c.dom.html."}, 61 {"org.enhydra.xml.lazydom.", "org.w3c.dom."}, 62 }; 63 64 68 private static final String [][] CLASS_INTERFACE_MAP = { 69 {"org.enhydra.xml.lazydom.LazyElementNS", "org.w3c.dom.Element"}, 70 {"org.enhydra.xml.lazydom.LazyElementNoNS", "org.w3c.dom.Element"}, 71 {"org.enhydra.xml.lazydom.LazyAttrNS", "org.w3c.dom.Attr"}, 72 {"org.enhydra.xml.lazydom.LazyAttrNoNS", "org.w3c.dom.Attr"}, 73 }; 74 75 78 public DocumentType createDocumentType(String qualifiedName, 79 String publicId, 80 String systemId, 81 String internalSubset) { 82 return new LazyDocumentType(null, null, qualifiedName, 83 publicId, systemId, 84 internalSubset); 85 } 86 87 90 public Document createDocument(String namespaceURI, 91 String qualifiedName, 92 DocumentType docType) { 93 Document doc = new LazyDocument(docType, null); 94 doc.appendChild(doc.createElementNS(namespaceURI, qualifiedName)); 96 return doc; 97 } 98 99 103 public Document createDocument(TemplateDOM templateDOM) { 104 return new LazyDocument(null, templateDOM); 105 } 106 107 110 public String nodeClassToInterface(Node node) { 111 String className = node.getClass().getName(); 112 113 for (int idx = 0; idx < CLASS_INTERFACE_MAP.length; idx++) { 115 if (className.equals(CLASS_INTERFACE_MAP[idx][0])) { 116 return CLASS_INTERFACE_MAP[idx][1]; 117 } 118 } 119 120 int packageIdx; 122 for (packageIdx = 0; packageIdx < DOM_PACKAGES_DOT_MAP.length; packageIdx++) { 123 if (className.startsWith(DOM_PACKAGES_DOT_MAP[packageIdx][0])) { 124 break; 125 } 126 } 127 if (packageIdx == DOM_PACKAGES_DOT_MAP.length) { 128 throw new XMLCError("Can't determine DOM interface for node of class \"" 129 + className 130 + "\" (maybe be mismatch between XMLCDomFactory DOM implementation)"); 131 } 132 133 String unqualClassName = className.substring(DOM_PACKAGES_DOT_MAP[packageIdx][0].length()); 134 135 int prefixIdx = unqualClassName.lastIndexOf(IMPL_CLASS_PREFIX); 137 if (prefixIdx >= 0) { 138 unqualClassName = unqualClassName.substring(IMPL_CLASS_PREFIX.length()); 139 } 140 int suffixIdx = unqualClassName.lastIndexOf(IMPL_CLASS_SUFFIX); 141 if (suffixIdx >= 0) { 142 unqualClassName = unqualClassName.substring(0, suffixIdx); 143 } 144 145 return DOM_PACKAGES_DOT_MAP[packageIdx][1] + unqualClassName; 146 } 147 148 151 public AccessorGenerator createAccessorGenerator(Document document) { 152 return new LazyDOMAccessorGenerator(document); 153 } 154 155 158 public DocBuilderGenerator createDocBuilderGenerator(Document document) { 159 return new LazyDOMDocBuilderGenerator(); 160 } 161 } 162 | Popular Tags |