Package org.simpleframework.xml.core
Class TreeModel
java.lang.Object
org.simpleframework.xml.core.TreeModel
The
TreeModel
object is used to build a tree like
structure to represent the XML schema for an annotated class. The
model is responsible for building, ordering, and validating all
criteria used to represent the class schema. This is immutable
to ensure it can be reused many time, in a concurrent environment.
Each time attribute and element definitions are requested they
are build as new LabelMap
objects using a provided
context. This ensures the mappings can be styled as required.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
TheOrderList
object is used to maintain the order of the XML elements within the model. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LabelMap
This holds the mappings for elements within the model.private Detail
This is the type used for reporting validation errors.private LabelMap
This holds the mappings for elements within the model.private Expression
This is the XPath expression representing the location.private int
This is the index used to sort similarly named models.private Label
This is an optional text label used for this model.private ModelMap
This holds the mappings for the models within this instance.private String
This must be a valid XML element representing the name.private TreeModel.OrderList
This is used to provide the order of the model elements.private Policy
This is the serialization policy enforced on this model.private String
This is used to represent the prefix for this model.private Label
This is an optional text label used for this model. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Model
This is used to register aModel
within this model.This is used to build a map from aContext
object.This is used to build a map from aContext
object.This returns anExpression
representing the path this model exists at within the class schema.int
getIndex()
This method is used to return the index of the model.This is used to build a map from aContext
object.getName()
This is used to return the name of the model.This is used to acquire the path prefix for the model.getText()
This returns a text label if one is associated with the model.boolean
isAttribute
(String name) This is used to determine if the provided name represents an attribute.boolean
This is used to perform a recursive search of the models that have been registered, if a model has elements or attributes then this returns true.boolean
This is used to determine if the provided name represents an element.boolean
isEmpty()
Used to determine if a model is empty.boolean
This is used to determine if the provided name represents a model.iterator()
This will return the names of all elements contained within the model.This method is used to look for aModel
that matches the specified element name.lookup
(Expression path) This method is used to look for aModel
that matches the specified expression.This is used to register aModel
within this model.void
This is used to register an XML entity within the model.void
registerAttribute
(String name) This is used to register an XML entity within the model.void
registerAttribute
(Label label) This is used to register an XML entity within the model.void
registerElement
(String name) This is used to register an XML entity within the model.void
registerElement
(Label label) This is used to register an XML entity within the model.void
registerText
(Label label) This is used to register an XML entity within the model.toString()
For the purposes of debugging we provide a representation of the model in a string format.void
This is used to validate the model to ensure all elements and attributes are valid.private void
validateAttributes
(Class type) This is used to validate the individual attributes within the model.private void
validateElements
(Class type) This is used to validate the individual elements within the model.private void
validateExpression
(Label label) This is used to validate the expressions used for a label that this model represents.private void
validateExpressions
(Class type) This is used to validate the expressions used for each label that this model represents.private void
validateModels
(Class type) This is used to validate the models within the instance.private void
validateText
(Class type) This method is used to validate the model based on whether it has a text annotation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
expression
This is the XPath expression representing the location. -
attributes
This holds the mappings for elements within the model. -
elements
This holds the mappings for elements within the model. -
models
This holds the mappings for the models within this instance. -
order
This is used to provide the order of the model elements. -
policy
This is the serialization policy enforced on this model. -
detail
This is the type used for reporting validation errors. -
name
This must be a valid XML element representing the name. -
prefix
This is used to represent the prefix for this model. -
text
This is an optional text label used for this model. -
list
This is an optional text label used for this model. -
index
private int indexThis is the index used to sort similarly named models.
-
-
Constructor Details
-
TreeModel
Constructor for theTreeModel
object. This can be used to register the attributes and elements associated with an annotated class. Also, if there are any path references, this can contain a tree of models mirroring the XML structure.- Parameters:
policy
- this is the serialization policy enforceddetail
- this is the detail associated with this model
-
TreeModel
Constructor for theTreeModel
object. This can be used to register the attributes and elements associated with an annotated class. Also, if there are any path references, this can contain a tree of models mirroring the XML structure.- Parameters:
policy
- this is the serialization policy enforceddetail
- this is the detail associated with this modelname
- this is the XML element name for this modelprefix
- this is the prefix used for this model objectindex
- this is the index used to order the model
-
-
Method Details
-
lookup
This method is used to look for aModel
that 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. -
registerElement
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over.- Specified by:
registerElement
in interfaceModel
- Parameters:
name
- this is the name of the element to register- Throws:
Exception
-
registerAttribute
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over.- Specified by:
registerAttribute
in interfaceModel
- Parameters:
name
- this is the name of the element to register- Throws:
Exception
-
registerText
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over.- Specified by:
registerText
in interfaceModel
- Parameters:
label
- this is the label to register with the model- Throws:
Exception
-
registerAttribute
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over.- Specified by:
registerAttribute
in interfaceModel
- Parameters:
label
- this is the label to register with the model- Throws:
Exception
-
registerElement
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over.- Specified by:
registerElement
in interfaceModel
- Parameters:
label
- this is the label to register with the model- Throws:
Exception
-
getModels
This is used to build a map from aContext
object. Building a map in this way ensures that any style specified by the context can be used to create the XML element and attribute names in the styled format. It also ensures that the model remains immutable as it only provides copies of its data. -
getAttributes
This is used to build a map from aContext
object. Building a map in this way ensures that any style specified by the context can be used to create the XML element and attribute names in the styled format. It also ensures that the model remains immutable as it only provides copies of its data.- Specified by:
getAttributes
in interfaceModel
- Returns:
- this returns a map built from the specified context
- Throws:
Exception
-
getElements
This is used to build a map from aContext
object. Building a map in this way ensures that any style specified by the context can be used to create the XML element and attribute names in the styled format. It also ensures that the model remains immutable as it only provides copies of its data.- Specified by:
getElements
in interfaceModel
- Returns:
- this returns a map built from the specified context
- Throws:
Exception
-
isModel
This is used to determine if the provided name represents a model. This is useful when validating the model as it allows determination of a named model, which is an element. -
isElement
This is used to determine if the provided name represents an element. This is useful when validating the model as it allows determination of a named XML element. -
isAttribute
This is used to determine if the provided name represents an attribute. This is useful when validating the model as it allows determination of a named XML attribute- Specified by:
isAttribute
in interfaceModel
- Parameters:
name
- this is the name of the attribute to determine- Returns:
- this returns true if the attribute is registered
-
iterator
This will return the names of all elements contained within the model. This includes the names of all XML elements that have been registered as well as any other models that have been added. Iteration is done in an ordered manner, according to the registration of elements and models. -
validate
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. -
validateText
This method is used to validate the model based on whether it has a text annotation. If this model has a text annotation then it is checked to see if it is a composite model or has any elements. If it has either then the model is considered invalid.- Parameters:
type
- this is the object type representing the schema- Throws:
Exception
-
validateExpressions
This is used to validate the expressions used for each label that this model represents. Each label within a model must have an XPath expression, if the expressions do not match then this will throw an exception. If the model contains no labels then it is considered empty and does not need validation.- Parameters:
type
- this is the object type representing the schema- Throws:
Exception
-
validateExpression
This is used to validate the expressions used for a label that this model represents. Each label within a model must have an XPath expression, if the expressions do not match then this will throw an exception. If the model contains no labels then it is considered empty and does not need validation.- Parameters:
label
- this is the object type representing the schema- Throws:
Exception
-
validateModels
This is used to validate the models within the instance. This will basically result in validation of the entire tree. Once finished all models contained within the tree will be valid. If any model is invalid an exception will be thrown.To ensure that all ordering and registration of the models is consistent this will check to ensure the indexes of each registered model are in sequence. If they are out of sequence then this will throw an exception.
- Parameters:
type
- this is the type this model is created for- Throws:
Exception
-
validateAttributes
This is used to validate the individual attributes within the model. Validation is done be acquiring all the attributes and determining if they are null. If they are null this means that an ordering has been imposed on a non-existing attribute.- Parameters:
type
- this is the type this model is created for- Throws:
Exception
-
validateElements
This is used to validate the individual elements within the model. Validation is done be acquiring all the elements and determining if they are null. If they are null this means that an ordering has been imposed on a non-existing element.- Parameters:
type
- this is the type this model is created for- Throws:
Exception
-
register
This is used to register an XML entity within the model. The registration process has the affect of telling the model that it will contain a specific, named, XML entity. It also has the affect of ordering them within the model, such that the first registered entity is the first iterated over. -
lookup
This method is used to look for aModel
that matches the specified element name. If no such model exists then this will return null. This is used as an alternative to providing an XPath expression to navigate the tree. -
register
This is used to register aModel
within this model. Registration of a model creates a tree of models that can be used to represent an XML structure. Each model can contain elements and attributes associated with a type. -
create
This is used to register aModel
within this model. Registration of a model creates a tree of models that can be used to represent an XML structure. Each model can contain elements and attributes associated with a type.- Parameters:
name
- this is the name of the model to be registeredprefix
- this is the prefix used for this modelindex
- this is the index used to order the model- Returns:
- this returns the model that was registered
- Throws:
Exception
-
isComposite
public boolean isComposite()This is used to perform a recursive search of the models that have been registered, if a model has elements or attributes then this returns true. If however no other model contains any attributes or elements then this will return false.- Specified by:
isComposite
in interfaceModel
- Returns:
- true if any model has elements or attributes
-
isEmpty
public boolean isEmpty()Used to determine if a model is empty. A model is considered empty if that model does not contain any registered elements or attributes. However, if the model contains other models that have registered elements or attributes it is not empty. -
getText
This returns a text label if one is associated with the model. If the model does not contain a text label then this method will return null. Any model with a text label should not be composite and should not contain any elements. -
getExpression
This returns anExpression
representing the path this model exists at within the class schema. This should never be null for any model that is not empty.- Specified by:
getExpression
in interfaceModel
- Returns:
- this returns the expression associated with this
-
getPrefix
This is used to acquire the path prefix for the model. The path prefix is used when the model is transformed in to an XML structure. This ensures that the XML element created to represent the model contains the optional prefix. -
getName
This is used to return the name of the model. The name is must be a valid XML element name. It is used when a style is applied to a section as the model name must be styled. -
getIndex
public int getIndex()This method is used to return the index of the model. The index is the order that this model appears within the XML document. Having an index allows multiple models of the same name to be inserted in to a sorted collection. -
toString
For the purposes of debugging we provide a representation of the model in a string format. This will basically show the name of the model and the index it exists at.
-