params.put (pn, frag);
} catch (SAXException e) {
String m = "Cannot convert JDOM to W3C DOM: "
+ e.getMessage ();
logger.error (m, e);
throw new ToolInvocationException (m);
} catch (TransformerConfigurationException e) {
String m = "Cannot convert JDOM to W3C DOM: "
+ e.getMessage ();
logger.error (m, e);
throw new ToolInvocationException (m);
}
}
}
} else if (xmlParameterMode == XMLArgumentTypeProvider.XML_AS_JDOM) {
for (Iterator i = params.keySet().iterator(); i.hasNext();) {
String pn = (String)i.next();
Object v = params.get (pn);
if (v instanceof SAXEventBuffer) {
try {
SAXHandler sh = new SAXHandler ();
convertWithTempRoot(sh, (SAXEventBuffer)v);
Element temporaryRoot
= sh.getDocument().getRootElement();
params.put (pn, temporaryRoot.getChildren());
} catch (SAXException e) {
logger.error (e.getMessage(), e);
throw new ToolInvocationException (e.getMessage());
}
}
}
}
// invoke
if (agent instanceof ContextRequester) {
((ContextRequester)agent).setToolAgentContext (agentContext);
}
if (logger.isDebugEnabled()) {
logger.debug ("Invoking " + this.toString()
+ " with " + formalParameters
+ " and " + params);
}
try {
agent.invoke(activity, formalParameters, params);
} catch (CannotExecuteException e) {
if (logger.isDebugEnabled()) {
logger.debug ("Invocation resulted in: " + e.toString());
}
// try to find mapping
if (e.getCause() != null && exceptionMappings != null) {
for (Iterator i = exceptionMappings.iterator(); i.hasNext();) {
ExceptionMapping m = (ExceptionMapping)i.next ();
if (m.getJavaException().isInstance(e.getCause())) {
if (m.getProcessException() == null) {
break;
}
ResultProvider.ExceptionResult eres
= new ResultProvider.ExceptionResult
(m.getProcessException(), m.getSuspendActivity());
if (logger.isDebugEnabled()) {
logger.debug
("Exception mapped to: " + eres.toString());
}
return new InvocationResult (eres);
}
}
}
throw new ToolInvocationException
("Cannot invoke tool, tool reports: " + e.getMessage(), e);
}
// maybe get result
if (agent instanceof ResultProvider) {
Object res = ((ResultProvider)agent).result ();
if (res != null
&& !(res instanceof Map)
&& !(res instanceof ExceptionResult)) {
throw new ToolInvocationException
(toString() + " returns result that is neither"
+ " Map nor ExceptionResult");
}
if (logger.isDebugEnabled()) {
logger.debug("Invocation result is: " + res);