2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.dialog.basic.config;
19
20 import java.util.HashMap;
21 import java.util.Iterator;
22 import java.util.Map;
23 import org.apache.shale.dialog.basic.model.Dialog;
24 import org.apache.shale.dialog.basic.model.State;
25 import org.apache.shale.dialog.basic.model.Transition;
26
27 /***
28 * <p>Abstract base class for {@link State} definitions. Each state is owned
29 * by exactly one owning {@link Dialog}. While an application
30 * is running, {@link Dialog} (and the constituent {@link State}s and
31 * other configuration information) is immutable, so that it may be
32 * shared by multiple simultaneous paths of execution.</p>
33 *
34 * @since 1.0.4
35 */
36
37 public abstract class AbstractState implements State {
38
39
40
41
42
43 /***
44 * <p>The {@link Dialog} that owns this {@link State} instance.</p>
45 */
46 private Dialog dialog = null;
47
48
49 /***
50 * <p>The identifier of this {@link State}, which must be unique among
51 * all {@link State}s within the owning {@link Dialog}.</p>
52 */
53 private String name = null;
54
55
56 /***
57 * <p>The {@link Transition}s owned by this {@link State}, keyed by
58 * outcome. <strong>FIXME</strong> - a different strategy will be needed
59 * if {@link Transition}s become more complex and manage their own
60 * criteria.</p>
61 */
62 private Map transitions = new HashMap();
63
64
65
66
67
68 /***
69 * {@inheritDoc}
70 */
71 public Dialog getDialog() {
72
73 return this.dialog;
74
75 }
76
77
78 /***
79 * {@inheritDoc}
80 */
81 public String getName() {
82
83 return this.name;
84
85 }
86
87
88 /***
89 * {@inheritDoc}
90 */
91 public Iterator getTransitionOutcomes() {
92
93 return this.transitions.keySet().iterator();
94
95 }
96
97
98
99
100
101 /***
102 * <p>Return the {@link Transition} for the specified logical outcome,
103 * if any; otherwise, return <code>null</code>.</p>
104 *
105 * @param outcome Logical outcome for which to return a {@link Transition}
106 * @return The matching {@link Transition}
107 */
108 public Transition findTransition(String outcome) {
109
110 return (Transition) transitions.get(outcome);
111
112 }
113
114
115
116
117
118 /***
119 * <p>Add the specified {@link Transition} to the {@link Transition}s owned
120 * by this {@link State}.</p>
121 *
122 * @param transition {@link Transition} to be added
123 *
124 * @exception IllegalArgumentException if the specified {@link Transition}
125 * cannot be added to this {@link State}
126 */
127 public void addTransition(Transition transition) throws IllegalArgumentException {
128
129
130 transitions.put(transition.getOutcome(), transition);
131
132 }
133
134
135 /***
136 * <p>Remove the specified {@link Transition} from the {@link Transition}s
137 * owned by this {@link State}, if it is currently registered. Otherwise,
138 * do nothing.</p>
139 *
140 * @param transition {@link Transition} to be removed
141 */
142 public void removeTransition(Transition transition) {
143
144 transitions.remove(transition.getOutcome());
145
146 }
147
148
149 /***
150 * <p>Set the {@link Dialog} that owns this {@link State}.</p>
151 *
152 * @param dialog New owning {@link Dialog}
153 */
154 public void setDialog(Dialog dialog) {
155
156 this.dialog = dialog;
157
158 }
159
160
161
162 /***
163 * <p>Set the identifier of this {@link State}, which must be unique
164 * among the {@link State}s owned by the same {@link Dialog}.</p>
165 *
166 * @param name New identifier
167 */
168 public void setName(String name) {
169
170 this.name = name;
171
172 }
173
174
175 }