org.deduced.dynamic
Class DefaultActionInvoker

java.lang.Object
  extended by org.deduced.dynamic.DefaultActionInvoker
All Implemented Interfaces:
ActionInvoker

public class DefaultActionInvoker
extends java.lang.Object
implements ActionInvoker

Default Action Invoker

Author:
Steve McDuff

Field Summary
private static java.util.logging.Logger LOGGER
          logger
 
Constructor Summary
DefaultActionInvoker()
           
 
Method Summary
private  java.lang.Object[] assembleParameters(PropertyCollection<?,?> collection, PropertyCollection<?,?> action, InvocationParameter[] parameters, java.lang.String actionName)
          assemble Parameters in an ordered array of values
private  void checkForUnusedParameters(PropertyCollection<?,?> collection, InvocationParameter[] parameters, java.lang.String actionName, java.util.Map<java.lang.String,InvocationParameter> mappedParameters)
          check For Unused Parameters and log them if necessary
static java.lang.String createInvokeActionMessage(PropertyCollection<?,?> collection, java.lang.String actionName, InvocationParameter[] parameters)
          create Invoke Action Message
 java.util.Map<java.lang.String,InvocationParameter> createNamedParameterMap(PropertyCollection<?,?> collection, InvocationParameter[] parameters, java.lang.String actionName)
          create a Named Parameter Map
 java.lang.Object extractParameterValue(PropertyCollection<?,?> collection, InvocationParameter[] parameters, java.lang.String actionName, PropertyCollection<?,?> parameterDefinition, java.lang.String parameterName, InvocationParameter currentAssignment)
          extract Parameter Value
static PropertyCollection<?,?> findActionByNameOnType(java.lang.String actionName, PropertyCollection<?,?> type)
          find Action By Name On Type
static RuleExecutionContext getContextFromCollection(PropertyCollection<?,?> collection)
          get Context From Collection
 java.lang.Object invokeAction(PropertyCollection<?,?> collection, java.lang.String actionName, InvocationParameter[] parameters)
          (non-JSDoc)
 java.lang.Object invokeActionSilent(PropertyCollection<?,?> collection, java.lang.String actionName, InvocationParameter[] parameters)
          (non-JSDoc)
static void logActionException(java.lang.Throwable exception)
          log Action Exception
static java.lang.String printParameters(InvocationParameter[] parameters)
          print Parameters
private  void validateAction(PropertyCollection<?,?> action, PropertyCollection<?,?> collection, java.lang.String actionName)
          validate Action
private  void validateCollectionAndActionName(PropertyCollection<?,?> collection, java.lang.String actionName)
          validate Collection And Action name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER
logger

Constructor Detail

DefaultActionInvoker

public DefaultActionInvoker()
Method Detail

invokeAction

public java.lang.Object invokeAction(PropertyCollection<?,?> collection,
                                     java.lang.String actionName,
                                     InvocationParameter[] parameters)
                              throws java.lang.IllegalArgumentException,
                                     java.lang.reflect.InvocationTargetException,
                                     java.lang.NullPointerException,
                                     java.lang.IllegalStateException,
                                     CompilationFailedException
(non-JSDoc)

Specified by:
invokeAction in interface ActionInvoker
Parameters:
collection - the property collection
actionName - the action name to invoke
parameters - the list of parameter and value to invoke. Any parameter not in this list will be assigned a default value. If a parameter doesn't have a default value, an InvocationTargetException will be thrown.
Returns:
the action return value
Throws:
java.lang.IllegalArgumentException - if some of the parameters are wrong or missing or the action fails to compile.
java.lang.reflect.InvocationTargetException - if the action code throws an exception.
java.lang.NullPointerException - if the collection or actionName parameters are null.
java.lang.IllegalStateException - if action isn't enabled.
CompilationFailedException - if action failed to compile.
See Also:
ActionInvoker.invokeAction(org.deduced.PropertyCollection, java.lang.String, org.deduced.InvocationParameter[])

assembleParameters

private java.lang.Object[] assembleParameters(PropertyCollection<?,?> collection,
                                              PropertyCollection<?,?> action,
                                              InvocationParameter[] parameters,
                                              java.lang.String actionName)
assemble Parameters in an ordered array of values

Parameters:
collection - the collection on which to invoke the action
action - the action
parameters - the parameters
actionName - the action name
Returns:
the ordered parameter array

checkForUnusedParameters

private void checkForUnusedParameters(PropertyCollection<?,?> collection,
                                      InvocationParameter[] parameters,
                                      java.lang.String actionName,
                                      java.util.Map<java.lang.String,InvocationParameter> mappedParameters)
check For Unused Parameters and log them if necessary

Parameters:
collection - the collection on which to invoke the action
parameters - the parameters
actionName - the action name
mappedParameters - the map of remaining parameters

extractParameterValue

public java.lang.Object extractParameterValue(PropertyCollection<?,?> collection,
                                              InvocationParameter[] parameters,
                                              java.lang.String actionName,
                                              PropertyCollection<?,?> parameterDefinition,
                                              java.lang.String parameterName,
                                              InvocationParameter currentAssignment)
extract Parameter Value

Parameters:
collection - the collection on which to invoke the action
parameters - the parameters to use
actionName - the action name
parameterDefinition - the parameter definition
parameterName - the parameter name
currentAssignment - the current parameter assignment
Returns:
the parameter value

getContextFromCollection

public static RuleExecutionContext getContextFromCollection(PropertyCollection<?,?> collection)
get Context From Collection

Parameters:
collection - the collection from which to fetch the context
Returns:
the rule execution context

createNamedParameterMap

public java.util.Map<java.lang.String,InvocationParameter> createNamedParameterMap(PropertyCollection<?,?> collection,
                                                                                   InvocationParameter[] parameters,
                                                                                   java.lang.String actionName)
create a Named Parameter Map

Parameters:
collection - the collection on which to invoke the action
parameters - the parameters to use
actionName - the action name
Returns:
the map of all the parameter assignments with their name as key

createInvokeActionMessage

public static java.lang.String createInvokeActionMessage(PropertyCollection<?,?> collection,
                                                         java.lang.String actionName,
                                                         InvocationParameter[] parameters)
create Invoke Action Message

Parameters:
collection - collection on which the action is invoked
actionName - action name
parameters - parameter values
Returns:
the invoke action message

printParameters

public static java.lang.String printParameters(InvocationParameter[] parameters)
print Parameters

Parameters:
parameters - parameters to print
Returns:
the printed version of the parameters

validateAction

private void validateAction(PropertyCollection<?,?> action,
                            PropertyCollection<?,?> collection,
                            java.lang.String actionName)
validate Action

Parameters:
action - the action to validate
collection - on which collection
actionName - the matching action name

validateCollectionAndActionName

private void validateCollectionAndActionName(PropertyCollection<?,?> collection,
                                             java.lang.String actionName)
validate Collection And Action name

Parameters:
collection - the collection to validate
actionName - the action name to validate

findActionByNameOnType

public static PropertyCollection<?,?> findActionByNameOnType(java.lang.String actionName,
                                                             PropertyCollection<?,?> type)
find Action By Name On Type

Parameters:
actionName - the action name to find
type - the type to search
Returns:
the matching action

invokeActionSilent

public java.lang.Object invokeActionSilent(PropertyCollection<?,?> collection,
                                           java.lang.String actionName,
                                           InvocationParameter[] parameters)
(non-JSDoc)

Specified by:
invokeActionSilent in interface ActionInvoker
Parameters:
collection - the property collection
actionName - the action name to invoke
parameters - the list of parameter and value to invoke. Any parameter not in this list will be assigned a default value. If a parameter doesn't have a default value, an InvocationTargetException will be thrown.
Returns:
the action return value
See Also:
ActionInvoker.invokeActionSilent(org.deduced.PropertyCollection, java.lang.String, org.deduced.InvocationParameter[])

logActionException

public static void logActionException(java.lang.Throwable exception)
log Action Exception

Parameters:
exception - the error that was detected