KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > mathml > MathMLDocumentImpl


1 package JSci.mathml;
2
3 import java.lang.reflect.*;
4 import java.util.Hashtable JavaDoc;
5 import org.w3c.dom.*;
6 import org.w3c.dom.mathml.*;
7 import org.apache.xerces.dom.DocumentImpl;
8 import org.apache.xerces.dom.DocumentTypeImpl;
9
10 /**
11  * Implements a MathML document.
12  * @version 1.0
13  * @author Mark Hale
14  */

15 public class MathMLDocumentImpl extends DocumentImpl implements MathMLDocument {
16         private static final String JavaDoc DOCTYPE_PUBLIC = "-//W3C//DTD MathML 2.0//EN";
17         private static final String JavaDoc DOCTYPE_SYSTEM = "http://www.w3.org/TR/MathML2/dtd/mathml2.dtd";
18         private static final Hashtable JavaDoc _elementTypesMathML;
19         private static final Class JavaDoc[] _elemClassSigMathML = new Class JavaDoc [] {MathMLDocumentImpl.class, String JavaDoc.class};
20
21         static {
22                 _elementTypesMathML = new Hashtable JavaDoc(160);
23                 _elementTypesMathML.put("math", MathMLMathElementImpl.class);
24                 _elementTypesMathML.put("annotation", MathMLAnnotationElementImpl.class);
25                 _elementTypesMathML.put("xml-annotation", MathMLXMLAnnotationElementImpl.class);
26                 // presentation
27
_elementTypesMathML.put("mi", MathMLPresentationTokenImpl.class);
28                 _elementTypesMathML.put("mn", MathMLPresentationTokenImpl.class);
29                 _elementTypesMathML.put("msub", MathMLScriptElementImpl.class);
30                 _elementTypesMathML.put("msup", MathMLScriptElementImpl.class);
31                 _elementTypesMathML.put("msubsup", MathMLScriptElementImpl.class);
32                 _elementTypesMathML.put("munder", MathMLUnderOverElementImpl.class);
33                 _elementTypesMathML.put("mover", MathMLUnderOverElementImpl.class);
34                 _elementTypesMathML.put("munderover", MathMLUnderOverElementImpl.class);
35                 _elementTypesMathML.put("mfrac", MathMLFractionElementImpl.class);
36                 _elementTypesMathML.put("msqrt", MathMLRadicalElementImpl.class);
37                 _elementTypesMathML.put("mroot", MathMLRadicalElementImpl.class);
38                 _elementTypesMathML.put("mrow", MathMLPresentationContainerImpl.class);
39                 _elementTypesMathML.put("mpadded", MathMLPaddedElementImpl.class);
40                 _elementTypesMathML.put("mfenced", MathMLFencedElementImpl.class);
41                 _elementTypesMathML.put("menclose", MathMLEncloseElementImpl.class);
42                 _elementTypesMathML.put("mglyph", MathMLGlyphElementImpl.class);
43                 _elementTypesMathML.put("maligngroup", MathMLAlignGroupElementImpl.class);
44                 _elementTypesMathML.put("malignmark", MathMLAlignMarkElementImpl.class);
45                 _elementTypesMathML.put("mtext", MathMLPresentationTokenImpl.class);
46                 _elementTypesMathML.put("mspace", MathMLSpaceElementImpl.class);
47                 _elementTypesMathML.put("ms", MathMLStringLitElementImpl.class);
48                 _elementTypesMathML.put("mphantom", MathMLPresentationContainerImpl.class);
49                 _elementTypesMathML.put("maction", MathMLActionElementImpl.class);
50                 _elementTypesMathML.put("merror", MathMLPresentationContainerImpl.class);
51                 // content
52
_elementTypesMathML.put("apply", MathMLApplyElementImpl.class);
53                 _elementTypesMathML.put("ci", MathMLCiElementImpl.class);
54                 _elementTypesMathML.put("cn", MathMLCnElementImpl.class);
55                 _elementTypesMathML.put("csymbol", MathMLCsymbolElementImpl.class);
56                 _elementTypesMathML.put("bvar", MathMLBvarElementImpl.class);
57                 _elementTypesMathML.put("condition", MathMLConditionElementImpl.class);
58                 _elementTypesMathML.put("uplimit", MathMLContentContainerImpl.class);
59                 _elementTypesMathML.put("lowlimit", MathMLContentContainerImpl.class);
60                 _elementTypesMathML.put("domainofapplication", MathMLContentContainerImpl.class);
61                 _elementTypesMathML.put("degree", MathMLContentContainerImpl.class);
62                 _elementTypesMathML.put("otherwise", MathMLContentContainerImpl.class);
63                 // matrices
64
_elementTypesMathML.put("vector", MathMLVectorElementImpl.class);
65                 _elementTypesMathML.put("matrix", MathMLMatrixElementImpl.class);
66                 _elementTypesMathML.put("matrixrow", MathMLMatrixrowElementImpl.class);
67                 // arithmetic
68
_elementTypesMathML.put("plus", MathMLNaryOpImpl.class);
69                 _elementTypesMathML.put("minus", MathMLBinaryOpImpl.class);
70                 _elementTypesMathML.put("times", MathMLNaryOpImpl.class);
71                 _elementTypesMathML.put("divide", MathMLBinaryOpImpl.class);
72                 _elementTypesMathML.put("quotient", MathMLBinaryOpImpl.class);
73                 _elementTypesMathML.put("rem", MathMLBinaryOpImpl.class);
74                 _elementTypesMathML.put("power", MathMLBinaryOpImpl.class);
75                 _elementTypesMathML.put("root", MathMLFunctionImpl.class);
76                 _elementTypesMathML.put("min", MathMLPredefinedSymbolImpl.class);
77                 _elementTypesMathML.put("max", MathMLPredefinedSymbolImpl.class);
78                 _elementTypesMathML.put("gcd", MathMLPredefinedSymbolImpl.class);
79                 _elementTypesMathML.put("lcm", MathMLPredefinedSymbolImpl.class);
80                 _elementTypesMathML.put("floor", MathMLFunctionImpl.class);
81                 _elementTypesMathML.put("ceiling", MathMLFunctionImpl.class);
82                 _elementTypesMathML.put("factorial", MathMLUnaryOpImpl.class);
83                 _elementTypesMathML.put("conjugate", MathMLUnaryOpImpl.class);
84                 _elementTypesMathML.put("abs", MathMLFunctionImpl.class);
85                 _elementTypesMathML.put("arg", MathMLFunctionImpl.class);
86                 _elementTypesMathML.put("real", MathMLFunctionImpl.class);
87                 _elementTypesMathML.put("imaginary", MathMLFunctionImpl.class);
88                 // calculus
89
_elementTypesMathML.put("int", MathMLUnaryOpImpl.class);
90                 _elementTypesMathML.put("diff", MathMLUnaryOpImpl.class);
91                 _elementTypesMathML.put("partialdiff", MathMLUnaryOpImpl.class);
92                 _elementTypesMathML.put("divergence", MathMLUnaryOpImpl.class);
93                 _elementTypesMathML.put("grad", MathMLUnaryOpImpl.class);
94                 _elementTypesMathML.put("curl", MathMLUnaryOpImpl.class);
95                 _elementTypesMathML.put("laplacian", MathMLUnaryOpImpl.class);
96                 // functional
97
_elementTypesMathML.put("inverse", MathMLUnaryOpImpl.class);
98                 _elementTypesMathML.put("compose", MathMLPredefinedSymbolImpl.class);
99                 _elementTypesMathML.put("ident", MathMLPredefinedSymbolImpl.class);
100                 _elementTypesMathML.put("domain", MathMLPredefinedSymbolImpl.class);
101                 _elementTypesMathML.put("codomain", MathMLPredefinedSymbolImpl.class);
102                 _elementTypesMathML.put("image", MathMLPredefinedSymbolImpl.class);
103                 // sequences
104
_elementTypesMathML.put("sum", MathMLPredefinedSymbolImpl.class);
105                 _elementTypesMathML.put("product", MathMLPredefinedSymbolImpl.class);
106                 _elementTypesMathML.put("limit", MathMLPredefinedSymbolImpl.class);
107                 _elementTypesMathML.put("tendsto", MathMLTendsToElementImpl.class);
108                 // logic
109
_elementTypesMathML.put("and", MathMLNaryOpImpl.class);
110                 _elementTypesMathML.put("or", MathMLNaryOpImpl.class);
111                 _elementTypesMathML.put("xor", MathMLNaryOpImpl.class);
112                 _elementTypesMathML.put("not", MathMLUnaryOpImpl.class);
113                 _elementTypesMathML.put("implies", MathMLBinaryRelImpl.class);
114                 _elementTypesMathML.put("forall", MathMLPredefinedSymbolImpl.class);
115                 _elementTypesMathML.put("exists", MathMLPredefinedSymbolImpl.class);
116                 // relations
117
_elementTypesMathML.put("eq", MathMLNaryRelImpl.class);
118                 _elementTypesMathML.put("neq", MathMLBinaryRelImpl.class);
119                 _elementTypesMathML.put("gt", MathMLNaryRelImpl.class);
120                 _elementTypesMathML.put("lt", MathMLNaryRelImpl.class);
121                 _elementTypesMathML.put("geq", MathMLNaryRelImpl.class);
122                 _elementTypesMathML.put("leq", MathMLNaryRelImpl.class);
123                 _elementTypesMathML.put("equivalent", MathMLNaryRelImpl.class);
124                 _elementTypesMathML.put("approx", MathMLBinaryRelImpl.class);
125                 _elementTypesMathML.put("factorof", MathMLBinaryRelImpl.class);
126                 // set theory
127
_elementTypesMathML.put("set", MathMLSetElementImpl.class);
128                 _elementTypesMathML.put("list", MathMLListElementImpl.class);
129                 _elementTypesMathML.put("union", MathMLNaryOpImpl.class);
130                 _elementTypesMathML.put("intersect", MathMLNaryOpImpl.class);
131                 _elementTypesMathML.put("cartesianproduct", MathMLNaryOpImpl.class);
132                 _elementTypesMathML.put("in", MathMLBinaryRelImpl.class);
133                 _elementTypesMathML.put("notin", MathMLBinaryRelImpl.class);
134                 _elementTypesMathML.put("subset", MathMLNaryRelImpl.class);
135                 _elementTypesMathML.put("prsubset", MathMLNaryRelImpl.class);
136                 _elementTypesMathML.put("notsubset", MathMLBinaryRelImpl.class);
137                 _elementTypesMathML.put("notprsubset", MathMLBinaryRelImpl.class);
138                 _elementTypesMathML.put("setdiff", MathMLBinaryOpImpl.class);
139                 _elementTypesMathML.put("card", MathMLFunctionImpl.class);
140                 // functions
141
_elementTypesMathML.put("exp", MathMLFunctionImpl.class);
142                 _elementTypesMathML.put("ln", MathMLFunctionImpl.class);
143                 _elementTypesMathML.put("log", MathMLFunctionImpl.class);
144                 // trig functions
145
_elementTypesMathML.put("sin", MathMLFunctionImpl.class);
146                 _elementTypesMathML.put("cos", MathMLFunctionImpl.class);
147                 _elementTypesMathML.put("tan", MathMLFunctionImpl.class);
148                 _elementTypesMathML.put("csc", MathMLFunctionImpl.class);
149                 _elementTypesMathML.put("sec", MathMLFunctionImpl.class);
150                 _elementTypesMathML.put("cot", MathMLFunctionImpl.class);
151                 _elementTypesMathML.put("sinh", MathMLFunctionImpl.class);
152                 _elementTypesMathML.put("cosh", MathMLFunctionImpl.class);
153                 _elementTypesMathML.put("tanh", MathMLFunctionImpl.class);
154                 _elementTypesMathML.put("csch", MathMLFunctionImpl.class);
155                 _elementTypesMathML.put("sech", MathMLFunctionImpl.class);
156                 _elementTypesMathML.put("coth", MathMLFunctionImpl.class);
157                 _elementTypesMathML.put("arcsin", MathMLFunctionImpl.class);
158                 _elementTypesMathML.put("arccos", MathMLFunctionImpl.class);
159                 _elementTypesMathML.put("arctan", MathMLFunctionImpl.class);
160                 _elementTypesMathML.put("arccsc", MathMLFunctionImpl.class);
161                 _elementTypesMathML.put("arcsec", MathMLFunctionImpl.class);
162                 _elementTypesMathML.put("arccot", MathMLFunctionImpl.class);
163                 _elementTypesMathML.put("arcsinh", MathMLFunctionImpl.class);
164                 _elementTypesMathML.put("arccosh", MathMLFunctionImpl.class);
165                 _elementTypesMathML.put("arctanh", MathMLFunctionImpl.class);
166                 _elementTypesMathML.put("arccsch", MathMLFunctionImpl.class);
167                 _elementTypesMathML.put("arcsech", MathMLFunctionImpl.class);
168                 _elementTypesMathML.put("arccoth", MathMLFunctionImpl.class);
169                 // statistics
170
_elementTypesMathML.put("mean", MathMLPredefinedSymbolImpl.class);
171                 _elementTypesMathML.put("mode", MathMLPredefinedSymbolImpl.class);
172                 _elementTypesMathML.put("median", MathMLPredefinedSymbolImpl.class);
173                 _elementTypesMathML.put("moment", MathMLPredefinedSymbolImpl.class);
174                 _elementTypesMathML.put("momentabout", MathMLContentContainerImpl.class);
175                 _elementTypesMathML.put("sdev", MathMLPredefinedSymbolImpl.class);
176                 _elementTypesMathML.put("variance", MathMLPredefinedSymbolImpl.class);
177                 // linear algebra
178
_elementTypesMathML.put("determinant", MathMLFunctionImpl.class);
179                 _elementTypesMathML.put("transpose", MathMLUnaryOpImpl.class);
180                 _elementTypesMathML.put("selector", MathMLPredefinedSymbolImpl.class);
181                 _elementTypesMathML.put("vectorproduct", MathMLBinaryOpImpl.class);
182                 _elementTypesMathML.put("scalarproduct", MathMLBinaryOpImpl.class);
183                 _elementTypesMathML.put("outerproduct", MathMLBinaryOpImpl.class);
184                 // symbols
185
_elementTypesMathML.put("integers", MathMLPredefinedSymbolImpl.class);
186                 _elementTypesMathML.put("reals", MathMLPredefinedSymbolImpl.class);
187                 _elementTypesMathML.put("rationals", MathMLPredefinedSymbolImpl.class);
188                 _elementTypesMathML.put("naturalnumbers", MathMLPredefinedSymbolImpl.class);
189                 _elementTypesMathML.put("complexes", MathMLPredefinedSymbolImpl.class);
190                 _elementTypesMathML.put("primes", MathMLPredefinedSymbolImpl.class);
191                 _elementTypesMathML.put("exponentiale", MathMLPredefinedSymbolImpl.class);
192                 _elementTypesMathML.put("imaginaryi", MathMLPredefinedSymbolImpl.class);
193                 _elementTypesMathML.put("notanumber", MathMLPredefinedSymbolImpl.class);
194                 _elementTypesMathML.put("true", MathMLPredefinedSymbolImpl.class);
195                 _elementTypesMathML.put("false", MathMLPredefinedSymbolImpl.class);
196                 _elementTypesMathML.put("emptyset", MathMLPredefinedSymbolImpl.class);
197                 _elementTypesMathML.put("pi", MathMLPredefinedSymbolImpl.class);
198                 _elementTypesMathML.put("eulergamma", MathMLPredefinedSymbolImpl.class);
199                 _elementTypesMathML.put("infinity", MathMLPredefinedSymbolImpl.class);
200                 // deprecated
201
_elementTypesMathML.put("fn", MathMLFnElementImpl.class);
202                 _elementTypesMathML.put("reln", MathMLContentContainerImpl.class);
203         }
204
205         public MathMLDocumentImpl() {
206                 super();
207         }
208
209         public DocumentType getDoctype() {
210                 if (docType == null) {
211                         docType = new DocumentTypeImpl(this, "math", DOCTYPE_PUBLIC, DOCTYPE_SYSTEM);
212                 }
213                 return docType;
214         }
215
216         public Element getDocumentElement() {
217                 Node math;
218
219                 math = super.getDocumentElement();
220                 if (math == null) {
221                         math = new MathMLMathElementImpl(this, "math");
222                         appendChild(math);
223                 }
224                 return (Element) math;
225         }
226
227         /** Xerces specific */
228         public Element createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName, String JavaDoc localpart) throws DOMException {
229                 return createElementNS(namespaceURI, qualifiedName);
230         }
231
232         public Element createElementNS(String JavaDoc namespaceURI, String JavaDoc qualifiedName) throws DOMException {
233                 if (MathMLElementImpl.mathmlURI.equals(namespaceURI)) {
234                         String JavaDoc localName;
235                         Class JavaDoc elemClass;
236                         Constructor cnst;
237
238                         int index = qualifiedName.indexOf(':');
239                         if (index < 0) {
240                                 localName = qualifiedName;
241                         } else {
242                                 localName = qualifiedName.substring(index+1);
243                         }
244
245                         elemClass = (Class JavaDoc) _elementTypesMathML.get(localName);
246                         if (elemClass != null) {
247                                 try {
248                                         cnst = elemClass.getConstructor(_elemClassSigMathML);
249                                         return (Element) cnst.newInstance(new Object JavaDoc[] {this, qualifiedName});
250                                 } catch (Exception JavaDoc except) {
251                                         Throwable JavaDoc thrw;
252
253                                         if (except instanceof InvocationTargetException) {
254                                                 thrw = ((InvocationTargetException) except).getTargetException();
255                                         } else {
256                                                 thrw = except;
257                                         }
258
259                                         System.out.println("Exception " + thrw.getClass().getName());
260                                         System.out.println(thrw.getMessage());
261
262                                         throw new IllegalStateException JavaDoc("Tag '" + qualifiedName + "' associated with an Element class that failed to construct.");
263                                 }
264                         } else {
265                                 return new MathMLElementImpl(this, qualifiedName);
266                         }
267                 } else {
268                         return super.createElementNS(namespaceURI, qualifiedName);
269                 }
270         }
271
272         public String JavaDoc getReferrer() {
273                 return null;
274         }
275         public String JavaDoc getDomain() {
276                 return null;
277         }
278         public String JavaDoc getURI() {
279                 return null;
280         }
281 }
282
283
Popular Tags