Package org.simpleframework.xml.core
Class LabelExtractor
- java.lang.Object
-
- org.simpleframework.xml.core.LabelExtractor
-
class LabelExtractor extends java.lang.Object
TheLabelExtractor
object is used to create instances of theLabel
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
LabelExtractor.LabelBuilder
TheLabelBuilder
object will create a constructor that can be used to instantiate the correct label for the XML annotation specified.
-
Field Summary
Fields Modifier and Type Field Description private Cache<LabelGroup>
cache
This is used to cache the list of labels that have been created.private Format
format
Contains the format that is associated with the serializer.
-
Constructor Summary
Constructors Constructor Description LabelExtractor(Format format)
Constructor for theLabelExtractor
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.annotation.Annotation[]
getAnnotations(java.lang.annotation.Annotation label)
This is used to extract the individual annotations associated with the union annotation provided.private LabelExtractor.LabelBuilder
getBuilder(java.lang.annotation.Annotation label)
Creates an entry that is used to select the constructor for the label.private java.lang.reflect.Constructor
getConstructor(java.lang.annotation.Annotation label)
Creates a constructor that can be used to instantiate the label used to represent the specified annotation.private LabelGroup
getGroup(Contact contact, java.lang.annotation.Annotation label, java.lang.Object key)
Creates aLabelGroup
using the provided contact and annotation.private java.lang.Object
getKey(Contact contact, java.lang.annotation.Annotation label)
This is used to create a key to uniquely identify a label that is associated with a contact.Label
getLabel(Contact contact, java.lang.annotation.Annotation label)
Creates aLabel
using the provided contact and XML annotation.private Label
getLabel(Contact contact, java.lang.annotation.Annotation label, java.lang.annotation.Annotation entry)
Creates aLabel
using the provided contact and XML annotation.private LabelGroup
getLabels(Contact contact, java.lang.annotation.Annotation label)
Creates aLabelGroup
using the provided contact and annotation.java.util.List<Label>
getList(Contact contact, java.lang.annotation.Annotation label)
Creates aList
using the provided contact and XML annotation.private LabelGroup
getSingle(Contact contact, java.lang.annotation.Annotation label)
Creates aLabelGroup
using the provided contact and annotation.private LabelGroup
getUnion(Contact contact, java.lang.annotation.Annotation label)
Creates aLabelGroup
using the provided contact and annotation.
-
-
-
Field Detail
-
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 Detail
-
LabelExtractor
public LabelExtractor(Format format)
Constructor for theLabelExtractor
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 Detail
-
getLabel
public Label getLabel(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aLabel
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 forlabel
- represents the XML annotation for the contact- Returns:
- returns the label instantiated for the contact
- Throws:
java.lang.Exception
-
getList
public java.util.List<Label> getList(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aList
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 forlabel
- represents the XML annotation for the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getGroup
private LabelGroup getGroup(Contact contact, java.lang.annotation.Annotation label, java.lang.Object key) throws java.lang.Exception
Creates aLabelGroup
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 forlabel
- represents the XML annotation for the contactkey
- this is the key that uniquely represents the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getLabels
private LabelGroup getLabels(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aLabelGroup
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 forlabel
- represents the XML annotation for the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getSingle
private LabelGroup getSingle(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aLabelGroup
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 forlabel
- represents the XML annotation for the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getUnion
private LabelGroup getUnion(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aLabelGroup
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 forlabel
- represents the XML annotation for the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getAnnotations
private java.lang.annotation.Annotation[] getAnnotations(java.lang.annotation.Annotation label) throws java.lang.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:
java.lang.Exception
-
getLabel
private Label getLabel(Contact contact, java.lang.annotation.Annotation label, java.lang.annotation.Annotation entry) throws java.lang.Exception
Creates aLabel
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 forlabel
- represents the XML annotation for the contactentry
- this is the annotation used for the entries- Returns:
- returns the label instantiated for the field
- Throws:
java.lang.Exception
-
getKey
private java.lang.Object getKey(Contact contact, java.lang.annotation.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 forlabel
- represents the XML annotation for the contact- Returns:
- this returns the key associated with the label
-
getConstructor
private java.lang.reflect.Constructor getConstructor(java.lang.annotation.Annotation label) throws java.lang.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 anAnnotation
of the type specified.- Parameters:
label
- the XML annotation representing the label- Returns:
- returns a constructor for instantiating the label
- Throws:
java.lang.Exception
-
getBuilder
private LabelExtractor.LabelBuilder getBuilder(java.lang.annotation.Annotation label) throws java.lang.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:
java.lang.Exception
-
-