KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > orbutil > fsm > Guard


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
8 package com.sun.corba.se.spi.orbutil.fsm;
9
10 /**
11  *
12  * @author Ken Cavanaugh
13  */

14 public interface Guard
15 {
16     public static final class Complement extends GuardBase {
17     private Guard guard ;
18
19     public Complement( GuardBase guard )
20     {
21         super( "not(" + guard.getName() + ")" ) ;
22         this.guard = guard ;
23     }
24
25     public Result evaluate( FSM fsm, Input in )
26     {
27         return guard.evaluate( fsm, in ).complement() ;
28     }
29     }
30
31     public static final class Result {
32     private String JavaDoc name ;
33
34     private Result( String JavaDoc name )
35     {
36         this.name = name ;
37     }
38
39     public static Result convert( boolean res )
40     {
41         return res ? ENABLED : DISABLED ;
42     }
43
44     public Result complement()
45     {
46         if (this == ENABLED)
47         return DISABLED ;
48         else if (this == DISABLED)
49         return ENABLED ;
50         else
51         return DEFERED ;
52     }
53     
54     public String JavaDoc toString()
55     {
56         return "Guard.Result[" + name + "]" ;
57     }
58
59     public static final Result ENABLED = new Result( "ENABLED" ) ;
60     public static final Result DISABLED = new Result( "DISABLED" ) ;
61     public static final Result DEFERED = new Result( "DEFERED" ) ;
62     }
63
64     /** Called by the state engine to determine whether a
65     * transition is enabled, defered, or disabled.
66     * The result is interpreted as follows:
67     * <ul>
68     * <li>ENABLED if the transition is ready to proceed
69     * <li>DISABLED if the transition is not ready to proceed
70     * <li>DEFERED if the action associated with the transition
71     * is to be deferred. This means that the input will not be
72     * acted upon, but rather it will be saved for later execution.
73     * Typically this is implemented using a CondVar wait, and the
74     * blocked thread represents the defered input. The defered
75     * input is retried when the thread runs again.
76     * </ul>
77     *
78     * @param FSM fsm is the state machine causing this action.
79     * @param Input in is the input that caused the transition.
80     */

81     public Result evaluate( FSM fsm, Input in ) ;
82 }
83
84 // end of Action.java
85

86
87
Popular Tags