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