int nCookie = m_helper.pushMarker(MetadataValidationException.TYPE_NAME, sElement);
m_helper.pushMarker("step", sStepName);
try
{
Step step;
if (sElement.equals("Action"))
{
if (isWorkflowHandler(element))
{
step = new Trigger(sStepName);
step.setActivity(activity);
loadWorkflowHandler(element, (Handler)step, activity.getFlow());
}
else
{
step = new Script(sStepName);
step.setActivity(activity);
}
String sCleanup = XMLUtil.getStringAttr(element, "cleanup");
if (sCleanup != null)
{
for (StringTokenizer tokenizer = new StringTokenizer(sCleanup); tokenizer.hasMoreTokens();)
{
step.addCleanupAssoc(Symbol.define(tokenizer.nextToken()));
}
}
((Scripted)step).setBody((Pair)m_helper.parse(m_helper.getElementValue(element),
true, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
}
else if (sElement.equals("Timeout"))
{
Timeout timeout = new Timeout(sStepName);
timeout.setActivity(activity);
timeout.setValue(m_helper.parse(XMLUtil.getReqStringAttr(element, "value"),
false, activity.getFlow().getPosMap(), null, m_metadata.getGlobalEnvironment()));
activity.addStep(timeout);
step = new Wait(timeout);
timeout.setNext(step);
}
else if (sElement.equals("Decision"))
{
final Decision decision = new Decision(sStepName);
decision.setActivity(activity);
decision.setManual(XMLUtil.getBooleanAttr(element, "manual", false));
loadDecision(element, decision, m_helper, m_metadata, new BranchLoader()
{
public String getElementName()
{
return "Branch";
}
public Branch createBranch()
{
return new Branch();
}
public void loadActivity(Element element, Activity activity)
{
XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
}
});
step = decision;
}
else if (sElement.equals("Loop"))
{
loadLoop(element, activity, false, m_helper, m_metadata, new ActivityLoader()
{
public void loadActivity(Element element, Activity activity)
{
XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
}
});
step = null;
}
else if (sElement.equals("TryCatch"))
{
TryCatch tryCatch = new TryCatch(sStepName);
step = loadTryCatch(element, tryCatch, activity, m_helper, m_metadata, new ActivityLoader()
{
public void loadActivity(Element element, Activity activity)
{
XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
}
});
}
else if (sElement.equals("Join"))
{
final Fork fork = new Fork(sStepName);
fork.setActivity(activity);
Join join = new Join(fork);
String sType = XMLUtil.getStringAttr(element, "type", "all");
if (sType.equals("all"))
{
join.setAny(false);
}
else if (sType.equals("any"))
{
join.setAny(true);
}
else
{
throw new MetadataException("err.meta.workflow.joinType",
new Object[]{sType, activity.getFlow().getFullName()});
}
XMLUtil.forEachChildElement(element, "Activity", new ElementHandler()
{
public void handleElement(Element activityElement)
{
Concurrent concurrent = new Concurrent();
concurrent.setFork(fork);
loadActivity(activityElement.getFirstChild(), concurrent);
fork.addConcurrent(concurrent);
}
});
activity.addStep(fork);
step = join;
}
else if (sElement.equals("Assignment"))
{
Flow workflow = activity.getFlow();
Assignment assignment = new Assignment(sStepName);
assignment.setActivity(activity);
assignment.setQueue(parseQueueName(XMLUtil.getStringAttr(element, "queue"), activity, m_machine));
assignment.setPriority(m_helper.parse(XMLUtil.getStringAttr(element, "priority"),
false, workflow.getPosMap(), assignment.getPriority(), m_metadata.getGlobalEnvironment()));
assignment.setAssignee(m_helper.parse(XMLUtil.getStringAttr(element, "assignee"),
false, workflow.getPosMap(), assignment.getAssignee(), m_metadata.getGlobalEnvironment()));
assignment.setOwner(m_helper.parse(XMLUtil.getStringAttr(element, "owner"),
false, workflow.getPosMap(), assignment.getOwner(), m_metadata.getGlobalEnvironment()));
assignment.setCaption(m_helper.parse(XMLUtil.getStringAttr(element, "title"),
false, workflow.getPosMap(), XMLUtil.getStringAttr(element, "caption"),
m_metadata.getGlobalEnvironment()));
assignment.setFactory((Pair)m_helper.parse(XMLUtil.getStringAttr(element, "factory"),
true, workflow.getPosMap(), assignment.getFactory(),
m_metadata.getGlobalEnvironment()));
boolean bTarget = loadTarget(element, assignment, Boolean.TRUE, null, false);
activity.addStep(assignment);
if (isWorkflowHandler(element))
{
AutoCompletion unassignment = new AutoCompletion(assignment);
loadWorkflowHandler(element, unassignment, workflow);
step = unassignment;
}
else
{
step = new ManualCompletion(assignment);
}
nextElement = XMLUtil.findFirstElement(element.getNextSibling());
if (nextElement != null)
{
if (nextElement.getNodeName().equals("UIAction"))
{
loadTarget(element, assignment, Boolean.TRUE, null, bTarget);
}
else
{
nextElement = null;
}
}
assignment.setNext(step);
}
else if (sElement.equals("Semaphore"))
{
step = loadSemaphore(element, sStepName, activity, m_machine, new ActivityLoader()
{
public void loadActivity(Element element, Activity activity)
{
XMLMetadataLoader.this.loadActivity(element.getFirstChild(), activity);
}
});
}
else if (sElement.equals("Goto"))
{
step = new Goto();
step.setActivity(activity);
}
else if (sElement.equals("Queue"))
{
final Flow workflow = activity.getFlow();
Assignment assignment = new Assignment(sStepName);
assignment.setActivity(activity);
assignment.setQueue(parseQueueName(XMLUtil.getStringAttr(element, "queue"), activity, m_machine));
assignment.setPriority(m_helper.parse(XMLUtil.getStringAttr(element, "priority"),
false, workflow.getPosMap(), assignment.getPriority(), m_metadata.getGlobalEnvironment()));
assignment.setAssignee(m_helper.parse(XMLUtil.getStringAttr(element, "assignee"),
false, workflow.getPosMap(), assignment.getAssignee(), m_metadata.getGlobalEnvironment()));
assignment.setOwner(m_helper.parse(XMLUtil.getStringAttr(element, "owner"),
false, workflow.getPosMap(), assignment.getOwner(), m_metadata.getGlobalEnvironment()));
assignment.setCaption(m_helper.parse(XMLUtil.getStringAttr(element, "title"),
false, workflow.getPosMap(), XMLUtil.getStringAttr(element, "caption"),
m_metadata.getGlobalEnvironment()));
assignment.setFactory((Pair)m_helper.parse(XMLUtil.getStringAttr(element, "factory"),
true, workflow.getPosMap(), assignment.getFactory(),
m_metadata.getGlobalEnvironment()));
activity.addStep(assignment);
step = loadQueue(element, assignment);
}
else if (sElement.equals("UIAction"))
{
m_helper.restoreMarker(nCookie);
throw new MetadataException("err.meta.workflow.misplacedElement",
new Object[]{sElement, activity.getFlow().getFullName()});
}
else
{
step = loadFlowMacroScript(element, sStepName, activity);
if (step == null)
{
m_helper.restoreMarker(nCookie);
throw new MetadataException("err.meta.workflow.invalidElement",
new Object[]{sElement, activity.getFlow().getFullName()});
}
}
final String sNextStepName = XMLUtil.getStringAttr(element, "next");
if (sNextStepName != null)
{
if (step == null)
{
step = new Goto();
}
final Step fstep = step;
m_flowFixupList.add(new ContextFixup(getHelper())
{
public void fixup()
{
fstep.setNext(activity.getFlow().getFlowStep(sNextStepName));
}
});
}
if (step != null)