Class ConverterScanner


  • class ConverterScanner
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private ScannerBuilder builder
      This is used to build a scanner to scan for annotations.
      private ConverterFactory factory
      This is used to instantiate converters given the type.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConverterScanner()
      Constructor for the ConverterScanner object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private <T extends java.lang.annotation.Annotation>
      T
      getAnnotation​(java.lang.Class<?> type, java.lang.Class<T> label)
      This is used to acquire the Convert annotation from the class provided.
      private Convert getConvert​(java.lang.Class real)
      This method is used to scan the provided Type for an annotation.
      private Convert getConvert​(Type type)
      This method is used to scan the provided Type for an annotation.
      private Convert getConvert​(Type type, java.lang.Class real)
      This method is used to scan the provided Type for an annotation.
      Converter getConverter​(Type type, java.lang.Object value)
      This method will lookup and instantiate a converter found from scanning the field or method type provided.
      Converter getConverter​(Type type, Value value)
      This method will lookup and instantiate a converter found from scanning the field or method type provided.
      private java.lang.Class getType​(Type type, java.lang.Object value)
      This is used to acquire the class that should be scanned.
      private java.lang.Class getType​(Type type, Value value)
      This is used to acquire the class that should be scanned.
      • Methods inherited from class java.lang.Object

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

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

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

      • getConverter

        public Converter getConverter​(Type type,
                                      Value value)
                               throws java.lang.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:
        java.lang.Exception
      • getConverter

        public Converter getConverter​(Type type,
                                      java.lang.Object value)
                               throws java.lang.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:
        java.lang.Exception
      • getConvert

        private Convert getConvert​(Type type,
                                   java.lang.Class real)
                            throws java.lang.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:
        java.lang.Exception
      • getConvert

        private Convert getConvert​(Type type)
                            throws java.lang.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:
        java.lang.Exception
      • getConvert

        private Convert getConvert​(java.lang.Class real)
                            throws java.lang.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:
        java.lang.Exception
      • getAnnotation

        private <T extends java.lang.annotation.Annotation> T getAnnotation​(java.lang.Class<?> type,
                                                                            java.lang.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 java.lang.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 java.lang.Class getType​(Type type,
                                        java.lang.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