cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1544946 - in /cayenne/main/trunk/cayenne-server/src: main/java/org/apache/cayenne/configuration/osgi/ test/java/org/apache/cayenne/configuration/osgi/
Date Sun, 24 Nov 2013 08:50:07 GMT
Author: aadamchik
Date: Sun Nov 24 08:50:07 2013
New Revision: 1544946

URL: http://svn.apache.org/r1544946
Log:
CAY-1882 Porting to OSGi environment

explicitly setting bundle ClassLoader in OSGi module

Modified:
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/OsgiModule.java
    cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactory.java
    cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactoryTest.java

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/OsgiModule.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/OsgiModule.java?rev=1544946&r1=1544945&r2=1544946&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/OsgiModule.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/OsgiModule.java
Sun Nov 24 08:50:07 2013
@@ -29,8 +29,33 @@ import org.apache.cayenne.di.Module;
  */
 public class OsgiModule implements Module {
 
+    /**
+     * A factory method that creates a new OsgiModule, initialized with any
+     * class from the OSGi bundle that contains Cayenne mapping and persistent
+     * classes. This is likely the the bundle that is calling this method.
+     */
+    public static OsgiModule forProject(Class<?> typeFromProjectBundle) {
+
+        if (typeFromProjectBundle == null) {
+            throw new NullPointerException("Null 'typeFromProjectBundle'");
+        }
+
+        OsgiModule module = new OsgiModule();
+        module.typeFromProjectBundle = typeFromProjectBundle;
+        return module;
+    }
+
+    private Class<?> typeFromProjectBundle;
+
+    private OsgiModule() {
+    }
+
     @Override
     public void configure(Binder binder) {
-        binder.bind(AdhocObjectFactory.class).to(SplitClassLoaderAdhocObjectFactory.class);
+        binder.bind(AdhocObjectFactory.class).toInstance(configureObjectFactory());
+    }
+
+    private AdhocObjectFactory configureObjectFactory() {
+        return new SplitClassLoaderAdhocObjectFactory(typeFromProjectBundle.getClassLoader());
     }
 }

Modified: cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactory.java?rev=1544946&r1=1544945&r2=1544946&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactory.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/main/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactory.java
Sun Nov 24 08:50:07 2013
@@ -32,10 +32,12 @@ public class SplitClassLoaderAdhocObject
     private static final String CAYENNE_PACKAGE = "org/apache/cayenne";
     private static final String CAYENNE_DI_PACKAGE_SUFFIX = "/di";
 
+    private ClassLoader applicationClassLoader;
     private ClassLoader cayenneServerClassLoader;
     private ClassLoader cayenneDiClassLoader;
 
-    public SplitClassLoaderAdhocObjectFactory() {
+    public SplitClassLoaderAdhocObjectFactory(ClassLoader applicationClassLoader) {
+        this.applicationClassLoader = applicationClassLoader;
         this.cayenneDiClassLoader = AdhocObjectFactory.class.getClassLoader();
         this.cayenneServerClassLoader = SplitClassLoaderAdhocObjectFactory.class.getClassLoader();
     }
@@ -58,7 +60,7 @@ public class SplitClassLoaderAdhocObject
     }
 
     protected ClassLoader applicationClassLoader(String resourceName) {
-        return super.getClassLoader(resourceName);
+        return applicationClassLoader;
     }
 
     protected ClassLoader cayenneDiClassLoader() {

Modified: cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactoryTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactoryTest.java?rev=1544946&r1=1544945&r2=1544946&view=diff
==============================================================================
--- cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactoryTest.java
(original)
+++ cayenne/main/trunk/cayenne-server/src/test/java/org/apache/cayenne/configuration/osgi/SplitClassLoaderAdhocObjectFactoryTest.java
Sun Nov 24 08:50:07 2013
@@ -29,11 +29,7 @@ public class SplitClassLoaderAdhocObject
         final ClassLoader diCl = mock(ClassLoader.class);
         final ClassLoader serverCl = mock(ClassLoader.class);
 
-        SplitClassLoaderAdhocObjectFactory factory = new SplitClassLoaderAdhocObjectFactory()
{
-            @Override
-            protected ClassLoader applicationClassLoader(String resourceName) {
-                return appCl;
-            }
+        SplitClassLoaderAdhocObjectFactory factory = new SplitClassLoaderAdhocObjectFactory(appCl)
{
 
             @Override
             protected ClassLoader cayenneDiClassLoader() {



Mime
View raw message