Guard.java revision 673:6b017d166ac2
117680Spst/*
217680Spst * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
317680Spst * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
417680Spst *
517680Spst * This code is free software; you can redistribute it and/or modify it
617680Spst * under the terms of the GNU General Public License version 2 only, as
717680Spst * published by the Free Software Foundation.  Oracle designates this
817680Spst * particular file as subject to the "Classpath" exception as provided
917680Spst * by Oracle in the LICENSE file that accompanied this code.
1017680Spst *
1117680Spst * This code is distributed in the hope that it will be useful, but WITHOUT
1217680Spst * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1317680Spst * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1417680Spst * version 2 for more details (a copy is included in the LICENSE file that
1517680Spst * accompanied this code).
1617680Spst *
1717680Spst * You should have received a copy of the GNU General Public License version
1817680Spst * 2 along with this work; if not, write to the Free Software Foundation,
1917680Spst * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2017680Spst *
2117680Spst * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2217680Spst * or visit www.oracle.com if you need additional information or have any
2317680Spst * questions.
2417680Spst */
2517680Spst
2617680Spstpackage com.sun.corba.se.spi.orbutil.fsm;
2717680Spst
2817680Spst/**
2917680Spst *
3017680Spst * @author Ken Cavanaugh
3117680Spst */
3217680Spstpublic interface Guard
3317680Spst{
3417680Spst    public static final class Complement extends GuardBase {
3517680Spst        private Guard guard ;
3617680Spst
3717680Spst        public Complement( GuardBase guard )
3817680Spst        {
3917680Spst            super( "not(" + guard.getName() + ")" ) ;
4017680Spst            this.guard = guard ;
4117680Spst        }
4217680Spst
4317680Spst        public Result evaluate( FSM fsm, Input in )
4417680Spst        {
4517680Spst            return guard.evaluate( fsm, in ).complement() ;
4617680Spst        }
4717680Spst    }
4817680Spst
4917680Spst    public static final class Result {
5017680Spst        private String name ;
5117680Spst
5217680Spst        private Result( String name )
5317680Spst        {
5417680Spst            this.name = name ;
5517680Spst        }
5617680Spst
5717680Spst        public static Result convert( boolean res )
5817680Spst        {
5917680Spst            return res ? ENABLED : DISABLED ;
6017680Spst        }
6117680Spst
6217680Spst        public Result complement()
6317680Spst        {
6417680Spst            if (this == ENABLED)
6517680Spst                return DISABLED ;
6617680Spst            else if (this == DISABLED)
6717680Spst                return ENABLED ;
6817680Spst            else
6917680Spst                return DEFERED ;
7017680Spst        }
7117680Spst
7217680Spst        public String toString()
7317680Spst        {
7417680Spst            return "Guard.Result[" + name + "]" ;
7517680Spst        }
7617680Spst
7717680Spst        public static final Result ENABLED = new Result( "ENABLED" ) ;
7817680Spst        public static final Result DISABLED = new Result( "DISABLED" ) ;
7917680Spst        public static final Result DEFERED = new Result( "DEFERED" ) ;
8017680Spst    }
8117680Spst
8217680Spst    /** Called by the state engine to determine whether a
8317680Spst    * transition is enabled, defered, or disabled.
8417680Spst    * The result is interpreted as follows:
8517680Spst    * <ul>
8617680Spst    * <li>ENABLED if the transition is ready to proceed
8717680Spst    * <li>DISABLED if the transition is not ready to proceed
8817680Spst    * <li>DEFERED if the action associated with the transition
8917680Spst    * is to be deferred.  This means that the input will not be
9017680Spst    * acted upon, but rather it will be saved for later execution.
9117680Spst    * Typically this is implemented using a CondVar wait, and the
9217680Spst    * blocked thread represents the defered input.  The defered
9317680Spst    * input is retried when the thread runs again.
9417680Spst    * </ul>
9517680Spst    *
9617680Spst    * @param fsm is the state machine causing this action.
9717680Spst    * @param in is the input that caused the transition.
9817680Spst    */
9917680Spst    public Result evaluate( FSM fsm, Input in ) ;
10017680Spst}
10117680Spst
10217680Spst// end of Action.java
10317680Spst