You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2006/10/19 22:05:30 UTC

svn commit: r465755 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java

Author: scheu
Date: Thu Oct 19 13:05:29 2006
New Revision: 465755

URL: http://svn.apache.org/viewvc?view=rev&rev=465755
Log:
WSCOMMONS-113
Contributor: Rich Scheuerle
OMTextImpl changes to accurately and efficiently determine the namespace and localpart.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?view=diff&rev=465755&r1=465754&r2=465755
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Thu Oct 19 13:05:29 2006
@@ -41,6 +41,7 @@
     protected String value = null;
     protected char[] charArray;
 
+    private boolean calcNS;  // Set to true after textNS is calculated
     protected OMNamespace textNS;
 
     protected String mimeType;
@@ -123,6 +124,7 @@
     public OMTextImpl(OMContainer parent, QName text, int nodeType,
                       OMFactory factory) {
         super(parent, factory, true);
+        this.calcNS = true;
         this.textNS = ((OMElementImpl) parent).handleNamespace(text);
         this.value = text == null ? EMTPY_STRING : text.getLocalPart();
         this.nodeType = nodeType;
@@ -219,7 +221,7 @@
      * Returns the value.
      */
     public String getText() throws OMException {
-        if (textNS != null) {
+        if (getNamespace() != null) {
             return getTextString();
         } else if (charArray != null || this.value != null) {
             return getTextFromProperPlace();
@@ -269,13 +271,14 @@
      * Returns the value.
      */
     public QName getTextAsQName() throws OMException {
-        if (textNS != null) {
-            String prefix = textNS.getPrefix();
-            String name = textNS.getNamespaceURI();
+        OMNamespace ns = getNamespace();
+        if (ns != null) { 
+            String prefix = ns.getPrefix();
+            String name = ns.getNamespaceURI();
             if (prefix == null || "".equals(prefix)) {
                 return new QName(name, getTextFromProperPlace());
             } else {
-                return new QName(textNS.getNamespaceURI(), getTextFromProperPlace(), prefix);
+                return new QName(ns.getNamespaceURI(), getTextFromProperPlace(), prefix);
             }
         } else if (this.value != null || charArray != null) {
             return new QName(getTextFromProperPlace());
@@ -307,6 +310,27 @@
 	 * @see org.apache.axiom.om.OMText#getNamespace()
 	 */
 	public OMNamespace getNamespace() {
+        // If the namespace has already been determined, return it
+        // Otherwise calculate the namespace if the text contains a colon and is not detached.
+        if (calcNS) {
+            return textNS;
+        } else {
+            calcNS = true;
+            if (getParent() != null) {
+                String text = getTextFromProperPlace();
+                if (text != null) {
+                    int colon = text.indexOf(':');
+                    if (colon > 0) {
+                        textNS = ((OMElementImpl) getParent()).
+                            findNamespaceURI(text.substring(0,colon));
+                        if (textNS != null) {
+                            charArray = null;
+                            value = text.substring(colon+1);
+                        }
+                    }
+                }
+            }
+        }
 		return textNS;
 	}
 
@@ -342,8 +366,9 @@
      * @return Returns javax.activation.DataHandler
      */
     public Object getDataHandler() {
-        if ((value != null || charArray != null || textNS != null) & isBinary) {
-            String text = textNS == null ? getTextFromProperPlace() : getTextString();
+        OMNamespace ns = getNamespace();
+        if ((value != null || charArray != null || ns != null) & isBinary) {
+            String text = ns == null ? getTextFromProperPlace() : getTextString();
             return org.apache.axiom.attachments.utils.DataHandlerUtils.getDataHandlerFromText(text, mimeType);
         } else {
 
@@ -359,8 +384,9 @@
     }
 
     private String getTextString() {
-        if (textNS != null) {
-            String prefix = textNS.getPrefix();
+        OMNamespace ns = getNamespace();
+        if (ns != null) {
+            String prefix = ns.getPrefix();
             if (prefix == null || "".equals(prefix)) {
                 return getTextFromProperPlace();
             } else {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java?view=diff&rev=465755&r1=465754&r2=465755
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/soap/impl/builder/StAXSOAPModelBuilderTest.java Thu Oct 19 13:05:29 2006
@@ -237,6 +237,15 @@
                             SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
             assertTrue("SOAP 1.2 :- Value1 text mismatch",
                     value1.getText().equals("env:Sender"));
+            
+            QName valueQName = value1.getTextAsQName();
+            assertTrue("SOAP 1.2 :- Fault code value's qname local name mismatch",
+                    valueQName.getLocalPart().equals("Sender"));
+                           
+            assertTrue("SOAP 1.2 :- Fault code value's qname namespace uri mismatch",
+                    valueQName.getNamespaceURI().equals(
+                            SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI));
+            
 
             iteratorInCode.next();
             SOAPFaultSubCode subCode1 = (SOAPFaultSubCode) iteratorInCode.next();



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org