package alma.ACS.MasterComponentImpl.statemachine;

import alma.ACS.SUBSYSSTATE_OFFLINE;
import alma.ACSErrTypeCommon.wrappers.AcsJIllegalStateEventEx;
import alma.acs.genfw.runtime.sm.AcsState;

public class OfflineState extends AvailableSubStateAbstract
{
	public OfflineSubStateAbstract m_subState;

	public OfflineState(AlmaSubsystemContext superContext, AvailableState context) {
		super(superContext, context);
	}

	public String stateName() {
		return SUBSYSSTATE_OFFLINE.value;
	}

	/**
	 * @see alma.ACS.MasterComponentImpl.statemachine.AcsState#getStateHierarchy()
	 */
	public AcsState[] getStateHierarchy() {
		AcsState[] substates = m_subState.getStateHierarchy();
		AcsState[] hierarchy = new AcsState[substates.length + 1];
		hierarchy[0] = this;
		System.arraycopy(substates, 0, hierarchy, 1, substates.length);
		return hierarchy;
	}

	public void setSubstate(OfflineSubStateAbstract newSubState, String eventName) {
		OfflineSubStateAbstract oldSubState = m_subState;
		if (oldSubState != newSubState) {
			m_superContext.logTransition(oldSubState, newSubState, eventName);
			m_subState = newSubState;
		}
		
		// always propagate state change upwards
		m_context.setSubstate(this, eventName);
		
		if (oldSubState != newSubState) {
			m_subState.entry();
		}
	}


	public void entry() {
	}
	
	public void initPass1() throws AcsJIllegalStateEventEx {
		m_subState.initPass1();
	}

	public void initPass2() throws AcsJIllegalStateEventEx {
		m_subState.initPass2();
	}

	public void shutdownPass2() throws AcsJIllegalStateEventEx {
		m_subState.shutdownPass2();
	}

}

@@ -294,16 +294,56 @@
 ubState;
+%0A%09public boolean newEntryToThis = false;
 %0A%0A%09publi
@@ -1203,16 +1203,105 @@
  upwards
+. May result in a call to entry() if the previous state was not a substate of this state.
 %0A%09%09m_con
@@ -1340,24 +1340,42 @@
 );%0A%09%09%0A%09%09if (
+newEntryToThis %7C%7C 
 oldSubState 
@@ -1419,16 +1419,45 @@
 ();%0A%09%09%7D%0A
+%09%09%0A%09%09newEntryToThis = false;%0A
 %09%7D%0A%0A%0A%09pu
@@ -1476,16 +1476,41 @@
 try() %7B%0A
+%09%09newEntryToThis = true;%0A
 %09%7D%0A%09%0A%09pu

Fix for COMP-1776: When the same substate that was active when leaving this state is later re-entered, its entry() method gets called. Without leaving and reentering the composite state, the call to substate.entry() still gets suppressed.