Package eu.bandm.tools.tdom.runtime
Class ElementDictionary<E extends TypedElement<E,X>,X extends TypedExtension>
java.lang.Object
eu.bandm.tools.tdom.runtime.ElementDictionary<E,X>
Realizes a map from String values to Elements.
Is intended to realize the ID/IDREF relations in
one particular Document object only, and thus instantiated
with the generated
Element
type. But it can also be used with different
Document
objects of the same class, or even of different classes, instantiated
with E=TypedElement
.
When generated by calling createDictionary()
in the generated
TypedDocument's code, which is the recommended way,
then most consistency checks will be carried out automatically.
The methods of this class realize most of the "validity constraints" w.r.t. ID/IDREF from
[XML 1.0].-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Stores a combination of id key and Element value.boolean
addIfIdentifiable
(E element) Stores an element if its definition includes an attribute of "ID type", and the actual value is!=null
.boolean
checkIds
(E top, @Opt MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Test whether all reachable IDREF and IDREFS attribute have a value which corresponds to some ID attribute in the maps of this ElementDictionary.void
clear()
Forget all assignments.Returns an unmodifiable snapshot.Returns an unmodifiable snapshot of all known elements.freshId()
Returns an id value not yet used.Returns the element indentified by the given String value, or null if no such exists.idMap()
Returns an unmodifiable snapshot.idSet()
Returns an unmodifiable snapshot of all known id values.
-
Field Details
-
get
Deprecated.use "e::get" instead.
-
-
Constructor Details
-
ElementDictionary
public ElementDictionary()
-
-
Method Details
-
clear
public void clear()Forget all assignments. -
idSet
Returns an unmodifiable snapshot of all known id values.- Returns:
- an unmodifiable snapshot of all known id values.
-
elementSet
Returns an unmodifiable snapshot of all known elements.- Returns:
- an unmodifiable snapshot of all known elements.
-
idMap
Returns an unmodifiable snapshot.- Returns:
- an unmodifiable snapshot.
-
element2idMap
Returns an unmodifiable snapshot.- Returns:
- an unmodifiable snapshot.
-
add
Stores a combination of id key and Element value.- Throws:
HomonymousIdException
- if one(1) id is used for two(2) different elements.SynonymousIdException
- if two(2) ids are used for one(1) element. (This can only happen if this method is called directly by the user, not by TDom generated code.)
-
addIfIdentifiable
Stores an element if its definition includes an attribute of "ID type", and the actual value is!=null
. The former is indicated by implementingIdentifiable
. The storing is done by callingadd(String,TypedElement)
.- Throws:
HomonymousIdException
- seeadd(String,TypedElement)
.SynonymousIdException
- seeadd(String,TypedElement)
.
-
get
Returns the element indentified by the given String value, or null if no such exists. For convenience, the string may be ==null, which comes e.g. from an unset, "#IMPLIED" attribute.- Parameters:
id
- (maybe null) the id value to look up.- Returns:
- the element indentified by the given String value, or null if no such exists, or if the id argument is null.
-
freshId
Returns an id value not yet used.
(Currently this is a concatenation of "i" plus a number.)
(Please note that the values of "ID" attributes have NOTHING to do with the "ids" generated by XSLT processing. The latter can also be generated automatically, but both may differ.)- Returns:
- an id value not yet used.
-
checkIds
public boolean checkIds(E top, @Opt @Opt MessageReceiver<? super SimpleMessage<XMLDocumentIdentifier>> msg) Test whether all reachable IDREF and IDREFS attribute have a value which corresponds to some ID attribute in the maps of this ElementDictionary.- Parameters:
top
- (never null) the element where to startmsg
- (maybe null) the drain of error messages. It it is null, an Exception is thrown instead of the first error.- Returns:
- Whether all id references are okay.
- Throws:
DanglingIdException
-