Caching XML Objects
The following objects usually remain static for the duration of the application:
Mapping specification
Document type definitions
Interface specification
Schemas
Serialization configurations
Deserialization configurations
Aliases
Each of the objects listed above can be created, stored, and reused. The AbtXmlObjectCache singleton instance contains protocol for managing each of the various reusable artifacts. The AbtXmlObjectCache class method current returns the singleton instance of the class.
AbtXmlObjectCache
The following methods are provided in the AbtXmlObjectCache class:
Class Methods
current
Returns the instance of the singleton class, creating it if necessary. Only one instance should be created.
reset
Reinitializes the active AbtXmlObjectCache by clearing all cached objects.
Instance Methods
addAlias: anAliasName forName: aRealName
Establishes @anAliasName as an alias for the name @aRealName. Aliases are useful when compatible versions of a namespace must be referenced. For example, if two namespaces contain compatible definitions, an alias can be used to enable an uncached resource to be resolved using it's alias.
addDeserializationConfiguration: anAbtXmlDeserializationConfiguration named: aName
Adds the deserialization configuration, anAbtXmlDeserializationConfiguration to the cache with name aName.
addDTD: anAbtDocumentType
Adds the DTD object, anAbtDocumentType to the cache. The DTD object is keyed by its URI.
addDTD: anAbtDocumentType named: aName
Adds the DTD object, anAbtDocumentType, to the cache. The DTD object is keyed by aName.
addInterfaceSpecsForModelDOM: anAbtDOMDocument
Loads interface specs from a DOM, (anAbtDOMDocument) into self. The DOM must be based on the abtcldef.dtd, which defines interface specs for XML.
addInterfaceSpec: anAbtInterfaceSpec forClass: aClass
Adds the interface specification, anAbtInterfaceSpec, of class aClass, to the cache.
addMappingSpec: anAbtXmlMappingSpec
Adds the mapping specification object, anAbtXmlMappingSpec, to the cache.
addMappingSpec: anAbtXmlMappingSpec named: aName
Returns the mapping specification object to the cache.
addOutputSerializer: anOutputSerializer named: aName
Adds the XML output serializer anOutputSerializer to the cache with name aName.
addSchema: anAbtXmlSchema
Adds the schema, anAbtXmlSchema to the cache using the #targetNamespace of the anAbtXmlSchema as the cache name.
addSchema: anAbtXmlSchema named: aName
Adds the schema, anAbtXmlSchema to the cache using with name aName
addSerializationConfiguration: anAbtXmlSerializationConfiguration named: aName
Adds the serialization configuration, anAbtXmlDeserializationConfiguration to the cache with name aName
aliasFor: aName
Answers the alias for aName or nil if no alias exists.
deserializationConfigurationNamed: aName
Returns the deserialization configuration named @aName. Deserialization configurations are used by the AbtXmlMappingParser to customize parser behavior.
dtdNamed: aName
Retrieves the DTD object, aName, from the cache. If the object is found, it is returned. If the object is not found, nil is returned.
elementNamed: aName inNamespace: aUriString
Return the schema element named @aName in namespace @aUriString.
interfaceSpecForClass: aClass
Retrieves the interface specification object, for aClass, from the cache. If the object is found, it is returned. If the object is not found, nil is returned.
mappingSpecNamed: aName
Retrieves the mapping specification object, aName, from the cache. If the object is found, it is returned. If the object is not found, nil is returned.
outputSerializerNamed: aName
Return the XML output serializer named @aName. The serializer control the creation of XML from domain objects.
removeAlias: aName
Remove the alias named @aName from the cache.
removeDeserializationConfigurationNamed: aName
Remove the deserialization configuration named @aName from the cache.
removeDTDNamed: aName
Removes the DTD, aName, from the cache. The user must maintain the cache.
removeInterfaceSpecforClass: aClass
Removes the interface specification object, aClass, from the cache. The user must maintain the cache.
removeMappingSpecNamed: aName
Removes the mapping specification object, aName, from the cache. The user must maintain the cache.
removeOutputSerializerNamed: aName
Remove the output serializer named @aName from the cache.
removeSchemaNamed: aName
Remove the schema named @aName from the cache.
removeSerializationConfigurationNamed: aName
Remove the serialization configuration named @aName from the cache.
schemaNamed: aName
Return the schema named @aName.
serializationConfigurationNamed: aName
Return the serialization configuration named @aName.
typeNamed: aName inNamespace: aUriString
Return the schema type named @aName in namespace @aUriString.
userDataAt:
Allows users to cache any application specific data, userData, without needing to create their own cache.
userDataAt:put:
Allows users to cache any application specific data, userData, without needing to create their own cache.
Caching Examples
The following examples demonstrate usage of the caching methods.
Adding a DTD to the XML resource cache
To add a DTD to the XML resource cache after parsing, use the addToXmlObjectCache method. Once the DTD exists in the object cache, it is used by subsequent parses. By default, DTDs are stored and retrieved using their systemId attribute. The following Smalltalk code parses an XML document and adds the DTD to the XML resource cache:
| parser domDocument |
parser := AbtXmlDOMParser newValidatingParser.
domDocument := parser parseURI: 'd:\workspce\resource.xml'.
domDocument dtd addToXmlObjectCache.
To parse a DTD directly and add it the XML object cache:
| spec |
spec := ( AbtXmlDOMParser newValidatingParser
parseDTD: 'abtxmap.dtd' ).
AbtXmlObjectCache current addMappingSpec: spec named: 'abtxmap.dtd'.
Disabling usage of the XML resource cache for resolving external DTD
To disable usage of the XML resource cache, set the useDTDCache attribute of the parser to false. Setting useDTDCache to false forces validating parsers to always read external DTD resources instead of using an instance that is stored in the XML object cache. DTD entries are then not automatically added to the XML object cache. When DTD caching is required, code must be included to add the parsed DTD to the cache.
The following Smalltalk code disables usage of the XML resource cache:
| parser |
parser := AbtXmlDOMParser newValidatingParser useDTDCache: false.
parser parseURI: 'd:\workspce\resource.xml'.
Retrieving XML objects from the cache
The AbtXmlObjectCache contains simple protocol to enable storage and retrieval of reusable XML support objects. Below are a few examples of how to use retrieve objects using the AbtXmlObjectCache API.
To retrieve an interface specification from the cache, use the following Smalltalk code:
AbtXmlObjectCache current interfaceSpecForClass: #MyClass
Retrieve a mapping spec
AbtXmlObjectCache current mappingSpecNamed: 'urn:VASTWebServiceDeployment600'.
Retrieve a serialization configuration
AbtXmlObjectCache current serializationConfigurationNamed: 'urn:VASTWebServiceDeployment600'.
Retrieve a deserialization configuration
AbtXmlObjectCache current deserializationConfigurationNamed: 'http://schemas.xmlsoap.org/wsdl/'.
Retrieve a schema
AbtXmlObjectCache current schemaNamed: 'urn:VASTWebServiceDeployment600'.
Last modified date: 01/29/2015