Search in sources :

Example 1 with ExtensionContextImpl

use of org.apache.ode.bpel.runtime.ExtensionContextImpl 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;
}
Also used : DataEndpointConfigurationException(org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException) ConfigurationException(org.apache.ode.bpel.explang.ConfigurationException) DataEndpointAgentConfigurationException(org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException) ScopeFrame(org.apache.ode.bpel.runtime.ScopeFrame) QName(javax.xml.namespace.QName) OXPath20ExpressionBPEL20(org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ExtensionContextImpl(org.apache.ode.bpel.runtime.ExtensionContextImpl) NodeList(org.w3c.dom.NodeList) List(java.util.List) EvaluationException(org.apache.ode.bpel.explang.EvaluationException) ExprEvaluationContextImpl(org.apache.ode.bpel.runtime.ExprEvaluationContextImpl) OExpressionLanguage(org.apache.ode.bpel.o.OExpressionLanguage)

Aggregations

Iterator (java.util.Iterator)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 OXPath20ExpressionBPEL20 (org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20)1 ConfigurationException (org.apache.ode.bpel.explang.ConfigurationException)1 EvaluationException (org.apache.ode.bpel.explang.EvaluationException)1 OExpressionLanguage (org.apache.ode.bpel.o.OExpressionLanguage)1 ExprEvaluationContextImpl (org.apache.ode.bpel.runtime.ExprEvaluationContextImpl)1 ExtensionContextImpl (org.apache.ode.bpel.runtime.ExtensionContextImpl)1 ScopeFrame (org.apache.ode.bpel.runtime.ScopeFrame)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 DataEndpointAgentConfigurationException (org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException)1 DataEndpointConfigurationException (org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationException)1