/*
* SAEnterStandAloneActionImpl
*
* 03/19/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.factory.*;
import com.ibm.retail.AEF.thread.*;
import com.ibm.retail.AEF.data.*;
import com.ibm.retail.AEF.session.*;
import java.util.*;
import java.rmi.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* SAEnterStandAloneActionImpl is a class which is used to enter stand alone mode in
* the supermarket application.
*
*/
public class SAEnterStandAloneActionImpl extends SAActionImpl
{
static String copyright()
{ return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT; }
private static Log log = LogFactory.getLog(SAEnterStandAloneActionImpl.class);
/**
* Constructor
*
* @param request The ActionRequest which contains a HashMap of arguments.
*
*/
public SAEnterStandAloneActionImpl(ActionRequest request) throws AEFException
{
super(request);
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter and -Exit SAEnterStandAloneActionImpl.SAEnterStandAloneActionImpl().");
log.trace(tempAEFMessage);
}
}
/**
* Perform the action represented by the ActionRequest and return an ActionResult.
*
*
* @param request The ActionRequest which contains the classname and arguments.
* @return Object Always returns a null object.
* @exception AEFException
*/
public Object performAction() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAEnterStandAloneActionImpl.performAction().");
log.trace(tempAEFMessage);
}
super.performAction(); // Call super to perform any common processing and clear any errors before we start.
Object retVal = null;
int seqResult = -1;
//Check precondition that we are in the ENTER_STANDALONE substate.
// If not, throw exception.
String currentSubState = "0";
currentSubState = getCurrentSubstate();
enterStandAloneSubState = Substate.getSubstate("ENTER_STANDALONE");
if (!currentSubState.equals(enterStandAloneSubState))
{
String tempString = "SAEnterStandAloneActionImpl.performAction(): POS application not in proper substate to perform logoff.\n Expected substate " + enterStandAloneSubState + ", but application is in state " + currentSubState + ".";
AEFException tempException = new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, tempString);
tempAEFMessage.setMessage(tempString);
log.error(tempAEFMessage, tempException);
throw tempException;
}
else
{
// Application is in correct substate to start preforming the action.
seqResult = sendStandAloneSequence();
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SAEnterStandAloneActionImpl.performAction().");
log.trace(tempAEFMessage);
}
return retVal;
}
/**
* Send the key sequence required to enter standalone.
*
*
* @return int An integer representing the result of the key sequence.
* @exception AEFException
*/
public int sendStandAloneSequence() throws AEFException
{
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("+Enter SAEnterStandAloneActionImpl.sendStandAloneSequence().");
log.trace(tempAEFMessage);
}
int retVal = -1;
lock = new ConditionLock();
// Send the first part of the logoff sequence and check for errors.
args.clear();
args.put("SEQUENCE_ID", "enterStandAlone");
keySequenceAction = (AEFAction) (actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args)));
Condition[] goodConditions =
{
new PropertyNotEqualsCondition(POSDeviceProperties.CATEGORY,
POSDeviceProperties.POS_SUB_STATE,
enterStandAloneSubState),
};
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage("SAEnterStandAloneActionImpl.sendStandAloneSequence() about to call performActionAndWait.");
log.debug(tempAEFMessage);
}
retVal = lock.performActionAndWait("wait-to-exit-enter-standalone-substate",
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout());
if (retVal < 0)
{
AEFErrorHandler errorHandler = new AEFErrorHandler("Send StandAlone Sequence Error");
retVal = errorHandler.handleError(lock,
keySequenceAction,
goodConditions,
BadConditionsImpl.getInstance().getBadConditions(),
getTimeout(),
retVal);
}
if (log.isDebugEnabled())
{
tempAEFMessage.setMessage("SAEnterStandAloneActionImpl.sendStandAloneSequence() retVal=" + retVal);
log.debug(tempAEFMessage);
}
if (log.isTraceEnabled())
{
tempAEFMessage.setMessage("-Exit SAEnterStandAloneActionImpl.sendStandAloneSequence().");
log.trace(tempAEFMessage);
}
return retVal;
}
/* Instance Variables */
protected AEFAction keySequenceAction = null;
protected ConditionLock lock = null;
protected String enterStandAloneSubState = null;
}