ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r190347 - in /webservices/axis/trunk/archive/java/scratch/Ajith/XPath: src/ src/org/ src/org/apache/ src/org/apache/axis/ src/org/apache/axis/om/ src/org/apache/axis/om/xpath/ test/ test/org/ test/org/apache/ test/org/apache/axis/ test/org/apache/axis/om/ test/org/apache/axis/om/xpath/
Date Mon, 13 Jun 2005 04:30:27 GMT
Author: ajith
Date: Sun Jun 12 21:30:24 2005
New Revision: 190347

URL: http://svn.apache.org/viewcvs?rev=190347&view=rev
Log:
Adding the XPath implementation based on Jaxen. This implementation still have some problems
with the namespaces but works for the default case. This is not checked in to the main tree
due to dependency on the Jaxen jars.

Added:
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMNavigator.java
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMXPath.java
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/
    webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/XPathTester.java

Added: webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMNavigator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMNavigator.java?rev=190347&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMNavigator.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMNavigator.java
Sun Jun 12 21:30:24 2005
@@ -0,0 +1,180 @@
+package org.apache.axis.om.xpath;
+
+import org.jaxen.XPath;
+import org.jaxen.UnsupportedAxisException;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMAttribute;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+*
+*/
+public class OMNavigator extends org.jaxen.DefaultNavigator{
+
+    private static OMNavigator navigator = null;
+
+    public static OMNavigator getInstance(){
+        if (navigator==null){
+            navigator = new OMNavigator();
+        }
+        return navigator;
+    }
+
+
+    private OMNavigator() {
+    }
+
+
+    public String getAttributeName(Object o) {
+        OMAttribute attrib = (OMAttribute)o;
+        return attrib.getLocalName();
+    }
+
+
+    public String getAttributeNamespaceUri(Object o) {
+        OMAttribute attrib = (OMAttribute)o;
+        OMNamespace ns = attrib.getNamespace();
+        if (ns==null || ns.getName()==null){
+            return "";
+        }else{
+            return ns.getName();
+        }
+    }
+
+
+    public String getAttributeQName(Object o) {
+        OMAttribute attrib = (OMAttribute)o;
+        QName qName = attrib.getQName();
+        if (qName.getPrefix()== null ||"".equals(qName.getPrefix())){
+            return qName.getLocalPart();
+        }else{
+            return qName.getPrefix() + ":"+qName.getLocalPart();
+        }
+    }
+
+
+    public String getAttributeStringValue(Object o) {
+        OMAttribute attrib = (OMAttribute)o;
+        return attrib.getValue();
+    }
+
+
+    public String getCommentStringValue(Object o) {
+        return null; //not supported yet
+    }
+
+
+    public String getElementName(Object o) {
+        OMElement elt = (OMElement)o;
+        return elt.getLocalName();
+    }
+
+    public String getElementNamespaceUri(Object o) {
+        OMElement elt = (OMElement)o;
+        OMNamespace ns = elt.getNamespace();
+        if (ns==null || ns.getName()==null){
+            return "";
+        }else{
+            return ns.getName();
+        }
+    }
+
+    public String getElementQName(Object o) {
+        OMElement elt = (OMElement)o;
+        QName qName = elt.getQName();
+        if (qName.getPrefix()== null ||"".equals(qName.getPrefix())){
+            return qName.getLocalPart();
+        }else{
+            return qName.getPrefix() + ":"+qName.getLocalPart();
+        }
+    }
+
+    public String getElementStringValue(Object o) {
+        OMElement elt = (OMElement)o;
+        return elt.getText();
+    }
+
+    public String getNamespacePrefix(Object o) {
+        OMNamespace ns = (OMNamespace)o;
+        return ns.getPrefix();
+    }
+
+    public String getNamespaceStringValue(Object o) {
+        OMNamespace ns = (OMNamespace)o;
+        return ns.getName();
+    }
+
+    public String getTextStringValue(Object o) {
+        OMText txt = (OMText)o;
+        return txt.getText();
+    }
+
+    public boolean isAttribute(Object o) {
+        return (o instanceof OMAttribute);
+    }
+
+    public boolean isComment(Object o) {
+        return false;  //still not supported
+    }
+
+    public boolean isDocument(Object o) {
+        return false;  //still not supported
+    }
+
+    public boolean isElement(Object o) {
+        return (o instanceof OMElement);
+    }
+
+    public boolean isNamespace(Object o) {
+        return (o instanceof OMNamespace);
+    }
+
+    public boolean isProcessingInstruction(Object o) {
+        return false; //PI's not supported yet
+    }
+
+    public boolean isText(Object o) {
+        return (o instanceof OMText);  //To change body of implemented methods use File |
Settings | File Templates.
+    }
+
+    public XPath parseXPath(String s) throws org.saxpath.SAXPathException {
+        return new OMXPath(s);
+    }
+
+    public Iterator getAttributeAxisIterator(Object contextNode) throws UnsupportedAxisException
{
+
+        if ( ! ( contextNode instanceof OMElement ) ){
+            return null;
+        }
+
+        OMElement elem = (OMElement) contextNode;
+        return elem.getAttributes();
+    }
+
+    public Iterator getChildAxisIterator(Object contextNode) throws UnsupportedAxisException
{
+        if ( contextNode instanceof OMElement ){
+            return ((OMElement)contextNode).getChildren();
+        }else{
+            return null;
+        }
+    }
+
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMXPath.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMXPath.java?rev=190347&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMXPath.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/XPath/src/org/apache/axis/om/xpath/OMXPath.java
Sun Jun 12 21:30:24 2005
@@ -0,0 +1,27 @@
+package org.apache.axis.om.xpath;
+
+import org.jaxen.BaseXPath;
+import org.jaxen.JaxenException;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class OMXPath extends BaseXPath{
+    public OMXPath(String xpath) throws JaxenException {
+         super(xpath,OMNavigator.getInstance());
+    }
+}

Added: webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/XPathTester.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/XPathTester.java?rev=190347&view=auto
==============================================================================
--- webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/XPathTester.java
(added)
+++ webservices/axis/trunk/archive/java/scratch/Ajith/XPath/test/org/apache/axis/om/xpath/XPathTester.java
Sun Jun 12 21:30:24 2005
@@ -0,0 +1,101 @@
+package org.apache.axis.om.xpath;
+
+import junit.framework.TestCase;
+import org.apache.axis.om.OMAbstractFactory;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMNamespace;
+import org.jaxen.XPath;
+
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 
+ */
+public class XPathTester extends TestCase{
+    private static final String CHILD1_TEXT = "I am child 1";
+    private static final String CHILD2_TEXT = "I am child 2";
+
+    public XPathTester(String s) {
+        super(s);
+    }
+
+    private OMElement rootElement =null;
+
+    protected void setUp() throws Exception {
+        super.setUp();    //To change body of overridden methods use File | Settings | File
Templates.
+    }
+
+    public void testXPathWithoutNs() throws Exception{
+        //create an OM tree
+        OMFactory fac = OMAbstractFactory.getOMFactory();
+        OMNamespace ns = fac.createOMNamespace("",null);
+        OMElement rootElement = fac.createOMElement("root",ns);
+
+        OMElement child1 = fac.createOMElement("child1",ns);
+        child1.setText(CHILD1_TEXT);
+        OMElement child2 = fac.createOMElement("child2",ns);
+        child2.setText(CHILD2_TEXT);
+        OMElement child11 = fac.createOMElement("child11",ns);
+        child11.setText(CHILD1_TEXT);
+        OMElement child21 = fac.createOMElement("child21",ns);
+        child21.setText(CHILD2_TEXT);
+
+        child1.addChild(child11);
+        child2.addChild(child21);
+
+        rootElement.addChild(child1);
+        rootElement.addChild(child2);
+
+
+        XPath xpath = new OMXPath("child1");
+        Object selectedNode = xpath.selectSingleNode(rootElement);
+        assertNotNull(selectedNode) ;
+        assertEquals(((OMElement)selectedNode).getText(),CHILD1_TEXT);
+
+
+        xpath = new OMXPath("child2/child21");
+        selectedNode = xpath.selectSingleNode(rootElement);
+        assertNotNull(selectedNode) ;
+        assertEquals(((OMElement)selectedNode).getText(),CHILD2_TEXT);
+
+
+
+
+    }
+
+//    public void testXPathWithNs() throws Exception{
+//        //create an OM tree
+//        OMFactory fac = OMAbstractFactory.getOMFactory();
+//        OMNamespace ns = fac.createOMNamespace("urn:myNs","ns1");
+//        OMElement rootElement = fac.createOMElement("root",ns);
+//
+//        OMElement child1 = fac.createOMElement("child1",ns);
+//        child1.setText(CHILD1_TEXT);
+//        OMElement child2 = fac.createOMElement("child2",ns);
+//        child2.setText(CHILD2_TEXT);
+//
+//        rootElement.addChild(child1);
+//        rootElement.addChild(child2);
+//
+//        //create the Xpath
+//        XPath xpath = new OMXPath("child1");
+//        Object selectedNode = xpath.selectSingleNode(rootElement);
+//        assertNotNull(selectedNode) ;
+//        assertEquals(((OMElement)selectedNode).getText(),CHILD1_TEXT);
+//
+//    }
+
+}



Mime
View raw message