User's Guide

Caching XML Objects

The following objects usually remain static for the duration of the application:

You can read and parse these objects one time, and save them in the image. To cache mapping specifications, DTDs, and interface specs, use the AbtXmlObjectCache singleton class and its instance methods to add and remove instances. 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

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.

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.

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.

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.

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 show examples of the caching methods.

Adding a DTD to the XML resource cache after parsing

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 adds the DTD to the XML resource cache after parsing:

	| parser domDocument |
	parser := AbtXmlDOMParser newValidatingParser.
	domDocument  := parser parseURI: 'd:\workspce\resource.xml'.
	domDocument dtd addToXmlObjectCache.

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 mapping and interface specifications from the cache

To retrieve a mapping specification from the cache, use the following Smalltalk code:

AbtXmlObjectCache current mappingSpecNamed: 'MySpec'

To retrieve an interface specification from the cache, use the following Smalltalk code:

AbtXmlObjectCache current interfaceSpecForClass:  #MyClass

To retrieve a mapping specification from the cache using a well-known name, use the following Smalltalk code:

| anXmlMappingSpec |
anXmlMappingSpec := AbtXmlMappingSpec new.
AbtXmlObjectCache current addMappingSpec: anXmlMappingSpec named: 'CustomerMapping'


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]