001: /*
002: * JBoss, Home of Professional Open Source
003: * Copyright 2005, JBoss Inc., and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jbpm.taskmgmt.exe;
023:
024: import java.io.Serializable;
025: import java.util.HashSet;
026: import java.util.Iterator;
027: import java.util.Set;
028:
029: import org.jbpm.util.EqualsUtil;
030:
031: public class PooledActor implements Serializable {
032:
033: private static final long serialVersionUID = 1L;
034:
035: long id = 0;
036: int version = 0;
037: protected String actorId = null;
038: protected Set taskInstances = null;
039: protected SwimlaneInstance swimlaneInstance = null;
040:
041: public static Set createPool(String[] actorIds,
042: SwimlaneInstance swimlaneInstance, TaskInstance taskInstance) {
043: Set pooledActors = new HashSet();
044: for (int i = 0; i < actorIds.length; i++) {
045: PooledActor pooledActor = new PooledActor(actorIds[i]);
046: if (swimlaneInstance != null) {
047: pooledActor.setSwimlaneInstance(swimlaneInstance);
048: }
049: if (taskInstance != null) {
050: pooledActor.addTaskInstance(taskInstance);
051: }
052: pooledActors.add(pooledActor);
053: }
054: return pooledActors;
055: }
056:
057: public static Set extractActorIds(Set poooledActors) {
058: Set extractedActorIds = null;
059: if (poooledActors != null) {
060: extractedActorIds = new HashSet();
061: Iterator iter = poooledActors.iterator();
062: while (iter.hasNext()) {
063: PooledActor pooledActor = (PooledActor) iter.next();
064: extractedActorIds.add(pooledActor.getActorId());
065: }
066: }
067: return extractedActorIds;
068: }
069:
070: public PooledActor() {
071: }
072:
073: public PooledActor(String actorId) {
074: this .actorId = actorId;
075: }
076:
077: public void addTaskInstance(TaskInstance taskInstance) {
078: if (taskInstances == null)
079: taskInstances = new HashSet();
080: taskInstances.add(taskInstance);
081: }
082:
083: public Set getTaskInstances() {
084: return taskInstances;
085: }
086:
087: public void removeTaskInstance(TaskInstance taskInstance) {
088: if (taskInstances != null) {
089: taskInstances.remove(taskInstance);
090: }
091: }
092:
093: // equals ///////////////////////////////////////////////////////////////////
094: // hack to support comparing hibernate proxies against the real objects
095: // since this always falls back to ==, we don't need to overwrite the hashcode
096: public boolean equals(Object o) {
097: return EqualsUtil.equals(this , o);
098: }
099:
100: public String toString() {
101: return "PooledActor(" + actorId + ")";
102: }
103:
104: // getters and setters //////////////////////////////////////////////////////
105:
106: public String getActorId() {
107: return actorId;
108: }
109:
110: public void setActorId(String actorId) {
111: this .actorId = actorId;
112: }
113:
114: public SwimlaneInstance getSwimlaneInstance() {
115: return swimlaneInstance;
116: }
117:
118: public void setSwimlaneInstance(SwimlaneInstance swimlaneInstance) {
119: this .swimlaneInstance = swimlaneInstance;
120: }
121:
122: public long getId() {
123: return id;
124: }
125: }
|