1 /*
   2  * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.corba.se.spi.orbutil.fsm;
  27 
  28 /**
  29  *
  30  * @author Ken Cavanaugh
  31  */
  32 public interface Guard
  33 {
  34     public static final class Complement extends GuardBase {
  35         private Guard guard ;
  36 
  37         public Complement( GuardBase guard )
  38         {
  39             super( "not(" + guard.getName() + ")" ) ;
  40             this.guard = guard ;
  41         }
  42 
  43         public Result evaluate( FSM fsm, Input in )
  44         {
  45             return guard.evaluate( fsm, in ).complement() ;
  46         }
  47     }
  48 
  49     public static final class Result {
  50         private String name ;
  51 
  52         private Result( String name )
  53         {
  54             this.name = name ;
  55         }
  56 
  57         public static Result convert( boolean res )
  58         {
  59             return res ? ENABLED : DISABLED ;
  60         }
  61 
  62         public Result complement()
  63         {
  64             if (this == ENABLED)
  65                 return DISABLED ;
  66             else if (this == DISABLED)
  67                 return ENABLED ;
  68             else
  69                 return DEFERED ;
  70         }
  71 
  72         public String toString()
  73         {
  74             return "Guard.Result[" + name + "]" ;
  75         }
  76 
  77         public static final Result ENABLED = new Result( "ENABLED" ) ;
  78         public static final Result DISABLED = new Result( "DISABLED" ) ;
  79         public static final Result DEFERED = new Result( "DEFERED" ) ;
  80     }
  81 
  82     /** Called by the state engine to determine whether a
  83     * transition is enabled, defered, or disabled.
  84     * The result is interpreted as follows:
  85     * <ul>
  86     * <li>ENABLED if the transition is ready to proceed
  87     * <li>DISABLED if the transition is not ready to proceed
  88     * <li>DEFERED if the action associated with the transition
  89     * is to be deferred.  This means that the input will not be
  90     * acted upon, but rather it will be saved for later execution.
  91     * Typically this is implemented using a CondVar wait, and the
  92     * blocked thread represents the defered input.  The defered
  93     * input is retried when the thread runs again.
  94     * </ul>
  95     *
  96     * @param fsm is the state machine causing this action.
  97     * @param in is the input that caused the transition.
  98     */
  99     public Result evaluate( FSM fsm, Input in ) ;
 100 }
 101 
 102 // end of Action.java