diff --git a/src/util/regx/RangeTokenMap.cpp b/src/util/regx/RangeTokenMap.cpp index 06e2976f02f72271ab8bb8f4b0b4595cd2d2a44b..dfff2c0b68e9724da3a946d7ad2b293b3e815ce0 100644 --- a/src/util/regx/RangeTokenMap.cpp +++ b/src/util/regx/RangeTokenMap.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.5 2001/10/25 15:06:26 tng + * Thread safe the static instance. + * * Revision 1.4 2001/10/23 23:13:41 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -271,14 +274,20 @@ void RangeTokenMap::initializeRegistry() { // RangeTokenMap: Instance methods // --------------------------------------------------------------------------- RangeTokenMap* RangeTokenMap::instance() { - static XMLRegisterCleanup instanceCleanup; - - if (!fInstance) { + static XMLRegisterCleanup instanceCleanup; + + if (!fInstance) { + RangeTokenMap* t = new RangeTokenMap(); + if (XMLPlatformUtils::compareAndSwap((void **)&fInstance, t, 0) != 0) + { + delete t; + } + else + { + instanceCleanup.registerCleanup(reinitInstance); + } - fInstance = new RangeTokenMap(); - instanceCleanup.registerCleanup(reinitInstance); - } - + } return (fInstance); } diff --git a/src/validators/datatype/DatatypeValidatorFactory.cpp b/src/validators/datatype/DatatypeValidatorFactory.cpp index 604f4a08e3d2061fdadcce8d859b01a9aaf8047e..de4e21d5314de85d20ac683c511edbbb78beac8f 100644 --- a/src/validators/datatype/DatatypeValidatorFactory.cpp +++ b/src/validators/datatype/DatatypeValidatorFactory.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.25 2001/10/25 15:06:49 tng + * Thread safe the static instance. + * * Revision 1.24 2001/10/23 23:14:22 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -357,54 +360,60 @@ void DatatypeValidatorFactory::reinitRegistry() { // --------------------------------------------------------------------------- void DatatypeValidatorFactory::initializeDTDRegistry() { - static XMLRegisterCleanup builtInRegistryCleanup; + if (fRegistryExpanded) + return; - if (fRegistryExpanded) - return; + static XMLRegisterCleanup builtInRegistryCleanup; if (fBuiltInRegistry == 0) { + RefHashTableOf<DatatypeValidator>* t = new RefHashTableOf<DatatypeValidator>(109); + if (XMLPlatformUtils::compareAndSwap((void **)&fBuiltInRegistry, t, 0) != 0) + { + delete t; + } + else + { + builtInRegistryCleanup.registerCleanup(reinitRegistry); + } - fBuiltInRegistry = new RefHashTableOf<DatatypeValidator>(109); - builtInRegistryCleanup.registerCleanup(reinitRegistry); } - - fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_STRING, + fBuiltInRegistry->put((void*) SchemaSymbols::fgDT_STRING, new StringDatatypeValidator()); - fBuiltInRegistry->put((void*) XMLUni::fgIDString, + fBuiltInRegistry->put((void*) XMLUni::fgIDString, new IDDatatypeValidator()); - fBuiltInRegistry->put((void*) XMLUni::fgIDRefString, + fBuiltInRegistry->put((void*) XMLUni::fgIDRefString, new IDREFDatatypeValidator()); - fBuiltInRegistry->put((void*) XMLUni::fgEntityString, + fBuiltInRegistry->put((void*) XMLUni::fgEntityString, new ENTITYDatatypeValidator()); - fBuiltInRegistry->put((void*) XMLUni::fgNotationString, + fBuiltInRegistry->put((void*) XMLUni::fgNotationString, new NOTATIONDatatypeValidator()); - // Create 'IDREFS' datatype validator - createDatatypeValidator(XMLUni::fgIDRefsString, + // Create 'IDREFS' datatype validator + createDatatypeValidator(XMLUni::fgIDRefsString, getDatatypeValidator(XMLUni::fgIDRefString), 0, 0, true, 0, false); - // Create 'ENTITIES' datatype validator - createDatatypeValidator(XMLUni::fgEntitiesString, + // Create 'ENTITIES' datatype validator + createDatatypeValidator(XMLUni::fgEntitiesString, getDatatypeValidator(XMLUni::fgEntityString), 0, 0, true, 0, false); - RefHashTableOf<KVStringPair>* facets = new RefHashTableOf<KVStringPair>(2); + RefHashTableOf<KVStringPair>* facets = new RefHashTableOf<KVStringPair>(2); - facets->put((void*) SchemaSymbols::fgELT_PATTERN , + facets->put((void*) SchemaSymbols::fgELT_PATTERN , new KVStringPair(SchemaSymbols::fgELT_PATTERN,fgTokPattern)); - facets->put((void*) SchemaSymbols::fgELT_WHITESPACE, + facets->put((void*) SchemaSymbols::fgELT_WHITESPACE, new KVStringPair(SchemaSymbols::fgELT_WHITESPACE, SchemaSymbols::fgWS_COLLAPSE)); - // Create 'NMTOKEN' datatype validator - createDatatypeValidator(XMLUni::fgNmTokenString, + // Create 'NMTOKEN' datatype validator + createDatatypeValidator(XMLUni::fgNmTokenString, getDatatypeValidator(SchemaSymbols::fgDT_STRING),facets, 0, false, 0, false); - // Create 'NMTOKENS' datatype validator - createDatatypeValidator(XMLUni::fgNmTokensString, - getDatatypeValidator(XMLUni::fgNmTokenString), 0, 0, true, 0, false); + // Create 'NMTOKENS' datatype validator + createDatatypeValidator(XMLUni::fgNmTokensString, + getDatatypeValidator(XMLUni::fgNmTokenString), 0, 0, true, 0, false); - fRegistryExpanded = 1; + fRegistryExpanded = 1; } diff --git a/src/validators/schema/GeneralAttributeCheck.cpp b/src/validators/schema/GeneralAttributeCheck.cpp index efc0a2f2534af556ac827210515fcfbfb32d6d7a..418130e1558092148b6fd2bf56583e4275728bc1 100644 --- a/src/validators/schema/GeneralAttributeCheck.cpp +++ b/src/validators/schema/GeneralAttributeCheck.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.10 2001/10/25 15:07:46 tng + * Thread safe the static instance. + * * Revision 1.9 2001/10/23 23:14:55 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -155,7 +158,7 @@ AttributeInfo::AttributeInfo(const XMLCh* const name, try { if (defaultValue) { fDefaultValue = XMLString::replicate(defaultValue); - } + } } catch(...) { cleanUp(); @@ -201,7 +204,7 @@ void GeneralAttributeCheck::setUpAttributes() { fAttributes = new AttributeInfo*[Att_Count]; - fAttributes[Att_Abstract_D] = + fAttributes[Att_Abstract_D] = new AttributeInfo(SchemaSymbols::fgATT_ABSTRACT, Att_Optional_Default, SchemaSymbols::fgATTVAL_FALSE, DT_Boolean); @@ -209,11 +212,11 @@ void GeneralAttributeCheck::setUpAttributes() { new AttributeInfo(SchemaSymbols::fgATT_ATTRIBUTEFORMDEFAULT, Att_Optional_Default, SchemaSymbols::fgATTVAL_UNQUALIFIED, DT_Form); - fAttributes[Att_Base_R] = + fAttributes[Att_Base_R] = new AttributeInfo(SchemaSymbols::fgATT_BASE, Att_Required, 0, DT_QName); - fAttributes[Att_Base_N] = + fAttributes[Att_Base_N] = new AttributeInfo(SchemaSymbols::fgATT_BASE, Att_Optional_NoDefault, 0, DT_QName); @@ -244,7 +247,7 @@ void GeneralAttributeCheck::setUpAttributes() { fAttributes[Att_Final1_N] = new AttributeInfo(SchemaSymbols::fgATT_FINAL, Att_Optional_NoDefault, 0, DT_Final1); - + fAttributes[Att_Final_D_D] = new AttributeInfo(SchemaSymbols::fgATT_FINALDEFAULT, Att_Optional_Default, XMLUni::fgZeroLenString, DT_Final); @@ -348,7 +351,7 @@ void GeneralAttributeCheck::setUpAttributes() { fAttributes[Att_System_N] = new AttributeInfo(SchemaSymbols::fgATT_SYSTEM, Att_Optional_NoDefault, 0, DT_AnyURI); - + fAttributes[Att_Target_N_N] = new AttributeInfo(SchemaSymbols::fgATT_TARGETNAMESPACE, Att_Optional_NoDefault, 0, 0); @@ -389,10 +392,10 @@ void GeneralAttributeCheck::setUpValidators() { DatatypeValidatorFactory dvFactory; dvFactory.expandRegistryToFullSchemaSet(); - fValidators[DT_NonNegInt] = + fValidators[DT_NonNegInt] = dvFactory.getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER); - fValidators[DT_Boolean] = + fValidators[DT_Boolean] = dvFactory.getDatatypeValidator(SchemaSymbols::fgDT_BOOLEAN); // TO DO - add remaining valdiators @@ -781,18 +784,24 @@ GeneralAttributeCheck* GeneralAttributeCheck::instance() { static XMLRegisterCleanup instanceCleanup; if (!fInstance) { + GeneralAttributeCheck* t = new GeneralAttributeCheck(); + if (XMLPlatformUtils::compareAndSwap((void **)&fInstance, t, 0) != 0) + { + delete t; + } + else + { + instanceCleanup.registerCleanup(reinitInstance); + } - fInstance = new GeneralAttributeCheck(); - instanceCleanup.registerCleanup(reinitInstance); } - return fInstance; } // ----------------------------------------------------------------------- // Notification that lazy data has been deleted // ----------------------------------------------------------------------- -void +void GeneralAttributeCheck::reinitInstance() { delete fInstance; fInstance = 0; @@ -851,7 +860,7 @@ GeneralAttributeCheck::checkAttributes(const DOM_Element& elem, prefixContext = localRefPrefix; } - else { + else { // We should report an error return; } @@ -881,7 +890,7 @@ GeneralAttributeCheck::checkAttributes(const DOM_Element& elem, } else { if (attInfo->getDefaultOption() == Att_Required) { - schema->reportSchemaError(XMLUni::fgXMLErrDomain, + schema->reportSchemaError(XMLUni::fgXMLErrDomain, XMLErrs::AttributeRequired, attName, contextStr, elemName); } } @@ -902,7 +911,7 @@ GeneralAttributeCheck::checkAttributes(const DOM_Element& elem, break; } - // Bypass attributes that start with xml + // Bypass attributes that start with xml DOMString attName = attribute.getNodeName(); aBuffer.set(attName.rawBuffer(), attName.length()); XMLCh* tmpName = aBuffer.getRawBuffer(); @@ -951,7 +960,7 @@ void GeneralAttributeCheck::validate(const XMLCh* const attName, } break; case DT_MinOccurs1: - if (XMLString::compareString(attValue, fgValueZero) != 0 + if (XMLString::compareString(attValue, fgValueZero) != 0 && XMLString::compareString(attValue, fgValueOne) != 0) { isInvalid = true; }