openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mprud...@apache.org
Subject svn commit: r440882 - /incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
Date Wed, 06 Sep 2006 21:42:32 GMT
Author: mprudhom
Date: Wed Sep  6 14:42:31 2006
New Revision: 440882

URL: http://svn.apache.org/viewvc?view=rev&rev=440882
Log:
OPENJPA-40 Fall back to using the ConfigurationProvider's ClassLoader in the even of a loader
mismatch.

Modified:
    incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java

Modified: incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java?view=diff&rev=440882&r1=440881&r2=440882
==============================================================================
--- incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
(original)
+++ incubator/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/Bootstrap.java
Wed Sep  6 14:42:31 2006
@@ -53,23 +53,17 @@
      */
     public static BrokerFactory newBrokerFactory(ConfigurationProvider conf,
         ClassLoader loader) {
-        if (conf == null)
-            conf = new MapConfigurationProvider();
-        ProductDerivations.beforeConfigurationConstruct(conf);
-
-        Class cls = getFactoryClass(conf, loader);
         try {
-            Method meth = cls.getMethod("newInstance", FACTORY_ARGS);
-            return (BrokerFactory) meth.invoke(null, new Object[]{ conf });
+            return invokeFactory(conf, loader, "newInstance");
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getTargetException();
             if (cause instanceof OpenJPAException)
                 throw (OpenJPAException) cause;
             throw new InternalException(s_loc.get("new-brokerfactory-excep",
-                cls), cause);
+                getFactoryClass(conf, loader)), cause);
         } catch (Exception e) {
-            throw new UserException(s_loc.get("bad-new-brokerfactory", cls),
-                e).setFatal(true);
+            throw new UserException(s_loc.get("bad-new-brokerfactory",
+                getFactoryClass(conf, loader)), e).setFatal(true);
         }
     }
 
@@ -87,24 +81,40 @@
      */
     public static BrokerFactory getBrokerFactory(ConfigurationProvider conf,
         ClassLoader loader) {
-        if (conf == null)
-            conf = new MapConfigurationProvider();
-        ProductDerivations.beforeConfigurationConstruct(conf);
-
-        Class cls = getFactoryClass(conf, loader);
         try {
-            Method meth = cls.getMethod("getInstance", FACTORY_ARGS);
-            return (BrokerFactory) meth.invoke(null, new Object[]{ conf });
+            return invokeFactory(conf, loader, "getInstance");
         } catch (InvocationTargetException ite) {
             Throwable cause = ite.getTargetException();
             if (cause instanceof OpenJPAException)
                 throw (OpenJPAException) cause;
-            throw new InternalException(s_loc.get("brokerfactory-excep", cls),
-                cause);
+            throw new InternalException(s_loc.get("brokerfactory-excep",
+                getFactoryClass(conf, loader)), cause);
         } catch (Exception e) {
-            throw new UserException(s_loc.get("bad-brokerfactory", cls), e).
-                setFatal(true);
+            throw new UserException(s_loc.get("bad-brokerfactory",
+                getFactoryClass(conf, loader)), e).setFatal(true);
         }
+    }
+
+    private static BrokerFactory invokeFactory (ConfigurationProvider conf,
+        ClassLoader loader, String methodName)
+        throws InvocationTargetException, NoSuchMethodException,
+            IllegalAccessException {
+        if (conf == null)
+            conf = new MapConfigurationProvider();
+        ProductDerivations.beforeConfigurationConstruct(conf);
+
+        Class cls = getFactoryClass(conf, loader);
+        Method meth;
+        try {
+            meth = cls.getMethod(methodName, FACTORY_ARGS); 
+        } catch (NoSuchMethodException nsme) {
+            // handle cases where there is a mismatch between loaders by falling
+            // back to the configuration's class loader for broker resolution
+            cls = getFactoryClass(conf, conf.getClass().getClassLoader());
+            meth = cls.getMethod(methodName, FACTORY_ARGS); 
+        }
+
+        return (BrokerFactory) meth.invoke(null, new Object[]{ conf });
     }
 
     /**



Mime
View raw message