info.javelot.functionalj
Class ConstructorFunction

java.lang.Object
  extended byinfo.javelot.functionalj.Function
      extended byinfo.javelot.functionalj.ReflectionFunction
          extended byinfo.javelot.functionalj.ConstructorFunction
All Implemented Interfaces:
Serializable

public class ConstructorFunction
extends ReflectionFunction

Represents a function that targets a constructor. Such a function does not use a name nor an object on which to invoke the target. The constructors of the target class are used, and the supplied parameters are forwarded to the Constructor.newInstance(Object[]) method when invoking the target, returning the new instance that is created.

Author:
Copyright © 2006 Frederic Daoud
See Also:
Serialized Form

Field Summary
 
Fields inherited from class info.javelot.functionalj.Function
m_class, m_name, m_object, m_parameters, m_targets
 
Constructor Summary
ConstructorFunction(Class p_class)
          Creates a function that targets the constructors of the given class.
ConstructorFunction(Class p_class, Object[] p_parameters)
          Creates a function that targets the constructors of the given class which accept the supplied parameters.
 
Method Summary
protected  Object[] getAllTargets(Class p_class)
          Returns the constructors of the target class.
protected  int getInsertIndex(Object p_target)
          Since constructors have no particular priority over one another, this method always returns 0 as the index at with to insert the target.
protected  Class[] getParameterTypes(Object p_target)
          Returns the types of the parameters accepted by the constructor.
protected  Object invoke(Object p_target, Object p_object, Object[] p_parameters)
          Invokes the Constructor.newInstance(Object[]) method using the supplied parameters.
 boolean isObjectRequired()
          Returns false since no object is required to invoke a constructor.
protected  Function newInstance(Class p_class, Object[] p_parameters)
          Creates a new ConstructorFunction object using the specified target class and parameters.
 Function object(Object p_object)
          Throws a FunctionException, since no object is required to invoke a constructor.
 
Methods inherited from class info.javelot.functionalj.ReflectionFunction
call
 
Methods inherited from class info.javelot.functionalj.Function
addParameter, addParameters, addParameters, addParameters, addParameters, addParameters, getName, getObject, getParameters, getTargetClass, getTargets, isObjectPresent, objectOrParameter, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstructorFunction

public ConstructorFunction(Class p_class)
Creates a function that targets the constructors of the given class.

Parameters:
p_class - the class that contains the constructors targetted by this function.

ConstructorFunction

public ConstructorFunction(Class p_class,
                           Object[] p_parameters)
                    throws FunctionException
Creates a function that targets the constructors of the given class which accept the supplied parameters.

Parameters:
p_class - the class that contains the constructors targetted by this function.
p_parameters - the parameters to be supplied to the constructor.
Throws:
FunctionException - thrown if none of the target class's constructors accept the supplied parameters.
Method Detail

getAllTargets

protected Object[] getAllTargets(Class p_class)
Returns the constructors of the target class.

Specified by:
getAllTargets in class ReflectionFunction
Parameters:
p_class - the target class.
Returns:
the constructors of the target class.

getParameterTypes

protected Class[] getParameterTypes(Object p_target)
Returns the types of the parameters accepted by the constructor.

Specified by:
getParameterTypes in class ReflectionFunction
Parameters:
p_target - the target constructor for which to determine the types of the parameters.
Returns:
the types of the parameters accepted by the constructor.

getInsertIndex

protected int getInsertIndex(Object p_target)
Since constructors have no particular priority over one another, this method always returns 0 as the index at with to insert the target.

Specified by:
getInsertIndex in class ReflectionFunction
Parameters:
p_target - the constructor for which to obtain the index.
Returns:
the index at which to insert the target into the list, which is 0 in this case.

invoke

protected Object invoke(Object p_target,
                        Object p_object,
                        Object[] p_parameters)
                 throws FunctionException
Invokes the Constructor.newInstance(Object[]) method using the supplied parameters. Since there is no object needed on which to invoke the target, it is not used.

Specified by:
invoke in class ReflectionFunction
Parameters:
p_target - the target constructor to invoke.
p_object - not used.
p_parameters - the parameters to pass to the constructor.
Returns:
the object created by the constructor.
Throws:
FunctionException - thrown if an exception occurs when invoking the constructor.

isObjectRequired

public boolean isObjectRequired()
Returns false since no object is required to invoke a constructor.

Specified by:
isObjectRequired in class Function
Returns:
false.

newInstance

protected Function newInstance(Class p_class,
                               Object[] p_parameters)
Creates a new ConstructorFunction object using the specified target class and parameters.

Specified by:
newInstance in class Function
Parameters:
p_class - the class of the target.
p_parameters - the supplied parameters.
Returns:
a new ConstructorFunction object of the target class, containing the supplied parameters.

object

public Function object(Object p_object)
                throws FunctionException
Throws a FunctionException, since no object is required to invoke a constructor.

Specified by:
object in class Function
Throws:
FunctionException - always thrown since invoking this method is not applicable to instances of the ConstructorFunction class.