dain 2004/01/17 17:22:42
Modified: modules/kernel/src/java/org/apache/geronimo/gbean
GOperationInfo.java
modules/kernel/src/java/org/apache/geronimo/gbean/jmx
GBeanMBeanOperation.java
Added: modules/kernel/src/java/org/apache/geronimo/gbean
DynamicGOperationInfo.java
Log:
Added dynamic operations.
Revision Changes Path
1.4 +2 -2
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GOperationInfo.java
Index: GOperationInfo.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/GOperationInfo.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GOperationInfo.java 16 Jan 2004 23:31:21 -0000 1.3
+++ GOperationInfo.java 18 Jan 2004 01:22:42 -0000 1.4
@@ -66,7 +66,7 @@
*
* @version $Revision$ $Date$
*/
-public final class GOperationInfo implements Serializable {
+public class GOperationInfo implements Serializable {
/**
* The name of this method.
*/
1.1
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/DynamicGOperationInfo.java
Index: DynamicGOperationInfo.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.gbean;
import java.util.List;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/18 01:22:42 $
*/
public class DynamicGOperationInfo extends GOperationInfo {
public DynamicGOperationInfo(String name) {
super(name);
}
public DynamicGOperationInfo(String name, String[] paramTypes) {
super(name, paramTypes);
}
public DynamicGOperationInfo(String name, List parameters) {
super(name, parameters);
}
}
1.4 +31 -17
incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java
Index: GBeanMBeanOperation.java
===================================================================
RCS file:
/home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/gbean/jmx/GBeanMBeanOperation.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- GBeanMBeanOperation.java 17 Jan 2004 00:32:10 -0000 1.3
+++ GBeanMBeanOperation.java 18 Jan 2004 01:22:42 -0000 1.4
@@ -70,6 +70,8 @@
import org.apache.geronimo.gbean.GOperationInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
+import org.apache.geronimo.gbean.DynamicGOperationInfo;
+import org.apache.geronimo.gbean.DynamicGBean;
/**
*
@@ -77,14 +79,14 @@
* @version $Revision$ $Date$
*/
public class GBeanMBeanOperation {
- private final GBeanMBean gMBean;
+ private final GBeanMBean gmbean;
private final String name;
private final List parameterTypes;
private final MBeanOperationInfo mbeanOperationInfo;
private final MethodInvoker methodInvoker;
public GBeanMBeanOperation(GBeanMBean gMBean, String name, List
parameterTypes, Class returnType, MethodInvoker methodInvoker) {
- this.gMBean = gMBean;
+ this.gmbean = gMBean;
this.name = name;
this.parameterTypes = Collections.unmodifiableList(new
ArrayList(parameterTypes));
this.methodInvoker = methodInvoker;
@@ -108,7 +110,7 @@
}
public GBeanMBeanOperation(GBeanMBean gMBean, GOperationInfo
operationInfo) throws InvalidConfigurationException {
- this.gMBean = gMBean;
+ this.gmbean = gMBean;
this.name = operationInfo.getName();
// get an array of the parameter classes
@@ -118,7 +120,7 @@
for (int i = 0; i < types.length; i++) {
String type = (String) parameterTypes.get(i);
try {
- types[i] = loadClass((String)parameterTypes.get(i),
classLoader);
+ types[i] = loadClass((String) parameterTypes.get(i),
classLoader);
} catch (ClassNotFoundException e) {
throw new InvalidConfigurationException("Could not load
operation parameter class:" +
" name=" + operationInfo.getName() +
@@ -128,15 +130,27 @@
// get a method invoker for the operation
Class returnType;
- try {
- Method javaMethod =
gMBean.getType().getMethod(operationInfo.getMethodName(), types);
- returnType = javaMethod.getReturnType();
- methodInvoker = new FastMethodInvoker(javaMethod);
- } catch (Exception e) {
- throw new InvalidConfigurationException("Target does not have
specified method:" +
- " name=" + operationInfo.getName() +
- " methodName=" + operationInfo.getMethodName() +
- " targetClass=" + gMBean.getType().getName());
+ if (operationInfo instanceof DynamicGOperationInfo) {
+ returnType = Object.class;
+ methodInvoker = new MethodInvoker() {
+ private String[] types = (String[])
parameterTypes.toArray(new String[parameterTypes.size()]);
+ public Object invoke(Object target, Object[] arguments)
throws Exception {
+ DynamicGBean dynamicGBean = (DynamicGBean)
GBeanMBeanOperation.this.gmbean.getTarget();
+ dynamicGBean.invoke(name, arguments, types);
+ return null;
+ }
+ };
+ } else {
+ try {
+ Method javaMethod =
gMBean.getType().getMethod(operationInfo.getMethodName(), types);
+ returnType = javaMethod.getReturnType();
+ methodInvoker = new FastMethodInvoker(javaMethod);
+ } catch (Exception e) {
+ throw new InvalidConfigurationException("Target does not
have specified method:" +
+ " name=" + operationInfo.getName() +
+ " methodName=" + operationInfo.getMethodName() +
+ " targetClass=" + gMBean.getType().getName());
+ }
}
MBeanParameterInfo[] signature = new
MBeanParameterInfo[parameterTypes.size()];
@@ -169,14 +183,14 @@
}
public Object invoke(Object[] arguments) throws MBeanException,
ReflectionException {
- if (gMBean.isOffline()) {
+ if (gmbean.isOffline()) {
throw new IllegalStateException("Operations can not be called
while offline");
}
ClassLoader oldClassLoader =
Thread.currentThread().getContextClassLoader();
try {
-
Thread.currentThread().setContextClassLoader(gMBean.getClassLoader());
- return methodInvoker.invoke(gMBean.getTarget(), arguments);
+
Thread.currentThread().setContextClassLoader(gmbean.getClassLoader());
+ return methodInvoker.invoke(gmbean.getTarget(), arguments);
} catch (Throwable throwable) {
throw new ReflectionException(new
InvocationTargetException(throwable));
} finally {