tomj        02/02/27 11:19:44

  Modified:    java/src/org/apache/axis/encoding/ser
                        SimpleDeserializer.java
  Log:
  Rework SimpleType to store attributes until after the endElement, then set them.
  
  Revision  Changes    Path
  1.4       +53 -18    
xml-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java
  
  Index: SimpleDeserializer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleDeserializer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SimpleDeserializer.java   27 Feb 2002 13:41:27 -0000      1.3
  +++ SimpleDeserializer.java   27 Feb 2002 19:19:44 -0000      1.4
  @@ -61,6 +61,8 @@
   import java.lang.reflect.InvocationTargetException;
   import java.util.Vector;
   import java.util.HashMap;
  +import java.util.Set;
  +import java.util.Iterator;
   
   import org.apache.axis.InternalException;
   import org.apache.axis.message.SOAPHandler;
  @@ -96,6 +98,7 @@
       private Constructor constructor = null;
       private BeanPropertyDescriptor[] pd = null;
       private HashMap propertyMap = new HashMap();
  +    private HashMap attributeMap = null;
   
       public QName xmlType;
       public Class javaType;
  @@ -175,6 +178,9 @@
           } catch (Exception e) {
               throw new SAXException(e);
           }
  +        
  +        // If this is a SimpleType, set attributes we have stashed away
  +        setSimpleTypeAttributes();
       }
       
       /**
  @@ -268,16 +274,22 @@
                       !beanAttributeNames.contains(attrNameLo))
                       continue;
   
  -                // look for the attribute property
  +                if (attributeMap == null)
  +                    attributeMap = new HashMap();
  +                
  +                // look for the attribute property, save the name
  +                attrName = attrNameUp;
                   BeanPropertyDescriptor bpd = 
                       (BeanPropertyDescriptor) propertyMap.get(attrNameUp);
  -                if (bpd == null)
  +                if (bpd == null) {
  +                    attrName = attrNameLo;
                       bpd = (BeanPropertyDescriptor) propertyMap.get(attrNameLo);
  -                if (bpd == null)
  +                }
  +                if (bpd == null) {
  +                    attrName = mangledName;
                       bpd = (BeanPropertyDescriptor) propertyMap.get(mangledName);
  +                }
                   if (bpd != null) {
  -                    if (bpd.getWriteMethod() == null ) continue ;
  -                    
                       // determine the QName for this child element
                       TypeMapping tm = context.getTypeMapping();
                       Class type = bpd.getType();
  @@ -293,20 +305,17 @@
                               JavaUtils.getMessage("noDeser00", type.toString()));
                       if (! (dSer instanceof SimpleDeserializer))
                           throw new SAXException(
  -                            JavaUtils.getMessage("AttrNotSimpleType00", 
  -                                                 bpd.getName(), 
  -                                                 type.toString()));
  -                
  -                    if (bpd.getWriteMethod().getParameterTypes().length == 1) {
  -                        // Success!  Create an object from the string and set
  -                        // it in the bean
  -                        try {
  -                            Object val = ((SimpleDeserializer)dSer).
  +                                JavaUtils.getMessage("AttrNotSimpleType00", 
  +                                        bpd.getName(), 
  +                                        type.toString()));
  +                    
  +                    // Success!  Store name, value in HashMap for later
  +                    try {
  +                        Object val = ((SimpleDeserializer)dSer).
                                   makeValue(attributes.getValue(i));
  -                            bpd.getWriteMethod().invoke(value, new Object[] {val} );
  -                        } catch (Exception e) {
  -                            throw new SAXException(e);
  -                        }
  +                        attributeMap.put(attrName, val);
  +                    } catch (Exception e) {
  +                        throw new SAXException(e);
                       }
                   
                   } // if bpd != null
  @@ -314,5 +323,31 @@
           } // if attributes exist
       } // onStartElement
   
  +    /**
  +     * Process any attributes we may have encountered (in onStartElement)
  +     */ 
  +    private void setSimpleTypeAttributes() throws SAXException {
  +        // if this isn't a simpleType bean, wont have attributes
  +        if (! SimpleType.class.isAssignableFrom(javaType))
  +            return;
  +        
  +        // loop through map
  +        Set keys = attributeMap.keySet();
  +        for (Iterator iterator = keys.iterator(); iterator.hasNext();) {
  +            String name = (String) iterator.next();
  +            Object val = attributeMap.get(name);
  +            
  +            BeanPropertyDescriptor bpd = 
  +                    (BeanPropertyDescriptor) propertyMap.get(name);
  +            if (bpd.getWriteMethod() == null) continue;
  +            try {
  +                if (bpd.getWriteMethod().getParameterTypes().length == 1) {
  +                    bpd.getWriteMethod().invoke(value, new Object[] {val} );
  +                }
  +            } catch (Exception e) {
  +                throw new SAXException(e);
  +            }
  +        }
  +    }
   
   }
  
  
  


Reply via email to