KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > wireless > voicexml > dom > xerces > VoiceXMLDocumentImpl


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 Original Code is DigitalSesame
15  * Portions created by DigitalSesame are Copyright (C) 1997-2000 DigitalSesame
16  * All Rights Reserved.
17  *
18  * Contributor(s):
19  *
20  * $Id: VoiceXMLDocumentImpl.java,v 1.4 2005/01/26 08:28:45 jkjome Exp $
21  */

22
23 package org.enhydra.wireless.voicexml.dom.xerces;
24
25 import java.lang.reflect.Constructor JavaDoc;
26 import java.util.Hashtable JavaDoc;
27
28 import org.enhydra.apache.xerces.dom.DocumentImpl;
29 import org.enhydra.wireless.voicexml.dom.VoiceXMLDocument;
30 import org.enhydra.xml.xmlc.XMLCError;
31 import org.enhydra.xml.xmlc.XMLObject;
32 import org.enhydra.xml.xmlc.XMLObjectLink;
33 import org.w3c.dom.DOMException JavaDoc;
34 import org.w3c.dom.DOMImplementation JavaDoc;
35 import org.w3c.dom.DocumentType JavaDoc;
36 import org.w3c.dom.Element JavaDoc;
37
38 public class VoiceXMLDocumentImpl extends DocumentImpl implements VoiceXMLDocument, XMLObjectLink {
39
40     private static Hashtable JavaDoc fElementTypes;
41     private static final Class JavaDoc[] fElemConstructorSig
42         = new Class JavaDoc[] {VoiceXMLDocumentImpl.class, String JavaDoc.class, String JavaDoc.class};
43
44     /**
45      * overload in order to return the correct dom implementation for VoiceXML
46      * @see org.enhydra.apache.xerces.dom.DocumentImpl#getImplementation
47      */

48     public DOMImplementation JavaDoc getImplementation() {
49         return VoiceXMLDOMImplementationImpl.getDOMImplementation();
50     }
51
52     public Element JavaDoc createElementNS(String JavaDoc namespaceURI,
53                                    String JavaDoc qualifiedName) throws DOMException JavaDoc {
54         // FIXME: should be a common method for doing this
55
int index = qualifiedName.indexOf(':');
56         String JavaDoc tagName;
57         if (index < 0) {
58             tagName = qualifiedName;
59         } else {
60             tagName = qualifiedName.substring(index+1);
61         }
62         Class JavaDoc elemClass = (Class JavaDoc)fElementTypes.get(tagName);
63         if (elemClass != null) {
64             try {
65                 Constructor JavaDoc cnst = elemClass.getConstructor(fElemConstructorSig);
66                 return (Element JavaDoc)cnst.newInstance(new Object JavaDoc[] {this, namespaceURI, qualifiedName});
67             } catch (Exception JavaDoc except) {
68                 // Need more specific error..
69
throw new XMLCError("failed to construct element for \""
70                                     + qualifiedName + "\"", except);
71             }
72         } else {
73             return new VoiceXMLElementImpl(this, null, tagName);
74         }
75     }
76
77     public Element JavaDoc createElement(String JavaDoc tagName) throws DOMException JavaDoc {
78         return createElementNS(null, tagName);
79     }
80
81     static {
82     fElementTypes = new Hashtable JavaDoc();
83     fElementTypes.put("exit", VoiceXMLExitElementImpl.class);
84     fElementTypes.put("script", VoiceXMLScriptElementImpl.class);
85     fElementTypes.put("link", VoiceXMLLinkElementImpl.class);
86     fElementTypes.put("param", VoiceXMLParamElementImpl.class);
87     fElementTypes.put("meta", VoiceXMLMetaElementImpl.class);
88     fElementTypes.put("field", VoiceXMLFieldElementImpl.class);
89     fElementTypes.put("enumerate", VoiceXMLEnumerateElementImpl.class);
90     fElementTypes.put("block", VoiceXMLBlockElementImpl.class);
91     fElementTypes.put("throw", VoiceXMLThrowElementImpl.class);
92     fElementTypes.put("subdialog", VoiceXMLSubdialogElementImpl.class);
93     fElementTypes.put("pros", VoiceXMLProsElementImpl.class);
94     fElementTypes.put("else", VoiceXMLElseElementImpl.class);
95     fElementTypes.put("goto", VoiceXMLGotoElementImpl.class);
96     fElementTypes.put("submit", VoiceXMLSubmitElementImpl.class);
97     fElementTypes.put("audio", VoiceXMLAudioElementImpl.class);
98     fElementTypes.put("sayas", VoiceXMLSayasElementImpl.class);
99     fElementTypes.put("var", VoiceXMLVarElementImpl.class);
100     fElementTypes.put("break", VoiceXMLBreakElementImpl.class);
101     fElementTypes.put("error", VoiceXMLErrorElementImpl.class);
102     fElementTypes.put("emp", VoiceXMLEmpElementImpl.class);
103     fElementTypes.put("transfer", VoiceXMLTransferElementImpl.class);
104     fElementTypes.put("help", VoiceXMLHelpElementImpl.class);
105     fElementTypes.put("noinput", VoiceXMLNoinputElementImpl.class);
106     fElementTypes.put("if", VoiceXMLIfElementImpl.class);
107     fElementTypes.put("choice", VoiceXMLChoiceElementImpl.class);
108     fElementTypes.put("form", VoiceXMLFormElementImpl.class);
109     fElementTypes.put("clear", VoiceXMLClearElementImpl.class);
110     fElementTypes.put("nomatch", VoiceXMLNomatchElementImpl.class);
111     fElementTypes.put("option", VoiceXMLOptionElementImpl.class);
112     fElementTypes.put("filled", VoiceXMLFilledElementImpl.class);
113     fElementTypes.put("record", VoiceXMLRecordElementImpl.class);
114     fElementTypes.put("elseif", VoiceXMLElseifElementImpl.class);
115     fElementTypes.put("object", VoiceXMLObjectElementImpl.class);
116     fElementTypes.put("value", VoiceXMLValueElementImpl.class);
117     fElementTypes.put("prompt", VoiceXMLPromptElementImpl.class);
118     fElementTypes.put("property", VoiceXMLPropertyElementImpl.class);
119     fElementTypes.put("grammar", VoiceXMLGrammarElementImpl.class);
120     fElementTypes.put("vxml", VoiceXMLVxmlElementImpl.class);
121     fElementTypes.put("disconnect", VoiceXMLDisconnectElementImpl.class);
122     fElementTypes.put("assign", VoiceXMLAssignElementImpl.class);
123     fElementTypes.put("catch", VoiceXMLCatchElementImpl.class);
124     fElementTypes.put("return", VoiceXMLReturnElementImpl.class);
125     fElementTypes.put("div", VoiceXMLDivElementImpl.class);
126     fElementTypes.put("menu", VoiceXMLMenuElementImpl.class);
127     fElementTypes.put("reprompt", VoiceXMLRepromptElementImpl.class);
128     fElementTypes.put("initial", VoiceXMLInitialElementImpl.class);
129     fElementTypes.put("dtmf", VoiceXMLDtmfElementImpl.class);
130     }
131     
132     /* DOM level 2 */
133     public VoiceXMLDocumentImpl(DocumentType JavaDoc doctype) {
134         super(doctype, false);
135     }
136
137     //-------------------------------------------------------------------------
138
// XMLObjectLink implementation
139
//-------------------------------------------------------------------------
140

141     /**
142      * Reference to XMLObject containing this Document.
143      */

144     private XMLObject fXmlObjectLink;
145
146     /**
147      * @see XMLObjectLink#setXMLObject
148      */

149     public void setXMLObject(XMLObject xmlObject) {
150         fXmlObjectLink = xmlObject;
151     }
152
153     /**
154      * @see XMLObjectLink#getXMLObject
155      */

156     public XMLObject getXMLObject() {
157         return fXmlObjectLink;
158     }
159
160 }
161
Popular Tags