Class LabelExtractor

java.lang.Object
org.simpleframework.xml.core.LabelExtractor

class LabelExtractor extends Object
The LabelExtractor object is used to create instances of the Label object that can be used to convert an XML node into a Java object. Each label created requires the contact it represents and the XML annotation it is marked with.

The Label objects created by this factory a selected using the XML annotation type. If the annotation type is not known the factory will throw an exception, otherwise a label instance is created that will expose the properties of the annotation.

  • Field Details

    • cache

      private final Cache<LabelGroup> cache
      This is used to cache the list of labels that have been created.
    • format

      private final Format format
      Contains the format that is associated with the serializer.
  • Constructor Details

    • LabelExtractor

      public LabelExtractor(Format format)
      Constructor for the LabelExtractor object. This creates an extractor that will extract labels for a specific contact. Labels are cached within the extractor so that they can be looked up without having to rebuild it each time.
      Parameters:
      format - this is the format used by the serializer
  • Method Details

    • getLabel

      public Label getLabel(Contact contact, Annotation label) throws Exception
      Creates a Label using the provided contact and XML annotation. The label produced contains all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      returns the label instantiated for the contact
      Throws:
      Exception
    • getList

      public List<Label> getList(Contact contact, Annotation label) throws Exception
      Creates a List using the provided contact and XML annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getGroup

      private LabelGroup getGroup(Contact contact, Annotation label, Object key) throws Exception
      Creates a LabelGroup using the provided contact and annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      key - this is the key that uniquely represents the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getLabels

      private LabelGroup getLabels(Contact contact, Annotation label) throws Exception
      Creates a LabelGroup using the provided contact and annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getSingle

      private LabelGroup getSingle(Contact contact, Annotation label) throws Exception
      Creates a LabelGroup using the provided contact and annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getUnion

      private LabelGroup getUnion(Contact contact, Annotation label) throws Exception
      Creates a LabelGroup using the provided contact and annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getAnnotations

      private Annotation[] getAnnotations(Annotation label) throws Exception
      This is used to extract the individual annotations associated with the union annotation provided. If the annotation does not represent a union then this will return null.
      Parameters:
      label - this is the annotation to extract from
      Returns:
      this returns an array of annotations from the union
      Throws:
      Exception
    • getLabel

      private Label getLabel(Contact contact, Annotation label, Annotation entry) throws Exception
      Creates a Label using the provided contact and XML annotation. The label produced contains all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      entry - this is the annotation used for the entries
      Returns:
      returns the label instantiated for the field
      Throws:
      Exception
    • getKey

      private Object getKey(Contact contact, Annotation label)
      This is used to create a key to uniquely identify a label that is associated with a contact. A key contains the contact type, the declaring class, the name, and the annotation type. This will uniquely identify the label within the class.
      Parameters:
      contact - this is contact that the label is produced for
      label - represents the XML annotation for the contact
      Returns:
      this returns the key associated with the label
    • getConstructor

      private Constructor getConstructor(Annotation label) throws Exception
      Creates a constructor that can be used to instantiate the label used to represent the specified annotation. The constructor created by this method takes two arguments, a contact object and an Annotation of the type specified.
      Parameters:
      label - the XML annotation representing the label
      Returns:
      returns a constructor for instantiating the label
      Throws:
      Exception
    • getBuilder

      private LabelExtractor.LabelBuilder getBuilder(Annotation label) throws Exception
      Creates an entry that is used to select the constructor for the label. Each label must implement a constructor that takes a contact and the specific XML annotation for that field. If the annotation is not know this method throws an exception.
      Parameters:
      label - the XML annotation used to create the label
      Returns:
      this returns the entry used to create a constructor
      Throws:
      Exception