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: *
005: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006: * General Public License as published by the Free Software Foundation; either version 2 of the License,
007: * or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: * GNU General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public License along with this program; if not,
014: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015: */
016:
017: package wilos.model.misc.wilosuser;
018:
019: import java.util.HashSet;
020: import java.util.Set;
021:
022: import org.apache.commons.lang.builder.EqualsBuilder;
023: import org.apache.commons.lang.builder.HashCodeBuilder;
024:
025: import wilos.model.spem2.process.Process;
026:
027: /**
028: * This class represents a process manager using Wilos.
029: *
030: */
031: public class ProcessManager extends WilosUser implements Cloneable {
032:
033: private Set<Process> processesManaged;
034:
035: /**
036: * Constructor.
037: *
038: */
039: public ProcessManager() {
040: super ();
041: this .processesManaged = new HashSet<Process>();
042: }
043:
044: /**
045: * Returns a copy of the current instance of ProcessManager
046: *
047: * @return a copy of the ProcessManager
048: * @throws CloneNotSupportedException
049: */
050: @Override
051: public ProcessManager clone() throws CloneNotSupportedException {
052: ProcessManager processManager = new ProcessManager();
053: processManager.copy(this );
054: return processManager;
055: }
056:
057: /**
058: * Copy the values of the specified ProcessManager into the current instance of the
059: * class.
060: *
061: * @param _processManager
062: * The ProcessManager to copy.
063: */
064: protected void copy(final ProcessManager _processManager) {
065: super .copy(_processManager);
066: }
067:
068: /**
069: * Defines if the specified Object is the same or has the same values as the
070: * current instance of the class.
071: *
072: * @param _obj
073: * the Object to be compare to the ProcessManager
074: * @return true if the specified Object is the same, false otherwise
075: */
076: public boolean equals(Object _obj) {
077: if (_obj instanceof ProcessManager == false) {
078: return false;
079: }
080: if (this == _obj) {
081: return true;
082: }
083: ProcessManager processManager = (ProcessManager) _obj;
084: return new EqualsBuilder().appendSuper(
085: super .equals(processManager)).append(
086: this .processesManaged, processManager.processesManaged)
087: .isEquals();
088: }
089:
090: /**
091: * Returns a hash code value for the object. This method is supported for
092: * the benefit of hash tables.
093: *
094: * @return the hash code of the current instance of ProcessManager
095: */
096: public int hashCode() {
097: return new HashCodeBuilder(17, 37)
098: .appendSuper(super .hashCode()).toHashCode();
099: }
100:
101: /**
102: * Getter of processManaged.
103: * @return the processManaged.
104: */
105: public Set<Process> getProcessesManaged() {
106: return this .processesManaged;
107: }
108:
109: /**
110: * Setter of processManaged.
111: * @param _processManaged The processManaged to set.
112: */
113: public void setProcessesManaged(Set<Process> _processManaged) {
114: this .processesManaged = _processManaged;
115: }
116:
117: /**
118: *
119: * Add a managed process to the process set
120: *
121: * @param project
122: */
123: public void addManagedProcess(Process _process) {
124: this .processesManaged.add(_process);
125: _process.setProcessManager(this );
126: }
127:
128: /**
129: *
130: * Remove a managed process
131: *
132: * @param project
133: */
134: public void removeManagedProcess(Process _process) {
135: _process.setProcessManager(null);
136: this .processesManaged.remove(_process);
137: }
138:
139: /**
140: *
141: * Remove all managed processes
142: *
143: */
144: public void removeAllManagedProcess() {
145: for (Process process : this.processesManaged) {
146: process.removeProcessManager(this);
147: }
148: this.processesManaged.clear();
149: }
150: }
|