blob: 556a9ca3af4e3580f0c685a13d4253cddb707e15 (
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
package com.c2kernel.lifecycle.instance;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.traversal.GraphTraversal;
import com.c2kernel.lookup.AgentPath;
import com.c2kernel.scripting.ScriptingEngineException;
import com.c2kernel.utils.Logger;
/**
* @version $Revision: 1.35 $ $Date: 2005/05/10 15:14:54 $
* @author $Author: abranson $
*/
public class Loop extends XOrSplit
{
/**
* @see java.lang.Object#Object()
*/
public Loop()
{
super();
}
/**
* @see com.c2kernel.lifecycle.instance.WfVertex#loop()
*/
public boolean loop()
{
return true;
}
public void followNext(Next activeNext, AgentPath agent) throws ScriptingEngineException
{
WfVertex v = activeNext.getTerminusVertex();
if (!isInPrev(v))
v.run(agent);
else
{
v.reinit(getID());
v.run(agent);
}
}
/**
* @see com.c2kernel.lifecycle.instance.WfVertex#reinit(int)
*/
public void reinit(int idLoop)
{
Logger.msg(8, "Loop.reinit");
if (idLoop == getID())
return;
else
{
Vertex[] outVertices = getOutGraphables();
for (int j = 0; j < outVertices.length; j++)
{
if (!isInPrev(outVertices[j]))
((WfVertex) outVertices[j]).reinit(idLoop);
}
}
}
/**
* @see com.c2kernel.lifecycle.instance.WfVertex#verify()
*/
public boolean verify()
{
boolean err = super.verify();
Vertex[] nexts = getOutGraphables();
Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
int k = 0;
int l = 0;
Vertex[] brothers = getParent().getChildren();
for (int i = 0; i < brothers.length; i++)
if (brothers[i] instanceof Loop)
l++;
for (int i = 0; i < nexts.length; i++)
{
for (int j = 0; j < anteVertices.length; j++)
if (nexts[i].getID() == anteVertices[j].getID())
k++;
}
if (k != 1 && !(l > 1))
{
mErrors.add("bad number of pointing back nexts");
return false;
}
// if (nexts.length>2) {
// mErrors.add("you must only have 2 nexts");
// return false;
// }
return err;
}
private boolean isInPrev(Vertex vertex)
{
int id = vertex.getID();
Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false);
for (int i = 0; i < anteVertices.length; i++)
{
if (anteVertices[i].getID() == id)
{
return true;
}
}
return false;
}
public boolean isLoop()
{
return true;
}
}
|