1. /*
  2. * @(#)Guard.java 1.7 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.spi.orbutil.fsm;
  8. /**
  9. *
  10. * @author Ken Cavanaugh
  11. */
  12. public interface Guard
  13. {
  14. public static final class Complement extends GuardBase {
  15. private Guard guard ;
  16. public Complement( GuardBase guard )
  17. {
  18. super( "not(" + guard.getName() + ")" ) ;
  19. this.guard = guard ;
  20. }
  21. public Result evaluate( FSM fsm, Input in )
  22. {
  23. return guard.evaluate( fsm, in ).complement() ;
  24. }
  25. }
  26. public static final class Result {
  27. private String name ;
  28. private Result( String name )
  29. {
  30. this.name = name ;
  31. }
  32. public static Result convert( boolean res )
  33. {
  34. return res ? ENABLED : DISABLED ;
  35. }
  36. public Result complement()
  37. {
  38. if (this == ENABLED)
  39. return DISABLED ;
  40. else if (this == DISABLED)
  41. return ENABLED ;
  42. else
  43. return DEFERED ;
  44. }
  45. public String toString()
  46. {
  47. return "Guard.Result[" + name + "]" ;
  48. }
  49. public static final Result ENABLED = new Result( "ENABLED" ) ;
  50. public static final Result DISABLED = new Result( "DISABLED" ) ;
  51. public static final Result DEFERED = new Result( "DEFERED" ) ;
  52. }
  53. /** Called by the state engine to determine whether a
  54. * transition is enabled, defered, or disabled.
  55. * The result is interpreted as follows:
  56. * <ul>
  57. * <li>ENABLED if the transition is ready to proceed
  58. * <li>DISABLED if the transition is not ready to proceed
  59. * <li>DEFERED if the action associated with the transition
  60. * is to be deferred. This means that the input will not be
  61. * acted upon, but rather it will be saved for later execution.
  62. * Typically this is implemented using a CondVar wait, and the
  63. * blocked thread represents the defered input. The defered
  64. * input is retried when the thread runs again.
  65. * </ul>
  66. *
  67. * @param FSM fsm is the state machine causing this action.
  68. * @param Input in is the input that caused the transition.
  69. */
  70. public Result evaluate( FSM fsm, Input in ) ;
  71. }
  72. // end of Action.java