use of org.apache.ode.bpel.explang.ConfigurationException in project carbon-business-process by wso2.
the class AnalyticsPublisherExtensionOperation method evaluateXPathExpression.
private String evaluateXPathExpression(ExtensionContext context, String xpath, Element element) throws FaultException {
String result = "";
QName qnVariableData = new QName(Namespaces.BPEL11_NS, "getVariableData");
QName qnGetVariableProperty = new QName(Namespaces.BPEL11_NS, "getVariableProperty");
QName qnGetLinkStatus = new QName(Namespaces.BPEL11_NS, "getLinkStatus");
QName qnDoXslTransform = new QName(Namespaces.BPEL11_NS, "getDoXslTransform");
OXPath20ExpressionBPEL20 oexpr = new OXPath20ExpressionBPEL20(context.getInternalInstance().getProcessModel().getOwner(), qnVariableData, qnGetVariableProperty, qnGetLinkStatus, qnDoXslTransform, false);
OExpressionLanguage oExpressionLanguage = new OExpressionLanguage(context.getProcessModel().getOwner(), null);
oExpressionLanguage.expressionLanguageUri = "urn:oasis:names:tc:wsbpel:2.0:sublang:xpath2.0";
oexpr.expressionLanguage = oExpressionLanguage;
oExpressionLanguage.properties.put("runtime-class", "org.apache.ode.bpel.elang.xpath20.runtime.XPath20ExpressionRuntime");
try {
context.getInternalInstance().getExpLangRuntime().registerRuntime(oExpressionLanguage);
} catch (ConfigurationException ex) {
String errMsg = "Error when trying to register xpath runtime";
log.error(errMsg, ex);
handleException(errMsg, ex);
}
oexpr.insertMissingData = true;
ScopeFrame scopeFrame = ((ExtensionContextImpl) context).getScopeFrame();
ExprEvaluationContextImpl exprEvaluationContext = new ExprEvaluationContextImpl(scopeFrame, context.getInternalInstance());
oexpr.vars = (HashMap) context.getVisibleVariables();
oexpr.namespaceCtx = context.getProcessModel().namespaceContext;
try {
oexpr.xpath = xpath;
List resultList = context.getInternalInstance().getExpLangRuntime().evaluate(oexpr, exprEvaluationContext);
if (result != null) {
Iterator iterator = resultList.iterator();
/**
* for analytics publishing to work, there should only be a single node here
*/
while (iterator.hasNext()) {
Node node = ((Node) iterator.next());
if (node.getNodeType() == Node.ELEMENT_NODE) {
result += node.getTextContent();
} else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
result += node.getNodeValue();
}
}
}
} catch (EvaluationException e) {
String errMsg = "Xpath evaluation failed";
log.error(errMsg);
handleException(errMsg, e);
}
return result;
}
Aggregations