[webbeans-commits] Webbeans SVN: r2902 - ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard and 6 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Jun 26 13:03:09 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-06-26 13:03:09 -0400 (Fri, 26 Jun 2009)
New Revision: 2902

Added:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/ExtensionBean.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/
   ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/ServiceLoader.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/BeforeBeanDiscoveryObserver.java
   tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/deployment/lifecycle/javax.enterprise.inject.spi.Extension
Removed:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
Modified:
   ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java
   ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverFactory.java
   tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/ExtensionsTest.java
Log:
Start on container lifecycle events

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/Validator.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -40,9 +40,11 @@
 
 import org.jboss.webbeans.bean.AbstractClassBean;
 import org.jboss.webbeans.bean.DecoratorBean;
+import org.jboss.webbeans.bean.DisposalMethodBean;
 import org.jboss.webbeans.bean.NewEnterpriseBean;
 import org.jboss.webbeans.bean.NewSimpleBean;
 import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bootstrap.BeanDeployerEnvironment;
 import org.jboss.webbeans.bootstrap.api.Service;
 import org.jboss.webbeans.injection.resolution.ResolvableWBClass;
 import org.jboss.webbeans.introspector.WBAnnotated;
@@ -170,7 +172,7 @@
       }
    }
    
-   public void validateDeployment(BeanManagerImpl manager)
+   public void validateDeployment(BeanManagerImpl manager, BeanDeployerEnvironment environment)
    {
       List<RIBean<?>> specializedBeans = new ArrayList<RIBean<?>>();
       for (Bean<?> bean : manager.getBeans())
@@ -185,6 +187,7 @@
          }
       }
       validateEnabledDecoratorClasses(manager);
+      validateDisposalMethods(environment);
       
    }
    
@@ -204,6 +207,23 @@
          }
       }
    }
+   
+   private void validateDisposalMethods(BeanDeployerEnvironment environment)
+   {
+      Set<DisposalMethodBean<?>> all = new HashSet<DisposalMethodBean<?>>(environment.getAllDisposalBeans());
+      Set<DisposalMethodBean<?>> resolved = new HashSet<DisposalMethodBean<?>>(environment.getResolvedDisposalBeans());
+      if (all.size() > 0 && !resolved.containsAll(all))
+      {
+         StringBuffer buff = new StringBuffer();
+         buff.append("The following Disposal methods where not resolved\n");
+         all.removeAll(resolved);
+         for (DisposalMethodBean<?> bean : all)
+         {
+            buff.append(bean.toString());
+         }
+         throw new UnsatisfiedResolutionException(buff.toString());
+      }
+   }   
 
    private static boolean hasHigherPrecedence(Class<? extends Annotation> deploymentType, Class<? extends Annotation> otherDeploymentType, BeanManagerImpl manager)
    {

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/ExtensionBean.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/ExtensionBean.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/ExtensionBean.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bean.standard;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.introspector.WBClass;
+
+/**
+ * @author pmuir
+ *
+ */
+public class ExtensionBean extends AbstractStandardBean<Extension>
+{
+   
+   private final WBClass<Extension> clazz;
+   private final Extension instance;
+   
+   public static ExtensionBean of(BeanManagerImpl manager, WBClass<Extension> clazz, Extension instance)
+   {
+      return new ExtensionBean(manager, clazz, instance);
+   }
+   
+   protected ExtensionBean(BeanManagerImpl manager, WBClass<Extension> clazz, Extension instance)
+   {
+      super(manager);
+      this.clazz = clazz;
+      this.instance = instance;
+   }
+
+   @Override
+   public Class<Extension> getType()
+   {
+      return clazz.getJavaClass();
+   }
+
+   public Set<Type> getTypes()
+   {
+      return clazz.getTypeClosure();
+   }
+   
+   @Override
+   public boolean isProxyable()
+   {
+      return clazz.isProxyable();
+   }
+
+   public Extension create(CreationalContext<Extension> creationalContext)
+   {
+      return instance;
+   }
+
+   public void destroy(Extension instance, CreationalContext<Extension> creationalContext)
+   {
+      // No-op
+   }
+   
+   @Override
+   public Class<? extends Annotation> getScopeType()
+   {
+      return ApplicationScoped.class;
+   }
+
+}


Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bean/standard/ExtensionBean.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Copied: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java (from rev 2896, ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java)
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,334 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.BindingType;
+import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Initializer;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.deployment.DeploymentType;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.Realizes;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.DecoratorBean;
+import org.jboss.webbeans.bean.DisposalMethodBean;
+import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.bean.NewEnterpriseBean;
+import org.jboss.webbeans.bean.NewSimpleBean;
+import org.jboss.webbeans.bean.ProducerFieldBean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.ejb.EJBApiAbstraction;
+import org.jboss.webbeans.event.ObserverFactory;
+import org.jboss.webbeans.event.ObserverImpl;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.WBField;
+import org.jboss.webbeans.introspector.WBMethod;
+import org.jboss.webbeans.introspector.WrappedWBField;
+import org.jboss.webbeans.introspector.WrappedWBMethod;
+import org.jboss.webbeans.jsf.JsfApiAbstraction;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.servlet.ServletApiAbstraction;
+import org.jboss.webbeans.util.Reflections;
+
+public class AbstractBeanDeployer
+{
+   
+   private static final LogProvider log = Logging.getLogProvider(AbstractBeanDeployer.class);
+   
+   private final BeanManagerImpl manager;
+   private final BeanDeployerEnvironment environment;
+   
+   public AbstractBeanDeployer(BeanManagerImpl manager, BeanDeployerEnvironment environment)
+   {
+      this.manager = manager;
+      this.environment = environment;
+   }
+   
+   protected BeanManagerImpl getManager()
+   {
+      return manager;
+   }
+   
+   public <T> AbstractBeanDeployer addBean(RIBean<T> bean)
+   {
+      this.environment.addBean(bean);
+      return this;
+   }
+   
+   public AbstractBeanDeployer deploy()
+   {
+      Set<RIBean<?>> beans = environment.getBeans();
+      // ensure that all disposal methods are initialized before initializing 
+      // the rest of the beans
+      for (DecoratorBean<?> bean : environment.getDecorators())
+      {
+         bean.initialize(environment);
+         manager.addRIBean(bean);
+         log.debug("Bean: " + bean);
+      }
+      for (RIBean<?> bean : beans)
+      {
+         bean.initialize(environment);
+         manager.addRIBean(bean);
+         log.debug("Bean: " + bean);
+      }
+      for (ObserverImpl<?> observer : environment.getObservers())
+      {
+         observer.initialize();
+         log.debug("Observer : " + observer);
+         manager.addObserver(observer);
+      }
+      
+      return this;
+   }
+
+   /**
+    * Creates the sub bean for an class (simple or enterprise) bean
+    * 
+    * @param bean
+    *           The class bean
+    * 
+    */
+   protected <T> void createSubBeans(AbstractClassBean<T> bean)
+   {
+      // TODO I don't think this is needed due to validation
+      manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
+      
+      createProducerMethods(bean, bean.getAnnotatedItem());
+      createProducerFields(bean, bean.getAnnotatedItem());
+      createObserverMethods(bean, bean.getAnnotatedItem());
+      createDisposalMethods(bean, bean.getAnnotatedItem());
+      
+      if (bean.getAnnotatedItem().isAnnotationPresent(Realizes.class))
+      {
+         createRealizedProducerMethods(bean, bean.getAnnotatedItem());
+         createRealizedProducerFields(bean, bean.getAnnotatedItem());
+         createRealizedObserverMethods(bean, bean.getAnnotatedItem());
+      }
+      
+   }
+   
+   protected void createProducerMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
+   {
+      for (WBMethod<?> method : annotatedClass.getDeclaredAnnotatedMethods(Produces.class))
+      {
+         createProducerMethod(declaringBean, method);         
+      }
+   }
+   
+   protected void createDisposalMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
+   {
+      for (WBMethod<?> method : annotatedClass.getDeclaredMethodsWithAnnotatedParameters(Disposes.class))
+      {
+         DisposalMethodBean<?> disposalBean = DisposalMethodBean.of(manager, method, declaringBean);
+         environment.addDisposalBean(disposalBean);
+      }
+   }
+   
+   protected <T> void createProducerMethod(AbstractClassBean<?> declaringBean, WBMethod<T> annotatedMethod)
+   {
+      ProducerMethodBean<T> bean = ProducerMethodBean.of(annotatedMethod, declaringBean, manager);
+      addBean(bean);
+      manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
+   }
+   
+   protected void createRealizedProducerMethods(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
+   {
+      WBClass<?> realizedClass = realizingClass.getSuperclass();
+      for (WBMethod<?> realizedMethod : realizedClass.getDeclaredAnnotatedMethods(Produces.class))
+      {
+         createProducerMethod(declaringBean, realizeProducerMethod(realizedMethod, realizingClass));
+      }
+   }
+   
+   protected void createRealizedProducerFields(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
+   {
+      WBClass<?> realizedClass = realizingClass.getSuperclass();
+      for (final WBField<?> realizedField : realizedClass.getDeclaredAnnotatedFields(Produces.class))
+      {
+         createProducerField(declaringBean, realizeProducerField(realizedField, realizingClass));
+      }
+   }
+   
+   protected <T> void createProducerField(AbstractClassBean<?> declaringBean, WBField<T> field)
+   {
+      ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean, manager);
+      addBean(bean);
+   }
+   
+   protected void createProducerFields(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
+   {
+      for (WBField<?> field : annotatedClass.getDeclaredAnnotatedFields(Produces.class))
+      {
+         createProducerField(declaringBean, field);
+      }
+   }
+   
+   protected void createObserverMethods(RIBean<?> declaringBean, WBClass<?> annotatedClass)
+   {
+      for (WBMethod<?> method : annotatedClass.getDeclaredMethodsWithAnnotatedParameters(Observes.class))
+      {
+         createObserverMethod(declaringBean, method);
+      }
+   }
+   
+   protected void createRealizedObserverMethods(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
+   {
+      createObserverMethods(declaringBean, realizingClass.getSuperclass());
+   }
+   
+   protected void createObserverMethod(RIBean<?> declaringBean, WBMethod<?> method)
+   {
+      ObserverImpl<?> observer = ObserverFactory.create(method, declaringBean, manager);
+      environment.getObservers().add(observer);
+   }
+   
+   protected <T> void createSimpleBean(WBClass<T> annotatedClass)
+   {
+      SimpleBean<T> bean = SimpleBean.of(annotatedClass, manager);
+      addBean(bean);
+      createSubBeans(bean);
+      addBean(NewSimpleBean.of(annotatedClass, manager));
+   }
+   
+   protected <T> void createDecorator(WBClass<T> annotatedClass)
+   {
+      DecoratorBean<T> bean = DecoratorBean.of(annotatedClass, manager);
+      addBean(bean);
+   }
+   
+   protected <T> void createEnterpriseBean(WBClass<T> annotatedClass)
+   {
+      // TODO Don't create enterprise bean if it has no local interfaces!
+      EnterpriseBean<T> bean = EnterpriseBean.of(annotatedClass, manager, environment);
+      addBean(bean);
+      createSubBeans(bean);
+      addBean(NewEnterpriseBean.of(annotatedClass, manager, environment));
+   }
+   
+   /**
+    * Indicates if the type is a simple Web Bean
+    * 
+    * @param type
+    *           The type to inspect
+    * @return True if simple Web Bean, false otherwise
+    */
+   protected boolean isTypeManagedBeanOrDecorator(WBClass<?> clazz)
+   {
+      Class<?> rawType = clazz.getJavaClass();
+      EJBApiAbstraction ejbApiAbstraction = manager.getServices().get(EJBApiAbstraction.class);
+      JsfApiAbstraction jsfApiAbstraction = manager.getServices().get(JsfApiAbstraction.class);
+      ServletApiAbstraction servletApiAbstraction = manager.getServices().get(ServletApiAbstraction.class);
+      return !clazz.isNonStaticMemberClass() &&
+             !Reflections.isParameterizedType(rawType) && 
+             !servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(rawType) && 
+             !servletApiAbstraction.FILTER_CLASS.isAssignableFrom(rawType) && 
+             !servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(rawType) && 
+             !servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(rawType) && 
+             !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(rawType) && 
+             !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(rawType) && 
+             !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(rawType) && 
+             hasSimpleWebBeanConstructor(clazz);
+   }
+   
+   private static boolean hasSimpleWebBeanConstructor(WBClass<?> type)
+   {
+      return type.getNoArgsConstructor() != null || type.getAnnotatedConstructors(Initializer.class).size() > 0;
+   }
+   
+   private static <T> WBMethod<T> realizeProducerMethod(final WBMethod<T> method, final WBClass<?> realizingClass)
+   {
+      return new WrappedWBMethod<T>(method, realizingClass.getMetaAnnotations(BindingType.class))
+      {
+         
+         @Override
+         public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
+         {
+            if (metaAnnotationType.equals(DeploymentType.class))
+            {
+               return realizingClass.getMetaAnnotations(DeploymentType.class);
+            }
+            else
+            {
+               return super.getMetaAnnotations(metaAnnotationType);
+            }
+         }
+         
+         @Override
+         public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
+         {
+            if (metaAnnotationType.equals(DeploymentType.class))
+            {
+               return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
+            }
+            else
+            {
+               return super.getDeclaredMetaAnnotations(metaAnnotationType);
+            }
+         }
+         
+      };
+   }
+   
+   private static <T> WBField<T> realizeProducerField(final WBField<T> field, final WBClass<?> realizingClass)
+   {
+      return new WrappedWBField<T>(field, realizingClass.getMetaAnnotations(BindingType.class))
+      {
+         
+         @Override
+         public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
+         {
+            if (metaAnnotationType.equals(DeploymentType.class))
+            {
+               return realizingClass.getMetaAnnotations(DeploymentType.class);
+            }
+            else
+            {
+               return super.getMetaAnnotations(metaAnnotationType);
+            }
+         }
+         
+         @Override
+         public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
+         {
+            if (metaAnnotationType.equals(DeploymentType.class))
+            {
+               return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
+            }
+            else
+            {
+               return super.getDeclaredMetaAnnotations(metaAnnotationType);
+            }
+         }
+         
+      };
+   }
+   
+   public BeanDeployerEnvironment getBeanDeployerEnvironment()
+   {
+      return environment;
+   }
+   
+}


Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/AbstractBeanDeployer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Deleted: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -1,416 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,  
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.jboss.webbeans.bootstrap;
-
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.decorator.Decorator;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.BindingType;
-import javax.enterprise.inject.Disposes;
-import javax.enterprise.inject.Initializer;
-import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.enterprise.inject.deployment.DeploymentType;
-
-import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.Realizes;
-import org.jboss.webbeans.bean.AbstractClassBean;
-import org.jboss.webbeans.bean.DecoratorBean;
-import org.jboss.webbeans.bean.DisposalMethodBean;
-import org.jboss.webbeans.bean.EnterpriseBean;
-import org.jboss.webbeans.bean.NewEnterpriseBean;
-import org.jboss.webbeans.bean.NewSimpleBean;
-import org.jboss.webbeans.bean.ProducerFieldBean;
-import org.jboss.webbeans.bean.ProducerMethodBean;
-import org.jboss.webbeans.bean.RIBean;
-import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.ejb.EJBApiAbstraction;
-import org.jboss.webbeans.ejb.EjbDescriptorCache;
-import org.jboss.webbeans.event.ObserverFactory;
-import org.jboss.webbeans.event.ObserverImpl;
-import org.jboss.webbeans.introspector.WBClass;
-import org.jboss.webbeans.introspector.WBField;
-import org.jboss.webbeans.introspector.WBMethod;
-import org.jboss.webbeans.introspector.WrappedWBField;
-import org.jboss.webbeans.introspector.WrappedWBMethod;
-import org.jboss.webbeans.jsf.JsfApiAbstraction;
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.resources.ClassTransformer;
-import org.jboss.webbeans.servlet.ServletApiAbstraction;
-import org.jboss.webbeans.util.Reflections;
-
-public class BeanDeployer
-{
-   
-   private static final LogProvider log = Logging.getLogProvider(BeanDeployer.class);
-   
-   private final BeanDeployerEnvironment environment;
-   private final Set<WBClass<?>> classes;
-   private final BeanManagerImpl manager;
-   private final ClassTransformer classTransformer;
-   
-   
-   public BeanDeployer(BeanManagerImpl manager, EjbDescriptorCache ejbDescriptors)
-   {
-      this.manager = manager;
-      this.environment = new BeanDeployerEnvironment(ejbDescriptors, manager);
-      this.classes = new HashSet<WBClass<?>>();
-      this.classTransformer = new ClassTransformer();
-   }
-   
-   public <T> BeanDeployer addBean(RIBean<T> bean)
-   {
-      this.environment.addBean(bean);
-      return this;
-   }
-   
-   public BeanDeployer addBeans(Iterable<? extends RIBean<?>> beans)
-   {
-      for (RIBean<?> bean : beans)
-      {
-         addBean(bean);
-      }
-      return this;
-   }
-   
-   public BeanDeployer addClass(Class<?> clazz)
-   {
-      if (!clazz.isAnnotation() && !clazz.isEnum())
-      {
-         classes.add(classTransformer.classForName(clazz));
-      }
-      return this;
-   }
-   
-   public BeanDeployer addClasses(Iterable<Class<?>> classes)
-   {
-      for (Class<?> clazz : classes)
-      {
-         addClass(clazz);
-      }
-      return this;
-   }
-   
-   public BeanDeployer addClasses(Collection<WBClass<?>> classes)
-   {
-      classes.addAll(classes);
-      return this;
-   }
-   
-   public BeanDeployer createBeans()
-   {
-      for (WBClass<?> clazz : classes)
-      {
-         if (environment.getEjbDescriptors().containsKey(clazz.getJavaClass()))
-         {
-            createEnterpriseBean(clazz);
-         }
-         else
-         {
-            boolean managedBeanOrDecorator = isTypeManagedBeanOrDecorator(clazz);
-            if (managedBeanOrDecorator && clazz.isAnnotationPresent(Decorator.class))
-            {
-               createDecorator(clazz);
-            }
-            else if (managedBeanOrDecorator && !clazz.isAbstract())
-            {
-               createSimpleBean(clazz);
-            }
-         }
-      }
-      return this;
-   }
-
-   public BeanDeployer deploy()
-   {
-      Set<RIBean<?>> beans = environment.getBeans();
-      // ensure that all disposal methods are initialized before initializing 
-      // the rest of the beans
-      for (DecoratorBean<?> bean : environment.getDecorators())
-      {
-         bean.initialize(environment);
-         manager.addRIBean(bean);
-         log.debug("Bean: " + bean);
-      }
-      for (RIBean<?> bean : beans)
-      {
-         bean.initialize(environment);
-         manager.addRIBean(bean);
-         log.debug("Bean: " + bean);
-      }
-      for (ObserverImpl<?> observer : environment.getObservers())
-      {
-         observer.initialize();
-         log.debug("Observer : " + observer);
-         manager.addObserver(observer);
-      }
-      
-      // TODO: move to boot
-      checkDisposalMethods();
-      
-      return this;
-   }
-
-   
-   private void checkDisposalMethods() {
-	      Set<DisposalMethodBean<?>> all = new HashSet<DisposalMethodBean<?>>(environment.getAllDisposalBeans()); 
-	      Set<DisposalMethodBean<?>> resolved = new HashSet<DisposalMethodBean<?>>(environment.getResolvedDisposalBeans());
-	      if(all.size()>0 && !resolved.containsAll(all)) {
-	         StringBuffer buff = new StringBuffer();
-	         buff.append("The following Disposal methods where not resolved\n");
-	         all.removeAll(resolved);
-	         for(DisposalMethodBean<?> bean: all) {
-	            buff.append(bean.toString());
-	         }
-	         throw new UnsatisfiedResolutionException(buff.toString());
-	      }
-	   }   
-   
-   public BeanDeployerEnvironment getBeanDeployerEnvironment()
-   {
-      return environment;
-   }
-   
-   /**
-    * Creates a Web Bean from a bean abstraction and adds it to the set of
-    * created beans
-    * 
-    * Also creates the implicit field- and method-level beans, if present
-    * 
-    * @param bean
-    *           The bean representation
-    */
-   protected <T> void createBean(AbstractClassBean<T> bean, final WBClass<T> annotatedClass)
-   {
-      
-      addBean(bean);
-      
-      manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
-      
-      createProducerMethods(bean, annotatedClass);
-      createProducerFields(bean, annotatedClass);
-      createObserverMethods(bean, annotatedClass);
-      createDisposalMethods(bean, annotatedClass);
-      
-      if (annotatedClass.isAnnotationPresent(Realizes.class))
-      {
-         createRealizedProducerMethods(bean, annotatedClass);
-         createRealizedProducerFields(bean, annotatedClass);
-         createRealizedObserverMethods(bean, annotatedClass);
-      }
-   }
-   
-   private void createProducerMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
-   {
-      for (WBMethod<?> method : annotatedClass.getDeclaredAnnotatedMethods(Produces.class))
-      {
-         createProducerMethod(declaringBean, method);         
-      }
-   }
-   
-   private void createDisposalMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
-   {
-      for (WBMethod<?> method : annotatedClass.getDeclaredMethodsWithAnnotatedParameters(Disposes.class))
-      {
-         DisposalMethodBean<?> disposalBean = DisposalMethodBean.of(manager, method, declaringBean);
-         environment.addDisposalBean(disposalBean);
-      }
-   }
-   
-   private <T> void createProducerMethod(AbstractClassBean<?> declaringBean, WBMethod<T> annotatedMethod)
-   {
-      ProducerMethodBean<T> bean = ProducerMethodBean.of(annotatedMethod, declaringBean, manager);
-      addBean(bean);
-      manager.getResolver().addInjectionPoints(bean.getAnnotatedInjectionPoints());
-   }
-   
-   private void createRealizedProducerMethods(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
-   {
-      WBClass<?> realizedClass = realizingClass.getSuperclass();
-      for (WBMethod<?> realizedMethod : realizedClass.getDeclaredAnnotatedMethods(Produces.class))
-      {
-         createProducerMethod(declaringBean, realizeProducerMethod(realizedMethod, realizingClass));
-      }
-   }
-   
-   private void createRealizedProducerFields(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
-   {
-      WBClass<?> realizedClass = realizingClass.getSuperclass();
-      for (final WBField<?> realizedField : realizedClass.getDeclaredAnnotatedFields(Produces.class))
-      {
-         createProducerField(declaringBean, realizeProducerField(realizedField, realizingClass));
-      }
-   }
-   
-   private <T> void createProducerField(AbstractClassBean<?> declaringBean, WBField<T> field)
-   {
-      ProducerFieldBean<T> bean = ProducerFieldBean.of(field, declaringBean, manager);
-      addBean(bean);
-   }
-   
-   private void createProducerFields(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
-   {
-      for (WBField<?> field : annotatedClass.getDeclaredAnnotatedFields(Produces.class))
-      {
-         createProducerField(declaringBean, field);
-      }
-   }
-   
-   private void createObserverMethods(AbstractClassBean<?> declaringBean, WBClass<?> annotatedClass)
-   {
-      for (WBMethod<?> method : annotatedClass.getDeclaredMethodsWithAnnotatedParameters(Observes.class))
-      {
-         createObserverMethod(declaringBean, method);
-      }
-   }
-   
-   private void createRealizedObserverMethods(AbstractClassBean<?> declaringBean, WBClass<?> realizingClass)
-   {
-      createObserverMethods(declaringBean, realizingClass.getSuperclass());
-   }
-   
-   private void createObserverMethod(AbstractClassBean<?> declaringBean, WBMethod<?> method)
-   {
-      ObserverImpl<?> observer = ObserverFactory.create(method, declaringBean, manager);
-      environment.getObservers().add(observer);
-   }
-   
-   private <T> void createSimpleBean(WBClass<T> annotatedClass)
-   {
-      SimpleBean<T> bean = SimpleBean.of(annotatedClass, manager);
-      createBean(bean, annotatedClass);
-      addBean(NewSimpleBean.of(annotatedClass, manager));
-   }
-   
-   private <T> void createDecorator(WBClass<T> annotatedClass)
-   {
-      DecoratorBean<T> bean = DecoratorBean.of(annotatedClass, manager);
-      addBean(bean);
-   }
-   
-   private <T> void createEnterpriseBean(WBClass<T> annotatedClass)
-   {
-      // TODO Don't create enterprise bean if it has no local interfaces!
-      EnterpriseBean<T> bean = EnterpriseBean.of(annotatedClass, manager, environment);
-      createBean(bean, annotatedClass);
-      addBean(NewEnterpriseBean.of(annotatedClass, manager, environment));
-   }
-   
-   /**
-    * Indicates if the type is a simple Web Bean
-    * 
-    * @param type
-    *           The type to inspect
-    * @return True if simple Web Bean, false otherwise
-    */
-   private boolean isTypeManagedBeanOrDecorator(WBClass<?> clazz)
-   {
-      Class<?> rawType = clazz.getJavaClass();
-      EJBApiAbstraction ejbApiAbstraction = manager.getServices().get(EJBApiAbstraction.class);
-      JsfApiAbstraction jsfApiAbstraction = manager.getServices().get(JsfApiAbstraction.class);
-      ServletApiAbstraction servletApiAbstraction = manager.getServices().get(ServletApiAbstraction.class);
-      return !clazz.isNonStaticMemberClass() &&
-             !Reflections.isParameterizedType(rawType) && 
-             !servletApiAbstraction.SERVLET_CLASS.isAssignableFrom(rawType) && 
-             !servletApiAbstraction.FILTER_CLASS.isAssignableFrom(rawType) && 
-             !servletApiAbstraction.SERVLET_CONTEXT_LISTENER_CLASS.isAssignableFrom(rawType) && 
-             !servletApiAbstraction.HTTP_SESSION_LISTENER_CLASS.isAssignableFrom(rawType) && 
-             !servletApiAbstraction.SERVLET_REQUEST_LISTENER_CLASS.isAssignableFrom(rawType) && 
-             !ejbApiAbstraction.ENTERPRISE_BEAN_CLASS.isAssignableFrom(rawType) && 
-             !jsfApiAbstraction.UICOMPONENT_CLASS.isAssignableFrom(rawType) && 
-             hasSimpleWebBeanConstructor(clazz);
-   }
-   
-   private static boolean hasSimpleWebBeanConstructor(WBClass<?> type)
-   {
-      return type.getNoArgsConstructor() != null || type.getAnnotatedConstructors(Initializer.class).size() > 0;
-   }
-   
-   private static <T> WBMethod<T> realizeProducerMethod(final WBMethod<T> method, final WBClass<?> realizingClass)
-   {
-      return new WrappedWBMethod<T>(method, realizingClass.getMetaAnnotations(BindingType.class))
-      {
-         
-         @Override
-         public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
-         {
-            if (metaAnnotationType.equals(DeploymentType.class))
-            {
-               return realizingClass.getMetaAnnotations(DeploymentType.class);
-            }
-            else
-            {
-               return super.getMetaAnnotations(metaAnnotationType);
-            }
-         }
-         
-         @Override
-         public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
-         {
-            if (metaAnnotationType.equals(DeploymentType.class))
-            {
-               return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
-            }
-            else
-            {
-               return super.getDeclaredMetaAnnotations(metaAnnotationType);
-            }
-         }
-         
-      };
-   }
-   
-   private static <T> WBField<T> realizeProducerField(final WBField<T> field, final WBClass<?> realizingClass)
-   {
-      return new WrappedWBField<T>(field, realizingClass.getMetaAnnotations(BindingType.class))
-      {
-         
-         @Override
-         public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
-         {
-            if (metaAnnotationType.equals(DeploymentType.class))
-            {
-               return realizingClass.getMetaAnnotations(DeploymentType.class);
-            }
-            else
-            {
-               return super.getMetaAnnotations(metaAnnotationType);
-            }
-         }
-         
-         @Override
-         public Set<Annotation> getDeclaredMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
-         {
-            if (metaAnnotationType.equals(DeploymentType.class))
-            {
-               return realizingClass.getDeclaredMetaAnnotations(DeploymentType.class);
-            }
-            else
-            {
-               return super.getDeclaredMetaAnnotations(metaAnnotationType);
-            }
-         }
-         
-      };
-   }
-   
-}

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bootstrap;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.decorator.Decorator;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.RIBean;
+import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.resources.ClassTransformer;
+
+/**
+ * @author pmuir
+ *
+ */
+public class BeanDeployer extends AbstractBeanDeployer
+{
+
+   private final Set<WBClass<?>> classes;
+
+   /**
+    * @param manager
+    * @param ejbDescriptors
+    */
+   public BeanDeployer(BeanManagerImpl manager, EjbDescriptorCache ejbDescriptors)
+   {
+      super(manager, new BeanDeployerEnvironment(ejbDescriptors, manager));
+      this.classes = new HashSet<WBClass<?>>();
+   }
+
+   public AbstractBeanDeployer addBeans(Iterable<? extends RIBean<?>> beans)
+   {
+      for (RIBean<?> bean : beans)
+      {
+         addBean(bean);
+      }
+      return this;
+   }
+
+   public AbstractBeanDeployer addClass(Class<?> clazz)
+   {
+      ClassTransformer classTransformer = getManager().getServices().get(ClassTransformer.class);
+      if (!clazz.isAnnotation() && !clazz.isEnum())
+      {
+         classes.add(classTransformer.classForName(clazz));
+      }
+      return this;
+   }
+
+   public AbstractBeanDeployer addClasses(Iterable<Class<?>> classes)
+   {
+      for (Class<?> clazz : classes)
+      {
+         addClass(clazz);
+      }
+      return this;
+   }
+
+   public AbstractBeanDeployer addClasses(Collection<WBClass<?>> classes)
+   {
+      classes.addAll(classes);
+      return this;
+   }
+
+   public AbstractBeanDeployer createBeans()
+   {
+      for (WBClass<?> clazz : classes)
+      {
+         if (getBeanDeployerEnvironment().getEjbDescriptors().containsKey(clazz.getJavaClass()))
+         {
+            createEnterpriseBean(clazz);
+         }
+         else
+         {
+            boolean managedBeanOrDecorator = isTypeManagedBeanOrDecorator(clazz);
+            if (managedBeanOrDecorator && clazz.isAnnotationPresent(Decorator.class))
+            {
+               createDecorator(clazz);
+            }
+            else if (managedBeanOrDecorator && !clazz.isAbstract())
+            {
+               createSimpleBean(clazz);
+            }
+         }
+      }
+      return this;
+   }
+
+}


Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeanDeployer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/BeforeBeanDiscoveryImpl.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -9,8 +9,7 @@
 
    public void addBindingType(Class<? extends Annotation> bindingType)
    {
-      throw new RuntimeException("Not Yet Implemented");
-
+      
    }
 
    public void addInterceptorBindingType(Class<? extends Annotation> bindingType)

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,73 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.bootstrap;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.standard.ExtensionBean;
+import org.jboss.webbeans.ejb.EjbDescriptorCache;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.resources.ClassTransformer;
+
+/**
+ * @author pmuir
+ *
+ */
+public class ExtensionBeanDeployer extends AbstractBeanDeployer
+{
+
+   private final Set<Extension> extensions;
+   
+   public ExtensionBeanDeployer(BeanManagerImpl manager)
+   {
+      super(manager, new BeanDeployerEnvironment(new EjbDescriptorCache(), manager));
+      this.extensions = new HashSet<Extension>();
+   }
+   
+   public AbstractBeanDeployer createBeans()
+   {
+      ClassTransformer classTransformer = getManager().getServices().get(ClassTransformer.class);
+      for (Extension extension : extensions)
+      {
+         @SuppressWarnings("unchecked")
+         WBClass<Extension> clazz = (WBClass<Extension>) classTransformer.classForName(extension.getClass());
+         
+         ExtensionBean bean = ExtensionBean.of(getManager(), clazz, extension);
+         addBean(bean);
+         createObserverMethods(bean, clazz);
+      }
+      return this;
+   }
+   
+   public void addExtensions(Iterable<Extension> extensions)
+   {
+      for (Extension extension : extensions)
+      {
+         addExtension(extension);
+      }
+   }
+   
+   public void addExtension(Extension extension)
+   {
+      this.extensions.add(extension);
+   }
+
+}


Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/ExtensionBeanDeployer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/bootstrap/WebBeansBootstrap.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -16,6 +16,8 @@
  */
 package org.jboss.webbeans.bootstrap;
 
+import javax.enterprise.inject.spi.Extension;
+
 import org.jboss.webbeans.BeanManagerImpl;
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.DefinitionException;
@@ -59,6 +61,7 @@
 import org.jboss.webbeans.servlet.HttpSessionManager;
 import org.jboss.webbeans.servlet.ServletApiAbstraction;
 import org.jboss.webbeans.transaction.spi.TransactionServices;
+import org.jboss.webbeans.util.serviceProvider.ServiceLoader;
 import org.jboss.webbeans.ws.spi.WebServices;
 import org.jboss.webbeans.xml.BeansXmlParser;
 
@@ -81,6 +84,7 @@
 
    // The Web Beans manager
    private BeanManagerImpl manager;
+   
    public WebBeansBootstrap()
    {
       // initialize default services
@@ -146,9 +150,8 @@
     * 
     * @param classes The classes to register as Web Beans
     */
-   protected void registerBeans(Iterable<Class<?>> classes, EjbDescriptorCache ejbDescriptors)
+   protected void registerBeans(Iterable<Class<?>> classes, BeanDeployer beanDeployer)
    {
-      BeanDeployer beanDeployer = new BeanDeployer(manager, ejbDescriptors);
       beanDeployer.addClasses(classes);
       beanDeployer.addBean(ManagerBean.of(manager));
       beanDeployer.addBean(InjectionPointBean.of(manager));
@@ -165,6 +168,11 @@
       beanDeployer.createBeans().deploy();
    }
    
+   private void registerExtensionBeans(Iterable<Extension> instances, AbstractBeanDeployer beanDeployer)
+   {
+      
+   }
+   
    public void boot()
    {
       synchronized (this)
@@ -177,9 +185,13 @@
          {
             throw new IllegalStateException("No application context BeanStore set");
          }
+         
+         parseBeansXml();
+         
          beginApplication(getApplicationContext());
          BeanStore requestBeanStore = new ConcurrentHashMapBeanStore();
          beginDeploy(requestBeanStore);
+         
          EjbDescriptorCache ejbDescriptors = new EjbDescriptorCache();
          if (getServices().contains(EjbServices.class))
          {
@@ -188,35 +200,48 @@
             ejbDescriptors.addAll(getServices().get(EjbServices.class).discoverEjbs());
          }
          
-         BeansXmlParser parser = new BeansXmlParser(getServices().get(ResourceLoader.class), getServices().get(WebBeanDiscovery.class).discoverWebBeansXml());
-         parser.parse();
+         // TODO Should use a separate event manager for sending bootstrap events
+         ExtensionBeanDeployer extensionBeanDeployer = new ExtensionBeanDeployer(manager);
+         extensionBeanDeployer.addExtensions(ServiceLoader.load(Extension.class));
+         extensionBeanDeployer.createBeans().deploy();
          
-         if (parser.getEnabledDeploymentTypes() != null)
-         {
-            manager.setEnabledDeploymentTypes(parser.getEnabledDeploymentTypes());
-         }
-         if (parser.getEnabledDecoratorClasses() != null)
-         {
-            manager.setEnabledDecoratorClasses(parser.getEnabledDecoratorClasses());
-         }
-         if (parser.getEnabledInterceptorClasses() != null)
-         {
-            manager.setEnabledInterceptorClasses(parser.getEnabledInterceptorClasses());
-         }
-         log.debug("Deployment types: " + manager.getEnabledDeploymentTypes());
+         BeanDeployer beanDeployer = new BeanDeployer(manager, ejbDescriptors);
+         
          fireBeforeBeanDiscoveryEvent();
-         registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses(), ejbDescriptors);
+         registerBeans(getServices().get(WebBeanDiscovery.class).discoverWebBeanClasses(), beanDeployer);
          fireAfterBeanDiscoveryEvent();
          log.debug("Web Beans initialized. Validating beans.");
-         getServices().get(Validator.class).validateDeployment(manager);
+         getServices().get(Validator.class).validateDeployment(manager, beanDeployer.getBeanDeployerEnvironment());
          // TODO I don't really think this is needed anymore, as we validate all points
          manager.getResolver().resolveInjectionPoints();
          fireAfterDeploymentValidationEvent();
          endDeploy(requestBeanStore);
       }
    }
+   
+   private void parseBeansXml()
+   {
+      BeansXmlParser parser = new BeansXmlParser(getServices().get(ResourceLoader.class), getServices().get(WebBeanDiscovery.class).discoverWebBeansXml());
+      parser.parse();
+      
+      if (parser.getEnabledDeploymentTypes() != null)
+      {
+         manager.setEnabledDeploymentTypes(parser.getEnabledDeploymentTypes());
+      }
+      if (parser.getEnabledDecoratorClasses() != null)
+      {
+         manager.setEnabledDecoratorClasses(parser.getEnabledDecoratorClasses());
+      }
+      if (parser.getEnabledInterceptorClasses() != null)
+      {
+         manager.setEnabledInterceptorClasses(parser.getEnabledInterceptorClasses());
+      }
+      log.debug("Enabled deployment types: " + manager.getEnabledDeploymentTypes());
+      log.debug("Enabled decorator types: " + manager.getEnabledDecoratorClasses());
+      log.debug("Enabled interceptor types: " + manager.getEnabledInterceptorClasses());
+   }
 
-   protected void fireBeforeBeanDiscoveryEvent()
+   private void fireBeforeBeanDiscoveryEvent()
    {
       BeforeBeanDiscoveryImpl event = new BeforeBeanDiscoveryImpl();
       try

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/EventManager.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -84,13 +84,13 @@
       {
          for (EventObserver<?> observer : manager.getRegisteredObservers().get(type))
          {
-            log.debug("Checking observer " + observer + " to see if it is interested in event [" + event + "]");
+            log.trace("Checking observer " + observer + " to see if it is interested in event [" + event + "]");
             if (observer.isObserverInterested(bindings))
             {
                @SuppressWarnings("unchecked")
                Observer<T> o = (Observer<T>) observer.getObserver();
                interestedObservers.add(o);
-               log.debug("Added observer " + observer + " for event [" + event + "]");
+               log.trace("Added observer " + observer + " for event [" + event + "]");
             }
          }
       }

Modified: ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverFactory.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverFactory.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/event/ObserverFactory.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -17,7 +17,7 @@
 package org.jboss.webbeans.event;
 
 import org.jboss.webbeans.BeanManagerImpl;
-import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.bean.RIBean;
 import org.jboss.webbeans.introspector.WBMethod;
 import org.jboss.webbeans.transaction.spi.TransactionServices;
 
@@ -37,7 +37,7 @@
     * @param manager The Web Beans manager
     * @return An observer implementation built from the method abstraction
     */
-   public static <T> ObserverImpl<T> create(WBMethod<?> method, AbstractClassBean<?> declaringBean, BeanManagerImpl manager)
+   public static <T> ObserverImpl<T> create(WBMethod<?> method, RIBean<?> declaringBean, BeanManagerImpl manager)
    {
       ObserverImpl<T> result = null;
       if (manager.getServices().contains(TransactionServices.class) && TransactionalObserverImpl.isObserverMethodTransactional(method))

Added: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/ServiceLoader.java
===================================================================
--- ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/ServiceLoader.java	                        (rev 0)
+++ ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/ServiceLoader.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,280 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.util.serviceProvider;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * This class handles looking up service providers on the class path. It
+ * implements the <a href="http://java.sun.com/javase/6/docs/technotes/guides/jar/jar.html#Service%20Provider"
+ * >Service Provider section of the JAR File Specification</a>.
+ * 
+ * The Service Provider programmatic lookup was not specified prior to Java 6 so
+ * this interface allows use of the specification prior to Java 6.
+ * 
+ * The API is copied from <a
+ * href="http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html"
+ * >java.util.ServiceLoader</a>
+ * 
+ * @author Pete Muir
+ * @author <a href="mailto:dev at avalon.apache.org">Avalon Development Team</a>
+ */
+public class ServiceLoader<S> implements Iterable<S>
+{
+   
+   private Log log = Logging.getLog(ServiceLoader.class);
+
+   private static final String SERVICES = "META-INF/services/";
+
+   /**
+    * Creates a new service loader for the given service type, using the current
+    * thread's context class loader.
+    * 
+    * An invocation of this convenience method of the form
+    * 
+    * {@code ServiceLoader.load(service)</code>}
+    * 
+    * is equivalent to
+    * 
+    * <code>ServiceLoader.load(service,
+    *                   Thread.currentThread().getContextClassLoader())</code>
+    * 
+    * @param service The interface or abstract class representing the service
+    * @return A new service loader
+    */
+   public static <S> ServiceLoader<S> load(Class<S> service)
+   {
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      return load(service, loader);
+   }
+
+   /**
+    * Creates a new service loader for the given service type and class loader.
+    * 
+    * @param service The interface or abstract class representing the service
+    * @param loader The class loader to be used to load provider-configuration
+    *           files and provider classes, or null if the system class loader
+    *           (or, failing that, the bootstrap class loader) is to be used
+    * @return A new service loader
+    */
+   public static <S> ServiceLoader<S> load(Class<S> service, ClassLoader loader)
+   {
+      if (loader == null)
+      {
+         loader = service.getClassLoader();
+      }
+      return new ServiceLoader<S>(service, loader);
+   }
+
+   /**
+    * Creates a new service loader for the given service type, using the
+    * extension class loader.
+    * 
+    * This convenience method simply locates the extension class loader, call it
+    * extClassLoader, and then returns
+    * 
+    * <code>ServiceLoader.load(service, extClassLoader)</code>
+    * 
+    * If the extension class loader cannot be found then the system class loader
+    * is used; if there is no system class loader then the bootstrap class
+    * loader is used.
+    * 
+    * This method is intended for use when only installed providers are desired.
+    * The resulting service will only find and load providers that have been
+    * installed into the current Java virtual machine; providers on the
+    * application's class path will be ignored.
+    * 
+    * @param service The interface or abstract class representing the service
+    * @return A new service loader
+    */
+   public static <S> ServiceLoader<S> loadInstalled(Class<S> service)
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+   private final String serviceFile;
+   private final ClassLoader loader;
+   
+   private Set<S> providers;
+
+   private ServiceLoader(Class<S> service, ClassLoader loader)
+   {
+      this.loader = loader;
+      this.serviceFile = SERVICES + service.getName();
+   }
+   
+   /**
+    * Clear this loader's provider cache so that all providers will be reloaded.
+    * 
+    * After invoking this method, subsequent invocations of the iterator method
+    * will lazily look up and instantiate providers from scratch, just as is
+    * done by a newly-created loader.
+    * 
+    * This method is intended for use in situations in which new providers can
+    * be installed into a running Java virtual machine.
+    */
+   public void reload()
+   {
+      providers = new HashSet<S>();
+      Enumeration<URL> enumeration = null;
+      boolean errorOccurred = false;
+
+      try
+      {
+         enumeration = loader.getResources(serviceFile);
+      }
+      catch (IOException ioe)
+      {
+         errorOccurred = true;
+      }
+
+      if (!errorOccurred)
+      {
+         while (enumeration.hasMoreElements())
+         {
+            try
+            {
+               final URL url = enumeration.nextElement();
+               final InputStream is = url.openStream();
+               final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+
+               String line = reader.readLine();
+               while (null != line)
+               {
+                  try
+                  {
+                     final int comment = line.indexOf('#');
+
+                     if (comment > -1)
+                     {
+                        line = line.substring(0, comment);
+                     }
+
+                     line.trim();
+
+                     if (line.length() > 0)
+                     {
+                        try
+                        {
+                           @SuppressWarnings("unchecked")
+                           Class<? extends S> clazz = (Class<? extends S>) loader.loadClass(line);
+                           S instance = clazz.newInstance();
+                           providers.add(instance);
+                        }
+                        catch (NoClassDefFoundError e)
+                        {
+                           log.warn("Error loading #0", line, e);
+                           throw e;
+                        }
+                        catch (InstantiationException e)
+                        {
+                           log.warn("Error loading #0", line, e);
+                           throw e;
+                        }
+                        catch (IllegalAccessException e)
+                        {
+                           log.warn("Error loading #0", line, e);
+                           throw e;
+                        }
+                     }
+                  }
+                  catch (Exception e)
+                  {
+                     // try the next line
+                  }
+
+                  line = reader.readLine();
+               }
+            }
+            catch (Exception e)
+            {
+               // try the next file
+            }
+         }
+      }
+   }
+   
+   
+
+   /**
+    * Lazily loads the available providers of this loader's service.
+    * 
+    * The iterator returned by this method first yields all of the elements of
+    * the provider cache, in instantiation order. It then lazily loads and
+    * instantiates any remaining providers, adding each one to the cache in
+    * turn.
+    * 
+    * To achieve laziness the actual work of parsing the available
+    * provider-configuration files and instantiating providers must be done by
+    * the iterator itself. Its hasNext and next methods can therefore throw a
+    * ServiceConfigurationError if a provider-configuration file violates the
+    * specified format, or if it names a provider class that cannot be found and
+    * instantiated, or if the result of instantiating the class is not
+    * assignable to the service type, or if any other kind of exception or error
+    * is thrown as the next provider is located and instantiated. To write
+    * robust code it is only necessary to catch ServiceConfigurationError when
+    * using a service iterator.
+    * 
+    * If such an error is thrown then subsequent invocations of the iterator
+    * will make a best effort to locate and instantiate the next available
+    * provider, but in general such recovery cannot be guaranteed.
+    * 
+    * Design Note Throwing an error in these cases may seem extreme. The
+    * rationale for this behavior is that a malformed provider-configuration
+    * file, like a malformed class file, indicates a serious problem with the
+    * way the Java virtual machine is configured or is being used. As such it is
+    * preferable to throw an error rather than try to recover or, even worse,
+    * fail silently.
+    * 
+    * The iterator returned by this method does not support removal. Invoking
+    * its remove method will cause an UnsupportedOperationException to be
+    * thrown.
+    * 
+    * @return An iterator that lazily loads providers for this loader's service
+    */
+   public Iterator<S> iterator()
+   {
+      if (providers == null)
+      {
+         reload();
+      }
+      return providers.iterator();
+   }
+
+   /**
+    * Returns a string describing this service.
+    * 
+    * @return A descriptive string
+    */
+   @Override
+   public String toString()
+   {
+      return "Services for " + serviceFile;
+   }
+
+}


Property changes on: ri/trunk/impl/src/main/java/org/jboss/webbeans/util/serviceProvider/ServiceLoader.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/BeforeBeanDiscoveryObserver.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/BeforeBeanDiscoveryObserver.java	                        (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/BeforeBeanDiscoveryObserver.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,  
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.jsr299.tck.tests.deployment.lifecycle;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+
+/**
+ * @author pmuir
+ *
+ */
+public class BeforeBeanDiscoveryObserver implements Extension
+{
+   
+   private static boolean observed;
+   
+   /**
+    * @return the observed
+    */
+   public static boolean isObserved()
+   {
+      return observed;
+   }
+   
+   /**
+    * @param observed the observed to set
+    */
+   public static void setObserved(boolean observed)
+   {
+      BeforeBeanDiscoveryObserver.observed = observed;
+   }
+   
+
+   public void observe(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+   {
+      setObserved(true);
+   }
+   
+}


Property changes on: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/BeforeBeanDiscoveryObserver.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/ExtensionsTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/ExtensionsTest.java	2009-06-26 15:53:39 UTC (rev 2901)
+++ tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/deployment/lifecycle/ExtensionsTest.java	2009-06-26 17:03:09 UTC (rev 2902)
@@ -18,6 +18,9 @@
 
 import org.jboss.jsr299.tck.AbstractJSR299Test;
 import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.Resources;
 import org.testng.annotations.Test;
 
 /**
@@ -25,13 +28,17 @@
  *
  */
 @Artifact
+ at Resources({
+   @Resource(source="javax.enterprise.inject.spi.Extension", destination="WEB-INF/classes/META-INF/services/javax.enterprise.inject.spi.Extension")
+})
+ at IntegrationTest
 public class ExtensionsTest extends AbstractJSR299Test
 {
    
    @Test
    public void testBeforeBeanDiscoveryEventIsCalled()
    {
-      
+      assert BeforeBeanDiscoveryObserver.isObserved();
    }
 
 }

Added: tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/deployment/lifecycle/javax.enterprise.inject.spi.Extension
===================================================================
--- tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/deployment/lifecycle/javax.enterprise.inject.spi.Extension	                        (rev 0)
+++ tck/trunk/impl/src/main/resources/org/jboss/jsr299/tck/tests/deployment/lifecycle/javax.enterprise.inject.spi.Extension	2009-06-26 17:03:09 UTC (rev 2902)
@@ -0,0 +1 @@
+org.jboss.jsr299.tck.tests.deployment.lifecycle.BeforeBeanDiscoveryObserver




More information about the weld-commits mailing list