gdaniels 02/03/08 06:12:13 Modified: java/src/org/apache/axis/description TypeDesc.java java/src/org/apache/axis/encoding/ser BeanDeserializer.java BeanSerializer.java SimpleDeserializer.java SimpleSerializer.java Log: Add static accessor to centralize access to type metadata for a class. For now this is limited to using the static getTypeDesc() method if it is found, but will allow us to add file-based metadata descriptors later. Revision Changes Path 1.3 +28 -0 xml-axis/java/src/org/apache/axis/description/TypeDesc.java Index: TypeDesc.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/description/TypeDesc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TypeDesc.java 8 Mar 2002 05:11:24 -0000 1.2 +++ TypeDesc.java 8 Mar 2002 14:12:13 -0000 1.3 @@ -55,9 +55,12 @@ package org.apache.axis.description; +import org.apache.axis.encoding.ser.BeanSerializer; + import javax.xml.rpc.namespace.QName; import java.util.HashMap; import java.lang.reflect.Array; +import java.lang.reflect.Method; /** * A TypeDesc represents a Java<->XML data binding. It is essentially @@ -67,6 +70,31 @@ * @author Glen Daniels ([EMAIL PROTECTED]) */ public class TypeDesc { + public static Class [] noClasses = new Class [] {}; + + /** + * Static function for centralizing access to type metadata for a + * given class. + * + * Right now this just checks for a static getTypeDesc() method on the + * class, but we will eventually extend this to provide for external + * metadata config (via files sitting in the classpath, etc). + * + * (Could introduce a cache here for speed as an optimization) + */ + public static TypeDesc getTypeDescForClass(Class cls) + { + try { + Method getTypeDesc = + cls.getMethod("getTypeDesc", noClasses); + if (getTypeDesc != null) + return (TypeDesc)getTypeDesc.invoke(null, + BeanSerializer.noArgs); + } catch (Exception e) { + } + return null; + } + private FieldDesc [] fields; /** A cache of FieldDescs by name */ 1.9 +3 -12 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- BeanDeserializer.java 8 Mar 2002 05:04:54 -0000 1.8 +++ BeanDeserializer.java 8 Mar 2002 14:12:13 -0000 1.9 @@ -121,18 +121,9 @@ BeanPropertyDescriptor descriptor = pd[i]; propertyMap.put(descriptor.getName(), descriptor); } - - // Get the class' TypeDesc if it provides one - try { - Method getTypeDesc = - javaType.getMethod("getTypeDesc", - new Class [] {}); - // get string array - typeDesc = (TypeDesc)getTypeDesc.invoke(null, - BeanSerializer.noArgs); - } catch (Exception e) { - } - + + typeDesc = TypeDesc.getTypeDescForClass(javaType); + // create a value try { value=javaType.newInstance(); 1.15 +1 -9 xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java Index: BeanSerializer.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/BeanSerializer.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- BeanSerializer.java 8 Mar 2002 05:04:54 -0000 1.14 +++ BeanSerializer.java 8 Mar 2002 14:12:13 -0000 1.15 @@ -137,15 +137,7 @@ this.javaType = javaType; propertyDescriptor = getPd(javaType); - // Get the class' TypeDesc if it provides one - try { - Method getTypeDesc = - javaType.getMethod("getTypeDesc", - new Class [] {}); - // get string array - typeDesc = (TypeDesc)getTypeDesc.invoke(null, noArgs); - } catch (Exception e) { - } + typeDesc = TypeDesc.getTypeDescForClass(javaType); } // Construct BeanSerializer for the indicated class/qname and format 1.6 +1 -10 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SimpleDeserializer.java 8 Mar 2002 05:04:54 -0000 1.5 +++ SimpleDeserializer.java 8 Mar 2002 14:12:13 -0000 1.6 @@ -124,16 +124,7 @@ propertyMap.put(descriptor.getName(), descriptor); } - // Get the class' TypeDesc if it provides one - try { - Method getTypeDesc = - javaType.getMethod("getTypeDesc", - new Class [] {}); - // get string array - typeDesc = (TypeDesc)getTypeDesc.invoke(null, - BeanSerializer.noArgs); - } catch (Exception e) { - } + typeDesc = TypeDesc.getTypeDescForClass(javaType); } } 1.6 +1 -10 xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java Index: SimpleSerializer.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/ser/SimpleSerializer.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SimpleSerializer.java 8 Mar 2002 05:04:54 -0000 1.5 +++ SimpleSerializer.java 8 Mar 2002 14:12:13 -0000 1.6 @@ -105,16 +105,7 @@ if (SimpleType.class.isAssignableFrom(javaType)) { // get the bean properties and the list of attributes from the bean propertyDescriptor = BeanSerializer.getPd(javaType); - // Get the class' TypeDesc if it provides one - try { - Method getTypeDesc = - javaType.getMethod("getTypeDesc", - new Class [] {}); - // get string array - typeDesc = (TypeDesc)getTypeDesc.invoke(null, - BeanSerializer.noArgs); - } catch (Exception e) { - } + typeDesc = TypeDesc.getTypeDescForClass(javaType); } } /**