*/
public static FlowMacroScript loadFlowMacroScript(Element stepElement, String sStepName, Activity activity,
XMLMetadataHelper helper, Machine machine, boolean bFull)
{
Flow flow = activity.getFlow();
FlowMacro macro = flow.getMetadata().findFlowMacro(stepElement.getNodeName());
if (macro == null)
{
return null;
}
if (flow instanceof Workflow && !macro.isWorkflowCompatible() ||
flow instanceof Service && !macro.isServiceCompatible())
{
throw new MetadataException("err.meta." + flow.getPropName() + ".incompatibleMacro",
new Object[]{macro.getName(), flow.getFullName()});
}
FlowMacroScript script = new FlowMacroScript(sStepName);
script.setActivity(activity);
script.setMacro(macro);
NamedNodeMap attributeMap = stepElement.getAttributes();
Set attributeSet = new HashHolder(attributeMap.getLength());
for (int i = 0; i < attributeMap.getLength(); ++i)
{
attributeSet.add(attributeMap.item(i).getNodeName());
}
Object[] args = new Object[macro.getArgumentCount()];
for (int i = 0, n = macro.getArgumentCount(); i < n; ++i)
{
FlowMacro.Argument arg = macro.getArgument(i);
String sValue = stepElement.getAttribute(arg.getName());
if (arg.getType() == null || arg.getType() == Primitive.ANY)
{
Object value = helper.parse(sValue, arg.getType() == null,
flow.getPosMap(), Undefined.VALUE,
machine.getGlobalEnvironment());
if (bFull)
{
script.setArgumentValue(i, value);
}
args[i] = (value == Undefined.VALUE) ? arg.getDefault() : value;
}
else
{
if (sValue == null)
{
args[i] = arg.getDefault();
if (bFull)
{
script.setArgumentValue(i, Undefined.VALUE);
}
}
else
{
args[i] = arg.getType().convert(sValue);
if (bFull)
{
script.setArgumentValue(i, args[i]);
}
}
}
if (args[i] == Undefined.VALUE)
{
throw new MetadataException("err.meta." + flow.getPropName() + ".missingMacroArg",
new Object[]{arg.getName(), macro.getName(), flow.getFullName()});
}
attributeSet.remove(arg.getName());
}
attributeSet.remove("name");
attributeSet.remove("caption");
attributeSet.remove("description");
attributeSet.remove("layout");
if (attributeSet.size() != 0)
{
throw new MetadataException("err.meta." + flow.getPropName() + ".macroArgLookup",
new Object[]{attributeSet.iterator().next(), macro.getName(), flow.getFullName()});
}
script.setBody(new Pair(machine.invoke(macro.getFunction(), args)));
Lookup flowPosMap = flow.getPosMap();
Lookup macroPosMap = macro.getTextPositionMap();
if (flowPosMap != null && macroPosMap != null)
{
for (Lookup.Iterator itr = macroPosMap.iterator(); itr.hasNext();)
{