Package org.simpleframework.xml.core
Interface Model
- All Known Implementing Classes:
TreeModel
The
Model
interface represents the core data structure
used for representing an XML schema. This is effectively a tree
like structure in that it can contain other models as well as XML
attributes and elements. Each model represents a context within an
XML document, each context is navigated to with an XPath expression.
The model is responsible for building the element and attribute labels used to read and write and also to ensure the correct order of the XML elements and attributes is enforced. Once the model has been completed it can then be validated to ensure its contents represent a valid XML structure.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionThis 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.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.void
This is used to validate the model to ensure all elements and attributes are valid.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
isEmpty
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.- Returns:
- true if the model does not contain registrations
-
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.- Parameters:
name
- this is the name of the section to determine- Returns:
- this returns true if the model is registered
-
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.- Parameters:
name
- this is the name of the section to determine- Returns:
- this returns true if the element is registered
-
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- Parameters:
name
- this is the name of the attribute to determine- Returns:
- this returns true if the attribute is registered
-
isComposite
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.- Returns:
- true if any model has elements or attributes
-
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.- Parameters:
type
- this is the object type representing the schema- Throws:
Exception
- if text and element annotations are present
-
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.- Parameters:
label
- this is the label to register with the model- 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.- 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.- 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.- 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.- 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.- Parameters:
name
- this is the name of the element to register- Throws:
Exception
-
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.- 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
-
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.- Parameters:
name
- this is the name of the model to be acquiredindex
- this is the index used to order the model- Returns:
- this returns the model located by the expression
-
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.- Parameters:
path
- an XPath expression used to locate a model- Returns:
- this returns the model located by the expression
-
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.- Returns:
- this returns a map built from the specified context
- Throws:
Exception
-
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.- Returns:
- this returns a map built from the specified context
- 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.- Returns:
- this returns a map built from the specified context
- Throws:
Exception
-
getText
Label 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.- Returns:
- this is the optional text label for this model
-
getExpression
Expression 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.- Returns:
- this returns the expression associated with this
-
getPrefix
String 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.- Returns:
- this returns the prefix for this model
-
getName
String 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.- Returns:
- this returns the name of this model instance
-
getIndex
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.- Returns:
- this is the index of this model instance
-