001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: * Copyright (C) 2007 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
005: *
006: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
007: * General Public License as published by the Free Software Foundation; either version 2 of the License,
008: * or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License along with this program; if not,
015: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016: */
017:
018: package wilos.model.spem2.activity;
019:
020: import java.util.HashSet;
021: import java.util.Set;
022: import java.util.SortedSet;
023: import java.util.TreeSet;
024:
025: import org.apache.commons.lang.builder.EqualsBuilder;
026: import org.apache.commons.lang.builder.HashCodeBuilder;
027:
028: import wilos.model.misc.concreteactivity.ConcreteActivity;
029: import wilos.model.spem2.breakdownelement.BreakdownElement;
030: import wilos.model.spem2.guide.Guidance;
031: import wilos.model.spem2.workbreakdownelement.WorkBreakdownElement;
032:
033: /**
034: *
035: * An Activity is a {@link WorkBreakdownElement} which supports the nesting and logical
036: * grouping of related Breakdown Elements forming breakdown structures. Although
037: * Activity is a concrete meta-class, other classes which represent breakdown
038: * structures derive from it; such as {@link Phase}, {@link Iteration} or {@link Process}.
039: * <p />
040: * It's an element of the SPEM2 specification of the OMG
041: * organization (http://www.omg.org/).
042: *
043: */
044: public class Activity extends WorkBreakdownElement implements Cloneable {
045:
046: private SortedSet<BreakdownElement> breakdownElements;
047:
048: private Set<ConcreteActivity> concreteActivities;
049:
050: private Set<Guidance> guidances;
051:
052: private String alternatives;
053:
054: private String howToStaff;
055:
056: private String purpose;
057:
058: /**
059: * Default constructor.
060: *
061: */
062: public Activity() {
063: super ();
064: this .breakdownElements = new TreeSet<BreakdownElement>();
065: this .concreteActivities = new HashSet<ConcreteActivity>();
066: this .guidances = new HashSet<Guidance>();
067: this .howToStaff = "";
068: this .purpose = "";
069: this .alternatives = "";
070: }
071:
072: /**
073: * Defines if the specified Object is the same or has the same values as the
074: * current instance of the class.
075: *
076: * @param _obj
077: * the Object to be compare to the Activity
078: * @return true if the specified Object is the same, false otherwise
079: */
080: public boolean equals(Object obj) {
081: if (obj instanceof Activity == false) {
082: return false;
083: }
084: if (this == obj) {
085: return true;
086: }
087: Activity activity = (Activity) obj;
088: return new EqualsBuilder().appendSuper(super .equals(activity))
089: .append(this .breakdownElements,
090: activity.breakdownElements).append(
091: this .concreteActivities,
092: activity.concreteActivities).append(
093: this .guidances, activity.guidances).append(
094: this .alternatives, activity.alternatives)
095: .append(this .howToStaff, activity.howToStaff).append(
096: this .purpose, activity.purpose).isEquals();
097: }
098:
099: /**
100: * Returns a hash code value for the object. This method is supported for
101: * the benefit of hash tables.
102: *
103: * @return the hash code of the current instance of Activity
104: */
105: public int hashCode() {
106: return new HashCodeBuilder(17, 37)
107: .appendSuper(super .hashCode())
108: .append(this .alternatives).append(this .howToStaff)
109: .append(this .purpose).toHashCode();
110: }
111:
112: /**
113: * Returns a copy of the current instance of Activity
114: *
115: * @return a copy of the Activity
116: * @throws CloneNotSupportedException
117: */
118: @Override
119: public Activity clone() throws CloneNotSupportedException {
120: Activity activity = new Activity();
121: activity.copy(this );
122: return activity;
123: }
124:
125: /**
126: * Copy the _activity into the current Activity.
127: *
128: * @param _activity
129: * The Activity to copy.
130: */
131: protected void copy(final Activity _activity) {
132: super .copy(_activity);
133: this .breakdownElements.addAll(_activity.getBreakdownElements());
134: this .concreteActivities.addAll(_activity
135: .getConcreteActivities());
136: this .guidances.addAll(_activity.getGuidances());
137: this .alternatives = _activity.getAlternatives();
138: this .howToStaff = _activity.getHowToStaff();
139: this .purpose = _activity.getPurpose();
140: }
141:
142: /*
143: * Manage BreakdownElement relation.
144: */
145:
146: /**
147: * Add a {@link BreakdownElement} to the BreakdownElement collection of an
148: * activity.
149: *
150: * @param _breakdownElement
151: * The {@link BreakdownElement} to add.
152: */
153: public void addBreakdownElement(BreakdownElement _breakdownElement) {
154: this .getBreakdownElements().add(_breakdownElement);
155: _breakdownElement.getSuperActivities().add(this );
156: }
157:
158: /**
159: * Add a {@link BreakdownElement} collection to the BreakdownElement
160: * collection of an activity.
161: *
162: * @param _breakdownElements
163: * The set of {@link BreakdownElement} to add.
164: */
165: public void addAllBreakdownElements(
166: SortedSet<BreakdownElement> _breakdownElements) {
167: for (BreakdownElement bde : _breakdownElements) {
168: bde.addSuperActivity(this );
169: }
170: }
171:
172: /**
173: * Remove from an Activity all its break down elements.
174: *
175: */
176: public void removeAllBreakdownElements() {
177: for (BreakdownElement bde : this .getBreakdownElements())
178: bde.getSuperActivities().remove(this );
179: this .getBreakdownElements().clear();
180: }
181:
182: /**
183: * Remove from an Activity one of these break downe elements.
184: *
185: * @param _breakdownElement
186: * The {@link BreakdownElement} to remove.
187: */
188: public void removeBreakdownElement(
189: BreakdownElement _breakdownElement) {
190: _breakdownElement.getSuperActivities().remove(this );
191: this .getBreakdownElements().remove(_breakdownElement);
192: }
193:
194: /*
195: * Manage ConcreteActivity relation.
196: */
197:
198: /**
199: * Add a {@link ConcreteActivity} to the BreakdownElement collection of an
200: * Activity.
201: *
202: * @param _concreteActivity
203: * The {@link ConcreteActivity} to add.
204: */
205: public void addConcreteActivity(ConcreteActivity _concreteActivity) {
206: this .concreteActivities.add(_concreteActivity);
207: _concreteActivity.setActivity(this );
208: }
209:
210: /**
211: * Add a {@link ConcreteActivity} collection to the concrete activities
212: * collection of an activity.
213: *
214: * @param _concreteActivities
215: * The set of {@link ConcreteActivity} to add.
216: */
217: public void addAllConcreteActivities(
218: Set<ConcreteActivity> _concreteActivities) {
219: for (ConcreteActivity ca : _concreteActivities) {
220: this .addConcreteActivity(ca);
221: }
222: }
223:
224: /**
225: * Remove from an Activity one of these concrete activities.
226: *
227: * @param _concreteActivity
228: * The {@link ConcreteActivity} to remove.
229: */
230: public void removeConcreteActivity(
231: ConcreteActivity _concreteActivity) {
232: this .concreteActivities.remove(_concreteActivity);
233: _concreteActivity.setActivity(null);
234: }
235:
236: /**
237: * Remove from an Activity all its concrete activities.
238: *
239: */
240: public void removeAllConcreteActivities() {
241:
242: for (ConcreteActivity tmp : this .concreteActivities) {
243: tmp.setActivity(null);
244: }
245: this .concreteActivities.clear();
246: }
247:
248: /*
249: * Manage Guidance relation.
250: */
251:
252: /**
253: * Remove from a Guidance one of these guidances.
254: *
255: * @param _guidance
256: * The {@link Guidance} to remove.
257: */
258: public void removeGuidance(Guidance _guidance) {
259: _guidance.getActivities().remove(this );
260: this .guidances.remove(_guidance);
261: }
262:
263: /**
264: * @param _guidance
265: */
266: public void addGuidance(Guidance _guidance) {
267: this .guidances.add(_guidance);
268: _guidance.getActivities().add(this );
269: }
270:
271: /**
272: * Remove from an Activity all its guidances.
273: *
274: */
275: public void removeAllGuidances() {
276: for (Guidance guidance : this .guidances) {
277: guidance.getActivities().remove(this );
278: }
279: this .guidances.clear();
280: }
281:
282: /**
283: * @param _guidances
284: */
285: public void addAllGuidances(Set<Guidance> _guidances) {
286: for (Guidance _guid1 : _guidances) {
287: this .addGuidance(_guid1);
288: }
289: }
290:
291: /*
292: * Getters & Setters.
293: */
294:
295: /**
296: * Getter of break down elements collection.
297: *
298: * @return the break down elements collection.
299: */
300: public SortedSet<BreakdownElement> getBreakdownElements() {
301: return this .breakdownElements;
302: }
303:
304: /**
305: * Setter of breakDownElements.
306: *
307: * @param _breakDownElements
308: * The breakDownElements to set.
309: */
310: public void setBreakdownElements(
311: SortedSet<BreakdownElement> _breakDownElements) {
312: this .breakdownElements = _breakDownElements;
313: }
314:
315: /**
316: * Getter of concrete activities.
317: *
318: * @return
319: */
320: public Set<ConcreteActivity> getConcreteActivities() {
321: return concreteActivities;
322: }
323:
324: /**
325: * Setter of concrete activities collection.
326: *
327: * @param _concreteActivities
328: * The concrete activities collection to set.
329: */
330: public void setConcreteActivities(
331: Set<ConcreteActivity> _concreteActivities) {
332: this .concreteActivities = _concreteActivities;
333: }
334:
335: /**
336: * Getter of guidances.
337: *
338: * @return The guidances collection to get.
339: */
340: public Set<Guidance> getGuidances() {
341: return guidances;
342: }
343:
344: /**
345: * Setter of guidances collection.
346: *
347: * @param _guidances
348: * The guidances collection to set.
349: */
350: public void setGuidances(Set<Guidance> _guidances) {
351: this .guidances = _guidances;
352: }
353:
354: /**
355: * Getter of alternatives.
356: *
357: * @return The alternatives collection.
358: */
359: public String getAlternatives() {
360: return alternatives;
361: }
362:
363: /**
364: * Setter of alternatives.
365: *
366: * @param _alternatives
367: */
368: public void setAlternatives(String _alternatives) {
369: this .alternatives = _alternatives;
370: }
371:
372: /**
373: * Getter of howToStaff.
374: *
375: * @return
376: */
377: public String getHowToStaff() {
378: return howToStaff;
379: }
380:
381: /**
382: * Setter of howToStaff.
383: *
384: * @param _howToStaff
385: */
386: public void setHowToStaff(String _howToStaff) {
387: this .howToStaff = _howToStaff;
388: }
389:
390: /**
391: * Getter of purpose.
392: *
393: * @return
394: */
395: public String getPurpose() {
396: return purpose;
397: }
398:
399: /**
400: * Setter of purpose.
401: *
402: * @param _purpose
403: */
404: public void setPurpose(String _purpose) {
405: this.purpose = _purpose;
406: }
407: }
|