package com.c2kernel.lifecycle; 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.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("Activity"), "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("Join"), "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, GraphPoint 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 */ @Override public WfVertex instantiate() throws ObjectNotFoundException, InvalidDataException { return instantiate(getName()); } @Override 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 (GraphableVertex graphableVertice : graphableVertices) { WfVertexDef vertex = (WfVertexDef) graphableVertice; if (getChildrenGraphModel().getOutEdges(vertex).length == 0) endingAct++; } if (endingAct > 1) return false; return true; } /** * @see com.c2kernel.graph.model.GraphableVertex#getPath() */ @Override public String getPath() { if (getParent() == null) return getName(); return super.getPath(); } @Override public void setChildrenGraphModel(GraphModel childrenGraph) { super.setChildrenGraphModel(childrenGraph); childrenGraph.setVertexOutlineCreator(new WfVertexDefOutlineCreator()); } //deprecated public String[] getCastorNonLayoutableChildren() { return new String[0]; } public void setCastorNonLayoutableChildren(String[] dummy) { } }