Class ObjectScanner

java.lang.Object
org.simpleframework.xml.core.ObjectScanner
All Implemented Interfaces:
Policy, Scanner

class ObjectScanner extends Object implements Scanner
The ObjectScanner performs the reflective inspection of a class and builds a map of attributes and elements for each annotated field. This acts as a cachable container for reflection actions performed on a specific type. When scanning the provided class this inserts the scanned field as a Label in to a map so that it can be retrieved by name. Annotations classified as attributes have the Attribute annotation, all other annotated fields are stored as elements.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This is used to store all XML attributes and XML elements.
    private Detail
    This contains the details for the class that is being scanned.
    private ClassScanner
    This method acts as a pointer to the types commit process.
    private Structure
    This defines the structure build from the class annotations.
    private Support
    This object contains various support functions for the class.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ObjectScanner(Detail detail, Support support)
    Constructor for the ObjectScanner object.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    commit(Detail detail)
    Once the scanner has completed extracting the annotations and validating the resulting structure this is called to complete the process.
    private void
    field(Detail detail)
    This is used to acquire the contacts for the annotated fields within the specified class.
    getCaller(Context context)
    This method is used to return the Caller for this class.
    This method is used to retrieve the schema class commit method during the deserialization process.
    This method is used to retrieve the schema class completion method.
    This is used to acquire the Decorator for this.
    This is used to acquire the instantiator for the type.
    This returns the name of the class processed by this scanner.
    This is used to acquire the Order annotation for the class schema.
    This returns a map of all parameters that exist.
    This method is used to retrieve the schema class persistence method.
    This method is used to retrieve the schema class replacement method.
    This method is used to retrieve the schema class replacement method.
    This is the Version for the scanned class.
    This is used to create a Section given the context used for serialization.
    This is used to acquire the default signature for the class.
    This returns the signatures for the type.
    This returns the Label that represents the text annotation for the scanned class.
    This is used to acquire the type that this scanner scans for annotations to be used in a schema.
    This method is used to retrieve the schema class validation method during the deserialization process.
    This returns the Label that represents the version annotation for the scanned class.
    boolean
    This is used to determine whether the scanned class represents a primitive type.
    boolean
    This is used to determine whether the scanned class represents a primitive type.
    boolean
    This method is used to determine whether strict mappings are required.
    private void
    method(Detail detail)
    This is used to acquire the contacts for the annotated fields within the specified class.
    private void
    order(Detail detail)
    This is used to acquire the optional order annotation to provide order to the elements and attributes for the generated XML.
    private void
    scan(Detail detail)
    This is used to scan the specified object to extract the fields and methods that are to be used in the serialization process.
    private void
    validate(Detail detail)
    This is used to validate the configuration of the scanned class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • builder

      private StructureBuilder builder
      This is used to store all XML attributes and XML elements.
    • scanner

      private ClassScanner scanner
      This method acts as a pointer to the types commit process.
    • structure

      private Structure structure
      This defines the structure build from the class annotations.
    • support

      private Support support
      This object contains various support functions for the class.
    • detail

      private Detail detail
      This contains the details for the class that is being scanned.
  • Constructor Details

    • ObjectScanner

      public ObjectScanner(Detail detail, Support support) throws Exception
      Constructor for the ObjectScanner object. This is used to scan the provided class for annotations that are used to build a schema for an XML file to follow.
      Parameters:
      detail - this contains the details for the class scanned
      support - this contains various support functions
      Throws:
      Exception
  • Method Details

    • getSignature

      public Signature getSignature()
      This is used to acquire the default signature for the class. The default signature is the signature for the no argument constructor for the type. If there is no default constructor for the type then this will return null.
      Specified by:
      getSignature in interface Scanner
      Returns:
      this returns the default signature if it exists
    • getSignatures

      public List<Signature> getSignatures()
      This returns the signatures for the type. All constructors are represented as a signature and returned. More signatures than constructors will be returned if a constructor is annotated with a union annotation.
      Specified by:
      getSignatures in interface Scanner
      Returns:
      this returns the list of signatures for the type
    • getParameters

      public ParameterMap getParameters()
      This returns a map of all parameters that exist. This is used to validate all the parameters against the field and method annotations that exist within the class.
      Specified by:
      getParameters in interface Scanner
      Returns:
      this returns a map of all parameters within the type
    • getInstantiator

      public Instantiator getInstantiator()
      This is used to acquire the instantiator for the type. This is used to create object instances based on the constructors that have been annotated. If no constructors have been annotated then this can be used to create default no argument instances.
      Specified by:
      getInstantiator in interface Scanner
      Returns:
      this instantiator responsible for creating instances
    • getType

      public Class getType()
      This is used to acquire the type that this scanner scans for annotations to be used in a schema. Exposing the class that this represents allows the schema it creates to be known.
      Specified by:
      getType in interface Scanner
      Returns:
      this is the type that this creator will represent
    • getDecorator

      public Decorator getDecorator()
      This is used to acquire the Decorator for this. A decorator is an object that adds various details to the node without changing the overall structure of the node. For example comments and namespaces can be added to the node with a decorator as they do not affect the deserialization.
      Specified by:
      getDecorator in interface Scanner
      Returns:
      this returns the decorator associated with this
    • getCaller

      public Caller getCaller(Context context)
      This method is used to return the Caller for this class. The caller is a means to deliver invocations to the object for the persister callback methods. It aggregates all of the persister callback methods in to a single object.
      Specified by:
      getCaller in interface Scanner
      Returns:
      this returns a caller used for delivering callbacks
    • getSection

      public Section getSection()
      This is used to create a Section given the context used for serialization. A section is an XML structure that contains all the elements and attributes defined for the class. Each section is a tree like structure defining exactly where each attribute an element is located within the source XML.
      Specified by:
      getSection in interface Scanner
      Returns:
      this will return a section for serialization
    • getRevision

      public Version getRevision()
      This is the Version for the scanned class. It allows the deserialization process to be configured such that if the version is different from the schema class none of the fields and methods are required and unmatched elements and attributes will be ignored.
      Specified by:
      getRevision in interface Scanner
      Returns:
      this returns the version of the class that is scanned
    • getOrder

      public Order getOrder()
      This is used to acquire the Order annotation for the class schema. The order annotation defines the order that the elements and attributes should appear within the document. Providing order in this manner makes the resulting XML more predictable. If no order is provided, appearance is random.
      Specified by:
      getOrder in interface Scanner
      Returns:
      this returns the order, if any, defined for the class
    • getVersion

      public Label getVersion()
      This returns the Label that represents the version annotation for the scanned class. Only a single version can exist within the class if more than one exists an exception is thrown. This will read only floating point types such as double.
      Specified by:
      getVersion in interface Scanner
      Returns:
      this returns the label used for reading the version
    • getText

      public Label getText()
      This returns the Label that represents the text annotation for the scanned class. Only a single text annotation can be used per class, so this returns only a single label rather than a LabelMap object. Also if this is not null then the elements label map must be empty.
      Specified by:
      getText in interface Scanner
      Returns:
      this returns the text label for the scanned class
    • getName

      public String getName()
      This returns the name of the class processed by this scanner. The name is either the name as specified in the last found Root annotation, or if a name was not specified within the discovered root then the Java Bean class name of the last class annotated with a root annotation.
      Specified by:
      getName in interface Scanner
      Returns:
      this returns the name of the object being scanned
    • getCommit

      public Function getCommit()
      This method is used to retrieve the schema class commit method during the deserialization process. The commit method must be marked with the Commit annotation so that when the object is deserialized the persister has a chance to invoke the method so that the object can build further data structures.
      Specified by:
      getCommit in interface Scanner
      Returns:
      this returns the commit method for the schema class
    • getValidate

      public Function getValidate()
      This method is used to retrieve the schema class validation method during the deserialization process. The validation method must be marked with the Validate annotation so that when the object is deserialized the persister has a chance to invoke that method so that object can validate its field values.
      Specified by:
      getValidate in interface Scanner
      Returns:
      this returns the validate method for the schema class
    • getPersist

      public Function getPersist()
      This method is used to retrieve the schema class persistence method. This is invoked during the serialization process to get the object a chance to perform an nessecary preparation before the serialization of the object proceeds. The persist method must be marked with the Persist annotation.
      Specified by:
      getPersist in interface Scanner
      Returns:
      this returns the persist method for the schema class
    • getComplete

      public Function getComplete()
      This method is used to retrieve the schema class completion method. This is invoked after the serialization process has completed and gives the object a chance to restore its state if the persist method required some alteration or locking. This is marked with the Complete annotation.
      Specified by:
      getComplete in interface Scanner
      Returns:
      returns the complete method for the schema class
    • getReplace

      public Function getReplace()
      This method is used to retrieve the schema class replacement method. The replacement method is used to substitute an object that has been deserialized with another object. This allows a seamless delegation mechanism to be implemented. This is marked with the Replace annotation.
      Specified by:
      getReplace in interface Scanner
      Returns:
      returns the replace method for the schema class
    • getResolve

      public Function getResolve()
      This method is used to retrieve the schema class replacement method. The replacement method is used to substitute an object that has been deserialized with another object. This allows a seamless delegation mechanism to be implemented. This is marked with the Replace annotation.
      Specified by:
      getResolve in interface Scanner
      Returns:
      returns the replace method for the schema class
    • isPrimitive

      public boolean isPrimitive()
      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.
      Specified by:
      isPrimitive in interface Scanner
      Returns:
      this returns true if no XML annotations were found
    • isEmpty

      public boolean isEmpty()
      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.
      Specified by:
      isEmpty in interface Scanner
      Returns:
      this returns true if no XML annotations were found
    • isStrict

      public boolean isStrict()
      This method is used to determine whether strict mappings are required. Strict mapping means that all labels in the class schema must match the XML elements and attributes in the source XML document. When strict mapping is disabled, then XML elements and attributes that do not exist in the schema class will be ignored without breaking the parser.
      Specified by:
      isStrict in interface Policy
      Specified by:
      isStrict in interface Scanner
      Returns:
      true if strict parsing is enabled, false otherwise
    • scan

      private void scan(Detail detail) throws Exception
      This is used to scan the specified object to extract the fields and methods that are to be used in the serialization process. This will acquire all fields and getter setter pairs that have been annotated with the XML annotations.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception
    • order

      private void order(Detail detail) throws Exception
      This is used to acquire the optional order annotation to provide order to the elements and attributes for the generated XML. This acts as an override to the order provided by the declaration of the types within the object.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception
    • commit

      private void commit(Detail detail) throws Exception
      Once the scanner has completed extracting the annotations and validating the resulting structure this is called to complete the process. This will build a Structure object and clean up any data structures no longer required by the scanner.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception
    • validate

      private void validate(Detail detail) throws Exception
      This is used to validate the configuration of the scanned class. If a Text annotation has been used with elements then validation will fail and an exception will be thrown.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception
    • field

      private void field(Detail detail) throws Exception
      This is used to acquire the contacts for the annotated fields within the specified class. The field contacts are added to either the attributes or elements map depending on annotation.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception
    • method

      private void method(Detail detail) throws Exception
      This is used to acquire the contacts for the annotated fields within the specified class. The field contacts are added to either the attributes or elements map depending on annotation.
      Parameters:
      detail - this contains the details for the class scanned
      Throws:
      Exception