01 /*
02 * Copyright (c) 1995-2010, The University of Sheffield. See the file
03 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
04 *
05 * This file is part of GATE (see http://gate.ac.uk/), and is free
06 * software, licenced under the GNU Library General Public License,
07 * Version 2, June 1991 (in the distribution as file licence.html,
08 * and also available at http://gate.ac.uk/gate/licence.html).
09 *
10 * Valentin Tablan 11 Apr 2002
11 *
12 * $Id: RunningStrategy.java 13179 2010-11-01 13:02:38Z ian_roberts $
13 */
14 package gate.creole;
15
16
17 import gate.ProcessingResource;
18
19 /**
20 * Base interface for objects that are used to decide whether a PR member of a
21 * {@link ConditionalController} needs to be run.
22 */
23
24 public interface RunningStrategy{
25 /**
26 * Returns true if the associated PR should be run.
27 * @return a boolean value.
28 */
29 public boolean shouldRun();
30
31 /**
32 * Returns the run mode (see {@link #RUN_ALWAYS}, {@link #RUN_NEVER},
33 * {@link #RUN_CONDITIONAL}).
34 * @return and int value.
35 */
36 public int getRunMode();
37
38 /**
39 * Gets the associated ProcessingResource.
40 * @return a {@link ProcessingResource} value.
41 */
42 public ProcessingResource getPR();
43
44
45 /**
46 * Run mode constant meaning the associated PR should be run regardless of
47 * what the {@link #shouldRun()} method returns.
48 */
49 public static final int RUN_ALWAYS = 1;
50
51 /**
52 * Run mode constant meaning the associated PR should NOT be run regardless of
53 * what the {@link #shouldRun()} method returns.
54 */
55 public static final int RUN_NEVER = 2;
56
57 /**
58 * Run mode constant meaning the associated PR should be run only if the
59 * {@link #shouldRun()} method returns true.
60 */
61 public static final int RUN_CONDITIONAL = 4;
62
63 /**
64 * RunningStrateguy implementation that unconditionally either runs
65 * or doesn't run a given PR.
66 */
67 public static class UnconditionalRunningStrategy implements RunningStrategy {
68 public UnconditionalRunningStrategy(ProcessingResource pr, boolean run) {
69 this.pr = pr;
70 this.shouldRun = run;
71 }
72 public boolean shouldRun(){return shouldRun;}
73
74 public void shouldRun(boolean run) { this.shouldRun = run; }
75
76 public int getRunMode(){return shouldRun ? RUN_ALWAYS : RUN_NEVER;}
77
78 public ProcessingResource getPR(){return pr;}
79
80 ProcessingResource pr;
81 boolean shouldRun;
82 }
83
84 /**
85 * @deprecated use {@link UnconditionalRunningStrategy} instead.
86 */
87 @Deprecated
88 public static class RunAlwaysStrategy extends UnconditionalRunningStrategy{
89 public RunAlwaysStrategy(ProcessingResource pr){
90 super(pr, true);
91 }
92 }
93 }
|