tomj        2002/07/01 09:09:39

  Modified:    java/test/wsdl Wsdl2javaTestSuite.xml
               java/src/org/apache/axis/encoding
                        SerializationContextImpl.java
                        SerializationContext.java
               java/src/org/apache/axis/wsdl/symbolTable SchemaUtils.java
               java/src/org/apache/axis/utils NSStack.java
               java/src/org/apache/axis/wsdl/toJava JavaWriter.java
                        JavaBeanWriter.java JavaBeanHelperWriter.java
               java/src/org/apache/axis/encoding/ser BeanSerializer.java
  Added:       java/test/wsdl/qualify2
                        AttributeQualify_ServiceTestCase.java
                        AttributeQualify_BindingImpl.java
                        attribute-qualify.wsdl
  Log:
  Fix for bug 9406: support for attribute qualification.
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9405
  
  Add a test case.
  
  Serialize and deserialize attributes on beans.
  Example:
  <person age="35" ns1:hair="brown" xmlns:ns1="urn:namespace">
  </person>
  
  This involved tweaking the prefix regitration in the serializer.
  
  Also fixed a minor bug with the WSDL2Java verbose output.
  
  Revision  Changes    Path
  1.110     +13 -2     xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml
  
  Index: Wsdl2javaTestSuite.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/Wsdl2javaTestSuite.xml,v
  retrieving revision 1.109
  retrieving revision 1.110
  diff -u -r1.109 -r1.110
  --- Wsdl2javaTestSuite.xml    27 Jun 2002 16:36:10 -0000      1.109
  +++ Wsdl2javaTestSuite.xml    1 Jul 2002 16:09:38 -0000       1.110
  @@ -884,11 +884,20 @@
       <wsdl2java url="test/wsdl/qualify/qualifytest.wsdl"
                  output="build/work"
                  serverSide="yes"
  -               testcase="yes">
  +               testcase="no">
           <mapping namespace="urn:qualifyTest" package="test.wsdl.qualify"/>
       </wsdl2java>
   
  -    <!-- This tests element qualification.  -->
  +    <!-- test for qualified or unqualified attributes -->
  +    <wsdl2java url="test/wsdl/qualify2/attribute-qualify.wsdl"
  +               output="build/work"
  +               serverSide="yes"
  +               testcase="no">
  +        <mapping namespace="urn:attributeQualify" package="test.wsdl.qualify2"/>
  +    </wsdl2java>
  +    
  +    
  +    <!-- This tests Bug 9642 -  Java Date not deserialize properly.  -->
       <wsdl2java url="test/wsdl/ram/ram.wsdl"
                  output="build/work"
                  serverSide="yes"
  @@ -912,6 +921,8 @@
                  serverSide="yes"
                  testcase="no">
       </wsdl2java>
  +    
  +    
       
       <!-- The following WSDL are BAD.  We're keeping them here so we can -->
       <!-- check periodically to see whether the owner has fixed them.    -->
  
  
  
  1.36      +33 -4     
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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- SerializationContextImpl.java     30 Jun 2002 18:15:46 -0000      1.35
  +++ SerializationContextImpl.java     1 Jul 2002 16:09:38 -0000       1.36
  @@ -325,7 +325,7 @@
        */
       public String getPrefixForURI(String uri)
       {
  -        return getPrefixForURI(uri, null);
  +        return getPrefixForURI(uri, null, false);
       }
   
       /**
  @@ -336,16 +336,22 @@
        */
       public String getPrefixForURI(String uri, String defaultPrefix)
       {
  +        return getPrefixForURI(uri, defaultPrefix, false);
  +    }
  +    public String getPrefixForURI(String uri, String defaultPrefix, boolean 
attribute)
  +    {
           if ((uri == null) || (uri.equals("")))
               return null;
   
  -        String prefix = nsStack.getPrefix(uri);
  +        // If we're looking for an attribute prefix, we shouldn't use the 
  +        // "" prefix, but always register/find one.
  +        String prefix = nsStack.getPrefix(uri, attribute);
   
           if (prefix == null && uri.equals(soapConstants.getEncodingURI())) {
               prefix = Constants.NS_PREFIX_SOAP_ENC;
               registerPrefixForURI(prefix, uri);
           }
  -
  +        
           if (prefix == null) {
               if (defaultPrefix == null) {
                   prefix = "ns" + lastPrefixIndex++;
  @@ -422,6 +428,29 @@
       {
           return qName2String(qName, false);
       }
  +
  +    /**
  +     * Convert attribute QName to a string of the form <prefix>:<localpart>
  +     * There are slightly different rules for attributes:
  +     *  - There is no default namespace
  +     *  - any attribute in a namespace must have a prefix
  +     * 
  +     * @param QName
  +     * @return prefixed qname representation for serialization.
  +     */
  +    public String attributeQName2String(QName qName) {
  +        String prefix = null;
  +
  +        if (! qName.getNamespaceURI().equals("")) {
  +            prefix = getPrefixForURI(qName.getNamespaceURI(), null, true);
  +        }
  +
  +        String ret = (((prefix != null) && (!prefix.equals(""))) ?
  +                      prefix + ":" : "") +
  +           qName.getLocalPart();
  +        return ret;
  +    }
  +
       /**
        * Get the QName associated with the specified class.
        * @param cls Class of an object requiring serialization.
  @@ -759,7 +788,7 @@
                           if (idx > -1) {
                               prefix = qname.substring(0, idx);
                               prefix = getPrefixForURI(uri,
  -                                                     prefix);
  +                                                     prefix, true);
                           }
                       }
                       if (!prefix.equals("")) {
  
  
  
  1.77      +8 -0      
xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.76
  retrieving revision 1.77
  diff -u -r1.76 -r1.77
  --- SerializationContext.java 11 Jun 2002 14:53:54 -0000      1.76
  +++ SerializationContext.java 1 Jul 2002 16:09:38 -0000       1.77
  @@ -228,6 +228,14 @@
       public String qName2String(QName qName);
   
       /**
  +     * Convert attribute QName to a string of the form <prefix>:<localpart>
  +     * There are some special rules for attributes
  +     * @param QName
  +     * @return prefixed qname representation for serialization.
  +     */
  +    public String attributeQName2String(QName qName);
  +
  +    /**
        * Get the QName associated with the specified class.
        * @param Class of an object requiring serialization.
        * @return appropriate QName associated with the class.
  
  
  
  1.10      +42 -17    
xml-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java
  
  Index: SchemaUtils.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/symbolTable/SchemaUtils.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SchemaUtils.java  20 Jun 2002 21:17:38 -0000      1.9
  +++ SchemaUtils.java  1 Jul 2002 16:09:38 -0000       1.10
  @@ -1049,28 +1049,53 @@
                   // we have an attribute node
                   if (v == null)
                       v = new Vector();
  -                
  -                // type
  -                QName typeAttr = Utils.getNodeTypeRefQName(child, "type");
  -                if (typeAttr == null) {
  -                    // Could be defined as an anonymous type
  -                    typeAttr = getAttributeAnonQName(child);
  -                }
   
  -                // Get the corresponding TypeEntry
  -                TypeEntry type = symbolTable.getTypeEntry(typeAttr, false);
  +                // Get the name and type qnames.
  +                // The type qname is used to locate the TypeEntry, which is then
  +                // used to retrieve the proper java name of the type.
  +                QName attributeName = Utils.getNodeNameQName(child);
  +                BooleanHolder forElement = new BooleanHolder();
  +                QName attributeType = Utils.getNodeTypeRefQName(child, forElement);
   
  -                // Need to add code here to get the qualified or unqualified
  -                // name.  Similar to the code around line 350 for elements.
  -                // Rich Scheuerle
  -
  -                // Now get the name.
  -                QName name = Utils.getNodeNameQName(child);
  +                // An attribute is either qualified or unqualified.
  +                // If the ref= attribute is used, the name of the ref'd element is 
used
  +                // (which must be a root element).  If the ref= attribute is not
  +                // used, the name of the attribute is unqualified.
  +                if (!forElement.value) {
  +                    // check the Form (or attributeFormDefault) attribute of 
  +                    // this node to determine if it should be namespace 
  +                    // quailfied or not.
  +                    String form = Utils.getAttribute(child, "form");
  +                    if (form != null && form.equals("unqualified")) {
  +                        // Unqualified nodeName
  +                        attributeName = new QName("", 
attributeName.getLocalPart());            
  +                    } else if (form == null) {
  +                        // check attributeFormDefault on schema element
  +                        String def = Utils.getScopedAttribute(child, 
  +                                                              
"attributeFormDefault");
  +                        if (def == null || def.equals("unqualified")) {
  +                            // Unqualified nodeName
  +                            attributeName = new QName("", 
attributeName.getLocalPart());            
  +                        }
  +                    }
  +                } else {
  +                    attributeName = attributeType;
  +                }
  +                if (attributeType == null) {
  +                    attributeType = getAttributeAnonQName(child);            
  +                    forElement.value = false;
  +                }
  +                
  +                // Get the corresponding TypeEntry from the symbol table
  +                TypeEntry type = 
  +                        (TypeEntry)symbolTable.getTypeEntry(attributeType, 
  +                                                            forElement.value);
  +                
                   // add type and name to vector, skip it if we couldn't parse it
                   // XXX - this may need to be revisited.
  -                if (type != null && name != null) {
  +                if (type != null && attributeName != null) {
                       v.add(type);
  -                    v.add(name.getLocalPart());
  +                    v.add(attributeName);
                   }
               }
           }            
  
  
  
  1.23      +7 -2      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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- NSStack.java      5 Apr 2002 21:24:33 -0000       1.22
  +++ NSStack.java      1 Jul 2002 16:09:38 -0000       1.23
  @@ -189,7 +189,7 @@
        * If we look for a prefix for "namespace" at the indicated spot, we won't
        * find one because "pre" is actually mapped to "otherNamespace"
        */ 
  -    public String getPrefix(String namespaceURI) {
  +    public String getPrefix(String namespaceURI, boolean noDefault) {
           if ((namespaceURI == null) || (namespaceURI.equals("")))
               return null;
           
  @@ -201,7 +201,8 @@
                       Mapping map = (Mapping)t.get(i);
                       if (map.getNamespaceURI().equals(namespaceURI)) {
                           String possiblePrefix = map.getPrefix();
  -                        if (getNamespaceURI(possiblePrefix).equals(namespaceURI))
  +                        if (getNamespaceURI(possiblePrefix).equals(namespaceURI) &&
  +                            (!noDefault || !"".equals(possiblePrefix)))
                               return possiblePrefix;
                       }
                   }
  @@ -211,6 +212,10 @@
           if (parent != null)
               return parent.getPrefix(namespaceURI);
           return null;
  +    }
  +
  +    public String getPrefix(String namespaceURI) {
  +        return getPrefix(namespaceURI, false);
       }
       
       public String getNamespaceURI(String prefix) {
  
  
  
  1.17      +4 -1      xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java
  
  Index: JavaWriter.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaWriter.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JavaWriter.java   7 Jun 2002 12:45:08 -0000       1.16
  +++ JavaWriter.java   1 Jul 2002 16:09:38 -0000       1.17
  @@ -140,7 +140,10 @@
           }
           registerFile(file);
           if (emitter.isVerbose()) {
  -            System.out.println(verboseMessage(file));
  +            String msg = verboseMessage(file);
  +            if (msg != null) {
  +                System.out.println(msg);
  +            }
           }
           PrintWriter pw = getPrintWriter(file);
           writeFileHeader(pw);
  
  
  
  1.20      +6 -3      
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java
  
  Index: JavaBeanWriter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- JavaBeanWriter.java       17 Jun 2002 19:25:40 -0000      1.19
  +++ JavaBeanWriter.java       1 Jul 2002 16:09:38 -0000       1.20
  @@ -67,6 +67,8 @@
   
   import org.w3c.dom.Node;
   
  +import javax.xml.namespace.QName;
  +
   /**
    * This is Wsdl2java's Complex Type Writer.  It writes the <typeName>.java file.
    */
  @@ -203,8 +205,9 @@
           if (attributes != null) {
               for (int i = 0; i < attributes.size(); i += 2) {
                   String typeName = ((TypeEntry) attributes.get(i)).getName();
  +                QName xmlName = (QName) attributes.get(i + 1);
                   String variableName = 
  -                    Utils.xmlNameToJava((String) attributes.get(i + 1));
  +                    Utils.xmlNameToJava(xmlName.getLocalPart());
                   names.add(typeName);
                   names.add(variableName);
                   if (type.isSimpleType() &&
  @@ -327,8 +330,8 @@
               if (attributes != null) {
                   for (int j=0; j<attributes.size(); j+=2) {
                       paramTypes.add(((TypeEntry) attributes.get(j)).getName());
  -                    paramNames.add(mangle +
  -                        Utils.xmlNameToJava((String) attributes.get(j + 1)));
  +                    String name = ((QName)attributes.get(j + 1)).getLocalPart();
  +                    paramNames.add(mangle + Utils.xmlNameToJava(name));
                   }
               }
               // Process the elements
  
  
  
  1.15      +19 -7     
xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java
  
  Index: JavaBeanHelperWriter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanHelperWriter.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- JavaBeanHelperWriter.java 27 Jun 2002 18:51:37 -0000      1.14
  +++ JavaBeanHelperWriter.java 1 Jul 2002 16:09:38 -0000       1.15
  @@ -134,6 +134,18 @@
       } // registerFile
   
       /**
  +     * Return the string:  "Generating <file>". 
  +     * only if we are going to generate a new file.
  +     */
  +    protected String verboseMessage(String file) {
  +        if (wrapperPW == null) {
  +            return super.verboseMessage(file);
  +        } else {
  +            return null;
  +        }
  +    } // verboseMessage
  +
  +    /**
        * Only write the file header if the bean helper is not wrapped
        * within a bean.
        */
  @@ -230,8 +242,9 @@
   
               if (attributes != null) {
                   for (int i = 0; i < attributes.size(); i += 2) {
  -                    String attrName = (String) attributes.get(i + 1);
  -                    String fieldName = Utils.xmlNameToJava(attrName);
  +                    QName attrName = (QName) attributes.get(i + 1);
  +                    String attrLocalName = attrName.getLocalPart();
  +                    String fieldName = Utils.xmlNameToJava(attrLocalName);
                       pw.print("        ");
                       if (!wroteFieldType) {
                           pw.print("org.apache.axis.description.FieldDesc ");
  @@ -239,11 +252,10 @@
                       }
                       pw.println("field = new 
org.apache.axis.description.AttributeDesc();");
                       pw.println("        field.setFieldName(\"" + fieldName + 
"\");");
  -                    if (!fieldName.equals(attrName)) {
  -                        pw.print("        field.setXmlName(");
  -                        pw.print("new javax.xml.namespace.QName(null, \"");
  -                        pw.println(attrName + "\"));");
  -                    }
  +                    pw.print("        field.setXmlName(");
  +                    pw.print("new javax.xml.namespace.QName(\""); 
  +                    pw.print(attrName.getNamespaceURI() +  "\", \"");
  +                    pw.println(attrName.getLocalPart() + "\"));");
                       pw.println("        typeDesc.addFieldDesc(field);");
                   }
               }
  
  
  
  1.38      +1 -1      
xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java
  
  Index: BeanSerializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- BeanSerializer.java       21 Jun 2002 21:40:03 -0000      1.37
  +++ BeanSerializer.java       1 Jul 2002 16:09:39 -0000       1.38
  @@ -488,7 +488,7 @@
   
           attrs.addAttribute(namespace,
                              localName,
  -                           context.qName2String(qname),
  +                           context.attributeQName2String(qname),
                              "CDATA",
                              propString);
       } 
  
  
  
  1.1                  
xml-axis/java/test/wsdl/qualify2/AttributeQualify_ServiceTestCase.java
  
  Index: AttributeQualify_ServiceTestCase.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  /**
   * Qualify_ServiceTestCase.java
   *
   * This file was auto-generated from WSDL
   * by the Apache Axis Wsdl2java emitter.
   */
  
  package test.wsdl.qualify2;
  
  import junit.framework.AssertionFailedError;
  import org.apache.axis.Message;
  import org.apache.axis.MessageContext;
  import org.apache.axis.utils.XMLUtils;
  import org.apache.axis.message.SOAPEnvelope;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Attr;
  import org.xml.sax.InputSource;
  
  import javax.xml.rpc.ServiceException;
  import java.io.InputStream;
  import java.io.IOException;
  import java.io.Reader;
  import java.io.StringReader;
  
  import test.wsdl.qualify2.Phone;
  
  public class AttributeQualify_ServiceTestCase extends junit.framework.TestCase {
  
      public static final String NAMESPACE = "urn:attributeQualify";
  
      public AttributeQualify_ServiceTestCase(String name) {
          super(name);
      }
  
      public void test1AttributeQualifyEchoPhone() {
          test.wsdl.qualify2.AttributeQualify_Port binding;
          test.wsdl.qualify2.AttributeQualify_ServiceLocator locator = new 
test.wsdl.qualify2.AttributeQualify_ServiceLocator();
          try {
              binding = locator.getAttributeQualify();
          }
          catch (javax.xml.rpc.ServiceException jre) {
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException 
caught: " + jre);
          }
          assertTrue("binding is null", binding != null);
  
          try {
              test.wsdl.qualify2.Phone phone = new Phone();
              phone.setAge(35);
              phone.setAreaCode(505);
              phone.setColor("red");
              phone.setExchange("555");
              phone.setHair("brown");
              phone.setNumber("1212");
              
              Phone result = binding.echoPhone(phone);
              
              // Check the response
              assertTrue(result.equals(phone));
  
              // Validate XML reponse to make sure attributes are properly 
              // qualified or not per the WSDL
              MessageContext mc = null;
              try {
                  mc = locator.getCall().getMessageContext();
              } catch (ServiceException e) {
                  throw new AssertionFailedError("Unable to get call object from 
service");
              }
              Message response = mc.getResponseMessage();
              SOAPEnvelope env = response.getSOAPEnvelope();
              String responseString = response.getSOAPPartAsString();
  
              Element body;
              try {
                  body = env.getFirstBody().getAsDOM();
              } catch (Exception e) {
                  throw new AssertionFailedError("Unable to get request body as DOM 
Element on server");
              }
  
              // debug
              //System.out.println("Response:\n---------\n" + responseString + 
"\n------");
  
              // Now we have a DOM Element, verfy namespace attributes
              // Here is what we think it looks like
              // <phone age="35" 
              //        ns1:color="red" 
              //        ns1:hair="brown" 
              //        xmlns:ns1="urn:attributeQualify">
              //   <areaCode>505</areaCode>
              //   <exchange>555</exchange>
              //   <number>1212</number>
              //</phone>
              
              String bodyNS = body.getNamespaceURI();
              assertEquals("Namespace of body element incorrect", bodyNS, NAMESPACE);
  
              // Verify age does NOT have a namespace (unqualified)
              Attr ageAttr = body.getAttributeNode("age");
              assertNull("namespace of attribute 'age' should be null", 
                         ageAttr.getNamespaceURI());
              
              // Verify hair and color have the right namespace (are qualified).
              Attr hairAttr = body.getAttributeNodeNS(NAMESPACE, "hair");
              assertNotNull("namespace of attribute 'hair' is not correct", 
                           hairAttr);
              Attr colorAttr = body.getAttributeNodeNS(NAMESPACE, "color");
              assertNotNull("namespace of attribute 'color' is not correct", 
                           colorAttr);
              
          } catch (java.rmi.RemoteException re) {
              throw new AssertionFailedError("Remote Exception caught: " + re);
          }
      }
  
  
  }
  
  
  
  
  1.1                  
xml-axis/java/test/wsdl/qualify2/AttributeQualify_BindingImpl.java
  
  Index: AttributeQualify_BindingImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Axis" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  
  /**
   * AttributeQualify_BindingImpl.java
   *
   * Service implementation for Qualified/Nonqualified attributes in a complex
   * type.  The service validates the request XML and the test client validates
   * the response XML to verify the attributes that should be namesapce qualified
   * are, and those that are not supposed to be aren't.
   */
  
  package test.wsdl.qualify2;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.Message;
  import org.apache.axis.MessageContext;
  import org.apache.axis.message.SOAPEnvelope;
  import org.w3c.dom.Attr;
  import org.w3c.dom.Element;
  
  public class AttributeQualify_BindingImpl implements 
test.wsdl.qualify2.AttributeQualify_Port {
  
      public static final String NAMESPACE = "urn:attributeQualify";
  
      public test.wsdl.qualify2.Phone echoPhone(test.wsdl.qualify2.Phone in) throws 
java.rmi.RemoteException {
  
          // Validate XML request to make sure elements are properly qualified
          // or not per the WSDL
          MessageContext mc = MessageContext.getCurrentContext();
          Message request = mc.getRequestMessage();
          SOAPEnvelope env = request.getSOAPEnvelope();
          String requestString = request.getSOAPPartAsString();
  
          Element body;
          try {
              body = env.getFirstBody().getAsDOM();
          } catch (Exception e) {
              throw new AxisFault("Unable to get request body as DOM Element on 
server");
          }
          
          // Now we have a DOM Element, verfy namespace attributes
          // Here is what we think it looks like
          // <phone age="35" 
          //        ns1:color="red" 
          //        ns1:hair="brown" 
          //        xmlns:ns1="urn:attributeQualify">
          //   <areaCode>505</areaCode>
          //   <exchange>555</exchange>
          //   <number>1212</number>
          //</phone>
              
          String bodyNS = body.getNamespaceURI();
          if (! NAMESPACE.equals(bodyNS))
          throw new AxisFault("On Server: Namespace of body element incorrect: " + 
                                  bodyNS + " should be: " + NAMESPACE);
  
          // Verify age does NOT have a namespace (unqualified)
          Attr ageAttr = body.getAttributeNode("age");
          if (ageAttr.getNamespaceURI() != null) {
              throw new AxisFault("On Server: Namespace of age attribute incorrect: "
                               + ageAttr.getNamespaceURI() + " should be: NULL");
          }
          
          // Verify hair and color have the right namespace (are qualified).
          Attr hairAttr = body.getAttributeNodeNS(NAMESPACE, "hair");
          if (hairAttr == null) {
              throw new AxisFault("On Server: Missing namespace for attribute 'hair' 
should be: " + NAMESPACE);
          }
          
          Attr colorAttr = body.getAttributeNodeNS(NAMESPACE, "color");
          if (hairAttr == null) {
              throw new AxisFault("On Server: Missing namespace for attribute 'color' 
should be: " + NAMESPACE);
          }
  
          // Echo input
          return in;
      }
  
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/qualify2/attribute-qualify.wsdl
  
  Index: attribute-qualify.wsdl
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  <definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/";
               xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
               xmlns:xsd="http://www.w3.org/2001/XMLSchema";
               xmlns:s0="urn:attributeQualify"
               xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/";
               targetNamespace="urn:attributeQualify"
               xmlns="http://schemas.xmlsoap.org/wsdl/";>
    <documentation>
    This test tests the use and overriding of the "attributeFormDefault" attribute.
    </documentation>
    <types>
      <xsd:schema attributeFormDefault="qualified" 
targetNamespace="urn:attributeQualify">
  
        <xsd:complexType name="phone">
          <xsd:all>
              <xsd:element name="areaCode" type="xsd:int"/>
              <xsd:element name="exchange" type="xsd:string"/>
              <xsd:element name="number" type="xsd:string"/>
          </xsd:all>
          <!-- These attributes should be qualified -->
          <attribute name="color" type="xsd:string"/>
          <attribute name="hair" type="xsd:string" form="qualified"/>
          <!-- This attribute should not -->
          <attribute name="age" type="xsd:int" form="unqualified"/>
        </xsd:complexType>
  
        <xsd:element name="phone" type="s0:phone"/>
      </xsd:schema>
    </types>
  
    <message name="echoPhoneIn">
      <part name="in" element="s0:phone" />
    </message>
    <message name="echoPhoneOut">
      <part name="out" element="s0:phone" />
    </message>
  
    <portType name="AttributeQualify">
      <operation name="echoPhone">
        <input message="s0:echoPhoneIn" />
        <output message="s0:echoPhoneOut" />
      </operation>
  
    </portType>
  
  
    <binding name="AttributeQualify" type="s0:AttributeQualify">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http"; style="document" 
/>
      <operation name="echoPhone">
        <soap:operation soapAction="" style="document" />
        <input>
          <soap:body use="literal" />
        </input>
        <output>
          <soap:body use="literal" />
        </output>
      </operation>
    </binding>
  
    <service name="AttributeQualify">
      <port name="AttributeQualify" binding="s0:AttributeQualify">
        <soap:address location="http://localhost:8080/axis/services/AttributeQualify"; 
/>
      </port>
    </service>
  </definitions>
  
  


Reply via email to