summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/CompositeActivityDef.java
blob: a46cc50aaeccb3ce97eee7729f08ea20bf28d50c (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package com.c2kernel.lifecycle;
import java.awt.Point;

import com.c2kernel.common.InvalidDataException;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.graph.model.GraphModel;
import com.c2kernel.graph.model.GraphPoint;
import com.c2kernel.graph.model.GraphableVertex;
import com.c2kernel.graph.model.TypeNameAndConstructionInfo;
import com.c2kernel.lifecycle.gui.model.WfVertexDefOutlineCreator;
import com.c2kernel.lifecycle.instance.CompositeActivity;
import com.c2kernel.lifecycle.instance.Next;
import com.c2kernel.lifecycle.instance.WfVertex;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
/**
 * @version $Revision: 1.93 $ $Date: 2005/10/05 07:39:36 $
 * @author $Author: abranson $
 */
public class CompositeActivityDef extends ActivityDef
{
	private final TypeNameAndConstructionInfo[] mVertexTypeNameAndConstructionInfo =
		{
			new TypeNameAndConstructionInfo(Language.translate("Atomic"), "Atomic"),
			new TypeNameAndConstructionInfo(Language.translate("Composite"), "Composite"),
			new TypeNameAndConstructionInfo(Language.translate("AND Split"), "And"),
			new TypeNameAndConstructionInfo(Language.translate("OR Split"), "Or"),
			new TypeNameAndConstructionInfo(Language.translate("XOR Split"), "XOr"),
			new TypeNameAndConstructionInfo(Language.translate("Junction"), "Join"),
			new TypeNameAndConstructionInfo(Language.translate("Loop"), "Loop"),
			};
	private final TypeNameAndConstructionInfo[] mEdgeTypeNameAndConstructionInfo =
		{
			new TypeNameAndConstructionInfo(Language.translate("Next Edge"), "Next")
		};
	public TypeNameAndConstructionInfo[] getVertexTypeNameAndConstructionInfo()
	{
		return mVertexTypeNameAndConstructionInfo;
	}
	public TypeNameAndConstructionInfo[] getEdgeTypeNameAndConstructionInfo()
	{
		return mEdgeTypeNameAndConstructionInfo;
	}

	public CompositeActivityDef()
	{
		super();
		setChildrenGraphModel(new GraphModel(new WfVertexDefOutlineCreator()));
		setIsComposite(true);
	}

	/**
	 * Method addNextDef.
	 * 
	 * @param origin
	 * @param terminus
	 * @return NextDef
	 */
	public NextDef addNextDef(WfVertexDef origin, WfVertexDef terminus)
	{
		NextDef returnNxt = new NextDef(origin, terminus);
		getChildrenGraphModel().addEdgeAndCreateId(returnNxt, origin, terminus);
		return returnNxt;
	}
	/**
	 * Method addExistingActivityDef.
	 * 
	 * @param actDef
	 * @param point
	 */
	public ActivitySlotDef addExistingActivityDef(String name, ActivityDef actDef, GraphPoint point)
	{
		changed = true;
		ActivitySlotDef child = new ActivitySlotDef();
		addChild(child, point);
		actDef.linkToSlot(child, actDef.getName(), name);
        return child;
	}
	/**
	 * Method newChild.
	 * 
	 * @param Name
	 * @param Type
	 * @param location
	 * @return WfVertexDef
	 */
	public WfVertexDef newChild(String Name, String Type, Point location)
	{
		changed = true;
		WfVertexDef child;
		if (Type.equals("Or"))
		{
			child = new OrSplitDef();
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("XOr"))
		{
			child = new XOrSplitDef();
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("And"))
		{
			child = new AndSplitDef();
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("Loop"))
		{
			child = new LoopDef();
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("Atomic"))
		{
			child = new ActivitySlotDef();
			ActivityDef act = new ActivityDef();
			act.changed = true;
			addChild(child, location);
			act.linkToSlot((ActivitySlotDef) child, Name, Name);
			act.getProperties().put("Description", Name);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("Join"))
		{
			child = new JoinDef();
			child.getProperties().put("Type", "Join");
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else if (Type.equals("Route"))
		{
			child = new JoinDef();
			child.getProperties().put("Type", "Route");
			addChild(child, location);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		else
		{
			child = new ActivitySlotDef();
			CompositeActivityDef act = new CompositeActivityDef();
			act.changed = true;
			addChild(child, location);
			act.linkToSlot((ActivitySlotDef) child, Name, Name);
			Logger.msg(5, Type + " " + child.getID() + " added to " + this.getID());
		}
		return child;
	}
	/**
	 * Method instantiateAct.
	 * 
	 * @return CompositeActivity
	 */
	public WfVertex instantiate() throws ObjectNotFoundException, InvalidDataException {
		return instantiate(getName());
	}
	
	public WfVertex instantiate(String name) throws ObjectNotFoundException, InvalidDataException
	{
		CompositeActivity cAct = new CompositeActivity();
        cAct.setType(getName());
        cAct.setName(name);
        GraphableVertex[] vertexDefs = getLayoutableChildren();
		WfVertex[] wfVertices = new WfVertex[vertexDefs.length];
		for (int i = 0; i < vertexDefs.length; i++)
		{
			WfVertexDef vertDef = (WfVertexDef)vertexDefs[i];
			wfVertices[i] = vertDef.instantiate();
			wfVertices[i].setParent(cAct);
		}
		Next[] nexts = new Next[getChildrenGraphModel().getEdges().length];
		for (int i = 0; i < getChildrenGraphModel().getEdges().length; i++)
		{
			NextDef nextDef = (NextDef) getChildrenGraphModel().getEdges()[i];
			nexts[i] = nextDef.instantiate();
			nexts[i].setParent(cAct);
		}
		cAct.getChildrenGraphModel().setStartVertexId(getChildrenGraphModel().getStartVertexId());
		cAct.getChildrenGraphModel().setEdges(nexts);
		cAct.getChildrenGraphModel().setVertices(wfVertices);
		cAct.getChildrenGraphModel().setNextId(getChildrenGraphModel().getNextId());
		cAct.getChildrenGraphModel().resetVertexOutlines();
		return cAct;
	}

	/**
	 * Method hasGoodNumberOfActivity.
	 * 
	 * @return boolean
	 */
	
	public boolean hasGoodNumberOfActivity()
	{
		int endingAct = 0;
		GraphableVertex[] graphableVertices = this.getLayoutableChildren();
		if (graphableVertices != null)
			for (int i = 0; i < graphableVertices.length; i++)
			{
				WfVertexDef vertex = (WfVertexDef) graphableVertices[i];
				if (getChildrenGraphModel().getOutEdges(vertex).length == 0)
					endingAct++;
			}
		if (endingAct > 1)
			return false;
		return true;
	}

	/**
	 * @see com.c2kernel.graph.model.GraphableVertex#getPath()
	 */
	public String getPath()
	{
		if (getParent() == null)
			return getName();
		return super.getPath();
	}
	
	//deprecated
	public String[] getCastorNonLayoutableChildren() {
		return new String[0];
	}
	
	public void setCastorNonLayoutableChildren(String[] dummy) { }
}