vhardy 2003/07/04 08:57:36 Modified: test-sources/org/apache/batik/test/xml XMLReflect.java Log: Improved XML reflection Revision Changes Path 1.7 +36 -6 xml-batik/test-sources/org/apache/batik/test/xml/XMLReflect.java Index: XMLReflect.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XMLReflect.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XMLReflect.java 18 Mar 2003 13:25:54 -0000 1.6 +++ XMLReflect.java 4 Jul 2003 15:57:36 -0000 1.7 @@ -126,13 +126,43 @@ * Sets the property with given name on object to the input value */ public static void setObjectProperty(Object obj, - String propertyName, - Object propertyValue) + String propertyName, + Object propertyValue) throws Exception { Class cl = obj.getClass(); - Method m = cl.getMethod("set" + propertyName, - new Class[]{propertyValue.getClass()}); - + Method m = null; + try { + m = cl.getMethod("set" + propertyName, + new Class[]{propertyValue.getClass()}); + + } catch (NoSuchMethodException e) { + // + // Check if the type was one of the primitive types, Double, + // Float, Boolean or Integer + // + Class propertyClass = propertyValue.getClass(); + try { + if (propertyClass == java.lang.Double.class) { + m = cl.getMethod("set" + propertyName, + new Class[] {java.lang.Double.TYPE}); + } else if (propertyClass == java.lang.Float.class) { + m = cl.getMethod("set" + propertyName, + new Class[] {java.lang.Float.TYPE}); + } else if (propertyClass == java.lang.Integer.class) { + m = cl.getMethod("set" + propertyName, + new Class[] {java.lang.Integer.TYPE}); + } else if (propertyClass == java.lang.Boolean.class) { + m = cl.getMethod("set" + propertyName, + new Class[] {java.lang.Boolean.TYPE}); + } else { + System.err.println("Could not find a set method for property : " + propertyName + + " with value " + propertyValue + " and class " + propertyValue.getClass().getName()); + throw e; + } + } catch (NoSuchMethodException nsme) { + throw nsme; + } + } if(m != null){ m.invoke(obj, new Object[]{propertyValue}); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]