scheu       02/05/24 09:48:59

  Modified:    java/src/org/apache/axis/encoding/ser BeanDeserializer.java
  Log:
  This change is in response to defect
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9352
  
  The defect indicates that an NPE is thrown if a bean
  cannot be constructed (possibly due to a private default constructor).
  
  Tom made some changes that may have fixed this problem.
  
  These additional changes ensure that the bean is constructed
  or an exception is thrown prior to the href/id processing.
  
  Revision  Changes    Path
  1.26      +40 -7     
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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- BeanDeserializer.java     17 May 2002 19:09:35 -0000      1.25
  +++ BeanDeserializer.java     24 May 2002 16:48:58 -0000      1.26
  @@ -122,15 +122,48 @@
           try {
               value=javaType.newInstance();
           } catch (Exception e) {
  -/*
  -            throw new SAXException(JavaUtils.getMessage("cantCreateBean00", 
  -                                                        javaType.getName(), 
  -                                                        e.toString()));
  -*/
  +            // Don't process the exception at this point.
  +            // This is defered until the call to startElement
  +            // which will throw the exception.
           }
       }
   
       /**
  +     * startElement
  +     * 
  +     * The ONLY reason that this method is overridden is so that
  +     * the object value can be set or a reasonable exception is thrown
  +     * indicating that the object cannot be created.  This is done
  +     * at this point so that it occurs BEFORE href/id processing.
  +     * @param namespace is the namespace of the element
  +     * @param localName is the name of the element
  +     * @param qName is the prefixed qName of the element
  +     * @param attributes are the attributes on the element...used to get the type
  +     * @param context is the DeserializationContext
  +     */
  +    public void startElement(String namespace, String localName,
  +                             String qName, Attributes attributes,
  +                             DeserializationContext context)
  +        throws SAXException
  +    {
  +        // Create the bean object if it was not already
  +        // created in the constructor.
  +        if (value == null) {
  +            try {
  +                value=javaType.newInstance();
  +            } catch (Exception e) {
  +                // Failed to create an object.
  +                throw new SAXException(JavaUtils.getMessage("cantCreateBean00", 
  +                                                            javaType.getName(), 
  +                                                            e.toString()));
  +            }
  +        }
  +        // Invoke super.startElement to do the href/id processing.
  +        super.startElement(namespace, localName, 
  +                           qName, attributes, context);
  +    }
  +
  +    /**
        * Deserializer interface called on each child element encountered in
        * the XML stream.
        * @param namespace is the namespace of the child element
  @@ -307,6 +340,8 @@
                                  DeserializationContext context)
               throws SAXException {
   
  +        // The value should have been created or assigned already.
  +        // This code may no longer be needed.
           if (value == null) {
               // create a value
               try {
  @@ -331,8 +366,6 @@
               String fieldName = typeDesc.getFieldNameForAttribute(attrQName);
               if (fieldName == null)
                   continue;
  -
  -//            String attrName = attributes.getLocalName(i);
   
               // look for the attribute property
               BeanPropertyDescriptor bpd =
  
  
  


Reply via email to