package com.c2kernel.lifecycle; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.graph.model.Vertex; import com.c2kernel.graph.traversal.GraphTraversal; import com.c2kernel.lifecycle.instance.Activity; import com.c2kernel.lifecycle.instance.WfVertex; import com.c2kernel.utils.KeyValuePair; import com.c2kernel.utils.LocalObjectLoader; /** * @version $Revision: 1.46 $ $Date: 2005/10/05 07:39:36 $ * @author $Author: abranson $ */ public class ActivitySlotDef extends WfVertexDef { private String activityDef; /** * Method setActivityDef. * * @param oActivityDef */ public void setActivityDef(String oActivityDef) { activityDef = oActivityDef; } /** * Method getActivityDef. * * @return String */ public String getActivityDef() { return activityDef; } /** * @see java.lang.Object#Object() */ public ActivitySlotDef() { getProperties().put("Name", ""); getProperties().put("Version", 0); } public ActivityDef getTheActivityDef() throws ObjectNotFoundException, InvalidDataException { ActivityDef actDef = LocalObjectLoader.getActDef(getActivityDef(), getVersionNumberProperty("Version")); if (actDef instanceof CompositeActivityDef) mIsComposite = true; return actDef; } /** * @see com.c2kernel.lifecycle.WfVertexDef#verify() */ /** launch the verification of the ActivityDef */ @Override public boolean verify() { mErrors.removeAllElements(); boolean err = true; int nbInEdgres = getInEdges().length; int nbOutEdges = getOutEdges().length; if (nbInEdgres == 0 && this.getID() != getParent().getChildrenGraphModel().getStartVertexId()) { mErrors.add("Unreachable"); err = false; } else if (nbInEdgres > 1) { mErrors.add("Bad nb of previous"); err = false; } else if (nbOutEdges > 1) { mErrors.add("too many next"); err = false; } else if (nbOutEdges == 0) { if (!((CompositeActivityDef) getParent()).hasGoodNumberOfActivity()) { mErrors.add("too many endpoints"); err = false; } } else { Vertex[] outV = getOutGraphables(); Vertex[] anteVertices = GraphTraversal.getTraversal(getParent().getChildrenGraphModel(), this, GraphTraversal.kUp, false); boolean errInLoop = false; for (Vertex element : outV) { for (Vertex anteVertice : anteVertices) if (!loop() && element.getID() == anteVertice.getID()) errInLoop = true; } if (errInLoop) { mErrors.add("Problem in Loop"); err = false; } } return err; } /** * Method getNextWfVertices. * * @return WfVertexDef[] */ public WfVertexDef[] getNextWfVertices() { return (WfVertexDef[]) getOutGraphables(); } /** * @see com.c2kernel.graph.model.GraphableVertex#isLayoutable() */ /** * @see com.c2kernel.graph.model.GraphableVertex#getIsLayoutable() */ public boolean isLayoutable() { return true; } /** * Method getInfo. * * @return CastorHashMap */ public void configureInstance(Activity act) { KeyValuePair[] k = getProperties().getKeyValuePairs(); for (KeyValuePair element : k) act.getProperties().put(element.getKey(), element.getValue()); act.setCentrePoint(getCentrePoint()); act.setOutlinePoints(getOutlinePoints()); act.setInEdgeIds(getInEdgeIds()); act.setOutEdgeIds(getOutEdgeIds()); act.setName(getActName()); act.setID(getID()); } public String getActName() { return (String) getProperties().get("Name"); } @Override public WfVertex instantiate() throws ObjectNotFoundException, InvalidDataException { Activity newActivity = (Activity)getTheActivityDef().instantiate(); configureInstance(newActivity); return newActivity; } }