1 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.impl.xs.XSDeclarationPool; 64 import com.sun.org.apache.xerces.internal.xs.XSConstants; 65 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 66 import com.sun.org.apache.xerces.internal.util.SymbolHash; 67 68 76 public class SchemaDVFactoryImpl extends SchemaDVFactory { 77 78 static final String URI_SCHEMAFORSCHEMA = "http://www.w3.org/2001/XMLSchema"; 79 80 static SymbolHash fBuiltInTypes = new SymbolHash(); 81 static { 82 createBuiltInTypes(); 83 } 84 85 protected XSDeclarationPool fDeclPool = null; 86 87 98 public XSSimpleType getBuiltInType(String name) { 99 return (XSSimpleType)fBuiltInTypes.get(name); 100 } 101 102 108 public SymbolHash getBuiltInTypes() { 109 return (SymbolHash)fBuiltInTypes.makeClone(); 110 } 111 112 123 public XSSimpleType createTypeRestriction(String name, String targetNamespace, 124 short finalSet, XSSimpleType base, XSObjectList annotations) { 125 126 if (fDeclPool != null) { 127 XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl(); 128 return st.setRestrictionValues((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, annotations); 129 } 130 return new XSSimpleTypeDecl((XSSimpleTypeDecl)base, name, targetNamespace, finalSet, false, annotations); 131 } 132 133 144 public XSSimpleType createTypeList(String name, String targetNamespace, 145 short finalSet, XSSimpleType itemType, 146 XSObjectList annotations) { 147 if (fDeclPool != null) { 148 XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl(); 149 return st.setListValues(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, annotations); 150 } 151 return new XSSimpleTypeDecl(name, targetNamespace, finalSet, (XSSimpleTypeDecl)itemType, false, annotations); 152 } 153 154 165 public XSSimpleType createTypeUnion(String name, String targetNamespace, 166 short finalSet, XSSimpleType[] memberTypes, 167 XSObjectList annotations) { 168 int typeNum = memberTypes.length; 169 XSSimpleTypeDecl[] mtypes = new XSSimpleTypeDecl[typeNum]; 170 System.arraycopy(memberTypes, 0, mtypes, 0, typeNum); 171 172 if (fDeclPool != null) { 173 XSSimpleTypeDecl st= fDeclPool.getSimpleTypeDecl(); 174 return st.setUnionValues(name, targetNamespace, finalSet, mtypes, annotations); 175 } 176 return new XSSimpleTypeDecl(name, targetNamespace, finalSet, mtypes, annotations); 177 } 178 179 static void createBuiltInTypes() { 181 final String ANYSIMPLETYPE = "anySimpleType"; 183 final String ANYURI = "anyURI"; 184 final String BASE64BINARY = "base64Binary"; 185 final String BOOLEAN = "boolean"; 186 final String BYTE = "byte"; 187 final String DATE = "date"; 188 final String DATETIME = "dateTime"; 189 final String DAY = "gDay"; 190 final String DECIMAL = "decimal"; 191 final String DOUBLE = "double"; 192 final String DURATION = "duration"; 193 final String ENTITY = "ENTITY"; 194 final String ENTITIES = "ENTITIES"; 195 final String FLOAT = "float"; 196 final String HEXBINARY = "hexBinary"; 197 final String ID = "ID"; 198 final String IDREF = "IDREF"; 199 final String IDREFS = "IDREFS"; 200 final String INT = "int"; 201 final String INTEGER = "integer"; 202 final String LONG = "long"; 203 final String NAME = "Name"; 204 final String NEGATIVEINTEGER = "negativeInteger"; 205 final String MONTH = "gMonth"; 206 final String MONTHDAY = "gMonthDay"; 207 final String NCNAME = "NCName"; 208 final String NMTOKEN = "NMTOKEN"; 209 final String NMTOKENS = "NMTOKENS"; 210 final String LANGUAGE = "language"; 211 final String NONNEGATIVEINTEGER= "nonNegativeInteger"; 212 final String NONPOSITIVEINTEGER= "nonPositiveInteger"; 213 final String NORMALIZEDSTRING = "normalizedString"; 214 final String NOTATION = "NOTATION"; 215 final String POSITIVEINTEGER = "positiveInteger"; 216 final String QNAME = "QName"; 217 final String SHORT = "short"; 218 final String STRING = "string"; 219 final String TIME = "time"; 220 final String TOKEN = "token"; 221 final String UNSIGNEDBYTE = "unsignedByte"; 222 final String UNSIGNEDINT = "unsignedInt"; 223 final String UNSIGNEDLONG = "unsignedLong"; 224 final String UNSIGNEDSHORT = "unsignedShort"; 225 final String YEAR = "gYear"; 226 final String YEARMONTH = "gYearMonth"; 227 228 final XSFacets facets = new XSFacets(); 229 230 XSSimpleTypeDecl anySimpleType = XSSimpleTypeDecl.fAnySimpleType; 232 fBuiltInTypes.put(ANYSIMPLETYPE, anySimpleType); 233 XSSimpleTypeDecl stringDV = new XSSimpleTypeDecl(anySimpleType, STRING, XSSimpleTypeDecl.DV_STRING, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.STRING_DT); 234 fBuiltInTypes.put(STRING, stringDV); 235 fBuiltInTypes.put(BOOLEAN, new XSSimpleTypeDecl(anySimpleType, BOOLEAN, XSSimpleTypeDecl.DV_BOOLEAN, XSSimpleType.ORDERED_FALSE, false, true, false, true, XSConstants.BOOLEAN_DT)); 236 XSSimpleTypeDecl decimalDV = new XSSimpleTypeDecl(anySimpleType, DECIMAL, XSSimpleTypeDecl.DV_DECIMAL, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.DECIMAL_DT); 237 fBuiltInTypes.put(DECIMAL, decimalDV); 238 239 fBuiltInTypes.put(ANYURI, new XSSimpleTypeDecl(anySimpleType, ANYURI, XSSimpleTypeDecl.DV_ANYURI, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ANYURI_DT)); 240 fBuiltInTypes.put(BASE64BINARY, new XSSimpleTypeDecl(anySimpleType, BASE64BINARY, XSSimpleTypeDecl.DV_BASE64BINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.BASE64BINARY_DT)); 241 fBuiltInTypes.put(DURATION, new XSSimpleTypeDecl(anySimpleType, DURATION, XSSimpleTypeDecl.DV_DURATION, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DURATION_DT)); 242 fBuiltInTypes.put(DATETIME, new XSSimpleTypeDecl(anySimpleType, DATETIME, XSSimpleTypeDecl.DV_DATETIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATETIME_DT)); 243 fBuiltInTypes.put(TIME, new XSSimpleTypeDecl(anySimpleType, TIME, XSSimpleTypeDecl.DV_TIME, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.TIME_DT)); 244 fBuiltInTypes.put(DATE, new XSSimpleTypeDecl(anySimpleType, DATE, XSSimpleTypeDecl.DV_DATE, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.DATE_DT)); 245 fBuiltInTypes.put(YEARMONTH, new XSSimpleTypeDecl(anySimpleType, YEARMONTH, XSSimpleTypeDecl.DV_GYEARMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEARMONTH_DT)); 246 fBuiltInTypes.put(YEAR, new XSSimpleTypeDecl(anySimpleType, YEAR, XSSimpleTypeDecl.DV_GYEAR, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GYEAR_DT)); 247 fBuiltInTypes.put(MONTHDAY, new XSSimpleTypeDecl(anySimpleType, MONTHDAY, XSSimpleTypeDecl.DV_GMONTHDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTHDAY_DT)); 248 fBuiltInTypes.put(DAY, new XSSimpleTypeDecl(anySimpleType, DAY, XSSimpleTypeDecl.DV_GDAY, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GDAY_DT)); 249 fBuiltInTypes.put(MONTH, new XSSimpleTypeDecl(anySimpleType, MONTH, XSSimpleTypeDecl.DV_GMONTH, XSSimpleType.ORDERED_PARTIAL, false, false, false, true, XSConstants.GMONTH_DT)); 250 251 XSSimpleTypeDecl integerDV = new XSSimpleTypeDecl(decimalDV, INTEGER, XSSimpleTypeDecl.DV_INTEGER, XSSimpleType.ORDERED_TOTAL, false, false, true, true, XSConstants.INTEGER_DT); 252 fBuiltInTypes.put(INTEGER, integerDV); 253 254 facets.maxInclusive = "0"; 255 XSSimpleTypeDecl nonPositiveDV = new XSSimpleTypeDecl(integerDV, NONPOSITIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONPOSITIVEINTEGER_DT); 256 nonPositiveDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0); 257 fBuiltInTypes.put(NONPOSITIVEINTEGER, nonPositiveDV); 258 259 facets.maxInclusive = "-1"; 260 XSSimpleTypeDecl negativeDV = new XSSimpleTypeDecl(integerDV, NEGATIVEINTEGER, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NEGATIVEINTEGER_DT); 261 negativeDV.applyFacets1(facets , XSSimpleType.FACET_MAXINCLUSIVE, (short)0); 262 fBuiltInTypes.put(NEGATIVEINTEGER, negativeDV); 263 264 facets.maxInclusive = "9223372036854775807"; 265 facets.minInclusive = "-9223372036854775808"; 266 XSSimpleTypeDecl longDV = new XSSimpleTypeDecl(integerDV, LONG, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LONG_DT); 267 longDV.applyFacets1(facets , (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 ); 268 fBuiltInTypes.put(LONG, longDV); 269 270 271 facets.maxInclusive = "2147483647"; 272 facets.minInclusive = "-2147483648"; 273 XSSimpleTypeDecl intDV = new XSSimpleTypeDecl(longDV, INT, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.INT_DT); 274 intDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 ); 275 fBuiltInTypes.put(INT, intDV); 276 277 facets.maxInclusive = "32767"; 278 facets.minInclusive = "-32768"; 279 XSSimpleTypeDecl shortDV = new XSSimpleTypeDecl(intDV, SHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.SHORT_DT); 280 shortDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 ); 281 fBuiltInTypes.put(SHORT, shortDV); 282 283 facets.maxInclusive = "127"; 284 facets.minInclusive = "-128"; 285 XSSimpleTypeDecl byteDV = new XSSimpleTypeDecl(shortDV, BYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.BYTE_DT); 286 byteDV.applyFacets1(facets, (short)(XSSimpleType.FACET_MAXINCLUSIVE | XSSimpleType.FACET_MININCLUSIVE), (short)0 ); 287 fBuiltInTypes.put(BYTE, byteDV); 288 289 facets.minInclusive = "0" ; 290 XSSimpleTypeDecl nonNegativeDV = new XSSimpleTypeDecl(integerDV, NONNEGATIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NONNEGATIVEINTEGER_DT); 291 nonNegativeDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 ); 292 fBuiltInTypes.put(NONNEGATIVEINTEGER, nonNegativeDV); 293 294 facets.maxInclusive = "18446744073709551615" ; 295 XSSimpleTypeDecl unsignedLongDV = new XSSimpleTypeDecl(nonNegativeDV, UNSIGNEDLONG , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDLONG_DT); 296 unsignedLongDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 ); 297 fBuiltInTypes.put(UNSIGNEDLONG, unsignedLongDV); 298 299 facets.maxInclusive = "4294967295" ; 300 XSSimpleTypeDecl unsignedIntDV = new XSSimpleTypeDecl(unsignedLongDV, UNSIGNEDINT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDINT_DT); 301 unsignedIntDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 ); 302 fBuiltInTypes.put(UNSIGNEDINT, unsignedIntDV); 303 304 facets.maxInclusive = "65535" ; 305 XSSimpleTypeDecl unsignedShortDV = new XSSimpleTypeDecl(unsignedIntDV, UNSIGNEDSHORT , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDSHORT_DT); 306 unsignedShortDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 ); 307 fBuiltInTypes.put(UNSIGNEDSHORT, unsignedShortDV); 308 309 facets.maxInclusive = "255" ; 310 XSSimpleTypeDecl unsignedByteDV = new XSSimpleTypeDecl(unsignedShortDV, UNSIGNEDBYTE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.UNSIGNEDBYTE_DT); 311 unsignedByteDV.applyFacets1(facets, XSSimpleType.FACET_MAXINCLUSIVE, (short)0 ); 312 fBuiltInTypes.put(UNSIGNEDBYTE, unsignedByteDV); 313 314 facets.minInclusive = "1" ; 315 XSSimpleTypeDecl positiveIntegerDV = new XSSimpleTypeDecl(nonNegativeDV, POSITIVEINTEGER , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.POSITIVEINTEGER_DT); 316 positiveIntegerDV.applyFacets1(facets, XSSimpleType.FACET_MININCLUSIVE, (short)0 ); 317 fBuiltInTypes.put(POSITIVEINTEGER, positiveIntegerDV); 318 319 320 fBuiltInTypes.put(FLOAT, new XSSimpleTypeDecl(anySimpleType, FLOAT, XSSimpleTypeDecl.DV_FLOAT, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.FLOAT_DT)); 321 fBuiltInTypes.put(DOUBLE, new XSSimpleTypeDecl(anySimpleType, DOUBLE, XSSimpleTypeDecl.DV_DOUBLE, XSSimpleType.ORDERED_PARTIAL, true, true, true, true, XSConstants.DOUBLE_DT)); 322 fBuiltInTypes.put(HEXBINARY, new XSSimpleTypeDecl(anySimpleType, HEXBINARY, XSSimpleTypeDecl.DV_HEXBINARY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.HEXBINARY_DT)); 323 fBuiltInTypes.put(NOTATION, new XSSimpleTypeDecl(anySimpleType, NOTATION, XSSimpleTypeDecl.DV_NOTATION, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.NOTATION_DT)); 324 325 326 facets.whiteSpace = XSSimpleType.WS_REPLACE; 327 XSSimpleTypeDecl normalizedDV = new XSSimpleTypeDecl(stringDV, NORMALIZEDSTRING , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NORMALIZEDSTRING_DT); 328 normalizedDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 ); 329 fBuiltInTypes.put(NORMALIZEDSTRING, normalizedDV); 330 331 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 332 XSSimpleTypeDecl tokenDV = new XSSimpleTypeDecl(normalizedDV, TOKEN , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.TOKEN_DT); 333 tokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0 ); 334 fBuiltInTypes.put(TOKEN, tokenDV); 335 336 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 337 facets.pattern = "([a-zA-Z]{1,8})(-[a-zA-Z0-9]{1,8})*"; 338 XSSimpleTypeDecl languageDV = new XSSimpleTypeDecl(tokenDV, LANGUAGE , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.LANGUAGE_DT); 339 languageDV.applyFacets1(facets, (short)(XSSimpleType.FACET_WHITESPACE | XSSimpleType.FACET_PATTERN) ,(short)0); 340 fBuiltInTypes.put(LANGUAGE, languageDV); 341 342 343 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 344 XSSimpleTypeDecl nameDV = new XSSimpleTypeDecl(tokenDV, NAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NAME_DT); 345 nameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NAME); 346 fBuiltInTypes.put(NAME, nameDV); 347 348 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 349 XSSimpleTypeDecl ncnameDV = new XSSimpleTypeDecl(nameDV, NCNAME , URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NCNAME_DT) ; 350 ncnameDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NCNAME); 351 fBuiltInTypes.put(NCNAME, ncnameDV); 352 353 fBuiltInTypes.put(QNAME, new XSSimpleTypeDecl(anySimpleType, QNAME, XSSimpleTypeDecl.DV_QNAME, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.QNAME_DT)); 354 355 fBuiltInTypes.put(ID, new XSSimpleTypeDecl(ncnameDV, ID, XSSimpleTypeDecl.DV_ID, XSSimpleType.ORDERED_FALSE, false, false, false , true, XSConstants.ID_DT)); 356 XSSimpleTypeDecl idrefDV = new XSSimpleTypeDecl(ncnameDV, IDREF , XSSimpleTypeDecl.DV_IDREF, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.IDREF_DT); 357 fBuiltInTypes.put(IDREF, idrefDV); 358 359 facets.minLength = 1; 360 XSSimpleTypeDecl tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, idrefDV, true, null); 361 XSSimpleTypeDecl idrefsDV = new XSSimpleTypeDecl(tempDV, IDREFS, URI_SCHEMAFORSCHEMA, (short)0, false, null); 362 idrefsDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 363 fBuiltInTypes.put(IDREFS, idrefsDV); 364 365 XSSimpleTypeDecl entityDV = new XSSimpleTypeDecl(ncnameDV, ENTITY , XSSimpleTypeDecl.DV_ENTITY, XSSimpleType.ORDERED_FALSE, false, false, false, true, XSConstants.ENTITY_DT); 366 fBuiltInTypes.put(ENTITY, entityDV); 367 368 facets.minLength = 1; 369 tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, entityDV, true, null); 370 XSSimpleTypeDecl entitiesDV = new XSSimpleTypeDecl(tempDV, ENTITIES, URI_SCHEMAFORSCHEMA, (short)0, false, null); 371 entitiesDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 372 fBuiltInTypes.put(ENTITIES, entitiesDV); 373 374 375 facets.whiteSpace = XSSimpleType.WS_COLLAPSE; 376 XSSimpleTypeDecl nmtokenDV = new XSSimpleTypeDecl(tokenDV, NMTOKEN, URI_SCHEMAFORSCHEMA, (short)0, false, null, XSConstants.NMTOKEN_DT); 377 nmtokenDV.applyFacets1(facets, XSSimpleType.FACET_WHITESPACE, (short)0, XSSimpleTypeDecl.SPECIAL_PATTERN_NMTOKEN); 378 fBuiltInTypes.put(NMTOKEN, nmtokenDV); 379 380 facets.minLength = 1; 381 tempDV = new XSSimpleTypeDecl(null, URI_SCHEMAFORSCHEMA, (short)0, nmtokenDV, true, null); 382 XSSimpleTypeDecl nmtokensDV = new XSSimpleTypeDecl(tempDV, NMTOKENS, URI_SCHEMAFORSCHEMA, (short)0, false, null); 383 nmtokensDV.applyFacets1(facets, XSSimpleType.FACET_MINLENGTH, (short)0); 384 fBuiltInTypes.put(NMTOKENS, nmtokensDV); 385 } 387 public void setDeclPool (XSDeclarationPool declPool){ 388 fDeclPool = declPool; 389 } 390 391 } | Popular Tags |