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 classTheOrderListobject is used to maintain the order of the XML elements within the model. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LabelMapThis holds the mappings for elements within the model.private DetailThis is the type used for reporting validation errors.private LabelMapThis holds the mappings for elements within the model.private ExpressionThis is the XPath expression representing the location.private intThis is the index used to sort similarly named models.private LabelThis is an optional text label used for this model.private ModelMapThis holds the mappings for the models within this instance.private StringThis must be a valid XML element representing the name.private TreeModel.OrderListThis is used to provide the order of the model elements.private PolicyThis is the serialization policy enforced on this model.private StringThis is used to represent the prefix for this model.private LabelThis is an optional text label used for this model. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate ModelThis is used to register aModelwithin this model.This is used to build a map from aContextobject.This is used to build a map from aContextobject.This returns anExpressionrepresenting the path this model exists at within the class schema.intgetIndex()This method is used to return the index of the model.This is used to build a map from aContextobject.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.booleanisAttribute(String name) This is used to determine if the provided name represents an attribute.booleanThis 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.booleanThis is used to determine if the provided name represents an element.booleanisEmpty()Used to determine if a model is empty.booleanThis 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 aModelthat matches the specified element name.lookup(Expression path) This method is used to look for aModelthat matches the specified expression.This is used to register aModelwithin this model.voidThis is used to register an XML entity within the model.voidregisterAttribute(String name) This is used to register an XML entity within the model.voidregisterAttribute(Label label) This is used to register an XML entity within the model.voidregisterElement(String name) This is used to register an XML entity within the model.voidregisterElement(Label label) This is used to register an XML entity within the model.voidregisterText(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.voidThis is used to validate the model to ensure all elements and attributes are valid.private voidvalidateAttributes(Class type) This is used to validate the individual attributes within the model.private voidvalidateElements(Class type) This is used to validate the individual elements within the model.private voidvalidateExpression(Label label) This is used to validate the expressions used for a label that this model represents.private voidvalidateExpressions(Class type) This is used to validate the expressions used for each label that this model represents.private voidvalidateModels(Class type) This is used to validate the models within the instance.private voidvalidateText(Class type) This method is used to validate the model based on whether it has a text annotation.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface 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 theTreeModelobject. 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 theTreeModelobject. 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 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. -
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:
registerElementin 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:
registerAttributein 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:
registerTextin 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:
registerAttributein 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:
registerElementin interfaceModel- Parameters:
label- this is the label to register with the model- Throws:
Exception
-
getModels
This is used to build a map from aContextobject. 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 aContextobject. 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:
getAttributesin interfaceModel- Returns:
- this returns a map built from the specified context
- Throws:
Exception
-
getElements
This is used to build a map from aContextobject. 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:
getElementsin 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:
isAttributein 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 aModelthat 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 aModelwithin 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 aModelwithin 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:
isCompositein 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 anExpressionrepresenting the path this model exists at within the class schema. This should never be null for any model that is not empty.- Specified by:
getExpressionin 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
-
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
-