KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002, 2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 2001, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl.dv.xs;
59
60 import com.sun.org.apache.xerces.internal.impl.dv.SchemaDVFactory;
61 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType;
62 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;
63 import com.sun.org.apache.xerces.internal.xs.XSConstants;
64 import com.sun.org.apache.xerces.internal.xs.XSObjectList;
65 import com.sun.org.apache.xerces.internal.util.SymbolHash;
66
67 /**
68  * the factory to create/return built-in schema DVs and create user-defined DVs
69  *
70  * @author Neeraj Bajaj, Sun Microsystems, inc.
71  * @author Sandy Gao, IBM
72  *
73  * @version $Id: BaseDVFactory.java,v 1.5 2003/11/12 23:17:32 sandygao Exp $
74  */

75 public class BaseDVFactory extends SchemaDVFactory {
76
77     static final String JavaDoc URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema";
78
79     // there are 27 types. 53 is the closest prime number to 27*2=54.
80
static SymbolHash fBaseTypes = new SymbolHash(53);
81     static {
82         createBuiltInTypes(fBaseTypes);
83     }
84
85     /**
86      * Get a built-in simple type of the given name
87      * REVISIT: its still not decided within the Schema WG how to define the
88      * ur-types and if all simple types should be derived from a
89      * complex type, so as of now we ignore the fact that anySimpleType
90      * is derived from anyType, and pass 'null' as the base of
91      * anySimpleType. It needs to be changed as per the decision taken.
92      *
93      * @param name the name of the datatype
94      * @return the datatype validator of the given name
95      */

96     public XSSimpleType getBuiltInType(String JavaDoc name) {
97         return (XSSimpleType)fBaseTypes.get(name);
98     }
99
100     /**
101      * get all built-in simple types, which are stored in a hashtable keyed by
102      * the name
103      *
104      * @return a hashtable which contains all built-in simple types
105      */

106     public SymbolHash getBuiltInTypes() {
107         return (SymbolHash)fBaseTypes.makeClone();
108     }
109
110     /**
111      * Create a new simple type which is derived by restriction from another
112      * simple type.
113      *
114      * @param name name of the new type, could be null
115      * @param targetNamespace target namespace of the new type, could be null
116      * @param finalSet value of "final"
117      * @param base base type of the new type
118      * @param annotations set of annotations
119      * @return the newly created simple type
120      */

121     public XSSimpleType createTypeRestriction(String JavaDoc name, String JavaDoc targetNamespace,
122                                               short finalSet, XSSimpleType base, XSObjectList annotations) {
123         return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations);
124     }
125
126     /**
127      * Create a new simple type which is derived by list from another simple
128      * type.
129      *
130      * @param name name of the new type, could be null
131      * @param targetNamespace target namespace of the new type, could be null
132      * @param finalSet value of "final"
133      * @param itemType item type of the list type
134      * @param annotations set of annotations
135      * @return the newly created simple type
136      */

137     public XSSimpleType createTypeList(String JavaDoc name, String JavaDoc targetNamespace,
138                                        short finalSet, XSSimpleType itemType,
139                                        XSObjectList annotations) {
140         return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations);
141     }
142
143     /**
144      * Create a new simple type which is derived by union from a list of other
145      * simple types.
146      *
147      * @param name name of the new type, could be null
148      * @param targetNamespace target namespace of the new type, could be null
149      * @param finalSet value of "final"
150      * @param base member types of the union type
151      * @param annotations set of annotations
152      * @return the newly created simple type
153      */

154     public XSSimpleType createTypeUnion(String JavaDoc name, String JavaDoc targetNamespace,
155                                         short finalSet, XSSimpleType[] memberTypes,
156                                         XSObjectList annotations) {
157         int typeNum = memberTypes.length;
158         XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum];
159         System.arraycopy(memberTypes, 0, mtypes, 0, typeNum);
160
161         return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations);
162     }
163
164     // create all built-in types
165
static void createBuiltInTypes(SymbolHash types) {
166         // base schema simple type names
167
final String JavaDoc ANYSIMPLETYPE = "anySimpleType";
168         final String JavaDoc ANYURI = "anyURI";
169         final String JavaDoc BASE64BINARY = "base64Binary";
170         final String JavaDoc BOOLEAN = "boolean";
171         final String JavaDoc BYTE = "byte";
172         final String JavaDoc DATE = "date";
173         final String JavaDoc DATETIME = "dateTime";
174         final String JavaDoc DAY = "gDay";
175         final String JavaDoc DECIMAL = "decimal";
176         final String JavaDoc INT = "int";
177         final String JavaDoc INTEGER = "integer";
178         final String JavaDoc LONG = "long";
179         final String JavaDoc NEGATIVEINTEGER = "negativeInteger";
180         final String JavaDoc MONTH = "gMonth";
181         final String JavaDoc MONTHDAY = "gMonthDay";
182         final String JavaDoc NONNEGATIVEINTEGER= "nonNegativeInteger";
183         final String JavaDoc NONPOSITIVEINTEGER= "nonPositiveInteger";
184         final String JavaDoc POSITIVEINTEGER = "positiveInteger";
185         final String JavaDoc SHORT = "short";
186         final String JavaDoc STRING = "string";
187         final String JavaDoc TIME = "time";
188         final String JavaDoc UNSIGNEDBYTE = "unsignedByte";
189         final String JavaDoc UNSIGNEDINT = "unsignedInt";
190         final String JavaDoc UNSIGNEDLONG = "unsignedLong";
191         final String JavaDoc UNSIGNEDSHORT = "unsignedShort";
192         final String JavaDoc YEAR = "gYear";
193         final String JavaDoc YEARMONTH = "gYearMonth";
194
195         final XSFacets facets = new XSFacets();
196
197         XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
198         types.put(ANYSIMPLETYPE, anySimpleType);
199         XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(anySimpleType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.STRING_DT);
200         types.put(STRING, stringDV);
201         types.put(BOOLEAN, new XSSimpleTypeDecl(anySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT));
202         XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(anySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT);
203         types.put(DECIMAL, decimalDV);
204
205         types.put(ANYURI, new XSSimpleTypeDecl(anySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT));
206         types.put(BASE64BINARY, new XSSimpleTypeDecl(anySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT));
207         types.put(DATETIME, new XSSimpleTypeDecl(anySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT));
208         types.put(TIME, new XSSimpleTypeDecl(anySimpleType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT));
209         types.put(DATE, new XSSimpleTypeDecl(anySimpleType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT));
210         types.put(YEARMONTH, new XSSimpleTypeDecl(anySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT));
211         types.put(YEAR, new XSSimpleTypeDecl(anySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT));
212         types.put(MONTHDAY, new XSSimpleTypeDecl(anySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT));
213         types.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT));
214         types.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT));
215
216         XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT);
217         types.put(INTEGER, integerDV);
218
219         facets.maxInclusive = "0";
220         XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT);
221         nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
222         types.put(NONPOSITIVEINTEGER, nonPositiveDV);
223
224         facets.maxInclusive = "-1";
225         XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(integerDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT);
226         negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0);
227         types.put(NEGATIVEINTEGER, negativeDV);
228
229         facets.maxInclusive = "9223372036854775807";
230         facets.minInclusive = "-9223372036854775808";
231         XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT);
232         longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
233         types.put(LONG, longDV);
234
235
236         facets.maxInclusive = "2147483647";
237         facets.minInclusive = "-2147483648";
238         XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT);
239         intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
240         types.put(INT, intDV);
241
242         facets.maxInclusive = "32767";
243         facets.minInclusive = "-32768";
244         XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT);
245         shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
246         types.put(SHORT, shortDV);
247
248         facets.maxInclusive = "127";
249         facets.minInclusive = "-128";
250         XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT);
251         byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 );
252         types.put(BYTE, byteDV);
253
254         facets.minInclusive = "0" ;
255         XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT);
256         nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
257         types.put(NONNEGATIVEINTEGER, nonNegativeDV);
258
259         facets.maxInclusive = "18446744073709551615" ;
260         XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT);
261         unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
262         types.put(UNSIGNEDLONG, unsignedLongDV);
263
264         facets.maxInclusive = "4294967295" ;
265         XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT);
266         unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
267         types.put(UNSIGNEDINT, unsignedIntDV);
268
269         facets.maxInclusive = "65535" ;
270         XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT);
271         unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
272         types.put(UNSIGNEDSHORT, unsignedShortDV);
273
274         facets.maxInclusive = "255" ;
275         XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT);
276         unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 );
277         types.put(UNSIGNEDBYTE, unsignedByteDV);
278
279         facets.minInclusive = "1" ;
280         XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT);
281         positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 );
282         types.put(POSITIVEINTEGER, positiveIntegerDV);
283     }//createBuiltInTypes(SymbolHash)
284

285 }//BaseDVFactory
286
Popular Tags