/**
  * This file was generated from model [Model1] on [Sun Feb 19 14:22:38 MSK 2006].
  * Do not change content of this file.
  */

//package ;

import java.util.*;

import com.evelopers.common.exception.*;
import com.evelopers.unimod.core.stateworks.*;
import com.evelopers.unimod.runtime.*;
import com.evelopers.unimod.runtime.context.*;


public class Model1EventProcessor extends AbstractEventProcessor {

  private ModelStructure modelStructure;

        private static final int A2 = 1;
      private static final int A1 = 2;
      private static final int A3 = 3;
  
  private int decodeStateMachine(String sm) {
          
    if ("A2".equals(sm)) {
      return A2;
            else 
        
    if ("A1".equals(sm)) {
      return A1;
            else 
        
    if ("A3".equals(sm)) {
      return A3;
      }

    return -1;
  }
    
      private A2EventProcessor _A2;
      private A1EventProcessor _A1;
      private A3EventProcessor _A3;
    
  public Model1EventProcessor() {
    modelStructure = new Model1ModelStructure();

          _A2 = new A2EventProcessor();
          _A1 = new A1EventProcessor();
          _A3 = new A3EventProcessor();
      }

    public ModelStructure getModelStructure() {
    return modelStructure;
  }  
  
    public void setControlledObjectsMap(ControlledObjectsMap controlledObjectsMap) {
        super.setControlledObjectsMap(controlledObjectsMap);
    
          _A2.init(controlledObjectsMap);
          _A1.init(controlledObjectsMap);
          _A3.init(controlledObjectsMap);
        }

  protected StateMachineConfig process(
            Event event, StateMachineContext context,
            StateMachinePath path, StateMachineConfig configthrows SystemException {

    // get state machine from path
    int sm = decodeStateMachine(path.getStateMachine());
    
    try {
    switch (sm) {
          case A2:
        return _A2.process(event, context, path, config);
          case A1:
        return _A1.process(event, context, path, config);
          case A3:
        return _A3.process(event, context, path, config);
          default:
        throw new EventProcessorException("Unknown state machine [" + path.getStateMachine() "]");
    }
    catch (Exception e) {
      if (instanceof SystemException) {
        throw (SystemException)e;
      else {
        throw new SystemException(e);
      }
    }
  }

    protected StateMachineConfig transiteToStableState(
            StateMachineContext context,
            StateMachinePath path, StateMachineConfig configthrows SystemException {

    // get state machine from path
    int sm = decodeStateMachine(path.getStateMachine());

    try {
    switch (sm) {
          case A2:
        return _A2.transiteToStableState(context, path, config);
          case A1:
        return _A1.transiteToStableState(context, path, config);
          case A3:
        return _A3.transiteToStableState(context, path, config);
          default:
        throw new EventProcessorException("Unknown state machine [" + path.getStateMachine() "]");
    }
    catch (Exception e) {
      if (instanceof SystemException) {
        throw (SystemException)e;
      else {
        throw new SystemException(e);
      }
    }
  }  

  private class Model1ModelStructure implements ModelStructure {

  private Map configManagers = new HashMap();

  private Model1ModelStructure() {
          configManagers.put("A2"new com.evelopers.unimod.runtime.config.DistinguishConfigManager());
          configManagers.put("A1"new com.evelopers.unimod.runtime.config.DistinguishConfigManager());
          configManagers.put("A3"new com.evelopers.unimod.runtime.config.DistinguishConfigManager());
      }

  public StateMachinePath getRootPath() throws EventProcessorException {
    return new StateMachinePath("A1");        
  }

  public StateMachineConfigManager getConfigManager(String stateMachinethrows EventProcessorException {
    return (StateMachineConfigManager)configManagers.get(stateMachine);
  }

  public StateMachineConfig getTopConfig(String stateMachinethrows EventProcessorException {
    int sm = decodeStateMachine(stateMachine);
    
    switch (sm) {
          case A2:
        return new StateMachineConfig("Top");
          case A1:
        return new StateMachineConfig("Top");
          case A3:
        return new StateMachineConfig("Top");
          default:
        throw new EventProcessorException("Unknown state machine [" + stateMachine + "]");
    }
  }

  public boolean isFinal(String stateMachine, StateMachineConfig configthrows EventProcessorException {
    // get state machine from path
    int sm = decodeStateMachine(stateMachine);
    int state;
    
    switch (sm) {
          case A2:
        state = _A2.decodeState(config.getActiveState());
        switch (state) {
                                                                                                                                                                                                                                                          default:
            return false;
        }
          case A1:
        state = _A1.decodeState(config.getActiveState());
        switch (state) {
                                                                                        default:
            return false;
        }
          case A3:
        state = _A3.decodeState(config.getActiveState());
        switch (state) {
                                                                                                                            default:
            return false;
        }
          default:
        throw new EventProcessorException("Unknown state machine [" + stateMachine + "]");
    }
  }      
}  
      







private class A2EventProcessor {

    // states
      private static final int Top = 1;
      private static final int s5 = 2;
      private static final int s9 = 3;
      private static final int s7 = 4;
      private static final int s8 = 5;
      private static final int s4 = 6;
      private static final int s6 = 7;
      private static final int s1 = 8;
      private static final int s11 = 9;
      private static final int s3 = 10;
      private static final int s10 = 11;
      private static final int s2 = 12;
  
  private int decodeState(String state) {
          
    if ("Top".equals(state)) {
      return Top;
            else 
        
    if ("s5".equals(state)) {
      return s5;
            else 
        
    if ("s9".equals(state)) {
      return s9;
            else 
        
    if ("s7".equals(state)) {
      return s7;
            else 
        
    if ("s8".equals(state)) {
      return s8;
            else 
        
    if ("s4".equals(state)) {
      return s4;
            else 
        
    if ("s6".equals(state)) {
      return s6;
            else 
        
    if ("s1".equals(state)) {
      return s1;
            else 
        
    if ("s11".equals(state)) {
      return s11;
            else 
        
    if ("s3".equals(state)) {
      return s3;
            else 
        
    if ("s10".equals(state)) {
      return s10;
            else 
        
    if ("s2".equals(state)) {
      return s2;
      }
    
    return -1;
  }
  
    // events
      private static final int e201 = 1;
      private static final int e101 = 2;
  
  private int decodeEvent(String event) {
          
    if ("e201".equals(event)) {
      return e201;
            else 
        
    if ("e101".equals(event)) {
      return e101;
        }
  
    return -1;
  }
    
              private svet.co.DrawingWindows o1;
        
  private void init(ControlledObjectsMap controlledObjectsMap) {
                  o1 = (svet.co.DrawingWindows)controlledObjectsMap.getControlledObject("o1");
            }
    
  private StateMachineConfig process(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    config = lookForTransition(event, context, path, config);
    
    config = transiteToStableState(context, path, config);
    
    // execute included state machines
    executeSubmachines(event, context, path, config);
    
    return config;
  }
  
  private void executeSubmachines(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    int state = decodeState(config.getActiveState());
    
    while (true) {
    switch (state) {
                                      case s5: 
          
                      return;
                                          case s9: 
          
                      return;
                                          case s7: 
          
                      return;
                                          case s8: 
          
                      return;
                                          case s4: 
          
                      return;
                                          case s6: 
          
                      return;
                                          case s1: 
          
                      return;
                                          case s11: 
          
                      return;
                                          case s3: 
          
                      return;
                                          case s10: 
          
                      return;
                                          case s2: 
          
                      return;
                                default:
          throw new EventProcessorException("State with name [" + config.getActiveState() "] is unknown for state machine [A2]");
    }
    }
  }
  
  private StateMachineConfig transiteToStableState(StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {

    int s = decodeState(config.getActiveState());
    Event event;

    switch (s) {
                  case Top:
          
                    
          fireComeToState(context, path, "s1");

          // s1->s10 [true]/
          event = Event.NO_EVENT;
            fireTransitionFound(context, path, "s1", event, "s1#s10##true");
  
    
  fireComeToState(context, path, "s10");
  
  // s10 [o1.z0]
        fireBeforeOutputActionExecution(context, path, "s1#s10##true""o1.z0");

        o1.z0(context);
    
  fireAfterOutputActionExecution(context, path, "s1#s10##true""o1.z0");
            
                      return new StateMachineConfig("s10");
                                                                                                                                      }
  
    return config;
  }    
  
  private StateMachineConfig lookForTransition(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
          
    
      boolean
                
      o1_x1 = false
                  ,
            
      o1_x2 = false
        ;
        
    
  
        BitSet calculatedInputActions = new BitSet(2);
    
    int s = decodeState(config.getActiveState());
    int e = decodeEvent(event.getName());
  
    while (true) {
      switch (s) {
                                      case s5:
            
                      
                        switch (e) {
                          case e201:
                                
            // s5->s6 e201[true]/o1.z10
      
      fireTransitionCandidate(context, path, "s5", event, "s5#s6#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s5", event, "s5#s6#e201#true");
  
        fireBeforeOutputActionExecution(context, path, "s5#s6#e201#true""o1.z10");

        o1.z10(context);
    
  fireAfterOutputActionExecution(context, path, "s5#s6#e201#true""o1.z10");
    
  fireComeToState(context, path, "s6");
  
  // s6 [o1.z5]
        fireBeforeOutputActionExecution(context, path, "s5#s6#e201#true""o1.z5");

        o1.z5(context);
    
  fireAfterOutputActionExecution(context, path, "s5#s6#e201#true""o1.z5");
          return new StateMachineConfig("s6");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s9:
            
                      
                        switch (e) {
                          case e101:
                                
            // s9->s3 e101[true]/
      
      fireTransitionCandidate(context, path, "s9", event, "s9#s3#e101#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s9", event, "s9#s3#e101#true");
  
    
  fireComeToState(context, path, "s3");
  
  // s3 [o1.z1]
        fireBeforeOutputActionExecution(context, path, "s9#s3#e101#true""o1.z1");

        o1.z1(context);
    
  fireAfterOutputActionExecution(context, path, "s9#s3#e101#true""o1.z1");
          return new StateMachineConfig("s3");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s7:
            
                      
                        switch (e) {
                          case e201:
                                
            // s7->s8 e201[true]/o1.z12
      
      fireTransitionCandidate(context, path, "s7", event, "s7#s8#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s7", event, "s7#s8#e201#true");
  
        fireBeforeOutputActionExecution(context, path, "s7#s8#e201#true""o1.z12");

        o1.z12(context);
    
  fireAfterOutputActionExecution(context, path, "s7#s8#e201#true""o1.z12");
    
  fireComeToState(context, path, "s8");
  
  // s8 [o1.z8]
        fireBeforeOutputActionExecution(context, path, "s7#s8#e201#true""o1.z8");

        o1.z8(context);
    
  fireAfterOutputActionExecution(context, path, "s7#s8#e201#true""o1.z8");
          return new StateMachineConfig("s8");

                                        
                            case e101:
                                
            // s7->s11 e101[true]/
      
      fireTransitionCandidate(context, path, "s7", event, "s7#s11#e101#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s7", event, "s7#s11#e101#true");
  
    
  fireComeToState(context, path, "s11");
  
  // s11 [o1.z6]
        fireBeforeOutputActionExecution(context, path, "s7#s11#e101#true""o1.z6");

        o1.z6(context);
    
  fireAfterOutputActionExecution(context, path, "s7#s11#e101#true""o1.z6");
          return new StateMachineConfig("s11");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s8:
            
                      
                        switch (e) {
                          case e201:
                                
            // s8->s2 e201[true]/o1.z13
      
      fireTransitionCandidate(context, path, "s8", event, "s8#s2#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s8", event, "s8#s2#e201#true");
  
        fireBeforeOutputActionExecution(context, path, "s8#s2#e201#true""o1.z13");

        o1.z13(context);
    
  fireAfterOutputActionExecution(context, path, "s8#s2#e201#true""o1.z13");
    
  fireComeToState(context, path, "s2");
  
  // s2 [o1.z9]
        fireBeforeOutputActionExecution(context, path, "s8#s2#e201#true""o1.z9");

        o1.z9(context);
    
  fireAfterOutputActionExecution(context, path, "s8#s2#e201#true""o1.z9");
          return new StateMachineConfig("s2");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s4:
            
                      
                        switch (e) {
                          case e201:
                                
            // s4->s5 e201[true]/o1.z12
      
      fireTransitionCandidate(context, path, "s4", event, "s4#s5#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s4", event, "s4#s5#e201#true");
  
        fireBeforeOutputActionExecution(context, path, "s4#s5#e201#true""o1.z12");

        o1.z12(context);
    
  fireAfterOutputActionExecution(context, path, "s4#s5#e201#true""o1.z12");
    
  fireComeToState(context, path, "s5");
  
  // s5 [o1.z4]
        fireBeforeOutputActionExecution(context, path, "s4#s5#e201#true""o1.z4");

        o1.z4(context);
    
  fireAfterOutputActionExecution(context, path, "s4#s5#e201#true""o1.z4");
          return new StateMachineConfig("s5");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s6:
            
                      
                        switch (e) {
                          case e201:
                                
            // s6->s7 e201[o1.x2]/o1.z11
      
      fireTransitionCandidate(context, path, "s6", event, "s6#s7#e201#o1.x2");
      
                                  if (!isInputActionCalculated(calculatedInputActions, _o1_x2)) {
  
    fireBeforeInputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.x2");

          o1_x2 = o1.x2(context);
    
      fireAfterInputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.x2"new Boolean(o1_x2));
      }          
              
              
      
                        if (o1_x2) {
        
          fireTransitionFound(context, path, "s6", event, "s6#s7#e201#o1.x2");
  
        fireBeforeOutputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.z11");

        o1.z11(context);
    
  fireAfterOutputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.z11");
    
  fireComeToState(context, path, "s7");
  
  // s7 [o1.z7]
        fireBeforeOutputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.z7");

        o1.z7(context);
    
  fireAfterOutputActionExecution(context, path, "s6#s7#e201#o1.x2""o1.z7");
          return new StateMachineConfig("s7");

                  }
                        // s6->s6 e201[!o1.x2]/
      
      fireTransitionCandidate(context, path, "s6", event, "s6#s6#e201#!o1.x2");
      
                          
              
      
                        if (!o1_x2) {
        
          fireTransitionFound(context, path, "s6", event, "s6#s6#e201#!o1.x2");
  
    
  fireComeToState(context, path, "s6");
  
  // s6 [o1.z5]
        fireBeforeOutputActionExecution(context, path, "s6#s6#e201#!o1.x2""o1.z5");

        o1.z5(context);
    
  fireAfterOutputActionExecution(context, path, "s6#s6#e201#!o1.x2""o1.z5");
          return new StateMachineConfig("s6");

                  }
                                
                    // transition not found
                return config;
                                    default:
                            
              
                    // transition not found
                return config;
                        }
            
                                                          case s11:
            
                      
                        switch (e) {
                          case e101:
                                
            // s11->s7 e101[true]/
      
      fireTransitionCandidate(context, path, "s11", event, "s11#s7#e101#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s11", event, "s11#s7#e101#true");
  
    
  fireComeToState(context, path, "s7");
  
  // s7 [o1.z7]
        fireBeforeOutputActionExecution(context, path, "s11#s7#e101#true""o1.z7");

        o1.z7(context);
    
  fireAfterOutputActionExecution(context, path, "s11#s7#e101#true""o1.z7");
          return new StateMachineConfig("s7");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s3:
            
                      
                        switch (e) {
                          case e201:
                                
            // s3->s4 e201[true]/
      
      fireTransitionCandidate(context, path, "s3", event, "s3#s4#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s3", event, "s3#s4#e201#true");
  
    
  fireComeToState(context, path, "s4");
  
  // s4 [o1.z3]
        fireBeforeOutputActionExecution(context, path, "s3#s4#e201#true""o1.z3");

        o1.z3(context);
    
  fireAfterOutputActionExecution(context, path, "s3#s4#e201#true""o1.z3");
          return new StateMachineConfig("s4");

                                        
                            case e101:
                                
            // s3->s9 e101[true]/
      
      fireTransitionCandidate(context, path, "s3", event, "s3#s9#e101#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s3", event, "s3#s9#e101#true");
  
    
  fireComeToState(context, path, "s9");
  
  // s9 [o1.z2]
        fireBeforeOutputActionExecution(context, path, "s3#s9#e101#true""o1.z2");

        o1.z2(context);
    
  fireAfterOutputActionExecution(context, path, "s3#s9#e101#true""o1.z2");
          return new StateMachineConfig("s9");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s10:
            
                      
                        switch (e) {
                          case e201:
                                
            // s10->s2 e201[true]/o1.z13
      
      fireTransitionCandidate(context, path, "s10", event, "s10#s2#e201#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s10", event, "s10#s2#e201#true");
  
        fireBeforeOutputActionExecution(context, path, "s10#s2#e201#true""o1.z13");

        o1.z13(context);
    
  fireAfterOutputActionExecution(context, path, "s10#s2#e201#true""o1.z13");
    
  fireComeToState(context, path, "s2");
  
  // s2 [o1.z9]
        fireBeforeOutputActionExecution(context, path, "s10#s2#e201#true""o1.z9");

        o1.z9(context);
    
  fireAfterOutputActionExecution(context, path, "s10#s2#e201#true""o1.z9");
          return new StateMachineConfig("s2");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s2:
            
                      
                        switch (e) {
                          case e201:
                                
            // s2->s3 e201[o1.x1]/o1.z14
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s3#e201#o1.x1");
      
                                  if (!isInputActionCalculated(calculatedInputActions, _o1_x1)) {
  
    fireBeforeInputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.x1");

          o1_x1 = o1.x1(context);
    
      fireAfterInputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.x1"new Boolean(o1_x1));
      }          
              
              
      
                        if (o1_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s3#e201#o1.x1");
  
        fireBeforeOutputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.z14");

        o1.z14(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.z14");
    
  fireComeToState(context, path, "s3");
  
  // s3 [o1.z1]
        fireBeforeOutputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.z1");

        o1.z1(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s3#e201#o1.x1""o1.z1");
          return new StateMachineConfig("s3");

                  }
                        // s2->s2 e201[!o1.x1]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e201#!o1.x1");
      
                          
              
      
                        if (!o1_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s2#e201#!o1.x1");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 [o1.z9]
        fireBeforeOutputActionExecution(context, path, "s2#s2#e201#!o1.x1""o1.z9");

        o1.z9(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s2#e201#!o1.x1""o1.z9");
          return new StateMachineConfig("s2");

                  }
                                
                    // transition not found
                return config;
                                    default:
                            
              
                    // transition not found
                return config;
                        }
            
                                  default:
          throw new EventProcessorException("Incorrect stable state [" + config.getActiveState() "] in state machine [A2]");
      }
    }
  }

        //o1.x1
        private static final int _o1_x1 = 0;
      //o1.x2
        private static final int _o1_x2 = 1;
          
}
      







private class A1EventProcessor {

    // states
      private static final int Top = 1;
      private static final int s1 = 2;
      private static final int s2 = 3;
  
  private int decodeState(String state) {
          
    if ("Top".equals(state)) {
      return Top;
            else 
        
    if ("s1".equals(state)) {
      return s1;
            else 
        
    if ("s2".equals(state)) {
      return s2;
      }
    
    return -1;
  }
  
    // events
      private static final int e011 = 1;
      private static final int e022 = 2;
      private static final int e012 = 3;
      private static final int e021 = 4;
  
  private int decodeEvent(String event) {
          
    if ("e011".equals(event)) {
      return e011;
            else 
        
    if ("e022".equals(event)) {
      return e022;
            else 
        
    if ("e012".equals(event)) {
      return e012;
            else 
        
    if ("e021".equals(event)) {
      return e021;
        }
  
    return -1;
  }
    
              private svet.co.TrafficEngine o2;
                    
  private void init(ControlledObjectsMap controlledObjectsMap) {
                  o2 = (svet.co.TrafficEngine)controlledObjectsMap.getControlledObject("o2");
                                }
    
  private StateMachineConfig process(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    config = lookForTransition(event, context, path, config);
    
    config = transiteToStableState(context, path, config);
    
    // execute included state machines
    executeSubmachines(event, context, path, config);
    
    return config;
  }
  
  private void executeSubmachines(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    int state = decodeState(config.getActiveState());
    
    while (true) {
    switch (state) {
                                      case s1: 
          
                      return;
                                          case s2: 
                                          // s2 includes A2
  
  fireBeforeSubmachineExecution(context, event, path, "s2""A2");
  
  Model1EventProcessor.this.process(event, context, new StateMachinePath(path,
    "s2""A2"));

    fireAfterSubmachineExecution(context, event, path, "s2""A2");
                                // s2 includes A3
  
  fireBeforeSubmachineExecution(context, event, path, "s2""A3");
  
  Model1EventProcessor.this.process(event, context, new StateMachinePath(path,
    "s2""A3"));

    fireAfterSubmachineExecution(context, event, path, "s2""A3");
                        
                      return;
                                default:
          throw new EventProcessorException("State with name [" + config.getActiveState() "] is unknown for state machine [A1]");
    }
    }
  }
  
  private StateMachineConfig transiteToStableState(StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {

    int s = decodeState(config.getActiveState());
    Event event;

    switch (s) {
                  case Top:
          
                    
          fireComeToState(context, path, "s1");

          // s1->s2 [true]/
          event = Event.NO_EVENT;
            fireTransitionFound(context, path, "s1", event, "s1#s2##true");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 []
            
                      return new StateMachineConfig("s2");
                                            }
  
    return config;
  }    
  
  private StateMachineConfig lookForTransition(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
          
    
      boolean
                
      o2_x1 = false
        ;
        
    
  
        BitSet calculatedInputActions = new BitSet(1);
    
    int s = decodeState(config.getActiveState());
    int e = decodeEvent(event.getName());
  
    while (true) {
      switch (s) {
                                                    case s2:
            
                      
                        switch (e) {
                          case e011:
                                
            // s2->s2 e011[!o2.x1]/o2.z011
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e011#!o2.x1");
      
                                  if (!isInputActionCalculated(calculatedInputActions, _o2_x1)) {
  
    fireBeforeInputActionExecution(context, path, "s2#s2#e011#!o2.x1""o2.x1");

          o2_x1 = o2.x1(context);
    
      fireAfterInputActionExecution(context, path, "s2#s2#e011#!o2.x1""o2.x1"new Boolean(o2_x1));
      }          
              
              
      
                        if (!o2_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s2#e011#!o2.x1");
  
        fireBeforeOutputActionExecution(context, path, "s2#s2#e011#!o2.x1""o2.z011");

        o2.z011(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s2#e011#!o2.x1""o2.z011");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                  }
                        // s2->s2 e011[o2.x1]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e011#o2.x1");
      
                          
              
      
                        if (o2_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s2#e011#o2.x1");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                  }
                                
                    // transition not found
                return config;
                                      case e022:
                                
            // s2->s2 e022[true]/o2.z022
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e022#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s2", event, "s2#s2#e022#true");
  
        fireBeforeOutputActionExecution(context, path, "s2#s2#e022#true""o2.z022");

        o2.z022(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s2#e022#true""o2.z022");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                                        
                            case e012:
                                
            // s2->s2 e012[!o2.x1]/o2.z012
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e012#!o2.x1");
      
                                  if (!isInputActionCalculated(calculatedInputActions, _o2_x1)) {
  
    fireBeforeInputActionExecution(context, path, "s2#s2#e012#!o2.x1""o2.x1");

          o2_x1 = o2.x1(context);
    
      fireAfterInputActionExecution(context, path, "s2#s2#e012#!o2.x1""o2.x1"new Boolean(o2_x1));
      }          
              
              
      
                        if (!o2_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s2#e012#!o2.x1");
  
        fireBeforeOutputActionExecution(context, path, "s2#s2#e012#!o2.x1""o2.z012");

        o2.z012(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s2#e012#!o2.x1""o2.z012");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                  }
                        // s2->s2 e012[o2.x1]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e012#o2.x1");
      
                          
              
      
                        if (o2_x1) {
        
          fireTransitionFound(context, path, "s2", event, "s2#s2#e012#o2.x1");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                  }
                                
                    // transition not found
                return config;
                                      case e021:
                                
            // s2->s2 e021[true]/o2.z021
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#e021#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s2", event, "s2#s2#e021#true");
  
        fireBeforeOutputActionExecution(context, path, "s2#s2#e021#true""o2.z021");

        o2.z021(context);
    
  fireAfterOutputActionExecution(context, path, "s2#s2#e021#true""o2.z021");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                                        
                          default:
                            
            // s2->s2 *[true]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s2#*#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s2", event, "s2#s2#*#true");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                                        
              }
            
                                  default:
          throw new EventProcessorException("Incorrect stable state [" + config.getActiveState() "] in state machine [A1]");
      }
    }
  }

        //o2.x1
        private static final int _o2_x1 = 0;
          
}
      







private class A3EventProcessor {

    // states
      private static final int Top = 1;
      private static final int s3 = 2;
      private static final int s2 = 3;
      private static final int s5 = 4;
      private static final int s1 = 5;
  
  private int decodeState(String state) {
          
    if ("Top".equals(state)) {
      return Top;
            else 
        
    if ("s3".equals(state)) {
      return s3;
            else 
        
    if ("s2".equals(state)) {
      return s2;
            else 
        
    if ("s5".equals(state)) {
      return s5;
            else 
        
    if ("s1".equals(state)) {
      return s1;
      }
    
    return -1;
  }
  
    // events
      private static final int e06 = 1;
      private static final int e04 = 2;
      private static final int e301 = 3;
      private static final int e03 = 4;
      private static final int e05 = 5;
      private static final int e07 = 6;
  
  private int decodeEvent(String event) {
          
    if ("e06".equals(event)) {
      return e06;
            else 
        
    if ("e04".equals(event)) {
      return e04;
            else 
        
    if ("e301".equals(event)) {
      return e301;
            else 
        
    if ("e03".equals(event)) {
      return e03;
            else 
        
    if ("e05".equals(event)) {
      return e05;
            else 
        
    if ("e07".equals(event)) {
      return e07;
        }
  
    return -1;
  }
    
              private svet.co.TrafficEngine o2;
        
  private void init(ControlledObjectsMap controlledObjectsMap) {
                  o2 = (svet.co.TrafficEngine)controlledObjectsMap.getControlledObject("o2");
            }
    
  private StateMachineConfig process(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    config = lookForTransition(event, context, path, config);
    
    config = transiteToStableState(context, path, config);
    
    // execute included state machines
    executeSubmachines(event, context, path, config);
    
    return config;
  }
  
  private void executeSubmachines(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
    int state = decodeState(config.getActiveState());
    
    while (true) {
    switch (state) {
                                      case s3: 
          
                      return;
                                          case s2: 
          
                      return;
                                          case s5: 
          
                      return;
                                          case s1: 
          
                      return;
                                default:
          throw new EventProcessorException("State with name [" + config.getActiveState() "] is unknown for state machine [A3]");
    }
    }
  }
  
  private StateMachineConfig transiteToStableState(StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {

    int s = decodeState(config.getActiveState());
    Event event;

    switch (s) {
                  case Top:
          
                    
          fireComeToState(context, path, "s1");

          // s1->s2 [true]/
          event = Event.NO_EVENT;
            fireTransitionFound(context, path, "s1", event, "s1#s2##true");
  
    
  fireComeToState(context, path, "s2");
  
  // s2 []
            
                      return new StateMachineConfig("s2");
                                                                }
  
    return config;
  }    
  
  private StateMachineConfig lookForTransition(Event event, StateMachineContext context, StateMachinePath path, StateMachineConfig configthrows Exception {
          
    
        
    
  
        BitSet calculatedInputActions = new BitSet(0);
    
    int s = decodeState(config.getActiveState());
    int e = decodeEvent(event.getName());
  
    while (true) {
      switch (s) {
                                      case s3:
            
                      
                        switch (e) {
                          case e04:
                                
            // s3->s3 e04[true]/o2.z4
      
      fireTransitionCandidate(context, path, "s3", event, "s3#s3#e04#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s3", event, "s3#s3#e04#true");
  
        fireBeforeOutputActionExecution(context, path, "s3#s3#e04#true""o2.z4");

        o2.z4(context);
    
  fireAfterOutputActionExecution(context, path, "s3#s3#e04#true""o2.z4");
    
  fireComeToState(context, path, "s3");
  
  // s3 []
          return new StateMachineConfig("s3");

                                        
                            case e301:
                                
            // s3->s3 e301[true]/o2.z3
      
      fireTransitionCandidate(context, path, "s3", event, "s3#s3#e301#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s3", event, "s3#s3#e301#true");
  
        fireBeforeOutputActionExecution(context, path, "s3#s3#e301#true""o2.z3");

        o2.z3(context);
    
  fireAfterOutputActionExecution(context, path, "s3#s3#e301#true""o2.z3");
    
  fireComeToState(context, path, "s3");
  
  // s3 []
          return new StateMachineConfig("s3");

                                        
                            case e07:
                                
            // s3->s2 e07[true]/o2.z6
      
      fireTransitionCandidate(context, path, "s3", event, "s3#s2#e07#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s3", event, "s3#s2#e07#true");
  
        fireBeforeOutputActionExecution(context, path, "s3#s2#e07#true""o2.z6");

        o2.z6(context);
    
  fireAfterOutputActionExecution(context, path, "s3#s2#e07#true""o2.z6");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s2:
            
                      
                        switch (e) {
                          case e03:
                                
            // s2->s3 e03[true]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s3#e03#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s2", event, "s2#s3#e03#true");
  
    
  fireComeToState(context, path, "s3");
  
  // s3 []
          return new StateMachineConfig("s3");

                                        
                            case e05:
                                
            // s2->s5 e05[true]/
      
      fireTransitionCandidate(context, path, "s2", event, "s2#s5#e05#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s2", event, "s2#s5#e05#true");
  
    
  fireComeToState(context, path, "s5");
  
  // s5 []
          return new StateMachineConfig("s5");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                            case s5:
            
                      
                        switch (e) {
                          case e06:
                                
            // s5->s5 e06[true]/o2.z9
      
      fireTransitionCandidate(context, path, "s5", event, "s5#s5#e06#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s5", event, "s5#s5#e06#true");
  
        fireBeforeOutputActionExecution(context, path, "s5#s5#e06#true""o2.z9");

        o2.z9(context);
    
  fireAfterOutputActionExecution(context, path, "s5#s5#e06#true""o2.z9");
    
  fireComeToState(context, path, "s5");
  
  // s5 []
          return new StateMachineConfig("s5");

                                        
                            case e301:
                                
            // s5->s5 e301[true]/o2.z8
      
      fireTransitionCandidate(context, path, "s5", event, "s5#s5#e301#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s5", event, "s5#s5#e301#true");
  
        fireBeforeOutputActionExecution(context, path, "s5#s5#e301#true""o2.z8");

        o2.z8(context);
    
  fireAfterOutputActionExecution(context, path, "s5#s5#e301#true""o2.z8");
    
  fireComeToState(context, path, "s5");
  
  // s5 []
          return new StateMachineConfig("s5");

                                        
                            case e07:
                                
            // s5->s2 e07[true]/o2.z10
      
      fireTransitionCandidate(context, path, "s5", event, "s5#s2#e07#true");
      
            
              
      
              
          fireTransitionFound(context, path, "s5", event, "s5#s2#e07#true");
  
        fireBeforeOutputActionExecution(context, path, "s5#s2#e07#true""o2.z10");

        o2.z10(context);
    
  fireAfterOutputActionExecution(context, path, "s5#s2#e07#true""o2.z10");
    
  fireComeToState(context, path, "s2");
  
  // s2 []
          return new StateMachineConfig("s2");

                                        
                          default:
                            
              
                    // transition not found
                return config;
                        }
            
                                                default:
          throw new EventProcessorException("Incorrect stable state [" + config.getActiveState() "] in state machine [A3]");
      }
    }
  }

            
}
  
  private static boolean isInputActionCalculated(BitSet calculatedInputActions, int k) {
    boolean b = calculatedInputActions.get(k);
            
        if (!b) {
      calculatedInputActions.set(k);
    }
            
        return b;
  }
  
}