Package org.simpleframework.xml.core
Class ModelSection
- java.lang.Object
-
- org.simpleframework.xml.core.ModelSection
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>
,Section
class ModelSection extends java.lang.Object implements Section
TheModelSection
represents a section that is backed by aModel
instance. This is used to expose the XML structure of a schema class. In addition to wrapping the model this will also apply aStyle
to the names of the attributes and elements of the class schema.
-
-
Field Summary
Fields Modifier and Type Field Description private LabelMap
attributes
Represents a mapping between styled names and attributes.private LabelMap
elements
Represents a mapping between styled names and elements.private Model
model
This is the model that contains the elements and attributes.private ModelMap
models
Represents a mapping between styled names and models.
-
Constructor Summary
Constructors Constructor Description ModelSection(Model model)
Constructor for theModelSection
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAttribute(java.lang.String name)
This is used to acquire the full attribute path for this section.LabelMap
getAttributes()
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations.Label
getElement(java.lang.String name)
Returns the named element as aLabel
object.LabelMap
getElements()
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations.ModelMap
getModels()
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations.java.lang.String
getName()
This is used to return the name of the section.java.lang.String
getPath(java.lang.String name)
This is used to acquire the full element path for this section.java.lang.String
getPrefix()
This is used to acquire the path prefix for the section.Section
getSection(java.lang.String name)
Returns the named section as aSection
object.Label
getText()
This is used to acquire the text label for this section if one has been specified.boolean
isSection(java.lang.String name)
To differentiate between a section and an element this can be used.java.util.Iterator<java.lang.String>
iterator()
This will return the names of all elements contained within the model.
-
-
-
Field Detail
-
attributes
private LabelMap attributes
Represents a mapping between styled names and attributes.
-
elements
private LabelMap elements
Represents a mapping between styled names and elements.
-
models
private ModelMap models
Represents a mapping between styled names and models.
-
model
private Model model
This is the model that contains the elements and attributes.
-
-
Constructor Detail
-
ModelSection
public ModelSection(Model model)
Constructor for theModelSection
object. This is used to wrap aModel
in such a way that it can not be modified. This allows it to be used concurrently.- Parameters:
model
- this is the model this section will wrap
-
-
Method Detail
-
getName
public java.lang.String getName()
This is used to return the name of the section. The name is must be a valid XML element name. It is used when a style is applied to a path as the section name must be styled.
-
getPrefix
public java.lang.String getPrefix()
This is used to acquire the path prefix for the section. The path prefix is used when the section is transformed in to an XML structure. This ensures that the XML element created to represent the section contains the optional prefix.
-
getPath
public java.lang.String getPath(java.lang.String name) throws java.lang.Exception
This is used to acquire the full element path for this section. The element path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.
-
getAttribute
public java.lang.String getAttribute(java.lang.String name) throws java.lang.Exception
This is used to acquire the full attribute path for this section. The attribute path is simply the fully qualified path for this expression with the provided name appended. If this is an empty path, the provided name is returned.- Specified by:
getAttribute
in interfaceSection
- Parameters:
name
- this is the name of the attribute to be used- Returns:
- a fully qualified path for the specified name
- Throws:
java.lang.Exception
-
iterator
public java.util.Iterator<java.lang.String> 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.- Specified by:
iterator
in interfacejava.lang.Iterable<java.lang.String>
- Returns:
- an ordered and styled list of elements and models
-
isSection
public boolean isSection(java.lang.String name) throws java.lang.Exception
To differentiate between a section and an element this can be used. When iterating over the elements within the section the names of both elements and sections are provided. So in order to determine how to interpret the structure this can be used.
-
getModels
public ModelMap getModels() throws java.lang.Exception
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations. All of the attribute annotations are considered and gathered by name in this map. Also, if there is an associatedStyle
for serialization the attribute names are renamed with this.- Returns:
- returns the attributes associated with this section
- Throws:
java.lang.Exception
-
getText
public Label getText() throws java.lang.Exception
This is used to acquire the text label for this section if one has been specified. A text label can only exist in a section if there are no elements associated with the section and the section is not composite, as in it does not contain any further sections.
-
getAttributes
public LabelMap getAttributes() throws java.lang.Exception
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations. All of the attribute annotations are considered and gathered by name in this map. Also, if there is an associatedStyle
for serialization the attribute names are renamed with this.- Specified by:
getAttributes
in interfaceSection
- Returns:
- returns the attributes associated with this section
- Throws:
java.lang.Exception
-
getElements
public LabelMap getElements() throws java.lang.Exception
Returns aLabelMap
that contains the details for all fields and methods marked with XML annotations. All of the element annotations are considered and gathered by name in this map. Also, if there is an associatedStyle
for serialization the element names are renamed with this.- Specified by:
getElements
in interfaceSection
- Returns:
- returns the elements associated with this section
- Throws:
java.lang.Exception
-
getElement
public Label getElement(java.lang.String name) throws java.lang.Exception
Returns the named element as aLabel
object. For convenience this method is provided so that when iterating over the names of the elements in the section a specific one of interest can be acquired.To ensure that elements of the same name are not referenced more than once this will remove the element once acquired. This ensures that they are visited only once in serialization.
- Specified by:
getElement
in interfaceSection
- Parameters:
name
- the name of the element that is to be acquired- Returns:
- this returns the label associated with the name
- Throws:
java.lang.Exception
-
getSection
public Section getSection(java.lang.String name) throws java.lang.Exception
Returns the named section as aSection
object. For convenience this method is provided so that when iterating over the names of the elements in the section a specific one of interest can be acquired.To ensure that models of the same name are not referenced more than once this will remove the model once acquired. This ensures that they are visited only once in serialization.
- Specified by:
getSection
in interfaceSection
- Parameters:
name
- the name of the element that is to be acquired- Returns:
- this returns the section associated with the name
- Throws:
java.lang.Exception
-
-