KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > DOMType


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  * $Id: DOMType.java,v 1.2 2003/08/02 05:02:48 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 /**
27  * Enumerated type for the predefined DOM factories.
28  */

29 public class DOMType extends EnumeratedType {
30     /**
31      * Constant for LazyDOM.
32      */

33     public static final DOMType LAZYDOM
34         = new DOMType("lazydom",
35                       org.enhydra.xml.xmlc.dom.lazydom.LazyDomFactory.class,
36                       org.enhydra.xml.xmlc.dom.lazydom.LazyHTMLDomFactory.class);
37
38     /**
39      * Constant for Xerces DOM.
40      */

41     public static final DOMType XERCES
42         = new DOMType("xerces",
43                       org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory.class,
44                       org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDomFactory.class);
45
46
47     /**
48      * Constant for genric DOM.
49      */

50     // FIXME: Check if xerces DOM really is generic enough...
51
public static final DOMType GENERIC
52         = new DOMType("generic",
53                       org.enhydra.xml.xmlc.dom.xerces.XercesDomFactory.class,
54                       org.enhydra.xml.xmlc.dom.xerces.XercesHTMLDomFactory.class);
55
56     /**
57      * Constant for XHTML DOM.
58      */

59     public static DOMType XHTML;
60
61     /**
62      * Constant for WML DOM.
63      */

64     public static DOMType WML;
65     
66     /**
67      * Constant for VoiceXML DOM.
68      */

69     public static DOMType VOICEXML;
70     
71     /**
72      * Constant for cHTML DOM.
73      */

74     public static DOMType CHTML;
75
76     // Initialize the optional DOM types
77
static {
78     try {
79         XHTML = new DOMType("xhtml",
80                 Class.forName("org.enhydra.xml.xhtml.XHTMLDomFactory"),
81                 Class.forName("org.enhydra.xml.xhtml.HTMLDomFactory"));
82     } catch (ClassNotFoundException JavaDoc e) { XHTML = null; }
83
84     try {
85         WML = new DOMType("wml",
86                   Class.forName("org.enhydra.wireless.wml.WMLDomFactory"),
87                   null);
88     } catch (ClassNotFoundException JavaDoc e) { WML = null; }
89
90     try {
91         VOICEXML = new DOMType("voicexml",
92                    Class.forName("org.enhydra.wireless.voicexml.VoiceXMLDomFactory"),
93                    null);
94
95     } catch (ClassNotFoundException JavaDoc e) { VOICEXML = null; }
96
97     try {
98         CHTML = new DOMType("chtml",
99                 null,
100                 Class.forName("org.enhydra.wireless.chtml.CHTMLDomFactory"));
101     } catch (ClassNotFoundException JavaDoc e) { CHTML = null; }
102     }
103
104     /**
105      * XML DOM factory class for this type.
106      */

107     private final Class JavaDoc fXMLDomFactoryClass;
108
109     /**
110      * HTML DOM factory class for this type.
111      */

112     private final Class JavaDoc fHTMLDomFactoryClass;
113
114     /**
115      * Internal constructor. Only a fixed set of types are allowed.
116      */

117     private DOMType(String JavaDoc name,
118                     Class JavaDoc xmlDomFactoryClass,
119                     Class JavaDoc htmlDomFactoryClass) {
120         super(name);
121         fXMLDomFactoryClass = xmlDomFactoryClass;
122         fHTMLDomFactoryClass = htmlDomFactoryClass;
123     }
124
125     /**
126      * Get the XML DOM factory class for this type.
127      */

128     public Class JavaDoc getXMLDomFactoryClass() {
129         return fXMLDomFactoryClass;
130     }
131
132     /**
133      * Get the HTML DOM factory class for this type.
134      */

135     public Class JavaDoc getHTMLDomFactoryClass() {
136         return fHTMLDomFactoryClass;
137     }
138
139     /**
140      * Get the object for the specified type. If desiredType is null,
141      * return null.
142      */

143     public static DOMType getType(String JavaDoc desiredType) {
144         if (desiredType == null) {
145             return null;
146         } else if (LAZYDOM.fName.equals(desiredType)) {
147             return LAZYDOM;
148         } else if (XERCES.fName.equals(desiredType)) {
149             return XERCES;
150         } else if (XHTML != null && XHTML.fName.equals(desiredType)) {
151             return XHTML;
152         } else if (CHTML != null && CHTML.fName.equals(desiredType)) {
153             return CHTML;
154         } else if (VOICEXML != null && VOICEXML.fName.equals(desiredType)) {
155             return VOICEXML;
156         } else if (WML != null && WML.fName.equals(desiredType)) {
157             return WML;
158         } else {
159             throw new IllegalArgumentException JavaDoc(
160                "Invalid DOMType: \""
161                + desiredType
162                + "\", expected one of \""
163                + (XHTML!=null?XHTML.fName + "\", \"":"")
164                + (WML!=null?WML.fName + "\", \"":"")
165                + (VOICEXML!=null?VOICEXML.fName + "\", \"":"")
166                + (CHTML!=null?CHTML.fName + "\", \"":"")
167                + LAZYDOM.fName + "\" or \""
168                + XERCES.fName);
169         }
170     }
171 }
172
Popular Tags