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.breakdownelement;
019:
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.apache.commons.lang.builder.EqualsBuilder;
024: import org.apache.commons.lang.builder.HashCodeBuilder;
025:
026: import wilos.model.misc.concretebreakdownelement.ConcreteBreakdownElement;
027: import wilos.model.spem2.activity.Activity;
028: import wilos.model.spem2.element.Element;
029:
030: /**
031: *
032: * BreakdownElement is an abstract generalization for any type of
033: * {@link Element} that is part of a breakdown structure. It defines a set of
034: * properties available to all of its specializations.
035: * <p />
036: * It's an element of the SPEM2 specification of the OMG organization
037: * (http://www.omg.org/).
038: *
039: */
040: public class BreakdownElement extends Element implements Cloneable,
041: Comparable<BreakdownElement> {
042:
043: private String presentationName;
044:
045: private String prefix;
046:
047: private Boolean isPlanned;
048:
049: private Boolean hasMultipleOccurrences;
050:
051: private Boolean isOptional;
052:
053: private Set<Activity> super Activities;
054:
055: private Set<ConcreteBreakdownElement> concreteBreakdownElements;
056:
057: /**
058: * Constructor.
059: *
060: */
061: public BreakdownElement() {
062: super ();
063: this .presentationName = "";
064: this .prefix = "";
065: this .isOptional = false;
066: this .isPlanned = true;
067: this .hasMultipleOccurrences = false;
068: this .super Activities = new HashSet<Activity>();
069: this .concreteBreakdownElements = new HashSet<ConcreteBreakdownElement>();
070: }
071:
072: /**
073: * Returns a copy of the current instance of BreakdownElement
074: *
075: * @return a copy of the BreakdownElement
076: * @throws CloneNotSupportedException
077: */
078: @Override
079: public BreakdownElement clone() throws CloneNotSupportedException {
080: BreakdownElement breakdownElement = new BreakdownElement();
081: breakdownElement.copy(this );
082: return breakdownElement;
083: }
084:
085: /**
086: * Copy the values of the specified BreakdownElement into the current
087: * instance of the class.
088: *
089: * @param _breakdownElement
090: * The BreakdownElement to copy.
091: */
092: protected void copy(final BreakdownElement _breakdownElement) {
093: super .copy(_breakdownElement);
094: this .presentationName = _breakdownElement.presentationName;
095: this .prefix = _breakdownElement.prefix;
096: this .hasMultipleOccurrences = _breakdownElement.hasMultipleOccurrences;
097: this .isPlanned = _breakdownElement.isPlanned;
098: this .isOptional = _breakdownElement.isOptional;
099: this .concreteBreakdownElements.addAll(_breakdownElement
100: .getConcreteBreakdownElements());
101: this .super Activities.addAll(_breakdownElement
102: .getSuperActivities());
103: }
104:
105: /**
106: * Defines if the specified Object is the same or has the same values as the
107: * current instance of the BreakdownElement.
108: *
109: * @param obj
110: * the Object to be compare to the BreakdownElement
111: * @return true if the specified Object is the same, false otherwise
112: */
113: public boolean equals(Object obj) {
114: if (obj instanceof BreakdownElement == false) {
115: return false;
116: }
117: if (this == obj) {
118: return true;
119: }
120: BreakdownElement breakdownElement = (BreakdownElement) obj;
121: return new EqualsBuilder().appendSuper(
122: super .equals(breakdownElement)).append(
123: this .presentationName,
124: breakdownElement.presentationName).append(this .prefix,
125: breakdownElement.prefix).append(this .isPlanned,
126: breakdownElement.isPlanned).append(
127: this .hasMultipleOccurrences,
128: breakdownElement.hasMultipleOccurrences).append(
129: this .isOptional, breakdownElement.isOptional).append(
130: this .concreteBreakdownElements,
131: breakdownElement.concreteBreakdownElements).append(
132: this .super Activities, breakdownElement.super Activities)
133: .isEquals();
134: }
135:
136: /**
137: * Returns a hash code value for the object. This method is supported for
138: * the benefit of hash tables.
139: *
140: * @return the hash code of the current instance of BreakdownElement
141: */
142: public int hashCode() {
143: return new HashCodeBuilder(17, 37)
144: .appendSuper(super .hashCode()).append(
145: this .presentationName).append(this .prefix)
146: .append(this .hasMultipleOccurrences).append(
147: this .isOptional).append(this .isPlanned)
148: .toHashCode();
149: }
150:
151: /*
152: * relation between BreakdownElement and ConcreteBreakdownElement.
153: *
154: */
155:
156: /**
157: * Adds a relation between the current instance of BreakdownElement
158: * and a specified ConcreteBreakdownElement.
159: *
160: * @param _concreteBreakdownElement the ConcreteBreakdownElement to link
161: */
162: public void addConcreteBreakdownElement(
163: ConcreteBreakdownElement _concreteBreakdownElement) {
164: this .concreteBreakdownElements.add(_concreteBreakdownElement);
165: _concreteBreakdownElement.addBreakdownElement(this );
166: }
167:
168: /**
169: * Removes the relation between the current instance of BreakdownElement
170: * and a specified ConcreteBreakdownElement.
171: *
172: * @param _concreteBreakdownElement the ConcreteBreakdownElement to unlink
173: */
174: public void removeConcreteBreakdownElement(
175: ConcreteBreakdownElement _concreteBreakdownElement) {
176: _concreteBreakdownElement.removeBreakdownElement(this );
177: this .concreteBreakdownElements
178: .remove(_concreteBreakdownElement);
179: }
180:
181: /**
182: * Adds a relation between the current instance of BreakdownElement
183: * and all the specified ConcreteBreakdownElement.
184: *
185: * @param _concreteBreakdownElements the Collection of ConcreteBreakdownElement to link
186: */
187: public void addAllConcreteBreakdownElements(
188: Set<ConcreteBreakdownElement> _concreteBreakdownElements) {
189: for (ConcreteBreakdownElement cbde : _concreteBreakdownElements) {
190: cbde.addBreakdownElement(this );
191: }
192: }
193:
194: /**
195: * Remove the relation between the current instance of BreakdownElement
196: * and all the related ConcreteBreakdownElement.
197: */
198: public void removeAllConcreteBreakdownElements() {
199: for (ConcreteBreakdownElement cbde : this
200: .getConcreteBreakdownElements())
201: cbde.setBreakdownElement(null);
202: this .getConcreteBreakdownElements().clear();
203: }
204:
205: /**
206: * Add an Activity to the activities collection of a BreakdownElement.
207: *
208: * @param _superActivity
209: * The activity to add
210: */
211: public void addSuperActivity(Activity _super Activity) {
212: this .getSuperActivities().add(_super Activity);
213: _super Activity.getBreakdownElements().add(this );
214: }
215:
216: /**
217: * Add an activity collection to the activity collection of a
218: * breakdownelement.
219: *
220: * @param _superActivities
221: * The set of Activity to add.
222: */
223: public void addAllSuperActivities(Set<Activity> _super Activities) {
224: for (Activity activity : _super Activities) {
225: activity.addBreakdownElement(this );
226: }
227: }
228:
229: /**
230: * Remove from a breakdownelement one of these activities.
231: *
232: * @param _superActivity
233: * The Activity to remove.
234: */
235: public void removeSuperActivity(Activity _super Activity) {
236: _super Activity.getBreakdownElements().remove(this );
237: this .getSuperActivities().remove(_super Activity);
238: }
239:
240: /**
241: * Remove from a breakdownelement all its activities.
242: *
243: */
244: public void removeAllSuperActivities() {
245: for (Activity activity : this .getSuperActivities())
246: activity.getBreakdownElements().remove(this );
247: this .getSuperActivities().clear();
248: }
249:
250: /*
251: * (non-Javadoc)
252: *
253: * @see java.lang.Comparable#compareTo(java.lang.Object)
254: */
255: public int compareTo(BreakdownElement _arg0) {
256: if (_arg0 != null) {
257: return (this .getInsertionOrder() - _arg0
258: .getInsertionOrder());
259: } else
260: return 0;
261: }
262:
263: /**
264: * Getter of presentationName.
265: *
266: * @return the presentationName
267: */
268: public String getPresentationName() {
269: return this .presentationName;
270: }
271:
272: /**
273: * Setter of presentationName.
274: *
275: * @param _presentationName
276: * The presentationName to set.
277: */
278: public void setPresentationName(String _presentationName) {
279: this .presentationName = _presentationName;
280: }
281:
282: /**
283: * Getter of hasMultipleOccurrences.
284: *
285: * @return the hasMultipleOccurrences.
286: */
287: public Boolean getHasMultipleOccurrences() {
288: return this .hasMultipleOccurrences;
289: }
290:
291: /**
292: * Setter of hasMultipleOccurrences.
293: *
294: * @param _hasMultipleOccurrences
295: * The hasMultipleOccurrences to set.
296: */
297: public void setHasMultipleOccurrences(
298: Boolean _hasMultipleOccurrences) {
299: this .hasMultipleOccurrences = _hasMultipleOccurrences;
300: }
301:
302: /**
303: * Getter of isOptional.
304: *
305: * @return the isOptional.
306: */
307: public Boolean getIsOptional() {
308: return this .isOptional;
309: }
310:
311: /**
312: * Setter of isOptional.
313: *
314: * @param _isOptional
315: * The isOptional to set.
316: */
317: public void setIsOptional(Boolean _isOptional) {
318: this .isOptional = _isOptional;
319: }
320:
321: /**
322: * Getter of isPlanned.
323: *
324: * @return the isPlanned.
325: */
326: public Boolean getIsPlanned() {
327: return this .isPlanned;
328: }
329:
330: /**
331: * Setter of isPlanned.
332: *
333: * @param _isPlanned
334: * The isPlanned to set.
335: */
336: public void setIsPlanned(Boolean _isPlanned) {
337: this .isPlanned = _isPlanned;
338: }
339:
340: /**
341: * Getter of prefix.
342: *
343: * @return the prefix.
344: */
345: public String getPrefix() {
346: return this .prefix;
347: }
348:
349: /**
350: * Setter of prefix.
351: *
352: * @param _prefix
353: * The prefix to set.
354: */
355: public void setPrefix(String _prefix) {
356: this .prefix = _prefix;
357: }
358:
359: /**
360: * Getter of activities.
361: *
362: * @return the activities.
363: */
364: public Set<Activity> getSuperActivities() {
365: return this .super Activities;
366: }
367:
368: /**
369: * Setter of activities.
370: *
371: * @param _superActivities
372: * The activities to set.
373: */
374: @SuppressWarnings("unused")
375: public void setSuperActivities(Set<Activity> _super Activities) {
376: this .super Activities = _super Activities;
377: }
378:
379: /**
380: * Getter of concreteBreakdownElements.
381: *
382: * @return the concreteBreakdownElements.
383: */
384: public Set<ConcreteBreakdownElement> getConcreteBreakdownElements() {
385: return this .concreteBreakdownElements;
386: }
387:
388: /**
389: * Setter of concreteBreakdownElements.
390: *
391: * @param _superActivities
392: * The activities to set.
393: */
394: @SuppressWarnings("unused")
395: private void setConcreteBreakdownElements(
396: Set<ConcreteBreakdownElement> _concreteBreakdownElements) {
397: this.concreteBreakdownElements = _concreteBreakdownElements;
398: }
399: }
|