summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/instance/OrSplit.java
blob: f0fcdd5c11320aeadad9f1f0b21cc27845afaecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.c2kernel.lifecycle.instance;
import java.util.StringTokenizer;

import com.c2kernel.graph.model.DirectedEdge;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
/**
 * @version $Revision: 1.22 $ $Date: 2005/05/10 15:14:54 $
 * @author $Author: abranson $
 */
public class OrSplit extends Split
{
	/**
	 * @see java.lang.Object#Object()
	 */
	public OrSplit()
	{
		super();
	}
	public void runNext(AgentPath agent) throws ScriptingEngineException
	{
		String nexts =
			this
				.evaluateScript((String) getProperties().get("RoutingScriptName"), (String) getProperties().get("RoutingScriptVersion"))
				.toString();
		StringTokenizer tok = new StringTokenizer(nexts, ",");
		Logger.msg(7, tok.countTokens() + " nexts to activate:" + nexts);
		int active = 0;
		try
		{
			DirectedEdge[] outEdges = getOutEdges();
            AdvancementCalculator adv = new AdvancementCalculator();
            adv.calculate((CompositeActivity)getParent());
			while (tok.hasMoreTokens())
			{
				String thisNext = tok.nextToken();
				Logger.msg(7, "Finding next " + thisNext);
				for (int i = 0; i < outEdges.length; i++)
				{
					Next nextEdge = (Next) outEdges[i];
					if (thisNext != null && thisNext.equals(nextEdge.getProperties().get("Alias")))
					{
                        WfVertex term = nextEdge.getTerminusVertex();
                        term.run(agent);
						Logger.msg(7, "Running " + nextEdge.getProperties().get("Alias"));
						active++;
					}
				}
			}
			// if no active nexts throw exception
		}
		catch (Exception e)
		{
			Logger.error(e);
		}
		if (active == 0)
			throw new ScriptingEngineException("No nexts were activated!");
	}
    
   
}