View Javadoc

1   package org.apache.maven.werkz;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  /*
22   $Id: Session.java 517014 2007-03-11 21:15:50Z ltheussl $
23  
24   Copyright 2002 (C) The Werken Company. All Rights Reserved.
25   
26   Redistribution and use of this software and associated documentation
27   ("Software"), with or without modification, are permitted provided
28   that the following conditions are met:
29  
30   1. Redistributions of source code must retain copyright
31   statements and notices.  Redistributions must also contain a
32   copy of this document.
33   
34   2. Redistributions in binary form must reproduce the
35   above copyright notice, this list of conditions and the
36   following disclaimer in the documentation and/or other
37   materials provided with the distribution.
38   
39   3. The name "werkz" must not be used to endorse or promote
40   products derived from this Software without prior written
41   permission of The Werken Company.  For written permission,
42   please contact bob@werken.com.
43   
44   4. Products derived from this Software may not be called "werkz"
45   nor may "werkz" appear in their names without prior written
46   permission of The Werken Company. "werkz" is a registered
47   trademark of The Werken Company.
48   
49   5. Due credit should be given to "the werkz project"
50   ( http://werkz.werken.com/ ).
51   
52   THIS SOFTWARE IS PROVIDED BY THE WERKEN COMPANY AND CONTRIBUTORS
53   ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
54   NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
55   FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
56   THE WERKEN COMPANY OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
57   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
58   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
59   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
61   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
63   OF THE POSSIBILITY OF SUCH DAMAGE.
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      //     Instance members
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     //     Constructors
104     // ------------------------------------------------------------
105 
106     /** Construct.
107      */
108     public Session()
109     {
110         this.satisfiedGoals = new HashSet();
111         this.attributes = new HashMap();
112     }
113 
114     // ------------------------------------------------------------
115     //     Instance methods
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         // intentionally left blank
201     }
202 
203     /** Log a warning message.
204      *
205      *  @param msg The message.
206      */
207     public void warn( String msg )
208     {
209         // intentionally left blank
210     }
211 
212     /** Log an error message.
213      *
214      *  @param msg The message.
215      */
216     public void error( String msg )
217     {
218         // intentionally left blank
219     }
220 
221 }