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/symbolTable SchemaUtils.java
Date Sat, 24 Aug 2002 01:25:20 GMT
scheu       2002/08/23 18:25:20

  Modified:    java/src/org/apache/axis Constants.java
               java/src/org/apache/axis/encoding
                        DeserializationContext.java
                        DeserializationContextImpl.java
                        TypeMappingImpl.java
               java/src/org/apache/axis/encoding/ser ArrayDeserializer.java
                        BeanDeserializer.java
               java/src/org/apache/axis/wsdl/symbolTable SchemaUtils.java
  Log:
  Some changes made to help performance.
  
  1) Speed up of the Pair class in TypeMappingImpl.  May need some more improvement later.
  
  2) DeserializationContestImpl.getTypeFromAttributes is called for every element.
     If the request does not have an xsi:type, a high performance penalty is incurred
     constructing a QName and doing a series of if tests.  This is now improved, and
     BeanDeserializer now calls getTypeFromXSITypeAttr for its children
  
  3) BeanDeserializer onStartChild constructs a default DeserializerImpl if no
     Deserializer is found for the child element.  This is a major performance penalty if
     the request does not have xsi:types.  In such cases a DeserializerImpl is created
     to simply find the right Deserializer down stream.  Added a short circuit to see
     if the child element is a simple primitive type (most cases) and create the proper
     deserializer directly.  A similar change is made in the array deserializer.
  
     Ultimately I think that DeserializationImpl should have a static createDeserializer(...)
     method instead of having hard-coded calls to new DeserializerImpl().  Thus extra
     logic (like the short circuit in (3) could be applied in all situations).
  
  Revision  Changes    Path
  1.84      +1 -1      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.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- Constants.java	19 Aug 2002 03:23:23 -0000	1.83
  +++ Constants.java	24 Aug 2002 01:25:19 -0000	1.84
  @@ -166,7 +166,7 @@
       public static String getValue(Attributes attributes,
                                     String [] search,
                                     String localPart) {
  -        if (attributes == null || search == null || localPart == null)
  +        if (attributes == null || attributes.getLength() == 0 || search == null || localPart
== null)
               return null;
   
           int len = attributes.getLength();
  
  
  
  1.49      +9 -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.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- DeserializationContext.java	23 Aug 2002 15:08:56 -0000	1.48
  +++ DeserializationContext.java	24 Aug 2002 01:25:19 -0000	1.49
  @@ -143,6 +143,15 @@
   
       /** 
        * Create a QName for the type of the element defined by localName and
  +     * namespace from the XSI type.
  +     * @param namespace of the element
  +     * @param localName is the local name of the element
  +     * @param attrs are the attributes on the element
  +     */
  +    public QName getTypeFromXSITypeAttr(String namespace, String localName,
  +                                        Attributes attrs);
  +    /** 
  +     * Create a QName for the type of the element defined by localName and
        * namespace with the specified attributes.
        * @param namespace of the element
        * @param localName is the local name of the element
  
  
  
  1.54      +43 -31    xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java
  
  Index: DeserializationContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- DeserializationContextImpl.java	23 Aug 2002 23:50:31 -0000	1.53
  +++ DeserializationContextImpl.java	24 Aug 2002 01:25:19 -0000	1.54
  @@ -330,53 +330,65 @@
   
       /**
        * Create a QName for the type of the element defined by localName and
  -     * namespace with the specified attributes.
  +     * namespace from the XSI type.
        * @param namespace of the element
        * @param localName is the local name of the element
        * @param attrs are the attributes on the element
        */
  -    public QName getTypeFromAttributes(String namespace, String localName,
  -                                       Attributes attrs)
  -    {
  -        QName typeQName = null;
  -
  +    public QName getTypeFromXSITypeAttr(String namespace, String localName,
  +                                          Attributes attrs) {
           // Check for type
           String type = Constants.getValue(attrs, Constants.URIS_SCHEMA_XSI,
                                            "type");
           if (type != null) {
               // Return the type attribute value converted to a QName
               return getQNameFromString(type);
  -        }
  +        } 
  +        return null;
  +    }
   
  +    /** 
  +     * Create a QName for the type of the element defined by localName and
  +     * namespace with the specified attributes.
  +     * @param namespace of the element
  +     * @param localName is the local name of the element
  +     * @param attrs are the attributes on the element
  +     */
  +    public QName getTypeFromAttributes(String namespace, String localName,
  +                                       Attributes attrs)
  +    {
  +        QName typeQName = getTypeFromXSITypeAttr(namespace, localName, attrs);
           if (typeQName == null) {
   
               // If the element is a SOAP-ENC element, the name of the element is the type.
               // If the default type mapping accepts SOAP 1.2, then use then set
               // the typeQName to the SOAP-ENC type.
  -            // Else if the default type mapping accepts SOAP 1.1, then
  -            // convert the SOAP-ENC type to the appropriate XSD Schema Type.
  -            QName myQName = new QName(namespace, localName);
  -            if (Constants.URI_DEFAULT_SOAP_ENC.equals(Constants.URI_SOAP12_ENC) &&
  -                Constants.isSOAP_ENC(namespace)) {
  -                typeQName = myQName;
  -            } else if (myQName.equals(Constants.SOAP_ARRAY)) {
  -                typeQName = Constants.SOAP_ARRAY;
  -            } else if (myQName.equals(Constants.SOAP_STRING)) {
  -                typeQName = Constants.SOAP_STRING;
  -            } else if (myQName.equals(Constants.SOAP_BOOLEAN)) {
  -                typeQName = Constants.SOAP_BOOLEAN;
  -            } else if (myQName.equals(Constants.SOAP_DOUBLE)) {
  -                typeQName = Constants.SOAP_DOUBLE;
  -            } else if (myQName.equals(Constants.SOAP_FLOAT)) {
  -                typeQName = Constants.SOAP_FLOAT;
  -            } else if (myQName.equals(Constants.SOAP_INT)) {
  -                typeQName = Constants.SOAP_INT;
  -            } else if (myQName.equals(Constants.SOAP_LONG)) {
  -                typeQName = Constants.SOAP_LONG;
  -            } else if (myQName.equals(Constants.SOAP_SHORT)) {
  -                typeQName = Constants.SOAP_SHORT;
  -            } else if (myQName.equals(Constants.SOAP_BYTE)) {
  -                typeQName = Constants.SOAP_BYTE;
  +            // Else if the default type mapping accepts SOAP 1.1, then 
  +            // convert the SOAP-ENC type to the appropriate SOAP Schema Type.
  +            if (Constants.isSOAP_ENC(namespace)) {
  +                QName myQName = new QName(namespace, localName);
  +                if (Constants.URI_DEFAULT_SOAP_ENC.equals(Constants.URI_SOAP12_ENC) &&
  +                    Constants.isSOAP_ENC(namespace)) {
  +                    typeQName = myQName;
  +                } else if (myQName.equals(Constants.SOAP_ARRAY)) {
  +                    typeQName = Constants.SOAP_ARRAY;
  +                } else if (myQName.equals(Constants.SOAP_STRING)) {
  +                    typeQName = Constants.SOAP_STRING;
  +                } else if (myQName.equals(Constants.SOAP_BOOLEAN)) {
  +                    typeQName = Constants.SOAP_BOOLEAN;
  +                } else if (myQName.equals(Constants.SOAP_DOUBLE)) {
  +                    typeQName = Constants.SOAP_DOUBLE;
  +                } else if (myQName.equals(Constants.SOAP_FLOAT)) {
  +                    typeQName = Constants.SOAP_FLOAT;
  +                } else if (myQName.equals(Constants.SOAP_INT)) {
  +                    typeQName = Constants.SOAP_INT;
  +                } else if (myQName.equals(Constants.SOAP_LONG)) {
  +                    typeQName = Constants.SOAP_LONG;
  +                } else if (myQName.equals(Constants.SOAP_SHORT)) {
  +                    typeQName = Constants.SOAP_SHORT;
  +                } else if (myQName.equals(Constants.SOAP_BYTE)) {
  +                    typeQName = Constants.SOAP_BYTE;
  +                }
               }
           }
   
  
  
  
  1.26      +8 -12     xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
  
  Index: TypeMappingImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- TypeMappingImpl.java	16 Aug 2002 16:41:35 -0000	1.25
  +++ TypeMappingImpl.java	24 Aug 2002 01:25:19 -0000	1.26
  @@ -108,21 +108,17 @@
           public boolean equals(Object o) {
               if (o == null) return false;
               Pair p = (Pair) o;
  -            if (p.xmlType == null) {
  -                if (this.xmlType != null)
  -                    return false;
  -            } else {
  -                if (!p.xmlType.equals(this.xmlType))
  -                    return false;
  -            }
  -            if (p.javaType == null) {
  -                return (this.javaType == null);
  -            } else {
  -                return (p.javaType.equals(this.javaType));
  +            // Test straight equality
  +            if (p.xmlType == this.xmlType &&
  +                p.javaType == this.javaType) {
  +                return true;
               }
  +            // Note xmlType and javaType are always non-null
  +            return (p.xmlType.equals(this.xmlType) &&
  +                    p.javaType.equals(this.javaType));
           }
           public int hashCode() {
  -            return javaType.hashCode();
  +            return javaType.hashCode() + xmlType.hashCode();
           }
       }
   
  
  
  
  1.26      +37 -16    xml-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java
  
  Index: ArrayDeserializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/ArrayDeserializer.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ArrayDeserializer.java	3 Aug 2002 21:25:24 -0000	1.25
  +++ ArrayDeserializer.java	24 Aug 2002 01:25:19 -0000	1.26
  @@ -63,7 +63,7 @@
   import org.apache.axis.message.SOAPHandler;
   import org.apache.axis.utils.ClassUtils;
   import org.apache.axis.utils.JavaUtils;
  -
  +import org.apache.axis.wsdl.symbolTable.SchemaUtils;
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.commons.logging.Log;
   
  @@ -391,27 +391,48 @@
                                                          localName,
                                                          attributes);
   
  -        // Get the deserializer for the type.  If no deserializer is 
  -        // found, the deserializer is set to DeserializerImpl().
  -        // It is possible that the element has an href, thus we
  -        // won't know the type until the definitition is encountered.
  +        // Get the deserializer for the type. 
           Deserializer dSer = null;
           if (itemType != null) {
               dSer = context.getDeserializerForType(itemType);
           }
  +
           if (dSer == null) {
  -            dSer = new DeserializerImpl();
  -            // Determine a default type for the deserializer
  -            if (itemType == null) {
  -                QName defaultType = defaultItemType;
  -                // If defaultType is not known, try using the arrayClass info
  -                if (defaultType == null &&
  -                    arrayClass != null &&
  -                    arrayClass.isArray()) {
  -                    defaultType = context.getTypeMapping().
  -                        getTypeQName(arrayClass.getComponentType());
  +            // No deserializer can be found directly.  Need to look harder
  +            QName defaultType = defaultItemType;
  +            Class javaType = null;
  +            if (arrayClass != null &&
  +                arrayClass.isArray() &&
  +                defaultType == null) {
  +                javaType = arrayClass.getComponentType();
  +                defaultType = context.getTypeMapping().getTypeQName(javaType);
  +            }
  +
  +            // We don't have a deserializer, the safest thing to do
  +            // is to set up using the DeserializerImpl below.  
  +            // The DeserializerImpl will take care of href/id and
  +            // install the appropriate serializer, etc.  The problem 
  +            // is that takes a lot of time and will occur 
  +            // all the time if no xsi:types are sent.  Most of the
  +            // time an item is a simple schema type (i.e. String)
  +            // so the following shortcut is used to get a Deserializer
  +            // for these cases. 
  +            if (itemType == null && dSer == null) {
  +                if (defaultType != null && SchemaUtils.isSimpleSchemaType(defaultType))
{
  +                    dSer = context.getDeserializer(javaType, defaultType);
  +                }
  +            }
  +            
  +            // If no deserializer is 
  +            // found, the deserializer is set to DeserializerImpl().
  +            // It is possible that the element has an href, thus we
  +            // won't know the type until the definitition is encountered.
  +            if (dSer == null) {
  +                dSer = new DeserializerImpl();
  +                // Determine a default type for the deserializer
  +                if (itemType == null) {
  +                    dSer.setDefaultType(defaultType);
                   }
  -                dSer.setDefaultType(defaultType);
               }
           }
   
  
  
  
  1.49      +33 -10    xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java
  
  Index: BeanDeserializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanDeserializer.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- BeanDeserializer.java	20 Aug 2002 03:55:47 -0000	1.48
  +++ BeanDeserializer.java	24 Aug 2002 01:25:19 -0000	1.49
  @@ -64,6 +64,7 @@
   import org.apache.axis.message.MessageElement;
   import org.apache.axis.utils.BeanPropertyDescriptor;
   import org.apache.axis.utils.JavaUtils;
  +import org.apache.axis.wsdl.symbolTable.SchemaUtils;
   
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.commons.logging.Log;
  @@ -248,21 +249,43 @@
   
           // Look at the type attribute specified.  If this fails,
           // use the javaType of the property to get the type qname.
  -        QName qn = context.getTypeFromAttributes(namespace, localName,
  -                                                 attributes);
  +        QName qn = context.getTypeFromXSITypeAttr(namespace, 
  +                                                  localName,
  +                                                  attributes);
   
           // get the deserializer
  -        Deserializer dSer = context.getDeserializerForType(qn);
  +        Deserializer dSer = null;
  +        if (qn !=null) {
  +            dSer = context.getDeserializerForType(qn);
  +        }
   
  -        // If no deserializer, use the base DeserializerImpl.
  -        // There may not be enough information yet to choose the
  -        // specific deserializer.
  +        // We don't have a deserializer, the safest thing to do
  +        // is to set up using the DeserializerImpl below.  
  +        // The DeserializerImpl will take care of href/id and
  +        // install the appropriate deserializer, etc.  The problem 
  +        // is that takes a lot of time and will occur 
  +        // all the time if no xsi:types are sent.  Most of the
  +        // time an element of a bean is a simple schema type (i.e. String)
  +        // so the following shortcut is used to get a Deserializer
  +        // for these cases.
           if (dSer == null) {
  -            dSer = new DeserializerImpl();
  -            // determine a default type for this child element
  +            Class javaType = propDesc.getType();
               TypeMapping tm = context.getTypeMapping();
  -            Class type = propDesc.getType();
  -            dSer.setDefaultType(tm.getTypeQName(type));
  +            QName qName = tm.getTypeQName(javaType);
  +            if (qn == null && dSer == null) {
  +                if (qName != null && SchemaUtils.isSimpleSchemaType(qName)) {
  +                    dSer = context.getDeserializer(javaType, qName);
  +                }
  +            }
  +            
  +            // If no deserializer, use the base DeserializerImpl
  +            // There may not be enough information yet to choose the
  +            // specific deserializer.
  +            if (dSer == null) {
  +                dSer = new DeserializerImpl();
  +                // determine a default javaType for this child element
  +                dSer.setDefaultType(qName);
  +            }
           }
                   
           if (propDesc.isWriteable()) {
  
  
  
  1.13      +3 -1      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.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- SchemaUtils.java	15 Aug 2002 21:27:47 -0000	1.12
  +++ SchemaUtils.java	24 Aug 2002 01:25:19 -0000	1.13
  @@ -1149,10 +1149,12 @@
       /**
        * Determine if a string is a simple XML Schema type 
        */ 
  -    public static boolean isSimpleSchemaType(String s) {
  +    private static boolean isSimpleSchemaType(String s) {
           if (s == null)
               return false;
           
  +        // This is rather expensive.  Probably should be
  +        // a hash lookup.  
           for (int i = 0; i < schemaTypes.length; i++) {
               if (schemaTypes[i].equals(s))
                   return true;
  
  
  

Mime
View raw message