Update of /var/cvs/src/org/mmbase/util/xml
In directory james.mmbase.org:/tmp/cvs-serv8185
Modified Files:
Instantiator.java
Log Message:
added support for setting properties by a 'setProperty' member too
See also: http://cvs.mmbase.org/viewcvs/src/org/mmbase/util/xml
Index: Instantiator.java
===================================================================
RCS file: /var/cvs/src/org/mmbase/util/xml/Instantiator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Instantiator.java 2 Aug 2008 15:15:00 -0000 1.5
+++ Instantiator.java 12 Jan 2009 21:12:47 -0000 1.6
@@ -40,7 +40,7 @@
*
* @since MMBase-1.9
* @author Michiel Meeuwissen
- * @version $Id: Instantiator.java,v 1.5 2008/08/02 15:15:00 michiel Exp $
+ * @version $Id: Instantiator.java,v 1.6 2009/01/12 21:12:47 michiel Exp $
*/
public abstract class Instantiator {
@@ -108,9 +108,10 @@
*
* @param value The value as a <code>String</code>
*/
- public static void setProperty(String name, Class claz, Object o, String
value) {
+ public static void setProperty(final String name, final Class claz, final
Object o, final String value) {
String methodName = "set" + name.substring(0, 1).toUpperCase() +
name.substring(1);
boolean invoked = false;
+ Method setProperty = null;
for (Method m : claz.getMethods()) {
try {
if (m.getName().equals(methodName) &&
m.getParameterTypes().length == 1) {
@@ -120,12 +121,28 @@
m.invoke(o, Casting.toType(m.getParameterTypes()[0],
value));
invoked = true;
}
+ if (m.getName().equals("setProperty") &&
m.getParameterTypes().length == 2 &&
String.class.isAssignableFrom(m.getParameterTypes()[0])) {
+ setProperty = m;
+ }
+ } catch (IllegalAccessException ie) {
+ log.warn(ie);
+ } catch (InvocationTargetException ite) {
+ log.warn(ite);
+ }
+ }
+ if (! invoked && setProperty != null) {
+ try {
+ invoked = true;
+ setProperty.invoke(o, name,
Casting.toType(setProperty.getParameterTypes()[1], value));
} catch (IllegalAccessException ie) {
log.warn(ie);
} catch (InvocationTargetException ite) {
log.warn(ite);
}
}
+ if (! invoked) {
+ log.warn("Could not set property '" + name + "' on " + o);
+ }
}
/**
@@ -134,7 +151,8 @@
* @param element Element in which a child specifying a java object must
be searched.
* @return a new object, or <code>null</code> if no matching child found.
*/
- public static Object getInstanceWithSubElement(Element element, Object...
args) throws org.xml.sax.SAXException, ClassNotFoundException,
NoSuchMethodException, InstantiationException, IllegalAccessException,
java.lang.reflect.InvocationTargetException {
+ public static Object getInstanceWithSubElement(Element element, Object...
args)
+ throws org.xml.sax.SAXException, ClassNotFoundException,
NoSuchMethodException, InstantiationException, IllegalAccessException,
InvocationTargetException {
NodeList childs = element.getChildNodes();
Object instance = null;
for (int i = 0; i < childs.getLength(); i++) {
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs