axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils NSStack.java
Date Wed, 11 Dec 2002 17:17:45 GMT
gdaniels    2002/12/11 09:17:45

  Modified:    java/test/functional TestMessageSample.java
               java/test/encoding TestDOM.java
               java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
               java/src/org/apache/axis/utils NSStack.java
  Log:
  Fix default namespace processing, which corrects a bunch of the XML
  we're sending.  Clean up message test to expect the correct value.
  
  Revision  Changes    Path
  1.10      +3 -3      xml-axis/java/test/functional/TestMessageSample.java
  
  Index: TestMessageSample.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/functional/TestMessageSample.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TestMessageSample.java	16 Sep 2002 19:34:24 -0000	1.9
  +++ TestMessageSample.java	11 Dec 2002 17:17:43 -0000	1.10
  @@ -85,12 +85,12 @@
           String[] args = { };
           String res = (new TestMsg()).doit(args);
           String expected="Res elem[0]=<ns1:e1 xmlns:ns1=\"urn:foo\">Hello</ns1:e1>"

  -                        +"Res elem[1]=<ns2:e1 xmlns:ns2=\"urn:foo\">World</ns2:e1>"
  -                        +"Res elem[2]=<ns3:e3 xmlns:ns3=\"urn:foo\">"
  +                        +"Res elem[1]=<ns1:e1 xmlns:ns1=\"urn:foo\">World</ns1:e1>"
  +                        +"Res elem[2]=<ns1:e3 xmlns:ns1=\"urn:foo\">"
                           +"<![CDATA["
                           +"Text with\n\tImportant  <b>  whitespace </b> and
tags! "
                           +"]]>"
  -                        +"</ns3:e3>";                        
  +                        +"</ns1:e3>";                        
           assertEquals("test result elements", res, expected);
       }
       
  
  
  
  1.15      +2 -6      xml-axis/java/test/encoding/TestDOM.java
  
  Index: TestDOM.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestDOM.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TestDOM.java	4 Sep 2002 20:15:11 -0000	1.14
  +++ TestDOM.java	11 Dec 2002 17:17:44 -0000	1.15
  @@ -1,7 +1,5 @@
   package test.encoding;
   
  -
  -
   import junit.framework.TestCase;
   import org.apache.axis.AxisEngine;
   import org.apache.axis.Message;
  @@ -13,8 +11,6 @@
   import org.apache.axis.server.AxisServer;
   import org.apache.axis.utils.XMLUtils;
   
  -import java.util.Iterator;
  -
   /**
   
    * Verify that deserialization actually can cause the soap service
  @@ -70,7 +66,7 @@
          message.setMessageContext(msgContext);
   
          // Now completely round trip it
  -       SOAPEnvelope envelope = message.getSOAPEnvelope();
  +       message.getSOAPEnvelope();
          // Element dom = message.getAsDOM();
          String result = message.getSOAPPartAsString();
   
  @@ -99,7 +95,7 @@
   
          Message message2 = new Message(result);
          message2.setMessageContext(msgContext);
  -       SOAPEnvelope envelope2 = message2.getSOAPEnvelope();
  +       message2.getSOAPEnvelope();
          String result2 = message2.getSOAPPartAsString();
   
          assertTrue(result2.indexOf("foo1")!=-1);
  
  
  
  1.84      +0 -1      xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java
  
  Index: SerializationContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContextImpl.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- SerializationContextImpl.java	4 Dec 2002 21:42:30 -0000	1.83
  +++ SerializationContextImpl.java	11 Dec 2002 17:17:45 -0000	1.84
  @@ -964,7 +964,6 @@
           }
   
           nsStack.pop();
  -        nsStack.clearFrame();
   
           if (writingStartTag) {
               writer.write("/>");
  
  
  
  1.36      +40 -10    xml-axis/java/src/org/apache/axis/utils/NSStack.java
  
  Index: NSStack.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/NSStack.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- NSStack.java	11 Dec 2002 16:12:30 -0000	1.35
  +++ NSStack.java	11 Dec 2002 17:17:45 -0000	1.36
  @@ -87,7 +87,8 @@
       private Mapping[] stack;
       private int top = 0;
       private int iterator = 0;
  -    
  +    private int currentDefaultNS = -1;
  +
       public NSStack() {
           stack = new Mapping[32];
           stack[0] = null;
  @@ -119,6 +120,17 @@
   
           top--;
   
  +        // If we've moved below the current default NS, figure out the new
  +        // default (if any)
  +        if (top < currentDefaultNS) {
  +            while (currentDefaultNS > 0) {
  +                if (stack[currentDefaultNS] != null &&
  +                        stack[currentDefaultNS].getPrefix().length() == 0)
  +                    break;
  +                currentDefaultNS--;
  +            }
  +        }
  +        
           if (top == 0) {
               if (log.isTraceEnabled())
                   log.trace("NSPop (" + Messages.getMessage("empty00") + ")");
  @@ -149,7 +161,7 @@
       /**
        * Remove all mappings from the current frame.
        */
  -    public void clearFrame() {
  +    private void clearFrame() {
           while (stack[top] != null) top--;
       }
   
  @@ -183,16 +195,27 @@
        * remap it to the (possibly different) namespaceURI.
        */
       public void add(String namespaceURI, String prefix) {
  -        // Replace duplicate prefixes (last wins - this could also fault)
  -        for (int cursor=top; stack[cursor]!=null; cursor--) {
  -            if (stack[cursor].getPrefix().equals(prefix)) {
  -                stack[cursor].setNamespaceURI(namespaceURI);
  -                return;
  +        int idx = top;
  +        try {
  +            // Replace duplicate prefixes (last wins - this could also fault)
  +            for (int cursor=top; stack[cursor]!=null; cursor--) {
  +                if (stack[cursor].getPrefix().equals(prefix)) {
  +                    stack[cursor].setNamespaceURI(namespaceURI);
  +                    idx = cursor;
  +                    return;
  +                }
  +            }
  +            
  +            push();
  +            stack[top] = new Mapping(namespaceURI, prefix);
  +            idx = top;
  +        } finally {
  +            // If this is the default namespace, note the new in-scope
  +            // default is here.
  +            if (prefix.length() == 0) {
  +                currentDefaultNS = idx;
               }
           }
  -
  -        push();
  -        stack[top] = new Mapping(namespaceURI, prefix);
       }
       
       /**
  @@ -216,6 +239,13 @@
           
           int hash = namespaceURI.hashCode();
   
  +        // If defaults are OK, and the given NS is the current default,
  +        // return "" as the prefix to favor defaults where possible.
  +        if (!noDefault && currentDefaultNS > 0 && 
  +                namespaceURI.equals(
  +                        stack[currentDefaultNS].getNamespaceURI()))
  +            return "";
  +            
           for (int cursor=top; cursor>0; cursor--) {
               Mapping map = stack[cursor];
               if (map == null) continue;
  
  
  

Mime
View raw message