beanface.el.functor
Class Functor<T>

java.lang.Object
  extended by beanface.el.functor.Functor<T>
Type Parameters:
T - The base class which the target method is a member of.

public class Functor<T>
extends java.lang.Object

A Functor is an abstraction of a function that maps a single parameter to a result. The result is either an arbitrary object, or a second functor which can take a further parameter. Once the appropriate number of parameters are accumulated for the method identified by the FunctorStub, that method is invoked to obtain the final result.


Constructor Summary
Functor(javax.el.ELContext context, FunctorStub<T> functor)
          Construct a functor from an EL context and FunctorStub with no initial parameters.
Functor(javax.el.ELContext context, FunctorStub<T> functor, Functor<T> preceding, java.lang.Object param)
          Construct a functor by applying new parameter to a previous functor.
 
Method Summary
 java.lang.String action()
          For JavaServer Faces action methods.
 java.lang.Object applyParam(javax.el.ELContext context, java.lang.Object property)
          If no more parameters can be applied, or if sufficient parameters have been applied and the new parameter is "result", then invoke the functor's method and return the result.
 java.lang.Object applyParams(javax.el.ELContext context, java.lang.Object... params)
          Apply as many of the given parameters as possible.
 java.lang.Class<?> getAllowedParamType()
          Determine what type the next parameter may validly be.
 FunctorStub<T> getFunctor()
          The functor identification (reference to a method or constructor) that this functor will invoke.
 java.lang.Object getParam()
          The last applied parameter.
 int getParamCount()
          How many parameters have been supplied so far.
 int getParamCountRequired()
          What is the minimum number of parameters the must be supplied to allow the method to be invoked.
 java.lang.Object[] getParams()
          An array of the parameters that have been supplied so far.
 Functor<T> getPreceding()
          The functor state before the current parameter was applied.
 java.lang.Object getResult(javax.el.ELContext context)
          If there are sufficient parameters, then invoke the functor's method and return the result.
 java.lang.Object getResultOrSelf(javax.el.ELContext context)
          If this functor is not deferred, and no more parameters can be applied, then invoke the functor's method and return the result.
 boolean hasFixedArgs()
          Is there a definite number of parameters to be applied?
 boolean hasSufficientParams()
          Are there sufficient parameters already supplied to allow the method to be invoked (getParamCount() is greater-or-equal-to getParamCountRequired())?
 boolean hasVarArgs()
          Does the method or constructor referred to by this functor have var-arg parameters?
 boolean isDeferred()
          If the functor is deferred, the method will not be automatically invoked once the needed parameters have been provided.
 void processValueChange(javax.faces.event.ValueChangeEvent event)
          For JavaServer Faces value-change methods.
 java.lang.String toString()
          Create a String representation of this functor and the applied parameters for debugging purposes.
 void validate(javax.faces.context.FacesContext context, javax.faces.component.UIComponent toValidate, java.lang.Object value)
          For JavaServer Faces validation methods.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Functor

public Functor(javax.el.ELContext context,
               FunctorStub<T> functor)
Construct a functor from an EL context and FunctorStub with no initial parameters.

Parameters:
context - the EL context
functor - the FunctorStub identifying the method or constructor that this functor applies to.

Functor

public Functor(javax.el.ELContext context,
               FunctorStub<T> functor,
               Functor<T> preceding,
               java.lang.Object param)
Construct a functor by applying new parameter to a previous functor.

Parameters:
context - the EL context
functor - the FunctorStub identifying the method or constructor that this functor applies to.
preceding - the previous functor (with incomplete parameters) to which the parameter will be applied.
param - the new parameter to apply.
Method Detail

getFunctor

public FunctorStub<T> getFunctor()
The functor identification (reference to a method or constructor) that this functor will invoke.


getPreceding

public Functor<T> getPreceding()
The functor state before the current parameter was applied.


getParam

public java.lang.Object getParam()
The last applied parameter.


getParamCount

public int getParamCount()
How many parameters have been supplied so far.

Returns:
the parameter count.

getParams

public java.lang.Object[] getParams()
An array of the parameters that have been supplied so far.


getParamCountRequired

public int getParamCountRequired()
What is the minimum number of parameters the must be supplied to allow the method to be invoked.

Returns:
the minimum parameters required.

hasSufficientParams

public boolean hasSufficientParams()
Are there sufficient parameters already supplied to allow the method to be invoked (getParamCount() is greater-or-equal-to getParamCountRequired())?

Returns:
true if there are enough parameters.

hasVarArgs

public boolean hasVarArgs()
Does the method or constructor referred to by this functor have var-arg parameters?


hasFixedArgs

public boolean hasFixedArgs()
Is there a definite number of parameters to be applied?

Returns:
true if the method is not a var args method, or if the parameter count was explicitly specified.

isDeferred

public boolean isDeferred()
If the functor is deferred, the method will not be automatically invoked once the needed parameters have been provided. Instead, the ".result" or other method can be invoked on the functor itself.

Returns:
flag to indicate if the functor is deferred.

getResult

public java.lang.Object getResult(javax.el.ELContext context)
If there are sufficient parameters, then invoke the functor's method and return the result. Otherwise return null.

Parameters:
context - the EL context (may be needed to construct error messages).
Returns:
the result of invoking the functor's method.

getResultOrSelf

public java.lang.Object getResultOrSelf(javax.el.ELContext context)
If this functor is not deferred, and no more parameters can be applied, then invoke the functor's method and return the result. Otherwise return this so more parameters can be applied later. This is the normal behavour that the FunctorELResolver will invoke for each additional parameter.

Parameters:
context - the EL context (may be needed to construct error messages).

applyParam

public java.lang.Object applyParam(javax.el.ELContext context,
                                   java.lang.Object property)
If no more parameters can be applied, or if sufficient parameters have been applied and the new parameter is "result", then invoke the functor's method and return the result. Otherwise just apply the next parameter and call getResultOrSelf(javax.el.ELContext).

Parameters:
context - the EL context (may be needed to construct error messages).
property - the next property value to apply (either another parameter or the "result" indicator).
Returns:
the result of applying the property.

applyParams

public java.lang.Object applyParams(javax.el.ELContext context,
                                    java.lang.Object... params)
Apply as many of the given parameters as possible.

Parameters:
context - the EL context (may be needed to construct error messages).
params - the set of parameters to apply.
Returns:
the result of applying all the parameters.

getAllowedParamType

public java.lang.Class<?> getAllowedParamType()
Determine what type the next parameter may validly be.

Returns:
the class that the parameter must be castable to.

toString

public java.lang.String toString()
Create a String representation of this functor and the applied parameters for debugging purposes.

Overrides:
toString in class java.lang.Object

action

public java.lang.String action()
For JavaServer Faces action methods.


validate

public void validate(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent toValidate,
                     java.lang.Object value)
For JavaServer Faces validation methods.


processValueChange

public void processValueChange(javax.faces.event.ValueChangeEvent event)
                        throws javax.faces.event.AbortProcessingException
For JavaServer Faces value-change methods.

Parameters:
event - the triggering event.
Throws:
javax.faces.event.AbortProcessingException