axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "R J Scheuerle Jr" <sc...@us.ibm.com>
Subject Re: Issue - hard to subclass BeanSerializer
Date Wed, 19 Dec 2001 22:34:09 GMT
See my comments <RJS>

Rich Scheuerle
XML & Web Services Development
512-838-5115  (IBM TL 678-5115)


                                                                                         
                 
                    Mark Roder                                                           
                 
                    <mroder@wamnet       To:     "'axis-dev@xml.apache.org'" <axis-dev@xml.apache.org>
    
                    .com>                cc:                                          
                    
                                         Subject:     Issue - hard to subclass BeanSerializer
             
                    12/19/2001                                                           
                 
                    03:37 PM                                                             
                 
                    Please respond                                                       
                 
                    to axis-dev                                                          
                 
                                                                                         
                 
                                                                                         
                 





I am trying to create a subclass of BeanSerializer.  I am working on a
UpperCaseBeanSerializer that will encode attributes to start with uppercase
instead of lowercase. ie.
<User><Name>foo</Name><Password>bar</Password></User>
instead of
<User><name>foo</name><password>bar</password></User>
 Note: I am doing the
client side soap app that hits a 3rd party soap service that I can not
touch.

<RJS>
Perhaps we can put this function into the current BeanSerializer via
an option.
</RJS>


In just trying to do a rename the class type operation to get it into my
package space I am seeing a couple of issues.

1)There is no easy way to get getDeserializer(Class cls) in a subclass
without a lot of copy/paste of the code.  My complete subclass is included.
Ideas on how to clean this up?

2)  The following code happens in two locations.
                    pd =
Introspector.getBeanInfo(cls).getPropertyDescriptors();
                    pd = sortPropertyDescriptors(pd, cls);
In doing my subclass, the first line is where I am going to have to change
the behavior for my subclass. I will modify the case of the properties that
the normal BeanInfo gives back.  One of these is expected in the getPd
method, but one is in the getDeserializer() method.   I would just replace
the call in getDeserializer() with getPd, but getPd has the side affect of
setting the enumSerializer.  Ideas on how to clean this up?

Couple of questions.

Why does BeanSerializer sneak in a EnumSerializer if it thinks it needs it?
Shouldn't the class just be registered with a EnumSerializer instead of a
BeanSerializer?

<RJS>
No way to set this up on the server side using the current deploy
mechanism.
</RJS>



I am having a hard time reading and understanding the getDeserializer code
and how the factory is working and what the local Hashtable cache is good
for.  It seems it might be missing a static on the hashtable?  Or is is an
instance of the factory going to have getDeserializer called on it that
many
times? A new factory instance is returned each time getFactory.


I don't have much time to wrap my head around this today, so if someone can
throw out pointers, that would be great!

Thanks.

Later

Mark


public class UpperCaseBeanSerializer extends BeanSerializer
    implements Serializer, Serializable
{
    static Category LOG =
            Category.getInstance(UpperCaseBeanSerializer.class.getName());

    /**
     * Default constructor.
     */
    public UpperCaseBeanSerializer() {
        super();
    }

    /**
     * Constructor that takes a class.  Provided only for convenience.
     * Equivalent to calling setCls(cls) on a new instance.
     */
    public UpperCaseBeanSerializer(Class cls) {
        super(cls);
    }

    public static DeserializerFactory getFactory()
    {
      return new UpperCaseBeanSerFactory();
    }

    /**
     * UpperCaseBeanSerializer Factory that creates instances with the
specified
     * class.  Caches the PropertyDescriptor
     */
    public static class UpperCaseBeanSerFactory implements
DeserializerFactory {
        private Hashtable propertyDescriptors = new Hashtable();

        public Deserializer getDeserializer(Class cls) {
            PropertyDescriptor [] pd =
                  (PropertyDescriptor [])propertyDescriptors.get(cls);
            if (pd == null) {
                try {
                    pd =
Introspector.getBeanInfo(cls).getPropertyDescriptors();
                    pd = sortPropertyDescriptors(pd, cls);
                } catch (IntrospectionException e) {
                    return null;
                }
                propertyDescriptors.put(cls, pd);
            }

            // If an enum class.  Return the Deserializer for Enumeration
            if (isEnumClass(cls)) {
                return EnumSerializer.getFactory().getDeserializer(cls);
            }

            UpperCaseBeanSerializer bs = new UpperCaseBeanSerializer();
            bs.setCls(cls);
            bs.setPd(pd);

            try {
                bs.setValue(cls.newInstance());
            } catch (Exception e) {
                // I'm not allowed to throw much, so I throw what I can!
                throw new NullPointerException(e.toString());
            }

            return bs;
        }

      }

}
I won't have time to look into this  of the




Mime
View raw message