Package org.simpleframework.xml.core
Class Support
- java.lang.Object
-
- org.simpleframework.xml.core.Support
-
- All Implemented Interfaces:
Filter
class Support extends java.lang.Object implements Filter
TheSupport
object is used to provide support to the serialization engine for processing and transforming strings. This contains aTransformer
which will create objects from strings and will also reverse this process converting an object to a string. This is used in the conversion of primitive types.- See Also:
Transformer
-
-
Field Summary
Fields Modifier and Type Field Description private DetailExtractor
defaults
This is used to extract the defaults for a specific class.private DetailExtractor
details
This is used to extract the details for a specific class.private Filter
filter
This is the filter used to transform the template variables.private Format
format
This is the format used by this persistence support object.private InstanceFactory
instances
This is the factory that is used to create the scanners.private LabelExtractor
labels
This is used to extract the labels for a specific contact.private Matcher
matcher
This is the matcher used to acquire the transform objects.private ScannerFactory
scanners
This will perform the scanning of types are provide scanners.private Transformer
transform
This is the transformer used to transform objects to text.
-
Constructor Summary
Constructors Constructor Description Support()
Constructor for theSupport
object.Support(Filter filter)
Constructor for theSupport
object.Support(Filter filter, Matcher matcher)
Constructor for theSupport
object.Support(Filter filter, Matcher matcher, Format format)
Constructor for theSupport
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
getClassName(java.lang.Class type)
This returns the name of the class specified.Detail
getDetail(java.lang.Class type)
This is used to get aDetail
object describing a class and its annotations.Detail
getDetail(java.lang.Class type, DefaultType access)
ContactList
getFields(java.lang.Class type)
This is used to acquire a list ofContact
objects that represent the annotated fields in a type.ContactList
getFields(java.lang.Class type, DefaultType access)
This is used to acquire a list ofContact
objects that represent the annotated fields in a type.Format
getFormat()
This is used to acquire theFormat
for this.Instance
getInstance(java.lang.Class type)
This will create anInstance
that can be used to instantiate objects of the specified class.Instance
getInstance(Value value)
This will create anInstance
that can be used to instantiate objects of the specified class.Label
getLabel(Contact contact, java.lang.annotation.Annotation label)
Creates aLabel
using the provided contact and XML annotation.java.util.List<Label>
getLabels(Contact contact, java.lang.annotation.Annotation label)
Creates aList
using the provided contact and XML annotation.ContactList
getMethods(java.lang.Class type)
This is used to acquire a list ofContact
objects that represent the annotated methods in a type.ContactList
getMethods(java.lang.Class type, DefaultType access)
This is used to acquire a list ofContact
objects that represent the annotated methods in a type.java.lang.String
getName(java.lang.Class type)
This is used to acquire the name of the specified type using theRoot
annotation for the class.static java.lang.Class
getPrimitive(java.lang.Class type)
This method is used to convert a primitive type to its object counterpart.Scanner
getScanner(java.lang.Class type)
This creates aScanner
object that can be used to examine the fields within the XML class schema.Style
getStyle()
This is used to acquire theStyle
for the format.Transform
getTransform(java.lang.Class type)
This is used to match aTransform
using the type specified.static boolean
isAssignable(java.lang.Class expect, java.lang.Class actual)
This is used to determine if two objects are assignable to each other.boolean
isContainer(java.lang.Class type)
This is used to determine if the type in question is a container of some kind.static boolean
isFloat(java.lang.Class type)
This is used to determine if the type specified is a floating point type.boolean
isPrimitive(java.lang.Class type)
This is used to determine whether the scanned class represents a primitive type.java.lang.Object
read(java.lang.String value, java.lang.Class type)
This method is used to convert the string value given to an appropriate representation.java.lang.String
replace(java.lang.String text)
Replaces the text provided with some property.boolean
valid(java.lang.Class type)
This method is used to determine if the type specified can be transformed.java.lang.String
write(java.lang.Object value, java.lang.Class type)
This method is used to convert the provided value into an XML usable format.
-
-
-
Field Detail
-
instances
private final InstanceFactory instances
This is the factory that is used to create the scanners.
-
scanners
private final ScannerFactory scanners
This will perform the scanning of types are provide scanners.
-
defaults
private final DetailExtractor defaults
This is used to extract the defaults for a specific class.
-
details
private final DetailExtractor details
This is used to extract the details for a specific class.
-
labels
private final LabelExtractor labels
This is used to extract the labels for a specific contact.
-
transform
private final Transformer transform
This is the transformer used to transform objects to text.
-
matcher
private final Matcher matcher
This is the matcher used to acquire the transform objects.
-
filter
private final Filter filter
This is the filter used to transform the template variables.
-
format
private final Format format
This is the format used by this persistence support object.
-
-
Constructor Detail
-
Support
public Support()
Constructor for theSupport
object. This will create a support object with a default matcher and default platform filter. This ensures it contains enough information to process a template and transform basic primitive types.
-
Support
public Support(Filter filter)
Constructor for theSupport
object. This will create a support object with a default matcher and the filter provided. This ensures it contains enough information to process a template and transform basic primitive types.- Parameters:
filter
- this is the filter to use with this support
-
Support
public Support(Filter filter, Matcher matcher)
Constructor for theSupport
object. This will create a support object with the matcher and filter provided. This allows the user to override the transformations that are used to convert types to strings and back again.- Parameters:
filter
- this is the filter to use with this supportmatcher
- this is the matcher used for transformations
-
Support
public Support(Filter filter, Matcher matcher, Format format)
Constructor for theSupport
object. This will create a support object with the matcher and filter provided. This allows the user to override the transformations that are used to convert types to strings and back again.- Parameters:
filter
- this is the filter to use with this supportmatcher
- this is the matcher used for transformationsformat
- this contains all the formatting for the XML
-
-
Method Detail
-
replace
public java.lang.String replace(java.lang.String text)
Replaces the text provided with some property. This method acts much like a the get method of theMap
object, in that it uses the provided text as a key to some value. However it can also be used to evaluate expressions and output the result for inclusion in the generated XML.
-
getStyle
public Style getStyle()
This is used to acquire theStyle
for the format. This requires that the style is not null, if a null style is returned from the format this will break serialization.- Returns:
- this returns the style used for this format object
-
getFormat
public Format getFormat()
This is used to acquire theFormat
for this. The format should never be null and contains information that relates to the indentation that is to be used with XML elements.- Returns:
- this returns the format to be used for serialization
-
getInstance
public Instance getInstance(Value value)
This will create anInstance
that can be used to instantiate objects of the specified class. This leverages an internal constructor cache to ensure creation is quicker.- Parameters:
value
- this contains information on the object instance- Returns:
- this will return an object for instantiating objects
-
getInstance
public Instance getInstance(java.lang.Class type)
This will create anInstance
that can be used to instantiate objects of the specified class. This leverages an internal constructor cache to ensure creation is quicker.- Parameters:
type
- this is the type that is to be instantiated- Returns:
- this will return an object for instantiating objects
-
getTransform
public Transform getTransform(java.lang.Class type) throws java.lang.Exception
This is used to match aTransform
using the type specified. If no transform can be acquired then this returns a null value indicating that no transform could be found.- Parameters:
type
- this is the type to acquire the transform for- Returns:
- returns a transform for processing the type given
- Throws:
java.lang.Exception
-
getLabel
public Label getLabel(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aLabel
using the provided contact and XML annotation. The label produced contains all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.- Parameters:
contact
- this is contact that the label is produced forlabel
- represents the XML annotation for the contact- Returns:
- returns the label instantiated for the contact
- Throws:
java.lang.Exception
-
getLabels
public java.util.List<Label> getLabels(Contact contact, java.lang.annotation.Annotation label) throws java.lang.Exception
Creates aList
using the provided contact and XML annotation. The labels produced contain all information related to an object member. It knows the name of the XML entity, as well as whether it is required. Once created the converter can transform an XML node into Java object and vice versa.- Parameters:
contact
- this is contact that the label is produced forlabel
- represents the XML annotation for the contact- Returns:
- returns the list of labels associated with the contact
- Throws:
java.lang.Exception
-
getDetail
public Detail getDetail(java.lang.Class type)
This is used to get aDetail
object describing a class and its annotations. Any detail retrieved from this will be cached to increase the performance of future accesses.- Parameters:
type
- this is the type to acquire the detail for- Returns:
- an object describing the type and its annotations
-
getDetail
public Detail getDetail(java.lang.Class type, DefaultType access)
-
getFields
public ContactList getFields(java.lang.Class type) throws java.lang.Exception
This is used to acquire a list ofContact
objects that represent the annotated fields in a type. The entire class hierarchy is scanned for annotated fields. Caching of the contact list is done to increase performance.- Parameters:
type
- this is the type to scan for annotated fields- Returns:
- this returns a list of the annotated fields
- Throws:
java.lang.Exception
-
getFields
public ContactList getFields(java.lang.Class type, DefaultType access) throws java.lang.Exception
This is used to acquire a list ofContact
objects that represent the annotated fields in a type. The entire class hierarchy is scanned for annotated fields. Caching of the contact list is done to increase performance.- Parameters:
type
- this is the type to scan for annotated fieldsaccess
- this is the access type to use for the fields- Returns:
- this returns a list of the annotated fields
- Throws:
java.lang.Exception
-
getMethods
public ContactList getMethods(java.lang.Class type) throws java.lang.Exception
This is used to acquire a list ofContact
objects that represent the annotated methods in a type. The entire class hierarchy is scanned for annotated methods. Caching of the contact list is done to increase performance.- Parameters:
type
- this is the type to scan for annotated methods- Returns:
- this returns a list of the annotated methods
- Throws:
java.lang.Exception
-
getMethods
public ContactList getMethods(java.lang.Class type, DefaultType access) throws java.lang.Exception
This is used to acquire a list ofContact
objects that represent the annotated methods in a type. The entire class hierarchy is scanned for annotated methods. Caching of the contact list is done to increase performance.- Parameters:
type
- this is the type to scan for annotated methodsaccess
- this is the access type used for the methods- Returns:
- this returns a list of the annotated methods
- Throws:
java.lang.Exception
-
getScanner
public Scanner getScanner(java.lang.Class type) throws java.lang.Exception
This creates aScanner
object that can be used to examine the fields within the XML class schema. The scanner maintains information when a field from within the scanner is visited, this allows the serialization and deserialization process to determine if all required XML annotations are used.- Parameters:
type
- the schema class the scanner is created for- Returns:
- a scanner that can maintains information on the type
- Throws:
java.lang.Exception
-
read
public java.lang.Object read(java.lang.String value, java.lang.Class type) throws java.lang.Exception
This method is used to convert the string value given to an appropriate representation. This is used when an object is being deserialized from the XML document and the value for the string representation is required.- Parameters:
value
- this is the string representation of the valuetype
- this is the type to convert the string value to- Returns:
- this returns an appropriate instanced to be used
- Throws:
java.lang.Exception
-
write
public java.lang.String write(java.lang.Object value, java.lang.Class type) throws java.lang.Exception
This method is used to convert the provided value into an XML usable format. This is used in the serialization process when there is a need to convert a field value in to a string so that that value can be written as a valid XML entity.- Parameters:
value
- this is the value to be converted to a stringtype
- this is the type to convert to a string value- Returns:
- this is the string representation of the given value
- Throws:
java.lang.Exception
-
valid
public boolean valid(java.lang.Class type) throws java.lang.Exception
This method is used to determine if the type specified can be transformed. This will use theMatcher
to find a suitable transform, if one exists then this returns true, if not then this returns false. This is used during serialization to determine how to convert a field or method parameter.- Parameters:
type
- the type to determine whether its transformable- Returns:
- true if the type specified can be transformed by this
- Throws:
java.lang.Exception
-
getName
public java.lang.String getName(java.lang.Class type) throws java.lang.Exception
This is used to acquire the name of the specified type using theRoot
annotation for the class. This will use either the name explicitly provided by the annotation or it will use the name of the class that the annotation was placed on if there is no explicit name for the root.- Parameters:
type
- this is the type to acquire the root name for- Returns:
- this returns the name of the type from the root
- Throws:
java.lang.Exception
- if the class contains an illegal schema
-
getClassName
private java.lang.String getClassName(java.lang.Class type) throws java.lang.Exception
This returns the name of the class specified. If there is a root annotation on the type, then this is ignored in favour of the actual class name. This is typically used when the type is a primitive or if there is noRoot
annotation present.- Parameters:
type
- this is the type to acquire the root name for- Returns:
- this returns the name of the type from the root
- Throws:
java.lang.Exception
-
isPrimitive
public boolean isPrimitive(java.lang.Class type) throws java.lang.Exception
This is used to determine whether the scanned class represents a primitive type. A primitive type is a type that contains no XML annotations and so cannot be serialized with an XML form. Instead primitives a serialized using transformations.- Parameters:
type
- this is the type to determine if it is primitive- Returns:
- this returns true if no XML annotations were found
- Throws:
java.lang.Exception
-
isContainer
public boolean isContainer(java.lang.Class type)
This is used to determine if the type in question is a container of some kind. A container is a Java collection object of an array of objects. Containers are treated as special objects in the case of default serialization as we do not want to apply default annotations when we can use them to better effect.- Parameters:
type
- this is the type to determine if it is a container- Returns:
- this returns true if the type represents a container
-
isFloat
public static boolean isFloat(java.lang.Class type) throws java.lang.Exception
This is used to determine if the type specified is a floating point type. Types that are floating point are the double and float primitives as well as the java types for this primitives.- Parameters:
type
- this is the type to determine if it is a float- Returns:
- this returns true if the type is a floating point
- Throws:
java.lang.Exception
-
isAssignable
public static boolean isAssignable(java.lang.Class expect, java.lang.Class actual)
This is used to determine if two objects are assignable to each other. To be sure that its is possible to inject primitive values in to a constructor the primitives are wrapped in their counterpart objects, this allows proper assignment checking.- Parameters:
expect
- this is the expected value of the objectactual
- this is the type in the declaration- Returns:
- this returns true if the types can be assigned
-
getPrimitive
public static java.lang.Class getPrimitive(java.lang.Class type)
This method is used to convert a primitive type to its object counterpart. Conversion to an object counterpart is useful when there is a need to mask the difference between types.- Parameters:
type
- this is the primitive type to convert to an object- Returns:
- this returns the primitive type as its object type
-
-