[webbeans-commits] Webbeans SVN: r1189 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean and 2 other directories.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Thu Jan 22 20:43:45 EST 2009
Author: pete.muir at jboss.org
Date: 2009-01-22 20:43:45 -0500 (Thu, 22 Jan 2009)
New Revision: 1189
Added:
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/AnotherDeploymentType.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Delivery.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/FarmShop.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Shop.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/EventTest.java
Log:
fixes + specialization support for events
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -527,9 +527,22 @@
*/
public <T> T getInstance(Bean<T> bean)
{
+ return getInstance(bean, true);
+ }
+
+ /**
+ * Returns an instance of a bean
+ *
+ * @param bean The bean to instantiate
+ * @return An instance of the bean
+ *
+ * @see javax.webbeans.manager.Manager#getInstance(javax.webbeans.manager.Bean)
+ */
+ public <T> T getInstance(Bean<T> bean, boolean create)
+ {
if (specializedBeans.containsKey(bean))
{
- return getInstance((Bean<T>) specializedBeans.get(bean));
+ return getInstance((Bean<T>) specializedBeans.get(bean), create);
}
else if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
{
@@ -582,18 +595,6 @@
return getInstanceByType(AnnotatedClassImpl.of(type, bindings), bindings);
}
- public <T> T getMostSpecializedInstance(Bean<T> bean, boolean create)
- {
- // TODO Implement specialization
- if (MetaDataCache.instance().getScopeModel(bean.getScopeType()).isNormal())
- {
- return (T) proxyPool.getClientProxy(bean, create);
- }
- else
- {
- return getContext(bean.getScopeType()).get(bean, create);
- }
- }
/**
* Returns an instance by type literal and binding types
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -31,6 +31,7 @@
import javax.webbeans.Event;
import javax.webbeans.InjectionPoint;
import javax.webbeans.Named;
+import javax.webbeans.Specializes;
import javax.webbeans.Standard;
import javax.webbeans.Stereotype;
import javax.webbeans.manager.Bean;
@@ -410,8 +411,6 @@
protected abstract String getDefaultName();
public abstract AbstractBean<?, ?> getSpecializedBean();
-
- public abstract boolean isSpecializing();
/**
* Gets the deployment type of the bean
@@ -560,13 +559,19 @@
return proxyable;
}
+ public boolean isSpecializing()
+ {
+ return getAnnotatedItem().isAnnotationPresent(Specializes.class);
+ }
+
@Override
public boolean equals(Object other)
{
if (other instanceof AbstractBean)
{
AbstractBean<?, ?> that = (AbstractBean<?, ?>) other;
- return this.getTypes().equals(that.getTypes()) && this.getBindings().equals(that.getBindings());
+ boolean equal = this.getTypes().equals(that.getTypes()) && this.getBindings().equals(that.getBindings());
+ return equal;
}
else
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -31,7 +31,6 @@
import javax.webbeans.Produces;
import javax.webbeans.Production;
import javax.webbeans.ScopeType;
-import javax.webbeans.Specializes;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.context.DependentInstancesStore;
@@ -280,12 +279,6 @@
throw new DefinitionException("Specializing bean must extend another bean");
}
}
-
- @Override
- public boolean isSpecializing()
- {
- return getAnnotatedItem().isAnnotationPresent(Specializes.class);
- }
/**
* Gets the annotated item
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewEnterpriseBean.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -116,5 +116,11 @@
{
return NEW_BINDING_SET;
}
+
+ @Override
+ public boolean isSpecializing()
+ {
+ return false;
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/NewSimpleBean.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -143,4 +143,10 @@
return NEW_BINDING_SET;
}
+ @Override
+ public boolean isSpecializing()
+ {
+ return false;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -24,7 +24,6 @@
import javax.webbeans.DefinitionException;
import javax.webbeans.Disposes;
import javax.webbeans.Observes;
-import javax.webbeans.Specializes;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.MetaDataCache;
@@ -227,11 +226,5 @@
{
this.specializedBean = ProducerMethodBean.of(declaringBean.getAnnotatedItem().getSuperclass().getMethod(getAnnotatedItem().getAnnotatedMethod()), SimpleBean.of(declaringBean.getAnnotatedItem().getSuperclass(), manager), manager);
}
-
- @Override
- public boolean isSpecializing()
- {
- return getAnnotatedItem().isAnnotationPresent(Specializes.class);
- }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -188,7 +188,7 @@
public void notify(final T event)
{
// Get the most specialized instance of the component
- Object instance = getInstance(!isConditional());
+ Object instance = manager.getInstance(observerBean, !isConditional());
if (instance != null)
{
try
@@ -221,20 +221,6 @@
}
/**
- * Uses the container to retrieve the most specialized instance of this
- * observer.
- *
- * @param create True if the instance should be created if not already done
- *
- * @return the most specialized instance
- */
- protected Object getInstance(boolean create)
- {
- // Return the most specialized instance of the component
- return manager.getMostSpecializedInstance(observerBean, create);
- }
-
- /**
* Checks if there is currently a transaction active
*
* @return True if there is one, false otherwise
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/AnotherDeploymentType.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/AnotherDeploymentType.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/AnotherDeploymentType.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.tck.unit.event;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import javax.webbeans.DeploymentType;
+
+ at Target( { TYPE, METHOD })
+ at Retention(RUNTIME)
+ at Documented
+ at DeploymentType
+ at interface AnotherDeploymentType
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/AnotherDeploymentType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Delivery.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Delivery.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Delivery.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.tck.unit.event;
+
+class Delivery
+{
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Delivery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/EventTest.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/EventTest.java 2009-01-23 01:21:23 UTC (rev 1188)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/EventTest.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -2,6 +2,7 @@
import java.lang.annotation.Annotation;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import javax.webbeans.DefinitionException;
@@ -29,6 +30,17 @@
@SpecVersion("20081206")
public class EventTest extends AbstractTest
{
+
+
+ @Override
+ protected List<Class<? extends Annotation>> getEnabledDeploymentTypes()
+ {
+ List<Class<? extends Annotation>> deploymentTypes = new ArrayList<Class<? extends Annotation>>();
+ deploymentTypes.addAll(getStandardDeploymentTypes());
+ deploymentTypes.add(AnotherDeploymentType.class);
+ return deploymentTypes;
+ }
+
public static class AnEventType
{
}
@@ -915,4 +927,13 @@
deployBeans(LazyFarmer.class);
assert manager.resolveObservers(new Egg()).isEmpty();
}
+
+ @Test @SpecAssertion(section="8.5.8")
+ public void testObserverCalledOnMostSpecializedInstance()
+ {
+ Shop.deliveryObservedBy = null;
+ deployBeans(FarmShop.class, Shop.class);
+ manager.fireEvent(new Delivery());
+ assert Shop.deliveryObservedBy.equals(FarmShop.class.getName());
+ }
}
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/FarmShop.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/FarmShop.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/FarmShop.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -0,0 +1,15 @@
+package org.jboss.webbeans.tck.unit.event;
+
+import javax.webbeans.Specializes;
+
+ at Specializes @AnotherDeploymentType
+class FarmShop extends Shop
+{
+
+ @Override
+ public String getClassName()
+ {
+ return FarmShop.class.getName();
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/FarmShop.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Shop.java
===================================================================
--- tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Shop.java (rev 0)
+++ tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Shop.java 2009-01-23 01:43:45 UTC (rev 1189)
@@ -0,0 +1,20 @@
+package org.jboss.webbeans.tck.unit.event;
+
+import javax.webbeans.Observes;
+
+class Shop
+{
+
+ public static String deliveryObservedBy = null;
+
+ public String getClassName()
+ {
+ return Shop.class.getName();
+ }
+
+ public void observeDelivery(@Observes Delivery delivery)
+ {
+ deliveryObservedBy = getClassName();
+ }
+
+}
Property changes on: tck/trunk/impl/src/main/java/org/jboss/webbeans/tck/unit/event/Shop.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
More information about the weld-commits
mailing list