in taverna-external-tool-activity/src/main/java/org/apache/taverna/activities/externaltool/desc/ToolDescription.java [316:454]
private void readFromXmlElement(Element programNode) throws DeserializationException {
if (programNode.getName().compareToIgnoreCase("program") != 0)
throw new DeserializationException("Expected <program>, read '" + programNode.getName() + "'");
setUsecaseid(programNode.getAttributeValue("name"));
setDescription(programNode.getAttributeValue("description"));
setCommand(programNode.getAttributeValue("command"));
String timeoutStr = programNode.getAttributeValue("timeout");
if (timeoutStr != null)
setExecutionTimeoutInSeconds(Integer.parseInt(timeoutStr));
timeoutStr = programNode.getAttributeValue("preparing_timeout");
if (timeoutStr != null)
setPreparingTimeoutInSeconds(Integer.parseInt(timeoutStr));
String includeStdInStr = programNode.getAttributeValue("includeStdIn");
if (includeStdInStr != null && !includeStdInStr.isEmpty()) {
setIncludeStdIn(includeStdInStr.equals("true"));
}
String includeStdOutStr = programNode.getAttributeValue("includeStdOut");
if (includeStdOutStr != null && !includeStdOutStr.isEmpty()) {
setIncludeStdOut(includeStdOutStr.equals("true"));
}
String includeStdErrStr = programNode.getAttributeValue("includeStdErr");
if (includeStdErrStr != null && !includeStdErrStr.isEmpty()) {
setIncludeStdErr(includeStdErrStr.equals("true"));
}
for (Object cur_ob : programNode.getChildren()) {
Element cur = (Element) cur_ob;
String name = cur.getAttributeValue("name");
String type = cur.getName();
boolean binary = false;
if (null != cur.getAttributeValue("binary") && cur.getAttributeValue("binary").equalsIgnoreCase("true")) {
binary = true;
}
boolean list = false;
if (null != cur.getAttributeValue("list") && cur.getAttributeValue("list").equalsIgnoreCase("true")) {
list = true;
}
boolean concatenate = false;
if (null != cur.getAttributeValue("concatenate") && cur.getAttributeValue("concatenate").equalsIgnoreCase("true")) {
concatenate = true;
}
boolean forceCopy = false;
if (null != cur.getAttributeValue("forceCopy") && cur.getAttributeValue("forceCopy").equalsIgnoreCase("true")) {
forceCopy = true;
}
Element inner = null;
String innerType = null, tag = null, path = null;
if (cur.getChildren().size() > 0) {
inner = (Element) cur.getChildren().get(0);
innerType = inner.getName();
tag = inner.getAttributeValue("tag");
path = inner.getAttributeValue("path");
}
// build mime type declaration list
ArrayList<String> mime = new ArrayList<String>();
for (Object child : cur.getChildren()) {
Element curChild = (Element) child;
if (curChild.getName().equalsIgnoreCase("mime")) {
mime.add(curChild.getAttributeValue("type"));
}
}
if (type.equalsIgnoreCase("static")) {
ScriptInputStatic si = new ScriptInputStatic();
Element content = cur.getChild("content");
if (content == null)
throw new DeserializationException("FIXME: script tag without embedded content tag");
si.setUrl(content.getAttributeValue("url"));
if (si.getUrl() == null)
si.setContent(content.getText());
fillInputDescription(si, binary, forceCopy, innerType, tag, path);
getStatic_inputs().add(si);
} else if (type.equalsIgnoreCase("input")) {
ScriptInputUser indesc = new ScriptInputUser();
indesc.setList(list);
indesc.setMime(mime);
indesc.setConcatenate(concatenate);
fillInputDescription(indesc, binary, forceCopy, innerType, tag, path);
getInputs().put(Tools.sanitiseName(name), indesc);
} else if (type.equalsIgnoreCase("output")) {
ScriptOutput outdesc = new ScriptOutput();
outdesc.setMime(mime);
boolean ok = true;
if (null == innerType) {
// don't know what to do
throw new DeserializationException("FIXME: Found null == innerType for output, is this the bug?");
} else if (innerType.equalsIgnoreCase("fromfile")) {
outdesc.setPath(path);
outdesc.setBinary(binary);
} else {
throw new DeserializationException("Problem reading output port: unknown innerType '" + innerType + "'");
}
if (ok) {
getOutputs().put(Tools.sanitiseName(name), outdesc);
}
} else if (type.equalsIgnoreCase("rte") || type.equalsIgnoreCase("re")) {
getREs().add(new RuntimeEnvironmentConstraint(name, cur.getAttributeValue("relation")));
} else if (type.equalsIgnoreCase("group")) {
group = name;
} else if (type.equalsIgnoreCase("test")) {
test_local = cur.getAttributeValue("local");
} else if (type.equalsIgnoreCase("icon")) {
icon_url = cur.getAttributeValue("url");
} else if (type.equalsIgnoreCase("queue")) {
for (Object child_ob : cur.getChildren()) {
Element child = (Element) child_ob;
if (child.getName().equalsIgnoreCase("prefer"))
getQueue_preferred().add(child.getAttributeValue("url"));
else if (child.getName().equalsIgnoreCase("deny"))
getQueue_deny().add(child.getAttributeValue("url"));
else
throw new DeserializationException("Error while reading usecase " + this.getUsecaseid() + ": invalid queue entry");
}
} else if (type.equalsIgnoreCase("command")) {
// i like to have the ability to inject complete shell script
// fragments into the use case,
// so this should be replace and should allow multiple lines
if ((getCommand() != null) && !getCommand().isEmpty()) {
throw new DeserializationException("You have specified both command attribute and command tag.");
}
setCommand(cur.getText());
} else if (type.equalsIgnoreCase("validReturnCodes")) {
String codeString = cur.getAttributeValue("codes");
if (codeString != null) {
setReturnCodesAsText(codeString);
}
}
else {
throw new DeserializationException("Unexpected and uninterpreted attribute " + type);
}
}
}