GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: DatatypeValidatorFactory.cpp 932887 2010-04-11 13:04:59Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/validators/datatype/DatatypeValidatorFactory.hpp> 00027 #include <xercesc/validators/schema/SchemaSymbols.hpp> 00028 #include <xercesc/util/XMLUniDefs.hpp> 00029 #include <xercesc/util/Janitor.hpp> 00030 #include <xercesc/validators/datatype/StringDatatypeValidator.hpp> 00031 #include <xercesc/validators/datatype/BooleanDatatypeValidator.hpp> 00032 #include <xercesc/validators/datatype/DecimalDatatypeValidator.hpp> 00033 #include <xercesc/validators/datatype/HexBinaryDatatypeValidator.hpp> 00034 #include <xercesc/validators/datatype/Base64BinaryDatatypeValidator.hpp> 00035 #include <xercesc/validators/datatype/IDDatatypeValidator.hpp> 00036 #include <xercesc/validators/datatype/IDREFDatatypeValidator.hpp> 00037 #include <xercesc/validators/datatype/NOTATIONDatatypeValidator.hpp> 00038 #include <xercesc/validators/datatype/ENTITYDatatypeValidator.hpp> 00039 #include <xercesc/validators/datatype/QNameDatatypeValidator.hpp> 00040 #include <xercesc/validators/datatype/NameDatatypeValidator.hpp> 00041 #include <xercesc/validators/datatype/NCNameDatatypeValidator.hpp> 00042 #include <xercesc/validators/datatype/ListDatatypeValidator.hpp> 00043 #include <xercesc/validators/datatype/UnionDatatypeValidator.hpp> 00044 #include <xercesc/validators/datatype/DoubleDatatypeValidator.hpp> 00045 #include <xercesc/validators/datatype/FloatDatatypeValidator.hpp> 00046 #include <xercesc/validators/datatype/AnyURIDatatypeValidator.hpp> 00047 #include <xercesc/validators/datatype/AnySimpleTypeDatatypeValidator.hpp> 00048 #include <xercesc/validators/datatype/DateTimeDatatypeValidator.hpp> 00049 #include <xercesc/validators/datatype/DateDatatypeValidator.hpp> 00050 #include <xercesc/validators/datatype/TimeDatatypeValidator.hpp> 00051 #include <xercesc/validators/datatype/DayDatatypeValidator.hpp> 00052 #include <xercesc/validators/datatype/MonthDatatypeValidator.hpp> 00053 #include <xercesc/validators/datatype/MonthDayDatatypeValidator.hpp> 00054 #include <xercesc/validators/datatype/YearDatatypeValidator.hpp> 00055 #include <xercesc/validators/datatype/YearMonthDatatypeValidator.hpp> 00056 #include <xercesc/validators/datatype/DurationDatatypeValidator.hpp> 00057 #include <xercesc/util/PlatformUtils.hpp> 00058 #include <xercesc/util/XMLInitializer.hpp> 00059 00060 #include <xercesc/internal/XTemplateSerializer.hpp> 00061 00062 XERCES_CPP_NAMESPACE_BEGIN 00063 00064 00065 // --------------------------------------------------------------------------- 00066 // DatatypeValidatorFactory: Local const data 00067 // --------------------------------------------------------------------------- 00068 const XMLCh fgTokPattern[] = 00069 { 00070 chBackSlash, chLatin_c, chPlus, chNull 00071 }; 00072 00073 //E2-43 00074 //[+\-]?[0-9]+ 00075 const XMLCh fgIntegerPattern[] = 00076 { 00077 chOpenSquare, chPlus, chBackSlash, chDash, chCloseSquare, chQuestion, 00078 chOpenSquare, chDigit_0, chDash, chDigit_9, chCloseSquare, chPlus, chNull 00079 }; 00080 00081 //"\\i\\c*" 00082 const XMLCh fgNamePattern[] = 00083 { 00084 chBackSlash, chLatin_i, chBackSlash, chLatin_c, chAsterisk, chNull 00085 }; 00086 00087 //"[\\i-[:]][\\c-[:]]*" 00088 const XMLCh fgNCNamePattern[] = 00089 { 00090 chOpenSquare, chBackSlash, chLatin_i, chDash, chOpenSquare, chColon, chCloseSquare, 00091 chCloseSquare, chOpenSquare, chBackSlash, chLatin_c, chDash, chOpenSquare, 00092 chColon, chCloseSquare, chCloseSquare, chAsterisk, chNull 00093 }; 00094 00095 00096 00097 const XMLCh fgP0Y[] = 00098 { 00099 chLatin_P, chDigit_0, chLatin_Y, chNull 00100 }; 00101 00102 const XMLCh fgP1Y[] = 00103 { 00104 chLatin_P, chDigit_1, chLatin_Y, chNull 00105 }; 00106 00107 const XMLCh fgP100Y[] = 00108 { 00109 chLatin_P, chDigit_1, chDigit_0, chDigit_0, chLatin_Y, chNull 00110 }; 00111 00112 const XMLCh fgPT24H[] = 00113 { 00114 chLatin_P, chLatin_T, chDigit_2, chDigit_4, chLatin_H, chNull 00115 }; 00116 00117 const XMLCh fgP1M[] = 00118 { 00119 chLatin_P, chDigit_1, chLatin_M, chNull 00120 }; 00121 00122 // --------------------------------------------------------------------------- 00123 // DatatypeValidatorFactory: Static member data 00124 // --------------------------------------------------------------------------- 00125 RefHashTableOf<DatatypeValidator>* DatatypeValidatorFactory::fBuiltInRegistry = 0; 00126 RefHashTableOf<XMLCanRepGroup, PtrHasher>* DatatypeValidatorFactory::fCanRepRegistry = 0; 00127 00128 void XMLInitializer::initializeDatatypeValidatorFactory() 00129 { 00130 // @@ This is ugly. Need to make expandRegistryToFullSchemaSet 00131 // static. 00132 // 00133 DatatypeValidatorFactory *dvFactory = new DatatypeValidatorFactory(); 00134 if (dvFactory) { 00135 dvFactory->expandRegistryToFullSchemaSet(); 00136 delete dvFactory; 00137 } 00138 } 00139 00140 void XMLInitializer::terminateDatatypeValidatorFactory() 00141 { 00142 delete DatatypeValidatorFactory::fBuiltInRegistry; 00143 DatatypeValidatorFactory::fBuiltInRegistry = 0; 00144 00145 delete DatatypeValidatorFactory::fCanRepRegistry; 00146 DatatypeValidatorFactory::fCanRepRegistry = 0; 00147 } 00148 00149 // --------------------------------------------------------------------------- 00150 // DatatypeValidatorFactory: Constructors and Destructor 00151 // --------------------------------------------------------------------------- 00152 DatatypeValidatorFactory::DatatypeValidatorFactory(MemoryManager* const manager) 00153 : fUserDefinedRegistry(0) 00154 , fMemoryManager(manager) 00155 { 00156 } 00157 00158 DatatypeValidatorFactory::~DatatypeValidatorFactory() 00159 { 00160 cleanUp(); 00161 } 00162 00163 00164 // --------------------------------------------------------------------------- 00165 // DatatypeValidatorFactory: Reset methods 00166 // --------------------------------------------------------------------------- 00167 void DatatypeValidatorFactory::resetRegistry() { 00168 00169 if (fUserDefinedRegistry != 0) { 00170 fUserDefinedRegistry->removeAll(); 00171 } 00172 } 00173 00174 // --------------------------------------------------------------------------- 00175 // DatatypeValidatorFactory: Registry initialization methods 00176 // --------------------------------------------------------------------------- 00177 void DatatypeValidatorFactory::expandRegistryToFullSchemaSet() 00178 { 00179 //Initialize common Schema/DTD Datatype validator set 00180 fBuiltInRegistry = new RefHashTableOf<DatatypeValidator>(29); 00181 00182 DatatypeValidator *dv = new StringDatatypeValidator(); 00183 dv->setTypeName(SchemaSymbols::fgDT_STRING, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00184 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_STRING, dv); 00185 00186 dv = new NOTATIONDatatypeValidator(); 00187 dv->setTypeName(XMLUni::fgNotationString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00188 fBuiltInRegistry->put((void*) XMLUni::fgNotationString, dv); 00189 00190 dv = new AnySimpleTypeDatatypeValidator(); 00191 dv->setTypeName(SchemaSymbols::fgDT_ANYSIMPLETYPE, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00192 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_ANYSIMPLETYPE, dv); 00193 00194 dv = new BooleanDatatypeValidator(); 00195 dv->setTypeName(SchemaSymbols::fgDT_BOOLEAN, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00196 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_BOOLEAN, dv); 00197 00198 dv = new DecimalDatatypeValidator(); 00199 dv->setTypeName(SchemaSymbols::fgDT_DECIMAL, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00200 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DECIMAL, dv); 00201 00202 dv = new HexBinaryDatatypeValidator(); 00203 dv->setTypeName(SchemaSymbols::fgDT_HEXBINARY, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00204 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_HEXBINARY, dv); 00205 00206 dv = new Base64BinaryDatatypeValidator(); 00207 dv->setTypeName(SchemaSymbols::fgDT_BASE64BINARY, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00208 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_BASE64BINARY, dv); 00209 00210 dv = new DoubleDatatypeValidator(); 00211 dv->setTypeName(SchemaSymbols::fgDT_DOUBLE, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00212 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DOUBLE, dv); 00213 00214 dv = new FloatDatatypeValidator(); 00215 dv->setTypeName(SchemaSymbols::fgDT_FLOAT, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00216 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_FLOAT, dv); 00217 00218 dv = new AnyURIDatatypeValidator(); 00219 dv->setTypeName(SchemaSymbols::fgDT_ANYURI, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00220 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_ANYURI, dv); 00221 00222 dv = new QNameDatatypeValidator(); 00223 dv->setTypeName(SchemaSymbols::fgDT_QNAME, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00224 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_QNAME, dv); 00225 00226 dv = new DateTimeDatatypeValidator(); 00227 dv->setTypeName(SchemaSymbols::fgDT_DATETIME, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00228 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DATETIME, dv); 00229 00230 dv = new DateDatatypeValidator(); 00231 dv->setTypeName(SchemaSymbols::fgDT_DATE, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00232 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DATE, dv); 00233 00234 dv = new TimeDatatypeValidator(); 00235 dv->setTypeName(SchemaSymbols::fgDT_TIME, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00236 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_TIME, dv); 00237 00238 dv = new DayDatatypeValidator(); 00239 dv->setTypeName(SchemaSymbols::fgDT_DAY, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00240 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DAY, dv); 00241 00242 dv = new MonthDatatypeValidator(); 00243 dv->setTypeName(SchemaSymbols::fgDT_MONTH, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00244 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_MONTH, dv); 00245 00246 dv = new MonthDayDatatypeValidator(); 00247 dv->setTypeName(SchemaSymbols::fgDT_MONTHDAY, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00248 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_MONTHDAY, dv); 00249 00250 dv = new YearDatatypeValidator(); 00251 dv->setTypeName(SchemaSymbols::fgDT_YEAR, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00252 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_YEAR, dv); 00253 00254 dv = new YearMonthDatatypeValidator(); 00255 dv->setTypeName(SchemaSymbols::fgDT_YEARMONTH, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00256 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_YEARMONTH, dv); 00257 00258 dv = new DurationDatatypeValidator(); 00259 dv->setTypeName(SchemaSymbols::fgDT_DURATION, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00260 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_DURATION, dv); 00261 00262 // REVISIT 00263 // We are creating a lot of Hashtables for the facets of the different 00264 // validators. It's better to have some kind of a memory pool and ask 00265 // the pool to give us a new instance of the hashtable. 00266 RefHashTableOf<KVStringPair>* facets = new RefHashTableOf<KVStringPair>(3); 00267 00268 // Create 'normalizedString' datatype validator 00269 facets->put((void*) SchemaSymbols::fgELT_WHITESPACE, 00270 new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_REPLACE)); 00271 00272 createDatatypeValidator(SchemaSymbols::fgDT_NORMALIZEDSTRING, 00273 getDatatypeValidator(SchemaSymbols::fgDT_STRING), 00274 facets, 0, false, 0, false); 00275 00276 // Create 'token' datatype validator 00277 facets = new RefHashTableOf<KVStringPair>(3); 00278 facets->put((void*) SchemaSymbols::fgELT_WHITESPACE, 00279 new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_COLLAPSE)); 00280 00281 createDatatypeValidator(SchemaSymbols::fgDT_TOKEN, 00282 getDatatypeValidator(SchemaSymbols::fgDT_NORMALIZEDSTRING), 00283 facets, 0, false, 0, false); 00284 00285 00286 dv = new NameDatatypeValidator(getDatatypeValidator(SchemaSymbols::fgDT_TOKEN), 0, 0, 0); 00287 dv->setTypeName(SchemaSymbols::fgDT_NAME, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00288 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_NAME, dv); 00289 00290 00291 dv = new NCNameDatatypeValidator(getDatatypeValidator(SchemaSymbols::fgDT_NAME), 0, 0, 0); 00292 dv->setTypeName(SchemaSymbols::fgDT_NCNAME, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00293 fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_NCNAME, dv); 00294 00295 // Create 'NMTOKEN' datatype validator 00296 facets = new RefHashTableOf<KVStringPair>(3); 00297 00298 facets->put((void*) SchemaSymbols::fgELT_PATTERN , 00299 new KVStringPair(SchemaSymbols::fgELT_PATTERN,fgTokPattern)); 00300 facets->put((void*) SchemaSymbols::fgELT_WHITESPACE, 00301 new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_COLLAPSE)); 00302 00303 createDatatypeValidator(XMLUni::fgNmTokenString, 00304 getDatatypeValidator(SchemaSymbols::fgDT_TOKEN),facets, 0, false, 0, false); 00305 00306 // Create 'NMTOKENS' datatype validator 00307 facets = new RefHashTableOf<KVStringPair>(2); 00308 facets->put((void*) SchemaSymbols::fgELT_MINLENGTH, 00309 new KVStringPair(SchemaSymbols::fgELT_MINLENGTH, XMLUni::fgValueOne)); 00310 00311 createDatatypeValidator(XMLUni::fgNmTokensString, 00312 getDatatypeValidator(XMLUni::fgNmTokenString), facets, 0, true, 0, false); 00313 00314 // Create 'language' datatype validator 00315 facets = new RefHashTableOf<KVStringPair>(3); 00316 00317 facets->put((void*) SchemaSymbols::fgELT_PATTERN, 00318 new KVStringPair(SchemaSymbols::fgELT_PATTERN, XMLUni::fgLangPattern)); 00319 00320 createDatatypeValidator(SchemaSymbols::fgDT_LANGUAGE, 00321 getDatatypeValidator(SchemaSymbols::fgDT_TOKEN), 00322 facets, 0, false, 0, false); 00323 00324 // Create 'integer' datatype validator 00325 facets = new RefHashTableOf<KVStringPair>(3); 00326 00327 facets->put((void*) SchemaSymbols::fgELT_FRACTIONDIGITS, 00328 new KVStringPair(SchemaSymbols::fgELT_FRACTIONDIGITS, XMLUni::fgValueZero)); 00329 00330 facets->put((void*) SchemaSymbols::fgELT_PATTERN, 00331 new KVStringPair(SchemaSymbols::fgELT_PATTERN, fgIntegerPattern)); 00332 00333 createDatatypeValidator(SchemaSymbols::fgDT_INTEGER, 00334 getDatatypeValidator(SchemaSymbols::fgDT_DECIMAL), 00335 facets, 0, false, 0, false); 00336 00337 // Create 'nonPositiveInteger' datatype validator 00338 facets = new RefHashTableOf<KVStringPair>(2); 00339 00340 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00341 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgValueZero)); 00342 00343 createDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER, 00344 getDatatypeValidator(SchemaSymbols::fgDT_INTEGER), 00345 facets, 0, false, 0, false); 00346 00347 // Create 'negativeInteger' datatype validator 00348 facets = new RefHashTableOf<KVStringPair>(2); 00349 00350 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00351 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgNegOne)); 00352 00353 createDatatypeValidator(SchemaSymbols::fgDT_NEGATIVEINTEGER, 00354 getDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER), 00355 facets, 0, false, 0, false); 00356 00357 // Create 'long' datatype validator 00358 facets = new RefHashTableOf<KVStringPair>(2); 00359 00360 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00361 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgLongMaxInc)); 00362 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00363 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgLongMinInc)); 00364 00365 createDatatypeValidator(SchemaSymbols::fgDT_LONG, 00366 getDatatypeValidator(SchemaSymbols::fgDT_INTEGER), 00367 facets, 0, false, 0, false); 00368 00369 // Create 'int' datatype validator 00370 facets = new RefHashTableOf<KVStringPair>(2); 00371 00372 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00373 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgIntMaxInc)); 00374 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00375 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgIntMinInc)); 00376 00377 createDatatypeValidator(SchemaSymbols::fgDT_INT, 00378 getDatatypeValidator(SchemaSymbols::fgDT_LONG), 00379 facets, 0, false, 0, false); 00380 00381 // Create 'short' datatype validator 00382 facets = new RefHashTableOf<KVStringPair>(2); 00383 00384 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00385 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgShortMaxInc)); 00386 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00387 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgShortMinInc)); 00388 00389 createDatatypeValidator(SchemaSymbols::fgDT_SHORT, 00390 getDatatypeValidator(SchemaSymbols::fgDT_INT), 00391 facets, 0, false, 0 ,false); 00392 00393 // Create 'byte' datatype validator 00394 facets = new RefHashTableOf<KVStringPair>(2); 00395 00396 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00397 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgByteMaxInc)); 00398 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00399 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgByteMinInc)); 00400 00401 createDatatypeValidator(SchemaSymbols::fgDT_BYTE, 00402 getDatatypeValidator(SchemaSymbols::fgDT_SHORT), 00403 facets, 0, false, 0, false); 00404 00405 // Create 'nonNegativeInteger' datatype validator 00406 facets = new RefHashTableOf<KVStringPair>(2); 00407 00408 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00409 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgValueZero)); 00410 00411 createDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER, 00412 getDatatypeValidator(SchemaSymbols::fgDT_INTEGER), 00413 facets, 0, false, 0, false); 00414 00415 // Create 'unsignedLong' datatype validator 00416 facets = new RefHashTableOf<KVStringPair>(2); 00417 00418 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00419 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgULongMaxInc)); 00420 00421 createDatatypeValidator(SchemaSymbols::fgDT_ULONG, 00422 getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER), 00423 facets, 0, false, 0, false); 00424 00425 // Create 'unsignedInt' datatype validator 00426 facets = new RefHashTableOf<KVStringPair>(2); 00427 00428 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00429 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgUIntMaxInc)); 00430 00431 createDatatypeValidator(SchemaSymbols::fgDT_UINT, 00432 getDatatypeValidator(SchemaSymbols::fgDT_ULONG), 00433 facets, 0, false, 0, false); 00434 00435 // Create 'unsignedShort' datatypeValidator 00436 facets = new RefHashTableOf<KVStringPair>(2); 00437 00438 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00439 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgUShortMaxInc)); 00440 00441 createDatatypeValidator(SchemaSymbols::fgDT_USHORT, 00442 getDatatypeValidator(SchemaSymbols::fgDT_UINT), 00443 facets, 0, false, 0, false); 00444 00445 // Create 'unsignedByte' datatype validator 00446 facets = new RefHashTableOf<KVStringPair>(2); 00447 00448 facets->put((void*) SchemaSymbols::fgELT_MAXINCLUSIVE, 00449 new KVStringPair(SchemaSymbols::fgELT_MAXINCLUSIVE, XMLUni::fgUByteMaxInc)); 00450 00451 createDatatypeValidator(SchemaSymbols::fgDT_UBYTE, 00452 getDatatypeValidator(SchemaSymbols::fgDT_USHORT), 00453 facets, 0, false, 0, false); 00454 00455 // Create 'positiveInteger' datatype validator 00456 facets = new RefHashTableOf<KVStringPair>(2); 00457 00458 facets->put((void*) SchemaSymbols::fgELT_MININCLUSIVE, 00459 new KVStringPair(SchemaSymbols::fgELT_MININCLUSIVE, XMLUni::fgValueOne)); 00460 00461 createDatatypeValidator(SchemaSymbols::fgDT_POSITIVEINTEGER, 00462 getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER), 00463 facets, 0, false, 0, false); 00464 00465 // Create 'ID', 'IDREF' and 'ENTITY' datatype validator 00466 dv = new IDDatatypeValidator(getDatatypeValidator(SchemaSymbols::fgDT_NCNAME), 0, 0, 0); 00467 dv->setTypeName(XMLUni::fgIDString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00468 fBuiltInRegistry->put((void*) XMLUni::fgIDString, dv); 00469 00470 dv = new IDREFDatatypeValidator(getDatatypeValidator(SchemaSymbols::fgDT_NCNAME), 0, 0, 0); 00471 dv->setTypeName(XMLUni::fgIDRefString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00472 fBuiltInRegistry->put((void*) XMLUni::fgIDRefString, dv); 00473 00474 dv = new ENTITYDatatypeValidator(getDatatypeValidator(SchemaSymbols::fgDT_NCNAME), 0, 0, 0); 00475 dv->setTypeName(XMLUni::fgEntityString, SchemaSymbols::fgURI_SCHEMAFORSCHEMA); 00476 fBuiltInRegistry->put((void*) XMLUni::fgEntityString, dv); 00477 00478 facets = new RefHashTableOf<KVStringPair>(2); 00479 facets->put((void*) SchemaSymbols::fgELT_MINLENGTH, 00480 new KVStringPair(SchemaSymbols::fgELT_MINLENGTH, XMLUni::fgValueOne)); 00481 00482 // Create 'IDREFS' datatype validator 00483 createDatatypeValidator 00484 ( 00485 XMLUni::fgIDRefsString 00486 , getDatatypeValidator(XMLUni::fgIDRefString) 00487 , facets 00488 , 0 00489 , true 00490 , 0 00491 , false 00492 ); 00493 00494 facets = new RefHashTableOf<KVStringPair>(2); 00495 00496 facets->put((void*) SchemaSymbols::fgELT_MINLENGTH, 00497 new KVStringPair(SchemaSymbols::fgELT_MINLENGTH, XMLUni::fgValueOne)); 00498 00499 // Create 'ENTITIES' datatype validator 00500 createDatatypeValidator 00501 ( 00502 XMLUni::fgEntitiesString 00503 , getDatatypeValidator(XMLUni::fgEntityString) 00504 , facets 00505 , 0 00506 , true 00507 , 0 00508 , false 00509 ); 00510 00511 initCanRepRegistory(); 00512 } 00513 00514 00515 /*** 00516 * 00517 * For Decimal-derivated, an instance of DecimalDatatypeValidator 00518 * can be used by the primitive datatype, decimal, or any one of 00519 * the derivated datatypes, such as int, long, unsighed short, just 00520 * name a few, or any user-defined datatypes, which may derivate from 00521 * either the primitive datatype, decimal, or from any one of those 00522 * decimal derivated datatypes, or other user-defined datatypes, which 00523 * in turn, indirectly derivate from decimal or decimal-derived. 00524 * 00525 * fCanRepRegisty captures deciaml dv and its derivatives. 00526 * 00527 ***/ 00528 void DatatypeValidatorFactory::initCanRepRegistory() 00529 { 00530 00531 /*** 00532 * key: dv 00533 * data: XMLCanRepGroup 00534 ***/ 00535 fCanRepRegistry = new RefHashTableOf<XMLCanRepGroup, PtrHasher>(29, true); 00536 00537 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_DECIMAL), 00538 new XMLCanRepGroup(XMLCanRepGroup::Decimal)); 00539 00540 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_INTEGER), 00541 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00542 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_LONG), 00543 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00544 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_INT), 00545 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00546 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_SHORT), 00547 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00548 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_BYTE), 00549 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00550 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER), 00551 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00552 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_POSITIVEINTEGER), 00553 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_signed)); 00554 00555 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_NEGATIVEINTEGER), 00556 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_unsigned)); 00557 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_ULONG), 00558 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_unsigned)); 00559 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_UINT), 00560 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_unsigned)); 00561 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_USHORT), 00562 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_unsigned)); 00563 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_UBYTE), 00564 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_unsigned)); 00565 00566 fCanRepRegistry->put((void*) getDatatypeValidator(SchemaSymbols::fgDT_NONPOSITIVEINTEGER), 00567 new XMLCanRepGroup(XMLCanRepGroup::Decimal_Derived_npi)); 00568 } 00569 00570 /*** 00571 * 00572 * For any dv other than Decimaldv, return String only. 00573 * Later on if support to dv other than Decimaldv arise, we may 00574 * add them fCanRepRegistry during DatatypeValidatorFactory::initCanRepRegistory() 00575 * 00576 ***/ 00577 XMLCanRepGroup::CanRepGroup DatatypeValidatorFactory::getCanRepGroup(const DatatypeValidator* const dv) 00578 { 00579 if (!dv) 00580 return XMLCanRepGroup::String; 00581 00582 DatatypeValidator *curdv = (DatatypeValidator*) dv; 00583 00584 while (curdv) 00585 { 00586 if (fCanRepRegistry->containsKey(curdv)) 00587 return fCanRepRegistry->get(curdv)->getGroup(); 00588 else 00589 curdv = curdv->getBaseValidator(); 00590 } 00591 00592 return XMLCanRepGroup::String; 00593 } 00594 00595 DatatypeValidator* DatatypeValidatorFactory::getBuiltInBaseValidator(const DatatypeValidator* const dv) 00596 { 00597 DatatypeValidator *curdv = (DatatypeValidator*)dv; 00598 00599 while (curdv) 00600 { 00601 if (curdv == getBuiltInRegistry()->get(curdv->getTypeLocalName())) 00602 return curdv; 00603 else 00604 curdv = curdv->getBaseValidator(); 00605 } 00606 00607 return 0; 00608 } 00609 00610 // --------------------------------------------------------------------------- 00611 // DatatypeValidatorFactory: factory methods 00612 // --------------------------------------------------------------------------- 00613 DatatypeValidator* DatatypeValidatorFactory::createDatatypeValidator 00614 ( 00615 const XMLCh* const typeName 00616 , DatatypeValidator* const baseValidator 00617 , RefHashTableOf<KVStringPair>* const facets 00618 , RefArrayVectorOf<XMLCh>* const enums 00619 , const bool isDerivedByList 00620 , const int finalSet 00621 , const bool isUserDefined 00622 , MemoryManager* const userManager 00623 ) 00624 { 00625 if (baseValidator == 0) { 00626 00627 if (facets) { 00628 Janitor<KVStringPairHashTable> janFacets(facets); 00629 } 00630 00631 if (enums) { 00632 Janitor<XMLChRefVector> janEnums(enums); 00633 } 00634 00635 return 0; 00636 } 00637 00638 DatatypeValidator* datatypeValidator = 0; 00639 MemoryManager* const manager = (isUserDefined) 00640 ? userManager : XMLPlatformUtils::fgMemoryManager; 00641 00642 if (isDerivedByList) { 00643 datatypeValidator = new (manager) ListDatatypeValidator(baseValidator, facets, enums, finalSet, manager); 00644 00645 // Set PSVI information for Ordered, Numeric, Bounded & Finite 00646 datatypeValidator->setOrdered(XSSimpleTypeDefinition::ORDERED_FALSE); 00647 datatypeValidator->setNumeric(false); 00648 if (facets && 00649 ((facets->get(SchemaSymbols::fgELT_LENGTH) || 00650 (facets->get(SchemaSymbols::fgELT_MINLENGTH) && facets->get(SchemaSymbols::fgELT_MAXLENGTH))))) 00651 { 00652 datatypeValidator->setBounded(true); 00653 datatypeValidator->setFinite(true); 00654 } 00655 else 00656 { 00657 datatypeValidator->setBounded(false); 00658 datatypeValidator->setFinite(false); 00659 } 00660 } 00661 else { 00662 00663 if ((baseValidator->getType() != DatatypeValidator::String) && facets) { 00664 00665 KVStringPair* value = facets->get(SchemaSymbols::fgELT_WHITESPACE); 00666 00667 if (value != 0) { 00668 facets->removeKey(SchemaSymbols::fgELT_WHITESPACE); 00669 } 00670 } 00671 00672 datatypeValidator = baseValidator->newInstance 00673 ( 00674 facets 00675 , enums 00676 , finalSet 00677 , manager 00678 ); 00679 00680 // Set PSVI information for Ordered, Numeric, Bounded & Finite 00681 datatypeValidator->setOrdered(baseValidator->getOrdered()); 00682 datatypeValidator->setNumeric(baseValidator->getNumeric()); 00683 RefHashTableOf<KVStringPair>* baseFacets = baseValidator->getFacets(); 00684 if (facets && 00685 ((facets->get(SchemaSymbols::fgELT_MININCLUSIVE) || 00686 facets->get(SchemaSymbols::fgELT_MINEXCLUSIVE) || 00687 (baseFacets && (baseFacets->get(SchemaSymbols::fgELT_MININCLUSIVE) || 00688 baseFacets->get(SchemaSymbols::fgELT_MINEXCLUSIVE))))) && 00689 (facets->get(SchemaSymbols::fgELT_MAXINCLUSIVE) || 00690 facets->get(SchemaSymbols::fgELT_MAXEXCLUSIVE) || 00691 (baseFacets && ((baseFacets->get(SchemaSymbols::fgELT_MAXINCLUSIVE) || 00692 baseFacets->get(SchemaSymbols::fgELT_MAXEXCLUSIVE)))))) 00693 { 00694 datatypeValidator->setBounded(true); 00695 } 00696 else 00697 { 00698 datatypeValidator->setBounded(false); 00699 } 00700 if (baseValidator->getFinite()) 00701 { 00702 datatypeValidator->setFinite(true); 00703 } 00704 else if (!facets) 00705 { 00706 datatypeValidator->setFinite(false); 00707 } 00708 else if (facets->get(SchemaSymbols::fgELT_LENGTH) || facets->get(SchemaSymbols::fgELT_MAXLENGTH) || 00709 facets->get(SchemaSymbols::fgELT_TOTALDIGITS)) 00710 { 00711 datatypeValidator->setFinite(true); 00712 } 00713 //for efficiency use this instead of rechecking... 00714 //else if ((facets->get(SchemaSymbols::fgELT_MININCLUSIVE) || facets->get(SchemaSymbols::fgELT_MINEXCLUSIVE)) && 00715 // (facets->get(SchemaSymbols::fgELT_MAXINCLUSIVE) || facets->get(SchemaSymbols::fgELT_MAXEXCLUSIVE))) 00716 else if (datatypeValidator->getBounded() || 00717 datatypeValidator->getType() == DatatypeValidator::Date || 00718 datatypeValidator->getType() == DatatypeValidator::YearMonth || 00719 datatypeValidator->getType() == DatatypeValidator::Year || 00720 datatypeValidator->getType() == DatatypeValidator::MonthDay || 00721 datatypeValidator->getType() == DatatypeValidator::Day || 00722 datatypeValidator->getType() == DatatypeValidator::Month) 00723 { 00724 if (facets->get(SchemaSymbols::fgELT_FRACTIONDIGITS)) 00725 { 00726 datatypeValidator->setFinite(true); 00727 } 00728 else 00729 { 00730 datatypeValidator->setFinite(false); 00731 } 00732 } 00733 else 00734 { 00735 datatypeValidator->setFinite(false); 00736 } 00737 } 00738 00739 if (datatypeValidator != 0) { 00740 00741 if (isUserDefined) { 00742 00743 if (!fUserDefinedRegistry) { 00744 fUserDefinedRegistry = new (userManager) RefHashTableOf<DatatypeValidator>(29, userManager); 00745 } 00746 00747 fUserDefinedRegistry->put((void *)typeName, datatypeValidator); 00748 } 00749 else { 00750 fBuiltInRegistry->put((void *)typeName, datatypeValidator); 00751 } 00752 00753 datatypeValidator->setTypeName(typeName); 00754 } 00755 00756 return datatypeValidator; 00757 } 00758 00759 static DatatypeValidator::ValidatorType getPrimitiveDV(DatatypeValidator::ValidatorType validationDV) 00760 { 00761 if (validationDV == DatatypeValidator::ID || 00762 validationDV == DatatypeValidator::IDREF || 00763 validationDV == DatatypeValidator::ENTITY) 00764 { 00765 return DatatypeValidator::String; 00766 } 00767 return validationDV; 00768 } 00769 00770 DatatypeValidator* DatatypeValidatorFactory::createDatatypeValidator 00771 ( 00772 const XMLCh* const typeName 00773 , RefVectorOf<DatatypeValidator>* const validators 00774 , const int finalSet 00775 , const bool userDefined 00776 , MemoryManager* const userManager 00777 ) 00778 { 00779 if (validators == 0) 00780 return 0; 00781 00782 DatatypeValidator* datatypeValidator = 0; 00783 MemoryManager* const manager = (userDefined) 00784 ? userManager : XMLPlatformUtils::fgMemoryManager; 00785 00786 datatypeValidator = new (manager) UnionDatatypeValidator(validators, finalSet, manager); 00787 00788 if (datatypeValidator != 0) { 00789 00790 if (userDefined) { 00791 00792 if (!fUserDefinedRegistry) { 00793 fUserDefinedRegistry = new (userManager) RefHashTableOf<DatatypeValidator>(29, userManager); 00794 } 00795 00796 fUserDefinedRegistry->put((void *)typeName, datatypeValidator); 00797 } 00798 else { 00799 fBuiltInRegistry->put((void *)typeName, datatypeValidator); 00800 } 00801 datatypeValidator->setTypeName(typeName); 00802 00803 // Set PSVI information for Ordered, Numeric, Bounded & Finite 00804 XMLSize_t valSize = validators->size(); 00805 if (valSize) 00806 { 00807 DatatypeValidator::ValidatorType ancestorId = getPrimitiveDV(validators->elementAt(0)->getType()); 00808 00809 // For a union the ORDERED {value} is partial unless one of the following: 00810 // 1. If every member of {member type definitions} is derived from a common ancestor other than the simple ur-type, then {value} is the same as that ancestor's ordered facet. 00811 // 2. If every member of {member type definitions} has a {value} of false for the ordered facet, then {value} is false. 00812 bool allOrderedFalse = true; 00813 bool commonAnc = ancestorId != DatatypeValidator::AnySimpleType; 00814 bool allNumeric = true; 00815 bool allBounded = true; 00816 bool allFinite = true; 00817 00818 for(XMLSize_t i = 0 ; (i < valSize) && (commonAnc || allOrderedFalse || allNumeric || allBounded || allFinite); i++) 00819 { 00820 // for the other member types, check whether the value is false 00821 // and whether they have the same ancestor as the first one 00822 if (commonAnc) 00823 commonAnc = ancestorId == getPrimitiveDV(validators->elementAt(i)->getType()); 00824 if (allOrderedFalse) 00825 allOrderedFalse = validators->elementAt(i)->getOrdered() == XSSimpleTypeDefinition::ORDERED_FALSE; 00826 00827 if (allNumeric && !validators->elementAt(i)->getNumeric()) 00828 { 00829 allNumeric = false; 00830 } 00831 if (allBounded && (!validators->elementAt(i)->getBounded() || 00832 ancestorId != getPrimitiveDV(validators->elementAt(i)->getType()))) 00833 { 00834 allBounded = false; 00835 } 00836 if (allFinite && !validators->elementAt(i)->getFinite()) 00837 { 00838 allFinite = false; 00839 } 00840 } 00841 if (commonAnc) 00842 { 00843 datatypeValidator->setOrdered(validators->elementAt(0)->getOrdered()); 00844 } 00845 else if (allOrderedFalse) 00846 { 00847 datatypeValidator->setOrdered(XSSimpleTypeDefinition::ORDERED_FALSE); 00848 } 00849 else 00850 { 00851 datatypeValidator->setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL); 00852 } 00853 datatypeValidator->setNumeric(allNumeric); 00854 datatypeValidator->setBounded(allBounded); 00855 datatypeValidator->setFinite(allFinite); 00856 } 00857 else // size = 0 00858 { 00859 datatypeValidator->setOrdered(XSSimpleTypeDefinition::ORDERED_PARTIAL); 00860 datatypeValidator->setNumeric(true); 00861 datatypeValidator->setBounded(true); 00862 datatypeValidator->setFinite(true); 00863 } 00864 } 00865 return datatypeValidator; 00866 } 00867 00868 /*** 00869 * Support for Serialization/De-serialization 00870 ***/ 00871 00872 IMPL_XSERIALIZABLE_TOCREATE(DatatypeValidatorFactory) 00873 00874 void DatatypeValidatorFactory::serialize(XSerializeEngine& serEng) 00875 { 00876 00877 // Need not to serialize static data member, fBuiltInRegistry 00878 00879 if (serEng.isStoring()) 00880 { 00881 /*** 00882 * Serialize RefHashTableOf<DatatypeValidator> 00883 ***/ 00884 XTemplateSerializer::storeObject(fUserDefinedRegistry, serEng); 00885 } 00886 else 00887 { 00888 /*** 00889 * Deserialize RefHashTableOf<DatatypeValidator> 00890 ***/ 00891 XTemplateSerializer::loadObject(&fUserDefinedRegistry, 29, true, serEng); 00892 } 00893 00894 } 00895 00896 XERCES_CPP_NAMESPACE_END 00897