com.ikokoon.toolkit
Class ObjectFactory

java.lang.Object
  extended by com.ikokoon.toolkit.ObjectFactory

public abstract class ObjectFactory
extends java.lang.Object

This is an abstract factory. Classes are selected for construction according to the best match between the parameters and the solid implementation of the class.

Since:
02.09.08
Version:
01.00
Author:
Michael Couck

Method Summary
protected static
<E> java.lang.reflect.Constructor<E>
getConstructor(java.lang.Class<E> klass, java.lang.Object[] allParameters, java.util.List<java.lang.Object> parameters)
          Finds a constructor in a class that has a signature that includes some the parameters in the parameter list on a best match principal.
static
<E> E
getObject(java.lang.Class<E> klass, java.lang.Object... allParameters)
          This method instantiates a class based on the solid implementation class passed as a parameter and the parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getObject

public static <E> E getObject(java.lang.Class<E> klass,
                              java.lang.Object... allParameters)
This method instantiates a class based on the solid implementation class passed as a parameter and the parameters. A best match between the two parameters determines the class to be instanciated.

Type Parameters:
E - the desired class to be instanciated
Parameters:
klass - the class to be instanciated
parameters - the parameters for the constructor, these cannot be primitives and the parameters in the constructor have to be objects as well, not primitives
Returns:
the class that best matches the desired class and the parameters for constructors

getConstructor

protected static <E> java.lang.reflect.Constructor<E> getConstructor(java.lang.Class<E> klass,
                                                                     java.lang.Object[] allParameters,
                                                                     java.util.List<java.lang.Object> parameters)
Finds a constructor in a class that has a signature that includes some the parameters in the parameter list on a best match principal. Note that this method will return the first constructor that has all the parameters in one of the permutations even if there is another constructor that has more parameters in another of the permutations.

Parameters:
klass - the class look for a constructor in
allParameters - all the parameters that are available for the constructor
parameters - the parameters that were collected for the best match constructor
Returns:
the constructor that has all the parameters


Copyright © 2010. All Rights Reserved.