com.hammurapi.convert

## Class DuckConverterFactory

- java.lang.Object
- - com.hammurapi.convert.DuckConverterFactory

-     public class DuckConverterFactory
      extends Object

  Creates converters which use "duck" typing.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DuckConverterFactory()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Integer` | `classAffinity(Class subClass, Class superClass)` Calculates how close is subclass to superclass in class hierarchy.
    `static boolean` | `duckMap(Class theInterface, Class theClass, Map<Method,Method> methodMap)` Duck maps source (interface methods) to compatible target (class) methods.
    `static boolean` | `duckMap(Method[] interfaceMethods, Method[] classMethods, Map<Method,Method> methodMap)` Duck maps source (interface methods) to compatible target (class) methods.
    `static ClassLoader` | `getChildClassLoader(ClassLoader cl1, ClassLoader cl2)`
    `static Class[]` | `getClassInterfaces(Class sourceClass)`
    `static ConverterClosure` | `getConverter(Class sourceClass, Class targetInterface, boolean lenient)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DuckConverterFactory

          public DuckConverterFactory()

  - ### Method Detail

    - #### getConverter

          public static ConverterClosure getConverter(Class sourceClass,
                                      Class targetInterface,
                                      boolean lenient)

      Parameters:
        `sourceClass` -
        `targetInterface` -
        `lenient` - If true converter is created even not all interface methods could be mapped to class methods.
      Returns:
        Converter which can "duck-type" instance of source class to target interface or null if conversion is not possible. Methods are mapped as follows: return types shall be compatible, arguments shall be compatible, exception declarations are ignored.

    - #### duckMap

          public static boolean duckMap(Class theInterface,
                        Class theClass,
                        Map<Method,Method> methodMap)

      Duck maps source (interface methods) to compatible target (class) methods.
      Parameters:
        `interfaceMethods` - Interface methods.
        `classMethods` - Class methods
        `methodMap` - Method map (interface to class methods).
      Returns:
        true if all source methods have been mapped.

    - #### duckMap

          public static boolean duckMap(Method[] interfaceMethods,
                        Method[] classMethods,
                        Map<Method,Method> methodMap)

      Duck maps source (interface methods) to compatible target (class) methods. Mapped interface entries are set to null.
      Parameters:
        `interfaceMethods` - Interface methods.
        `classMethods` - Class methods
        `methodMap` - Method map (interface to class methods).
      Returns:
        true if all source methods have been mapped.

    - #### classAffinity

          public static Integer classAffinity(Class subClass,
                              Class superClass)

      Calculates how close is subclass to superclass in class hierarchy.
      Parameters:
        `subClass` -
        `superClass` -
      Returns:
        affinity, or null if classes don't belong to the same class hierarchy.

    - #### getChildClassLoader

          public static ClassLoader getChildClassLoader(ClassLoader cl1,
                                        ClassLoader cl2)

      Parameters:
        `cl1` -
        `cl2` -
      Returns:
        Child classloader or null if classloaders are not related

    - #### getClassInterfaces

          public static Class[] getClassInterfaces(Class sourceClass)

      Parameters:
        `sourceClass` -
      Returns:
        all interfaces implemented by this class