KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > xs > BaseDVFactory


1 /*
2  * Copyright 2002, 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.xerces.impl.dv.xs;
18
19 import org.apache.xerces.impl.dv.SchemaDVFactory;
20 import org.apache.xerces.impl.dv.XSSimpleType;
21 import org.apache.xerces.impl.dv.XSFacets;
22 import org.apache.xerces.xs.XSConstants;
23 import org.apache.xerces.xs.XSObjectList;
24 import org.apache.xerces.util.SymbolHash;
25
26 /**
27  * the factory to create/return built-in schema DVs and create user-defined DVs
28  *
29  * @xerces.internal
30  *
31  * @author Neeraj Bajaj, Sun Microsystems, inc.
32  * @author Sandy Gao, IBM
33  *
34  * @version $Id: BaseDVFactory.java,v 1.8 2004/10/06 14:56:47 mrglavas Exp $
35  */

36 public class BaseDVFactory extends SchemaDVFactory {
37
38     static final String JavaDoc URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
39
40     // there are 27 types. 53 is the closest prime number to 27*2=54.
41
static SymbolHash fBaseTypes = new SymbolHash(53);
42     static {
43         createBuiltInTypes(fBaseTypes);
44     }
45
46     /**
47      * Get a built-in simple type of the given name
48      * REVISIT: its still not decided within the Schema WG how to define the
49      * ur-types and if all simple types should be derived from a
50      * complex type, so as of now we ignore the fact that anySimpleType
51      * is derived from anyType, and pass 'null' as the base of
52      * anySimpleType. It needs to be changed as per the decision taken.
53      *
54      * @param name the name of the datatype
55      * @return the datatype validator of the given name
56      */

57     public XSSimpleType getBuiltInType(String JavaDoc name) {
58         return (XSSimpleType)fBaseTypes.get(name);
59     }
60
61     /**
62      * get all built-in simple types, which are stored in a hashtable keyed by
63      * the name
64      *
65      * @return a hashtable which contains all built-in simple types
66      */

67     public SymbolHash getBuiltInTypes() {
68         return (SymbolHash)fBaseTypes.makeClone();
69     }
70
71     /**
72      * Create a new simple type which is derived by restriction from another
73      * simple type.
74      *
75      * @param name name of the new type, could be null
76      * @param targetNamespace target namespace of the new type, could be null
77      * @param finalSet value of "final"
78      * @param base base type of the new type
79      * @param annotations set of annotations
80      * @return the newly created simple type
81      */

82     public XSSimpleType createTypeRestriction(String JavaDoc name, String JavaDoc targetNamespace,
83                                               short finalSet, XSSimpleType base, XSObjectList annotations) {
84         return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
85     }
86
87     /**
88      * Create a new simple type which is derived by list from another simple
89      * type.
90      *
91      * @param name name of the new type, could be null
92      * @param targetNamespace target namespace of the new type, could be null
93      * @param finalSet value of "final"
94      * @param itemType item type of the list type
95      * @param annotations set of annotations
96      * @return the newly created simple type
97      */

98     public XSSimpleType createTypeList(String JavaDoc name, String JavaDoc targetNamespace,
99                                        short finalSet, XSSimpleType itemType,
100                                        XSObjectList annotations) {
101         return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
102     }
103
104     /**
105      * Create a new simple type which is derived by union from a list of other
106      * simple types.
107      *
108      * @param name name of the new type, could be null
109      * @param targetNamespace target namespace of the new type, could be null
110      * @param finalSet value of "final"
111      * @param memberTypes member types of the union type
112      * @param annotations set of annotations
113      * @return the newly created simple type
114      */

115     public XSSimpleType createTypeUnion(String JavaDoc name, String JavaDoc targetNamespace,
116                                         short finalSet, XSSimpleType[] memberTypes,
117                                         XSObjectList annotations) {
118         int typeNum = memberTypes.length;
119         XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
120         System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
121
122         return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
123     }
124
125     // create all built-in types
126
static void createBuiltInTypes(SymbolHash types) {
127         // base schema simple type names
128
final String JavaDoc ANYSIMPLETYPE = "anySimpleType";
129         final String JavaDoc ANYURI = "anyURI";
130         final String JavaDoc BASE64BINARY = "base64Binary";
131         final String JavaDoc BOOLEAN = "boolean";
132         final String JavaDoc BYTE = "byte";
133         final String JavaDoc DATE = "date";
134         final String JavaDoc DATETIME = "dateTime";
135         final String JavaDoc DAY = "gDay";
136         final String JavaDoc DECIMAL = "decimal";
137         final String JavaDoc INT = "int";
138         final String JavaDoc INTEGER = "integer";
139         final String JavaDoc LONG = "long";
140         final String JavaDoc NEGATIVEINTEGER = "negativeInteger";
141         final String JavaDoc MONTH = "gMonth";
142         final String JavaDoc MONTHDAY = "gMonthDay";
143         final String JavaDoc NONNEGATIVEINTEGER= "nonNegativeInteger";
144         final String JavaDoc NONPOSITIVEINTEGER= "nonPositiveInteger";
145         final String JavaDoc POSITIVEINTEGER = "positiveInteger";
146         final String JavaDoc SHORT = "short";
147         final String JavaDoc STRING = "string";
148         final String JavaDoc TIME = "time";
149         final String JavaDoc UNSIGNEDBYTE = "unsignedByte";
150         final String JavaDoc UNSIGNEDINT = "unsignedInt";
151         final String JavaDoc UNSIGNEDLONG = "unsignedLong";
152         final String JavaDoc UNSIGNEDSHORT = "unsignedShort";
153         final String JavaDoc YEAR = "gYear";
154         final String JavaDoc YEARMONTH = "gYearMonth";
155
156         final XSFacets facets = new XSFacets();
157
158         XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
159         types.put(ANYSIMPLETYPE, anySimpleType);
160         XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(anySimpleType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.STRING_DT);
161         types.put(STRING, stringDV);
162         types.put(BOOLEAN, new XSSimpleTypeDecl(anySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT));
163         XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(anySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT);
164         types.put(DECIMAL, decimalDV);
165
166         types.put(ANYURI, new XSSimpleTypeDecl(anySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT));
167         types.put(BASE64BINARY, new XSSimpleTypeDecl(anySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT));
168         types.put(DATETIME, new XSSimpleTypeDecl(anySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT));
169         types.put(TIME, new XSSimpleTypeDecl(anySimpleType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT));
170         types.put(DATE, new XSSimpleTypeDecl(anySimpleType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT));
171         types.put(YEARMONTH, new XSSimpleTypeDecl(anySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT));
172         types.put(YEAR, new XSSimpleTypeDecl(anySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT));
173         types.put(MONTHDAY, new XSSimpleTypeDecl(anySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT));
174         types.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT));
175         types.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT));
176
177         XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT);
178         types.put(INTEGER, integerDV);
179
180         facets.maxInclusive = "0";
181         XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT);
182         nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
183         types.put(NONPOSITIVEINTEGER, nonPositiveDV);
184
185         facets.maxInclusive = "-1";
186         XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(integerDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT);
187         negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
188         types.put(NEGATIVEINTEGER, negativeDV);
189
190         facets.maxInclusive = "9223372036854775807";
191         facets.minInclusive = "-9223372036854775808";
192         XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT);
193         longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
194         types.put(LONG, longDV);
195
196
197         facets.maxInclusive = "2147483647";
198         facets.minInclusive = "-2147483648";
199         XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT);
200         intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
201         types.put(INT, intDV);
202
203         facets.maxInclusive = "32767";
204         facets.minInclusive = "-32768";
205         XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT);
206         shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
207         types.put(SHORT, shortDV);
208
209         facets.maxInclusive = "127";
210         facets.minInclusive = "-128";
211         XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT);
212         byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
213         types.put(BYTE, byteDV);
214
215         facets.minInclusive = "0" ;
216         XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT);
217         nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
218         types.put(NONNEGATIVEINTEGER, nonNegativeDV);
219
220         facets.maxInclusive = "18446744073709551615" ;
221         XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT);
222         unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
223         types.put(UNSIGNEDLONG, unsignedLongDV);
224
225         facets.maxInclusive = "4294967295" ;
226         XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT);
227         unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
228         types.put(UNSIGNEDINT, unsignedIntDV);
229
230         facets.maxInclusive = "65535" ;
231         XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT);
232         unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
233         types.put(UNSIGNEDSHORT, unsignedShortDV);
234
235         facets.maxInclusive = "255" ;
236         XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT);
237         unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
238         types.put(UNSIGNEDBYTE, unsignedByteDV);
239
240         facets.minInclusive = "1" ;
241         XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT);
242         positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
243         types.put(POSITIVEINTEGER, positiveIntegerDV);
244     }//createBuiltInTypes(SymbolHash)
245

246 }//BaseDVFactory
247
Popular Tags