KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > bridge > XMLCConnectionFactory


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22
23 package org.enhydra.kelp.common.bridge;
24
25 // ToolBox imports
26
import org.enhydra.tool.ToolBoxInfo;
27
28 // XMLC imports
29
import org.w3c.dom.Document JavaDoc;
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 // Kelp imports
36
import org.enhydra.kelp.KelpInfo;
37 import org.enhydra.kelp.common.node.OtterXMLCNode;
38 import org.enhydra.kelp.common.node.OtterProject;
39
40 // Standard imports
41
import java.io.PrintWriter JavaDoc;
42 import java.lang.reflect.Constructor JavaDoc;
43 import java.lang.reflect.Method JavaDoc;
44
45 //
46
public class XMLCConnectionFactory {
47
48     // string not to be resourced
49
private static final String JavaDoc EDIT_DOM_CLASS =
50         "org.enhydra.xml.xmlc.compiler.EditDOM"; // nores
51
private static final String JavaDoc ADD_URL_EDITS_METHOD = "addURLEdits"; // nores
52
private static final String JavaDoc ADD_DELETE_CLASSES_METHOD =
53         "addDeleteClasses"; // nores
54

55     //
56
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 JavaDoc editClass = null;
76             Class JavaDoc[] params = new Class JavaDoc[0];
77             Constructor JavaDoc construct = null;
78             Method JavaDoc[] meths = new Method JavaDoc[0];
79             Object JavaDoc[] values = new Object JavaDoc[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 JavaDoc[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 JavaDoc[1];
98                         values[0] = h.getDeleteElements();
99                         meths[i].invoke(editDOM, values);
100                         break;
101                     }
102                 }
103             } catch (Exception JavaDoc e) {
104                 editClass = null;
105                 e.printStackTrace();
106             }
107         }
108         return editDOM;
109     }
110
111     public static PrintInfo createPrintInfo(Document JavaDoc 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 JavaDoc 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 JavaDoc 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