KickJava   Java API By Example, From Geeks To Geeks.

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


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.XSSimpleType;
20 import org.apache.xerces.impl.dv.XSFacets;
21 import org.apache.xerces.util.SymbolHash;
22 import org.apache.xerces.xs.XSConstants;
23
24 /**
25  * the factory to create/return built-in schema DVs and create user-defined DVs
26  *
27  * @xerces.internal
28  *
29  * @author Neeraj Bajaj, Sun Microsystems, inc.
30  * @author Sandy Gao, IBM
31  *
32  * @version $Id: FullDVFactory.java,v 1.7 2004/10/06 14:56:47 mrglavas Exp $
33  */

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

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

65     public SymbolHash getBuiltInTypes() {
66         return (SymbolHash)fFullTypes.makeClone();
67     }
68
69     // create all built-in types
70
static void createBuiltInTypes(SymbolHash types) {
71         // create base types first
72
BaseDVFactory.createBuiltInTypes(types);
73         
74         // full schema simple type names
75
final String JavaDoc DOUBLE = "double";
76         final String JavaDoc DURATION = "duration";
77         final String JavaDoc ENTITY = "ENTITY";
78         final String JavaDoc ENTITIES = "ENTITIES";
79         final String JavaDoc FLOAT = "float";
80         final String JavaDoc HEXBINARY = "hexBinary";
81         final String JavaDoc ID = "ID";
82         final String JavaDoc IDREF = "IDREF";
83         final String JavaDoc IDREFS = "IDREFS";
84         final String JavaDoc NAME = "Name";
85         final String JavaDoc NCNAME = "NCName";
86         final String JavaDoc NMTOKEN = "NMTOKEN";
87         final String JavaDoc NMTOKENS = "NMTOKENS";
88         final String JavaDoc LANGUAGE = "language";
89         final String JavaDoc NORMALIZEDSTRING = "normalizedString";
90         final String JavaDoc NOTATION = "NOTATION";
91         final String JavaDoc QNAME = "QName";
92         final String JavaDoc STRING = "string";
93         final String JavaDoc TOKEN = "token";
94
95         final XSFacets facets = new XSFacets();
96
97         XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
98         XSSimpleTypeDecl stringDV = (XSSimpleTypeDecl)types.get(STRING);
99
100         types.put(FLOAT, new XSSimpleTypeDecl(anySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT));
101         types.put(DOUBLE, new XSSimpleTypeDecl(anySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT));
102         types.put(DURATION, new XSSimpleTypeDecl(anySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT));
103         types.put(HEXBINARY, new XSSimpleTypeDecl(anySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT));
104         types.put(QNAME, new XSSimpleTypeDecl(anySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT));
105         types.put(NOTATION, new XSSimpleTypeDecl(anySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT));
106
107         facets.whiteSpace = XSSimpleType.WS_REPLACE;
108         XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT);
109         normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
110         types.put(NORMALIZEDSTRING, normalizedDV);
111
112         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
113         XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT);
114         tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
115         types.put(TOKEN, tokenDV);
116
117         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
118         facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*";
119         XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT);
120         languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0);
121         types.put(LANGUAGE, languageDV);
122
123         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
124         XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT);
125         nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME);
126         types.put(NAME, nameDV);
127
128         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
129         XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ;
130         ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME);
131         types.put(NCNAME, ncnameDV);
132
133         types.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT));
134         XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT);
135         types.put(IDREF, idrefDV);
136
137         facets.minLength = 1;
138         XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null);
139         XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
140         idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
141         types.put(IDREFS, idrefsDV);
142
143         XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT);
144         types.put(ENTITY, entityDV);
145
146         facets.minLength = 1;
147         tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null);
148         XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null);
149         entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
150         types.put(ENTITIES, entitiesDV);
151
152
153         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
154         XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT);
155         nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN);
156         types.put(NMTOKEN, nmtokenDV);
157
158         facets.minLength = 1;
159         tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null);
160         XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
161         nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
162         types.put(NMTOKENS, nmtokensDV);
163     }//createBuiltInTypes(SymbolHash)
164

165 }//XFormsDVFactory
166
Popular Tags