Package org.simpleframework.xml.core
Class StructureBuilder
java.lang.Object
org.simpleframework.xml.core.StructureBuilder
The
StructureBuilder object is used to build the XML
structure of an annotated class. Once all the information scanned
from the class has been collected a Structure object
can be built using this object. The structure instance will
contain relevant information regarding the class schema.
This builder exposes several methods, which are invoked in a
sequence by the Scanner object. In particular there
is a process method which is used to consume the
annotated fields and methods. With the annotations it then builds
the underlying structure representing the class schema.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ModelAssemblerThis is used to perform the initial ordered registrations.private LabelMapFor validation all attributes must be stored in the builder.private ExpressionBuilderThis is used to build XPath expressions from annotations.private LabelMapFor validation all elements must be stored in the builder.private InstantiatorThis is the instantiator that is used to create instances.private booleanThis is used to determine if the scanned class is primitive.private InstantiatorBuilderThis is used to build an instantiator for creating objects.private ModelThis the core model used to represent the XML structure.private ScannerThis is the source scanner that is used to scan the class.private SupportThis object contains various support functions for the class.private LabelThis represents a text annotation extracted from the class.private LabelMapThis is used to maintain the text labels for the class.private LabelThis is the version annotation extracted from the class. -
Constructor Summary
ConstructorsConstructorDescriptionStructureBuilder(Scanner scanner, Detail detail, Support support) Constructor for theStructureBuilderobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis is used to acquire the optional order annotation to provide order to the elements and attributes for the generated XML.This is used to build theStructurethat has been built.voidThis is used to commit the structure of the type.private Modelcreate(Expression path) This is used to register aModelfor this builder.private booleanisAttribute(String path) This is used to determine if the specified XPath expression represents an attribute within the root model.private booleanThis is used to determine if the specified XPath expression represents an element within the root model.private booleanisEmpty()This is used to determine if the structure is empty.private Modellookup(Expression path) This method is used to look for aModelthat matches the specified expression.voidprocess(Contact field, Annotation label) This reflectively checks the annotation to determine the type of annotation it represents.private voidprocess(Contact field, Annotation type, LabelMap map) This is used when all details from a field have been gathered and aLabelimplementation needs to be created.private voidThis is used when all details from a field have been gathered and aLabelimplementation needs to be created.private Modelregister(Expression path) This is used to register aModelfor this builder.private voidtext(Contact field, Annotation type) This is used to process theTextannotations that are present in the scanned class.private voidunion(Contact field, Annotation type, LabelMap map) This is used when all details from a field have been gathered and aLabelimplementation needs to be created.voidThis is used to validate the configuration of the scanned class.private voidvalidateAttributes(Class type, Order order) This is used to validate the configuration of the scanned class.private voidvalidateElements(Class type, Order order) This is used to validate the configuration of the scanned class.private voidvalidateModel(Class type) This is used to validate the model to ensure all elements and attributes are valid.private voidvalidateText(Class type) This is used to validate the configuration of the scanned class.private voidvalidateTextList(Class type) This is used to validate the configuration of the scanned class.private voidvalidateUnions(Class type) This is used to validate the unions that have been defined within the type.private voidversion(Contact field, Annotation type) This is used to process theTextannotations that are present in the scanned class.
-
Field Details
-
resolver
This is used to build an instantiator for creating objects. -
builder
This is used to build XPath expressions from annotations. -
assembler
This is used to perform the initial ordered registrations. -
factory
This is the instantiator that is used to create instances. -
attributes
For validation all attributes must be stored in the builder. -
elements
For validation all elements must be stored in the builder. -
texts
This is used to maintain the text labels for the class. -
scanner
This is the source scanner that is used to scan the class. -
support
This object contains various support functions for the class. -
version
This is the version annotation extracted from the class. -
text
This represents a text annotation extracted from the class. -
root
This the core model used to represent the XML structure. -
primitive
private boolean primitiveThis is used to determine if the scanned class is primitive.
-
-
Constructor Details
-
StructureBuilder
Constructor for theStructureBuilderobject. This is used to process all the annotations for a class schema and build a hierarchical model representing the required structure. Once the structure has been built then it is validated to ensure that all elements and attributes exist.- Parameters:
scanner- this is the scanner used to scan annotationstype- this is the type that is being scannedformat- this is the format used to style the XML- Throws:
Exception
-
-
Method Details
-
assemble
This is used to acquire the optional order annotation to provide order to the elements and attributes for the generated XML. This acts as an override to the order provided by the declaration of the types within the object.- Parameters:
type- this is the type to be scanned for the order- Throws:
Exception
-
process
This reflectively checks the annotation to determine the type of annotation it represents. If it represents an XML schema annotation it is used to create aLabelwhich can be used to represent the field within the context object.- Parameters:
field- the field that the annotation comes fromlabel- the annotation used to model the XML schema- Throws:
Exception- if there is more than one text annotation
-
union
This is used when all details from a field have been gathered and aLabelimplementation needs to be created. This will build a label instance based on the field annotation. If a label with the same name was already inserted then it is ignored and the value for that field will not be serialized.- Parameters:
field- the field the annotation was extracted fromtype- the annotation extracted from the fieldmap- this is used to collect the label instance created- Throws:
Exception- thrown if the label can not be created
-
process
This is used when all details from a field have been gathered and aLabelimplementation needs to be created. This will build a label instance based on the field annotation. If a label with the same name was already inserted then it is ignored and the value for that field will not be serialized.- Parameters:
field- the field the annotation was extracted fromtype- the annotation extracted from the fieldmap- this is used to collect the label instance created- Throws:
Exception- thrown if the label can not be created
-
process
This is used when all details from a field have been gathered and aLabelimplementation needs to be created. This will build a label instance based on the field annotation. If a label with the same name was already inserted then it is ignored and the value for that field will not be serialized.- Parameters:
field- the field the annotation was extracted fromlabel- this is the label representing a field or methodmap- this is used to collect the label instance created- Throws:
Exception- thrown if the label can not be created
-
text
This is used to process theTextannotations that are present in the scanned class. This will set the text label for the class and an ensure that if there is more than one text label within the class an exception is thrown.- Parameters:
field- the field the annotation was extracted fromtype- the annotation extracted from the field- Throws:
Exception- if there is more than one text annotation
-
version
This is used to process theTextannotations that are present in the scanned class. This will set the text label for the class and an ensure that if there is more than one text label within the class an exception is thrown.- Parameters:
field- the field the annotation was extracted fromtype- the annotation extracted from the field- Throws:
Exception- if there is more than one text annotation
-
build
This is used to build theStructurethat has been built. The structure will contain all the details required to serialize and deserialize the type. Once created the structure is immutable, and can be used to createSectionobjects, which contains the element and attribute details.- Parameters:
type- this is the type that represents the schema class- Returns:
- this returns the structure that has been built
- Throws:
Exception
-
isElement
This is used to determine if the specified XPath expression represents an element within the root model. This will return true if the specified path exists as either an element or as a valid path to an existing model.If the path references a
Modelthen that is an element only if it is not empty. If the model is empty this means that it was used in theOrderannotation only and this does not refer to a value XML element.- Parameters:
path- this is the path to search for the element- Returns:
- this returns true if an element or model exists
- Throws:
Exception
-
isAttribute
This is used to determine if the specified XPath expression represents an attribute within the root model. This returns true if the specified path exists as either an attribute.- Parameters:
path- this is the path to search for the attribute- Returns:
- this returns true if the attribute exists
- Throws:
Exception
-
lookup
This method is used to look for aModelthat matches the specified expression. If no such model exists then this will return null. Using an XPath expression allows a tree like structure to be navigated with ease.- Parameters:
path- an XPath expression used to locate a model- Returns:
- this returns the model located by the expression
- Throws:
Exception
-
register
This is used to register aModelfor this builder. Registration of a model creates a tree of models that is used to represent an XML structure. Each model can contain elements and attributes associated with a type.- Parameters:
path- this is the path of the model to be resolved- Returns:
- this returns the model that was registered
- Throws:
Exception
-
create
This is used to register aModelfor this builder. Registration of a model creates a tree of models that is used to represent an XML structure. Each model can contain elements and attributes associated with a type.- Parameters:
path- this is the path of the model to be resolved- Returns:
- this returns the model that was registered
- Throws:
Exception
-
commit
This is used to commit the structure of the type. This will build anInstantiatorthat can be used to create instances using annotated constructors. If no constructors have be annotated then instances can use the default constructor.- Parameters:
type- this is the type that this builder creates- Throws:
Exception
-
validate
This is used to validate the configuration of the scanned class. If aTextannotation has been used with elements then validation will fail and an exception will be thrown.- Parameters:
type- this is the object type that is being scanned- Throws:
Exception
-
validateModel
This is used to validate the model to ensure all elements and attributes are valid. Validation also ensures that any order specified by an annotated class did not contain invalid XPath values, or redundant elements and attributes.- Parameters:
type- this is the object type representing the schema- Throws:
Exception
-
validateText
This is used to validate the configuration of the scanned class. If aTextannotation has been used with elements then validation will fail and an exception will be thrown.- Parameters:
type- this is the object type that is being scanned- Throws:
Exception
-
validateTextList
This is used to validate the configuration of the scanned class. If anElementListUnionannotation has been used with aTextannotation this validates to ensure there are no other elements declared and noPathannotations have been used, which ensures free text can be processed.- Parameters:
type- this is the object type that is being scanned- Throws:
Exception
-
validateUnions
This is used to validate the unions that have been defined within the type. Union validation is done by determining if the union has consistent inline values. If one annotation in the union declaration is inline, then all must be inline.- Parameters:
type- this is the type to validate the unions for- Throws:
Exception
-
validateElements
This is used to validate the configuration of the scanned class. If an ordered element is specified but does not refer to an existing element then this will throw an exception.- Parameters:
type- this is the object type that is being scannedorder- this is the order that is to be validated- Throws:
Exception
-
validateAttributes
This is used to validate the configuration of the scanned class. If an ordered attribute is specified but does not refer to an existing attribute then this will throw an exception.- Parameters:
type- this is the object type that is being scannedorder- this is the order that is to be validated- Throws:
Exception
-
isEmpty
private boolean isEmpty()This is used to determine if the structure is empty. To check to see if the structure is empty all models within the tree must be examined. Also, if there is a text annotation then it is not considered to be empty.- Returns:
- true if the structure represents an empty schema
-