ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From boisv...@apache.org
Subject svn commit: r462888 - /incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java
Date Wed, 11 Oct 2006 18:01:56 GMT
Author: boisvert
Date: Wed Oct 11 11:01:55 2006
New Revision: 462888

URL: http://svn.apache.org/viewvc?view=rev&rev=462888
Log:
Some Geronimo voodoo to inject Jencks into Geronimo's classloader

Modified:
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java

Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java?view=diff&rev=462888&r1=462887&r2=462888
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java
(original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/GeronimoFactory.java
Wed Oct 11 11:01:55 2006
@@ -19,40 +19,65 @@
 
 package org.apache.ode.axis2.util;
 
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.config.MultiParentClassLoader;
 import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.transaction.context.GeronimoTransactionManager;
 import org.apache.geronimo.transaction.context.TransactionContextManager;
-import javax.transaction.TransactionManager;
-import javax.management.ObjectName;
-import java.net.URI;
-import java.net.URISyntaxException;
+import org.apache.log4j.Logger;
 
 public class GeronimoFactory {
 
+    static final Logger LOGGER = Logger.getLogger(GeronimoFactory.class);
+    
+    /* Public no-arg contructor is required */
     public GeronimoFactory() {
     }
 
     public TransactionManager getTransactionManager() {
         Kernel kernel = KernelRegistry.getSingleKernel(); 
+        TransactionContextManager ctxManager = null;
+
         try {
-            // Using Jencks.
-            TransactionContextManager ctxManager = (TransactionContextManager)kernel.getProxyManager().createProxy(
-                new AbstractName(new URI("geronimo/j2ee-server/1.1/car?ServiceModule=geronimo/j2ee-server/1.1/car,j2eeType=TransactionContextManager,name=TransactionContextManager")),
-                TransactionContextManager.class);
-            return new GeronimoTransactionManager(ctxManager);
-/*
-            // Passing TransactionManager directly.
-            TransactionManager txManager = (TransactionManager)kernel.getProxyManager().createProxy(
-                new AbstractName(new URI("geronimo/j2ee-server/1.1/car?ServiceModule=geronimo/j2ee-server/1.1/car,j2eeType=TransactionManager,name=TransactionManager")),
-                TransactionManager.class);
-            return txManager;
-*/
-        } catch (URISyntaxException except) {
-            throw new RuntimeException(except);
+            ctxManager = (TransactionContextManager) kernel.getGBean(TransactionContextManager.class);
+        } catch (GBeanNotFoundException except) {
+            throw new RuntimeException( "Can't lookup GBean: " + TransactionContextManager.class,
except);
         }
+
+        MultiParentClassLoader loader = (MultiParentClassLoader) ctxManager.getClass().getClassLoader();
+
+        // Add Jencks to Geronimo's root classloader to avoid InvalidAccessError
+        AbstractNameQuery abstractNameQuery = new AbstractNameQuery(null, Collections.EMPTY_MAP,
Repository.class.getName());
+        Set set = kernel.listGBeans(abstractNameQuery);
+        for (Iterator iterator = set.iterator(); iterator.hasNext();) {
+            AbstractName abstractName = (AbstractName) iterator.next();
+            File f = null;
+            try {
+                Repository repo = (Repository) kernel.getGBean(abstractName);
+                f = repo.getLocation(new Artifact("org.jencks", "jencks", "1.3", "jar"));
+                loader.addURL(f.toURL());
+            } catch (GBeanNotFoundException except) {
+                throw new RuntimeException("Can't lookup GBean: " + abstractName, except);
+            } catch (MalformedURLException except) {
+                throw new RuntimeException("Invalid URL for jencks: " + f, except);
+            }
+        }            
+            
+        // Use Jenck to wrap TransactionContextManager back to TransactionManager
+        return new GeronimoTransactionManager(ctxManager);
     }
 
 }



Mime
View raw message