Package javax.xml.xpath

Examples of javax.xml.xpath.XPathExpression


    public void testIntentsRef() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        String str = "//sca:composite/sca:component[IntentRefs('sca:confidentiality')]";
        str = normalize(str, "sca");
        // Test the rewrite of xpath so that the self:node() is passed into the SCA function
        XPathExpression exp = xpath.compile(str);
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here


    public void testIntentsRef2() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        String str = " //sca:composite/sca:component[sca:IntentRefs('sca:confidentiality')]";
        str = normalize(str, "sca");
        // Test the rewrite of xpath so that the self:node() is passed into the SCA function
        XPathExpression exp = xpath.compile(str);
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here

    public void testIntentsRef3() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        String str = "   IntentRefs('sca:confidentiality')  ";
        str = normalize(str, "sca");
        // Test the rewrite of xpath so that the self:node() is passed into the SCA function
        XPathExpression exp = xpath.compile(str);
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here

        Assert.assertEquals(1, nodes.getLength());
    }
    @Test
    public void testURIRef() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        XPathExpression exp = xpath.compile(normalize("sca:composite/sca:component[sca:URIRef('AddServiceComponent')]","sca"));
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        // Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here

    }
   
    @Test
    public void testInterfaceRef() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:service[sca:InterfaceRef('AddService')]","sca"));
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        // Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here

    }

    @Test
    public void testOperationRef() throws Exception {
        InputSource xml = new InputSource(getClass().getResourceAsStream("Calculator.composite"));
        XPathExpression exp = xpath.compile(normalize("//sca:composite/sca:component/sca:reference[sca:OperationRef('AddService/add')]","sca"));
        Object result = exp.evaluate(xml, XPathConstants.NODESET);
        Assert.assertTrue(result instanceof NodeList);
        NodeList nodes = (NodeList)result;
        // Assert.assertEquals(1, nodes.getLength());
    }
View Full Code Here

    }

    private static void addAlwaysApplicablePolicySets(PolicySet policySet,
                                                      Document doc,
                                                      int prefixCount) throws XPathExpressionException {
        XPathExpression expression = policySet.getAlwaysAppliesToXPathExpression();
        NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);

        if (result != null) {
            for (int counter = 0; counter < result.getLength(); ++counter) {
                Node aResultNode = result.item(counter);
View Full Code Here

    }

    private static void addApplicablePolicySets(PolicySet policySet,
                                         Document doc,
                                         int prefixCount) throws XPathExpressionException {
        XPathExpression expression = policySet.getAppliesToXPathExpression();
        NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);

        if (result != null) {
            for (int counter = 0; counter < result.getLength(); ++counter) {
                Node aResultNode = result.item(counter);
View Full Code Here

            String rateTable = entry.getDescription().getValue();

            Document doc = builder.parse(new ByteArrayInputStream(rateTable.getBytes()));
            Node node = doc.getDocumentElement();
            XPath path = XPathFactory.newInstance().newXPath();
            XPathExpression exp = path.compile("/TABLE/TR[TD[1]='" + currency.toUpperCase() + "']/TD[2]");
            Node rateNode = (Node)exp.evaluate(node, XPathConstants.NODE);
            double rate = Double.valueOf(rateNode.getTextContent().trim());
            System.out.println("Exchange rate: USD 1.0=" + currency + " " + rate);
            return rate;
        } catch (Exception e) {
            throw new ServiceRuntimeException(e);
View Full Code Here

    /**
     * Evaluates the expression as the given result type
     */
    protected Object evaluateAs(Exchange exchange, QName resultQName) {
        // pool a pre compiled expression from pool
        XPathExpression xpathExpression = pool.poll();
        if (xpathExpression == null) {
            LOG.trace("Creating new XPathExpression as none was available from pool");
            // no avail in pool then create one
            try {
                xpathExpression = createXPathExpression();
View Full Code Here

TOP

Related Classes of javax.xml.xpath.XPathExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.