Class GroupExtractor.Registry

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<Label>, java.util.Map<java.lang.Class,​Label>
    Enclosing class:
    GroupExtractor

    private static class GroupExtractor.Registry
    extends java.util.LinkedHashMap<java.lang.Class,​Label>
    implements java.lang.Iterable<Label>
    The Registry object is used to maintain mappings from types to labels. Each of the mappings can be used to dynamically select a label based on the instance type that is to be serialized. This also registers based on the label name.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private LabelMap elements
      This maintains a mapping between label names and labels.
      private Label text
      This label represents the free text between elements.
    • Constructor Summary

      Constructors 
      Constructor Description
      Registry​(LabelMap elements)
      Constructor for the Registry object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean isText()
      This is used to determine if an annotated list is a text list.
      java.util.Iterator<Label> iterator()
      This is used so that all the Label objects that have been added to the registry can be iterated over.
      void register​(java.lang.Class type, Label label)
      This is used to register a label based on the name.
      private void registerElement​(java.lang.Class type, Label label)
      This is used to register a label based on the name.
      private void registerText​(Label label)
      This is used to register the provided label is a text label.
      Label resolve​(java.lang.Class type)
      Here we resolve the Label the type is matched with by checking if the type is directly mapped or if any of the super classes of the type are mapped.
      private Label resolveElement​(java.lang.Class type)
      Here we resolve the Label the type is matched with by checking if the type is directly mapped or if any of the super classes of the type are mapped.
      Label resolveText()
      This is used to resolve the text for this registry.
      private Label resolveText​(java.lang.Class type)
      This is used to resolve the text for this registry.
      • Methods inherited from class java.util.LinkedHashMap

        clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
      • Methods inherited from class java.util.HashMap

        clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
      • Methods inherited from class java.util.AbstractMap

        equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, size
    • Field Detail

      • elements

        private LabelMap elements
        This maintains a mapping between label names and labels.
      • text

        private Label text
        This label represents the free text between elements.
    • Constructor Detail

      • Registry

        public Registry​(LabelMap elements)
        Constructor for the Registry object. This is used to register label instances using both the name and type of the label. Registration in this way ensures that each label can be dynamically selected.
        Parameters:
        elements - this contains name to label mappings
    • Method Detail

      • isText

        public boolean isText()
        This is used to determine if an annotated list is a text list. A text list is a list of elements that also accepts free text. Typically this will be an element list union that will allow unstructured XML such as XHTML to be parsed.
        Returns:
        returns true if the label represents a text list
      • iterator

        public java.util.Iterator<Label> iterator()
        This is used so that all the Label objects that have been added to the registry can be iterated over. Iteration over the labels allows for easy validation.
        Specified by:
        iterator in interface java.lang.Iterable<Label>
        Returns:
        this returns an iterator for all the labels
      • resolveText

        public Label resolveText()
        This is used to resolve the text for this registry. If there is a text annotation declared with the union then this will return a Label that can be used to convert the free text between elements in to strings.
        Returns:
        this returns the label representing free text
      • resolve

        public Label resolve​(java.lang.Class type)
        Here we resolve the Label the type is matched with by checking if the type is directly mapped or if any of the super classes of the type are mapped. If there are no classes in the hierarchy of the type that are mapped then this will return null otherwise the label will be returned.
        Parameters:
        type - this is the type to resolve the label for
        Returns:
        this will return the label that is best matched
      • resolveText

        private Label resolveText​(java.lang.Class type)
        This is used to resolve the text for this registry. If there is a text annotation declared with the union then this will return a Label that can be used to convert the free text between elements in to strings.
        Parameters:
        type - this is the type to resolve the text as
        Returns:
        this returns the label representing free text
      • resolveElement

        private Label resolveElement​(java.lang.Class type)
        Here we resolve the Label the type is matched with by checking if the type is directly mapped or if any of the super classes of the type are mapped. If there are no classes in the hierarchy of the type that are mapped then this will return null otherwise the label will be returned.
        Parameters:
        type - this is the type to resolve the label for
        Returns:
        this will return the label that is best matched
      • register

        public void register​(java.lang.Class type,
                             Label label)
                      throws java.lang.Exception
        This is used to register a label based on the name. This is done to ensure the label instance can be dynamically found during the deserialization process by providing the name.
        Parameters:
        name - this is the name of the label to be registered
        label - this is the label that is to be registered
        Throws:
        java.lang.Exception
      • registerElement

        private void registerElement​(java.lang.Class type,
                                     Label label)
                              throws java.lang.Exception
        This is used to register a label based on the name. This is done to ensure the label instance can be dynamically found during the deserialization process by providing the name.
        Parameters:
        name - this is the name of the label to be registered
        label - this is the label that is to be registered
        Throws:
        java.lang.Exception
      • registerText

        private void registerText​(Label label)
                           throws java.lang.Exception
        This is used to register the provided label is a text label. Registration as a text label can only happen if the field or method has a Text annotation declared on it.
        Parameters:
        label - this is the label to register as text
        Throws:
        java.lang.Exception