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.jpdl.exe;
023:
024: import java.io.*;
025: import java.util.*;
026:
027: import org.jbpm.context.exe.*;
028: import org.jbpm.graph.def.*;
029: import org.jbpm.graph.exe.*;
030:
031: public class MilestoneInstance implements Serializable {
032:
033: private static final long serialVersionUID = 1L;
034:
035: protected long id = 0;
036: protected String name = null;
037: protected boolean reached = false;
038: protected Token token = null;
039: protected Collection listeners = null;
040:
041: public MilestoneInstance() {
042: }
043:
044: public MilestoneInstance(String name) {
045: this .name = name;
046: }
047:
048: public static MilestoneInstance getMilestoneInstance(
049: String milestoneName, Token token) {
050: ContextInstance ci = (ContextInstance) token
051: .getProcessInstance()
052: .getInstance(ContextInstance.class);
053: MilestoneInstance mi = (MilestoneInstance) ci.getVariable(
054: milestoneName, token);
055: if (mi == null) {
056: mi = new MilestoneInstance(milestoneName);
057: mi.setToken(token);
058: ci.setVariable(milestoneName, mi);
059: }
060: return mi;
061: }
062:
063: public void addListener(Token token) {
064: if (listeners == null)
065: listeners = new HashSet();
066: listeners.add(token);
067: }
068:
069: public void notifyListeners() {
070: if (listeners != null) {
071: // for every token that was waiting for this milestone
072: Iterator iter = listeners.iterator();
073: while (iter.hasNext()) {
074: Token token = (Token) iter.next();
075: // leave the milestone node
076: Node node = token.getNode();
077: ExecutionContext executionContext = new ExecutionContext(
078: token);
079: node.leave(executionContext);
080: }
081: }
082: }
083:
084: public long getId() {
085: return id;
086: }
087:
088: public void setId(long id) {
089: this .id = id;
090: }
091:
092: public Collection getListeners() {
093: return listeners;
094: }
095:
096: public void setListeners(Collection listeners) {
097: this .listeners = listeners;
098: }
099:
100: public String getName() {
101: return name;
102: }
103:
104: public void setName(String name) {
105: this .name = name;
106: }
107:
108: public boolean isReached() {
109: return reached;
110: }
111:
112: public void setReached(boolean reached) {
113: this .reached = reached;
114: }
115:
116: public Token getToken() {
117: return token;
118: }
119:
120: public void setToken(Token token) {
121: this.token = token;
122: }
123: }
|