BDE 4.14.0 Production release
|
Provide a unique integer ID for each XML namespace.
This component provides an in-core value-semantic type, balxml::NamespaceRegistry
, that associates an integer ID with each registered namespace URI. In typical usage, client code would call the lookupOrRegister
method each time it encounters a namespace URI. The lookupOrRegister
method will return the ID corresponding to the URI, assigning a new ID if none already exists. The client can also retrieve the ID an already-registered namespace by providing the URI to the lookup
method and can retrieve the URI of an already-registered namespace by providing the ID to the lookup
method.
Note that namespace IDs may be negative. Client code should not assume an incremental assignment of IDs starting at zero. (See Preregistered Namespaces), below.
Even before any namespaces have been registered, a balxml::NamespaceRegistry
can be used to lookup several preregistered namespaces. The IDs for these preregistered namespaces are declared as constants within the balxml::NamespaceRegistry
class. These constants and their associated URI's are as follows:
Note that the above constants are negative numbers. In addition, the value, -1, is permanently assigned to the empty string. The use of predefined namespace IDs allows client code avoid lookups of the above, well-known URIs.
It is safe to read or modify multiple instances of balxml::NamespaceRegistry
simultaneously, each from a separate thread. It is safe to read a single instance of balxml::NamespaceRegistry
from multiple threads, provided no thread is modifying it at the same time. It is not safe to read or modify an instance of balxml::NamespaceRegistry
from one thread while any other thread is modifying the same instance.
Typically, a program will register namespaces as it encounters them in an XML document. Alternatively, namespaces that are important to the program are registered in advance, as in the following code:
Later, IDs can be looked up without concern for whether they have already been registered. Any new namespaces are simply given a new ID:
If one of the preregistered namespaces is presented, it's predefined ID is returned, even though it was never explicitly registered:
Using the lookup
method, a namespace ID can be looked up without registering it. In this case, an unregistered namespace will result in an ID of -1:
There is also a lookup
method for performing the reverse mapping – from ID to URI: