Package org.simpleframework.xml.core
Interface Model
-
- All Superinterfaces:
java.lang.Iterable<java.lang.String>
- All Known Implementing Classes:
TreeModel
interface Model extends java.lang.Iterable<java.lang.String>
TheModel
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:
Section
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description LabelMap
getAttributes()
This is used to build a map from aContext
object.LabelMap
getElements()
This is used to build a map from aContext
object.Expression
getExpression()
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.ModelMap
getModels()
This is used to build a map from aContext
object.java.lang.String
getName()
This is used to return the name of the model.java.lang.String
getPrefix()
This is used to acquire the path prefix for the model.Label
getText()
This returns a text label if one is associated with the model.boolean
isAttribute(java.lang.String name)
This is used to determine if the provided name represents an attribute.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.boolean
isElement(java.lang.String name)
This is used to determine if the provided name represents an element.boolean
isEmpty()
Used to determine if a model is empty.boolean
isModel(java.lang.String name)
This is used to determine if the provided name represents a model.Model
lookup(java.lang.String name, int index)
This method is used to look for aModel
that matches the specified element name.Model
lookup(Expression path)
This method is used to look for aModel
that matches the specified expression.Model
register(java.lang.String name, java.lang.String prefix, int index)
This is used to register aModel
within this model.void
register(Label label)
This is used to register an XML entity within the model.void
registerAttribute(java.lang.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(java.lang.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
validate(java.lang.Class type)
This is used to validate the model to ensure all elements and attributes are valid.
-
-
-
Method Detail
-
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
boolean isModel(java.lang.String name)
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
boolean isElement(java.lang.String name)
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
boolean isAttribute(java.lang.String name)
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
void validate(java.lang.Class type) throws java.lang.Exception
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:
java.lang.Exception
- if text and element annotations are present
-
register
void register(Label label) throws java.lang.Exception
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:
java.lang.Exception
-
registerText
void registerText(Label label) throws java.lang.Exception
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:
java.lang.Exception
-
registerElement
void registerElement(Label label) throws java.lang.Exception
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:
java.lang.Exception
-
registerAttribute
void registerAttribute(Label label) throws java.lang.Exception
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:
java.lang.Exception
-
registerElement
void registerElement(java.lang.String name) throws java.lang.Exception
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:
java.lang.Exception
-
registerAttribute
void registerAttribute(java.lang.String name) throws java.lang.Exception
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:
java.lang.Exception
-
register
Model register(java.lang.String name, java.lang.String prefix, int index) throws java.lang.Exception
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:
java.lang.Exception
-
lookup
Model lookup(java.lang.String name, int index)
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
Model lookup(Expression path)
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
LabelMap getElements() throws java.lang.Exception
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:
java.lang.Exception
-
getAttributes
LabelMap getAttributes() throws java.lang.Exception
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:
java.lang.Exception
-
getModels
ModelMap getModels() throws java.lang.Exception
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:
java.lang.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
java.lang.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
java.lang.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
-
-