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
Transition
which invokes aMethod
. TheMethod
will 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
Event
the currentEvent
will 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 theStateContext
type and will in that case be bound to the currentStateContext
.Normally you wouldn't create instances of this class directly but rather use the
Transition
annotation to define the methods which should be used as transitions in your state machine and then letStateMachineFactory
create aStateMachine
for you.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description MethodTransition(Object eventId, Object target)
MethodTransition(Object eventId, Method method, Object target)
MethodTransition(Object eventId, String methodName, Object target)
MethodTransition(Object eventId, State nextState, Object target)
MethodTransition(Object eventId, State nextState, Method method, Object target)
MethodTransition(Object eventId, State nextState, String methodName, Object target)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
doExecute(Event event)
Executes thisTransition
.boolean
equals(Object o)
Method
getMethod()
Object
getTarget()
int
hashCode()
String
toString()
-
Methods inherited from class org.apache.mina.statemachine.transition.AbstractTransition
execute, getNextState
-
-
-
-
Constructor Detail
-
MethodTransition
public MethodTransition(Object eventId, State nextState, Method method, Object target)
-
MethodTransition
public MethodTransition(Object eventId, Method method, Object target)
- Parameters:
eventId
- theEvent
id.method
- the target method.target
- the target object.
-
MethodTransition
public MethodTransition(Object eventId, State nextState, Object target)
Creates a new instance with the specifiedState
as next state and for the specifiedEvent
id. The targetMethod
will be the method in the specified target object with the same name as the specifiedEvent
id.- Parameters:
eventId
- theEvent
id.nextState
- the nextState
.target
- the target object.- Throws:
NoSuchMethodException
- if no method could be found with a name equal to theEvent
id.AmbiguousMethodException
- if more than one method was found with a name equal to theEvent
id.
-
MethodTransition
public MethodTransition(Object eventId, Object target)
Creates a new instance which will loopback to the sameState
for the specifiedEvent
id. The targetMethod
will be the method in the specified target object with the same name as the specifiedEvent
id.- Parameters:
eventId
- theEvent
id.target
- the target object.- Throws:
NoSuchMethodException
- if no method could be found with a name equal to theEvent
id.AmbiguousMethodException
- if more than one method was found with a name equal to theEvent
id.
-
MethodTransition
public MethodTransition(Object eventId, String methodName, Object target)
- Parameters:
eventId
- theEvent
id.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(Object eventId, State nextState, String methodName, Object target)
- Parameters:
eventId
- theEvent
id.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
-
getTarget
public 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:
doExecute
in classAbstractTransition
- Parameters:
event
- the currentEvent
.- Returns:
true
if theTransition
has been executed successfully and theStateMachine
should move to the nextState
.false
otherwise.
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractTransition
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractTransition
-
toString
public String toString()
- Overrides:
toString
in classAbstractTransition
-
-