atg.commerce.order.processor
Class ProcDispatchOnProperty

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.order.processor.ProcDispatchOnProperty
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, PipelineProcessor, java.util.EventListener

public class ProcDispatchOnProperty
extends GenericService
implements PipelineProcessor

Dispatch to the next processor element based on the value of some named property of some designated object in the pipeline arguments map.

This processor allows you to specify an object in the pipeline arguments map and the name of some property on that object. It finds the named property's value, then looks up that value in a dispatch table and returns the corresponding integer value. This allows you to control pipeline transitions based on a property value.

For example, a generic "validatePaymentGroup" pipeline might branch based on the payment group class type by configuring an instance of this processor to examine the "paymentGroupClassType" property and including it in the pipeline as follows:

<pipelinelink name="DispatchOnType"> <processor jndi="/atg/commerce/order/processor/DispatchOnPaymentType"/> <transition returnvalue="1" link="ValidateCreditCard"/> <transition returnvalue="2" link="ValidateStoreCredit"/> <transition returnvalue="3" link="ValidateGiftCertificate"/> </pipelinelink>

The mapping of payment types to transition values is set through the returnValues property of this pipeline processor, e.g.:

returnValues=\ creditCard=1,\ storeCredit=2,\ giftCertificate=3,\ myCreditCard=1

You can assign the same return value to multiple property values if you want them to follow the same pipeline processor transition. For example, you could have your own extended credit card payment method use the same validation process as the build-in credit card payment method by assigning both methods the same return value as shown above.

This processor assumes that the type of the pipeline arguments object is compatible with and may be cast to java.util.Map.


Field Summary
static java.lang.String CLASS_VERSION
           
protected static java.util.ResourceBundle sDefaultResources
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.service.pipeline.PipelineProcessor
STOP_CHAIN_EXECUTION, STOP_CHAIN_EXECUTION_AND_COMMIT, STOP_CHAIN_EXECUTION_AND_ROLLBACK
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
ProcDispatchOnProperty()
           
 
Method Summary
protected  void convertReturnValues(java.util.Properties pReturnValues)
          Build the valueMap and retCodes objects from the values specified in pReturnValues.
 int getDefaultReturnValue()
          Get the default value to return if propertyName's value is not found in the lookup table.
 java.lang.String getPipelineKey()
          Get the lookup key that will identify the target object in the pipeline arguments map.
 java.lang.String getPropertyName()
          Set the name of the property whose value will determine the next processor invoked.
 int[] getRetCodes()
          Get the list of return values this processor can return.
 java.util.Properties getReturnValues()
          Return the mapping between values of propertyName and return values from runProcess.
protected  int getTransitionValue(java.lang.Object pPropertyValue)
          Given a value for the property specified by propertyName, find the corresponding return value from returnValues, choosing the default value if the property value was not listed in the lookup table.
 java.util.HashMap getValueMap()
          Get the mapping from property values to Integer return codes.
 boolean isWarnOnDefaultValue()
          Query whether or not to log a warning when returning defaultReturnValue for a property value that was not found in the lookup table.
static void main(java.lang.String[] args)
          Test method for convertReturnValues and getTransitionValue.
 int runProcess(java.lang.Object pParam, PipelineResult pResult)
          Look up the object identified by pipelineKey in the arguments map, retrieve the property named by propertyName, and return a value based on that property's value.
 void setDefaultReturnValue(int pDefaultReturnValue)
          Set the default value to return if propertyName's value is not found in the lookup table.
 void setPipelineKey(java.lang.String pPipelineKey)
          Set the lookup key that will identify the target object in the pipeline arguments map.
 void setPropertyName(java.lang.String pPropertyName)
          Set the name of the property whose value will determine the next processor invoked.
 void setReturnValues(java.util.Properties pReturnValues)
          Specify the mapping between values of propertyName and return values from runProcess.
 void setWarnOnDefaultValue(boolean pWarnOnDefaultValue)
          Specify whether or not to log a warning when returning defaultReturnValue for a property value that was not found in the lookup table.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
See Also:
Constant Field Values

sDefaultResources

protected static java.util.ResourceBundle sDefaultResources
Constructor Detail

ProcDispatchOnProperty

public ProcDispatchOnProperty()
Method Detail

setPipelineKey

public void setPipelineKey(java.lang.String pPipelineKey)
Set the lookup key that will identify the target object in the pipeline arguments map.


getPipelineKey

public java.lang.String getPipelineKey()
Get the lookup key that will identify the target object in the pipeline arguments map.


setPropertyName

public void setPropertyName(java.lang.String pPropertyName)
Set the name of the property whose value will determine the next processor invoked.


getPropertyName

public java.lang.String getPropertyName()
Set the name of the property whose value will determine the next processor invoked.


setReturnValues

public void setReturnValues(java.util.Properties pReturnValues)
Specify the mapping between values of propertyName and return values from runProcess.

Parameters:
pReturnValues - A properties object that specifies mappings between property values and return values expressed as strings. Each value in the properties object must be parsable as an integer. The returnValues object is of type Properties only to simplify setting the values from a Nucleus configuration file.

getReturnValues

public java.util.Properties getReturnValues()
Return the mapping between values of propertyName and return values from runProcess.


setDefaultReturnValue

public void setDefaultReturnValue(int pDefaultReturnValue)
Set the default value to return if propertyName's value is not found in the lookup table.


getDefaultReturnValue

public int getDefaultReturnValue()
Get the default value to return if propertyName's value is not found in the lookup table.


setWarnOnDefaultValue

public void setWarnOnDefaultValue(boolean pWarnOnDefaultValue)
Specify whether or not to log a warning when returning defaultReturnValue for a property value that was not found in the lookup table.


isWarnOnDefaultValue

public boolean isWarnOnDefaultValue()
Query whether or not to log a warning when returning defaultReturnValue for a property value that was not found in the lookup table. The default value is true.


getValueMap

public java.util.HashMap getValueMap()
Get the mapping from property values to Integer return codes. This mapping is built by traversing the returnValues Properties object and building a parallel structure whose keys are strings, but whose values are Integers instead of Strings, as in the Properties object.


getRetCodes

public int[] getRetCodes()
Get the list of return values this processor can return. This list is built by traversing the returnValues Properties object and the defaultReturnValue and building an array containing exactly one copy of each value that can be returned.

Specified by:
getRetCodes in interface PipelineProcessor
Returns:
an array of all the return codes that could be returned by this PipelineProcessor.

runProcess

public int runProcess(java.lang.Object pParam,
                      PipelineResult pResult)
               throws java.lang.Exception
Look up the object identified by pipelineKey in the arguments map, retrieve the property named by propertyName, and return a value based on that property's value.

Specified by:
runProcess in interface PipelineProcessor
Parameters:
pParam - Pipeline arguments object, assumed to be of a type that can be cast to java.util.Map
pResult - Pipeline results object, not used by this method.
Returns:
an integer value which is mapped to the next processor to execute. STOP_CHAIN_EXECUTION will notify the PipelineManager to stop execution. An unmapped value will throw a RunProcessException.
Throws:
java.lang.ClassCastException - If the type of pParam is not compatible with java.util.Map.
InvalidParameterException - If the object named by pipelineKey does not appear in the parameter map.
PropertyNotFoundException - If the object does not have a property with the name specified by propertyName.
java.lang.Exception

getTransitionValue

protected int getTransitionValue(java.lang.Object pPropertyValue)
Given a value for the property specified by propertyName, find the corresponding return value from returnValues, choosing the default value if the property value was not listed in the lookup table.

Parameters:
pPropertyValue - The value upon which to dispatch to the next pipeline processor.

convertReturnValues

protected void convertReturnValues(java.util.Properties pReturnValues)
Build the valueMap and retCodes objects from the values specified in pReturnValues.


main

public static void main(java.lang.String[] args)
Test method for convertReturnValues and getTransitionValue.