Class GroupExtractor

  • All Implemented Interfaces:
    Group

    class GroupExtractor
    extends java.lang.Object
    implements Group
    The GroupExtractor represents an extractor for labels associated with a particular union annotation. This extractor registers Label by name and by type. Acquiring the label by type allows the serialization process to dynamically select a label, and thus converter, based on the instance type. On deserialization a label is dynamically selected based on name.
    See Also:
    Group
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  GroupExtractor.Registry
      The Registry object is used to maintain mappings from types to labels.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private LabelMap elements
      This contains each label registered by label name.
      private ExtractorFactory factory
      This represents a factory for creating union extractors.
      private java.lang.annotation.Annotation label
      This represents the union label to be used for this group.
      private GroupExtractor.Registry registry
      This contains each label registered by name and by type.
    • Constructor Summary

      Constructors 
      Constructor Description
      GroupExtractor​(Contact contact, java.lang.annotation.Annotation label, Format format)
      Constructor for the GroupExtractor object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void extract()
      This is used to extract the labels associated with the group.
      private void extract​(Extractor extractor)
      This is used to extract the labels associated with the group.
      private void extract​(Extractor extractor, java.lang.annotation.Annotation value)
      This is used to extract the labels associated with the group.
      LabelMap getElements()
      This is used to acquire a LabelMap containing the labels available to the group.
      Label getLabel​(java.lang.Class type)
      This is used to acquire a Label based on the type of an object.
      java.lang.String[] getNames()
      This is used to acquire the names for each label associated with this Group instance.
      java.lang.String[] getPaths()
      This is used to acquire the paths for each label associated with this Group instance.
      Label getText()
      This is used to get a Label that represents the text between elements on an element union.
      boolean isDeclared​(java.lang.Class type)
      This is used to determine if a type has been declared by the annotation associated with the group.
      boolean isInline()
      This is used to determine if the group is inline.
      boolean isTextList()
      This is used to determine if an annotated list is a text list.
      boolean isValid​(java.lang.Class type)
      This is used to determine if the associated type represents a label defined within the union group.
      java.lang.String toString()
      This returns a string representation of the union group.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • factory

        private final ExtractorFactory factory
        This represents a factory for creating union extractors.
      • label

        private final java.lang.annotation.Annotation label
        This represents the union label to be used for this group.
      • registry

        private final GroupExtractor.Registry registry
        This contains each label registered by name and by type.
      • elements

        private final LabelMap elements
        This contains each label registered by label name.
    • Constructor Detail

      • GroupExtractor

        public GroupExtractor​(Contact contact,
                              java.lang.annotation.Annotation label,
                              Format format)
                       throws java.lang.Exception
        Constructor for the GroupExtractor object. This will create an extractor for the provided union annotation. Each individual declaration within the union is extracted and made available within the group.
        Parameters:
        contact - this is the annotated field or method
        label - this is the label associated with the contact
        format - this is the format used by this extractor
        Throws:
        java.lang.Exception
    • Method Detail

      • getNames

        public java.lang.String[] getNames()
                                    throws java.lang.Exception
        This is used to acquire the names for each label associated with this Group instance. The names provided here are not styled according to a serialization context.
        Returns:
        this returns the names of each union extracted
        Throws:
        java.lang.Exception
      • getPaths

        public java.lang.String[] getPaths()
                                    throws java.lang.Exception
        This is used to acquire the paths for each label associated with this Group instance. The paths provided here are not styled according to a serialization context.
        Returns:
        this returns the paths of each union extracted
        Throws:
        java.lang.Exception
      • getElements

        public LabelMap getElements()
                             throws java.lang.Exception
        This is used to acquire a LabelMap containing the labels available to the group. Providing a context object ensures that each of the labels is mapped to a name that is styled according to its internal style.
        Specified by:
        getElements in interface Group
        Returns:
        this returns a label map containing the labels
        Throws:
        java.lang.Exception
      • getLabel

        public Label getLabel​(java.lang.Class type)
        This is used to acquire a Label based on the type of an object. Selecting a label based on the type ensures that the serialization process can dynamically convert an object to XML. If the type is not supported, this returns null.
        Specified by:
        getLabel in interface Group
        Parameters:
        type - this is the type to select the label from
        Returns:
        this returns the label based on the type
      • getText

        public Label getText()
        This is used to get a Label that represents the text between elements on an element union. Providing a label here ensures that the free text found between elements can be converted in to strings and added to the list.
        Specified by:
        getText in interface Group
        Returns:
        a label if a text annotation has been declared
      • isValid

        public boolean isValid​(java.lang.Class type)
        This is used to determine if the associated type represents a label defined within the union group. If the label exists this returns true, if not then this returns false.
        Parameters:
        type - this is the type to check for
        Returns:
        this returns true if a label for the type exists
      • isDeclared

        public boolean isDeclared​(java.lang.Class type)
        This is used to determine if a type has been declared by the annotation associated with the group. Unlike determining if the type is valid this will not consider super types.
        Parameters:
        type - this is the type to determine if it is declared
        Returns:
        this returns true if the type has been declared
      • isInline

        public boolean isInline()
        This is used to determine if the group is inline. A group is inline if all of the elements in the group is inline. If any of the Label objects in the group is not inline then the entire group is not inline, although this is unlikely.
        Specified by:
        isInline in interface Group
        Returns:
        this returns true if each label in the group is inline
      • isTextList

        public boolean isTextList()
        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.
        Specified by:
        isTextList in interface Group
        Returns:
        returns true if the label represents a text list
      • extract

        private void extract()
                      throws java.lang.Exception
        This is used to extract the labels associated with the group. Extraction will instantiate a Label object for an individual annotation declared within the union. Each of the label instances is then registered by both name and type.
        Throws:
        java.lang.Exception
      • extract

        private void extract​(Extractor extractor)
                      throws java.lang.Exception
        This is used to extract the labels associated with the group. Extraction will instantiate a Label object for an individual annotation declared within the union. Each of the label instances is then registered by both name and type.
        Parameters:
        extractor - this is the extractor to get labels for
        Throws:
        java.lang.Exception
      • extract

        private void extract​(Extractor extractor,
                             java.lang.annotation.Annotation value)
                      throws java.lang.Exception
        This is used to extract the labels associated with the group. Extraction will instantiate a Label object for an individual annotation declared within the union. Each of the label instances is then registered by both name and type.
        Parameters:
        extractor - this is the extractor to get labels for
        value - this is an individual annotation declared
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        This returns a string representation of the union group. Providing a string representation in this way ensures that the group can be used in exception messages and for any debugging.
        Specified by:
        toString in interface Group
        Overrides:
        toString in class java.lang.Object
        Returns:
        this returns a string representation of the group