axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/encoding/ser BaseDeserializerFactory.java BaseSerializerFactory.java SimpleDeserializer.java SimpleDeserializerFactory.java SimpleSerializerFactory.java
Date Thu, 18 Nov 2004 23:39:18 GMT
gawor       2004/11/18 15:39:18

  Modified:    java/src/org/apache/axis/encoding/ser
                        BaseDeserializerFactory.java
                        BaseSerializerFactory.java SimpleDeserializer.java
                        SimpleDeserializerFactory.java
                        SimpleSerializerFactory.java
  Log:
  just some optimizations to avoid reflection for selected builtin types
  
  Revision  Changes    Path
  1.24      +4 -4      ws-axis/java/src/org/apache/axis/encoding/ser/BaseDeserializerFactory.java
  
  Index: BaseDeserializerFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/BaseDeserializerFactory.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- BaseDeserializerFactory.java	15 Nov 2004 07:13:11 -0000	1.23
  +++ BaseDeserializerFactory.java	18 Nov 2004 23:39:18 -0000	1.24
  @@ -106,7 +106,7 @@
        */
       protected Deserializer getGeneralPurpose(String mechanismType) {
           if (javaType != null && xmlType != null) {
  -        	Constructor deserClassConstructor = getDeserClassConstructor();
  +            Constructor deserClassConstructor = getDeserClassConstructor();
               if (deserClassConstructor != null) {
                   try {
                       return (Deserializer) 
  @@ -148,7 +148,7 @@
        */
       protected Deserializer getSpecialized(String mechanismType) {
           if (javaType != null && xmlType != null) {
  -        	Method getDeserializer = getGetDeserializer();
  +            Method getDeserializer = getGetDeserializer();
               if (getDeserializer != null) {
                   try {
                       return (Deserializer) 
  @@ -279,7 +279,7 @@
        * Returns the deserClassConstructor.
        * @return Constructor
        */
  -	protected Constructor getDeserClassConstructor() {
  +    protected Constructor getDeserClassConstructor() {
       	if (deserClassConstructor == null) { 
               deserClassConstructor = getConstructor(deserClass);
           } 
  @@ -290,7 +290,7 @@
        * Returns the getDeserializer.
        * @return Method
        */
  -	protected Method getGetDeserializer() {
  +    protected Method getGetDeserializer() {
       	if (getDeserializer == null) {
               getDeserializer = getMethod(javaType,"getDeserializer");    
           }
  
  
  
  1.32      +7 -5      ws-axis/java/src/org/apache/axis/encoding/ser/BaseSerializerFactory.java
  
  Index: BaseSerializerFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/BaseSerializerFactory.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- BaseSerializerFactory.java	15 Nov 2004 07:13:11 -0000	1.31
  +++ BaseSerializerFactory.java	18 Nov 2004 23:39:18 -0000	1.32
  @@ -116,7 +116,7 @@
        */
       protected Serializer getGeneralPurpose(String mechanismType) {
           if (javaType != null && xmlType != null) {
  -        	Constructor serClassConstructor = getSerClassConstructor();
  +            Constructor serClassConstructor = getSerClassConstructor();
               if (serClassConstructor != null) {
                   try {
                       return (Serializer) 
  @@ -159,6 +159,7 @@
        */
       protected Serializer getSpecialized(String mechanismType) {
           if (javaType != null && xmlType != null) {
  +            Method getSerializer = getGetSerializer();
               if (getSerializer != null) {
                   try {
                       return (Serializer) 
  @@ -303,26 +304,27 @@
           }
           return sf;
       }
  +
       /**
        * Returns the getSerializer.
        * @return Method
        */
  -	protected Method getGetSerializer() {
  +    protected Method getGetSerializer() {
       	if (getSerializer == null) {
               getSerializer = getMethod(javaType, "getSerializer");
           }
       	return getSerializer;
       }
  -
  +    
       /**
        * Returns the serClassConstructor.
        * @return Constructor
        */
  -	protected Constructor getSerClassConstructor() {
  +    protected Constructor getSerClassConstructor() {
       	if (serClassConstructor == null) {
               serClassConstructor = getConstructor(serClass);
           }
       	return serClassConstructor;
       }
  -
  +    
   }
  
  
  
  1.42      +81 -34    ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java
  
  Index: SimpleDeserializer.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- SimpleDeserializer.java	16 Nov 2004 16:36:37 -0000	1.41
  +++ SimpleDeserializer.java	18 Nov 2004 23:39:18 -0000	1.42
  @@ -78,6 +78,7 @@
           
           init();
       }
  +
       public SimpleDeserializer(Class javaType, QName xmlType, TypeDesc typeDesc) {
           this.xmlType = xmlType;
           this.javaType = javaType;
  @@ -191,17 +192,62 @@
        */
       public Object makeValue(String source) throws Exception
       {
  +        if (javaType == java.lang.String.class) {
  +            return source;
  +        }
  +
           // Trim whitespace if non-String
  -        if (javaType != java.lang.String.class)
  -            source = source.trim();
  +        source = source.trim();
   
  -        if (source.length() == 0 && typeDesc == null &&
  -                javaType != java.lang.String.class) {
  +        if (source.length() == 0 && typeDesc == null) {
               return null;
           }
           
  +        // if constructor is set skip all basic java type checks
  +        if (this.constructor == null) {
  +            Object value = makeBasicValue(source);
  +            if (value != null) {
  +                return value;
  +            }
  +        }
  +            
  +        Object [] args = null;
  +        
  +        boolean isQNameSubclass = QName.class.isAssignableFrom(javaType);
  +
  +        if (isQNameSubclass) {
  +            int colon = source.lastIndexOf(":");
  +            String namespace = colon < 0 ? "" :
  +                context.getNamespaceURI(source.substring(0, colon));
  +            String localPart = colon < 0 ? source : source.substring(colon + 1);
  +            args = new Object [] {namespace, localPart};
  +        } 
  +
  +        if (constructor == null) {
  +            try {
  +                if (isQNameSubclass) {
  +                    constructor = 
  +                        javaType.getDeclaredConstructor(STRING_STRING_CLASS);
  +                } else {
  +                    constructor = 
  +                        javaType.getDeclaredConstructor(STRING_CLASS);
  +                }
  +            } catch (Exception e) {
  +                return null;
  +            }
  +        }
  +        
  +        if (args == null) {
  +            args = new Object[] { source };
  +        }
  +        
  +        return constructor.newInstance(args);
  +    }
  +
  +    private Object makeBasicValue(String source) throws Exception {
           // If the javaType is a boolean, except a number of different sources
  -        if (javaType == boolean.class || javaType == Boolean.class) {
  +        if (javaType == boolean.class || 
  +            javaType == Boolean.class) {
               // This is a pretty lame test, but it is what the previous code did.
               switch (source.charAt(0)) {
                   case '0': case 'f': case 'F':
  @@ -213,63 +259,64 @@
                   default:
                       throw new NumberFormatException(
                               Messages.getMessage("badBool00"));
  -            }
  +                }
               
           }
           
           // If expecting a Float or a Double, need to accept some special cases.
           if (javaType == float.class ||
  -                javaType == java.lang.Float.class) {
  +            javaType == java.lang.Float.class) {
               if (source.equals("NaN")) {
                   return new Float(Float.NaN);
               } else if (source.equals("INF")) {
                   return new Float(Float.POSITIVE_INFINITY);
               } else if (source.equals("-INF")) {
                   return new Float(Float.NEGATIVE_INFINITY);
  +            } else {
  +                return new Float(source);
               }
           }
  +        
           if (javaType == double.class ||
  -                javaType == java.lang.Double.class) {
  +            javaType == java.lang.Double.class) {
               if (source.equals("NaN")) {
                   return new Double(Double.NaN);
               } else if (source.equals("INF")) {
                   return new Double(Double.POSITIVE_INFINITY);
               } else if (source.equals("-INF")) {
                   return new Double(Double.NEGATIVE_INFINITY);
  +            } else {
  +                return new Double(source);
               }
           }    
  -
  -        Object [] args = null;
           
  -        if (QName.class.isAssignableFrom(javaType)) {
  -            int colon = source.lastIndexOf(":");
  -            String namespace = colon < 0 ? "" :
  -                context.getNamespaceURI(source.substring(0, colon));
  -            String localPart = colon < 0 ? source : source.substring(colon + 1);
  -            args = new Object [] {namespace, localPart};
  -        } 
  -
  -        if (constructor == null) {
  -            try {
  -                if (QName.class.isAssignableFrom(javaType)) {
  -                    constructor = 
  -                        javaType.getDeclaredConstructor(STRING_STRING_CLASS);
  -                } else {
  -                    constructor = 
  -                        javaType.getDeclaredConstructor(STRING_CLASS);
  -                }
  -            } catch (Exception e) {
  -                return null;
  -            }
  +        if (javaType == int.class ||
  +            javaType == java.lang.Integer.class) {
  +            return new Integer(source);
           }
           
  -        if (args == null) {
  -            args = new Object[] { source };
  +        if (javaType == short.class ||
  +            javaType == java.lang.Short.class) {
  +            return new Short(source);
           }
           
  -        return constructor.newInstance(args);
  +        if (javaType == long.class ||
  +            javaType == java.lang.Long.class) {
  +            return new Long(source);
  +        }
  +        
  +        if (javaType == byte.class ||
  +            javaType == java.lang.Byte.class) {
  +            return new Byte(source);
  +        }
  +        
  +        if (javaType == org.apache.axis.types.URI.class) {
  +            return new org.apache.axis.types.URI(source);
  +        }
  +
  +        return null;
       }
  -    
  +        
       /**
        * Set the bean properties that correspond to element attributes.
        * 
  
  
  
  1.11      +34 -17    ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializerFactory.java
  
  Index: SimpleDeserializerFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializerFactory.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- SimpleDeserializerFactory.java	15 Nov 2004 07:13:11 -0000	1.10
  +++ SimpleDeserializerFactory.java	18 Nov 2004 23:39:18 -0000	1.11
  @@ -40,14 +40,17 @@
           new Class [] {String.class};
   
       private Constructor constructor = null;
  +    private boolean isBasicType = false;
       /**
        * Note that the factory is constructed with the QName and xmlType.  This is important
        * to allow distinction between primitive values and java.lang wrappers.
        **/
       public SimpleDeserializerFactory(Class javaType, QName xmlType) {
           super(SimpleDeserializer.class, xmlType, javaType);
  -        try {
  -            if (!javaType.isPrimitive()) {
  +        this.isBasicType = isBasic(javaType);
  +        if (!this.isBasicType) {
  +            // discover the constructor for non basic types
  +            try {
                   if (QName.class.isAssignableFrom(javaType)) {
                       constructor = 
                           javaType.getDeclaredConstructor(STRING_STRING_CLASS);
  @@ -55,18 +58,24 @@
                       constructor = 
                           javaType.getDeclaredConstructor(STRING_CLASS);
                   }
  -            }
  -            else {
  -                Class wrapper = JavaUtils.getWrapperClass(javaType);
  -                if (wrapper != null)
  -                    constructor = 
  -                        wrapper.getDeclaredConstructor(STRING_CLASS);
  -            }
  -        } catch (java.lang.NoSuchMethodException e) {
  -            throw new IllegalArgumentException(e.toString());
  -        } 
  +            } catch (java.lang.NoSuchMethodException e) {
  +                throw new IllegalArgumentException(e.toString());
  +            } 
  +        }
       }
       
  +    /*
  +     * Any builtin type that has a constructor that takes a String is a basic
  +     * type.
  +     * This is for optimization purposes, so that we don't introspect
  +     * primitive java types or some basic Axis types.
  +     */
  +    private static boolean isBasic(Class javaType) {
  +        return (javaType.isPrimitive() || 
  +                javaType == java.lang.String.class ||
  +                javaType == org.apache.axis.types.URI.class);
  +    }
  +
       /**
        * Get the Deserializer and the set the Constructor so the
        * deserializer does not have to do introspection.
  @@ -76,10 +85,18 @@
           if (javaType == java.lang.Object.class) {
               return null;
           }
  -        SimpleDeserializer deser = (SimpleDeserializer) super.getDeserializerAs(mechanismType);
  -        if (deser != null)
  -            deser.setConstructor(constructor);
  -        return deser;
  +        if (this.isBasicType) {
  +            return new SimpleDeserializer(javaType, xmlType);
  +        } else {
  +            // XXX: don't think we can always expect to be SimpleDeserializer
  +            // since getSpecialized() might return a different type
  +            SimpleDeserializer deser = 
  +                (SimpleDeserializer) super.getDeserializerAs(mechanismType);
  +            if (deser != null) {
  +                deser.setConstructor(constructor);
  +            }
  +            return deser;
  +        }
       }
  -            
  +    
   }
  
  
  
  1.4       +26 -0     ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializerFactory.java
  
  Index: SimpleSerializerFactory.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializerFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleSerializerFactory.java	25 Feb 2004 14:02:37 -0000	1.3
  +++ SimpleSerializerFactory.java	18 Nov 2004 23:39:18 -0000	1.4
  @@ -20,13 +20,39 @@
   package org.apache.axis.encoding.ser;
   
   import javax.xml.namespace.QName;
  +import javax.xml.rpc.JAXRPCException;
   
   public class SimpleSerializerFactory extends BaseSerializerFactory {
  +
  +    private boolean isBasicType = false;
  +
       /**
        * Note that the factory is constructed with the QName and xmlType.  This is important
        * to allow distinction between primitive values and java.lang wrappers.
        **/
       public SimpleSerializerFactory(Class javaType, QName xmlType) {
           super(SimpleSerializer.class, xmlType, javaType);
  +        this.isBasicType = isBasic(javaType);
  +    }
  +
  +    /*
  +     * Any builtin type that has a constructor that takes a String is a basic
  +     * type.
  +     * This is for optimization purposes, so that we don't introspect
  +     * primitive java types or some basic Axis types.
  +     */
  +    private static boolean isBasic(Class javaType) {
  +        return (javaType.isPrimitive() || 
  +                javaType == java.lang.String.class ||
  +                javaType == org.apache.axis.types.URI.class);
  +    }
  +
  +    public javax.xml.rpc.encoding.Serializer getSerializerAs(String mechanismType) throws
JAXRPCException {
  +        if (this.isBasicType) {
  +            return new SimpleSerializer(javaType, xmlType);
  +        } else {
  +            return super.getSerializerAs(mechanismType);
  +        }
       }
  +    
   }
  
  
  

Mime
View raw message