/* * GSASetTrainingModeOnActionImpl * * 06/30/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 org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * GSASetTrainingModeOnActionImpl is a class which the POSAutomationProvider * uses to put the terminal into training mode. * */ public class GSASetTrainingModeOnActionImpl extends GSAActionImpl { static String copyright() { return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT;} /** * Constructor * * @param request The ActionRequest which contains a HashMap of arguments. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public GSASetTrainingModeOnActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASetTrainingModeOnActionImpl.GSASetTrainingModeOnActionImpl()."); log.trace(tempAEFMessage); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASetTrainingModeOnActionImpl.GSASetTrainingModeOnActionImpl()."); log.trace(tempAEFMessage); } } /** * Puts the terminal into training mode. * * @return Object That is Null. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <br>AEFConst.APPLICATION_NOT_IN_PROPER_STATE, AEFConst.NONE */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASetTrainingModeOnActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. try { String transactionSelectState = State.getState("TRANSACTION_SELECT"); // Continue with the training mode action. String currentState = getCurrentState(); if (currentState.equalsIgnoreCase(transactionSelectState)) { sendTrainingOnSequence(); } else { throw new AEFException(AEFConst.APPLICATION_NOT_IN_PROPER_STATE, 0, "GSASetTrainingModeOnActionImpl.performAction(): POS application not in proper state to go into training mode.\n Application is in state " + currentState + ". It should be in state " + transactionSelectState + "."); } if (log.isDebugEnabled()) { tempAEFMessage.setMessage("GSASetTrainingModeOnActionImpl.performAction Ended."); log.debug(tempAEFMessage); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSASetTrainingModeOnActionImpl."); log.error(tempAEFMessage, e); throw e; } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASetTrainingModeOnActionImpl.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 training mode. * @exception AEFException * AEFException error codes: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR */ public int sendTrainingOnSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSASetTrainingModeOnActionImpl.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_STATE, State.getState("ID")) }; lock = new ConditionLock(); 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("An AEF exception was thrown in GSASetTrainingModeOnActionImpl.sendTrainingOnSequence()."); log.error(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSASetTrainingModeOnActionImpl.sendTrainingOnSequence()."); log.trace(tempAEFMessage); } return retVal; } /* Instance Variables */ private static Log log = LogFactory.getLog(GSASetTrainingModeOnActionImpl.class); }