You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by st...@apache.org on 2005/11/03 13:35:27 UTC

svn commit: r330533 - in /webservices/axis2/trunk/java/modules/xml: src/org/apache/axis2/om/ src/org/apache/axis2/om/impl/llom/ test/org/apache/axis2/om/

Author: stevel
Date: Thu Nov  3 04:35:11 2005
New Revision: 330533

URL: http://svn.apache.org/viewcvs?rev=330533&view=rev
Log:
QNAme evaluation w/ test. And some extraction of all test resources into a set of constants. So they can be reused.

Added:
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
Modified:
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
    webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
    webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java Thu Nov  3 04:35:11 2005
@@ -281,4 +281,20 @@
     public String toStringWithConsume() throws XMLStreamException;
 
 
+    /**
+     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
+     *
+     * @param qname                    qname to resolve
+     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
+     * @return null for any failure to extract a qname.
+     */
+    QName resolveQName(String qname, boolean defaultToParentNameSpace);
+
+    /**
+     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
+     * unprefixed qnames resolve to the local namespace
+     * @param qname prefixed qname string to resolve
+     * @return null for any failure to extract a qname.
+     */
+    QName resolveQName(String qname);
 }

Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
+++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Thu Nov  3 04:35:11 2005
@@ -806,4 +806,48 @@
             builder.discard(this);
         }
     }
+
+
+    /**
+     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
+     *
+     * @param qname                    qname to resolve
+     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
+     * @return null for any failure to extract a qname.
+     */
+    public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
+        int colon = qname.indexOf(':');
+        if (colon < 0) {
+            if (defaultToParentNameSpace) {
+                //get the parent ns and use it for the child
+                OMNamespace namespace = this.getNamespace();
+                return new QName(namespace.getName(), qname, namespace.getPrefix());
+            } else {
+                //else things without no prefix are local.
+                return new QName(qname);
+            }
+        }
+        String prefix = qname.substring(0, colon);
+        String local = qname.substring(colon + 1);
+        if (local.length() == 0) {
+            //empy local, exit accordingly
+            return null;
+        }
+
+        OMNamespace namespace = findNamespace(null, prefix);
+        if (namespace == null) {
+            return null;
+        }
+        return new QName(namespace.getName(), local, prefix);
+    }
+
+    /**
+     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
+     * unprefixed qnames resolve to the local namespace
+     * @param qname prefixed qname string to resolve
+     * @return null for any failure to extract a qname.
+     */
+    public QName resolveQName(String qname) {
+        return resolveQName(qname,true);
+    }
 }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java Thu Nov  3 04:35:11 2005
@@ -18,10 +18,7 @@
 
 import org.apache.axis2.soap.SOAPEnvelope;
 
-import java.io.File;
-
 public class BadInputTest extends OMTestCase {
-    File dir = new File(testResourceDir, "badsoap");
 
     public BadInputTest(String testName) {
         super(testName);
@@ -33,7 +30,7 @@
         try {
             SOAPEnvelope soapEnvelope =
                     (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                            new File(dir, "envelopeMissing.xml"))
+                            getTestResourceFile(TestConstants.BAD_ENVELOPE_MISSING))
                     .getDocumentElement();
             OMTestUtils.walkThrough(soapEnvelope);
             fail("this must failed gracefully with OMException or AxisFault");
@@ -48,7 +45,7 @@
         try {
             SOAPEnvelope soapEnvelope =
                     (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                            new File(dir, "haederBodyWrongOrder.xml"))
+                            getTestResourceFile(TestConstants.BAD_HEADER_BODY_WRONG_ORDER))
                     .getDocumentElement();
             OMTestUtils.walkThrough(soapEnvelope);
             fail("this must failed gracefully with OMException or AxisFault");
@@ -93,7 +90,7 @@
         try {
             SOAPEnvelope soapEnvelope =
                     (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                            new File(dir, "twoBodymessage.xml"))
+                            getTestResourceFile(TestConstants.BAD_TWO_BODY))
                     .getDocumentElement();
             OMTestUtils.walkThrough(soapEnvelope);
             fail("this must failed gracefully with OMException or AxisFault");
@@ -108,7 +105,7 @@
         try {
             SOAPEnvelope soapEnvelope =
                     (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                            new File(dir, "twoheaders.xml"))
+                            getTestResourceFile(TestConstants.BAD_TWO_HEADERS))
                     .getDocumentElement();
             OMTestUtils.walkThrough(soapEnvelope);
             fail("this must failed gracefully with OMException or AxisFault");
@@ -123,7 +120,7 @@
         try {
             SOAPEnvelope soapEnvelope =
                     (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                            new File(dir, "wrongSoapNs.xml"))
+                            getTestResourceFile(TestConstants.BAD_WRONG_SOAP_NS))
                     .getDocumentElement();
             OMTestUtils.walkThrough(soapEnvelope);
             fail("this must failed gracefully with OMException or AxisFault");
@@ -133,7 +130,7 @@
 
     }
 
-    
+
 
 
 }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java Thu Nov  3 04:35:11 2005
@@ -29,7 +29,7 @@
             Exception {
         soapEnvelope =
                 (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                        getTestResourceFile("soap/whitespacedMessage.xml"))
+                        getTestResourceFile(TestConstants.WHITESPACE_MESSAGE))
                 .getDocumentElement();
         OMTestUtils.walkThrough(soapEnvelope);
     }
@@ -37,7 +37,7 @@
     public void testMinimalMessage() throws OMException, Exception {
         soapEnvelope =
                 (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                        getTestResourceFile("soap/minimalMessage.xml"))
+                        getTestResourceFile(TestConstants.MINIMAL_MESSAGE))
                 .getDocumentElement();
         OMTestUtils.walkThrough(soapEnvelope);
     }
@@ -45,7 +45,7 @@
     public void testReallyBigMessage() throws OMException, Exception {
         soapEnvelope =
                 (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                        getTestResourceFile("soap/reallyReallyBigMessage.xml"))
+                        getTestResourceFile(TestConstants.REALLY_BIG_MESSAGE))
                 .getDocumentElement();
         OMTestUtils.walkThrough(soapEnvelope);
     }
@@ -53,7 +53,7 @@
     public void testEmptyBodiedMessage() throws OMException, Exception {
         soapEnvelope =
                 (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                        getTestResourceFile("soap/emtyBodymessage.xml"))
+                        getTestResourceFile(TestConstants.EMPTY_BODY_MESSAGE))
                 .getDocumentElement();
         OMTestUtils.walkThrough(soapEnvelope);
     }

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java Thu Nov  3 04:35:11 2005
@@ -34,12 +34,12 @@
 
 public class OMElementCloneTest extends XMLTestCase {
 
-    File dir = new File("test-resources", "soap");
+    File dir = new File(TestConstants.TEST_RESOURCES, TestConstants.SOAP_DIR);
 
     public void testElementCloning() throws Exception {
         SOAPEnvelope soapEnvelope =
                 (SOAPEnvelope) OMTestUtils.getOMBuilder(
-                        new File(dir, "soapmessage.xml"))
+                        new File(dir, TestConstants.SOAPMESSAGE))
                         .getDocumentElement();
         SOAPBody body = soapEnvelope.getBody();
 

Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java?rev=330533&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java (added)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java Thu Nov  3 04:35:11 2005
@@ -0,0 +1,88 @@
+/** (C) Copyright 2005 Hewlett-Packard Development Company, LP
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+ For more information: www.smartfrog.org
+
+ */
+package org.apache.axis2.om;
+
+import org.apache.axis2.soap.SOAPEnvelope;
+
+import javax.xml.namespace.QName;
+
+/**
+ * created 03-Nov-2005 11:46:32
+ */
+
+public class OMElementQNameTest extends OMTestCase {
+
+
+    private static final String WSA= "http://schemas.xmlsoap.org/ws/2004/03/addressing";
+    private static final String SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
+    private static final String XSD = "http://www.w3.org/2001/XMLSchema";
+
+    public OMElementQNameTest(String testName) {
+        super(testName);
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        soapEnvelope =
+                (SOAPEnvelope) OMTestUtils.getOMBuilder(
+                        getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1))
+                        .getDocumentElement();
+    }
+
+    public void testSimpleQName() throws Exception {
+        QName result = soapEnvelope.resolveQName("wsa:To");
+        assertEquals(WSA,result.getNamespaceURI());
+        assertEquals("wsa", result.getPrefix());
+        assertEquals("To", result.getLocalPart());
+    }
+
+    public void testDefaultQName() throws Exception {
+        QName result = soapEnvelope.resolveQName("localonly");
+        assertEquals(SOAPENV, result.getNamespaceURI());
+        assertEquals("soapenv", result.getPrefix());
+        assertEquals("localonly", result.getLocalPart());
+    }
+
+    public void testDefaultQNameCanBeLocal() throws Exception {
+        QName result = soapEnvelope.resolveQName("localonly",false);
+        assertEquals("", result.getNamespaceURI());
+        assertEquals("localonly", result.getLocalPart());
+    }
+
+    public void testNoLocal() throws Exception {
+        assertResolvesToNull("wsa:");
+    }
+
+    public void testNoMatch() throws Exception {
+        assertResolvesToNull("wsa2005:To");
+    }
+
+    public void testNothing() throws Exception {
+        assertResolvesToNull(":");
+    }
+
+
+
+    private void assertResolvesToNull(String qname) {
+        QName result = soapEnvelope.resolveQName(qname);
+        assertNull("Expected "+qname+" to resolve to null",result);
+    }
+
+}

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java Thu Nov  3 04:35:11 2005
@@ -43,7 +43,7 @@
         XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
                 createXMLStreamReader(
                         new FileReader(
-                                getTestResourceFile("soap/soapmessage1.xml")));
+                                getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1)));
         SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
         builder = new StAXSOAPModelBuilder(xmlStreamReader, null);
         envelope = (SOAPEnvelope) builder.getDocumentElement();

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java Thu Nov  3 04:35:11 2005
@@ -41,7 +41,7 @@
     }
 
     protected void setUp() throws Exception {
-        File file = getTestResourceFile("soap/sample1.xml");
+        File file = getTestResourceFile(TestConstants.SAMPLE1);
         XMLStreamReader parser = XMLInputFactory.newInstance()
                 .createXMLStreamReader(new FileReader(file));
         fac = OMAbstractFactory.getSOAP11Factory();

Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java?rev=330533&r1=330532&r2=330533&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java (original)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java Thu Nov  3 04:35:11 2005
@@ -30,7 +30,6 @@
 import java.io.OutputStream;
 
 public abstract class OMTestCase extends AbstractTestCase {
-    protected static final String IN_FILE_NAME = "soap/soapmessage.xml";
     protected StAXSOAPModelBuilder builder;
     protected OMFactory ombuilderFactory;
     protected SOAPFactory soapFactory;
@@ -50,7 +49,7 @@
 
     protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {
         if ("".equals(fileName) || fileName == null) {
-            fileName = IN_FILE_NAME;
+            fileName = TestConstants.SOAP_SOAPMESSAGE;
         }
         XMLStreamReader parser = XMLInputFactory.newInstance()
                 .createXMLStreamReader(

Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java?rev=330533&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java (added)
+++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java Thu Nov  3 04:35:11 2005
@@ -0,0 +1,44 @@
+/*
+ * Copyright 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.
+ */
+package org.apache.axis2.om;
+
+/**
+ * All the various files
+ * created 03-Nov-2005 12:02:12
+ */
+
+public class TestConstants {
+    public static final String TEST_RESOURCES = "test-resources";
+    public static final String SOAP_DIR = "soap";
+    public static final String SOAPMESSAGE = "soapmessage.xml";
+    public static final String SOAP_SOAPMESSAGE = "soap/soapmessage.xml";
+    public static final String SOAP_SOAPMESSAGE1 = "soap/soapmessage1.xml";
+    public static final String SAMPLE1 = "soap/sample1.xml";
+    public static final String WHITESPACE_MESSAGE = "soap/whitespacedMessage.xml";
+    public static final String MINIMAL_MESSAGE = "soap/minimalMessage.xml";
+    public static final String REALLY_BIG_MESSAGE = "soap/reallyReallyBigMessage.xml";
+    public static final String EMPTY_BODY_MESSAGE = "soap/emtyBodymessage.xml";
+    public static final String BAD_WRONG_SOAP_NS = "badsoap/wrongSoapNs.xml";
+    public static final String BAD_TWO_HEADERS = "badsoap/twoheaders.xml";
+    public static final String BAD_TWO_BODY = "badsoap/twoBodymessage.xml";
+    public static final String BAD_ENVELOPE_MISSING = "badsoap/envelopeMissing.xml";
+    public static final String BAD_HEADER_BODY_WRONG_ORDER = "badsoap/haederBodyWrongOrder.xml";
+
+    private TestConstants() {
+    }
+
+
+}



Re: svn commit: r330533 - in /webservices/axis2/trunk/java/modules/xml: src/org/apache/axis2/om/ src/org/apache/axis2/om/impl/llom/ test/org/apache/axis2/om/

Posted by Davanum Srinivas <da...@gmail.com>.
Steve,

Could u please fix the licens on top of OMElementQNameTest.java?

thanks,
dims

On 11/3/05, stevel@apache.org <st...@apache.org> wrote:
> Author: stevel
> Date: Thu Nov  3 04:35:11 2005
> New Revision: 330533
>
> URL: http://svn.apache.org/viewcvs?rev=330533&view=rev
> Log:
> QNAme evaluation w/ test. And some extraction of all test resources into a set of constants. So they can be reused.
>
> Added:
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
> Modified:
>     webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
>     webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java
>
> Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java Thu Nov  3 04:35:11 2005
> @@ -281,4 +281,20 @@
>      public String toStringWithConsume() throws XMLStreamException;
>
>
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     *
> +     * @param qname                    qname to resolve
> +     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
> +     * @return null for any failure to extract a qname.
> +     */
> +    QName resolveQName(String qname, boolean defaultToParentNameSpace);
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     * unprefixed qnames resolve to the local namespace
> +     * @param qname prefixed qname string to resolve
> +     * @return null for any failure to extract a qname.
> +     */
> +    QName resolveQName(String qname);
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Thu Nov  3 04:35:11 2005
> @@ -806,4 +806,48 @@
>              builder.discard(this);
>          }
>      }
> +
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     *
> +     * @param qname                    qname to resolve
> +     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
> +     * @return null for any failure to extract a qname.
> +     */
> +    public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
> +        int colon = qname.indexOf(':');
> +        if (colon < 0) {
> +            if (defaultToParentNameSpace) {
> +                //get the parent ns and use it for the child
> +                OMNamespace namespace = this.getNamespace();
> +                return new QName(namespace.getName(), qname, namespace.getPrefix());
> +            } else {
> +                //else things without no prefix are local.
> +                return new QName(qname);
> +            }
> +        }
> +        String prefix = qname.substring(0, colon);
> +        String local = qname.substring(colon + 1);
> +        if (local.length() == 0) {
> +            //empy local, exit accordingly
> +            return null;
> +        }
> +
> +        OMNamespace namespace = findNamespace(null, prefix);
> +        if (namespace == null) {
> +            return null;
> +        }
> +        return new QName(namespace.getName(), local, prefix);
> +    }
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     * unprefixed qnames resolve to the local namespace
> +     * @param qname prefixed qname string to resolve
> +     * @return null for any failure to extract a qname.
> +     */
> +    public QName resolveQName(String qname) {
> +        return resolveQName(qname,true);
> +    }
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java Thu Nov  3 04:35:11 2005
> @@ -18,10 +18,7 @@
>
>  import org.apache.axis2.soap.SOAPEnvelope;
>
> -import java.io.File;
> -
>  public class BadInputTest extends OMTestCase {
> -    File dir = new File(testResourceDir, "badsoap");
>
>      public BadInputTest(String testName) {
>          super(testName);
> @@ -33,7 +30,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "envelopeMissing.xml"))
> +                            getTestResourceFile(TestConstants.BAD_ENVELOPE_MISSING))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -48,7 +45,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "haederBodyWrongOrder.xml"))
> +                            getTestResourceFile(TestConstants.BAD_HEADER_BODY_WRONG_ORDER))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -93,7 +90,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "twoBodymessage.xml"))
> +                            getTestResourceFile(TestConstants.BAD_TWO_BODY))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -108,7 +105,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "twoheaders.xml"))
> +                            getTestResourceFile(TestConstants.BAD_TWO_HEADERS))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -123,7 +120,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "wrongSoapNs.xml"))
> +                            getTestResourceFile(TestConstants.BAD_WRONG_SOAP_NS))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -133,7 +130,7 @@
>
>      }
>
> -
> +
>
>
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java Thu Nov  3 04:35:11 2005
> @@ -29,7 +29,7 @@
>              Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/whitespacedMessage.xml"))
> +                        getTestResourceFile(TestConstants.WHITESPACE_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -37,7 +37,7 @@
>      public void testMinimalMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/minimalMessage.xml"))
> +                        getTestResourceFile(TestConstants.MINIMAL_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -45,7 +45,7 @@
>      public void testReallyBigMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/reallyReallyBigMessage.xml"))
> +                        getTestResourceFile(TestConstants.REALLY_BIG_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -53,7 +53,7 @@
>      public void testEmptyBodiedMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/emtyBodymessage.xml"))
> +                        getTestResourceFile(TestConstants.EMPTY_BODY_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java Thu Nov  3 04:35:11 2005
> @@ -34,12 +34,12 @@
>
>
>  public class OMElementCloneTest extends XMLTestCase {
>
>
>
> -    File dir = new File("test-resources", "soap");
>
> +    File dir = new File(TestConstants.TEST_RESOURCES, TestConstants.SOAP_DIR);
>
>
>
>      public void testElementCloning() throws Exception {
>
>          SOAPEnvelope soapEnvelope =
>
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
>
> -                        new File(dir, "soapmessage.xml"))
>
> +                        new File(dir, TestConstants.SOAPMESSAGE))
>
>                          .getDocumentElement();
>
>          SOAPBody body = soapEnvelope.getBody();
>
>
>
>
> Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java?rev=330533&view=auto
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java (added)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java Thu Nov  3 04:35:11 2005
> @@ -0,0 +1,88 @@
> +/** (C) Copyright 2005 Hewlett-Packard Development Company, LP
> +
> + This library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + This library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with this library; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +
> + For more information: www.smartfrog.org
> +
> + */
> +package org.apache.axis2.om;
> +
> +import org.apache.axis2.soap.SOAPEnvelope;
> +
> +import javax.xml.namespace.QName;
> +
> +/**
> + * created 03-Nov-2005 11:46:32
> + */
> +
> +public class OMElementQNameTest extends OMTestCase {
> +
> +
> +    private static final String WSA= "http://schemas.xmlsoap.org/ws/2004/03/addressing";
> +    private static final String SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
> +    private static final String XSD = "http://www.w3.org/2001/XMLSchema";
> +
> +    public OMElementQNameTest(String testName) {
> +        super(testName);
> +    }
> +
> +    protected void setUp() throws Exception {
> +        super.setUp();
> +        soapEnvelope =
> +                (SOAPEnvelope) OMTestUtils.getOMBuilder(
> +                        getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1))
> +                        .getDocumentElement();
> +    }
> +
> +    public void testSimpleQName() throws Exception {
> +        QName result = soapEnvelope.resolveQName("wsa:To");
> +        assertEquals(WSA,result.getNamespaceURI());
> +        assertEquals("wsa", result.getPrefix());
> +        assertEquals("To", result.getLocalPart());
> +    }
> +
> +    public void testDefaultQName() throws Exception {
> +        QName result = soapEnvelope.resolveQName("localonly");
> +        assertEquals(SOAPENV, result.getNamespaceURI());
> +        assertEquals("soapenv", result.getPrefix());
> +        assertEquals("localonly", result.getLocalPart());
> +    }
> +
> +    public void testDefaultQNameCanBeLocal() throws Exception {
> +        QName result = soapEnvelope.resolveQName("localonly",false);
> +        assertEquals("", result.getNamespaceURI());
> +        assertEquals("localonly", result.getLocalPart());
> +    }
> +
> +    public void testNoLocal() throws Exception {
> +        assertResolvesToNull("wsa:");
> +    }
> +
> +    public void testNoMatch() throws Exception {
> +        assertResolvesToNull("wsa2005:To");
> +    }
> +
> +    public void testNothing() throws Exception {
> +        assertResolvesToNull(":");
> +    }
> +
> +
> +
> +    private void assertResolvesToNull(String qname) {
> +        QName result = soapEnvelope.resolveQName(qname);
> +        assertNull("Expected "+qname+" to resolve to null",result);
> +    }
> +
> +}
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java Thu Nov  3 04:35:11 2005
> @@ -43,7 +43,7 @@
>          XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
>                  createXMLStreamReader(
>                          new FileReader(
> -                                getTestResourceFile("soap/soapmessage1.xml")));
> +                                getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1)));
>          SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
>          builder = new StAXSOAPModelBuilder(xmlStreamReader, null);
>          envelope = (SOAPEnvelope) builder.getDocumentElement();
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java Thu Nov  3 04:35:11 2005
> @@ -41,7 +41,7 @@
>      }
>
>      protected void setUp() throws Exception {
> -        File file = getTestResourceFile("soap/sample1.xml");
> +        File file = getTestResourceFile(TestConstants.SAMPLE1);
>          XMLStreamReader parser = XMLInputFactory.newInstance()
>                  .createXMLStreamReader(new FileReader(file));
>          fac = OMAbstractFactory.getSOAP11Factory();
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java Thu Nov  3 04:35:11 2005
> @@ -30,7 +30,6 @@
>  import java.io.OutputStream;
>
>  public abstract class OMTestCase extends AbstractTestCase {
> -    protected static final String IN_FILE_NAME = "soap/soapmessage.xml";
>      protected StAXSOAPModelBuilder builder;
>      protected OMFactory ombuilderFactory;
>      protected SOAPFactory soapFactory;
> @@ -50,7 +49,7 @@
>
>      protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {
>          if ("".equals(fileName) || fileName == null) {
> -            fileName = IN_FILE_NAME;
> +            fileName = TestConstants.SOAP_SOAPMESSAGE;
>          }
>          XMLStreamReader parser = XMLInputFactory.newInstance()
>                  .createXMLStreamReader(
>
> Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java?rev=330533&view=auto
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java (added)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java Thu Nov  3 04:35:11 2005
> @@ -0,0 +1,44 @@
> +/*
> + * Copyright 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.
> + */
> +package org.apache.axis2.om;
> +
> +/**
> + * All the various files
> + * created 03-Nov-2005 12:02:12
> + */
> +
> +public class TestConstants {
> +    public static final String TEST_RESOURCES = "test-resources";
> +    public static final String SOAP_DIR = "soap";
> +    public static final String SOAPMESSAGE = "soapmessage.xml";
> +    public static final String SOAP_SOAPMESSAGE = "soap/soapmessage.xml";
> +    public static final String SOAP_SOAPMESSAGE1 = "soap/soapmessage1.xml";
> +    public static final String SAMPLE1 = "soap/sample1.xml";
> +    public static final String WHITESPACE_MESSAGE = "soap/whitespacedMessage.xml";
> +    public static final String MINIMAL_MESSAGE = "soap/minimalMessage.xml";
> +    public static final String REALLY_BIG_MESSAGE = "soap/reallyReallyBigMessage.xml";
> +    public static final String EMPTY_BODY_MESSAGE = "soap/emtyBodymessage.xml";
> +    public static final String BAD_WRONG_SOAP_NS = "badsoap/wrongSoapNs.xml";
> +    public static final String BAD_TWO_HEADERS = "badsoap/twoheaders.xml";
> +    public static final String BAD_TWO_BODY = "badsoap/twoBodymessage.xml";
> +    public static final String BAD_ENVELOPE_MISSING = "badsoap/envelopeMissing.xml";
> +    public static final String BAD_HEADER_BODY_WRONG_ORDER = "badsoap/haederBodyWrongOrder.xml";
> +
> +    private TestConstants() {
> +    }
> +
> +
> +}
>
>
>


--
Davanum Srinivas : http://wso2.com/blogs/

Re: svn commit: r330533 - in /webservices/axis2/trunk/java/modules/xml: src/org/apache/axis2/om/ src/org/apache/axis2/om/impl/llom/ test/org/apache/axis2/om/

Posted by Davanum Srinivas <da...@gmail.com>.
Steve,

Could u please fix the licens on top of OMElementQNameTest.java?

thanks,
dims

On 11/3/05, stevel@apache.org <st...@apache.org> wrote:
> Author: stevel
> Date: Thu Nov  3 04:35:11 2005
> New Revision: 330533
>
> URL: http://svn.apache.org/viewcvs?rev=330533&view=rev
> Log:
> QNAme evaluation w/ test. And some extraction of all test resources into a set of constants. So they can be reused.
>
> Added:
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
> Modified:
>     webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
>     webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
>     webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java
>
> Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/OMElement.java Thu Nov  3 04:35:11 2005
> @@ -281,4 +281,20 @@
>      public String toStringWithConsume() throws XMLStreamException;
>
>
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     *
> +     * @param qname                    qname to resolve
> +     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
> +     * @return null for any failure to extract a qname.
> +     */
> +    QName resolveQName(String qname, boolean defaultToParentNameSpace);
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     * unprefixed qnames resolve to the local namespace
> +     * @param qname prefixed qname string to resolve
> +     * @return null for any failure to extract a qname.
> +     */
> +    QName resolveQName(String qname);
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/src/org/apache/axis2/om/impl/llom/OMElementImpl.java Thu Nov  3 04:35:11 2005
> @@ -806,4 +806,48 @@
>              builder.discard(this);
>          }
>      }
> +
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     *
> +     * @param qname                    qname to resolve
> +     * @param defaultToParentNameSpace flag that controls behaviour when there is no namespace.
> +     * @return null for any failure to extract a qname.
> +     */
> +    public QName resolveQName(String qname, boolean defaultToParentNameSpace) {
> +        int colon = qname.indexOf(':');
> +        if (colon < 0) {
> +            if (defaultToParentNameSpace) {
> +                //get the parent ns and use it for the child
> +                OMNamespace namespace = this.getNamespace();
> +                return new QName(namespace.getName(), qname, namespace.getPrefix());
> +            } else {
> +                //else things without no prefix are local.
> +                return new QName(qname);
> +            }
> +        }
> +        String prefix = qname.substring(0, colon);
> +        String local = qname.substring(colon + 1);
> +        if (local.length() == 0) {
> +            //empy local, exit accordingly
> +            return null;
> +        }
> +
> +        OMNamespace namespace = findNamespace(null, prefix);
> +        if (namespace == null) {
> +            return null;
> +        }
> +        return new QName(namespace.getName(), local, prefix);
> +    }
> +
> +    /**
> +     * Turn a prefix:local qname string into a proper QName, evaluating it in the OMElement context
> +     * unprefixed qnames resolve to the local namespace
> +     * @param qname prefixed qname string to resolve
> +     * @return null for any failure to extract a qname.
> +     */
> +    public QName resolveQName(String qname) {
> +        return resolveQName(qname,true);
> +    }
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/BadInputTest.java Thu Nov  3 04:35:11 2005
> @@ -18,10 +18,7 @@
>
>  import org.apache.axis2.soap.SOAPEnvelope;
>
> -import java.io.File;
> -
>  public class BadInputTest extends OMTestCase {
> -    File dir = new File(testResourceDir, "badsoap");
>
>      public BadInputTest(String testName) {
>          super(testName);
> @@ -33,7 +30,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "envelopeMissing.xml"))
> +                            getTestResourceFile(TestConstants.BAD_ENVELOPE_MISSING))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -48,7 +45,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "haederBodyWrongOrder.xml"))
> +                            getTestResourceFile(TestConstants.BAD_HEADER_BODY_WRONG_ORDER))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -93,7 +90,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "twoBodymessage.xml"))
> +                            getTestResourceFile(TestConstants.BAD_TWO_BODY))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -108,7 +105,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "twoheaders.xml"))
> +                            getTestResourceFile(TestConstants.BAD_TWO_HEADERS))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -123,7 +120,7 @@
>          try {
>              SOAPEnvelope soapEnvelope =
>                      (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                            new File(dir, "wrongSoapNs.xml"))
> +                            getTestResourceFile(TestConstants.BAD_WRONG_SOAP_NS))
>                      .getDocumentElement();
>              OMTestUtils.walkThrough(soapEnvelope);
>              fail("this must failed gracefully with OMException or AxisFault");
> @@ -133,7 +130,7 @@
>
>      }
>
> -
> +
>
>
>  }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/MessagesTest.java Thu Nov  3 04:35:11 2005
> @@ -29,7 +29,7 @@
>              Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/whitespacedMessage.xml"))
> +                        getTestResourceFile(TestConstants.WHITESPACE_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -37,7 +37,7 @@
>      public void testMinimalMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/minimalMessage.xml"))
> +                        getTestResourceFile(TestConstants.MINIMAL_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -45,7 +45,7 @@
>      public void testReallyBigMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/reallyReallyBigMessage.xml"))
> +                        getTestResourceFile(TestConstants.REALLY_BIG_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
> @@ -53,7 +53,7 @@
>      public void testEmptyBodiedMessage() throws OMException, Exception {
>          soapEnvelope =
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
> -                        getTestResourceFile("soap/emtyBodymessage.xml"))
> +                        getTestResourceFile(TestConstants.EMPTY_BODY_MESSAGE))
>                  .getDocumentElement();
>          OMTestUtils.walkThrough(soapEnvelope);
>      }
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementCloneTest.java Thu Nov  3 04:35:11 2005
> @@ -34,12 +34,12 @@
>
>
>  public class OMElementCloneTest extends XMLTestCase {
>
>
>
> -    File dir = new File("test-resources", "soap");
>
> +    File dir = new File(TestConstants.TEST_RESOURCES, TestConstants.SOAP_DIR);
>
>
>
>      public void testElementCloning() throws Exception {
>
>          SOAPEnvelope soapEnvelope =
>
>                  (SOAPEnvelope) OMTestUtils.getOMBuilder(
>
> -                        new File(dir, "soapmessage.xml"))
>
> +                        new File(dir, TestConstants.SOAPMESSAGE))
>
>                          .getDocumentElement();
>
>          SOAPBody body = soapEnvelope.getBody();
>
>
>
>
> Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java?rev=330533&view=auto
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java (added)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMElementQNameTest.java Thu Nov  3 04:35:11 2005
> @@ -0,0 +1,88 @@
> +/** (C) Copyright 2005 Hewlett-Packard Development Company, LP
> +
> + This library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + This library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with this library; if not, write to the Free Software
> + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> +
> + For more information: www.smartfrog.org
> +
> + */
> +package org.apache.axis2.om;
> +
> +import org.apache.axis2.soap.SOAPEnvelope;
> +
> +import javax.xml.namespace.QName;
> +
> +/**
> + * created 03-Nov-2005 11:46:32
> + */
> +
> +public class OMElementQNameTest extends OMTestCase {
> +
> +
> +    private static final String WSA= "http://schemas.xmlsoap.org/ws/2004/03/addressing";
> +    private static final String SOAPENV = "http://schemas.xmlsoap.org/soap/envelope/";
> +    private static final String XSD = "http://www.w3.org/2001/XMLSchema";
> +
> +    public OMElementQNameTest(String testName) {
> +        super(testName);
> +    }
> +
> +    protected void setUp() throws Exception {
> +        super.setUp();
> +        soapEnvelope =
> +                (SOAPEnvelope) OMTestUtils.getOMBuilder(
> +                        getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1))
> +                        .getDocumentElement();
> +    }
> +
> +    public void testSimpleQName() throws Exception {
> +        QName result = soapEnvelope.resolveQName("wsa:To");
> +        assertEquals(WSA,result.getNamespaceURI());
> +        assertEquals("wsa", result.getPrefix());
> +        assertEquals("To", result.getLocalPart());
> +    }
> +
> +    public void testDefaultQName() throws Exception {
> +        QName result = soapEnvelope.resolveQName("localonly");
> +        assertEquals(SOAPENV, result.getNamespaceURI());
> +        assertEquals("soapenv", result.getPrefix());
> +        assertEquals("localonly", result.getLocalPart());
> +    }
> +
> +    public void testDefaultQNameCanBeLocal() throws Exception {
> +        QName result = soapEnvelope.resolveQName("localonly",false);
> +        assertEquals("", result.getNamespaceURI());
> +        assertEquals("localonly", result.getLocalPart());
> +    }
> +
> +    public void testNoLocal() throws Exception {
> +        assertResolvesToNull("wsa:");
> +    }
> +
> +    public void testNoMatch() throws Exception {
> +        assertResolvesToNull("wsa2005:To");
> +    }
> +
> +    public void testNothing() throws Exception {
> +        assertResolvesToNull(":");
> +    }
> +
> +
> +
> +    private void assertResolvesToNull(String qname) {
> +        QName result = soapEnvelope.resolveQName(qname);
> +        assertNull("Expected "+qname+" to resolve to null",result);
> +    }
> +
> +}
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMNavigatorTest.java Thu Nov  3 04:35:11 2005
> @@ -43,7 +43,7 @@
>          XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance().
>                  createXMLStreamReader(
>                          new FileReader(
> -                                getTestResourceFile("soap/soapmessage1.xml")));
> +                                getTestResourceFile(TestConstants.SOAP_SOAPMESSAGE1)));
>          SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
>          builder = new StAXSOAPModelBuilder(xmlStreamReader, null);
>          envelope = (SOAPEnvelope) builder.getDocumentElement();
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTest.java Thu Nov  3 04:35:11 2005
> @@ -41,7 +41,7 @@
>      }
>
>      protected void setUp() throws Exception {
> -        File file = getTestResourceFile("soap/sample1.xml");
> +        File file = getTestResourceFile(TestConstants.SAMPLE1);
>          XMLStreamReader parser = XMLInputFactory.newInstance()
>                  .createXMLStreamReader(new FileReader(file));
>          fac = OMAbstractFactory.getSOAP11Factory();
>
> Modified: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java?rev=330533&r1=330532&r2=330533&view=diff
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java (original)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/OMTestCase.java Thu Nov  3 04:35:11 2005
> @@ -30,7 +30,6 @@
>  import java.io.OutputStream;
>
>  public abstract class OMTestCase extends AbstractTestCase {
> -    protected static final String IN_FILE_NAME = "soap/soapmessage.xml";
>      protected StAXSOAPModelBuilder builder;
>      protected OMFactory ombuilderFactory;
>      protected SOAPFactory soapFactory;
> @@ -50,7 +49,7 @@
>
>      protected StAXSOAPModelBuilder getOMBuilder(String fileName) throws Exception {
>          if ("".equals(fileName) || fileName == null) {
> -            fileName = IN_FILE_NAME;
> +            fileName = TestConstants.SOAP_SOAPMESSAGE;
>          }
>          XMLStreamReader parser = XMLInputFactory.newInstance()
>                  .createXMLStreamReader(
>
> Added: webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java
> URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java?rev=330533&view=auto
> ==============================================================================
> --- webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java (added)
> +++ webservices/axis2/trunk/java/modules/xml/test/org/apache/axis2/om/TestConstants.java Thu Nov  3 04:35:11 2005
> @@ -0,0 +1,44 @@
> +/*
> + * Copyright 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.
> + */
> +package org.apache.axis2.om;
> +
> +/**
> + * All the various files
> + * created 03-Nov-2005 12:02:12
> + */
> +
> +public class TestConstants {
> +    public static final String TEST_RESOURCES = "test-resources";
> +    public static final String SOAP_DIR = "soap";
> +    public static final String SOAPMESSAGE = "soapmessage.xml";
> +    public static final String SOAP_SOAPMESSAGE = "soap/soapmessage.xml";
> +    public static final String SOAP_SOAPMESSAGE1 = "soap/soapmessage1.xml";
> +    public static final String SAMPLE1 = "soap/sample1.xml";
> +    public static final String WHITESPACE_MESSAGE = "soap/whitespacedMessage.xml";
> +    public static final String MINIMAL_MESSAGE = "soap/minimalMessage.xml";
> +    public static final String REALLY_BIG_MESSAGE = "soap/reallyReallyBigMessage.xml";
> +    public static final String EMPTY_BODY_MESSAGE = "soap/emtyBodymessage.xml";
> +    public static final String BAD_WRONG_SOAP_NS = "badsoap/wrongSoapNs.xml";
> +    public static final String BAD_TWO_HEADERS = "badsoap/twoheaders.xml";
> +    public static final String BAD_TWO_BODY = "badsoap/twoBodymessage.xml";
> +    public static final String BAD_ENVELOPE_MISSING = "badsoap/envelopeMissing.xml";
> +    public static final String BAD_HEADER_BODY_WRONG_ORDER = "badsoap/haederBodyWrongOrder.xml";
> +
> +    private TestConstants() {
> +    }
> +
> +
> +}
>
>
>


--
Davanum Srinivas : http://wso2.com/blogs/