001: /*
002: *
003: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
004: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
005: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
006: * Copyright (C) 2007 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
007: *
008: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
009: * General Public License as published by the Free Software Foundation; either version 2 of the License,
010: * or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
013: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License along with this program; if not,
017: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
018: */
019:
020: package wilos.model.misc.concretebreakdownelement;
021:
022: import java.util.HashSet;
023: import java.util.Set;
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.misc.project.Project;
030: import wilos.model.spem2.breakdownelement.BreakdownElement;
031:
032: /**
033: *
034: * A ConcreteBreakdownElement is a specific {@link BreakdownElement} for a
035: * {@link Project}.
036: *
037: */
038: public class ConcreteBreakdownElement implements Cloneable,
039: Comparable<ConcreteBreakdownElement> {
040:
041: private String id;
042:
043: private Project project;
044:
045: private String concreteName;
046:
047: private Set<ConcreteActivity> super ConcreteActivities;
048:
049: private BreakdownElement breakdownElement;
050:
051: private String displayOrder;
052:
053: /*
054: * The instanciation order of the concrete element.
055: */
056: private int instanciationOrder;
057:
058: /**
059: * Class constructor.
060: */
061: public ConcreteBreakdownElement() {
062: this .id = "";
063: this .concreteName = "";
064: this .project = null;
065: this .breakdownElement = null;
066: this .super ConcreteActivities = new HashSet<ConcreteActivity>();
067: this .displayOrder = "";
068: }
069:
070: /**
071: * Compares the specified ConcreteBreakdownElement with the current instance
072: * of the class.
073: *
074: * @param _arg0
075: * the ConcreteBreakdownElement to be compare with the current
076: * instance
077: * @return
078: */
079: public int compareTo(ConcreteBreakdownElement _arg0) {
080: if (this .breakdownElement != null) {
081: int compare = this .breakdownElement.compareTo(_arg0
082: .getBreakdownElement());
083: if (compare == 0) {
084: return this .getInstanciationOrder()
085: - _arg0.getInstanciationOrder();
086: } else
087: return compare;
088: } else
089: // TODO : check the instanciationOrder attribution algorithm
090: // return 0;
091: return this .getInstanciationOrder()
092: - _arg0.getInstanciationOrder();
093: }
094:
095: /**
096: * Returns a copy of the current instance of ConcreteBreakdownElement
097: *
098: * @return a copy of the ConcreteBreakdownElement
099: * @throws CloneNotSupportedException
100: */
101: public ConcreteBreakdownElement clone()
102: throws CloneNotSupportedException {
103: ConcreteBreakdownElement concreteBreakdownElement = new ConcreteBreakdownElement();
104: concreteBreakdownElement.copy(this );
105: return concreteBreakdownElement;
106: }
107:
108: /**
109: * Copy the values of the specified ConcreteBreakdownElement into the
110: * current instance.
111: *
112: * @param _concreteBreakdownElement
113: * the ConcreteBreakdownElement to be copy
114: */
115: protected void copy(
116: final ConcreteBreakdownElement _concreteBreakdownElement) {
117: this .concreteName = _concreteBreakdownElement.getConcreteName();
118: this .breakdownElement = _concreteBreakdownElement
119: .getBreakdownElement();
120: this .super ConcreteActivities.addAll(_concreteBreakdownElement
121: .getSuperConcreteActivities());
122: this .project = _concreteBreakdownElement.getProject();
123: this .instanciationOrder = _concreteBreakdownElement.instanciationOrder;
124: this .displayOrder = _concreteBreakdownElement.displayOrder;
125: }
126:
127: /**
128: * Defines if the specified Object is the same or has the same values as the
129: * current instance of the class.
130: *
131: * @param obj
132: * the Object to be compare to the ConcreteBreakdownElement
133: * @return true if the specified Object is the same, false otherwise
134: */
135: public boolean equals(Object obj) {
136: if (obj instanceof ConcreteBreakdownElement == false) {
137: return false;
138: }
139: if (this == obj) {
140: return true;
141: }
142: ConcreteBreakdownElement concreteBreakdownElement = (ConcreteBreakdownElement) obj;
143: return new EqualsBuilder().append(this .concreteName,
144: concreteBreakdownElement.concreteName).append(
145: this .breakdownElement,
146: concreteBreakdownElement.breakdownElement).append(
147: this .super ConcreteActivities,
148: concreteBreakdownElement.super ConcreteActivities)
149: .append(this .project, concreteBreakdownElement.project)
150: .append(this .instanciationOrder,
151: concreteBreakdownElement.instanciationOrder)
152: .append(this .displayOrder,
153: concreteBreakdownElement.displayOrder)
154: .isEquals();
155: }
156:
157: /**
158: * Returns a hash code value for the object. This method is supported for
159: * the benefit of hash tables.
160: *
161: * @return the hash code of the current instance of ConcreteBreakdownElement
162: */
163: public int hashCode() {
164: return new HashCodeBuilder(17, 37).append(this .concreteName)
165: .append(this .breakdownElement).append(this .project)
166: .append(this .instanciationOrder).append(
167: this .displayOrder).toHashCode();
168: }
169:
170: /*
171: * Relation between BreakdownElement and ConcreteBreakdownElement.
172: *
173: */
174:
175: /**
176: * Specifies the BreakdownElement related to the ConcreteBreakdownElement.
177: * Links the BreakdownElement to the current ConcreteBreakdownElement.
178: *
179: * @param _breakdownElement
180: * the BreakdownElement to be assigned to the
181: * ConcreteBreakdownElement
182: */
183: public void addBreakdownElement(BreakdownElement _breakdownElement) {
184: this .breakdownElement = _breakdownElement;
185: _breakdownElement.getConcreteBreakdownElements().add(this );
186: }
187:
188: /**
189: * Remove the relation between the ConcreteBreakdownElement and the
190: * specified BreakdownElement.
191: *
192: * @param _breakdownElement
193: * the BreakdownElement to unlinked with the
194: * ConcreteBreakdownElement
195: */
196: public void removeBreakdownElement(
197: BreakdownElement _breakdownElement) {
198: _breakdownElement.getConcreteBreakdownElements().remove(this );
199: this .breakdownElement = null;
200: }
201:
202: /*
203: * Relation between ConcreteActivity and ConcreteBreakdownElement.
204: *
205: */
206:
207: /**
208: * Adds a specified ConcreteActivity in the Collection of super
209: * ConcreteActivities related to the current instance of the class.
210: *
211: * @param _superConcreteActivity
212: * the ConcreteActivity to be add to the Collection of super
213: * ConcreteActivities
214: */
215: public void addSuperConcreteActivity(
216: ConcreteActivity _super ConcreteActivity) {
217: this .getSuperConcreteActivities().add(_super ConcreteActivity);
218: _super ConcreteActivity.getConcreteBreakdownElements().add(this );
219: }
220:
221: /**
222: * Adds the ConcreteBreakdownElement to the Collection of the specified
223: * ConcreteActivities related to .
224: *
225: * @param _superConcreteActivities
226: * the Set of concreteActivities to be add to the existing
227: * Collection
228: */
229: public void addAllSuperActivities(
230: Set<ConcreteActivity> _super ConcreteActivities) {
231: for (ConcreteActivity concreteActivity : _super ConcreteActivities) {
232: concreteActivity.addConcreteBreakdownElement(this );
233: }
234: }
235:
236: /**
237: * Removes the relation between a specified ConcreteActivity and the
238: * ConcreteBreakdownElement.
239: *
240: * @param _superConcreteActivity
241: * the ConcreteActivity to be remove
242: */
243: public void removeSuperConcreteActivity(
244: ConcreteActivity _super ConcreteActivity) {
245: _super ConcreteActivity.getConcreteBreakdownElements().remove(
246: this );
247: this .getSuperConcreteActivities()
248: .remove(_super ConcreteActivity);
249: }
250:
251: /**
252: * Removes the ConcreteBreakdownElement from all the Sets of the
253: * ConcreteActivities related.
254: */
255: public void removeAllSuperConcreteActivities() {
256: for (ConcreteActivity concreteActivity : this
257: .getSuperConcreteActivities())
258: concreteActivity.getConcreteBreakdownElements()
259: .remove(this );
260: this .getSuperConcreteActivities().clear();
261: }
262:
263: /*
264: * Getter & Setter.
265: *
266: */
267:
268: /**
269: * Returns the name of the instance of ConcreteBreakdownElement.
270: *
271: * @return the name of the ConcreteBreakdownElement
272: */
273: public String getConcreteName() {
274: return concreteName;
275: }
276:
277: /**
278: * Initialize the name of the ConcreteBreakdownElement with the String
279: * specified in parameter.
280: *
281: * @param concreteName
282: * the name to be assigned to the ConcreteBreakdownElement
283: */
284: public void setConcreteName(String concreteName) {
285: this .concreteName = concreteName;
286: }
287:
288: /**
289: * Returns the String that identify uniquely an instance of
290: * ConcreteBreakdownElement.
291: *
292: * @return the identifier of the current instance
293: */
294: public String getId() {
295: return this .id;
296: }
297:
298: /**
299: * Initializes the value of the identifier with the specified one.
300: *
301: * @param _id
302: * the identifier to be assigned to the ConcreteBreakdownElement
303: */
304: @SuppressWarnings("unused")
305: protected void setId(String _id) {
306: this .id = _id;
307: }
308:
309: /**
310: * Returns the Set of ConcreteActivity that are related to the
311: * ConcreteBreakdownElement.
312: *
313: * @return the Set of ConcreteActivity of the ConcreteBreakdownElement
314: */
315: public Set<ConcreteActivity> getSuperConcreteActivities() {
316:
317: return super ConcreteActivities;
318: }
319:
320: /**
321: * Initializes the Set of the ConcreteActivity related to the
322: * ConcreteBreakdownElement with the values of the one passed in parameter.
323: *
324: * @param superConcreteActivities
325: * the Set that is assigned to the ConcreteBreakdownElement
326: */
327: public void setSuperConcreteActivities(
328: Set<ConcreteActivity> super ConcreteActivities) {
329: this .super ConcreteActivities = super ConcreteActivities;
330: }
331:
332: /**
333: * Returns the BreakdownElement related to the ConcreteBreakdownElement.
334: *
335: * @return the BreakdownElement assigned to the ConcreteBreakdownElement
336: */
337: public BreakdownElement getBreakdownElement() {
338: return breakdownElement;
339: }
340:
341: /**
342: * Initializes the BreakdownElement of the ConcreteBreakdownElement with the
343: * one passed in parameter.
344: *
345: * @param breakdownElement
346: * the BreakdownElement to be assigned to the
347: * ConcreteBreakdownElement
348: */
349: public void setBreakdownElement(BreakdownElement breakdownElement) {
350: this .breakdownElement = breakdownElement;
351: }
352:
353: /**
354: * Returns the Project that the ConcreteBreakdownElement is assigned to.
355: *
356: * @return the Project assigned to the ConcreteBreakdownElement
357: */
358: public Project getProject() {
359: return project;
360: }
361:
362: /**
363: * Initializes the attribute that defines the Project related to the
364: * ConcreteBreakdownElement.
365: *
366: * @param project
367: * the project to set for the ConcreteBreakdownElement
368: */
369: public void setProject(Project project) {
370: this .project = project;
371: }
372:
373: /**
374: * Returns the order in which the ConcreteBreakdownElement has been
375: * instanciated.
376: *
377: * @return the rank of instanciation of the ConcreteBreakdownElement
378: */
379: public int getInstanciationOrder() {
380: return instanciationOrder;
381: }
382:
383: /**
384: * Defines the rank of instanciation of the ConcreteBreakdownElement.
385: *
386: * @param instanciationOrder
387: * the value of the ConcreteBreakdownElement's rank
388: */
389: public void setInstanciationOrder(int instanciationOrder) {
390: this .instanciationOrder = instanciationOrder;
391: }
392:
393: /**
394: * Returns the order in which the ConcreteBreakdownElement is to be
395: * displayed.
396: *
397: * @return the order of display
398: */
399: public String getDisplayOrder() {
400: return displayOrder;
401: }
402:
403: /**
404: * Initialized the display order of the ConcreteBreakdownElement.
405: *
406: * @param displayOrder
407: * the display order to be assigned to the
408: * ConcreteBreakdownElement
409: */
410: public void setDisplayOrder(String displayOrder) {
411: this.displayOrder = displayOrder;
412: }
413: }
|