/* * GSALogoffActionImpl * * 06/06/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; /** * GSALogoffActionImpl is a class which the POSAutomationProvider uses to accomplish * a logoff from the GSA application. * */ public class GSALogoffActionImpl extends GSAActionImpl { static String copyright() { return com.ibm.retail.si.Copyright.IBM_COPYRIGHT_SHORT;} private static Log log = LogFactory.getLog(GSALogoffActionImpl.class); private static AEFPerfTrace perfTrace = AEFPerfTrace.getInstance(); /** * Constructor * * @param request The ActionRequest which contains a HashMap of arguments. * @exception com.ibm.retail.AEF.util.AEFException * Among the possible AEFException error codes are: * <br>AEFConst.CONFIG_ERROR, AEFConst.FACTORY_ERROR * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public GSALogoffActionImpl(ActionRequest request) throws AEFException { super(request); if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSALogoffActionImpl.GSALogoffActionImpl()."); log.trace(tempAEFMessage); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSALogoffActionImpl.GSALogoffActionImpl()."); 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 The Operator instance. * @exception AEFException * Among the possible error codes are: * <br>AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_IN_PROGRESS * <br><a href="../commonerrorcodes.html">Common Errors</a> */ public Object performAction() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSALogoffActionImpl.performAction()."); log.trace(tempAEFMessage); } super.performAction(); // Call super to perform any common processing and clear any errors before we start. try { Transaction trans = automationProvider.getTransaction(); if (trans != null) { // We have a transaction in progress. The client must void the transaction before logging off. throw new AEFException(AEFConst.PROCEDURE_NOT_ALLOWED, AEFConst.TRANSACTION_IN_PROGRESS, "GSALogoffActionImpl.performAction(): Unable to logoff because a transaction is in progress."); } sendLogoffSequence(); // Log Trace info. if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "logoff", "<<<Detected logoff from application."); } } catch (AEFException e) { tempAEFMessage.setMessage("There was an AEF exception thrown in performAction of GSALogoffActionImpl."); log.error(tempAEFMessage, e); throw e; } catch (RemoteException re) { // We should never get here because we are calling locally. tempAEFMessage.setMessage("There was a remote exception thrown in performAction of GSALogoffActionImpl."); log.error(tempAEFMessage, re); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSALogoffActionImpl.performAction()."); log.trace(tempAEFMessage); } return null; } /** * Send the key sequence required for a logoff. * * * @return int An integer representing the result of the key sequence. * @exception AEFException */ private int sendLogoffSequence() throws AEFException { if (log.isTraceEnabled()) { tempAEFMessage.setMessage("+Enter GSALogoffActionImpl.sendLogoffSequence()."); log.trace(tempAEFMessage); } int retVal = -1; AEFAction keySequenceAction = null; ConditionLock lock = new ConditionLock(); // Send the first part of the logoff sequence and check for errors. args.clear(); args.put("SEQUENCE_ID", "logoff1"); keySequenceAction = (AEFAction) (actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions1 = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, State.getState("SIGNOFF")) }; if (log.isInfoEnabled()) { tempAEFMessage.setMessage("GSALogoffActionImpl.sendLogoffSequence() about to call performActionAndWait for part one of Signoff."); log.info(tempAEFMessage); } retVal = lock.performActionAndWait("wait-for-id-state", keySequenceAction, goodConditions1, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Logoff Sequence Error Part 1"); retVal = errorHandler.handleError(lock, keySequenceAction, goodConditions1, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); if (retVal < 0) { tempAEFMessage.setMessage("An AEF exception was thrown in GSALogoffActionImpl.performAction()."); log.trace(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } // Send the second part of the logoff sequence and check for errors. args.clear(); args.put("SEQUENCE_ID", "logoff2"); keySequenceAction = (AEFAction)(actionFactory.makeAction(new ActionRequest("SimpleKeySequenceAction", args))); Condition[] goodConditions2 = { new PropertyEqualsCondition(POSDeviceProperties.CATEGORY, POSDeviceProperties.POS_STATE, State.getState("ID")) }; if (log.isDebugEnabled()) { tempAEFMessage.setMessage("GSALogoffActionImpl.sendLogoffSequence() about to call performActionAndWait for part two of Signoff."); log.debug(tempAEFMessage); } if (perfTrace.isEnabled(AEFPerfTrace. COARSE)) { perfTrace.reportTimer(AEFPerfTrace. COARSE, sessionID, "logoff", ">>>Sending logoff key sequence to application."); } retVal = lock.performActionAndWait("wait-for-id-state", keySequenceAction, goodConditions2, BadConditionsImpl.getInstance().getBadConditions(), getTimeout()); if (retVal < 0) { AEFErrorHandler errorHandler = new AEFErrorHandler("Send Logoff Sequence Error Part 2"); retVal = errorHandler.handleError(lock, keySequenceAction, goodConditions2, BadConditionsImpl.getInstance().getBadConditions(), getTimeout(), retVal); if (retVal < 0) { tempAEFMessage.setMessage("An AEF exception was thrown in GSALogoffActionImpl.performAction()."); log.trace(tempAEFMessage, errorHandler.getAllExceptions()); throw errorHandler.getAllExceptions(); } } if (log.isDebugEnabled()) { tempAEFMessage.setMessage("GSALogoffActionImpl.sendLogoffSequence() retVal=" + retVal); log.debug(tempAEFMessage); } if (log.isTraceEnabled()) { tempAEFMessage.setMessage("-Exit GSALogoffActionImpl.sendLogoffSequence()."); log.trace(tempAEFMessage); } return retVal; } }