Example usage for org.apache.commons.jxpath JXPathContext newContext

List of usage examples for org.apache.commons.jxpath JXPathContext newContext

Introduction

In this page you can find the example usage for org.apache.commons.jxpath JXPathContext newContext.

Prototype

public static JXPathContext newContext(Object contextBean) 

Source Link

Document

Creates a new JXPathContext with the specified object as the root node.

Usage

From source file:org.fireflow.pdl.fpdl20.test.service.callback.TheCallbackServiceProcessTest1.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??//from ww  w  . jav a 2s.  c  o m
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //3???      
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //??
            try {

                ProcessInstance processInstance = stmt.startProcess(process.getId(), bizId, null);

                if (processInstance != null) {
                    processInstanceId = processInstance.getId();
                }

            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (WorkflowProcessNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InvalidOperationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;
        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"http://www.fireflow.org/junit/callbackservice\">"
            + "<cal:id>" + bizId + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");

    Assert.assertEquals(responseResult, response2);

    this.assertResult(session);
}

From source file:org.fireflow.pdl.fpdl20.test.service.callback.WebserviceStartProcessTest.java

@Test
public void testCallbackService() {
    final WorkflowSession session = WorkflowSessionFactory.createWorkflowSession(runtimeContext,
            FireWorkflowSystem.getInstance());
    final WorkflowStatement stmt = session.createWorkflowStatement(FpdlConstants.PROCESS_TYPE_FPDL20);

    //0??/*  w w w  .j a v  a2  s  . c o  m*/
    final WorkflowProcess process = getWorkflowProcess();

    //1???
    transactionTemplate.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus arg0) {

            //?
            try {

                stmt.uploadProcessObject(process, true, null, null);
            } catch (InvalidModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    });

    //2?CallbackManagerinit?Webservice
    WebServiceManager callbackManager = this.runtimeContext.getEngineModule(WebServiceManager.class,
            FpdlConstants.PROCESS_TYPE_FPDL20);
    try {
        callbackManager.publishAllCallbackServices();
    } catch (WebservicePublishException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    //JaxwsWebservice      
    Environment env = runtimeContext.getEngineModule(Environment.class, FpdlConstants.PROCESS_TYPE_FPDL20);
    URL url = null;
    try {
        String contextPath = env.getWebserviceContextPath();
        if (!contextPath.startsWith("/")) {
            contextPath = "/" + contextPath;
        }
        if (!contextPath.endsWith("/")) {
            contextPath = contextPath + "/";
        }
        String address = "http://" + env.getWebserviceIP() + ":" + Integer.toString(env.getWebservicePort())
                + contextPath;

        url = new URL(address + serviceQName.getLocalPart() + "?wsdl");
    } catch (Exception e) {
        e.printStackTrace();
    }

    javax.xml.ws.Service jawsService = javax.xml.ws.Service.create(url, serviceQName);
    Dispatch<Source> dispatch = jawsService.createDispatch(portQName, Source.class,
            javax.xml.ws.Service.Mode.PAYLOAD);

    String messageStr = "<cal:acceptRequest  xmlns:cal=\"" + targetNsUri + "\">" + "<cal:id>" + bizId
            + "</cal:id>" + "<cal:approveResult>" + approveResult + "</cal:approveResult>"
            + "</cal:acceptRequest>";
    java.io.ByteArrayInputStream byteInStream = new java.io.ByteArrayInputStream(messageStr.getBytes());
    StreamSource source = new StreamSource(byteInStream);

    Source response = dispatch.invoke(source);

    DOMResult result = new DOMResult();
    //      StreamResult result = new StreamResult(System.out);
    Transformer transformer = null;
    try {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        transformer = transformerFactory.newTransformer();
        transformer.transform(response, result);
    } catch (TransformerConfigurationException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    } catch (TransformerException e) {
        throw new RuntimeException("Couldn't parse response stream.", e);
    }

    Document theResponsePayload = (Document) result.getNode();
    Assert.assertNotNull(theResponsePayload);
    JXPathContext jxpathContext = JXPathContext.newContext(theResponsePayload);
    jxpathContext.registerNamespace("ns0", targetNsUri);
    String response2 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response2");
    String response1 = (String) jxpathContext.getValue("ns0:acceptResponse/ns0:response1");
    Assert.assertEquals(responseResult, response2);

    Assert.assertNotNull(response1);

    this.processInstanceId = response1;

    this.assertResult(session);
}

From source file:org.firesoa.common.jxpath.XMLModelTestCase.java

protected JXPathContext createContext(Object obj) {
    JXPathContext context = JXPathContext.newContext(obj);
    context.setFactory(getAbstractFactory());
    context.registerNamespace("product", "productNS");
    context.registerNamespace(Constants.DEFAULT_NS_PREFIX, "http://test/");//default namespace
    return context;
}

From source file:org.freud.analysed.css.jdom.CssJdomParser.java

@SuppressWarnings("unchecked")
static Iterable<CssRule> parseCssRules(final Reader reader) throws RecognitionException, IOException {
    List<CssRule> cssRuleList = new ArrayList<CssRule>();
    Document root = parseCssToDocument(reader);
    JXPathContext context = JXPathContext.newContext(root.getRootElement());
    List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE");
    for (Element element : cssRuleElementList) {
        final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0);
        cssRuleList.add(cssRuleJdom);//  w ww  .  j a v a  2  s  . c om
        for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) {
            cssRuleList.add(new CssRuleJdom(element, i));
        }
    }
    return cssRuleList;
}

From source file:org.freud.analysed.css.jdom.CssRuleJdom.java

@SuppressWarnings("unchecked")
private void parseDeclarations() {
    cssDeclarationList = new ArrayList<CssDeclaration>();
    JXPathContext context = JXPathContext.newContext(ruleElement);
    List<Element> cssSelectorElementList = (List<Element>) context
            .selectNodes("/" + CssTokenType.PROPERTY.name());

    for (Element element : cssSelectorElementList) {
        cssDeclarationList.add(new CssDeclarationJdom(this, element));
    }//  w  w w . j ava 2s. c  om
}

From source file:org.freud.analysed.javasource.jdom.AnnotationJdom.java

private String getAnnotationValueForElement(final Element element) {
    final JXPathContext context = JXPathContext.newContext(element);
    final Element expr = (Element) context.selectSingleNode("/" + JavaSourceTokenType.EXPR.name() + "/*");
    if (expr != null) {
        return expr.getText();
    } else {// ww w  . j  ava 2  s .c o  m
        final List<Element> exprList = context.selectNodes("//" + JavaSourceTokenType.EXPR.name() + "/*");
        StringBuilder sb = new StringBuilder("{");
        for (Element item : exprList) {
            sb.append(item.getText()).append(",");
        }
        sb.setCharAt(sb.length() - 1, '}');
        return sb.toString();
    }
}

From source file:org.freud.analysed.javasource.jdom.ClassDeclarationJdom.java

@SuppressWarnings("unchecked")
public Map<String, ClassDeclaration> getInnerClassDeclarationByNameMap() {
    if (innerClassDeclarationByNameMap == null) {
        JXPathContext context = JXPathContext.newContext(classDeclElement);
        innerClassDeclarationByNameMap = new LinkedHashMap<String, ClassDeclaration>();
        for (JavaSourceTokenType tokenType : POSSIBLE_CLASS_DECLARATION_TYPES) {
            final String tokenName = tokenType.getName();
            List<Element> innerClassElementList = context
                    .selectNodes("/" + CLASS_TOP_LEVEL_SCOPE.getName() + "/" + tokenName);
            for (Element innerClassElement : innerClassElementList) {
                ClassDeclaration innerClass = new ClassDeclarationJdom(innerClassElement,
                        DeclarationType.valueOf(tokenName), this);
                innerClassDeclarationByNameMap.put(innerClass.getName(), innerClass);
            }/*  ww  w.  j  a v a2  s  . com*/
        }
    }
    return innerClassDeclarationByNameMap;
}

From source file:org.freud.analysed.javasource.jdom.ClassDeclarationJdom.java

public Map<String, List<MethodDeclaration>> getMethodDeclarationListByNameMap() {
    if (methodDeclarationListByNameMap == null) {
        JXPathContext context = JXPathContext.newContext(classDeclElement);
        methodDeclarationListByNameMap = new LinkedHashMap<String, List<MethodDeclaration>>();
        getMethodDeclarationListByNameMap(context);
    }/*from  w w  w  .j a  va  2 s.c o  m*/
    return methodDeclarationListByNameMap;
}

From source file:org.freud.analysed.javasource.jdom.ClassDeclarationJdom.java

public String getSuperClassName() {
    if (superClassName == NOT_RETRIEVED) {
        JXPathContext context = JXPathContext.newContext(classDeclElement);

        final Element superClassElement = (Element) context
                .selectSingleNode("/" + EXTENDS_CLAUSE.getName() + "//" + IDENT.getName());
        superClassName = (null == superClassElement) ? null : superClassElement.getValue();
    }// w w w.j av a 2 s  . c  o  m
    return superClassName;
}

From source file:org.freud.analysed.javasource.jdom.CodeBlockJdom.java

@Override
@SuppressWarnings("unchecked")
public Map<String, List<MethodCall>> getMethodCallByMethodNameMap() {
    if (methodCallByMethodNameMap == null) {
        methodCallByMethodNameMap = new HashMap<String, List<MethodCall>>();
        JXPathContext context = JXPathContext.newContext(codeBlockElement);
        List<Element> methodCallElementList = context
                .selectNodes("//" + JavaSourceTokenType.METHOD_CALL.getName());
        for (Element methodCallElement : methodCallElementList) {
            final MethodCall methodCall = new MethodCallJdom(methodCallElement);
            List<MethodCall> methodCallList = methodCallByMethodNameMap.get(methodCall.getMethodName());
            if (methodCallList == null) {
                methodCallList = new LinkedList<MethodCall>();
                methodCallByMethodNameMap.put(methodCall.getMethodName(), methodCallList);
            }//from w  ww . jav a 2s .  com
            methodCallList.add(methodCall);
        }
    }
    return methodCallByMethodNameMap;
}