1 package org.apache.maven.werkz;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 import java.util.HashMap;
68 import java.util.HashSet;
69 import java.util.Map;
70 import java.util.Set;
71
72 /** Goal satisfaction state.
73 *
74 * <p>
75 * A <code>Session</code> isolates satisfaction of <code>Goal</code>s
76 * into an objectified context. Multiple <code>Session</code>s can
77 * be deployed simultaneously against a <code>Project</code> or
78 * arbitrary <code>Goal</code> graph. Likewise, a single <code>Session</code>
79 * may be used simultaneous against several <code>Project</code>s
80 * or <code>Goal</code> graphs. A caveat with this last idiom
81 * revolves around <code>Goal</code>'s implementation of equality
82 * which utilitizes only the <code>Goal</code>'s name.
83 * </p>
84 *
85 * @see WerkzProject
86 * @see Goal
87 *
88 * @author <a href="mailto:bob@eng.werken.com">bob mcwhirter</a>
89 */
90 public class Session
91 {
92
93
94
95
96 /** Set of <code>Goal</code>s satisfied within this context. */
97 private Set satisfiedGoals;
98
99 /** Set of attributes that can be used during the execution of <code>Action</code>s. */
100 private Map attributes;
101
102
103
104
105
106 /** Construct.
107 */
108 public Session()
109 {
110 this.satisfiedGoals = new HashSet();
111 this.attributes = new HashMap();
112 }
113
114
115
116
117
118 /** Clear and reset this <code>Session</code> so that
119 * no <code>Goal</code>s are considered satisfied.
120 */
121 public void clear()
122 {
123 this.satisfiedGoals.clear();
124 }
125
126 /** Add a satisfied <code>Goal</code> to this context.
127 *
128 * @param goal The <code>Goal</code> that is satisfied.
129 */
130 void addSatisfiedGoal( Goal goal )
131 {
132 this.satisfiedGoals.add( goal );
133 }
134
135 /** Remove a satisfied <code>Goal</code> from this context.
136 *
137 * @param goal The <code>Goal</code> that is no longer satisfied.
138 */
139 void removeSatisfiedGoal( Goal goal )
140 {
141 this.satisfiedGoals.remove( goal );
142 }
143
144 /** Test a <code>Goal</code> to determine if it has been
145 * satisfied within this context.
146 *
147 * @param goal The <code>Goal</code> to test.
148 *
149 * @return <code>true</code> if the <code>Goal</code> has been
150 * satisfied within this context, otherwise <code>false</code>.
151 */
152 boolean isGoalSatisfied( Goal goal )
153 {
154 return this.satisfiedGoals.contains( goal );
155 }
156
157 /** Set the attributes for this <code>Session</code>.
158 *
159 * @param attributes The attributes for this <code>Session</code>.
160 */
161 public void setAttributes( Map attributes )
162 {
163 this.attributes = attributes;
164 }
165
166 /** Get the attributes from this <code>Session</code>.
167 *
168 * @return Attributes for this <code>Session</code>.
169 */
170 public Map getAttributes()
171 {
172 return this.attributes;
173 }
174
175 /** Set an attribute for this <code>Session</code>.
176 *
177 * @param key Attribute key.
178 * @param value Attribute value.
179 */
180 public void setAttribute( String key, Object value )
181 {
182 getAttributes().put( key, value );
183 }
184
185 /** Get an attribute from this <code>Session</code>.
186 *
187 * @return An attribute from this <code>Session</code>.
188 */
189 public Object getAttribute( String key )
190 {
191 return getAttributes().get( key );
192 }
193
194 /** Log an informative message.
195 *
196 * @param msg The message.
197 */
198 public void info( String msg )
199 {
200
201 }
202
203 /** Log a warning message.
204 *
205 * @param msg The message.
206 */
207 public void warn( String msg )
208 {
209
210 }
211
212 /** Log an error message.
213 *
214 * @param msg The message.
215 */
216 public void error( String msg )
217 {
218
219 }
220
221 }