Class Support

java.lang.Object
org.simpleframework.xml.core.Support
All Implemented Interfaces:
Filter

class Support extends Object implements Filter
The Support object is used to provide support to the serialization engine for processing and transforming strings. This contains a Transformer 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:
  • Field Details

    • 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 Details

    • Support

      public Support()
      Constructor for the Support 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 the Support 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 the Support 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 support
      matcher - this is the matcher used for transformations
    • Support

      public Support(Filter filter, Matcher matcher, Format format)
      Constructor for the Support 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 support
      matcher - this is the matcher used for transformations
      format - this contains all the formatting for the XML
  • Method Details

    • replace

      public String replace(String text)
      Replaces the text provided with some property. This method acts much like a the get method of the Map 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.
      Specified by:
      replace in interface Filter
      Parameters:
      text - this is the text value that is to be replaced
      Returns:
      returns a replacement for the provided text value
    • getStyle

      public Style getStyle()
      This is used to acquire the Style 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 the Format 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 an Instance 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(Class type)
      This will create an Instance 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(Class type) throws Exception
      This is used to match a Transform 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:
      Exception
    • getLabel

      public Label getLabel(Contact contact, Annotation label) throws Exception
      Creates a Label 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 for
      label - represents the XML annotation for the contact
      Returns:
      returns the label instantiated for the contact
      Throws:
      Exception
    • getLabels

      public List<Label> getLabels(Contact contact, Annotation label) throws Exception
      Creates a List 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 for
      label - represents the XML annotation for the contact
      Returns:
      returns the list of labels associated with the contact
      Throws:
      Exception
    • getDetail

      public Detail getDetail(Class type)
      This is used to get a Detail 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(Class type, DefaultType access)
    • getFields

      public ContactList getFields(Class type) throws Exception
      This is used to acquire a list of Contact 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:
      Exception
    • getFields

      public ContactList getFields(Class type, DefaultType access) throws Exception
      This is used to acquire a list of Contact 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
      access - this is the access type to use for the fields
      Returns:
      this returns a list of the annotated fields
      Throws:
      Exception
    • getMethods

      public ContactList getMethods(Class type) throws Exception
      This is used to acquire a list of Contact 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:
      Exception
    • getMethods

      public ContactList getMethods(Class type, DefaultType access) throws Exception
      This is used to acquire a list of Contact 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
      access - this is the access type used for the methods
      Returns:
      this returns a list of the annotated methods
      Throws:
      Exception
    • getScanner

      public Scanner getScanner(Class type) throws Exception
      This creates a Scanner 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:
      Exception
    • read

      public Object read(String value, Class type) throws 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 value
      type - this is the type to convert the string value to
      Returns:
      this returns an appropriate instanced to be used
      Throws:
      Exception
    • write

      public String write(Object value, Class type) throws 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 string
      type - this is the type to convert to a string value
      Returns:
      this is the string representation of the given value
      Throws:
      Exception
    • valid

      public boolean valid(Class type) throws Exception
      This method is used to determine if the type specified can be transformed. This will use the Matcher 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:
      Exception
    • getName

      public String getName(Class type) throws Exception
      This is used to acquire the name of the specified type using the Root 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:
      Exception - if the class contains an illegal schema
    • getClassName

      private String getClassName(Class type) throws 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 no Root 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:
      Exception
    • isPrimitive

      public boolean isPrimitive(Class type) throws 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:
      Exception
    • isContainer

      public boolean isContainer(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(Class type) throws 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:
      Exception
    • isAssignable

      public static boolean isAssignable(Class expect, 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 object
      actual - this is the type in the declaration
      Returns:
      this returns true if the types can be assigned
    • getPrimitive

      public static Class getPrimitive(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