summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/lifecycle/CompositeActivityDef.java
diff options
context:
space:
mode:
Diffstat (limited to 'source/com/c2kernel/lifecycle/CompositeActivityDef.java')
-rwxr-xr-xsource/com/c2kernel/lifecycle/CompositeActivityDef.java225
1 files changed, 225 insertions, 0 deletions
diff --git a/source/com/c2kernel/lifecycle/CompositeActivityDef.java b/source/com/c2kernel/lifecycle/CompositeActivityDef.java
new file mode 100755
index 0000000..a46cc50
--- /dev/null
+++ b/source/com/c2kernel/lifecycle/CompositeActivityDef.java
@@ -0,0 +1,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) { }
+}