1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2002, 2003,2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.dv.xs; 22 23 import com.sun.org.apache.xerces.internal.impl.dv.XSSimpleType; 24 import com.sun.org.apache.xerces.internal.impl.dv.XSFacets; 25 import com.sun.org.apache.xerces.internal.util.SymbolHash; 26 import com.sun.org.apache.xerces.internal.xs.XSConstants; 27 28 /** 29 * the factory to create/return built-in schema DVs and create user-defined DVs 30 * 31 * @xerces.internal 32 * 33 * @author Neeraj Bajaj, Sun Microsystems, inc. 34 * @author Sandy Gao, IBM 35 * 36 */ 37 public class FullDVFactory extends BaseDVFactory { 38 39 static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema"; 40 41 // there are 45 types. 89 is the closest prime number to 45*2=90. 42 static SymbolHash fFullTypes = new SymbolHash(89); 43 static { 44 createBuiltInTypes(fFullTypes); 45 } 46 47 /** 48 * Get a built-in simple type of the given name 49 * REVISIT: its still not decided within the Schema WG how to define the 50 * ur-types and if all simple types should be derived from a 51 * complex type, so as of now we ignore the fact that anySimpleType 52 * is derived from anyType, and pass 'null' as the base of 53 * anySimpleType. It needs to be changed as per the decision taken. 54 * 55 * @param name the name of the datatype 56 * @return the datatype validator of the given name 57 */ 58 public XSSimpleType getBuiltInType(String name) { 59 return (XSSimpleType)fFullTypes.get(name); 60 } 61 62 /** 63 * get all built-in simple types, which are stored in a hashtable keyed by 64 * the name 65 * 66 * @return a hashtable which contains all built-in simple types 67 */ 68 public SymbolHash getBuiltInTypes() { 69 return (SymbolHash)fFullTypes.makeClone(); 70 } 71 72 // create all built-in types 73 static void createBuiltInTypes(SymbolHash types) { 74 // create base types first 75 BaseDVFactory.createBuiltInTypes(types); 76 77 // full schema simple type names 78 final String DOUBLE = "double"; 79 final String DURATION = "duration"; 80 final String ENTITY = "ENTITY"; 81 final String ENTITIES = "ENTITIES"; 82 final String FLOAT = "float"; 83 final String HEXBINARY = "hexBinary"; 84 final String ID = "ID"; 85 final String IDREF = "IDREF"; 86 final String IDREFS = "IDREFS"; 87 final String NAME = "Name"; 88 final String NCNAME = "NCName"; 89 final String NMTOKEN = "NMTOKEN"; 90 final String NMTOKENS = "NMTOKENS"; 91 final String LANGUAGE = "language"; 92 final String NORMALIZEDSTRING = "normalizedString"; 93 final String NOTATION = "NOTATION"; 94 final String QNAME = "QName"; 95 final String STRING = "string"; 96 final String TOKEN = "token"; 97 98 final XSFacets facets = new XSFacets(); 99 100 XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType; 101 XSSimpleTypeDecl stringDV = (XSSimpleTypeDecl)types.get(STRING); 102 103 types.put(FLOAT, new XSSimpleTypeDecl(anySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT)); 104 types.put(DOUBLE, new XSSimpleTypeDecl(anySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT)); 105 types.put(DURATION, new XSSimpleTypeDecl(anySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT)); 106 types.put(HEXBINARY, new XSSimpleTypeDecl(anySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT)); 107 types.put(QNAME, new XSSimpleTypeDecl(anySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT)); 108 types.put(NOTATION, new XSSimpleTypeDecl(anySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT)); 109 110 facets.whiteSpace = XSSimpleType.WS_REPLACE; 111 XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT); 112 normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 ); 113 types.put(NORMALIZEDSTRING, normalizedDV); 114 115 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 116 XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT); 117 tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 ); 118 types.put(TOKEN, tokenDV); 119 120 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 121 facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*"; 122 XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT); 123 languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0); 124 types.put(LANGUAGE, languageDV); 125 126 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 127 XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT); 128 nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME); 129 types.put(NAME, nameDV); 130 131 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 132 XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ; 133 ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME); 134 types.put(NCNAME, ncnameDV); 135 136 types.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT)); 137 XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT); 138 types.put(IDREF, idrefDV); 139 140 facets.minLength = 1; 141 XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null); 142 XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null); 143 idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 144 types.put(IDREFS, idrefsDV); 145 146 XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT); 147 types.put(ENTITY, entityDV); 148 149 facets.minLength = 1; 150 tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null); 151 XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null); 152 entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 153 types.put(ENTITIES, entitiesDV); 154 155 156 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 157 XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT); 158 nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN); 159 types.put(NMTOKEN, nmtokenDV); 160 161 facets.minLength = 1; 162 tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null); 163 XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null); 164 nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 165 types.put(NMTOKENS, nmtokensDV); 166 }//createBuiltInTypes(SymbolHash) 167 168 }//XFormsDVFactory