Class ConverterScanner

java.lang.Object
org.simpleframework.xml.convert.ConverterScanner

class ConverterScanner extends Object
The ConverterScanner is used to create a converter given a method or field representation. Creation of the converter is done using the Convert annotation, which may be used to annotate a field, method or class. This describes the implementation to use for object serialization. To account for polymorphism the type scanned for annotations can be overridden from type provided in the Type object. This ensures that if a collection of objects are serialized the correct implementation will be used for each type or subtype.
  • Field Details

    • factory

      private final ConverterFactory factory
      This is used to instantiate converters given the type.
    • builder

      private final ScannerBuilder builder
      This is used to build a scanner to scan for annotations.
  • Constructor Details

    • ConverterScanner

      public ConverterScanner()
      Constructor for the ConverterScanner object. This uses an internal factory to instantiate and cache all of the converters created. This will ensure that there is reduced overhead for a serialization process using converters.
  • Method Details

    • getConverter

      public Converter getConverter(Type type, Value value) throws Exception
      This method will lookup and instantiate a converter found from scanning the field or method type provided. If the type has been overridden then the Value object will provide the type to scan. If no annotation is found on the class, field or method then this will return null.
      Parameters:
      type - this is the type to search for the annotation
      value - this contains the type if it was overridden
      Returns:
      a converter scanned from the provided field or method
      Throws:
      Exception
    • getConverter

      public Converter getConverter(Type type, Object value) throws Exception
      This method will lookup and instantiate a converter found from scanning the field or method type provided. If the type has been overridden then the object instance will provide the type to scan. If no annotation is found on the class, field or method then this will return null.
      Parameters:
      type - this is the type to search for the annotation
      value - this contains the type if it was overridden
      Returns:
      a converter scanned from the provided field or method
      Throws:
      Exception
    • getConvert

      private Convert getConvert(Type type, Class real) throws Exception
      This method is used to scan the provided Type for an annotation. If the Type represents a field or method then the annotation can be taken directly from that field or method. If however the type represents a class then the class itself must contain the annotation.
      Parameters:
      type - the field or method containing the annotation
      real - the type that represents the field or method
      Returns:
      this returns the annotation on the field or method
      Throws:
      Exception
    • getConvert

      private Convert getConvert(Type type) throws Exception
      This method is used to scan the provided Type for an annotation. If the Type represents a field or method then the annotation can be taken directly from that field or method. If however the type represents a class then the class itself must contain the annotation.
      Parameters:
      type - the field or method containing the annotation
      Returns:
      this returns the annotation on the field or method
      Throws:
      Exception
    • getConvert

      private Convert getConvert(Class real) throws Exception
      This method is used to scan the provided Type for an annotation. If the Type represents a field or method then the annotation can be taken directly from that field or method. If however the type represents a class then the class itself must contain the annotation.
      Parameters:
      real - the type that represents the field or method
      Returns:
      this returns the annotation on the field or method
      Throws:
      Exception
    • getAnnotation

      private <T extends Annotation> T getAnnotation(Class<?> type, Class<T> label)
      This is used to acquire the Convert annotation from the class provided. If the type does not contain the annotation then this scans all supertypes until either an annotation is found or there are no further supertypes.
      Parameters:
      type - this is the type to scan for annotations
      label - this is the annotation type that is to be found
      Returns:
      this returns the annotation if found otherwise null
    • getType

      private Class getType(Type type, Value value)
      This is used to acquire the class that should be scanned. The type is found either on the method or field, or should there be a subtype then the class is taken from the provided value.
      Parameters:
      type - this is the type representing the field or method
      value - this contains the type if it was overridden
      Returns:
      this returns the class that has been scanned
    • getType

      private Class getType(Type type, Object value)
      This is used to acquire the class that should be scanned. The type is found either on the method or field, or should there be a subtype then the class is taken from the provided value.
      Parameters:
      type - this is the type representing the field or method
      value - this contains the type if it was overridden
      Returns:
      this returns the class that has been scanned