geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject svn commit: r712321 - in /geronimo/server/trunk/framework/modules/geronimo-kernel/src: main/java/org/apache/geronimo/gbean/ main/java/org/apache/geronimo/gbean/annotation/ test/java/org/apache/geronimo/gbean/
Date Sat, 08 Nov 2008 00:28:43 GMT
Author: gdamour
Date: Fri Nov  7 16:28:43 2008
New Revision: 712321

URL: http://svn.apache.org/viewvc?rev=712321&view=rev
Log:
GBeanInfo.getGBeanInfo should call the MultiGBeanInfoFactory so that the annotation GBean
configuration style is attempted.

(GERONIMO-4399) GBean Annotations are not supported for GBeans declared in XML configuration

Removed:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/AbstractGBeanInfoFactory.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/BasicGBeanInfoFactory.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoFactoryException.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/MultiGBeanInfoFactory.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoFactory.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/BasicGBeanInfoFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/BasicGBeanInfoFactory.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/BasicGBeanInfoFactory.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/BasicGBeanInfoFactory.java
Fri Nov  7 16:28:43 2008
@@ -19,19 +19,61 @@
 
 package org.apache.geronimo.gbean;
 
+import java.lang.reflect.Method;
+
+
 
 /**
  *
  * @version $Rev:$ $Date:$
  */
-public class BasicGBeanInfoFactory extends AbstractGBeanInfoFactory {
+public class BasicGBeanInfoFactory implements GBeanInfoFactory {
 
     public GBeanInfo getGBeanInfo(Class clazz) throws GBeanInfoFactoryException {
+        return getGBeanInfo(clazz.getName(), clazz.getClassLoader());
+    }
+
+    public GBeanInfo getGBeanInfo(String className, ClassLoader classLoader) throws GBeanInfoFactoryException
{
+        Class clazz;
         try {
-            return GBeanInfo.getGBeanInfo(clazz.getName(), clazz.getClassLoader());
-        } catch (InvalidConfigurationException e) {
-            throw new GBeanInfoFactoryException(e);
+            clazz = classLoader.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new GBeanInfoFactoryException("Could not load class " + className, e);
+        } catch (NoClassDefFoundError e) {
+            throw new GBeanInfoFactoryException("Could not load class " + className, e);
+        }
+        Method method;
+        try {
+            method = clazz.getDeclaredMethod("getGBeanInfo", new Class[]{});
+        } catch (NoSuchMethodException e) {
+            try {
+                // try to get the info from ${className}GBean
+                clazz = classLoader.loadClass(className + "GBean");
+                method = clazz.getDeclaredMethod("getGBeanInfo", new Class[]{});
+            } catch (Exception ignored) {
+                throw new GBeanInfoFactoryException("Class does not have a getGBeanInfo()
method: " + className);
+            }
+        } catch (NoClassDefFoundError e) {
+            String message = e.getMessage();
+            StringBuffer buf = new StringBuffer("Could not load gbean class ").append(className).append("
due to NoClassDefFoundError\n");
+            if (message != null) {
+                message = message.replace('/', '.');
+                buf.append("    problematic class ").append(message);
+                try {
+                    Class hardToLoad = classLoader.loadClass(message);
+                    buf.append(" can be loaded in supplied classloader ").append(classLoader).append("\n");
+                    buf.append("    and is found in ").append(hardToLoad.getClassLoader());
+                } catch (ClassNotFoundException e1) {
+                    buf.append(" cannot be loaded in supplied classloader ").append(classLoader).append("\n");
+                }
+            }
+            throw new GBeanInfoFactoryException(buf.toString(), e);
+        }
+        try {
+            return (GBeanInfo) method.invoke(null, new Object[]{});
+        } catch (Exception e) {
+            throw new GBeanInfoFactoryException("Could not get GBeanInfo from class: " +
className, e);
         }
     }
-
+    
 }
\ No newline at end of file

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanData.java
Fri Nov  7 16:28:43 2008
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.io.NotSerializableException;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfo.java
Fri Nov  7 16:28:43 2008
@@ -20,7 +20,6 @@
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.Serializable;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -57,48 +56,14 @@
      *          if there is a problem getting the GBeanInfo from the class
      */
     public static GBeanInfo getGBeanInfo(String className, ClassLoader classLoader) throws
InvalidConfigurationException {
-        Class clazz;
+        GBeanInfoFactory infoFactory = new MultiGBeanInfoFactory();
         try {
-            clazz = classLoader.loadClass(className);
-        } catch (ClassNotFoundException e) {
-            throw new InvalidConfigurationException("Could not load class " + className,
e);
-        } catch (NoClassDefFoundError e) {
-            throw new InvalidConfigurationException("Could not load class " + className,
e);
-        }
-        Method method;
-        try {
-            method = clazz.getDeclaredMethod("getGBeanInfo", new Class[]{});
-        } catch (NoSuchMethodException e) {
-            try {
-                // try to get the info from ${className}GBean
-                clazz = classLoader.loadClass(className + "GBean");
-                method = clazz.getDeclaredMethod("getGBeanInfo", new Class[]{});
-            } catch (Exception ignored) {
-                throw new InvalidConfigurationException("Class does not have a getGBeanInfo()
method: " + className);
-            }
-        } catch (NoClassDefFoundError e) {
-            String message = e.getMessage();
-            StringBuffer buf = new StringBuffer("Could not load gbean class ").append(className).append("
due to NoClassDefFoundError\n");
-            if (message != null) {
-                message = message.replace('/', '.');
-                buf.append("    problematic class ").append(message);
-                try {
-                    Class hardToLoad = classLoader.loadClass(message);
-                    buf.append(" can be loaded in supplied classloader ").append(classLoader).append("\n");
-                    buf.append("    and is found in ").append(hardToLoad.getClassLoader());
-                } catch (ClassNotFoundException e1) {
-                    buf.append(" cannot be loaded in supplied classloader ").append(classLoader).append("\n");
-                }
-            }
-            throw new InvalidConfigurationException(buf.toString(), e);
-        }
-        try {
-            return (GBeanInfo) method.invoke(null, new Object[]{});
-        } catch (Exception e) {
-            throw new InvalidConfigurationException("Could not get GBeanInfo from class:
" + className, e);
+            return infoFactory.getGBeanInfo(className, classLoader);
+        } catch (GBeanInfoFactoryException e) {
+            throw new InvalidConfigurationException("See nested", e);
         }
     }
-
+    
     private final String sourceClass;
     private final String name;
     private final String className;

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoFactoryException.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoFactoryException.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoFactoryException.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/GBeanInfoFactoryException.java
Fri Nov  7 16:28:43 2008
@@ -26,6 +26,13 @@
  */
 public class GBeanInfoFactoryException extends RuntimeException {
 
+    public GBeanInfoFactoryException() {
+    }
+
+    public GBeanInfoFactoryException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
     public GBeanInfoFactoryException(String message) {
         super(message);
     }

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/MultiGBeanInfoFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/MultiGBeanInfoFactory.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/MultiGBeanInfoFactory.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/MultiGBeanInfoFactory.java
Fri Nov  7 16:28:43 2008
@@ -19,8 +19,6 @@
 
 package org.apache.geronimo.gbean;
 
-import java.util.ArrayList;
-import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.geronimo.gbean.annotation.AnnotationGBeanInfoFactory;
@@ -30,24 +28,24 @@
  *
  * @version $Rev:$ $Date:$
  */
-public class MultiGBeanInfoFactory extends AbstractGBeanInfoFactory implements GBeanInfoFactoryRegistry
{
-    private final static CopyOnWriteArrayList<GBeanInfoFactory> factories = new CopyOnWriteArrayList<GBeanInfoFactory>();
+public class MultiGBeanInfoFactory implements GBeanInfoFactory, GBeanInfoFactoryRegistry
{
+    private final static CopyOnWriteArrayList<GBeanInfoFactory> FACTORIES = new CopyOnWriteArrayList<GBeanInfoFactory>();
     
     static {
-        factories.add(new BasicGBeanInfoFactory());
-        factories.add(new AnnotationGBeanInfoFactory());
+        FACTORIES.add(new BasicGBeanInfoFactory());
+        FACTORIES.add(new AnnotationGBeanInfoFactory());
     }
 
     public void registerFactory(GBeanInfoFactory factory) {
-        factories.add(0, factory);
+        FACTORIES.add(0, factory);
     }
     
     public void unregisterFactory(GBeanInfoFactory factory) {
-        factories.remove(factory);
+        FACTORIES.remove(factory);
     }
     
     public GBeanInfo getGBeanInfo(Class clazz) throws GBeanInfoFactoryException {
-        for (GBeanInfoFactory factory : factories) {
+        for (GBeanInfoFactory factory : FACTORIES) {
             try {
                 return factory.getGBeanInfo(clazz);
             } catch (GBeanInfoFactoryException e) {
@@ -56,4 +54,14 @@
         throw new GBeanInfoFactoryException("Cannot create a GBeanInfo for [" + clazz + "]");
     }
 
+    public GBeanInfo getGBeanInfo(String className, ClassLoader classLoader) throws GBeanInfoFactoryException
{
+        for (GBeanInfoFactory factory : FACTORIES) {
+            try {
+                return factory.getGBeanInfo(className, classLoader);
+            } catch (GBeanInfoFactoryException e) {
+            }
+        }
+        throw new GBeanInfoFactoryException("Cannot create a GBeanInfo for [" + className
+ "]");
+    }
+    
 }
\ No newline at end of file

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoFactory.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoFactory.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoFactory.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/gbean/annotation/AnnotationGBeanInfoFactory.java
Fri Nov  7 16:28:43 2008
@@ -19,9 +19,10 @@
 
 package org.apache.geronimo.gbean.annotation;
 
-import org.apache.geronimo.gbean.AbstractGBeanInfoFactory;
 import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoFactory;
 import org.apache.geronimo.gbean.GBeanInfoFactoryException;
+import org.apache.geronimo.gbean.InvalidConfigurationException;
 
 
 
@@ -30,7 +31,19 @@
  *
  * @version $Rev:$ $Date:$
  */
-public class AnnotationGBeanInfoFactory extends AbstractGBeanInfoFactory {
+public class AnnotationGBeanInfoFactory implements GBeanInfoFactory {
+
+    public GBeanInfo getGBeanInfo(String className, ClassLoader classLoader) throws GBeanInfoFactoryException
{
+        Class clazz;
+        try {
+            clazz = classLoader.loadClass(className);
+        } catch (ClassNotFoundException e) {
+            throw new InvalidConfigurationException("Could not load class " + className,
e);
+        } catch (NoClassDefFoundError e) {
+            throw new InvalidConfigurationException("Could not load class " + className,
e);
+        }
+        return getGBeanInfo(clazz);
+    }
 
     public GBeanInfo getGBeanInfo(Class clazz) throws GBeanInfoFactoryException {
         AnnotationGBeanInfoBuilder infoFactory = new AnnotationGBeanInfoBuilder(clazz);

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java?rev=712321&r1=712320&r2=712321&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/test/java/org/apache/geronimo/gbean/GBeanInfoTest.java
Fri Nov  7 16:28:43 2008
@@ -45,14 +45,6 @@
             fail("InvalidConfigurationException expected");
         } catch (InvalidConfigurationException expected) {
         }
-
-        // 3. Test GBean that exist, but doesn't declare a getGBeanInfo()
-        // method
-        try {
-            GBeanInfo.getGBeanInfo(String.class.getName(), this.getClass().getClassLoader());
-            fail("InvalidConfigurationException expected");
-        } catch (InvalidConfigurationException expected) {
-        }
     }
 
     public void testGetName() {



Mime
View raw message