com.go.trove.util
Class MergedClass

java.lang.Object
  |
  +--com.go.trove.util.MergedClass

public class MergedClass
extends java.lang.Object

Merges several classes together, producing a new class that has all of the methods of the combined classes. All methods in the combined class delegate to instances of the source classes. If multiple classes implement the same method, the first one provided is used. The merged class implements all of the interfaces provided by the source classes or interfaces.

This class performs a function almost the same as the Proxy class introduced in JDK1.3. It differs in that it supports classes as well as interfaces as input, and it binds to wrapped objects without using runtime reflection. It is less flexible than Proxy in that there isn't way to customize the method delegation, and so it isn't suitable for creating dynamically generated interface implementations.

Version:
30 , 01/02/20
Author:
Brian S O'Neill

Inner Class Summary
static interface MergedClass.InstanceFactory
          InstanceFactory allows merged class instances to be requested only when first needed.
 
Method Summary
static java.lang.reflect.Constructor getConstructor(ClassInjector injector, java.lang.Class[] classes)
          Returns the constructor for a class that merges all of the given source classes.
static java.lang.reflect.Constructor getConstructor(ClassInjector injector, java.lang.Class[] classes, java.lang.String[] prefixes)
          Returns the constructor for a class that merges all of the given source classes.
static java.lang.reflect.Constructor getConstructor2(ClassInjector injector, java.lang.Class[] classes)
          Returns the constructor for a class that merges all of the given source classes.
static java.lang.reflect.Constructor getConstructor2(ClassInjector injector, java.lang.Class[] classes, java.lang.String[] prefixes)
          Returns the constructor for a class that merges all of the given source classes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConstructor

public static java.lang.reflect.Constructor getConstructor(ClassInjector injector,
                                                           java.lang.Class[] classes)
                                                    throws java.lang.IllegalArgumentException
Returns the constructor for a class that merges all of the given source classes. The constructor's parameter types match the source classes. An IllegalArgumentException is thrown if any of the given conditions are not satisfied: Note: Because a constructor is limited to 254 parameters, if more than 254 classes are to be merged together, call getConstructor2(com.go.trove.util.ClassInjector, java.lang.Class[]).
Parameters:
injector - ClassInjector that will receive class definition
classes - Source classes used to derive merged class

getConstructor

public static java.lang.reflect.Constructor getConstructor(ClassInjector injector,
                                                           java.lang.Class[] classes,
                                                           java.lang.String[] prefixes)
                                                    throws java.lang.IllegalArgumentException
Returns the constructor for a class that merges all of the given source classes. The constructor's parameter types match the source classes. An IllegalArgumentException is thrown if any of the given conditions are not satisfied: To help resolve ambiguities, a method prefix can be specified for each passed in class. For each prefixed method, the non-prefixed method is also generated, unless that method conflicts with the return type of another method. If any passed in classes are or have interfaces, then those interfaces will be implemented only if there are no conflicts.

The array of prefixes may be null, have null elements or be shorter than the array of classes. A prefix of "" is treated as null.

Note: Because a constructor is limited to 254 parameters, if more than 254 classes are to be merged together, call getConstructor2(com.go.trove.util.ClassInjector, java.lang.Class[]).

Parameters:
injector - ClassInjector that will receive class definition
classes - Source classes used to derive merged class
prefixes - Optional prefixes to apply to methods of each generated class to eliminate duplicate method names

getConstructor2

public static java.lang.reflect.Constructor getConstructor2(ClassInjector injector,
                                                            java.lang.Class[] classes)
                                                     throws java.lang.IllegalArgumentException
Returns the constructor for a class that merges all of the given source classes. The constructor accepts one parameter type: an MergedClass.InstanceFactory. Merged instances are requested only when first needed. An IllegalArgumentException is thrown if any of the given conditions are not satisfied:
Parameters:
injector - ClassInjector that will receive class definition
classes - Source classes used to derive merged class

getConstructor2

public static java.lang.reflect.Constructor getConstructor2(ClassInjector injector,
                                                            java.lang.Class[] classes,
                                                            java.lang.String[] prefixes)
                                                     throws java.lang.IllegalArgumentException
Returns the constructor for a class that merges all of the given source classes. The constructor accepts one parameter type: an MergedClass.InstanceFactory. Merged instances are requested only when first needed. An IllegalArgumentException is thrown if any of the given conditions are not satisfied: To help resolve ambiguities, a method prefix can be specified for each passed in class. For each prefixed method, the non-prefixed method is also generated, unless that method conflicts with the return type of another method. If any passed in classes are or have interfaces, then those interfaces will be implemented only if there are no conflicts.

The array of prefixes may be null, have null elements or be shorter than the array of classes. A prefix of "" is treated as null.

Parameters:
injector - ClassInjector that will receive class definition
classes - Source classes used to derive merged class
prefixes - Optional prefixes to apply to methods of each generated class to eliminate duplicate method names