diff options
Diffstat (limited to 'source/com/c2kernel/lifecycle/instance/ParserWF.java')
| -rwxr-xr-x | source/com/c2kernel/lifecycle/instance/ParserWF.java | 357 |
1 files changed, 357 insertions, 0 deletions
diff --git a/source/com/c2kernel/lifecycle/instance/ParserWF.java b/source/com/c2kernel/lifecycle/instance/ParserWF.java new file mode 100755 index 0000000..c3d718d --- /dev/null +++ b/source/com/c2kernel/lifecycle/instance/ParserWF.java @@ -0,0 +1,357 @@ +package com.c2kernel.lifecycle.instance;
+
+import java.awt.Point;
+import java.io.IOException;
+import java.util.Vector;
+
+import com.c2kernel.lookup.AgentPath;
+import com.c2kernel.utils.CastorHashMap;
+import com.c2kernel.utils.Logger;
+
+/**
+ * @version $Revision: 1.26 $ $Date: 2006/03/03 13:52:21 $
+ * @author $Author: abranson $
+ */
+public class ParserWF
+{
+ static Vector nexts;
+ static String file = "";
+ static int i;
+ static CastorHashMap mInfo = new CastorHashMap();
+
+ /**
+ * Method addStep.
+ * @param act
+ * @param xmlfile
+ * @return CompositeActivity
+ * @throws IOException
+ */
+ /**
+ * @associates <{com.c2kernel.lifecycle.instance.Workflow}>
+ * @label creates
+ */
+ public static CompositeActivity addStep(CompositeActivity act, String xmlfile, AgentPath agent) throws IOException
+ {
+ nexts = new Vector(1, 1);
+ i = 0;
+ file = xmlfile;
+ int c;
+ while (i < file.length() - 5)
+ {
+ if (file.substring(i, i + 5).equals("<STEP"))
+ {
+ readStep(act);
+ }
+ else
+ {
+ i++;
+ }
+ }
+ boolean flag = false;
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ for (int k = j + 1; k < nexts.size(); k++)
+ {
+ if (((String[]) nexts.elementAt(j))[0].equals(((String[]) nexts.elementAt(k))[0]))
+ {
+ int tmp = act.newSplitChild("And", new Point(0, 0)).getID();
+ ((WfVertex) act.search(((String[]) nexts.elementAt(k))[0])).addNext(act.search(tmp));
+ ((Split) act.search(tmp)).addNext((WfVertex) act.search(((String[]) nexts.elementAt(k))[1]));
+ ((Split) act.search(tmp)).addNext((WfVertex) act.search(((String[]) nexts.elementAt(j))[1]));
+ nexts.removeElementAt(k--);
+ flag = true;
+ }
+ }
+ if (flag)
+ {
+ nexts.removeElementAt(j--);
+ }
+ flag = false;
+ }
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ for (int k = j + 1; k < nexts.size(); k++)
+ {
+ if (((String[]) nexts.elementAt(j))[1].equals(((String[]) nexts.elementAt(k))[1]))
+ {
+ int tmp = act.newJoinChild(new Point(0, 0)).getID();
+ ((WfVertex) act.search(((String[]) nexts.elementAt(j))[0])).addNext(act.search(tmp));
+ ((WfVertex) act.search(((String[]) nexts.elementAt(k))[0])).addNext(act.search(tmp));
+ ((Join) act.search(tmp)).addNext(((String[]) nexts.elementAt(j))[1]);
+ nexts.removeElementAt(k--);
+ flag = true;
+ }
+ }
+ if (flag)
+ {
+ nexts.removeElementAt(j--);
+ }
+ flag = false;
+ }
+ for (int j = 0; j < nexts.size(); j++)
+ {
+ Logger.msg(
+ 7,
+ "try to add next " + ((String[]) nexts.elementAt(j))[1] + " to " + ((String[]) nexts.elementAt(j))[0]);
+ ((Activity) act.search(((String[]) nexts.elementAt(j))[0])).addNext(((String[]) nexts.elementAt(j))[1]);
+ }
+ if (act instanceof Workflow)
+ try
+ {
+ act.run(agent);
+ }
+ catch (Exception ex)
+ {
+ Logger.error(ex);
+ }
+ return act;
+ }
+
+ private static void readStep(CompositeActivity parent)
+ {
+ Activity act = null;
+ String[] step = new String[15];
+ for (int j = 0; j < 15; j++)
+ {
+ step[j] = "";
+ }
+ i += 5;
+ while (!file.substring(i, i + 7).equals("</STEP>"))
+ {
+ if (file.substring(i, i + 5).equals("<STEP"))
+ {
+ Logger.msg(7, "<STEP");
+ if (!step[14].equals("done"))
+ {
+ act = parent.newCompChild(step[0], step[12].startsWith("true"), new Point(0, 0));
+ }
+ readStep((CompositeActivity) act);
+ step[14] = "done";
+ }
+ else if (file.substring(i, i + 3).equals("Id="))
+ {
+ Logger.msg(7, "Id=");
+ i += 4;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[0] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("Alias="))
+ {
+ Logger.msg(7, "Alias=");
+ i += 7;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[10] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 9).equals("Resource="))
+ {
+ Logger.msg(7, "Ressource=");
+ i += 10;
+ int j = 0;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[1] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("First="))
+ {
+ Logger.msg(7, "First=");
+ i += 7;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[12] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 3).equals("LC="))
+ {
+ Logger.msg(7, "LC=");
+ i += 4;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[2] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 3).equals("WC="))
+ {
+ Logger.msg(7, "WC=");
+ i += 4;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[3] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 6).equals("Posts="))
+ {
+ Logger.msg(7, "Posts=");
+ i += 7;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[4] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 17).equals("Preparation-Time="))
+ {
+ Logger.msg(7, "Preparation-Time=");
+ i += 18;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[5] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 12).equals("Active-Time="))
+ {
+ Logger.msg(7, "Active-Time=");
+ i += 13;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[6] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 13).equals("OP-Startdate="))
+ {
+ Logger.msg(7, "OP-Startdate=");
+ i += 14;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[7] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 11).equals("OP-Enddate="))
+ {
+ Logger.msg(7, "OP-Enddate=");
+ i += 12;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ step[8] = file.substring(i, i + j);
+ i += (j + 1);
+ }
+ else if (file.substring(i, i + 13).equals("<DESCRIPTION>"))
+ {
+ Logger.msg(7, "<DESCRIPTION>");
+ i += 13;
+ int j = 0;
+ ;
+ while (file.charAt(i + j) != '<')
+ {
+ j++;
+ }
+ step[9] = file.substring(i, i + j);
+ i += (j + 14);
+ }
+ else if (file.substring(i, i + 6).equals("<NEXT>"))
+ {
+ Logger.msg(7, "<NEXT>");
+ i += 6;
+ int j = 0;
+ ;
+ String[] tmp = new String[2];
+ while (file.charAt(i + j) != '<')
+ {
+ j++;
+ }
+ tmp[0] = step[0];
+ tmp[0] = parent.getPath() + "/" + tmp[0];
+ tmp[1] = file.substring(i, i + j);
+ tmp[1] = parent.getPath() + "/" + tmp[1];
+ nexts.addElement(tmp);
+ i += (j + 8);
+ Logger.msg(7, "</NEXT>");
+ }
+ else if (file.substring(i, i + 5).equals("Path="))
+ {
+ Logger.msg(7, "Path=");
+ i += 6;
+ int j = 0;
+ ;
+ step[11] = file.substring(i, i + j);
+ while (file.charAt(i + j) != '"')
+ {
+ j++;
+ }
+ i += (j + 1);
+ }
+ else
+ {
+ i++;
+ }
+ }
+ i += 7;
+ if (!step[14].equals("done"))
+ act = parent.newAtomChild(step[0], step[12].startsWith("true"), new Point(0, 0));
+ Logger.msg(7, "Step Created");
+
+ try
+ {
+ Logger.msg(7, "Starting to create info");
+ if (!step[1].equals(""))
+ act.getProperties().put("Agent ID", step[1]);
+ if (!step[2].equals(""))
+ act.getProperties().put("Lc", step[2]);
+ if (!step[3].equals(""))
+ act.getProperties().put("Wc", step[3]);
+ if (!step[4].equals(""))
+ act.getProperties().put("Posts", step[4]);
+ if (!step[5].equals(""))
+ act.getProperties().put("PreparationTime", step[5]);
+ if (!step[6].equals(""))
+ act.getProperties().put("ActiveTime", step[6]);
+ if (!step[7].equals(""))
+ act.getProperties().put("OpStartdate", step[7]);
+ if (!step[8].equals(""))
+ act.getProperties().put("OpEnddate", step[8]);
+ if (!step[9].equals(""))
+ act.getProperties().put("Description", step[9]);
+ Logger.msg(7, "create info for " + act.getID());
+ Logger.msg(7, "Finished to create info");
+ }
+ catch (Exception e)
+ {
+ Logger.error(e);
+ }
+ file = file.substring(i);
+ i = 0;
+ }
+}
|
