001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: */
022:
023: package org.enhydra.kelp.common.bridge;
024:
025: // ToolBox imports
026: import org.enhydra.tool.ToolBoxInfo;
027:
028: // XMLC imports
029: import org.w3c.dom.Document;
030: import org.enhydra.xml.xmlc.dom.XMLCDocument;
031: import org.enhydra.xml.xmlc.XMLCException;
032: import org.enhydra.xml.xmlc.compiler.EditDOM;
033: import org.enhydra.xml.xmlc.metadata.MetaData;
034:
035: // Standard imports
036: import java.io.PrintWriter;
037: import java.lang.reflect.Constructor;
038: import java.lang.reflect.Method;
039:
040: //
041: public class XMLCConnectionFactory {
042:
043: // string not to be resourced
044: private static final String EDIT_DOM_CLASS = "org.enhydra.xml.xmlc.compiler.EditDOM"; // nores
045: private static final String ADD_URL_EDITS_METHOD = "addURLEdits"; // nores
046: private static final String ADD_DELETE_CLASSES_METHOD = "addDeleteClasses"; // nores
047:
048: //
049: public XMLCConnectionFactory() {
050: }
051:
052: public static MetaDataHandler createMetaDataHandler() {
053: MetaDataHandler handler = null;
054:
055: if (ToolBoxInfo.isXMLCVersion(2)) {
056: handler = new MetaDataHandlerV2();
057: } else {
058: handler = new MetaDataHandlerV1();
059: }
060: return handler;
061: }
062:
063: public static EditDOM createEditDOM(MetaDataHandler h) {
064: EditDOM editDOM = null;
065:
066: if (ToolBoxInfo.isXMLCVersion(2)) {
067: editDOM = new EditDOM((MetaData) h.getMetaData());
068: } else {
069: Class editClass = null;
070: Class[] params = new Class[0];
071: Constructor construct = null;
072: Method[] meths = new Method[0];
073: Object[] values = new Object[0];
074:
075: try {
076: editClass = Class
077: .forName(XMLCConnectionFactory.EDIT_DOM_CLASS);
078: construct = editClass.getConstructor(params);
079: editDOM = (EditDOM) construct.newInstance(params);
080: meths = editClass.getMethods();
081: for (int i = 0; i < meths.length; i++) {
082: if (meths[i].getName().equalsIgnoreCase(
083: XMLCConnectionFactory.ADD_URL_EDITS_METHOD)) {
084: values = new Object[1];
085: values[0] = h.getURLMappings();
086: meths[i].invoke(editDOM, values);
087: break;
088: }
089: }
090: for (int i = 0; i < meths.length; i++) {
091: if (meths[i]
092: .getName()
093: .equalsIgnoreCase(
094: XMLCConnectionFactory.ADD_DELETE_CLASSES_METHOD)) {
095: values = new Object[1];
096: values[0] = h.getDeleteElements();
097: meths[i].invoke(editDOM, values);
098: break;
099: }
100: }
101: } catch (Exception e) {
102: editClass = null;
103: e.printStackTrace();
104: }
105: }
106: return editDOM;
107: }
108:
109: public static PrintInfo createPrintInfo(Document doc,
110: XMLCDocument xmlcDoc) {
111: PrintInfo pi = null;
112:
113: if (ToolBoxInfo.isXMLCVersion(2)) {
114: pi = new PrintInfoV2(doc, xmlcDoc);
115: } else {
116: pi = new PrintInfoV1(doc, xmlcDoc);
117: }
118: return pi;
119: }
120:
121: public static Generator createGenerator(MetaDataHandler h,
122: XMLCDocument doc, PrintWriter writer) throws XMLCException {
123: Generator gen = null;
124:
125: if (ToolBoxInfo.isXMLCVersion(2)) {
126: gen = new GeneratorV2(h, doc, writer);
127: } else {
128: gen = new GeneratorV1(h, doc, writer);
129: }
130: return gen;
131: }
132:
133: public static Parser createParser(PrintWriter traceWriter,
134: MetaDataHandler metaData) {
135: Parser parser = null;
136:
137: if (ToolBoxInfo.isXMLCVersion(2)) {
138: parser = new ParserV2(traceWriter, metaData);
139: } else {
140: parser = new ParserV1(traceWriter, metaData);
141: }
142: return parser;
143: }
144:
145: }
|