net.sf.cglib
Class Delegator

java.lang.Object
  |
  +--net.sf.cglib.Delegator

public class Delegator
extends java.lang.Object

Delegator provides a number of static methods that allow multiple objects to be combined into a single larger object. The methods in the generated object simply call the original methods in the underlying "delegate" objects.

Version:
$Id: Delegator.java,v 1.22 2003/07/15 16:38:46 herbyderby Exp $
Author:
Chris Nokleberg

Inner Class Summary
static interface Delegator.Factory
           
 
Method Summary
static java.lang.Object create(java.lang.Class[] interfaces, java.lang.Object[] delegates, java.lang.ClassLoader loader)
          Returns an object that implements all of the specified interfaces.
static java.lang.Object create(java.lang.Class type, java.lang.Class[] interfaces, java.lang.Object[] delegates, java.lang.ClassLoader loader)
          Returns an object that implements all of the specified interfaces.
static java.lang.Object create(java.lang.Class type, java.lang.Class[] interfaces, java.lang.Object[] delegates, int[] routing, java.lang.ClassLoader loader)
          Returns an object that implements all of the specified interfaces.
static java.lang.Object create(java.lang.Object[] delegates, java.lang.ClassLoader loader)
          Returns an object that implements all of the interfaces implemented by the specified objects.
static java.lang.Object createBean(java.lang.Class type, java.lang.Object[] beans, java.lang.ClassLoader loader)
          Combines an array of JavaBeans into a single "super" bean.
static java.lang.Object createBean(java.lang.Object[] beans, java.lang.ClassLoader loader)
          Combines an array of JavaBeans into a single "super" bean.
static java.util.Map getInterfaceMap(java.lang.Object[] delegates)
          Returns a Map that describes how interfaces would be delegated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static java.lang.Object create(java.lang.Class[] interfaces,
                                      java.lang.Object[] delegates,
                                      java.lang.ClassLoader loader)
Returns an object that implements all of the specified interfaces. For each interface, all methods are delegated to the respective object in the delegates argument array.
Parameters:
interfaces - the array of interfaces to implement
delegates - The array of delegates. Must be the same length as the interface array, and each delegates must implements the corresponding interface.
loader - The ClassLoader to use. If null uses the one that loaded this class.
Returns:
the dynamically created object

create

public static java.lang.Object create(java.lang.Class type,
                                      java.lang.Class[] interfaces,
                                      java.lang.Object[] delegates,
                                      java.lang.ClassLoader loader)
Returns an object that implements all of the specified interfaces. For each interface, all methods are delegated to the respective object in the delegates argument array.
Parameters:
type - the Class to extend, uses Object if null
interfaces - the array of interfaces to implement
delegates - The array of delegates. Must be the same length as the interface array, and each delegates must implements the corresponding interface.
loader - The ClassLoader to use. If null uses the one that loaded this class.
Returns:
the dynamically created object

create

public static java.lang.Object create(java.lang.Class type,
                                      java.lang.Class[] interfaces,
                                      java.lang.Object[] delegates,
                                      int[] routing,
                                      java.lang.ClassLoader loader)
Returns an object that implements all of the specified interfaces. For each interface, all methods are delegated to the respective object in the delegates argument array.
Parameters:
type - the Class to extend, uses Object if null
interfaces - the array of interfaces to implement
delegates - The array of delegates. If the routing parameter is null, this must be the same length as the interface array. Each delegate must implement the interfaces delegated to it.
routing - An optional routing table. Must be null, or the same length as the interfaces array. If non null, the values represent which delegate the corresponding interface should be mapped to. If null, a 1:1 correspondence is assumed.
loader - The ClassLoader to use. If null uses the one that loaded this class.
Returns:
the dynamically created object

create

public static java.lang.Object create(java.lang.Object[] delegates,
                                      java.lang.ClassLoader loader)
Returns an object that implements all of the interfaces implemented by the specified objects. For each interface, all methods are delegated to the first object in the argument array which implements the interface.

Note: interfaces which have no methods (marker interfaces) are not implemented by the returned object.

Parameters:
delegates - the array of delegates
loader - The ClassLoader to use. If null uses the one that loaded this class.
Returns:
the dynamically created object
See Also:
getInterfaceMap(Object[])

getInterfaceMap

public static java.util.Map getInterfaceMap(java.lang.Object[] delegates)
Returns a Map that describes how interfaces would be delegated. The keys are interfaces (Class objects) that would be implemented by the object returned by the create methods. For each interface, the Map value is the objects from the argument array that would be used as a delegate.
Parameters:
delegates - the array of delegates
Returns:
the Map of interfaces -> delegates
See Also:
#makeDelegator(Object[])

createBean

public static java.lang.Object createBean(java.lang.Object[] beans,
                                          java.lang.ClassLoader loader)
Combines an array of JavaBeans into a single "super" bean. Calls to the super bean will delegate to the underlying beans. In the case of a property name conflicts, the first bean is used.
Parameters:
beans - the list of beans to delegate to
loader - The ClassLoader to use. If null uses the one that loaded this class.
Returns:
the dynamically created bean

createBean

public static java.lang.Object createBean(java.lang.Class type,
                                          java.lang.Object[] beans,
                                          java.lang.ClassLoader loader)
Combines an array of JavaBeans into a single "super" bean. Calls to the super bean will delegate to the underlying beans.
Parameters:
type - the Class to extend
beans - the list of beans to delegate to if true, "set" methods will set all applicable beans, and "get" will return the value from the last bean in the list.
loader - The ClassLoader to use. If null uses the one that loaded this class.


Copyright © 2002-2003 cglib. All Rights Reserved.