You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2009/04/20 00:31:26 UTC

svn commit: r766539 - in /incubator/openwebbeans/trunk/webbeans-impl: ./ src/main/java/org/apache/webbeans/config/ src/main/java/org/apache/webbeans/ejb/ src/main/java/org/apache/webbeans/inject/ src/main/java/org/apache/webbeans/jsf/ src/main/java/org...

Author: struberg
Date: Sun Apr 19 22:31:25 2009
New Revision: 766539

URL: http://svn.apache.org/viewvc?rev=766539&view=rev
Log:
OWB-88 OWB-91 creating plugin mechanism and moving out JSF and JPA into own modules

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
Removed:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/jsf/
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/JPAService.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/jsf/
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/se/JPAServicePersistenceImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/se/jpa/
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JSFUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/resource/
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/mock/MockEntityManager.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/resource/
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/pom.xml
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/ejb/EJBUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/WebBeansLifeCycle.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/ConversationService.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans-default.properties
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/disposal/Disposal1.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java
    incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java

Modified: incubator/openwebbeans/trunk/webbeans-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/pom.xml?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/pom.xml (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/pom.xml Sun Apr 19 22:31:25 2009
@@ -55,10 +55,6 @@
             <scope>provided</scope>
 		</dependency>
 		<dependency>
-		    <groupId>org.apache.myfaces.core</groupId>
-		    <artifactId>myfaces-api</artifactId>
-		</dependency>
-		<dependency>
 			<groupId>javassist</groupId>
 			<artifactId>javassist</artifactId>
 		</dependency>
@@ -73,10 +69,6 @@
 		</dependency>
 		<dependency>
 		    <groupId>org.apache.geronimo.specs</groupId>
-		    <artifactId>geronimo-jpa_3.0_spec</artifactId>
-		</dependency>
-		<dependency>
-		    <groupId>org.apache.geronimo.specs</groupId>
 		    <artifactId>geronimo-interceptor_3.0_spec</artifactId>
 		</dependency>
 		<dependency>
@@ -98,18 +90,6 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>      
-        <dependency>
-            <groupId>org.apache.openjpa</groupId>
-            <artifactId>openjpa</artifactId>
-            <version>1.2.0</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>hsqldb</groupId>
-            <artifactId>hsqldb</artifactId>
-            <version>1.8.0.7</version>
-            <scope>test</scope>
-        </dependency>
 	</dependencies>
 
     <build>

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansFinder.java Sun Apr 19 22:31:25 2009
@@ -82,6 +82,10 @@
             if (object == null)
             {
                 Class<?> clazz = ClassUtil.getClassFromName(singletonName);
+                if (clazz == null)
+                {
+                    throw new WebBeansException("Cannot find class : " + singletonName);
+                }
                 try
                 {
                     object = clazz.newInstance();
@@ -91,7 +95,6 @@
                 catch (InstantiationException e)
                 {
                     throw new WebBeansException("Unable to instantiate class : " + singletonName, e);
-
                 }
                 catch (IllegalAccessException e)
                 {

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/ejb/EJBUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/ejb/EJBUtil.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/ejb/EJBUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/ejb/EJBUtil.java Sun Apr 19 22:31:25 2009
@@ -16,7 +16,6 @@
 import javax.ejb.MessageDriven;
 import javax.ejb.Stateful;
 import javax.ejb.Stateless;
-import javax.persistence.Entity;
 
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
@@ -69,12 +68,6 @@
         return (AnnotationUtil.isAnnotationExistOnClass(clazz, Stateless.class));
     }    
     
-    public static boolean isEJBEntityBean(Class<?> clazz)
-    {
-        return (AnnotationUtil.isAnnotationExistOnClass(clazz, Entity.class));
-    }        
-    
-
     /**
      * Check the given class is an EJB is MDB class or not.
      * <p>

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Sun Apr 19 22:31:25 2009
@@ -17,6 +17,7 @@
 import java.lang.reflect.Member;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.util.List;
 
 import javax.context.CreationalContext;
 import javax.context.Dependent;
@@ -25,17 +26,14 @@
 import javax.inject.manager.Bean;
 import javax.inject.manager.InjectionPoint;
 
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
-
 import org.apache.webbeans.component.AbstractComponent;
 import org.apache.webbeans.container.InjectionResolver;
 import org.apache.webbeans.container.ManagerImpl;
 import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.inject.impl.InjectionPointFactory;
-import org.apache.webbeans.spi.JPAService;
-import org.apache.webbeans.spi.ServiceLoader;
+import org.apache.webbeans.plugins.OpenWebBeansPlugin;
+import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.WebBeansUtil;
@@ -89,7 +87,6 @@
         {
             if (isResource(this.injectionAnnotations))
             {
-                //X TODO do we need the args too?
                 return injectResource(type, this.injectionAnnotations);
             }
                         
@@ -136,7 +133,7 @@
      */
     protected boolean isResource(Annotation... annotations)
     {
-        return AnnotationUtil.hasResourceAnnotation(annotations);
+        return AnnotationUtil.hasResourceAnnotation(annotations); 
     }
 
     private boolean isObservableBinding(Annotation... annotations)
@@ -153,8 +150,8 @@
     }
     
     /**
-     * create the instance for injecting web beans resources.
-     * @see AnnotationUtil#isResourceAnnotation(Class)
+     * If the annotation is a resource annotation, we create 
+     * the instance for injecting web beans resources.
      * @param type the class type which should be created
      * @param annotations which has been defined in the web bean
      * @return the instance linked with the annotation
@@ -162,29 +159,17 @@
      */
     private Object injectResource(Type type, Annotation... annotations)
     {
-        Object ret = null;
-        Annotation annot = AnnotationUtil.getAnnotation(annotations, PersistenceUnit.class);
-        if (annot != null)
+        List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
+        for (OpenWebBeansPlugin plugin : plugins)
         {
-            PersistenceUnit pu = (PersistenceUnit) annot;
-            String unitName = pu.unitName();
-            
-            //X TODO what if the EntityManagerFactory is null?
-            return getJPAService().getPersistenceUnit(unitName);
+            Object toInject = plugin.injectResource(type, annotations);
+            if (toInject != null)
+            {
+                return toInject;
+            }
         }
         
-        annot = AnnotationUtil.getAnnotation(annotations, PersistenceContext.class);
-        if (annot != null)
-        {
-            PersistenceContext pc = (PersistenceContext) annot;
-            String unitName = pc.unitName();
-            String name = pc.name();
-            
-            //X TODO what if the EntityManager is null?
-            return getJPAService().getPersistenceContext(unitName, name);
-        }
-
-        return ret;
+        return null;
     }
     
     private Object injectForObservable(Type[] args, Annotation... annotations)
@@ -227,8 +212,4 @@
         return injectionOwnerComponent;
     }
 
-    protected JPAService getJPAService()
-    {
-        return ServiceLoader.getService(JPAService.class);
-    }
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/WebBeansLifeCycle.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/WebBeansLifeCycle.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/WebBeansLifeCycle.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/lifecycle/WebBeansLifeCycle.java Sun Apr 19 22:31:25 2009
@@ -37,6 +37,7 @@
 import org.apache.webbeans.el.WebBeansELResolver;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
+import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.spi.JNDIService;
 import org.apache.webbeans.spi.ServiceLoader;
 import org.apache.webbeans.spi.deployer.MetaDataDiscoveryService;
@@ -101,7 +102,10 @@
     {
         this.discovery = ServiceLoader.getService(MetaDataDiscoveryService.class);
         this.discovery.init(event.getServletContext());
-        
+
+        // load all optional plugins
+        PluginLoader.getInstance().startUp();
+
         // I do not know this is the correct way, spec is not so explicit.
         service = Executors.newScheduledThreadPool(1);
         service.scheduleWithFixedDelay(new Runnable()
@@ -176,6 +180,9 @@
         
         WebBeansFinder.clearInstances();
 
+        // finally free all plugin resources
+        PluginLoader.getInstance().shutDown();
+
     }
 
 }
\ No newline at end of file

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java?rev=766539&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/OpenWebBeansPlugin.java Sun Apr 19 22:31:25 2009
@@ -0,0 +1,92 @@
+package org.apache.webbeans.plugins;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.util.AnnotationUtil;
+
+/**
+ * <p>Interface which all OpenWebBeans plugins has to implement to 
+ * extend the webbeans-core with additional IOC functionality.</p>
+ * 
+ * <p>There are 4 different types of functions for this interface:
+ * <ol>
+ *  <li>
+ *    plugin lifecycle like {@code #startUp()} and {@code #shutDown()}
+ *  </li>
+ *  <li>
+ *    check functions which will be called when a class is scanned
+ *    like {@code #isSimpleBeanClass(Class)}
+ *  </li>
+ *  <li>
+ *    injection preparation functions will be called once when
+ *    the bean is being scanned like TODO
+ *  </li>
+ *  <li>
+ *    injection execution will be called every time a been get's
+ *    injected like {@code #injectResource(Type, Annotation[])}
+ *  </li>
+ * </ol> 
+ * @see PluginLoader for documentation of the whole mechanism
+ */
+public interface OpenWebBeansPlugin
+{
+    /**
+     * initialise the plugin.
+     * This is called once after the very plugin has been loaded.
+     * @throws WebBeansConfigurationException
+     */
+    public void startUp() throws WebBeansConfigurationException;
+
+    /**
+     * At shutdown, the plugin must release all locked resources.
+     * This is called once before the very plugin gets destroyed.
+     * This is usually the case when the WebApplication gets stopped.
+     * @throws WebBeansConfigurationException
+     */
+    public void shutDown() throws WebBeansConfigurationException;
+    
+
+    /**
+     * Make sure that the given class is ok for simple web bean conditions, 
+     * otherwise throw a {@code WebBeansConfigurationException}
+     * @param clazz the class to check
+     * @throws WebBeansConfigurationException if the given clazz cannot be used as simple web bean.
+     */
+    public void isSimpleBeanClass(Class<?> clazz) throws WebBeansConfigurationException;
+
+    /**
+     * Check whether the given annotation class represents a resource which
+     * can be injected by this plugin.
+     * @param annotationClass which should be ckecked
+     * @return <code>true</code> if this plugin handles the resource represented by this annotation
+     */
+    public boolean isResourceAnnotation(Class<? extends Annotation> annotationClass);
+
+    /**
+     * Check conditions for the resources.
+     * 
+     * @param type
+     * @param clazz
+     * @param name
+     * @param annotations annotations
+     * @throws WebBeansConfigurationException if resource annotations exists and do not fit to the fields type, etc.
+     * @see #isResourceAnnotation(Class)
+     */
+    
+    public void checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations);
+    
+    /**
+     * Get a resource to inject.
+     * A resource is not a usual bean but one predefined one like 
+     * javax.persistence.PersistenceUnit, javax.persistence.PersistenceContext
+     * etc.
+     * @param type the bean type
+     * @param annotations all the annotations which are defined on the member. 
+     * @return the bean to inject or <code>null</code> if non found.  
+     */
+    public Object injectResource(Type type, Annotation[] annotations);
+
+
+}

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java?rev=766539&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/plugins/PluginLoader.java Sun Apr 19 22:31:25 2009
@@ -0,0 +1,110 @@
+package org.apache.webbeans.plugins;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ServiceLoader;
+
+import org.apache.webbeans.config.WebBeansFinder;
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.logger.WebBeansLogger;
+
+/**
+ * <p>OpenWebBeans plugins are used to extend 'core' functionality of the injection
+ * mechanism with functionality of other frameworks.</p>
+ * 
+ * <p>Core functionality are all parts which are available in a standard
+ * JDK-1.5 SE runtime. Extended functionality are things like JPA, JSF, EJB etc.</p>
+ * 
+ * <p>The plugin mechanism is based on the ServiceProvider functionality 
+ * {@link http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider}.
+ * A jar containing an OWB plugin has to expose itself in the file
+ * <code>META-INF/services/org.apache.webbeans.plugins.OpenWebBeansPlugin</code></p> 
+ *
+ * TODO: what about ordering the plugins via an ordinal?
+ */
+public class PluginLoader
+{
+    /**Logger instance*/
+    private static WebBeansLogger logger = WebBeansLogger.getLogger(PluginLoader.class);
+
+    /** unmodifiable list with all found OWB plugins */
+    private List<OpenWebBeansPlugin> plugins = null;
+
+    /**
+     * @return singleton PluginLoader 
+     */
+    public static PluginLoader getInstance()
+    {
+        return (PluginLoader) WebBeansFinder.getSingletonInstance(PluginLoader.class.getName());
+    }
+    
+    public PluginLoader()
+    {
+    }
+
+    /**
+     * load and startup all registered plugins.
+     * This must be called once the WebApplication is started.
+     * @throws WebBeansConfigurationException
+     */
+    public void startUp() throws WebBeansConfigurationException
+    {
+        logger.debug("PluginLoader startUp called");
+        ArrayList<OpenWebBeansPlugin> ps = new ArrayList<OpenWebBeansPlugin>();
+
+        ServiceLoader<OpenWebBeansPlugin> owbPluginsLoader = ServiceLoader.load(OpenWebBeansPlugin.class);
+        Iterator<OpenWebBeansPlugin> pluginIter = owbPluginsLoader.iterator();
+        while(pluginIter.hasNext()) 
+        {
+          OpenWebBeansPlugin plugin = pluginIter.next();
+          logger.info("adding OpenWebBeansPlugin " + plugin.getClass().getSimpleName());
+          ps.add(plugin);
+        }   
+        
+        // just to make sure the plugins aren't modified afterwards
+        plugins = Collections.unmodifiableList(ps);
+    }
+    
+    /**
+     * Tell all the plugins to free up all locked resources.
+     * This must be called before the WebApplication gets undeployed or stopped.
+     * @throws WebBeansConfigurationException
+     */
+    public void shutDown() throws WebBeansConfigurationException
+    {
+        logger.debug("PluginLoader shutDown called");
+        ArrayList<String> failedShutdown = new ArrayList<String>();
+        
+        for (OpenWebBeansPlugin plugin : plugins)
+        {
+            try 
+            {
+                plugin.shutDown();
+            }
+            catch (Exception e)
+            {
+                // we catch ALL exceptions, since we like to continue shutting down all other plugins!
+                String pluginName = plugin.getClass().getSimpleName();
+                logger.error("error while shutdown the pugin " + pluginName, e);
+                failedShutdown.add(pluginName);
+            }
+        }
+        
+        if (!failedShutdown.isEmpty())
+        {
+            throw new WebBeansConfigurationException("got Exceptions while sending shutdown to the following plugins: "
+                                                     + failedShutdown.toString());
+        }
+    }
+    
+    /**
+     * @return an unmodifiable list of all registered {code OpenWebBeansPlugin}s
+     */
+    public List<OpenWebBeansPlugin> getPlugins()
+    {
+        return plugins;
+    }
+    
+}

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/ConversationService.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/ConversationService.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/ConversationService.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/spi/conversation/ConversationService.java Sun Apr 19 22:31:25 2009
@@ -16,8 +16,6 @@
  */
 package org.apache.webbeans.spi.conversation;
 
-import org.apache.webbeans.util.JSFUtil;
-
 /**
  * Defines the SPI for the conversation management.
  * @version $Rev$ $Date$

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/AnnotationUtil.java Sun Apr 19 22:31:25 2009
@@ -27,8 +27,6 @@
 
 import javax.annotation.Resource;
 import javax.ejb.EJB;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceUnit;
 import javax.xml.ws.WebServiceRef;
 
 import javax.annotation.NonBinding;
@@ -39,6 +37,8 @@
 import javax.interceptor.InterceptorBindingType;
 
 import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.plugins.OpenWebBeansPlugin;
+import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.xml.XMLAnnotationTypeManager;
 
 /**
@@ -764,7 +764,7 @@
             {
                 return true;
             }
-        }
+        }        
         
         return false;
     }
@@ -800,14 +800,21 @@
             return true;
         }
         else if (clazz.equals(Resource.class) ||
-                 clazz.equals(PersistenceContext.class) ||
-                 clazz.equals(PersistenceUnit.class) ||
                  clazz.equals(EJB.class) ||
                  clazz.equals(WebServiceRef.class) )
         {
             return true;
         }
 
+        List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
+        for (OpenWebBeansPlugin plugin : plugins)
+        {
+            if (plugin.isResourceAnnotation(clazz))
+            {
+                return true;
+            }
+        }
+
         return false;
     }
 

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Sun Apr 19 22:31:25 2009
@@ -48,7 +48,6 @@
 import javax.ejb.EnterpriseBean;
 import javax.event.Fires;
 import javax.event.Observes;
-import javax.faces.component.UIComponent;
 import javax.inject.DefinitionException;
 import javax.inject.DeploymentType;
 import javax.inject.Disposes;
@@ -68,12 +67,6 @@
 import javax.inject.manager.Manager;
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.InvocationContext;
-import javax.persistence.Entity;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceContext;
-import javax.persistence.PersistenceContextType;
-import javax.persistence.PersistenceUnit;
 import javax.servlet.Filter;
 import javax.servlet.Servlet;
 import javax.servlet.ServletContextListener;
@@ -120,6 +113,8 @@
 import org.apache.webbeans.intercept.InterceptorsManager;
 import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+import org.apache.webbeans.plugins.OpenWebBeansPlugin;
+import org.apache.webbeans.plugins.PluginLoader;
 
 /**
  * Contains some utility methods used in the all project.
@@ -167,70 +162,63 @@
     }
 
     /**
-     * Return true if the given class is ok for simple web bean conditions,
-     * falase otherwise.
+     * Return <code>true</code> if the given class is ok for simple web bean conditions,
+     * <code>false</code> otherwise.
      * 
      * @param clazz class in hand
-     * @return true if the given class is ok for simple web bean conditions.
+     * @return <code>true</code> if the given class is ok for simple web bean conditions.
      */
     public static void isSimpleWebBeanClass(Class<?> clazz)
     {
-        try
-        {
-            Asserts.nullCheckForClass(clazz);
-            int modifier = clazz.getModifiers();
-
-            if (ClassUtil.isParametrized(clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be parametrized type");
-
-            if (!ClassUtil.isStatic(modifier) && ClassUtil.isInnerClazz(clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be non-static inner class");
+        Asserts.nullCheckForClass(clazz);
+        int modifier = clazz.getModifiers();
 
-            if (!ClassUtil.isConcrete(clazz) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " have to be concrete if not defines as @Decorator");
+        if (ClassUtil.isParametrized(clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be parametrized type");
 
-            if (AnnotationUtil.isAnnotationExistOnClass(clazz, Entity.class))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be JPA Entity class");
+        if (!ClassUtil.isStatic(modifier) && ClassUtil.isInnerClazz(clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be non-static inner class");
 
-            if (EJBUtil.isEJBClass(clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be EJB class");
+        if (!ClassUtil.isConcrete(clazz) && !AnnotationUtil.isAnnotationExistOnClass(clazz, Decorator.class))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " have to be concrete if not defines as @Decorator");
 
-            if (ClassUtil.isAssignable(Servlet.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement Servlet interface");
+        if (EJBUtil.isEJBClass(clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not be EJB class");
 
-            if (ClassUtil.isAssignable(Filter.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement Filter interface");
+        if (ClassUtil.isAssignable(Servlet.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement Servlet interface");
 
-            if (ClassUtil.isAssignable(ServletContextListener.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement ServletContextListener");
+        if (ClassUtil.isAssignable(Filter.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement Filter interface");
 
-            if (ClassUtil.isAssignable(HttpSessionListener.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement HttpSessionListener");
+        if (ClassUtil.isAssignable(ServletContextListener.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement ServletContextListener");
 
-            if (ClassUtil.isAssignable(ServletRequestListener.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can notimplement ServletRequestListener");
+        if (ClassUtil.isAssignable(HttpSessionListener.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement HttpSessionListener");
 
-            if (ClassUtil.isAssignable(EnterpriseBean.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement EnterpriseBean");
+        if (ClassUtil.isAssignable(ServletRequestListener.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can notimplement ServletRequestListener");
 
-            if (ClassUtil.isAssignable(UIComponent.class, clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement JSF UIComponent");
+        if (ClassUtil.isAssignable(EnterpriseBean.class, clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not implement EnterpriseBean");
 
-            // TODO ejb-jar.xml check
-            if (EJBUtil.isDefinedInXML(clazz.getName()))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not defined in the ejb-jar.xml");
+        // TODO ejb-jar.xml check
+        if (EJBUtil.isDefinedInXML(clazz.getName()))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not defined in the ejb-jar.xml");
 
-            // TODO orm.xml check
-            if (ORMUtil.isDefinedInXML(clazz.getName()))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not defined in orm.xml");
+        // TODO orm.xml check
+        if (ORMUtil.isDefinedInXML(clazz.getName()))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " can not defined in orm.xml");
 
-            if (!isConstructureOk(clazz))
-                throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " must define at least one Constructor");
+        if (!isConstructureOk(clazz))
+            throw new WebBeansConfigurationException("Web Beans component implementation class : " + clazz.getName() + " must define at least one Constructor");
 
-        }
-        catch (WebBeansConfigurationException e)
+        // and finally call all checks which are defined in plugins like JSF, JPA, etc
+        List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
+        for (OpenWebBeansPlugin plugin : plugins)
         {
-            throw e;
+            plugin.isSimpleBeanClass(clazz);
         }
     }
 
@@ -444,49 +432,20 @@
      * Check conditions for the resources.
      * 
      * @param annotations annotations
-     * @return Annotation[] with all binding annotations
      * @throws WebBeansConfigurationException if resource annotations exists and do not fit to the fields type, etc.
      * @see AnnotationUtil#isResourceAnnotation(Class)
      */
-    public static Annotation[] checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations)
+    public static void checkForValidResources(Type type, Class<?> clazz, String name, Annotation[] annotations)
     {
         Asserts.assertNotNull(type, "Type argument can not be null");
         Asserts.assertNotNull(clazz, "Clazz argument can not be null");
         Asserts.assertNotNull(annotations, "Annotations argument can not be null");
 
-        Annotation[] as = AnnotationUtil.getResourceAnnotations(annotations);
-        for (Annotation a : annotations)
+        List<OpenWebBeansPlugin> plugins = PluginLoader.getInstance().getPlugins();
+        for (OpenWebBeansPlugin plugin : plugins)
         {
-            if (a.annotationType().equals(PersistenceUnit.class))
-            {
-                if (!type.equals(EntityManagerFactory.class))
-                {
-                    throw new WebBeansConfigurationException("@PersistenceUnit must only be injected into field/method with type EntityManagerFactory! class : "  
-                                                             + clazz.getName() + " in field/method : " + name);
-                }
-            }
-            
-            if (a.annotationType().equals(PersistenceContext.class))
-            {
-                PersistenceContext pc = (PersistenceContext) a;
-                
-                if (!type.equals(EntityManager.class))
-                {
-                    throw new WebBeansConfigurationException("@PersistenceContext must only be injected into field/method with type EntityManager! class : "  
-                                                             + clazz.getName() + " in field/method : " + name);
-                }
-             
-                if (pc.type().equals(PersistenceContextType.EXTENDED))
-                {
-                    throw new WebBeansConfigurationException("type of @PersistenceContext must not be 'EXTENDED'! class : "  
-                            + clazz.getName() + " in field/method : " + name);
-                    
-                }
-            }
+            plugin.checkForValidResources(type, clazz, name, annotations);
         }
-                
-        //X TODO add checks for other resources
-        return as;
     }
     
     /**

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans-default.properties
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans-default.properties?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans-default.properties (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans-default.properties Sun Apr 19 22:31:25 2009
@@ -19,7 +19,7 @@
 org.apache.webbeans.spi.TransactionService=org.apache.webbeans.spi.ee.TransactionServiceJndiImpl
 
 # use the JPAService which retrieves the PersistenceManagerFactory from the Persistence class as default 
-org.apache.webbeans.spi.JPAService=org.apache.webbeans.spi.se.JPAServicePersistenceImpl
+org.apache.webbeans.jpa.spi.JPAService=org.apache.webbeans.jpa.spi.se.JPAServicePersistenceImpl
 
 #use the web metadata as default
 org.apache.webbeans.spi.deployer.MetaDataDiscoveryService=org.apache.webbeans.spi.ee.deployer.WarMetaDataDiscoveryImpl

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/disposal/Disposal1.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/disposal/Disposal1.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/disposal/Disposal1.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/component/disposal/Disposal1.java Sun Apr 19 22:31:25 2009
@@ -13,17 +13,18 @@
  */
 package org.apache.webbeans.test.component.disposal;
 
+import java.util.List;
 import java.io.Serializable;
+import java.util.ArrayList;
 
 import javax.annotation.Named;
 import javax.context.RequestScoped;
 import javax.context.SessionScoped;
 import javax.inject.Disposes;
 import javax.inject.Produces;
-import javax.persistence.EntityManager;
 
 import org.apache.webbeans.test.annotation.binding.Binding1;
-import org.apache.webbeans.test.mock.MockEntityManager;
+
 
 @SessionScoped
 public class Disposal1 implements Serializable
@@ -39,14 +40,16 @@
     @Binding1
     @Named
     @RequestScoped
-    public EntityManager createEntityManager()
+    public List<Integer> createBinding1()
     {
-        return new MockEntityManager();
+        List<Integer> lst = new ArrayList<Integer>();
+        lst.add(new Integer(42));
+        return lst;
     }
 
-    public void dispose(@Disposes @Binding1 EntityManager em)
+    public void dispose(@Disposes @Binding1 List<Integer> list)
     {
         disposeCall = true;
-        em.close();
+        list.clear();
     }
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/servlet/TestContext.java Sun Apr 19 22:31:25 2009
@@ -52,6 +52,7 @@
 import org.apache.webbeans.intercept.InterceptorUtil;
 import org.apache.webbeans.intercept.InterceptorsManager;
 import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
+import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeIsnotInterface;
 import org.apache.webbeans.test.component.decorator.broken.DelegateAttributeMustImplementAllDecoratedTypes;
 import org.apache.webbeans.test.component.decorator.broken.MoreThanOneDelegateAttribute;
@@ -132,6 +133,8 @@
             initStereoTypes();
             initDependentContext();
 
+            PluginLoader.getInstance().startUp();
+            
             init = true;
         }
     }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java?rev=766539&r1=766538&r2=766539&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/disposal/DisposalTest.java Sun Apr 19 22:31:25 2009
@@ -13,7 +13,7 @@
  */
 package org.apache.webbeans.test.unittests.disposal;
 
-import javax.persistence.EntityManager;
+import java.util.List;
 
 import org.apache.webbeans.context.ContextFactory;
 import org.apache.webbeans.test.component.disposal.Disposal1;
@@ -47,10 +47,10 @@
 
         defineSimpleWebBean(Disposal1.class);
 
-        EntityManager em = (EntityManager) getManager().getInstanceByName("createEntityManager");
-        em.clear();
-        Assert.assertNotNull(em);
-
+        @SuppressWarnings("unchecked")
+        List<Integer> list = (List<Integer>) getManager().getInstanceByName("createBinding1");
+        Assert.assertNotNull(list);
+        Assert.assertTrue(list.size() == 1);
         ContextFactory.destroyRequestContext(null);
 
         Assert.assertTrue(Disposal1.disposeCall);