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/message RPCParam.java
Date Sat, 05 May 2001 13:47:13 GMT
gdaniels    01/05/05 06:47:13

  Modified:    java/src/org/apache/axis Constants.java
               java/src/org/apache/axis/deployment/wsdd WSDDDocument.java
               java/src/org/apache/axis/encoding
                        DeserializationContext.java DeserializerBase.java
                        SOAPTypeMappingRegistry.java
                        TypeMappingRegistry.java
               java/src/org/apache/axis/message RPCParam.java
  Added:       java/src/org/apache/axis/encoding ArraySerializer.java
                        ValueReceiver.java
  Log:
  Rough in support for Arrays.
  
  We don't yet automatically detect arrays, or serialize them, but
  deserialization (including arrays of structs, with ID/HREFs) works
  fine if you manually map the ArraySerializer to your type.
  
  This required a change to the TypeMappingRegistry (sorry, Sam -
  I should think this will merge easily, though) to allow looking
  up a Class using a QName as a key - so now both addSerializer() and
  addDeserializer() need both QName and Class.  We should add a
  convenience function registerTypes(QName, Class, Serializer,
  Deserializer) at some point.
  
  Also added a new way for deserializers to get their values back
  to interested parties, namely a callback to a ValueReceiver.
  Array deserialization uses this technique to plug values into
  the array.
  
  Still need to handle typing better, deal with the position
  attribute, deal with variably-sized arrays, deal with multi-
  dimensional arrays, serialize, and auto-detect arrays.
  
  Revision  Changes    Path
  1.12      +1 -0      xml-axis/java/src/org/apache/axis/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Constants.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Constants.java	2001/05/04 06:09:49	1.11
  +++ Constants.java	2001/05/05 13:47:11	1.12
  @@ -126,6 +126,7 @@
     public static String ATTR_ROOT            = "root" ;
     public static String ATTR_ID              = "id" ;
     public static String ATTR_HREF            = "href" ;
  +  public static final String ATTR_ARRAY_TYPE = "arrayType";
   
     // Fault Codes
     //////////////////////////////////////////////////////////////////////////
  
  
  
  1.3       +3 -1      xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDocument.java
  
  Index: WSDDDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDocument.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WSDDDocument.java	2001/05/05 09:03:33	1.2
  +++ WSDDDocument.java	2001/05/05 13:47:11	1.3
  @@ -139,7 +139,9 @@
                                       mapping.getQName(), ser);
               
                   if (deser != null)
  -                    tmr.addDeserializerFactory(mapping.getQName(), deser);
  +                    tmr.addDeserializerFactory(mapping.getQName(),
  +                                               mapping.getLanguageSpecificType(),
  +                                               deser);
               } catch (Exception e) {
                   throw new DeploymentException(e.getMessage());
               }
  
  
  
  1.7       +32 -0     xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java
  
  Index: DeserializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContext.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DeserializationContext.java	2001/05/04 21:29:56	1.6
  +++ DeserializationContext.java	2001/05/05 13:47:12	1.7
  @@ -57,6 +57,7 @@
   
   import org.xml.sax.*;
   import java.util.*;
  +import org.apache.axis.Constants;
   import org.apache.axis.encoding.*;
   import org.apache.axis.message.*;
   import org.apache.axis.utils.QName;
  @@ -138,6 +139,37 @@
       public String getNamespaceURI(String prefix)
       {
           return (String)baseHandler.getNamespaceURI(prefix);
  +    }
  +    
  +    public QName getQNameFromString(String qNameStr)
  +    {
  +        // OK, this is a QName, so look up the prefix in our current mappings.
  +        
  +        int i = qNameStr.indexOf(":");
  +        if (i == -1)
  +            return null;
  +        
  +        String nsURI = getNamespaceURI(qNameStr.substring(0, i));
  +        
  +        //System.out.println("namespace = " + nsURI);
  +        
  +        if (nsURI == null)
  +            return null;  // ???
  +        
  +        return new QName(nsURI, qNameStr.substring(i + 1));
  +    }
  +    
  +    public QName getTypeFromAttributes(Attributes attrs)
  +    {
  +        // Check for type
  +        String type = null;
  +        for (int i=0; i<Constants.URIS_SCHEMA_XSI.length && type==null; i++)
  +            type = attrs.getValue(Constants.URIS_SCHEMA_XSI[i], "type");
  +        
  +        if (type == null)
  +          return null;
  +        
  +        return getQNameFromString(type);
       }
       
       public void setTypeMappingRegistry(TypeMappingRegistry reg)
  
  
  
  1.5       +50 -16    xml-axis/java/src/org/apache/axis/encoding/DeserializerBase.java
  
  Index: DeserializerBase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializerBase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DeserializerBase.java	2001/05/04 19:24:38	1.4
  +++ DeserializerBase.java	2001/05/05 13:47:12	1.5
  @@ -76,6 +76,7 @@
       
       protected Object value = null;
       protected DeserializationContext context = null;
  +    protected boolean isComplete = false;
       
       public Object getValue()
       {
  @@ -86,6 +87,27 @@
           this.value = value;
       }
   
  +    class CallbackTarget {
  +        public ValueReceiver target;
  +        public Object hint;
  +        CallbackTarget(ValueReceiver target, Object hint)
  +        {
  +            this.target = target;
  +            this.hint = hint;
  +        }
  +    }
  +    protected Vector callbacks = null;
  +
  +    public void registerCallback(ValueReceiver target, Object hint)
  +    {
  +        if (target == null)
  +            return;
  +        
  +        if (callbacks == null)
  +            callbacks = new Vector();
  +        callbacks.addElement(new CallbackTarget(target, hint));
  +    }
  +    
       /////////////////////////////////////////////////////////////
       //  Reflection-based insertion of values into target objects
       //  once deserialization is complete.
  @@ -106,6 +128,9 @@
       protected Vector targets = null;
       public void registerValueTarget(Object target, Field field)
       {
  +        if ((target == null) || (field == null))
  +            return;
  +        
           if (targets == null)
               targets = new Vector();
           
  @@ -143,23 +168,32 @@
        */
       public void valueComplete() throws SAXException
       {
  -        if (targets == null)
  -            return;
  +        isComplete = true;
           
  -        Enumeration e = targets.elements();
  -        while (e.hasMoreElements()) {
  -            FieldTarget target = (FieldTarget)e.nextElement();
  -            Field field = target.targetField;
  -            Object object = target.targetObject;
  -            
  -            try {
  -                field.set(object, value);
  -            } catch (IllegalAccessException accEx) {
  -                accEx.printStackTrace();
  -                throw new SAXException(accEx);
  -            } catch (IllegalArgumentException argEx) {
  -                argEx.printStackTrace();
  -                throw new SAXException(argEx);
  +        if (callbacks != null) {
  +            Enumeration e = callbacks.elements();
  +            while (e.hasMoreElements()) {
  +                CallbackTarget target = (CallbackTarget)e.nextElement();
  +                target.target.valueReady(value, target.hint);
  +            }
  +        }
  +        
  +        if (targets != null) {
  +            Enumeration e = targets.elements();
  +            while (e.hasMoreElements()) {
  +                FieldTarget target = (FieldTarget)e.nextElement();
  +                Field field = target.targetField;
  +                Object object = target.targetObject;
  +                
  +                try {
  +                    field.set(object, value);
  +                } catch (IllegalAccessException accEx) {
  +                    accEx.printStackTrace();
  +                    throw new SAXException(accEx);
  +                } catch (IllegalArgumentException argEx) {
  +                      argEx.printStackTrace();
  +                      throw new SAXException(argEx);
  +                }
               }
           }
       }
  
  
  
  1.6       +10 -10    xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java
  
  Index: SOAPTypeMappingRegistry.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SOAPTypeMappingRegistry.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SOAPTypeMappingRegistry.java	2001/05/04 19:24:39	1.5
  +++ SOAPTypeMappingRegistry.java	2001/05/05 13:47:12	1.6
  @@ -85,13 +85,13 @@
        * @param base QName based on the current Schema namespace
        * @param factory common factory to be used across all schemas
        */
  -    private void addDeserializersFor(QName base, DeserializerFactory factory) {
  -        addDeserializerFactory(base, factory);
  +    private void addDeserializersFor(QName base, Class cls, DeserializerFactory factory)
{
  +        addDeserializerFactory(base, cls, factory);
           String localPart = base.getLocalPart();
           for (int i=0; i<Constants.URIS_SCHEMA_XSD.length; i++) {
               if (!Constants.URIS_SCHEMA_XSD[i].equals(base.getNamespaceURI())) {
                  QName qname = new QName(Constants.URIS_SCHEMA_XSD[i], localPart);
  -               addDeserializerFactory(qname, factory);
  +               addDeserializerFactory(qname, cls, factory);
               }
           }
       }
  @@ -106,13 +106,13 @@
           addSerializer(java.lang.Long.class, XSD_LONG, se);
           addSerializer(java.lang.Short.class, XSD_SHORT, se);
           
  -        addDeserializersFor(XSD_STRING, new StringDeserializerFactory());    
  -        addDeserializersFor(XSD_BOOLEAN, new BooleanDeserializerFactory());
  -        addDeserializersFor(XSD_DOUBLE, new DoubleDeserializerFactory());
  -        addDeserializersFor(XSD_FLOAT, new FloatDeserializerFactory());
  -        addDeserializersFor(XSD_INT, new IntDeserializerFactory());
  -        addDeserializersFor(XSD_LONG, new LongDeserializerFactory());
  -        addDeserializersFor(XSD_SHORT, new ShortDeserializerFactory());
  +        addDeserializersFor(XSD_STRING, java.lang.String.class, new StringDeserializerFactory());
   
  +        addDeserializersFor(XSD_BOOLEAN, java.lang.Boolean.class, new BooleanDeserializerFactory());
  +        addDeserializersFor(XSD_DOUBLE, java.lang.Double.class, new DoubleDeserializerFactory());
  +        addDeserializersFor(XSD_FLOAT, java.lang.Float.class, new FloatDeserializerFactory());
  +        addDeserializersFor(XSD_INT, java.lang.Integer.class, new IntDeserializerFactory());
  +        addDeserializersFor(XSD_LONG, java.lang.Long.class, new LongDeserializerFactory());
  +        addDeserializersFor(XSD_SHORT, java.lang.Short.class, new ShortDeserializerFactory());
   
           /*
           addDeserializerFactory(SOAP_STRING, se);
  
  
  
  1.7       +27 -5     xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java
  
  Index: TypeMappingRegistry.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingRegistry.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TypeMappingRegistry.java	2001/05/04 21:22:51	1.6
  +++ TypeMappingRegistry.java	2001/05/05 13:47:12	1.7
  @@ -78,19 +78,32 @@
               this.serializer = serializer;
           }
       }
  +
  +    class DeserializerDescriptor implements Serializable {
  +        Class cls;
  +        DeserializerFactory factory;
  +        DeserializerDescriptor(Class cls, DeserializerFactory factory)
  +        {
  +            this.cls = cls;
  +            this.factory = factory;
  +        }
  +    }
       
       Hashtable s;
       Hashtable d;
       
  -    public void addSerializer(Class _class, QName qName, Serializer serializer) {
  +    public void addSerializer(Class _class,
  +                              QName qName,
  +                              Serializer serializer) {
           if (s == null) s = new Hashtable();
           s.put(_class, new SerializerDescriptor(qName, serializer));
       }
       
       public void addDeserializerFactory(QName qname,
  +                                       Class _class,
                                          DeserializerFactory deserializerFactory) {
           if (d == null) d= new Hashtable();
  -        d.put(qname, deserializerFactory);
  +        d.put(qname, new DeserializerDescriptor(_class, deserializerFactory));
       }
   
       public Serializer getSerializer(Class _class) {
  @@ -109,15 +122,24 @@
           return null;
       }
       
  +    public Class getClassForQName(QName type)
  +    {
  +        if (d == null)
  +            return null;
  +        DeserializerDescriptor desc = (DeserializerDescriptor)d.get(type);
  +        if (desc != null) return desc.cls;
  +        return null;
  +    }
  +    
       public DeserializerBase getDeserializer(QName qname) {
           if (d == null)
               return null;
           
  -        DeserializerFactory factory = (DeserializerFactory)d.get(qname);
  -        if (factory == null)
  +        DeserializerDescriptor desc = (DeserializerDescriptor)d.get(qname);
  +        if ((desc == null) || (desc.factory == null))
               return null;
           
  -        DeserializerBase dSer = factory.getDeserializer();
  +        DeserializerBase dSer = desc.factory.getDeserializer();
           return dSer;
       }
       
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/ArraySerializer.java
  
  Index: ArraySerializer.java
  ===================================================================
  package org.apache.axis.encoding;
  
  /*
   * 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 apache@apache.org.
   *
   * 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/>.
   */
  
  import org.apache.axis.*;
  import org.apache.axis.message.*;
  import org.apache.axis.utils.*;
  import org.xml.sax.*;
  import java.lang.reflect.Array;
  import java.io.IOException;
  
  /** An ArraySerializer handles serializing and deserializing SOAP
   * arrays.
   * 
   * Some code borrowed from ApacheSOAP - thanks to Matt Duftler!
   * 
   * @author Glen Daniels (gdaniels@macromedia.com)
   */
  
  /** !!! FIRST CUT - INCOMPLETE (doesn't yet do serialization)
   */
  public class ArraySerializer extends DeserializerBase
      implements ValueReceiver, Serializer
  {
      public static class Factory implements DeserializerFactory {
          public DeserializerBase getDeserializer() {
              return new ArraySerializer();
          }
      }
      public static DeserializerFactory factory = new Factory();
                                                       
      public QName arrayType = null;
      public int curIndex = 0;
      QName arrayItemType;
      
      public void startElement(String namespace, String localName,
                               String qName, Attributes attributes)
          throws SAXException
      {
          super.startElement(namespace, localName, qName, attributes);
          
          System.out.println("In Array.startElement");
  
          QName arrayTypeValue = context.getQNameFromString(
                   attributes.getValue(Constants.URI_SOAP_ENC,
                                       Constants.ATTR_ARRAY_TYPE));
          if (arrayTypeValue == null)
              throw new SAXException("No arrayType attribute for array!");
          
          String arrayTypeValueNamespaceURI = arrayTypeValue.getNamespaceURI();
          String arrayTypeValueLocalPart = arrayTypeValue.getLocalPart();
          int leftBracketIndex = arrayTypeValueLocalPart.lastIndexOf('[');
          int rightBracketIndex = arrayTypeValueLocalPart.lastIndexOf(']');
  
          if (leftBracketIndex == -1
              || rightBracketIndex == -1
              || rightBracketIndex < leftBracketIndex)
          {
              throw new IllegalArgumentException("Malformed arrayTypeValue '" +
                  arrayTypeValue + "'.");
          }
  
          String componentTypeName =
                      arrayTypeValueLocalPart.substring(0, leftBracketIndex);
  
          if (componentTypeName.endsWith("]"))
          {
              throw new IllegalArgumentException("Arrays of arrays are not " +
                  "supported '" + arrayTypeValue +
                  "'.");
          }
          
          arrayItemType = new QName(arrayTypeValueNamespaceURI,
                                    componentTypeName);
  
          String lengthStr =
                   arrayTypeValueLocalPart.substring(leftBracketIndex + 1,
                                                     rightBracketIndex);
          
          if (lengthStr.length() > 0)
          {
              if (lengthStr.indexOf(',') != -1)
              {
                  throw new IllegalArgumentException("Multi-dimensional arrays are " +
                      "not supported '" +
                      lengthStr + "'.");
              }
  
              try
              {
                  int length = Integer.parseInt(lengthStr);
                  Class componentType = context.getTypeMappingRegistry().getClassForQName(arrayItemType);
          
                  if (componentType == null)
                      throw new SAXException("No component type for " + arrayItemType);
                  
                  value = Array.newInstance(componentType, length);
  
              }
              catch (NumberFormatException e)
              {
                  throw new IllegalArgumentException("Explicit array length is not a " +
                      "valid integer '" + lengthStr +
                      "'.");
              }
          }
      }
      
      public void onStartChild(String namespace, String localName,
                               String qName, Attributes attributes)
          throws SAXException
      {
          // Array element
          System.out.println("In array element...");
          
          // !!! Check position attribute, type attribute....
          QName itemType = context.getTypeFromAttributes(attributes);
          
          if (itemType != null) {
              if (!arrayItemType.equals(itemType))
                  throw new SAXException("Item type (" + itemType + ") didn't match ArrayType
(" +
                                          itemType + ")");
          }
          
          DeserializerBase dSer = context.getDeserializer(arrayItemType);
          dSer.registerCallback(this, new Integer(curIndex++));
          context.pushElementHandler(dSer);
      }
      
      public void onEndChild(String localName, DeserializerBase deserializer)
          throws SAXException
      {
      }
      
      public void valueReady(Object value, Object hint)
      {
          Array.set(this.value, ((Integer)hint).intValue(), value);
      }
  
      public void serialize(QName name, Attributes attributes,
                            Object value, SerializationContext context)
          throws IOException
      {
          throw new IOException("Can't serialize Arrays just yet...");
      }
  }
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/encoding/ValueReceiver.java
  
  Index: ValueReceiver.java
  ===================================================================
  package org.apache.axis.encoding;
  
  public interface ValueReceiver
  {
      public void valueReady(Object value, Object hint);
  }
  
  
  
  1.11      +1 -29     xml-axis/java/src/org/apache/axis/message/RPCParam.java
  
  Index: RPCParam.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCParam.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RPCParam.java	2001/05/04 19:24:47	1.10
  +++ RPCParam.java	2001/05/05 13:47:13	1.11
  @@ -83,36 +83,8 @@
       {
           super(namespace, localName, attrs, context);
           name = localName;
  -
  -        // Check for type
  -        String type = null;
  -        for (int i=0; i<Constants.URIS_SCHEMA_XSI.length && type==null; i++)
  -            type = attrs.getValue(Constants.URIS_SCHEMA_XSI[i], "type");
           
  -        if (DEBUG_LOG)
  -            System.out.println("Got param.  Name ='" + name + "' Type is '" + type + "'");
  -        
  -        if (type == null)
  -          return;
  -        
  -        // OK, this is a QName, so look up the prefix in our current mappings.
  -        
  -        int i = type.indexOf(":");
  -        
  -        // !!! Can we have types that are in the default namespace?
  -        String nsURI = context.getNamespaceURI(type.substring(0, i));
  -        
  -        //System.out.println("namespace = " + nsURI);
  -        
  -        if (nsURI == null) {
  -            // !!! Should we just fault here (invalid NS prefix)?
  -            //     This of course implies that all the MessageElement
  -            //     constructors would be able to throw exceptions...
  -            type = null;
  -            return;
  -        }
  -        
  -        typeQName = new QName(nsURI, type.substring(i + 1));
  +        typeQName = context.getTypeFromAttributes(attrs);
       }
       
       /** Constructor for building up messages.
  
  
  

Mime
View raw message