biz.hammurapi.convert
Class DuckConverterFactory

java.lang.Object
  extended by biz.hammurapi.convert.DuckConverterFactory

public class DuckConverterFactory
extends java.lang.Object

Creates converters which use "duck" typing.

Author:
Pavel

Constructor Summary
DuckConverterFactory()
           
 
Method Summary
static java.lang.Integer classAffinity(java.lang.Class subClass, java.lang.Class superClass)
          Calculates how close is subclass to superclass in class hierarchy.
static boolean duckMap(java.lang.Class theInterface, java.lang.Class theClass, java.util.Map methodMap)
          Duck maps source (interface methods) to compatible target (class) methods.
static boolean duckMap(java.lang.reflect.Method[] interfaceMethods, java.lang.reflect.Method[] classMethods, java.util.Map methodMap)
          Duck maps source (interface methods) to compatible target (class) methods.
static java.lang.ClassLoader getChildClassLoader(java.lang.ClassLoader cl1, java.lang.ClassLoader cl2)
           
static ConverterClosure getConverter(java.lang.Class sourceClass, java.lang.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(java.lang.Class sourceClass,
                                            java.lang.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(java.lang.Class theInterface,
                              java.lang.Class theClass,
                              java.util.Map 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(java.lang.reflect.Method[] interfaceMethods,
                              java.lang.reflect.Method[] classMethods,
                              java.util.Map 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 java.lang.Integer classAffinity(java.lang.Class subClass,
                                              java.lang.Class superClass)
Calculates how close is subclass to superclass in class hierarchy.

Parameters:
subClass -
superClass -
Returns:
affinity, or Integer.MAX_VALUE if classes don't belong to the same class hierarchy.

getChildClassLoader

public static java.lang.ClassLoader getChildClassLoader(java.lang.ClassLoader cl1,
                                                        java.lang.ClassLoader cl2)
Parameters:
cl1 -
cl2 -
Returns:
Child classloader or null if classloaders are not related


Copyright © 2003 Hammurapi Group. All Rights Reserved.