You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gd...@apache.org on 2004/07/27 04:13:21 UTC
cvs commit: incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean DynamicGBeanDelegate.java
gdamour 2004/07/26 19:13:21
Modified: modules/kernel/src/java/org/apache/geronimo/gbean
DynamicGBeanDelegate.java
Log:
Apply patch GERONIMO-270 submitted by Toby Cabot.
DynamicGBeanDelegate implements the same attribute naming conventions than Raw and JMX GBeanInvokers.
Revision Changes Path
1.8 +21 -10 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/DynamicGBeanDelegate.java
Index: DynamicGBeanDelegate.java
===================================================================
RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/DynamicGBeanDelegate.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DynamicGBeanDelegate.java 27 May 2004 01:05:58 -0000 1.7
+++ DynamicGBeanDelegate.java 27 Jul 2004 02:13:21 -0000 1.8
@@ -17,6 +17,7 @@
package org.apache.geronimo.gbean;
+import java.beans.Introspector;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
@@ -27,15 +28,18 @@
/**
+ * Wraps an <code>Object</code> in a <code>DynamicGBean</code> facade.
+ *
* @version $Revision$ $Date$
*/
public class DynamicGBeanDelegate implements DynamicGBean {
protected final Map getters = new HashMap();
protected final Map setters = new HashMap();
protected final Map operations = new HashMap();
+ private Class targetClass;
public void addAll(Object target) {
- Class targetClass = target.getClass();
+ this.targetClass = target.getClass();
Method[] methods = targetClass.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
@@ -52,11 +56,11 @@
public void addGetter(Object target, Method method) {
String name = method.getName();
if (name.startsWith("get")) {
- addGetter(method.getName().substring(3), target, method);
+ addGetter(name.substring(3), target, method);
} else if (name.startsWith("is")) {
- addGetter(method.getName().substring(2), target, method);
+ addGetter(name.substring(2), target, method);
} else {
- throw new IllegalArgumentException("Method method name must start with 'get' or 'is' " + method);
+ throw new IllegalArgumentException("Method name must start with 'get' or 'is' " + method);
}
}
@@ -65,11 +69,14 @@
throw new IllegalArgumentException("Method must take no parameters and return a value " + method);
}
getters.put(name, new Operation(target, method));
+ // we want to be user-friendly so we put the attribute name in
+ // the Map in both lower-case and upper-case
+ getters.put(Introspector.decapitalize(name), new Operation(target, method));
}
public void addSetter(Object target, Method method) {
if (!method.getName().startsWith("set")) {
- throw new IllegalArgumentException("Method method name must start with 'set' " + method);
+ throw new IllegalArgumentException("Method name must start with 'set' " + method);
}
addSetter(method.getName().substring(3), target, method);
}
@@ -79,6 +86,9 @@
throw new IllegalArgumentException("Method must take one parameter and not return anything " + method);
}
setters.put(name, new Operation(target, method));
+ // we want to be user-friendly so we put the attribute name in
+ // the Map in both lower-case and upper-case
+ setters.put(Introspector.decapitalize(name), new Operation(target, method));
}
public void addOperation(Object target, Method method) {
@@ -107,7 +117,7 @@
public Object getAttribute(String name) throws Exception {
Operation operation = (Operation) getters.get(name);
if (operation == null) {
- throw new IllegalArgumentException("Unknown attribute " + name);
+ throw new IllegalArgumentException(targetClass.getName() + ": no getter for " + name);
}
return operation.invoke(null);
}
@@ -115,15 +125,16 @@
public void setAttribute(String name, Object value) throws Exception {
Operation operation = (Operation) setters.get(name);
if (operation == null) {
- throw new IllegalArgumentException("Unknown attribute " + name);
+ throw new IllegalArgumentException(targetClass.getName() + ": no setter for " + name);
}
operation.invoke(new Object[]{value});
}
public Object invoke(String name, Object[] arguments, String[] types) throws Exception {
- Operation operation = (Operation) operations.get(new GOperationSignature(name, types));
+ GOperationSignature signature = new GOperationSignature(name, types);
+ Operation operation = (Operation) operations.get(signature);
if (operation == null) {
- throw new IllegalArgumentException("Unknown attribute " + name);
+ throw new IllegalArgumentException(targetClass.getName() + ": no operation " + signature);
}
return operation.invoke(arguments);
}