KickJava   Java API By Example, From Geeks To Geeks.

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


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.XSSimpleType;
61 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets;
62 import com.sun.org.apache.xerces.internal.util.SymbolHash;
63 import com.sun.org.apache.xerces.internal.xs.XSConstants;
64
65 /**
66  * the factory to create/return built-in schema DVs and create user-defined DVs
67  *
68  * @author Neeraj Bajaj, Sun Microsystems, inc.
69  * @author Sandy Gao, IBM
70  *
71  * @version $Id: FullDVFactory.java,v 1.5 2003/11/12 23:17:32 sandygao Exp $
72  */

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

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

104     public SymbolHash getBuiltInTypes() {
105         return (SymbolHash)fFullTypes.makeClone();
106     }
107
108     // create all built-in types
109
static void createBuiltInTypes(SymbolHash types) {
110         // create base types first
111
BaseDVFactory.createBuiltInTypes(types);
112         
113         // full schema simple type names
114
final String JavaDoc DOUBLE = "double";
115         final String JavaDoc DURATION = "duration";
116         final String JavaDoc ENTITY = "ENTITY";
117         final String JavaDoc ENTITIES = "ENTITIES";
118         final String JavaDoc FLOAT = "float";
119         final String JavaDoc HEXBINARY = "hexBinary";
120         final String JavaDoc ID = "ID";
121         final String JavaDoc IDREF = "IDREF";
122         final String JavaDoc IDREFS = "IDREFS";
123         final String JavaDoc NAME = "Name";
124         final String JavaDoc NCNAME = "NCName";
125         final String JavaDoc NMTOKEN = "NMTOKEN";
126         final String JavaDoc NMTOKENS = "NMTOKENS";
127         final String JavaDoc LANGUAGE = "language";
128         final String JavaDoc NORMALIZEDSTRING = "normalizedString";
129         final String JavaDoc NOTATION = "NOTATION";
130         final String JavaDoc QNAME = "QName";
131         final String JavaDoc STRING = "string";
132         final String JavaDoc TOKEN = "token";
133
134         final XSFacets facets = new XSFacets();
135
136         XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType;
137         XSSimpleTypeDecl stringDV = (XSSimpleTypeDecl)types.get(STRING);
138
139         types.put(FLOAT, new XSSimpleTypeDecl(anySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT));
140         types.put(DOUBLE, new XSSimpleTypeDecl(anySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT));
141         types.put(DURATION, new XSSimpleTypeDecl(anySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT));
142         types.put(HEXBINARY, new XSSimpleTypeDecl(anySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT));
143         types.put(QNAME, new XSSimpleTypeDecl(anySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT));
144         types.put(NOTATION, new XSSimpleTypeDecl(anySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT));
145
146         facets.whiteSpace = XSSimpleType.WS_REPLACE;
147         XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT);
148         normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
149         types.put(NORMALIZEDSTRING, normalizedDV);
150
151         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
152         XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT);
153         tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 );
154         types.put(TOKEN, tokenDV);
155
156         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
157         facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*";
158         XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT);
159         languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0);
160         types.put(LANGUAGE, languageDV);
161
162         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
163         XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT);
164         nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME);
165         types.put(NAME, nameDV);
166
167         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
168         XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ;
169         ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME);
170         types.put(NCNAME, ncnameDV);
171
172         types.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT));
173         XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT);
174         types.put(IDREF, idrefDV);
175
176         facets.minLength = 1;
177         XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null);
178         XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
179         idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
180         types.put(IDREFS, idrefsDV);
181
182         XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT);
183         types.put(ENTITY, entityDV);
184
185         facets.minLength = 1;
186         tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null);
187         XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null);
188         entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
189         types.put(ENTITIES, entitiesDV);
190
191
192         facets.whiteSpace = XSSimpleType.WS_COLLAPSE;
193         XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT);
194         nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN);
195         types.put(NMTOKEN, nmtokenDV);
196
197         facets.minLength = 1;
198         tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null);
199         XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null);
200         nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0);
201         types.put(NMTOKENS, nmtokensDV);
202     }//createBuiltInTypes(SymbolHash)
203

204 }//XFormsDVFactory
205
Popular Tags