geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1038217 - in /geronimo/server/trunk/plugins: j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/ openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/ openwebbeans/g...
Date Tue, 23 Nov 2010 17:37:27 GMT
Author: djencks
Date: Tue Nov 23 17:37:27 2010
New Revision: 1038217

URL: http://svn.apache.org/viewvc?rev=1038217&view=rev
Log:
GERONIMO-5050 OWB integration set up injection of ee resources with naming builders.  Also
provide a more likely classloader for proxies

Modified:
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilderCollection.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansNamingBuilder.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
    geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
    geronimo/server/trunk/plugins/openwebbeans/openwebbeans-deployer/src/main/plan/plan.xml

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilderCollection.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilderCollection.java?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilderCollection.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/NamingBuilderCollection.java
Tue Nov 23 17:37:27 2010
@@ -33,6 +33,7 @@ import org.apache.geronimo.gbean.annotat
 import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.openejb.jee.JndiConsumer;
+import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.XmlObject;
 
 /**
@@ -88,7 +89,15 @@ public class NamingBuilderCollection ext
     }
 
     public QName getBaseQName() {
-        throw new IllegalStateException("Don't call this");
+        return new QName("foo");
+    }
+
+    public QNameSet getSpecQNameSet() {
+        return QNameSet.EMPTY;
+    }
+
+    public QNameSet getPlanQNameSet() {
+        return QNameSet.EMPTY;
     }
 
 }

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
(original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansModuleBuilderExtension.java
Tue Nov 23 17:37:27 2010
@@ -17,14 +17,22 @@
 
 package org.apache.geronimo.openwebbeans.deployment;
 
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.jar.JarFile;
 
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.Producer;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.ModuleIDBuilder;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
@@ -32,6 +40,7 @@ import org.apache.geronimo.gbean.Abstrac
 import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.annotation.GBean;
 import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
 import org.apache.geronimo.j2ee.annotation.Holder;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
@@ -45,9 +54,14 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.openwebbeans.WebBeansConfigurationListener;
 import org.apache.geronimo.web.info.WebAppInfo;
 import org.apache.openejb.jee.WebApp;
+import org.apache.xbean.finder.BundleAnnotationFinder;
 import org.apache.xbean.finder.ClassFinder;
+import org.apache.xbean.osgi.bundle.util.DiscoveryRange;
+import org.apache.xbean.osgi.bundle.util.ResourceDiscoveryFilter;
 import org.apache.xmlbeans.XmlObject;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.packageadmin.PackageAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -61,14 +75,16 @@ public class OpenWebBeansModuleBuilderEx
 
     private final Environment defaultEnvironment;
     //only plausible naming builder is ours that adds BeanManager entry
-    private final NamingBuilder namingBuilders  = new OpenWebBeansNamingBuilder();
+    private final NamingBuilder namingBuilders;
 
     //this is the geronimo copy
     private static final String CONTEXT_LISTENER_NAME = WebBeansConfigurationListener.class.getName();
 
     public OpenWebBeansModuleBuilderExtension(
-            @ParamAttribute(name = "defaultEnvironment") Environment defaultEnvironment)
{
+            @ParamAttribute(name = "defaultEnvironment") Environment defaultEnvironment,
+            @ParamReference(name = "NamingBuilders", namingType = NameFactory.MODULE_BUILDER)
NamingBuilder namingBuilders) {
         this.defaultEnvironment = defaultEnvironment;
+        this.namingBuilders = namingBuilders;
     }
 
     public void createModule(Module module, Bundle bundle, Naming naming, ModuleIDBuilder
idBuilder)
@@ -164,7 +180,46 @@ public class OpenWebBeansModuleBuilderEx
     }
 
     private List<Class> getManagedClasses(WebApp webApp, WebModule webModule) throws
DeploymentException {
-        return Collections.EMPTY_LIST;
+        Bundle bundle = webModule.getEarContext().getDeploymentBundle();
+        ServiceReference reference = bundle.getBundleContext().getServiceReference(PackageAdmin.class.getName());
+        try {
+            PackageAdmin packageAdmin = (PackageAdmin) bundle.getBundleContext().getService(reference);
+            Map<Class<? extends Annotation>, Set<Class>> annotationClassSetMap
= new HashMap<Class<? extends Annotation>, Set<Class>>();
+            BundleAnnotationFinder bundleAnnotationFinder = new BundleAnnotationFinder(packageAdmin,
bundle, new ResourceDiscoveryFilter() {
+
+                @Override
+                public boolean directoryDiscoveryRequired(String directory) {
+                    //TODO WEB-INF/classes ???
+                    return true;
+                }
+
+                @Override
+                public boolean rangeDiscoveryRequired(DiscoveryRange discoveryRange) {
+                    return discoveryRange.equals(DiscoveryRange.BUNDLE_CLASSPATH);
+                }
+
+                @Override
+                public boolean zipFileDiscoveryRequired(String jarFile) {
+                    //????
+                    return true;
+                }
+
+            });
+            Set<Class<?>> classes = new HashSet<Class<?>>();
+            List<Method> methods = bundleAnnotationFinder.findAnnotatedMethods(Produces.class);
+            for (Method method: methods) {
+                classes.add(method.getDeclaringClass());
+            }
+            List<Field> fields = bundleAnnotationFinder.findAnnotatedFields(Produces.class);
+            for (Field field: fields) {
+                classes.add(field.getDeclaringClass());
+            }
+            return new ArrayList(classes);
+        } catch (Exception e) {
+            throw new DeploymentException("Fail to scan jsr299 annotations", e);
+        } finally {
+            bundle.getBundleContext().ungetService(reference);
+        }
     }
-
+    
 }

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansNamingBuilder.java?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansNamingBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans-builder/src/main/java/org/apache/geronimo/openwebbeans/deployment/OpenWebBeansNamingBuilder.java
Tue Nov 23 17:37:27 2010
@@ -24,8 +24,10 @@ import java.util.Collections;
 import java.util.Map;
 
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.gbean.annotation.GBean;
 import org.apache.geronimo.j2ee.deployment.EARContext;
 import org.apache.geronimo.j2ee.deployment.Module;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
 import org.apache.geronimo.openwebbeans.BeanManagerReference;
 import org.apache.openejb.jee.InjectionTarget;
@@ -36,6 +38,7 @@ import org.apache.xmlbeans.XmlObject;
 /**
  * @version $Rev:$ $Date:$
  */
+@GBean(j2eeType = NameFactory.MODULE_BUILDER)
 public class OpenWebBeansNamingBuilder extends AbstractNamingBuilder {
     @Override
     public void buildNaming(JndiConsumer specDD, XmlObject plan, Module module, Map<EARContext.Key,
Object> sharedContext) throws DeploymentException {
@@ -44,11 +47,11 @@ public class OpenWebBeansNamingBuilder e
 
     @Override
     public QNameSet getSpecQNameSet() {
-        return null;
+        return QNameSet.EMPTY;
     }
 
     @Override
     public QNameSet getPlanQNameSet() {
-        return null;
+        return QNameSet.EMPTY;
     }
 }

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
(original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/OsgiMetaDataScannerService.java
Tue Nov 23 17:37:27 2010
@@ -18,8 +18,11 @@
  */
 package org.apache.geronimo.openwebbeans;
 
+import org.apache.webbeans.config.OpenWebBeansConfiguration;
+import org.apache.webbeans.corespi.se.DefaultBDABeansXmlScanner;
 import org.apache.webbeans.exception.WebBeansDeploymentException;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.spi.BDABeansXmlScanner;
 import org.apache.webbeans.spi.ScannerService;
 
 import org.apache.xbean.finder.BundleAssignableClassFinder;
@@ -52,10 +55,12 @@ public class OsgiMetaDataScannerService 
 
     private boolean configured = false;
 
-//    protected ServletContext servletContext = null;
     private static final String META_INF_BEANS_XML = "META-INF/beans.xml";
     private static final String WEB_INF_BEANS_XML = "WEB-INF/beans.xml";
 
+    protected boolean isBDAScannerEnabled = false;
+    protected BDABeansXmlScanner bdaBeansXmlScanner;
+
     /** All classes which have to be scanned for Bean information */
     private Set<Class<?>> beanClasses = new HashSet<Class<?>>();
 
@@ -68,10 +73,15 @@ public class OsgiMetaDataScannerService 
     @Override
     public void init(Object object)
     {
-//        if (object instanceof ServletContext)
-//        {
-//            servletContext = (ServletContext) object;
-//        }
+        // set per BDA beans.xml flag here because setting it in constructor
+        // occurs before
+        // properties are loaded.
+        String usage = OpenWebBeansConfiguration.getInstance().getProperty(OpenWebBeansConfiguration.USE_BDA_BEANSXML_SCANNER);
+        this.isBDAScannerEnabled = Boolean.parseBoolean(usage);
+        if (isBDAScannerEnabled)
+        {
+            bdaBeansXmlScanner = new DefaultBDABeansXmlScanner();
+        }
     }
 
     @Override
@@ -221,4 +231,16 @@ public class OsgiMetaDataScannerService 
     {
         return beanClasses;
     }
+
+    @Override
+    public boolean isBDABeansXmlScanningEnabled()
+    {
+        return isBDAScannerEnabled;
+    }
+
+    @Override
+    public BDABeansXmlScanner getBDABeansXmlScanner()
+    {
+        return bdaBeansXmlScanner;
+    }
 }

Modified: geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
(original)
+++ geronimo/server/trunk/plugins/openwebbeans/geronimo-openwebbeans/src/main/java/org/apache/geronimo/openwebbeans/SingletonServiceInitializerGBean.java
Tue Nov 23 17:37:27 2010
@@ -20,6 +20,18 @@
 
 package org.apache.geronimo.openwebbeans;
 
+import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javassist.util.proxy.ProxyFactory;
+import javassist.util.proxy.ProxyObject;
 import org.apache.geronimo.gbean.annotation.GBean;
 import org.apache.geronimo.gbean.annotation.ParamSpecial;
 import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
@@ -34,5 +46,111 @@ public class SingletonServiceInitializer
 
     public SingletonServiceInitializerGBean(@ParamSpecial(type = SpecialAttributeType.bundle)
Bundle bundle) {
         GeronimoSingletonService.init(bundle);
+        ProxyFactory.classLoaderProvider = new GeronimoClassLoaderProvider();
+    }
+
+    private static class GeronimoClassLoaderProvider implements ProxyFactory.ClassLoaderProvider
{
+
+        private final ConcurrentMap<Bundle, ClassLoader> proxyClassLoaders = new ConcurrentHashMap<Bundle,
ClassLoader>();
+
+        @Override
+        public ClassLoader get(ProxyFactory proxyFactory) {
+            Collection<ClassLoader> baseCl = getBaseCl(proxyFactory);
+            if (baseCl.size() == 1) {
+                return baseCl.iterator().next();
+            }
+//            Bundle bundle = null;
+//            if (baseCl instanceof BundleReference) {
+//                bundle = ((BundleReference)baseCl).getBundle();
+//                ClassLoader proxyCl = proxyClassLoaders.get(bundle);
+//                if (proxyCl != null) {
+//                    return proxyCl;
+//                }
+//            }
+//            ClassLoader extensionCl = baseProvider.getClass().getClassLoader();
+            ClassLoader proxyCl = new MultiParentClassLoader(baseCl);
+//            if (bundle != null) {
+//                ClassLoader oldCl = proxyClassLoaders.putIfAbsent(bundle, proxyCl);
+//                if (oldCl != null) {
+//                    return oldCl;
+//                }
+//            }
+            return proxyCl;
+        }
+
+        private Collection<ClassLoader> getBaseCl(ProxyFactory proxyFactory) {
+            Set<Class<?>> classes = new HashSet<Class<?>>();
+            classes.add(ProxyObject.class);
+            Class<?> superClass = proxyFactory.getSuperclass();
+            if (superClass != null && superClass != Object.class) {
+                classes.add(superClass);
+            }
+            for (Class<?> clazz: proxyFactory.getInterfaces()) {
+                classes.add(clazz);
+            }
+            Map<Class<?>, ClassLoader> classLoaderMap = new HashMap<Class<?>,
ClassLoader>(3);
+            for (Class<?> clazz: classes) {
+                ClassLoader newCl = clazz.getClassLoader();
+                if (newCl != null) {
+                    boolean loadable = false;
+                    for (Map.Entry<Class<?>, ClassLoader> entry: classLoaderMap.entrySet())
{
+                        try {
+                            entry.getValue().loadClass(clazz.getName());
+                            loadable = true;
+                            break;
+                        } catch (ClassNotFoundException e) {
+                            //continue looking
+                        }
+                    }
+                    if (!loadable) {
+                        for (Iterator<Map.Entry<Class<?>, ClassLoader>>
it = classLoaderMap.entrySet().iterator(); it.hasNext(); ) {
+                            Map.Entry<Class<?>, ClassLoader> entry = it.next();
+                            try {
+                                newCl.loadClass(entry.getKey().getName());
+                                it.remove();
+                            } catch (ClassNotFoundException e) {
+                                //continue
+                            }
+                        }
+                        classLoaderMap.put(clazz, newCl);
+                    }
+                }
+            }
+            //check for default access superclass and more than one or wrong classloader
+
+
+            return classLoaderMap.values();
+        }
+
+        private static class MultiParentClassLoader extends ClassLoader {
+            private final Collection<ClassLoader> classLoaders;
+            public MultiParentClassLoader(Collection<ClassLoader> classLoaders) {
+                this.classLoaders = classLoaders;
+            }
+
+            @Override
+            public Class<?> loadClass(String name) throws ClassNotFoundException {
+                for (ClassLoader cl: classLoaders) {
+                    try {
+                        return cl.loadClass(name);
+                    } catch (ClassNotFoundException e) {
+                        //ignore
+                    }
+
+                }
+                return super.loadClass(name);
+            }
+
+            @Override
+            public URL getResource(String name) {
+                for (ClassLoader cl: classLoaders) {
+                    URL url = cl.getResource(name);
+                    if (url != null) {
+                        return url;
+                    }
+                }
+                return null;
+            }
+        }
     }
 }

Modified: geronimo/server/trunk/plugins/openwebbeans/openwebbeans-deployer/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openwebbeans/openwebbeans-deployer/src/main/plan/plan.xml?rev=1038217&r1=1038216&r2=1038217&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openwebbeans/openwebbeans-deployer/src/main/plan/plan.xml
(original)
+++ geronimo/server/trunk/plugins/openwebbeans/openwebbeans-deployer/src/main/plan/plan.xml
Tue Nov 23 17:37:27 2010
@@ -21,6 +21,9 @@
 <module xmlns="http://geronimo.apache.org/xml/ns/deployment-${geronimoSchemaVersion}">
 
     <gbean name="OpenWebBeansModuleBuilderExtension" class="org.apache.geronimo.openwebbeans.deployment.OpenWebBeansModuleBuilderExtension">
+        <reference name="NamingBuilders">
+            <name>OWBNamingBuilders</name>
+        </reference>
         <xml-attribute name="defaultEnvironment">
             <environment xmlns="http://geronimo.apache.org/xml/ns/deployment-1.2">
                 <dependencies>
@@ -53,4 +56,17 @@
         </xml-attribute>
     </gbean>
 
+    <gbean name="OWBNamingBuilder" class="org.apache.geronimo.openwebbeans.deployment.OpenWebBeansNamingBuilder"/>
+
+    <gbean name="OWBNamingBuilders" class="org.apache.geronimo.j2ee.deployment.NamingBuilderCollection">
+        <references name="NamingBuilders">
+            <pattern>
+                <name>NamingBuilders</name>
+            </pattern>
+            <pattern>
+                <name>OWBNamingBuilder</name>
+            </pattern>
+        </references>
+    </gbean>
+
 </module>



Mime
View raw message