Patches item #492261, was opened at 2001-12-12 15:49 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=376687&aid=492261&group_id=22866
Category: JBossServer Group: v2.4 BETA (stable) Status: Open Resolution: None Priority: 5 Submitted By: Larry Sanderson (lsanders) Assigned to: Nobody/Anonymous (nobody) Summary: XADataSourceLoader properties attribute Initial Comment: The Properties attribute of org.jboss.jdbc.XADataSourceLoader MBean only supports a "setProperties(java.util.Properties)" method of a wrapped XADataSource. This is incompatible with Informix's XADataSource - that class only supports beans style setters. I modified the code so that if a NoSuchMethodException is thrown on the setProperties method, then it attempts the JavaBean style setters. This is a related patch that has some more info: http://sourceforge.net/tracker/index.php? func=detail&aid=491399&group_id=22866&atid=376687 ======================================================= ============ RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jdbc/Atti c/XADataSourceLoader.java,v retrieving revision 1.16.4.3 diff -u -r1.16.4.3 XADataSourceLoader.java --- XADataSourceLoader.java 2001/11/20 09:42:53 1.16.4.3 +++ XADataSourceLoader.java 2001/12/12 23:38:04 @@ -9,6 +9,8 @@ import java.io.PrintWriter; import java.lang.reflect.Method; import java.sql.SQLException; +import java.util.Map; +import java.util.HashMap; import java.util.Iterator; import java.util.Properties; import java.util.StringTokenizer; @@ -360,8 +362,16 @@ if(properties != null && properties.length() > 0) { Properties props = parseProperties (properties); - Method setProperties = cls.getMethod ("setProperties", new Class[] { Properties.class }); - setProperties.invoke(vendorSource, new Object [] { props }); + try + { + Method setProperties = cls.getMethod ("setProperties", new Class[] { Properties.class }); + setProperties.invoke(vendorSource, new Object[] { props }); + } + catch (NoSuchMethodException e) + { + // no "setProperties(..) method... try individual sets + populate(vendorSource, props); + } } if(userName != null && userName.length() > 0) @@ -480,6 +490,121 @@ props.put(key, value); } return props; + } + + /** + * Populate the vendorSource with the properties in the Map. No exceptions + * are thrown if a property is specified for which there is no setter, + * however a warning is issued. + * + * @param props the properties to use. + */ + private void populate(Object vendorSource, Map props) + { + // get all valid set methods - + Method[] methods = vendorSource.getClass ().getMethods(); + HashMap setters = new HashMap(); + + for (int i = 0; i < methods.length; i++) + { + Method meth = methods[i]; + String name = meth.getName(); + if (name.startsWith("set")) + { + String attrName = name.substring(3); + if (meth.getParameterTypes().length == 1) + { + setters.put(attrName, meth); + } + } + } + } + + for (Iterator i = props.entrySet().iterator(); i.hasNext();) + { + Map.Entry entry = (Map.Entry) i.next(); + String attributeName = (String) entry.getKey (); + String attributeValue = (String) entry.getValue(); + + Method meth = (Method)setters.get (attributeName); + if (meth != null) + { + try + { + Object val = convert(attributeValue, meth.getParameterTypes()[0]); + meth.invoke(vendorSource, new Object[] { val }); + } + catch (Exception e) + { + log.warn("Error setter attribute '" + attributeName + + "' - skipping", e); + } + } + else + { + log.warn("No setter method for attribute '" + attributeName + + "' - skipping"); + } + } + } + + /** + * Convert the specified value to the specified class. This should be + * replaced with the org.apache.commons.beanUtils.ConvertUtils class. + * + * @return the value converted to type + * @param value the String value to convert + * @type the class to convert to. Must be a primitive type or String. + */ + private Object convert(String value, Class type) + { + if (type == String.class) + { + return value; + } + if (type == Integer.TYPE) + { + return Integer.valueOf(value); + } + if (type == Double.TYPE) + { + return Double.valueOf(value); + } + if (type == Boolean.TYPE) { + return new Boolean( + value.equalsIgnoreCase("true") || + value.equalsIgnoreCase("on") || + value.equalsIgnoreCase("yes") + ); + } + if (type == Long.TYPE) + { + return Long.valueOf(value); + } + if (type == Float.TYPE) + { + return Float.valueOf(value); + } + if (type == Byte.TYPE) + { + return Byte.valueOf(value); + } + if (type == Short.TYPE) + { + return Short.valueOf(value); + } + if (type == Character.TYPE) + { + return new Character(value.charAt(0)); + } + if (type == Double.TYPE) + { + return Double.valueOf(value); + } + return null; } } ---------------------------------------------------------------------- You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=376687&aid=492261&group_id=22866 _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
