axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/wsdl/fromJava Types.java
Date Thu, 20 Dec 2001 19:51:32 GMT
scheu       01/12/20 11:51:32

  Modified:    java/docs user-guide.html
               java/samples/echo deploy.wsdd
               java/src/org/apache/axis/deployment/wsdd
                        WSDDBeanMapping.java
               java/src/org/apache/axis/encoding BeanSerializer.java
                        TypeMappingRegistry.java
               java/src/org/apache/axis/wsdl/fromJava Types.java
  Log:
  The following changes were made:
    1) In Bean Deserialization, accept an element name if it matches
       a class property ignoring the case of the first letter.
    2) In Bean Serialization, new constructors are provided to allow a
       client to force the first letter of property element names to upper (or lower) case.
    3) Changed the class BeanSerFactory to BeanDeserFactory!  After all it is a
       deserialization factory!  Changed the samples and documentation to reflect
       the name change.
    4) Minor change in Java2WSDL
  
  Revision  Changes    Path
  1.32      +1 -1      xml-axis/java/docs/user-guide.html
  
  Index: user-guide.html
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/docs/user-guide.html,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- user-guide.html	2001/12/19 15:30:08	1.31
  +++ user-guide.html	2001/12/20 19:51:31	1.32
  @@ -568,7 +568,7 @@
   the class name of a Deserializer <i>factory</i> that generates Deserializers
   which can be used to unmarshall XML into the correct Java class.
   <p>(the &lt;beanMapping> tag is really just shorthand for a &lt;typeMapping>
  -tag with serializer="org.apache.axis.encoding.BeanSerializer" and deserializer="org.apache.axis.encoding.BeanSerializer$BeanSerFactory",
  +tag with serializer="org.apache.axis.encoding.BeanSerializer" and deserializer="org.apache.axis.encoding.BeanSerializer$BeanDeserFactory",
   but clearly it can save a lot of typing!)
   <h2>
   <a NAME="WSDL"></a>Using WSDL with Axis</h2>
  
  
  
  1.5       +1 -1      xml-axis/java/samples/echo/deploy.wsdd
  
  Index: deploy.wsdd
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/echo/deploy.wsdd,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- deploy.wsdd	2001/12/01 13:04:25	1.4
  +++ deploy.wsdd	2001/12/20 19:51:31	1.5
  @@ -16,5 +16,5 @@
   
     <typeMapping xmlns:echo="http://soapinterop.org/xsd"
       qname="echo:SOAPStruct" languageSpecificType="java:samples.echo.SOAPStruct"
  -    serializer="org.apache.axis.encoding.BeanSerializer" deserializer="org.apache.axis.encoding.BeanSerializer$BeanSerFactory"/>
  +    serializer="org.apache.axis.encoding.BeanSerializer" deserializer="org.apache.axis.encoding.BeanSerializer$BeanDeserFactory"/>
   </deployment>
  
  
  
  1.2       +1 -1      xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDBeanMapping.java
  
  Index: WSDDBeanMapping.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDBeanMapping.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- WSDDBeanMapping.java	2001/11/25 23:49:33	1.1
  +++ WSDDBeanMapping.java	2001/12/20 19:51:31	1.2
  @@ -94,7 +94,7 @@
           super(e, true);
           
           serializer = "org.apache.axis.encoding.BeanSerializer";
  -        deserializer = "org.apache.axis.encoding.BeanSerializer$BeanSerFactory";
  +        deserializer = "org.apache.axis.encoding.BeanSerializer$BeanDeserFactory";
       }
   
       protected QName getElementName() {
  
  
  
  1.26      +83 -31    xml-axis/java/src/org/apache/axis/encoding/BeanSerializer.java
  
  Index: BeanSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/BeanSerializer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- BeanSerializer.java	2001/12/19 21:08:21	1.25
  +++ BeanSerializer.java	2001/12/20 19:51:32	1.26
  @@ -82,22 +82,71 @@
   {
       static Category category =
               Category.getInstance(BeanSerializer.class.getName());
  +    private Class cls;
  +    private PropertyDescriptor[] pd = null;
  +    private EnumSerializer enumSerializer = null;
  +    private static final Object[] noArgs = new Object[] {};  // For convenience
   
  +    // When serializing, the property element names passed over the wire
  +    // are the names of the properties (format=PROPERTY_NAME).
  +    // Setting the format to FORCE_UPPER will cause the
  +    // serializer to uppercase the first letter of the property element name.
  +    // Setting the format to FORCE_LOWER will cause the
  +    // serializer to uppercase the first letter of the property element name.
  +    private short elementPropertyFormat = PROPERTY_NAME;
  +    public static short PROPERTY_NAME = 0;
  +    public static short FORCE_UPPER   = 1;
  +    public static short FORCE_LOWER   = 2;
  +    
       /**
  -     * Class being serialized/deserialized
  +     * Default constructor.
        */
  -    private Class cls;
  +    public BeanSerializer() {
  +        super();
  +    }
  +
  +    /**
  +     * Constructor that takes a class.  Provided only for convenience.
  +     * Equivalent to calling setCls(cls) on a new instance.
  +     */
  +    public BeanSerializer(Class cls) {
  +        super();
  +        this.cls = cls;
  +    }
   
  +    /**
  +     * Constructor that takes a class and a format (PROPERTY_NAME, FORCE_UPPER, FORCE_LOWER)
  +     * Equivalent to calling setCls(cls) on a new instance.
  +     */
  +    public BeanSerializer(Class cls, short format) {
  +        super();
  +        this.cls = cls;
  +        if (format > FORCE_UPPER ||
  +            format < PROPERTY_NAME)
  +            format = PROPERTY_NAME;
  +        this.elementPropertyFormat = format;
  +    }
  +
  +    /**
  +     * Constructor that takes a class and a PropertyDescriptor array
  +     */
  +    public BeanSerializer(Class cls, PropertyDescriptor[] pd) {
  +        super();
  +        this.cls = cls;
  +        this.pd = pd;
  +    }
  +
  +    /**
  +     * Class being serialized/deserialized
  +     */
       protected void setCls(Class cls) {
           this.cls = cls;
       }
   
  +
       /**
        * Property Descriptors.  Retrieved once and cached in the serializer.
        */
  -    private PropertyDescriptor[] pd = null;
  -    private EnumSerializer enumSerializer = null;
  -
       protected PropertyDescriptor[] getPd() {
           if (pd==null) {
               try {
  @@ -208,37 +257,17 @@
           } catch (java.lang.NoSuchMethodException e) {}
           return false;
       }  
  -    /**
  -     * Default constructor.
  -     */
  -    public BeanSerializer() {
  -        super();
  -    }
   
  -    /**
  -     * Constructor that takes a class.  Provided only for convenience.
  -     * Equivalent to calling setCls(cls) on a new instance.
  -     */
  -    public BeanSerializer(Class cls) {
  -        super();
  -        this.cls = cls;
  -    }
  -
  -    /**
  -     * An array of nothing, defined only once.
  -     */
  -    private static final Object[] noArgs = new Object[] {};
  -
       public static DeserializerFactory getFactory()
       {
  -      return new BeanSerFactory();
  +      return new BeanDeserFactory();
       }
   
       /**
  -     * BeanSerializer Factory that creates instances with the specified
  +     * BeanDeSerializer Factory that creates instances with the specified
        * class.  Caches the PropertyDescriptor
        */
  -    public static class BeanSerFactory implements DeserializerFactory {
  +    public static class BeanDeserFactory implements DeserializerFactory {
           private Hashtable propertyDescriptors = new Hashtable();
         
           public Deserializer getDeserializer(Class cls) {
  @@ -336,9 +365,13 @@
   
           // look for a field by this name.  Assumes the the number of
           // properties in a bean is (relatively) small, so uses a linear
  -        // search.
  +        // search.  Accept a property if it differs only by the 
  +        // capitalization of the first character.
  +        String localNameUp = format(localName, FORCE_UPPER);
  +        String localNameLo = format(localName, FORCE_LOWER);
           for (int i=0; i<pd.length; i++) {
  -            if (pd[i].getName().equals(localName)) {
  +            if (pd[i].getName().equals(localNameUp) ||
  +                pd[i].getName().equals(localNameLo)) {
   
                   // determine the QName for this child element
                   TypeMappingRegistry tmr = context.getTypeMappingRegistry();
  @@ -381,8 +414,10 @@
   
           try {
               for (int i=0; i<pd.length; i++) {
  -                String propName = pd[i].getName();
  +                String propName = pd[i].getName();                
                   if (propName.equals("class")) continue;
  +                propName = format(propName, elementPropertyFormat);
  +                    
                   Object propValue = pd[i].getReadMethod().invoke(value,noArgs);
                   context.serialize(new QName("", propName), null, propValue);
               }
  @@ -394,6 +429,23 @@
           context.endElement();
       }
   
  +    /**
  +     * Returns the property name string formatted in the specified manner
  +     * @param name to format
  +     * @param fmt (PROPERTY_NAME, FORCE_LOWER, FORCE_UPPER)
  +     * @return formatted name 
  +     */
  +    private String format(String name, short fmt) {
  +        if (fmt == PROPERTY_NAME)
  +            return name;
  +        String theRest = "";
  +        if (name.length() > 1)
  +            theRest = name.substring(1);
  +        if (fmt == FORCE_UPPER)
  +            return Character.toUpperCase(name.charAt(0)) + theRest;
  +        else
  +            return Character.toLowerCase(name.charAt(0)) + theRest;
  +    }
   
   
       /**
  
  
  
  1.45      +1 -1      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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- TypeMappingRegistry.java	2001/12/12 21:39:42	1.44
  +++ TypeMappingRegistry.java	2001/12/20 19:51:32	1.45
  @@ -323,7 +323,7 @@
               QName elementQName;
   
               if (desc.factory.getClass() ==
  -                    BeanSerializer.BeanSerFactory.class) {
  +                    BeanSerializer.BeanDeserFactory.class) {
                   elementQName = WSDDConstants.BEANMAPPING_QNAME;
               } else {
                   elementQName = WSDDConstants.TYPE_QNAME;
  
  
  
  1.6       +4 -3      xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java
  
  Index: Types.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/fromJava/Types.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Types.java	2001/12/20 17:50:14	1.5
  +++ Types.java	2001/12/20 19:51:32	1.6
  @@ -190,10 +190,11 @@
           if (type.isArray()) {
               Class componentType = type.getComponentType();
   
  -            // Check for byte[] and Object[]
  -            if (componentType == java.lang.Byte.class ||
  -                componentType == java.lang.Byte.TYPE) {
  +            // Check for Byte[], byte[] and Object[]
  +            if (componentType == java.lang.Byte.class) {
                   qName = new javax.xml.rpc.namespace.QName(Constants.URI_SOAP_ENC, "base64");
  +            } else if (componentType == java.lang.Byte.TYPE) {
  +                qName = new javax.xml.rpc.namespace.QName(Constants.URI_CURRENT_SCHEMA_XSD,
"base64Binary");
               } else if (componentType == java.lang.Object.class) {
                   qName = new javax.xml.rpc.namespace.QName(Constants.URI_SOAP_ENC, "Array");
               } else {
  
  
  

Mime
View raw message