[weld-commits] Weld SVN: r5995 - in core/trunk: impl/src/main/java/org/jboss/weld/bootstrap and 4 other directories.

weld-commits at lists.jboss.org weld-commits at lists.jboss.org
Wed Mar 3 23:23:14 EST 2010


Author: swd847
Date: 2010-03-03 23:23:13 -0500 (Wed, 03 Mar 2010)
New Revision: 5995

Added:
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeEjbExtension.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeSessionBeanTest.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/BigLathe.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/ConveyorShaft.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Lathe.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/LatheLocal.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Shaft.java
   core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/SmallLathe.java
   core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/ejb/
   core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/ejb/javax.enterprise.inject.spi.Extension
Modified:
   core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
   core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
   core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
Log:
WELD-460 this also fixed adding multiple ejb's with the same java type through BeforeBeanDiscovery.addAnnotatedType()



Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java	2010-03-03 21:49:14 UTC (rev 5994)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -72,6 +72,7 @@
 import org.jboss.weld.manager.BeanManagerImpl;
 import org.jboss.weld.resources.ClassTransformer;
 import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
+import org.jboss.weld.util.AnnotatedTypes;
 import org.jboss.weld.util.Beans;
 import org.jboss.weld.util.Proxies;
 import org.jboss.weld.util.Proxies.TypeInfo;
@@ -106,13 +107,39 @@
    public static <T> SessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl beanManager)
    {
       WeldClass<T> type = beanManager.getServices().get(ClassTransformer.class).loadClass(ejbDescriptor.getBeanClass());
-      return new SessionBean<T>(type, ejbDescriptor, createId(SessionBean.class.getSimpleName(), ejbDescriptor) , beanManager);
+      return new SessionBean<T>(type, ejbDescriptor, createId(SessionBean.class.getSimpleName(), ejbDescriptor, type), beanManager);
    }
 
+   /**
+    * Creates a simple, annotation defined Enterprise Web Bean using the annotations specified on type
+    * 
+    * @param <T> The type
+    * @param clazz The class
+    * @param beanManager the current manager
+    * @param type the AnnotatedType to use
+    * @return An Enterprise Web Bean
+    */
+   public static <T> SessionBean<T> of(InternalEjbDescriptor<T> ejbDescriptor, BeanManagerImpl beanManager, WeldClass<T> type)
+   {
+      return new SessionBean<T>(type, ejbDescriptor, createId(SessionBean.class.getSimpleName(), ejbDescriptor, type), beanManager);
+   }
+
    protected static String createId(String beanType, InternalEjbDescriptor<?> ejbDescriptor)
    {
       return new StringBuilder().append(beanType).append(BEAN_ID_SEPARATOR).append(ejbDescriptor.getEjbName()).toString();
    }
+
+   protected static String createId(String beanType, InternalEjbDescriptor<?> ejbDescriptor, WeldClass<?> type)
+   {
+      if (type.isDiscovered())
+      {
+         return createId(beanType, ejbDescriptor);
+      }
+      else
+      {
+         return new StringBuilder().append(beanType).append(BEAN_ID_SEPARATOR).append(ejbDescriptor.getEjbName()).append(AnnotatedTypes.createTypeId(type)).toString();
+      }
+   }
    
    /**
     * Constructor

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java	2010-03-03 21:49:14 UTC (rev 5994)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/AbstractBeanDeployer.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -265,6 +265,15 @@
       return bean;
    }
    
+   protected <T> SessionBean<T> createSessionBean(InternalEjbDescriptor<T> ejbDescriptor, WeldClass<T> weldClass)
+   {
+      // TODO Don't create enterprise bean if it has no local interfaces!
+      SessionBean<T> bean = SessionBean.of(ejbDescriptor, manager, weldClass);
+      getEnvironment().addSessionBean(bean);
+      createObserversProducersDisposers(bean);
+      return bean;
+   }
+
    protected <T> void createNewSessionBean(InternalEjbDescriptor<T> ejbDescriptor)
    {
       getEnvironment().addSessionBean(NewSessionBean.of(ejbDescriptor, manager));

Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java	2010-03-03 21:49:14 UTC (rev 5994)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/BeanDeployer.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -34,6 +34,9 @@
 import org.jboss.weld.manager.BeanManagerImpl;
 import org.jboss.weld.resources.ClassTransformer;
 
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
 /**
  * @author pmuir
  *
@@ -92,6 +95,7 @@
 
    public BeanDeployer createBeans()
    {
+      Multimap<Class<?>, WeldClass<?>> otherWeldClasses = HashMultimap.create();
       for (WeldClass<?> clazz : classes)
       {
          boolean managedBeanOrDecorator = !getEnvironment().getEjbDescriptors().contains(clazz.getJavaClass()) && isTypeManagedBeanOrDecoratorOrInterceptor(clazz);
@@ -109,12 +113,26 @@
          {
             createManagedBean(clazz);
          }
+         else
+         {
+            otherWeldClasses.put(clazz.getJavaClass(), clazz);
+         }
       }
       for (InternalEjbDescriptor<?> ejbDescriptor : getEnvironment().getEjbDescriptors())
       {
          if (ejbDescriptor.isSingleton() || ejbDescriptor.isStateful() || ejbDescriptor.isStateless())
          {
-            createSessionBean(ejbDescriptor);
+            if (otherWeldClasses.containsKey(ejbDescriptor.getBeanClass()))
+            {
+               for (WeldClass<?> c : otherWeldClasses.get(ejbDescriptor.getBeanClass()))
+               {
+                  createSessionBean(ejbDescriptor, (WeldClass) c);
+               }
+            }
+            else
+            {
+               createSessionBean(ejbDescriptor);
+            }
          }
       }
       

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeEjbExtension.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeEjbExtension.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeEjbExtension.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Produces;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.weld.tests.util.annotated.TestAnnotatedTypeBuilder;
+
+public class AnnotatedTypeEjbExtension implements Extension
+{
+   /**
+    * Adds two ejb beans
+    */
+   public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
+   {
+      TestAnnotatedTypeBuilder<Lathe> builder = new TestAnnotatedTypeBuilder<Lathe>(Lathe.class);
+      builder.addToClass(new AnnotationLiteral<SmallLathe>() { });
+      beforeBeanDiscovery.addAnnotatedType(builder.create());
+      builder = new TestAnnotatedTypeBuilder<Lathe>(Lathe.class);
+      builder.addToClass(new AnnotationLiteral<BigLathe>() { });
+      beforeBeanDiscovery.addAnnotatedType(builder.create());
+   }
+   /**
+    * Adds annotations to an EJB
+    */
+   public void overrideLatheAnnotations(@Observes ProcessAnnotatedType<Lathe> event) throws SecurityException, NoSuchMethodException
+   {
+     TestAnnotatedTypeBuilder<Lathe> builder = new TestAnnotatedTypeBuilder<Lathe>(Lathe.class);
+     for(Annotation a : event.getAnnotatedType().getAnnotations())
+     {
+        builder.addToClass(a);
+     }
+     Method method = Lathe.class.getMethod("doWork");
+     builder.addToMethod(method, new AnnotationLiteral<ConveyorShaft>() {});
+     builder.addToMethod(method, new AnnotationLiteral<Produces>() {});
+     event.setAnnotatedType(builder.create());
+   }
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeSessionBeanTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeSessionBeanTest.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/AnnotatedTypeSessionBeanTest.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Packaging;
+import org.jboss.testharness.impl.packaging.PackagingType;
+import org.jboss.testharness.impl.packaging.jsr299.Extension;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+/**
+ * Tests that it is possible to override ejb annotations through the SPI
+ * @author Stuart Douglas <stuart at baileyroberts.com.au>
+ *
+ */
+ at Artifact
+ at Packaging(PackagingType.EAR)
+ at IntegrationTest
+ at Extension("javax.enterprise.inject.spi.Extension")
+ at Classes(packages = { "org.jboss.weld.tests.util.annotated" })
+public class AnnotatedTypeSessionBeanTest extends AbstractWeldTest
+{
+   @Test
+   public void testOverridingEjbAnnotations()
+   {
+      Shaft conveyerShaft = getReference(Shaft.class, new AnnotationLiteral<ConveyorShaft>() { });
+      assert conveyerShaft != null;
+   }
+   
+   @Test
+   public void testAddingBultipleBeansPerEjbClass()
+   {
+      LatheLocal bigLathe = getReference(LatheLocal.class, new AnnotationLiteral<BigLathe>() { });
+      assert bigLathe != null;
+      LatheLocal smallLathe = getReference(LatheLocal.class, new AnnotationLiteral<SmallLathe>() { });
+      assert smallLathe != null;
+   }
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/BigLathe.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/BigLathe.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/BigLathe.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface BigLathe
+{
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/ConveyorShaft.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/ConveyorShaft.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/ConveyorShaft.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ConveyorShaft
+{
+
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Lathe.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Lathe.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Lathe.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,28 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import javax.ejb.Stateless;
+
+ at Stateless
+public class Lathe implements LatheLocal
+{
+   public Shaft doWork()
+   {
+      return new Shaft();
+   }
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/LatheLocal.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/LatheLocal.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/LatheLocal.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,27 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import javax.ejb.Local;
+
+ at Local
+public interface LatheLocal
+{
+
+   public Shaft doWork();
+
+}
\ No newline at end of file

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Shaft.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Shaft.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/Shaft.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,22 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+public class Shaft
+{
+   
+}

Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/SmallLathe.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/SmallLathe.java	                        (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/extensions/annotatedType/ejb/SmallLathe.java	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.weld.tests.extensions.annotatedType.ejb;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+ at Qualifier
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface SmallLathe
+{
+
+}

Added: core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/ejb/javax.enterprise.inject.spi.Extension
===================================================================
--- core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/ejb/javax.enterprise.inject.spi.Extension	                        (rev 0)
+++ core/trunk/tests/src/test/resources/org/jboss/weld/tests/extensions/annotatedType/ejb/javax.enterprise.inject.spi.Extension	2010-03-04 04:23:13 UTC (rev 5995)
@@ -0,0 +1 @@
+org.jboss.weld.tests.extensions.annotatedType.ejb.AnnotatedTypeEjbExtension
\ No newline at end of file



More information about the weld-commits mailing list