org.apache.mina.statemachine.transition

## 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 a `Method`. The `Method` will only be invoked if its argument types actually matches a subset of the `Event`'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 current `Event` will be bound to that argument. In the same manner the second argument (or first if the method isn't interested in the current `Event`) can have the `StateContext` type and will in that case be bound to the current `StateContext`.

  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 let `StateMachineFactory` create a `StateMachine` for you.

  Author:
    Apache MINA Project

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `MethodTransition(Object eventId, Method method, Object target)` Creates a new instance which will loopback to the same `State` for the specified `Event` id.
    `MethodTransition(Object eventId, Object target)` Creates a new instance which will loopback to the same `State` for the specified `Event` id.
    `MethodTransition(Object eventId, State nextState, Method method, Object target)` Creates a new instance with the specified `State` as next state and for the specified `Event` id.
    `MethodTransition(Object eventId, State nextState, Object target)` Creates a new instance with the specified `State` as next state and for the specified `Event` id.
    `MethodTransition(Object eventId, State nextState, String methodName, Object target)` Creates a new instance with the specified `State` as next state and for the specified `Event` id.
    `MethodTransition(Object eventId, String methodName, Object target)` Creates a new instance which will loopback to the same `State` for the specified `Event` id.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `doExecute(Event event)` Executes this `Transition`.
    `boolean` | `equals(Object o)`
    `Method` | `getMethod()` Returns the target `Method`.
    `Object` | `getTarget()` Returns the target object.
    `int` | `hashCode()`
    `String` | `toString()`

    - ### Methods inherited from class org.apache.mina.statemachine.transition.AbstractTransition

      `execute, getNextState`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### MethodTransition

          public MethodTransition(Object eventId,
                          State nextState,
                          Method method,
                          Object target)

      Creates a new instance with the specified `State` as next state and for the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `nextState` - the next `State`.
        `method` - the target method.
        `target` - the target object.

    - #### MethodTransition

          public MethodTransition(Object eventId,
                          Method method,
                          Object target)

      Creates a new instance which will loopback to the same `State` for the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `method` - the target method.
        `target` - the target object.

    - #### MethodTransition

          public MethodTransition(Object eventId,
                          State nextState,
                          Object target)

      Creates a new instance with the specified `State` as next state and for the specified `Event` id. The target `Method` will be the method in the specified target object with the same name as the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `nextState` - the next `State`.
        `target` - the target object.
      Throws:
        `NoSuchMethodException` - if no method could be found with a name equal to the `Event` id.
        `AmbiguousMethodException` - if more than one method was found with a name equal to the `Event` id.

    - #### MethodTransition

          public MethodTransition(Object eventId,
                          Object target)

      Creates a new instance which will loopback to the same `State` for the specified `Event` id. The target `Method` will be the method in the specified target object with the same name as the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `target` - the target object.
      Throws:
        `NoSuchMethodException` - if no method could be found with a name equal to the `Event` id.
        `AmbiguousMethodException` - if more than one method was found with a name equal to the `Event` id.

    - #### MethodTransition

          public MethodTransition(Object eventId,
                          String methodName,
                          Object target)

      Creates a new instance which will loopback to the same `State` for the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `methodName` - the name of the target `Method`.
        `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)

      Creates a new instance with the specified `State` as next state and for the specified `Event` id.
      Parameters:
        `eventId` - the `Event` id.
        `nextState` - the next `State`.
        `methodName` - the name of the target `Method`.
        `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 Method getMethod()

      Returns the target `Method`.
      Returns:
        the method.

    - #### getTarget

          public Object getTarget()

      Returns the target object.
      Returns:
        the target object.

    - #### doExecute

          public boolean doExecute(Event event)

      Description copied from class: `AbstractTransition`
      Executes this `Transition`. This method doesn't have to check if the `Event`'s id matches because `AbstractTransition.execute(Event)` has already made sure that that is the case.
      Specified by:
        `doExecute` in class `AbstractTransition`
      Parameters:
        `event` - the current `Event`.
      Returns:
        `true` if the `Transition` has been executed successfully and the `StateMachine` should move to the next `State`. `false` otherwise.

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `AbstractTransition`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `AbstractTransition`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `AbstractTransition`

Copyright © 2004-2012 Apache MINA Project. All Rights Reserved.