Class ElementDictionary<E extends TypedElement<E,X>,X extends TypedExtension>

java.lang.Object
eu.bandm.tools.tdom.runtime.ElementDictionary<E,X>

public class ElementDictionary<E extends TypedElement<E,X>,X extends TypedExtension> extends Object
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 Details

  • Constructor Details

    • ElementDictionary

      public ElementDictionary()
  • Method Details

    • clear

      public void clear()
      Forget all assignments.
    • idSet

      public Set<String> idSet()
      Returns an unmodifiable snapshot of all known id values.
      Returns:
      an unmodifiable snapshot of all known id values.
    • elementSet

      public Set<E> elementSet()
      Returns an unmodifiable snapshot of all known elements.
      Returns:
      an unmodifiable snapshot of all known elements.
    • idMap

      public Map<String,E> idMap()
      Returns an unmodifiable snapshot.
      Returns:
      an unmodifiable snapshot.
    • element2idMap

      public Map<E,String> element2idMap()
      Returns an unmodifiable snapshot.
      Returns:
      an unmodifiable snapshot.
    • add

      public boolean add(String id, E element)
      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

      public boolean addIfIdentifiable(E element)
      Stores an element if its definition includes an attribute of "ID type", and the actual value is !=null. The former is indicated by implementing Identifiable. The storing is done by calling add(String,TypedElement).
      Throws:
      HomonymousIdException - see add(String,TypedElement).
      SynonymousIdException - see add(String,TypedElement).
    • get

      @Opt public E get(@Opt @Opt String id)
      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

      public String 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 start
      msg - (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