/*
* SASetTrainingModeOnActionImpl
*
* 02/12/2003
*
* Copyright:
* Licensed Materials - Property of IBM
* "Restricted Materials of IBM"
* 5724-AEF
* (C) Copyright IBM Corp. 2003.
*
* %W% %E%
*/
package com.ibm.retail.AEF.action;
import com.ibm.retail.AEF.automation.*;
import com.ibm.retail.AEF.util.*;
import com.ibm.retail.si.util.*;
import com.ibm.retail.si.Copyright;
import com.ibm.retail.AEF.thread.*;
import com.ibm.retail.AEF.data.*;
import java.util.*;
import java.rmi.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* SASetTrainingModeOnActionImpl is a class which the POSAutomationProvider
* uses to put the terminal into training mode.
*
*/
public class SASetTrainingModeOnActionImpl extends SAActionImpl
{
static String copyright()
{ return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; }
private static AEFPerfTrace perfTrace = AEFPerfTrace.getInstance();
/**
* Constructor
*
* @param request The ActionRequest which contains a HashMap of arguments.
* @exception com.ibm.retail.AEF.util.AEFException
* AEFException error codes are:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public SASetTrainingModeOnActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASetTrainingModeOnActionImpl.SASetTrainingModeOnActionImpl().");
log.trace(tempAEFMessage);
}
mainState = State.getState("MAIN");
mainSubState = Substate.getSubstate("SELECT_PROCEDURE");
trainingSubState = Substate.getSubstate("TRAINING_MODE");
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SASetTrainingModeOnActionImpl.SASetTrainingModeOnActionImpl().");
log.trace(tempAEFMessage);
}
}
/**
* Puts the terminal into training mode.
*
* @return Object That is Null.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*
AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASetTrainingModeOnActionImpl.performAction().");
log.trace(tempAEFMessage);
}
super.performAction(); // Call super to perform any common processing and clear any errors before we start.
// Make sure that we are not in the Terminal Secured state.
checkForSpecialSignon();
// Continue with the training mode action.
String currentState = getCurrentState();
String currentSubState = getCurrentSubstate();
if (currentState.equalsIgnoreCase(mainState) && currentSubState.equalsIgnoreCase(mainSubState))
{
sendTrainingOnSequence();
}
else
{
String tempString = "SASetTrainingModeOnActionImpl.performAction(): POS application not in proper state to go into training mode.\n Application is in state " + currentState + " substate " + currentSubState + ". It should be in state " + mainState + " substate " + mainSubState + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SASetTrainingModeOnActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return null;
}
/**
* Send the training mode on sequence to the terminal.
*
* @return int A negative number means there was an error.
* 0 means that we are in sub-state 11045.
* @exception AEFException
* AEFException error codes:
*
AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR
*/
public int sendTrainingOnSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SASetTrainingModeOnActionImpl.sendTrainingOnSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
ConditionLock lock = null;
AEFAction keySequenceAction = null;
AEFErrorHandler errorHandler = null;
args.clear();
args.put("SEQUENCE_ID", "trainingModeOn");
keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
AbstractPropertyCondition[] goodConditions =
{
new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_SUB_STATE, trainingSubState)
};
lock = new ConditionLock();
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"setTrainingMode",
">>>Sending training mode key sequence to application.");
}
retVal = lock.performActionAndWait("wait-for-training-mode",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
errorHandler = new AEFErrorHandler("Set Training Mode On Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
if (retVal < 0)
{
tempAEFMessage.setMessage("Set Training Mode On Error");
log.error(tempAEFMessage, errorHandler.getAllExceptions());
throw errorHandler.getAllExceptions();
}
}
if (perfTrace.isEnabled(AEFPerfTrace. COARSE))
{
perfTrace.reportTimer(AEFPerfTrace. COARSE,
sessionID,
"setTrainingMode",
"<<