KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > type > BuiltInSchemaFactory


1 package net.sf.saxon.type;
2 import net.sf.saxon.om.NamespaceConstant;
3 import net.sf.saxon.style.StandardNames;
4
5 import java.io.Serializable JavaDoc;
6 import java.util.HashMap JavaDoc;
7
8 /**
9  * This class is used to construct Schema objects containing all the built-in types:
10  * that is, the types defined in the "xs" and "xdt" namespaces.
11  */

12
13 public abstract class BuiltInSchemaFactory implements Serializable JavaDoc {
14
15     /**
16     * Define the type hierarchy
17     */

18
19     private static HashMap JavaDoc lookup = new HashMap JavaDoc(100);
20
21     private BuiltInSchemaFactory() {
22     }
23
24     static {
25
26         final String JavaDoc XS = NamespaceConstant.SCHEMA;
27         final String JavaDoc XDT = NamespaceConstant.XDT;
28
29         AnySimpleType anySimpleType = AnySimpleType.getInstance();
30         lookup.put(new Integer JavaDoc(StandardNames.XS_ANY_SIMPLE_TYPE), anySimpleType);
31
32         BuiltInAtomicType anyAtomicType =
33                 makeAtomicType(XDT, "anyAtomicType", anySimpleType);
34         BuiltInAtomicType numeric =
35                 makeAtomicType(XDT, "numeric", anyAtomicType);
36         BuiltInAtomicType string =
37                 makeAtomicType(XS, "string", anyAtomicType);
38         BuiltInAtomicType xsboolean =
39                 makeAtomicType(XS, "boolean", anyAtomicType);
40         BuiltInAtomicType duration =
41                 makeAtomicType(XS, "duration", anyAtomicType);
42         BuiltInAtomicType dateTime =
43                 makeAtomicType(XS, "dateTime", anyAtomicType);
44         BuiltInAtomicType date =
45                 makeAtomicType(XS, "date", anyAtomicType);
46         BuiltInAtomicType time =
47                 makeAtomicType(XS, "time", anyAtomicType);
48         BuiltInAtomicType gYearMonth =
49                 makeAtomicType(XS, "gYearMonth", anyAtomicType);
50         BuiltInAtomicType gMonth =
51                 makeAtomicType(XS, "gMonth", anyAtomicType);
52         BuiltInAtomicType gMonthDay =
53                 makeAtomicType(XS, "gMonthDay", anyAtomicType);
54         BuiltInAtomicType gYear =
55                 makeAtomicType(XS, "gYear", anyAtomicType);
56         BuiltInAtomicType gDay =
57                 makeAtomicType(XS, "gDay", anyAtomicType);
58         BuiltInAtomicType hexBinary =
59                 makeAtomicType(XS, "hexBinary", anyAtomicType);
60         BuiltInAtomicType base64Binary =
61                 makeAtomicType(XS, "base64Binary", anyAtomicType);
62         BuiltInAtomicType anyURI =
63                 makeAtomicType(XS, "anyURI", anyAtomicType);
64         BuiltInAtomicType qName =
65                 makeAtomicType(XS, "QName", anyAtomicType);
66         BuiltInAtomicType notation =
67                 makeAtomicType(XS, "NOTATION", anyAtomicType);
68
69         BuiltInAtomicType untypedAtomic =
70                 makeAtomicType(XDT, "untypedAtomic", anyAtomicType);
71
72         //SimpleType javaObject =
73
// makeSimpleType(NamespaceConstant.JAVA_TYPE, "java.lang.Object", anyAtomicType, Type.OBJECT);
74

75         BuiltInAtomicType decimal =
76                 makeAtomicType(XS, "decimal", numeric);
77         BuiltInAtomicType xsfloat =
78                 makeAtomicType(XS, "float", numeric);
79         BuiltInAtomicType xsdouble =
80                 makeAtomicType(XS, "double", numeric);
81
82         BuiltInAtomicType xsinteger =
83                 makeAtomicType(XS, "integer", decimal);
84
85         BuiltInAtomicType nonPositiveInteger =
86                 makeAtomicType(XS, "nonPositiveInteger", xsinteger);
87         BuiltInAtomicType negativeInteger =
88                 makeAtomicType(XS, "negativeInteger", nonPositiveInteger);
89         BuiltInAtomicType xslong =
90                 makeAtomicType(XS, "long", xsinteger);
91         BuiltInAtomicType xsint =
92                 makeAtomicType(XS, "int", xslong);
93         BuiltInAtomicType xsshort =
94                 makeAtomicType(XS, "short", xsint);
95         BuiltInAtomicType xsbyte =
96                 makeAtomicType(XS, "byte", xsshort);
97         BuiltInAtomicType nonNegativeInteger =
98                 makeAtomicType(XS, "nonNegativeInteger", xsinteger);
99         BuiltInAtomicType positiveInteger =
100                 makeAtomicType(XS, "positiveInteger", nonNegativeInteger);
101         BuiltInAtomicType unsignedLong =
102                 makeAtomicType(XS, "unsignedLong", nonNegativeInteger);
103         BuiltInAtomicType unsignedInt =
104                 makeAtomicType(XS, "unsignedInt", unsignedLong);
105         BuiltInAtomicType unsignedShort =
106                 makeAtomicType(XS, "unsignedShort", unsignedInt);
107         BuiltInAtomicType unsignedByte =
108                 makeAtomicType(XS, "unsignedByte", unsignedShort);
109
110         BuiltInAtomicType ymd =
111                 makeAtomicType(XDT, "yearMonthDuration", duration);
112         BuiltInAtomicType dtd =
113                 makeAtomicType(XDT, "dayTimeDuration", duration);
114
115         BuiltInAtomicType normalizedString =
116                 makeAtomicType(XS, "normalizedString", string);
117         BuiltInAtomicType token =
118                 makeAtomicType(XS, "token", normalizedString);
119         BuiltInAtomicType language =
120                 makeAtomicType(XS, "language", token);
121         BuiltInAtomicType name =
122                 makeAtomicType(XS, "Name", token);
123         BuiltInAtomicType nmtoken =
124                 makeAtomicType(XS, "NMTOKEN", token);
125         BuiltInAtomicType ncname =
126                 makeAtomicType(XS, "NCName", name);
127         BuiltInAtomicType id =
128                 makeAtomicType(XS, "ID", ncname);
129         BuiltInAtomicType idref =
130                 makeAtomicType(XS, "IDREF", ncname);
131         BuiltInAtomicType entity =
132                 makeAtomicType(XS, "ENTITY", ncname);
133
134         makeListType(XS, "NMTOKENS");
135         makeListType(XS, "IDREFS");
136         makeListType(XS, "ENTITIES");
137
138         lookup.put(new Integer JavaDoc(StandardNames.XS_ANY_TYPE), AnyType.getInstance());
139         lookup.put(new Integer JavaDoc(StandardNames.XDT_UNTYPED), Untyped.getInstance());
140     }
141
142     private static BuiltInAtomicType makeAtomicType(String JavaDoc namespace,
143                                              String JavaDoc lname,
144                                              SimpleType baseType) {
145         BuiltInAtomicType t = new BuiltInAtomicType(StandardNames.getFingerprint(namespace, lname));
146         t.setBaseTypeFingerprint(baseType.getFingerprint());
147         lookup.put(new Integer JavaDoc(t.getFingerprint()), t);
148         return t;
149     }
150
151     private static BuiltInListType makeListType(String JavaDoc namespace,
152                                            String JavaDoc lname) {
153         BuiltInListType t = new BuiltInListType(StandardNames.getFingerprint(namespace, lname));
154         lookup.put(new Integer JavaDoc(t.getFingerprint()), t);
155         return t;
156     }
157
158     public static SchemaType getSchemaType(int fingerprint) {
159         return (SchemaType)lookup.get(new Integer JavaDoc(fingerprint));
160     }
161
162
163 }
164
165 //
166
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
167
// you may not use this file except in compliance with the License. You may obtain a copy of the
168
// License at http://www.mozilla.org/MPL/
169
//
170
// Software distributed under the License is distributed on an "AS IS" basis,
171
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
172
// See the License for the specific language governing rights and limitations under the License.
173
//
174
// The Original Code is: all this file.
175
//
176
// The Initial Developer of the Original Code is Michael H. Kay
177
//
178
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
179
//
180
// Contributor(s): none.
181
//
182
Popular Tags