geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r220236 - in /geronimo/trunk/modules/kernel/src: java/org/apache/geronimo/gbean/ java/org/apache/geronimo/gbean/runtime/ java/org/apache/geronimo/kernel/basic/ java/org/apache/geronimo/kernel/jmx/ java/org/apache/geronimo/kernel/proxy/ test...
Date Fri, 22 Jul 2005 04:34:42 GMT
Author: ammulder
Date: Thu Jul 21 21:34:39 2005
New Revision: 220236

URL: http://svn.apache.org/viewcvs?rev=220236&view=rev
Log:
Start implementing new management API
 - GBeanInfo remembers interfaces passed to addInterface
 - ProxyManager can create a proxy for interfaces based on GBeanInfo
 - Tests of the above
JMXProxyManager now much much smaller (extends BasicProxyManager)

Added:
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java
  (with props)
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java
  (with props)
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java
  (with props)
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java
  (with props)
Modified:
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXProxyManager.java
    geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
    geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java (original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfo.java Thu Jul
21 21:34:39 2005
@@ -77,26 +77,27 @@
     private final Set operations;
     private final Set notifications;
     private final Set references;
+    private final Set interfaces;
 
-    public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo
constructor, Collection operations, Set references) {
-        this(className, className, j2eeType, attributes, constructor, operations, references,
DEFAULT_NOTIFICATIONS);
+    public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo
constructor, Collection operations, Set references, Set interfaces) {
+        this(className, className, j2eeType, attributes, constructor, operations, references,
interfaces, DEFAULT_NOTIFICATIONS);
     }
 
-    public GBeanInfo(String name, String className, String j2eeType, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references) {
-        this(name, className, j2eeType, attributes, constructor, operations, references,
DEFAULT_NOTIFICATIONS);
+    public GBeanInfo(String name, String className, String j2eeType, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references, Set interfaces) {
+        this(name, className, j2eeType, attributes, constructor, operations, references,
interfaces, DEFAULT_NOTIFICATIONS);
     }
 
     /**
      * @deprecated
      */
-    public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo
constructor, Collection operations, Set references, Set notifications) {
-        this(className, className, j2eeType, attributes, constructor, operations, references,
notifications);
+    public GBeanInfo(String className, String j2eeType, Collection attributes, GConstructorInfo
constructor, Collection operations, Set references, Set interfaces, Set notifications) {
+        this(className, className, j2eeType, attributes, constructor, operations, references,
interfaces, notifications);
     }
 
     /**
      * @deprecated
      */
-    public GBeanInfo(String name, String className, String j2eeType, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references, Set notifications) {
+    public GBeanInfo(String name, String className, String j2eeType, Collection attributes,
GConstructorInfo constructor, Collection operations, Set references, Set interfaces, Set notifications)
{
         this.name = name;
         this.className = className;
         this.j2eeType = j2eeType;
@@ -127,6 +128,11 @@
         } else {
             this.references = Collections.unmodifiableSet(new HashSet(references));
         }
+        if (interfaces == null) {
+            this.interfaces = Collections.EMPTY_SET;
+        } else {
+            this.interfaces = Collections.unmodifiableSet(new HashSet(interfaces));
+        }
         if (notifications == null) {
             this.notifications = Collections.EMPTY_SET;
         } else {
@@ -179,6 +185,10 @@
 
     public Set getReferences() {
         return references;
+    }
+
+    public Set getInterfaces() {
+        return interfaces;
     }
 
     public String toString() {

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/GBeanInfoBuilder.java
Thu Jul 21 21:34:39 2005
@@ -51,6 +51,8 @@
 
     private final Map references = new HashMap();
 
+    private final Set interfaces = new HashSet();
+
     public GBeanInfoBuilder(Class gbeanType) {
         this(checkNotNull(gbeanType).getName(), gbeanType, null, null);
     }
@@ -177,6 +179,9 @@
                 addOperation(new GOperationInfo(method.getName(), method.getParameterTypes()));
             }
         }
+        if(intf.isInterface()) {
+            interfaces.add(intf);
+        }
     }
 
     public void addAttribute(String name, Class type, boolean persistent) {
@@ -269,7 +274,7 @@
         }
 
 
-        return new GBeanInfo(name, gbeanType.getName(), j2eeType, attributes.values(), constructor,
operations.values(), referenceInfos);
+        return new GBeanInfo(name, gbeanType.getName(), j2eeType, attributes.values(), constructor,
operations.values(), referenceInfos, interfaces);
     }
 
     private Map getConstructorTypes() throws InvalidConfigurationException {

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/GBeanInstance.java
Thu Jul 21 21:34:39 2005
@@ -104,6 +104,11 @@
     private final GBeanLifecycleController gbeanLifecycleController;
 
     /**
+     * Interfaces for this GBean
+     */
+    private final Class[] interfaces;
+
+    /**
      * Attributes lookup table
      */
     private final GBeanAttribute[] attributes;
@@ -214,6 +219,9 @@
         //
         Set constructorArgs = new HashSet(gbeanInfo.getConstructor().getAttributeNames());
 
+        // interfaces
+        interfaces = (Class[]) gbeanInfo.getInterfaces().toArray(new Class[0]);
+
         // attributes
         Map attributesMap = new HashMap();
         for (Iterator iterator = gbeanInfo.getAttributes().iterator(); iterator.hasNext();)
{
@@ -1191,13 +1199,19 @@
             referenceInfos.add(references[i].getReferenceInfo());
         }
 
+        Set interfaceInfos = new HashSet();
+        for (int i = 0; i < interfaces.length; i++) {
+            interfaceInfos.add(interfaces[i]);
+        }
+
         return new GBeanInfo(name,
                 type.getName(),
                 j2eeType,
                 attributeInfos,
                 constructor,
                 operationInfos,
-                referenceInfos);
+                referenceInfos,
+                interfaceInfos);
     }
 
     public static final class GBeanInstanceLifecycleController implements GBeanLifecycleController
{

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
Thu Jul 21 21:34:39 2005
@@ -17,14 +17,19 @@
 package org.apache.geronimo.kernel.basic;
 
 import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
 import javax.management.ObjectName;
 
 import net.sf.cglib.proxy.Callback;
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.MethodInterceptor;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.proxy.ProxyFactory;
 import org.apache.geronimo.kernel.proxy.ProxyManager;
+import org.apache.geronimo.gbean.GBeanInfo;
 
 /**
  * @version $Rev$ $Date$
@@ -44,6 +49,11 @@
         return new ManagedProxyFactory(type);
     }
 
+    public synchronized ProxyFactory createProxyFactory(Class[] type) {
+        assert type != null: "type is null";
+        return new ManagedProxyFactory(type);
+    }
+
     public synchronized Object createProxy(ObjectName target, Class type) {
         assert type != null: "type is null";
         assert target != null: "target is null";
@@ -51,12 +61,57 @@
         return createProxyFactory(type).createProxy(target);
     }
 
+    public Object createProxy(ObjectName target) {
+        assert target != null: "target is null";
+        try {
+            GBeanInfo info = kernel.getGBeanInfo(target);
+            if(info.getInterfaces().size() == 0) {
+                return null;
+            }
+            Class[] intfs = (Class[]) info.getInterfaces().toArray(new Class[0]);
+            return createProxyFactory(intfs).createProxy(target);
+        } catch (GBeanNotFoundException e) {
+            throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target);
+        }
+    }
+
+    public Object createProxy(ObjectName target, Class required, Class[] optional) {
+        assert target != null: "target is null";
+        if(required == null && (optional == null || optional.length == 0)) {
+            throw new IllegalArgumentException("Cannot create proxy for no interfaces");
+        }
+        if(required != null && !required.isInterface()) {
+            throw new IllegalArgumentException("Cannot create a proxy for a class (only interfaces)
-- "+required.getName());
+        }
+        List list = new ArrayList();
+        if(required != null) {
+            list.add(required);
+        }
+        if (optional != null) {
+            try {
+                GBeanInfo info = kernel.getGBeanInfo(target);
+                Set set = info.getInterfaces();
+                for (int i = 0; i < optional.length; i++) {
+                    if (!optional[i].isInterface()) {
+                        throw new IllegalArgumentException("Cannot create a proxy for a class
(only interfaces) -- " + optional[i].getName());
+                    }
+                    if (set.contains(optional[i])) {
+                        list.add(optional[i]);
+                    }
+                }
+            } catch (GBeanNotFoundException e) {
+                throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target);
+            }
+        }
+        return createProxyFactory((Class[]) list.toArray(new Class[list.size()])).createProxy(target);
+    }
+
     public synchronized void destroyProxy(Object proxy) {
         if (proxy == null) {
             return;
         }
 
-        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.get(proxy);
+        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.remove(proxy);
         if (methodInterceptor != null) {
             methodInterceptor.destroy();
         }
@@ -67,7 +122,7 @@
     }
 
     public synchronized ObjectName getProxyTarget(Object proxy) {
-        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.remove(proxy);
+        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.get(proxy);
         if (methodInterceptor == null) {
             return null;
         }
@@ -75,28 +130,93 @@
     }
 
     private class ManagedProxyFactory implements ProxyFactory {
-        private final Class type;
+        private final Class proxyType;
         private final Enhancer enhancer;
 
         public ManagedProxyFactory(Class type) {
+            this(new Class[]{type});
+        }
+
+        public ManagedProxyFactory(Class[] type) {
             enhancer = new Enhancer();
-            enhancer.setSuperclass(type);
+            if(type.length > 1) { // shrink first -- may reduce from many to one
+                type = reduceInterfaces(type);
+            }
+            if(type.length == 0) {
+                throw new IllegalArgumentException("Cannot generate proxy for 0 interfaces!");
+            } else if(type.length == 1) {
+                enhancer.setSuperclass(type[0]);
+            } else {
+                enhancer.setSuperclass(Object.class);
+                enhancer.setInterfaces(type);
+            }
             enhancer.setCallbackType(MethodInterceptor.class);
             enhancer.setUseFactory(false);
-            this.type = enhancer.createClass();
+            proxyType = enhancer.createClass();
         }
 
         public synchronized Object createProxy(ObjectName target) {
             assert target != null: "target is null";
 
-            ProxyMethodInterceptor interceptor = new ProxyMethodInterceptor(type, kernel,
target);
+            Callback callback = getMethodInterceptor(proxyType, kernel, target);
 
             // @todo trap CodeGenerationException indicating missing no-arg ctr
-            enhancer.setCallbacks(new Callback[]{interceptor});
+            enhancer.setCallbacks(new Callback[]{callback});
             Object proxy = enhancer.create();
 
-            interceptors.put(proxy, interceptor);
+            interceptors.put(proxy, callback);
             return proxy;
         }
+
+        /**
+         * If there are multiple interfaces, and some of them extend each other,
+         * eliminate the superclass in favor of the subclasses that extend them.
+         * @param source the original list of interfaces
+         * @return the equal or smaller list of interfaces
+         */
+        private Class[] reduceInterfaces(Class[] source) {
+            boolean changed = false;
+            for (int i = 0; i < source.length-1; i++) {
+                Class original = source[i];
+                if(original == null) {
+                    continue;
+                }
+                if(!original.isInterface()) {
+                    throw new IllegalArgumentException(original.getName()+" is not an interface;
cannot generate proxy");
+                }
+                for (int j = i+1; j < source.length; j++) {
+                    Class other = source[j];
+                    if(other == null) {
+                        continue;
+                    }
+                    if(!other.isInterface()) {
+                        throw new IllegalArgumentException(other.getName()+" is not an interface;
cannot generate proxy");
+                    }
+                    if(other.isAssignableFrom(original)) {
+                        other = null;
+                        changed = true;
+                    } else if(original.isAssignableFrom(other)) {
+                        original = null;
+                        changed = true;
+                        break; // the original has been eliminated; move on to the next original
+                    }
+                }
+            }
+
+            if(!changed) {
+                return source;
+            }
+            List list = new ArrayList(source.length-1);
+            for (int i = 0; i < source.length; i++) {
+                if(source[i] != null) {
+                    list.add(source[i]);
+                }
+            }
+            return (Class[]) list.toArray(new Class[list.size()]);
+        }
+    }
+
+    protected Callback getMethodInterceptor(Class proxyType, Kernel kernel, ObjectName target)
{
+        return new ProxyMethodInterceptor(proxyType, kernel, target);
     }
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXProxyManager.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXProxyManager.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/jmx/JMXProxyManager.java
Thu Jul 21 21:34:39 2005
@@ -16,86 +16,23 @@
  */
 package org.apache.geronimo.kernel.jmx;
 
-import java.util.IdentityHashMap;
 import javax.management.ObjectName;
-
 import net.sf.cglib.proxy.Callback;
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.MethodInterceptor;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.basic.ProxyMethodInterceptor;
-import org.apache.geronimo.kernel.proxy.ProxyFactory;
-import org.apache.geronimo.kernel.proxy.ProxyManager;
+import org.apache.geronimo.kernel.basic.BasicProxyManager;
 
 /**
+ * Pretty much the same as the BasicProxyManager, but it has a different way
+ * of handling the actual invocations.
+ *
  * @version $Rev$ $Date$
  */
-public class JMXProxyManager implements ProxyManager {
-    private final Kernel kernel;
-    private final IdentityHashMap interceptors = new IdentityHashMap();
-
+public class JMXProxyManager extends BasicProxyManager {
     public JMXProxyManager(Kernel kernel) {
-        this.kernel = kernel;
-    }
-
-    public synchronized ProxyFactory createProxyFactory(Class type) {
-        assert type != null: "type is null";
-        return new ManagedProxyFactory(type);
-    }
-
-    public synchronized Object createProxy(ObjectName target, Class type) {
-        assert type != null: "type is null";
-        assert target != null: "target is null";
-
-        return createProxyFactory(type).createProxy(target);
-    }
-
-    public synchronized void destroyProxy(Object proxy) {
-        if (proxy == null) {
-            return;
-        }
-
-        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.remove(proxy);
-        if (methodInterceptor != null) {
-            methodInterceptor.destroy();
-        }
+        super(kernel);
     }
 
-    public boolean isProxy(Object proxy) {
-        return interceptors.containsKey(proxy);
-    }
-
-    public synchronized ObjectName getProxyTarget(Object proxy) {
-        ProxyMethodInterceptor methodInterceptor = (ProxyMethodInterceptor) interceptors.remove(proxy);
-        if (methodInterceptor == null) {
-            return null;
-        }
-        return methodInterceptor.getObjectName();
-    }
-
-    private class ManagedProxyFactory implements ProxyFactory {
-        private final Class type;
-        private final Enhancer enhancer;
-
-        public ManagedProxyFactory(Class type) {
-            enhancer = new Enhancer();
-            enhancer.setSuperclass(type);
-            enhancer.setCallbackType(MethodInterceptor.class);
-            enhancer.setUseFactory(false);
-            this.type = enhancer.createClass();
-        }
-
-        public synchronized Object createProxy(ObjectName target) {
-            assert target != null: "target is null";
-
-            JMXProxyMethodInterceptor interceptor = new JMXProxyMethodInterceptor(type, kernel,
target);
-
-            // @todo trap CodeGenerationException indicating missing no-arg ctr
-            enhancer.setCallbacks(new Callback[]{interceptor});
-            Object proxy = enhancer.create();
-
-            interceptors.put(proxy, interceptor);
-            return proxy;
-        }
+    protected Callback getMethodInterceptor(Class proxyType, Kernel kernel, ObjectName target)
{
+        return new JMXProxyMethodInterceptor(proxyType, kernel, target);
     }
 }

Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
(original)
+++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
Thu Jul 21 21:34:39 2005
@@ -31,12 +31,45 @@
     public ProxyFactory createProxyFactory(Class type);
 
     /**
-     * Create a proxy implementing the class to the specified target.
+     * Create a proxy for the specified target.  The proxy will implement
+     * all of the interfaces that the underlying GBean specifies in its
+     * GBeanInfo.  If there are no interfaces in the GBeanInfo, this method
+     * will return null.
+     *
+     * @param target the target object name
+     * @return the proxy, or null if the GBeanInfo declares no interfaces
+     */
+    public Object createProxy(ObjectName target);
+
+    /**
+     * Create a proxy for the specified target, implementing the specified
+     * interface.
+     *
      * @param target the target object name
      * @param type the type of the proxy to create
      * @return the proxy
      */
     public Object createProxy(ObjectName target, Class type);
+
+    /**
+     * Create a proxy for the specified target, implementing a variable
+     * number of interfaces.  It's possible to specify one interface that must
+     * be included, and also to specify a number of variable interfaces that
+     * the proxy should implement if the underlying GBean supports them. 
+     *
+     * @param target the target object name
+     * @param required an interface that the proxy must implement.  This may be
+     *                 null in which case only the optional interfaces will be
+     *                 evaluated.
+     * @param optional Interfaces that the proxy may implement.  For each
+     *                 of these interfaces, the proxy must implement it if the
+     *                 underlying GBean declares that it implements it (by
+     *                 declaring the interface in its GBeanInfo), and otherwise
+     *                 the interface will be ignored.
+     * @return the proxy, or null if no required interfaces was specified and
+     *         none of the optional interfaces match the GBeanInfo
+     */
+    public Object createProxy(ObjectName target, Class required, Class[] optional);
 
     /**
      * Cleans up and resources associated with the proxy

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java (original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java Thu Jul
21 21:34:39 2005
@@ -27,6 +27,7 @@
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanLifecycleController;
 import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.proxy.ProxyManager;
 
 /**
  * @version $Rev$ $Date$
@@ -81,6 +82,111 @@
         kernel.startGBean(name2);
 
         assertEquals("endpointCheck", kernel.invoke(name2, "checkEndpoint", null, null));
+    }
+
+    public void testProxiesInterfaces() throws Exception {
+        ClassLoader cl = getClass().getClassLoader();
+        ClassLoader myCl = new URLClassLoader(new URL[0], cl);
+        GBeanData gbean = new GBeanData(name, MockGBean.getGBeanInfo());
+        gbean.setAttribute("name", "Test");
+        gbean.setAttribute("finalInt", new Integer(123));
+        kernel.loadGBean(gbean, myCl);
+        kernel.startGBean(name);
+        ProxyManager mgr = kernel.getProxyManager();
+
+        Object test = mgr.createProxy(name);
+        assertTrue(test instanceof MockEndpoint);
+        assertTrue(test instanceof MockParentInterface1);
+        assertTrue(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertTrue(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+        ((MockEndpoint)test).doNothing();
+        assertEquals("Foo", ((MockEndpoint)test).echo("Foo"));
+        ((MockParentInterface1)test).setValue("Foo");
+        assertEquals("Foo", ((MockParentInterface1)test).getValue());
+        ((MockParentInterface1)test).setMutableInt(6);
+        assertEquals(6, ((MockParentInterface1)test).getMutableInt());
+        ((MockParentInterface2)test).doNothing();
+        assertEquals("Foo", ((MockParentInterface2)test).echo("Foo"));
+        ((MockParentInterface2)test).setValue("Foo");
+        assertEquals("Foo", ((MockParentInterface2)test).getValue());
+        ((MockChildInterface1)test).getFinalInt();
+        ((MockChildInterface2)test).doNothing();
+        assertEquals("Foo", ((MockChildInterface2)test).doSomething("Foo"));
+
+        test = mgr.createProxy(name, MockEndpoint.class);
+        assertTrue(test instanceof MockEndpoint);
+        assertFalse(test instanceof MockParentInterface1);
+        assertFalse(test instanceof MockParentInterface2);
+        assertFalse(test instanceof MockChildInterface1);
+        assertFalse(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        test = mgr.createProxy(name, MockEndpoint.class, new Class[]{MockParentInterface2.class,
MockChildInterface2.class});
+        assertTrue(test instanceof MockEndpoint);
+        assertTrue(test instanceof MockParentInterface1);
+        assertTrue(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertTrue(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        test = mgr.createProxy(name, MockEndpoint.class, new Class[]{MockParentInterface1.class,
MockChildInterface1.class});
+        assertTrue(test instanceof MockEndpoint);
+        assertTrue(test instanceof MockParentInterface1);
+        assertFalse(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertFalse(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        test = mgr.createProxy(name, MockEndpoint.class, new Class[]{MockParentInterface1.class,
MockChildInterface1.class, Comparable.class});
+        assertTrue(test instanceof MockEndpoint);
+        assertTrue(test instanceof MockParentInterface1);
+        assertFalse(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertFalse(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        test = mgr.createProxy(name, null, new Class[]{MockParentInterface1.class, MockChildInterface1.class,
Comparable.class});
+        assertFalse(test instanceof MockEndpoint);
+        assertTrue(test instanceof MockParentInterface1);
+        assertFalse(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertFalse(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        test = mgr.createProxy(name, MockEndpoint.class, new Class[]{Comparable.class});
+        assertTrue(test instanceof MockEndpoint);
+        assertFalse(test instanceof MockParentInterface1);
+        assertFalse(test instanceof MockParentInterface2);
+        assertFalse(test instanceof MockChildInterface1);
+        assertFalse(test instanceof MockChildInterface2);
+        assertFalse(test instanceof Comparable);
+
+        try {
+            test = mgr.createProxy(name, null, new Class[]{Comparable.class}); // no implementable
interface
+            fail();
+        }catch(IllegalArgumentException e) {}
+
+        try {
+            test = mgr.createProxy(name, null, new Class[0]); // no interface
+            fail();
+        }catch(IllegalArgumentException e) {}
+
+        try {
+            test = mgr.createProxy(name, null, null); // no interface
+            fail();
+        }catch(IllegalArgumentException e) {}
+
+        try {
+            test = mgr.createProxy(name, Class.class, null); // class not interface
+            fail();
+        }catch(IllegalArgumentException e) {}
+
+        try {
+            test = mgr.createProxy(name, null, new Class[]{Class.class}); // class not interface
+            fail();
+        }catch(IllegalArgumentException e) {}
     }
 
     protected void setUp() throws Exception {

Added: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java?rev=220236&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java
(added)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java
Thu Jul 21 21:34:39 2005
@@ -0,0 +1,12 @@
+package org.apache.geronimo.kernel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ammulder
+ * Date: Jul 21, 2005
+ * Time: 11:54:44 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface MockChildInterface1 extends MockParentInterface1 {
+    public int getFinalInt();
+}

Propchange: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java?rev=220236&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java
(added)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java
Thu Jul 21 21:34:39 2005
@@ -0,0 +1,14 @@
+package org.apache.geronimo.kernel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ammulder
+ * Date: Jul 21, 2005
+ * Time: 11:55:16 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface MockChildInterface2 extends MockChildInterface1 {
+    public String doSomething(String name);
+
+    public void doNothing();
+}

Propchange: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockChildInterface2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java?rev=220236&r1=220235&r2=220236&view=diff
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java (original)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockGBean.java Thu Jul
21 21:34:39 2005
@@ -29,7 +29,7 @@
 /**
  * @version $Rev$ $Date$
  */
-public class MockGBean implements MockEndpoint {
+public class MockGBean implements MockEndpoint, MockParentInterface1, MockParentInterface2,
MockChildInterface1, MockChildInterface2 {
 
     private static final GBeanInfo GBEAN_INFO;
 
@@ -80,6 +80,10 @@
         infoFactory.addOperation("doSomething", new Class[]{String.class});
 
         infoFactory.addInterface(MockEndpoint.class, new String[]{"mutableInt"});
+        infoFactory.addInterface(MockParentInterface1.class, new String[]{"value"});
+        infoFactory.addInterface(MockParentInterface2.class, new String[]{"value"});
+        infoFactory.addInterface(MockChildInterface1.class, new String[]{"finalInt"});
+        infoFactory.addInterface(MockChildInterface2.class, new String[]{});
 
         infoFactory.addReference("MockEndpoint", MockEndpoint.class, null);
         infoFactory.addReference("EndpointCollection", MockEndpoint.class, null);

Added: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java?rev=220236&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java
(added)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java
Thu Jul 21 21:34:39 2005
@@ -0,0 +1,18 @@
+package org.apache.geronimo.kernel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ammulder
+ * Date: Jul 21, 2005
+ * Time: 11:54:09 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface MockParentInterface1 {
+    public String getValue();
+
+    public void setValue(String value);
+
+    public int getMutableInt();
+
+    public void setMutableInt(int mutableInt);
+}

Propchange: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface1.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java?rev=220236&view=auto
==============================================================================
--- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java
(added)
+++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java
Thu Jul 21 21:34:39 2005
@@ -0,0 +1,19 @@
+package org.apache.geronimo.kernel;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: ammulder
+ * Date: Jul 21, 2005
+ * Time: 11:54:22 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public interface MockParentInterface2 {
+    public String getValue();
+
+    public void setValue(String value);
+
+    public void doNothing();
+
+    public String echo(String msg);
+
+}

Propchange: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/MockParentInterface2.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message