Class MethodTransition
- java.lang.Object
-
- org.apache.mina.statemachine.transition.AbstractTransition
-
- org.apache.mina.statemachine.transition.MethodTransition
-
- All Implemented Interfaces:
Transition
public class MethodTransition extends AbstractTransition
Transitionwhich invokes aMethod. TheMethodwill only be invoked if its argument types actually matches a subset of theEvent's argument types. The argument types are matched in order so you must make sure the order of the method's arguments corresponds to the order of the event's arguments.If the first method argument type matches
Eventthe currentEventwill be bound to that argument. In the same manner the second argument (or first if the method isn't interested in the currentEvent) can have theStateContexttype and will in that case be bound to the currentStateContext.Normally you wouldn't create instances of this class directly but rather use the
Transitionannotation to define the methods which should be used as transitions in your state machine and then letStateMachineFactorycreate aStateMachinefor you.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Object[]EMPTY_ARGUMENTSprivate static org.slf4j.LoggerLOGGERprivate java.lang.reflect.Methodmethodprivate java.lang.Objecttarget
-
Constructor Summary
Constructors Constructor Description MethodTransition(java.lang.Object eventId, java.lang.Object target)MethodTransition(java.lang.Object eventId, java.lang.reflect.Method method, java.lang.Object target)MethodTransition(java.lang.Object eventId, java.lang.String methodName, java.lang.Object target)MethodTransition(java.lang.Object eventId, State nextState, java.lang.Object target)MethodTransition(java.lang.Object eventId, State nextState, java.lang.reflect.Method method, java.lang.Object target)MethodTransition(java.lang.Object eventId, State nextState, java.lang.String methodName, java.lang.Object target)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandoExecute(Event event)Executes thisTransition.booleanequals(java.lang.Object o)java.lang.reflect.MethodgetMethod()java.lang.ObjectgetTarget()inthashCode()private voidinvokeMethod(java.lang.Object[] arguments)private booleanmatch(java.lang.Class<?> paramType, java.lang.Object arg, java.lang.Class<?> argType)java.lang.StringtoString()-
Methods inherited from class org.apache.mina.statemachine.transition.AbstractTransition
execute, getNextState
-
-
-
-
Constructor Detail
-
MethodTransition
public MethodTransition(java.lang.Object eventId, State nextState, java.lang.reflect.Method method, java.lang.Object target)
-
MethodTransition
public MethodTransition(java.lang.Object eventId, java.lang.reflect.Method method, java.lang.Object target)- Parameters:
eventId- theEventid.method- the target method.target- the target object.
-
MethodTransition
public MethodTransition(java.lang.Object eventId, State nextState, java.lang.Object target)Creates a new instance with the specifiedStateas next state and for the specifiedEventid. The targetMethodwill be the method in the specified target object with the same name as the specifiedEventid.- Parameters:
eventId- theEventid.nextState- the nextState.target- the target object.- Throws:
NoSuchMethodException- if no method could be found with a name equal to theEventid.AmbiguousMethodException- if more than one method was found with a name equal to theEventid.
-
MethodTransition
public MethodTransition(java.lang.Object eventId, java.lang.Object target)Creates a new instance which will loopback to the sameStatefor the specifiedEventid. The targetMethodwill be the method in the specified target object with the same name as the specifiedEventid.- Parameters:
eventId- theEventid.target- the target object.- Throws:
NoSuchMethodException- if no method could be found with a name equal to theEventid.AmbiguousMethodException- if more than one method was found with a name equal to theEventid.
-
MethodTransition
public MethodTransition(java.lang.Object eventId, java.lang.String methodName, java.lang.Object target)- Parameters:
eventId- theEventid.methodName- the name of the targetMethod.target- the target object.- Throws:
NoSuchMethodException- if the method could not be found.AmbiguousMethodException- if there are more than one method with the specified name.
-
MethodTransition
public MethodTransition(java.lang.Object eventId, State nextState, java.lang.String methodName, java.lang.Object target)- Parameters:
eventId- theEventid.nextState- the nextState.methodName- the name of the targetMethod.target- the target object.- Throws:
NoSuchMethodException- if the method could not be found.AmbiguousMethodException- if there are more than one method with the specified name.
-
-
Method Detail
-
getMethod
public java.lang.reflect.Method getMethod()
- Returns:
- the target
Method.
-
getTarget
public java.lang.Object getTarget()
- Returns:
- the target object.
-
doExecute
public boolean doExecute(Event event)
Executes thisTransition. This method doesn't have to check if theEvent's id matches becauseAbstractTransition.execute(Event)has already made sure that that is the case.- Specified by:
doExecutein classAbstractTransition- Parameters:
event- the currentEvent.- Returns:
trueif theTransitionhas been executed successfully and theStateMachineshould move to the nextState.falseotherwise.
-
match
private boolean match(java.lang.Class<?> paramType, java.lang.Object arg, java.lang.Class<?> argType)
-
invokeMethod
private void invokeMethod(java.lang.Object[] arguments)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classAbstractTransition
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractTransition
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractTransition
-
-