geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r396405 - in /geronimo/branches/1.1: applications/console-standard/src/java/org/apache/geronimo/console/car/ modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ modules/kernel/src/java/org/apache/geronimo/kernel/basic/ modules/kernel...
Date Mon, 24 Apr 2006 03:53:28 GMT
Author: dain
Date: Sun Apr 23 20:53:26 2006
New Revision: 396405

URL: http://svn.apache.org/viewcvs?rev=396405&view=rev
Log:
When creating a proxy add all visible interfaces that were declared in the GBean.
Removed all old unused ObjectName methods from the ProxyManager.
Fixed code in GeronimoAsMavenServlet that queried using an AbstractNameQuery but then tried
to cast the results to an ObjectName.

Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyFactory.java
    geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
    geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
Sun Apr 23 20:53:26 2006
@@ -26,7 +26,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-import javax.management.ObjectName;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
@@ -34,32 +33,30 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.geronimo.console.util.KernelManagementHelper;
-import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.config.ConfigurationData;
 import org.apache.geronimo.kernel.config.ConfigurationInfo;
 import org.apache.geronimo.kernel.config.ConfigurationManager;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
-import org.apache.geronimo.kernel.config.ConfigurationData;
-import org.apache.geronimo.kernel.config.NoSuchConfigException;
-import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.repository.Dependency;
+import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.repository.Version;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.w3c.dom.Document;
@@ -175,7 +172,7 @@
         // Step 2: check if it's in a repository
         Set repos = kernel.listGBeans(new AbstractNameQuery(Repository.class.getName()));
         for (Iterator it = repos.iterator(); it.hasNext();) {
-            ObjectName name = (ObjectName) it.next();
+            AbstractName name = (AbstractName) it.next();
             Repository repo = (Repository) kernel.getProxyManager().createProxy(name, Repository.class);
             if(repo.contains(configId)) {
                 File path = repo.getLocation(configId);

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/gbean/runtime/ProxyCollection.java
Sun Apr 23 20:53:26 2006
@@ -22,7 +22,6 @@
 import org.apache.geronimo.gbean.ReferenceCollection;
 import org.apache.geronimo.gbean.ReferenceCollectionEvent;
 import org.apache.geronimo.gbean.ReferenceCollectionListener;
-import org.apache.geronimo.kernel.proxy.ProxyFactory;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 
@@ -43,19 +42,15 @@
     private static final Log log = LogFactory.getLog(ProxyCollection.class);
     private final String name;
     private final Kernel kernel;
-    private final ProxyFactory factory;
     private final Map proxies = new HashMap();
     private final Set listeners = new HashSet();
     private boolean stopped = false;
+    private final Class type;
 
     public ProxyCollection(String name, Class type, Set targets, Kernel kernel) {
         this.name = name;
         this.kernel = kernel;
-        if (AbstractGBeanReference.NO_PROXY) {
-            factory = null;
-        } else {
-            factory = kernel.getProxyManager().createProxyFactory(type);
-        }
+        this.type = type;
 
         for (Iterator iterator = targets.iterator(); iterator.hasNext();) {
             addTarget((AbstractName) iterator.next());
@@ -92,7 +87,7 @@
                     return;
                 }
             } else {
-                proxy = factory.createProxy(target);
+                proxy = kernel.getProxyManager().createProxy(target, type);
             }
             proxies.put(target, proxy);
 

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/basic/BasicProxyManager.java
Sun Apr 23 20:53:26 2006
@@ -16,32 +16,27 @@
  */
 package org.apache.geronimo.kernel.basic;
 
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import net.sf.cglib.proxy.Callback;
 import net.sf.cglib.proxy.Enhancer;
 import net.sf.cglib.proxy.MethodInterceptor;
 import net.sf.cglib.reflect.FastClass;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.AbstractName;
-import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.kernel.ClassLoading;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.ClassLoading;
+import org.apache.geronimo.kernel.proxy.ProxyCreationException;
 import org.apache.geronimo.kernel.proxy.ProxyFactory;
 import org.apache.geronimo.kernel.proxy.ProxyManager;
-import org.apache.geronimo.kernel.proxy.ProxyCreationException;
-
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.Map;
-import java.util.Collections;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Modifier;
 
 /**
  * Creates proxies that communicate directly with a Kernel located in the same
@@ -60,31 +55,6 @@
         this.kernel = kernel;
     }
 
-    /**
-     * Creates a proxy factory for GBeans of the specified type.  The proxy class will be
created within the class
-     * loader from which the specified type was loaded, or from the system class loader if
the specified type has
-     * a null class loader.
-     *
-     * @param type the type of the proxies this factory should create
-     * @return the proxy factory
-     */
-    public ProxyFactory createProxyFactory(Class type) {
-        if (type == null) throw new NullPointerException("type is null");
-        if (!type.isInterface() && !hasDefaultConstructor(type)) {
-            throw new IllegalArgumentException("Type class does not have a default constructor
" + type.getName());
-        }
-
-        ClassLoader classLoader = type.getClassLoader();
-        if(classLoader == null) {
-            classLoader = getClass().getClassLoader();
-        }
-        if(classLoader == null) {
-            classLoader = ClassLoader.getSystemClassLoader();
-        }
-
-        return createProxyFactory(new Class[] {type}, classLoader);
-    }
-
     public ProxyFactory createProxyFactory(Class[] types, ClassLoader classLoader) {
         if (types == null) throw new NullPointerException("type is null");
         if (types.length == 0) throw new IllegalArgumentException("interface list is empty");
@@ -108,45 +78,26 @@
         return new ManagedProxyFactory(types, classLoader);
     }
 
-    public Object createProxy(ObjectName target, Class type) {
-        if (target == null) throw new NullPointerException("target is null");
-        if (type == null) throw new NullPointerException("type is null");
-
-        ProxyFactory proxyFactory = createProxyFactory(type);
-        return proxyFactory.createProxy(target);
-    }
-
     public Object createProxy(AbstractName target, Class type) {
         if (target == null) throw new NullPointerException("target is null");
         if (type == null) throw new NullPointerException("type is null");
 
-        ProxyFactory proxyFactory = createProxyFactory(type);
-        return proxyFactory.createProxy(target);
-    }
-
-    public Object createProxy(ObjectName target, ClassLoader classLoader) {
-        if (target == null) throw new NullPointerException("target is null");
-        if (classLoader == null) throw new NullPointerException("classLoader is null");
-
         try {
-            GBeanInfo info = kernel.getGBeanInfo(target);
-            Set interfaces = info.getInterfaces();
-            if(interfaces.size() == 0) {
-                log.warn("No interfaces found for " + target + " ("+info.getClassName()+")");
-                return null;
-            }
-            String[] names = (String[]) interfaces.toArray(new String[0]);
-            List types = new ArrayList();
-            for (int i = 0; i < names.length; i++) {
-                try {
-                    Class type = classLoader.loadClass(names[i]);
-                    if (type.isInterface()) {
-                        types.add(type);
-                    }
-                } catch (ClassNotFoundException e) {
-                    log.warn("Could not load interface "+names[i]+" in provided ClassLoader
for "+target.getKeyProperty("name"));
+            // if the type is visible from the target's classloader use it
+            // otherwise use the type's classloader
+            ClassLoader classLoader = kernel.getClassLoaderFor(target);
+            try {
+                if (!type.equals(ClassLoading.loadClass(type.getName(), classLoader))) {
+                    classLoader = type.getClassLoader();
                 }
+            } catch (ClassNotFoundException ignored) {
             }
+
+            // add any interface exposed by the gbean that is visible from the selected class
loader
+            List types = getVisibleInterfaces(target, classLoader, true);
+            if (types == null) types = new ArrayList();
+            types.add(type);
+
             return createProxyFactory((Class[]) types.toArray(new Class[types.size()]), classLoader).createProxy(target);
         } catch (GBeanNotFoundException e) {
             throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target);
@@ -158,43 +109,38 @@
         if (classLoader == null) throw new NullPointerException("classLoader is null");
 
         try {
-            GBeanInfo info = kernel.getGBeanInfo(target);
-            Set interfaces = info.getInterfaces();
-            if(interfaces.size() == 0) {
-                log.warn("No interfaces found for " + target + " ("+target+")");
-                return null;
-            }
-            String[] names = (String[]) interfaces.toArray(new String[0]);
-            List types = new ArrayList();
-            for (int i = 0; i < names.length; i++) {
-                try {
-                    Class type = classLoader.loadClass(names[i]);
-                    if (type.isInterface()) {
-                        types.add(type);
-                    }
-                } catch (ClassNotFoundException e) {
-                    log.warn("Could not load interface "+names[i]+" in provided ClassLoader
for "+target);
-                }
-            }
+            List types = getVisibleInterfaces(target, classLoader, true);
+            if (types == null) return null;
             return createProxyFactory((Class[]) types.toArray(new Class[types.size()]), classLoader).createProxy(target);
         } catch (GBeanNotFoundException e) {
             throw new IllegalArgumentException("Could not get GBeanInfo for target object:
" + target);
         }
     }
 
-    public Object[] createProxies(String[] objectNameStrings, ClassLoader classLoader) throws
MalformedObjectNameException {
-        Object[] result = new Object[objectNameStrings.length];
-        for (int i = 0; i < result.length; i++) {
-            result[i] = createProxy(ObjectName.getInstance(objectNameStrings[i]), classLoader);
-        }
-        return result;
-    }
-    public Object[] createProxies(AbstractName[] names, ClassLoader classLoader) {
-        Object[] result = new Object[names.length];
-        for (int i = 0; i < result.length; i++) {
-            result[i] = createProxy(names[i], classLoader);
+    private List getVisibleInterfaces(AbstractName target, ClassLoader classLoader, boolean
shouldLog) throws GBeanNotFoundException {
+        GBeanInfo info = kernel.getGBeanInfo(target);
+        Set interfaces = info.getInterfaces();
+        if(interfaces.size() == 0) {
+            if (shouldLog) {
+                log.warn("No interfaces found for " + target + " ("+target+")");
+            }
+            return null;
         }
-        return result;
+        String[] names = (String[]) interfaces.toArray(new String[0]);
+        List types = new ArrayList();
+        for (int i = 0; i < names.length; i++) {
+            try {
+                Class type = classLoader.loadClass(names[i]);
+                if (type.isInterface()) {
+                    types.add(type);
+                }
+            } catch (ClassNotFoundException e) {
+                if (shouldLog) {
+                    log.warn("Could not load interface "+names[i]+" in provided ClassLoader
for "+target);
+                }
+            }
+        }
+        return types;
     }
 
     public void destroyProxy(Object proxy) {
@@ -255,35 +201,6 @@
             fastClass = FastClass.create(proxyType);
         }
 
-        public Object createProxy(ObjectName target) {
-            assert target != null: "target is null";
-
-            Callback callback;
-            try {
-                AbstractName targetName = getAbstractName(target, kernel);
-                callback = getMethodInterceptor(proxyType, kernel, targetName);
-            } catch (GBeanNotFoundException e) {
-                throw new ProxyCreationException(e);
-            }
-
-            Enhancer.registerCallbacks(proxyType, new Callback[]{callback});
-            try {
-                Object proxy = fastClass.newInstance();
-                interceptors.put(proxy, callback);
-                return proxy;
-            } catch (InvocationTargetException e) {
-                Throwable cause = e.getCause();
-                if (cause instanceof RuntimeException) {
-                  throw (RuntimeException) cause;
-                } else  if (cause instanceof Error) {
-                  throw (Error) cause;
-                } else if (cause != null) {
-                  throw new ProxyCreationException(cause);
-                } else {
-                  throw new ProxyCreationException(e);
-                }
-            }
-        }
         public Object createProxy(AbstractName target) {
             assert target != null: "target is null";
 
@@ -309,10 +226,6 @@
         }
     }
 
-    protected Callback getMethodInterceptor(Class proxyType, Kernel kernel, ObjectName target)
throws GBeanNotFoundException {
-        AbstractName targetName = getAbstractName(target, kernel);
-        return new ProxyMethodInterceptor(proxyType, kernel, targetName);
-    }
     protected Callback getMethodInterceptor(Class proxyType, Kernel kernel, AbstractName
target) {
         return new ProxyMethodInterceptor(proxyType, kernel, target);
     }
@@ -321,28 +234,7 @@
          ((ProxyMethodInterceptor)methodInterceptor).destroy();
     }
 
-     protected AbstractName getAbstractName(MethodInterceptor methodInterceptor) {
+    protected AbstractName getAbstractName(MethodInterceptor methodInterceptor) {
         return ((ProxyMethodInterceptor)methodInterceptor).getAbstractName();
-    }
-
-    private AbstractName getAbstractName(ObjectName objectName, Kernel kernel) throws GBeanNotFoundException
{
-        GBeanData gBeanData = kernel.getGBeanData(objectName);
-        return gBeanData.getAbstractName();
-    }
-
-    public static boolean hasDefaultConstructor(Class type) {
-        if (!Modifier.isPublic(type.getModifiers())) {
-            return false;
-        }
-        Constructor[] constructors = type.getDeclaredConstructors();
-        for (int i = 0; i < constructors.length; i++) {
-            Constructor constructor = constructors[i];
-            boolean accessible = Modifier.isPublic(constructor.getModifiers()) ||
-                    Modifier.isProtected(constructor.getModifiers());
-            if (accessible && constructor.getParameterTypes().length == 0) {
-                return true;
-            }
-        }
-        return false;
     }
 }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyFactory.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyFactory.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyFactory.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyFactory.java
Sun Apr 23 20:53:26 2006
@@ -23,14 +23,8 @@
 
 
 /**
- * @version $Rev$ $Date$
+ * @version $Rev: 383682 $ $Date$
  */
 public interface ProxyFactory {
-    /**
-     * Creates a proxy to the specified target
-     * @param target the name of the target
-     * @return the proxy
-     */
-    Object createProxy(ObjectName target);
     Object createProxy(AbstractName target);
 }

Modified: geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/java/org/apache/geronimo/kernel/proxy/ProxyManager.java
Sun Apr 23 20:53:26 2006
@@ -30,16 +30,6 @@
  * @version $Rev$ $Date$
  */
 public interface ProxyManager {
-    /**
-     * Create a proxy factory which will generate proxies of the specified type,
-     * plus GeronimoManagedBean. The proxy class will be created within the class
-     * loader from which the specified type was loaded, or from the system class
-     * loader if the specified type has a null class loader.
-     *
-     * @param type the type of the proxies to create
-     * @return the proxy factory
-     */
-    public ProxyFactory createProxyFactory(Class type);
 
 
     /**
@@ -52,45 +42,8 @@
      */
     ProxyFactory createProxyFactory(Class[] types, ClassLoader classLoader);
 
-    /**
-     * Create a proxy for the specified target.  The proxy will implement
-     * all of the interfaces that the underlying GBean specifies in its
-     * GBeanInfo, plus GeronimoManagedBean.  If there are no interfaces in
-     * the GBeanInfo, this method will return null.
-     *
-     * @param target the target object name
-     * @param loader the ClassLoader used to load the interfaces used by the
-     *        proxy
-     * @return the proxy, or null if the GBeanInfo declares no interfaces
-     */
-    public Object createProxy(ObjectName target, ClassLoader loader);
     public Object createProxy(AbstractName target, ClassLoader loader);
 
-    /**
-     * Create proxies for the specified targets.  The proxies will implement
-     * all of the interfaces that the underlying GBeans specify in their
-     * GBeanInfo, plus GeronimoManagedBean.  If there are no interfaces in the
-     * GBeanInfo, this method will return a null in that spot in the array.
-     *
-     * @param objectNameStrings An array of ObjectNames, each in String form
-     * @param loader the ClassLoader used to load the interfaces used by the
-     *               proxies
-     * @return an array of proxies of the same length as the argument array,
-     *         where each value is a proxy or null if the corresponding
-     *         GBeanInfo declares no interfaces
-     */
-    public Object[] createProxies(String[] objectNameStrings, ClassLoader loader) throws
MalformedObjectNameException;
-    public Object[] createProxies(AbstractName[] Names, ClassLoader loader) ;
-
-    /**
-     * Create a proxy for the specified target, implementing the specified
-     * interface, plus GeronimoManagedBean.
-     *
-     * @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);
     public Object createProxy(AbstractName target, Class type);
 
     /**

Modified: geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java?rev=396405&r1=396404&r2=396405&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
(original)
+++ geronimo/branches/1.1/modules/kernel/src/test/org/apache/geronimo/kernel/GBeanTest.java
Sun Apr 23 20:53:26 2006
@@ -425,10 +425,10 @@
 
         test = mgr.createProxy(gbean.getAbstractName(), MockEndpoint.class);
         assertTrue(test instanceof MockEndpoint);
-        assertFalse(test instanceof MockParentInterface1);
-        assertFalse(test instanceof MockParentInterface2);
-        assertFalse(test instanceof MockChildInterface1);
-        assertFalse(test instanceof MockChildInterface2);
+        assertTrue(test instanceof MockParentInterface1);
+        assertTrue(test instanceof MockParentInterface2);
+        assertTrue(test instanceof MockChildInterface1);
+        assertTrue(test instanceof MockChildInterface2);
         assertFalse(test instanceof Comparable);
 
         ProxyFactory proxyFactory;



Mime
View raw message