Commit e183ca6e by amir

first

parent 2a178998
Pipeline #75 skipped in 0 seconds
/build/
/bin/
.gradle
.settings
.idea
.lck
.project
.classpath
gradle/
group 'com.ipgallery.common'
version '1.0.0'
apply plugin: 'java'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
repositories {
//mavenCentral()
maven { url "http://172.16.1.132:8081/repository/internal" }
}
dependencies {
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.3'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
publishing {
publications {
repositories.maven {
url 'http://172.16.1.132:8081/repository/internal'
credentials {
username "admin"
password "giptmgr1"
}
}
mavenJava(MavenPublication) {
//artifactId 'group-service'
from components.java
}
}
}
\ No newline at end of file
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
rootProject.name = 'seh'
package seh.SEH;
import java.lang.invoke.CallSite;
import java.lang.reflect.Method;
import seh.Types.RetStatSupplier;
/**
* this is the interface of all the classes
* that use the GenericSEH engine
* @author amir
*
*/
public interface BaseSEH
{
public Method resolveAction(String actionName);
public int resolveEvent(String eventName);
public String resolveEventName(int event);
public SEHParam getNewSEHParam();
public void setAppData(Object appData);
public RetStatSupplier invokeFunc(CallSite callSite, SEHParam sehParam) throws Throwable;
}
package seh.SEH;
public class Constants
{
public static final int C_NO_ENTRY = -1;
public static final int C_MAX_SEH_STATE_NAME_LEN = 256;
public static final int C_MAX_SEH_CALL_FLOW_FILE_NAME_LEN = 128;
public static final int C_MAX_SEH_EVENT_NAME_LEN = 128;
public static final int C_MAX_SEH_FULL_EVENT_NAME_LEN = 128;
public static final int C_MAX_SEH_FULL_ACTION_NAME = 128;
public static final int C_MAX_SEH_ERROR_MSG = 256;
public static final int C_ACTION_PARAMS_LEN = 6;
public static final int C_ACTION_PRIORITY_LEN = 8;
public static final int C_ACTION_PRIORITY_MANDATORY_LEN = 9;
public static final int C_ACTION_PRIORITY_CRITICAL_LEN = 8;
public static final String C_ACTION_PARAMS ="Params";
public static final String C_ACTION_PRIORITY = "Priority";
public static final String C_ACTION_PRIORITY_MANDATORY = "Mandatory";
public static final String C_ACTION_PRIORITY_CRITICAL = "Critical";
public static final String C_BASE_STATE = "BaseState";
public static final String C_NAME = "Name";
public static final String C_NEXT_STATE = "NextState";
public static final String C_WRONG_SEH_STATE = "Wrong State";
public static final String C_PARAM_COND_ATTRIBUTE = "Cond";
public static final String C_NULL_STATE = "NULL";
public static final String C_STATES = "States";
public static final String C_EVENTS = "Events";
public static final String C_ACTIONS = "Actions";
public static final String C_TYPE = "Type";
public static final String C_IF_THEN = "Then";
public static final String C_IF_ELSE = "Else";
public static final String C_CASES = "Cases";
}
package seh.SEH;
/**
* all the enums are here
* @author amir
*
*/
public class Enums
{
public enum EnumRetStat
{
E_FAIL,
E_SUCCESS
}
public enum EnumsEventActionType
{
E_ActionType_Regular("Action"),
E_ActionType_If("If"),
E_ActionType_While("While"),
E_ActionType_Switch("Switch");
private String name;
private EnumsEventActionType(String type)
{
name = type;
}
public String getName() { return name; }
public static EnumsEventActionType create(String type)
{
for ( EnumsEventActionType eventType : EnumsEventActionType.values()) {
if (eventType.getName().equals(type))
return eventType;
}
return null;
}
};
}
package seh.SEH;
import seh.Types.CallFlow;
import seh.Types.RetStat;
public interface ICallFlowBuilder {
RetStat buildFlowTableFromFile(String flowFileName, CallFlow callFlow,BaseSEH baseSEHObject);
RetStat buildFlowTableFromString(String flowFSM, CallFlow callFlow,BaseSEH baseSEHObject);
}
package seh.SEH;
/**
* interface for the parameter passed to the action method
* @author amir
*
*/
public interface SEHParam
{
void SetParam(String name, String value);
}
package seh.Types;
import seh.SEH.BaseSEH;
/**
* Data needed to activate the actions and move to the next state
*/
public class ActivateActionData
{
public BaseSEH object;
public StateIndex nextStateIndex;
public boolean boolWasStateChanged; // if true means that the called object
// change the state - moved to the next
// state
}
\ No newline at end of file
package seh.Types;
import seh.SEH.BaseSEH;
/**
* a complete call flow (FSM) file with all its states
*
* @author amir
*
*/
public class CallFlow
{
public int flowIndex = 0;
public State[] stateArray;
public int iNumOfStates;
public String flowFileName;
public BaseSEH baseSEHObject = null;
public void Reset()
{
flowIndex = 0;
stateArray = null;
flowFileName = null;
iNumOfStates = 0;
baseSEHObject = null;
}
public String GetFlowFileName()
{
return flowFileName;
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
import seh.SEH.SEHEngine;
import seh.SEH.Enums.EnumRetStat;
/**
* contains basic handling for activating complex actions
*
* @author amir
*
*/
public class ComplexEventAction extends EventAction
{
Logger logger = Logger.getLogger(getClass().getName());
/**
*
*/
public ComplexEventAction() {
super();
}
RetStat retStat = new RetStat(EnumRetStat.E_SUCCESS, 0, null);
public RetStat ActivateActions(EventData eventData,
ActivateActionData activateActionData, Boolean bMoveToNextState)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
int iNumOfActions = eventData.getNumOfActions();
for (EventAction eventAction : eventData.listActions)
{
/*
* activating the action
*/
retStat = (RetStat) eventAction.action.invoke(
activateActionData.object, eventAction.param);
if (retStat.enumRetStat.equals(EnumRetStat.E_FAIL))
{
logger.severe("ComplexEventAction::ActivateActions-\tFailed in Action");
break;
}
}
/******************************************
* check whether to move to the next state
******************************************/
if (bMoveToNextState)
{
if (iNumOfActions > 0)
{
if (eventData.isNextStateValid())
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex.uiStateFlowIndex = eventData.nextState.stateIndex.uiStateFlowIndex;
activateActionData.nextStateIndex.uiStateIndex = eventData.nextState.stateIndex.uiStateIndex;
logger.info("SEHEngine-\tChanging to State: "
+ eventData.nextState.stateName);
} else
{
activateActionData.boolWasStateChanged = false;
}
} else
{
retStat.enumRetStat = EnumRetStat.E_FAIL;
return retStat;
}
}
retStat.enumRetStat = EnumRetStat.E_SUCCESS;
return retStat;
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
import seh.SEH.SEHEngine;
import seh.SEH.Enums.EnumRetStat;
/**
* same as {@link ComplexEventAction} but for value actions
*
* @author amir
*
*/
public class ComplexValueEventAction extends EventAction
{
/**
*
*/
Logger logger = Logger.getLogger(getClass().getName());
/**
* @param sehEngine
*/
public ComplexValueEventAction() {
super();
}
RetStat retStat = new RetStat(EnumRetStat.E_SUCCESS, 0, null);
public RetStat ActivateActions(EventData eventData,
ActivateActionData activateActionData, Boolean bMoveToNextState)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
int iNumOfActions = eventData.getNumOfActions();
for (EventAction eventAction : eventData.listActions)
{
retStat = (RetStat) eventAction.action.invoke(
activateActionData.object, eventAction.param);
if (retStat.enumRetStat.equals(EnumRetStat.E_FAIL))
{
logger.severe("ComplexValueEventAction::ActivateActions-\tFailed in Action");
break;
}
}
/******************************************
* check whether to move to the next state
******************************************/
if (bMoveToNextState)
{
if (iNumOfActions > 0)
{
if (eventData.isNextStateValid())
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex.uiStateFlowIndex = eventData.nextState.stateIndex.uiStateFlowIndex;
activateActionData.nextStateIndex.uiStateIndex = eventData.nextState.stateIndex.uiStateIndex;
logger.info("SEHEngine-\tChanging to State: "
+ eventData.nextState.stateName);
} else
{
activateActionData.boolWasStateChanged = false;
}
} else
{
retStat.enumRetStat = EnumRetStat.E_FAIL;
return retStat;
}
}
retStat.enumRetStat = EnumRetStat.E_SUCCESS;
return retStat;
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import seh.SEH.SEHParam;
import seh.SEH.Enums.EnumsEventActionType;
/**
* contains the data for the action such as the Method (function pointer),
* the param to pass to the method is this a mandatory action or critical.
* This is also a base class for other complex actions
*
* @author amir
*
*/
public class EventAction
{
public RetStatSupplier actionFunc;
public Method action;
public SEHParam param;
public EnumsEventActionType actionType;
public boolean bIsMandatory = false; // mandatory means that it have to be
// execute , even if the former action
// failed
public boolean bIsCritical = false; // Critical means that if this action
// failes then none of the following
// actions should be
// executed, unless they have 'mandatory' attribute
public EventAction()
{
actionType = EnumsEventActionType.E_ActionType_Regular;
}
public void Reset()
{
action = null;
param = null;
bIsMandatory = false;
bIsCritical = false;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
@Override
public Object clone() throws CloneNotSupportedException
{
EventAction eventAction = new EventAction();
eventAction.action = this.action;
if (this.param != null)
{
eventAction.param = this.param;
}
return eventAction;
}
public EnumsEventActionType getActionType()
{
return actionType;
}
/**
* activating the action
*
* @param activateActionData
* @return
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public RetStat ActivateAction(ActivateActionData activateActionData)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
activateActionData.boolWasStateChanged = false;
if (this.actionFunc != null)
return actionFunc.call();
else // backward support for xml callflow builder
return (RetStat) this.action.invoke(activateActionData.object, param);
}
public boolean isActionMandatory()
{
return bIsMandatory;
}
public boolean isActionCritical()
{
return bIsCritical;
}
}
\ No newline at end of file
package seh.Types;
import java.util.LinkedList;
import java.util.List;
/**
* Contains the event data: the list of actions to activate, the next state
* and the event name
*
* @author amir
*
*/
public class EventData
{
// vector < tEventAction*> ta_Actions;
// test - amir
public List<EventAction> listActions = new LinkedList<EventAction>();
public NextState nextState = new NextState();
public String eventName;
public void Reset()
{
listActions.clear();
nextState.Reset();
eventName = null;
}
public int getNumOfActions()
{
return listActions.size();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
@Override
public Object clone() throws CloneNotSupportedException
{
EventData ed = new EventData();
ed.listActions.addAll(this.listActions);
ed.nextState = (NextState) this.nextState.clone();
ed.eventName = new String(this.eventName);
return ed;
}
public void AddAction(EventAction action)
{
listActions.add(action);
}
public boolean isEmpty()
{
return (listActions.size() == 0); /* ta_Actions.empty(); */
}
public boolean isNextStateValid()
{
return nextState.IsValid();
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import seh.SEH.Enums.EnumRetStat;
import seh.SEH.Enums.EnumsEventActionType;
/**
* implements If/Else event actions
*
* @author amir
*
*/
public class EventIfAction extends ComplexEventAction
{
public EventData trueActions;
public EventData falseActions;
public EventIfAction()
{
super();
this.actionType = EnumsEventActionType.E_ActionType_If;
trueActions = new EventData();
falseActions = new EventData();
}
public void Reset()
{
super.Reset();
trueActions.Reset();
falseActions.Reset();
}
@Override
public RetStat ActivateAction(ActivateActionData activateActionData)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
/***********************************
* Activating the Condition action
**********************************/
retStat = (RetStat) this.action.invoke(activateActionData.object,
this.param);
if (retStat.enumRetStat.equals(EnumRetStat.E_SUCCESS))
return ActivateActions(trueActions, activateActionData, true);
else
return ActivateActions(falseActions, activateActionData, true);
}
/*
* (non-Javadoc)
*
* @see SEH.SEHEngine.EventAction#clone()
*/
@Override
public Object clone() throws CloneNotSupportedException
{
// TODO Auto-generated method stub
EventIfAction eia = (EventIfAction) super.clone();
eia.trueActions = (EventData) this.trueActions.clone();
eia.falseActions = (EventData) this.falseActions.clone();
return eia;
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import seh.SEH.SEHEngine;
import seh.SEH.Enums.EnumRetStat;
import seh.SEH.Enums.EnumsEventActionType;
/**
* implements switch case event actions the case is of numbers e.g:<br />
* switch (action)<br />
* {<br />
* case 1:<br />
* &nbsp;&nbsp;break;<br />
* case 2:<br />
* &nbsp;&nbsp;break;<br />
* }
*
* @author amir
*
*/
public class EventSwitchAction extends ComplexValueEventAction
{
Logger logger = Logger.getLogger(getClass().getName());
/**
*
*/
public List<EventData> switchActions = new ArrayList<EventData>();
public EventSwitchAction()
{
this.actionType = EnumsEventActionType.E_ActionType_Switch;
}
public void Reset()
{
super.Reset();
switchActions.clear();
}
@Override
public RetStat ActivateAction(ActivateActionData activateActionData)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
EventData eventData;
/*
* activating the switch condition action
*/
retStat = (RetStat) this.action.invoke(activateActionData.object,
this.param);
if (retStat.enumRetStat.equals(EnumRetStat.E_FAIL))
return retStat;
/************************************************************
* Activating the appropriate case according to the ret_code
***********************************************************/
if (retStat.retCode < switchActions.size())
{
eventData = switchActions.get(retStat.retCode);
retStat = (RetStat) ActivateActions(eventData,
activateActionData, true);
if (retStat.enumRetStat.equals(EnumRetStat.E_FAIL))
return retStat;
} else
{
logger.severe("SEHEngine::EventSwitchAction::ActivateAction-\tReturn value is bigger the num of switch cases");
retStat.enumRetStat = EnumRetStat.E_FAIL;
return retStat;
}
/******************************************
* check whether to move to the next state
******************************************/
if (eventData.isNextStateValid())
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex.uiStateFlowIndex = eventData.nextState.stateIndex.uiStateFlowIndex;
activateActionData.nextStateIndex.uiStateIndex = eventData.nextState.stateIndex.uiStateIndex;
logger.info("SEHEngine-\tChanging to State: "
+ eventData.nextState.stateName);
} else
{
activateActionData.boolWasStateChanged = false;
}
retStat.enumRetStat = EnumRetStat.E_SUCCESS;
return retStat;
}
/*
* (non-Javadoc)
*
* @see SEH.SEHEngine.EventAction#clone()
*/
@Override
public Object clone() throws CloneNotSupportedException
{
EventSwitchAction esa = (EventSwitchAction) super.clone();
esa.switchActions.addAll(switchActions);
return esa;
}
}
\ No newline at end of file
package seh.Types;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Logger;
import seh.SEH.Enums.EnumRetStat;
import seh.SEH.Enums.EnumsEventActionType;
/**
* implements while event actions
*
* @author amir
*
*/
public class EventWhileAction extends ComplexEventAction
{
Logger logger = Logger.getLogger(getClass().getName());
/**
*
*/
public EventData whileActions;
public EventWhileAction()
{
super();
this.actionType = EnumsEventActionType.E_ActionType_While;
}
public void Reset()
{
super.Reset();
whileActions.Reset();
}
@Override
public RetStat ActivateAction(ActivateActionData activateActionData)
throws IllegalArgumentException, IllegalAccessException,
InvocationTargetException
{
/*
* activating the while condition if success then activating the
* while actions
*/
while (((RetStat) this.action.invoke(activateActionData.object,
this.param)).enumRetStat.equals(EnumRetStat.E_SUCCESS))
{
retStat = (RetStat) ActivateActions(whileActions,
activateActionData, true);
if (retStat.enumRetStat.equals(EnumRetStat.E_FAIL))
return retStat;
}
/******************************************
* check whether to move to the next state
******************************************/
if (whileActions.isNextStateValid())
{
activateActionData.boolWasStateChanged = true;
activateActionData.nextStateIndex.uiStateFlowIndex = whileActions.nextState.stateIndex.uiStateFlowIndex;
activateActionData.nextStateIndex.uiStateIndex = whileActions.nextState.stateIndex.uiStateIndex;
logger.info("SEHEngine-\tChanging to State: "
+ whileActions.nextState.stateName);
} else
{
activateActionData.boolWasStateChanged = false;
}
retStat.enumRetStat = EnumRetStat.E_SUCCESS;
return retStat;
}
/*
* (non-Javadoc)
*
* @see SEH.SEHEngine.EventAction#clone()
*/
@Override
public Object clone() throws CloneNotSupportedException
{
EventWhileAction ewa = (EventWhileAction) super.clone();
ewa.whileActions = this.whileActions;
return ewa;
}
}
\ No newline at end of file
package seh.Types;
/**
* data for the next state
*
* @author amir
*
*/
public class NextState
{
public StateIndex stateIndex = new StateIndex();
public String stateName = null;
public void Reset()
{
stateIndex.Reset();
stateName = null;
}
@Override
public Object clone() throws CloneNotSupportedException
{
NextState ns = new NextState();
ns.stateName = new String(stateName);
return ns;
}
public boolean IsValid()
{
return stateName != null;
}
public String getStateName() {
return stateName;
}
public void setStateName(String stateName) {
this.stateName = stateName;
}
}
\ No newline at end of file
package seh.Types;
import seh.SEH.Enums.EnumRetStat;
public class RetStat
{
public EnumRetStat enumRetStat;
public int retCode;
public String errorText;
public RetStat()
{
enumRetStat = EnumRetStat.E_SUCCESS;
retCode = 0;
errorText = null;
}
public RetStat(EnumRetStat eRetStat, int retCode,String errorText)
{
this.enumRetStat = eRetStat;
this.retCode = retCode;
this.errorText = errorText;
}
public void setSuccess() { enumRetStat = EnumRetStat.E_SUCCESS; }
public void setFail() { enumRetStat = EnumRetStat.E_FAIL; }
public void setFail(String error)
{
enumRetStat = EnumRetStat.E_FAIL;
errorText = new String(error);
}
public void setError(String error)
{
errorText = new String(error);
}
public boolean isSuccess() { return enumRetStat.equals(EnumRetStat.E_SUCCESS); }
public boolean isFail() { return enumRetStat.equals(EnumRetStat.E_FAIL); }
public String getError() { return errorText; }
}
package seh.Types;
@FunctionalInterface
public interface RetStatSupplier {
RetStat call();
}
package seh.Types;
import java.util.HashMap;
import java.util.Map;
/**
* holds that data structure for a State in the xml FSM
*
* @author amir
*
*/
public class State
{
public Map<String,EventData> eventsMap;
public String stateName;
public NextState baseState; // the base state for this state (optional)
public State()
{
Reset();
eventsMap = new HashMap<String,EventData>();
}
public void Reset()
{
eventsMap = null;
stateName = null;
baseState = null;
}
}
\ No newline at end of file
package seh.Types;
import seh.SEH.Constants;
public class StateIndex
{
public int uiStateIndex;
public int uiStateFlowIndex;
public StateIndex()
{
}
public StateIndex(int uiStateIndex,int uiFlowIndex)
{
this.uiStateIndex = uiStateIndex;
this.uiStateFlowIndex = uiFlowIndex;
}
public void Reset()
{
uiStateIndex = Constants.C_NO_ENTRY;
uiStateFlowIndex = Constants.C_NO_ENTRY;
}
public boolean isValid()
{
return (uiStateIndex != Constants.C_NO_ENTRY &&
uiStateFlowIndex != Constants.C_NO_ENTRY);
}
}
package seh.Util;
import java.io.File;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class XMLTree
{
public TreeModel parse(String filename) {
SAXParserFactory factory = SAXParserFactory.newInstance();
XMLTreeHandler handler = new XMLTreeHandler();
try {
// Parse the input.
SAXParser saxParser = factory.newSAXParser();
saxParser.parse(new File(filename), handler);
} catch (Exception e) {
System.err.println("File Read Error: " + e);
e.printStackTrace();
return new DefaultTreeModel(new DefaultMutableTreeNode("error"));
}
return new DefaultTreeModel(handler.getRoot());
}
public static class XMLTreeHandler extends DefaultHandler {
private DefaultMutableTreeNode root, currentNode;
public DefaultMutableTreeNode getRoot() {
return root;
}
// SAX Parser Handler methods...
public void startElement(String namespaceURI, String lName,
String qName, Attributes attrs) throws SAXException {
String eName = lName; // Element name
if ("".equals(eName))
eName = qName;
Tag t = new Tag(eName, attrs);
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(t);
if (currentNode == null) {
root = newNode;
} else {
// Must not be the root node...
currentNode.add(newNode);
}
currentNode = newNode;
}
public void endElement(String namespaceURI, String sName, String qName)
throws SAXException {
currentNode = (DefaultMutableTreeNode) currentNode.getParent();
}
public void characters(char buf[], int offset, int len)
throws SAXException {
String s = new String(buf, offset, len).trim();
((Tag) currentNode.getUserObject()).addData(s);
}
}
public static class Tag {
private String name;
private String data;
private Attributes attr;
public Tag(String n, Attributes a) {
name = n;
attr = a;
}
public String getName() {
return name;
}
public Attributes getAttributes() {
return attr;
}
public void setData(String d) {
data = d;
}
public String getData() {
return data;
}
public void addData(String d) {
if (data == null) {
setData(d);
} else {
data += d;
}
}
public String getAttributesAsString() {
StringBuffer buf = new StringBuffer(256);
for (int i = 0; i < attr.getLength(); i++) {
buf.append(attr.getQName(i));
buf.append("=\"");
buf.append(attr.getValue(i));
buf.append("\"");
}
return buf.toString();
}
public String toString() {
String a = getAttributesAsString();
return name + ": " + a + (data == null ? "" : " (" + data + ")");
}
}
// public static void main(String args[]) {
// JFrame frame = new JFrame("VSX Test");
// VSX parser = new VSX();
// JTree tree = new JTree(parser.parse("build.xml"));
// frame.getContentPane().add(new JScrollPane(tree));
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setSize(300, 400);
// frame.setVisible(true);
// }
}
package seh;
import java.lang.invoke.CallSite;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import org.junit.Test;
import seh.SEH.BaseSEH;
import seh.SEH.SEHEngine;
import seh.SEH.SEHParam;
import seh.Types.RetStat;
import seh.Types.RetStatSupplier;
import seh.Types.StateIndex;
public class TestSEH implements seh.SEH.BaseSEH
{
private Logger logger = Logger.getLogger(getClass().getName());
public class TestSEHParam implements seh.SEH.SEHParam
{
int intValue = 0;
String strVal = null;
@Override
public void SetParam(String name, String value)
{
if (name.equalsIgnoreCase("TO") ||
name.equalsIgnoreCase("TDCause"))
intValue = Integer.parseInt(value);
else if (name.equalsIgnoreCase("Party") ||
name.equalsIgnoreCase("CallType"))
strVal = new String(value);
}
/**
* @return the intValue
*/
public int getIntValue()
{
return intValue;
}
/**
* @return the strVal
*/
public String getStrVal()
{
return strVal;
}
}
enum EnumEvents
{
Event1,
Event2,
Event3,
Event4
}
enum EnumSwitchValues
{
Val1,
Val2,
Val3
}
RetStat retStat = new RetStat();
@Override
public RetStatSupplier invokeFunc(CallSite callSite, SEHParam sehParam) throws Throwable {
// TODO Auto-generated method stub
return (RetStatSupplier) callSite.getTarget().invokeExact(this, sehParam);
}
@Override
public Method resolveAction(String actionName)
{
try
{
return TestSEH.class.getMethod(actionName,SEHParam.class);
} catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
@Override
public int resolveEvent(String eventName)
{
try
{
return EnumEvents.valueOf(eventName).ordinal();
}
catch (Exception e)
{
return EnumEvents.values().length; // max events
}
}
@Override
public String resolveEventName(int event)
{
try
{
return EnumEvents.values()[event].toString();
}
catch (Exception e)
{
return null;
}
}
@Override
public SEHParam getNewSEHParam()
{
return new TestSEHParam();
}
/*
* ACTIONS
*/
public RetStat SimpleAction(SEHParam param)
{
retStat.setSuccess();
logger.info("Action: \tSimpleAction");
return retStat;
}
public RetStat ActionWithParamInt(SEHParam param)
{
retStat.setSuccess();
logger.info("Action: \tActionWithParamInt: " + String.valueOf(((TestSEHParam)param).intValue));
return retStat;
}
public RetStat ActionWithParamString(SEHParam param)
{
retStat.setSuccess();
logger.info("Action: \tActionWithParamString: " + ((TestSEHParam)param).getStrVal());
return retStat;
}
public RetStat IfElseAction(SEHParam param)
{
retStat.setFail();
logger.info("Action: \tIfElseAction");
return retStat;
}
public RetStat SwitchAction(SEHParam param)
{
retStat.setSuccess();
logger.info("Action: \tSwitchAction");
retStat.retCode = EnumSwitchValues.Val1.ordinal();
return retStat;
}
@Test
public void TestEngine()
{
RetStat stat = new RetStat();
SEHEngine fsmEngine = new SEHEngine();
StateIndex state = new StateIndex();
EnumEvents event = EnumEvents.Event1;
try
{
Map<String,String> flowFilesMap = new HashMap<String, String>();
Map<String,BaseSEH> flowsSEHMap = new HashMap<String, BaseSEH>();
//flowFilesMap.put("Test", "src/test/resources/seh/TestSEH.xml");
flowFilesMap.put("Test", "src/test/resources/seh/TestSEH.json");
flowsSEHMap.put("Test", this);
stat = fsmEngine.InitMultiFlows(flowFilesMap, flowsSEHMap);
state.uiStateFlowIndex = 0;
state.uiStateIndex = 0; // idle
fsmEngine.HandleEvent(state, event.toString());
event = EnumEvents.Event3;
fsmEngine.HandleEvent(state, event.toString());
event = EnumEvents.Event2;
fsmEngine.HandleEvent(state, event.toString());
event = EnumEvents.Event2;
fsmEngine.HandleEvent(state, event.toString());
event = EnumEvents.Event4;
fsmEngine.HandleEvent(state, event.toString());
} catch (SecurityException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void setAppData(Object appData)
{
// TODO Auto-generated method stub
}
}
{
"States": [{
"Name": "Idle",
"Events": [{
"Name": "Event1",
"Actions": [{
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TO": "20"
}
}, {
"Type": "Action",
"Name": "ActionWithParamString",
"Params": {
"CallType": "IncOut"
}
}],
"NextState": "Idle_NestState1"
}, {
"Name": "Event2",
"Actions": [{
"Type": "If",
"Name": "IfElseAction",
"Then": {
"Actions": [{
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TO": "30000"
}
}, {
"Type": "Action",
"Name": "SimpleAction"
}],
"NextState": "Idle_IfThenState"
},
"Else": {
"Actions": [{
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TO": "5000"
}
}, {
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "SimpleAction"
}],
"NextState": "Idle_IfElseState"
}
}],
"NextState": "Idle_IfElseDefaultState"
}]
}, {
"Name": "Idle_NestState1",
"Events": [{
"Name": "Event3",
"Actions": [{
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Switch",
"Name": "SwitchAction",
"Cases": [{
"Val1": {
"Actions": [{
"Type": "Action",
"Name": "SimpleAction"
}, {
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TDCause": "8"
}
}, {
"Type": "Action",
"Name": "ActionWithParamString",
"Params": {
"Party": "ICP"
}
}],
"NextState": "Idle"
}
}, {
"Val2": {
"Actions": [{
"Type": "Action",
"Name": "ActionWithParamInt",
"Params": {
"TDCause": "8"
}
}, {
"Type": "Action",
"Name": "ActionWithParamString",
"Params": {
"Party": "ICP"
}
}],
"NextState": "Idle_NestState1"
}
}]
}],
"NextState": "Idle_SwitchDefaultState"
}]
}, {
"Name": "Idle_IfThenState",
"Events": [{
"Name": "Event4",
"Actions": [
{
"Type": "Action",
"Name": "SimpleAction"
}
],
"NextState": "Idle"
}]
}, {
"Name": "Idle_IfElseState",
"Events": [{
"Name": "Event4",
"Actions": [
{
"Type": "Action",
"Name": "SimpleAction"
}
],
"NextState": "Idle"
}]
}, {
"Name": "Idle_IfElseDefaultState",
"Events": [{
"Name": "Event4",
"Actions": [
{
"Type": "Action",
"Name": "SimpleAction"
}
],
"NextState": "Idle"
}]
}, {
"Name": "Idle_SwitchDefaultState",
"Events": [{
"Name": "Event4",
"Actions": [
{
"Type": "Action",
"Name": "SimpleAction"
}
],
"NextState": "Idle"
}]
}]
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<State>
<Name>Idle</Name>
<Event>
<Name>Event1</Name>
<Actions>
<Action>SimpleAction</Action>
<Action>
<Name>ActionWithParamInt</Name>
<Params>
<TO>20</TO>
</Params>
</Action>
<Action>
<Name>ActionWithParamString</Name>
<Params>
<CallType>IncOut</CallType>
</Params>
</Action>
</Actions>
<NextState>Idle_NestState1</NextState>
</Event>
<Event>
<Name>Event2</Name>
<Actions>
<If>
<Action>IfElseAction</Action>
<Then>
<Actions>
<Action>SimpleAction</Action>
<Action>
<Name>ActionWithParamInt</Name>
<Params>
<TO>30000</TO>
</Params>
</Action>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle_IfThenState</NextState>
</Then>
<Else>
<Actions>
<Action>
<Name>ActionWithParamInt</Name>
<Params>
<TO>5000</TO>
</Params>
</Action>
<Action>SimpleAction</Action>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle_IfElseState</NextState>
</Else>
</If>
</Actions>
<NextState>Idle_IfElseDefaultState</NextState>
</Event>
</State>
<State>
<Name>Idle_NestState1</Name>
<Event>
<Name>Event3</Name>
<Actions>
<Action>SimpleAction</Action>
<Action>SimpleAction</Action>
<Switch>
<Action>SwitchAction</Action>
<Case>
<Value>Val1</Value>
<Actions>
<Action>SimpleAction</Action>
<Action>
<Name>ActionWithParamInt</Name>
<Params>
<TDCause>8</TDCause><!-- SetUp TO -->
</Params>
</Action>
<Action>
<Name>ActionWithParamString</Name>
<Params>
<Party>ICP</Party>
</Params>
</Action>
</Actions>
<NextState>Idle</NextState>
</Case>
<Case>
<Value>Val2</Value>
<Actions>
<Action>
<Name>ActionWithParamInt</Name>
<Params>
<TDCause>8</TDCause><!-- SetUp TO -->
</Params>
</Action>
<Action>
<Name>ActionWithParamString</Name>
<Params>
<Party>ICP</Party>
</Params>
</Action>
</Actions>
<NextState>Idle_NestState1</NextState>
</Case>
<Case>
<Value>Val3</Value>
<Actions>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle_SwitchDefaultState</NextState>
</Case>
</Switch>
</Actions>
<NextState>Idle_SwitchDefaultState</NextState>
</Event>
</State>
<State>
<Name>Idle_IfThenState</Name>
<Event>
<Name>Event4</Name>
<Actions>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle</NextState>
</Event>
</State>
<State>
<Name>Idle_IfElseState</Name>
<Event>
<Name>Event4</Name>
<Actions>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle</NextState>
</Event>
</State>
<State>
<Name>Idle_IfElseDefaultState</Name>
<Event>
<Name>Event4</Name>
<Actions>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle</NextState>
</Event>
</State>
<State>
<Name>Idle_SwitchDefaultState</Name>
<Event>
<Name>Event4</Name>
<Actions>
<Action>SimpleAction</Action>
</Actions>
<NextState>Idle</NextState>
</Event>
</State>
</xml>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment