Class GroupExtractor.Registry

All Implemented Interfaces:
Serializable, Cloneable, Iterable<Label>, Map<Class,Label>, SequencedMap<Class,Label>
Enclosing class:
GroupExtractor

private static class GroupExtractor.Registry extends LinkedHashMap<Class,Label> implements 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.
  • Field Details

    • 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 Details

    • 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 Details

    • 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 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 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(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(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(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(Class type, Label label) throws 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:
      label - this is the label that is to be registered
      name - this is the name of the label to be registered
      Throws:
      Exception
    • registerElement

      private void registerElement(Class type, Label label) throws 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:
      label - this is the label that is to be registered
      name - this is the name of the label to be registered
      Throws:
      Exception
    • registerText

      private void registerText(Label label) throws 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:
      Exception