1 22 23 package org.enhydra.kelp.common.bridge; 24 25 import org.enhydra.tool.ToolBoxInfo; 27 28 import org.w3c.dom.Document ; 30 import org.enhydra.xml.xmlc.dom.XMLCDocument; 31 import org.enhydra.xml.xmlc.XMLCException; 32 import org.enhydra.xml.xmlc.compiler.EditDOM; 33 import org.enhydra.xml.xmlc.metadata.MetaData; 34 35 import org.enhydra.kelp.KelpInfo; 37 import org.enhydra.kelp.common.node.OtterXMLCNode; 38 import org.enhydra.kelp.common.node.OtterProject; 39 40 import java.io.PrintWriter ; 42 import java.lang.reflect.Constructor ; 43 import java.lang.reflect.Method ; 44 45 public class XMLCConnectionFactory { 47 48 private static final String EDIT_DOM_CLASS = 50 "org.enhydra.xml.xmlc.compiler.EditDOM"; private static final String ADD_URL_EDITS_METHOD = "addURLEdits"; private static final String ADD_DELETE_CLASSES_METHOD = 53 "addDeleteClasses"; 55 public XMLCConnectionFactory() {} 57 58 public static MetaDataHandler createMetaDataHandler() { 59 MetaDataHandler handler = null; 60 61 if (ToolBoxInfo.isXMLCVersion(2)) { 62 handler = new MetaDataHandlerV2(); 63 } else { 64 handler = new MetaDataHandlerV1(); 65 } 66 return handler; 67 } 68 69 public static EditDOM createEditDOM(MetaDataHandler h) { 70 EditDOM editDOM = null; 71 72 if (ToolBoxInfo.isXMLCVersion(2)) { 73 editDOM = new EditDOM((MetaData) h.getMetaData()); 74 } else { 75 Class editClass = null; 76 Class [] params = new Class [0]; 77 Constructor construct = null; 78 Method [] meths = new Method [0]; 79 Object [] values = new Object [0]; 80 81 try { 82 editClass = 83 Class.forName(XMLCConnectionFactory.EDIT_DOM_CLASS); 84 construct = editClass.getConstructor(params); 85 editDOM = (EditDOM) construct.newInstance(params); 86 meths = editClass.getMethods(); 87 for (int i = 0; i < meths.length; i++) { 88 if (meths[i].getName().equalsIgnoreCase(XMLCConnectionFactory.ADD_URL_EDITS_METHOD)) { 89 values = new Object [1]; 90 values[0] = h.getURLMappings(); 91 meths[i].invoke(editDOM, values); 92 break; 93 } 94 } 95 for (int i = 0; i < meths.length; i++) { 96 if (meths[i].getName().equalsIgnoreCase(XMLCConnectionFactory.ADD_DELETE_CLASSES_METHOD)) { 97 values = new Object [1]; 98 values[0] = h.getDeleteElements(); 99 meths[i].invoke(editDOM, values); 100 break; 101 } 102 } 103 } catch (Exception e) { 104 editClass = null; 105 e.printStackTrace(); 106 } 107 } 108 return editDOM; 109 } 110 111 public static PrintInfo createPrintInfo(Document doc, 112 XMLCDocument xmlcDoc) { 113 PrintInfo pi = null; 114 115 if (ToolBoxInfo.isXMLCVersion(2)) { 116 pi = new PrintInfoV2(doc, xmlcDoc); 117 } else { 118 pi = new PrintInfoV1(doc, xmlcDoc); 119 } 120 return pi; 121 } 122 123 public static Generator createGenerator(MetaDataHandler h, 124 XMLCDocument doc, 125 PrintWriter writer) throws XMLCException { 126 Generator gen = null; 127 128 if (ToolBoxInfo.isXMLCVersion(2)) { 129 gen = new GeneratorV2(h, doc, writer); 130 } else { 131 gen = new GeneratorV1(h, doc, writer); 132 } 133 return gen; 134 } 135 136 public static Parser createParser(PrintWriter traceWriter, 137 MetaDataHandler metaData) { 138 Parser parser = null; 139 140 if (ToolBoxInfo.isXMLCVersion(2)) { 141 parser = new ParserV2(traceWriter, metaData); 142 } else { 143 parser = new ParserV1(traceWriter, metaData); 144 } 145 return parser; 146 } 147 148 } 149 | Popular Tags |