[webbeans-commits] Webbeans SVN: r193 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-28 07:02:00 -0400 (Tue, 28 Oct 2008)
New Revision: 193
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
Log:
fill in stubs for context tests
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-28 10:51:40 UTC (rev 192)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-28 11:02:00 UTC (rev 193)
@@ -1,9 +1,15 @@
package org.jboss.webbeans.test;
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.RequestScoped;
+import javax.webbeans.manager.Context;
+
+import org.jboss.webbeans.contexts.NormalContext;
+import org.jboss.webbeans.contexts.RequestContext;
import org.testng.annotations.Test;
@SpecVersion("PDR")
-public class ManagerTest
+public class ManagerTest extends AbstractTest
{
@Test(groups={"manager", "injection"}) @SpecAssertion(section="4.8")
@@ -11,35 +17,42 @@
{
assert false;
}
-
- @Test(groups={"manager"}) @SpecAssertion(section="8.6")
- public void testAddContext()
- {
- assert false;
- }
- @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ @Test(expectedExceptions={ContextNotActiveException.class}, groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithNoActiveContextsFails()
{
- assert false;
+ Context requestContext = new RequestContext();
+ ((NormalContext)requestContext).setActive(false);
+ manager.addContext(requestContext);
+ manager.getContext(RequestScoped.class);
}
- @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ @Test(expectedExceptions={IllegalArgumentException.class}, groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithTooManyActiveContextsFails()
{
- assert false;
+ Context firstContext = new RequestContext();
+ Context secondContext = new RequestContext();
+ manager.addContext(firstContext);
+ manager.addContext(secondContext);
+ manager.getContext(RequestScoped.class);
+ assert true;
}
- @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ @Test(expectedExceptions={ContextNotActiveException.class}, groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithNoRegisteredContextsFails()
{
+ manager.getContext(RequestScoped.class);
assert false;
}
@Test(groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextReturnsActiveContext()
{
- assert false;
+ Context requestContext = new RequestContext();
+ manager.addContext(requestContext);
+ Context testContext = manager.getContext(RequestScoped.class);
+ assert testContext == requestContext;
+
}
@Test(groups={"manager", "ejb3"}) @SpecAssertion(section="4.8")
16 years, 1 month
[webbeans-commits] Webbeans SVN: r192 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: event and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-10-28 06:51:40 -0400 (Tue, 28 Oct 2008)
New Revision: 192
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
Log:
Event bus tied into Manager implementation; transaction handling still needs to be corrected and tests fixed.
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 2008-10-28 08:25:21 UTC (rev 191)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-28 10:51:40 UTC (rev 192)
@@ -32,6 +32,7 @@
import org.jboss.webbeans.injectable.ResolverInjectable;
import org.jboss.webbeans.util.ClientProxy;
import org.jboss.webbeans.util.MapWrapper;
+import org.jboss.webbeans.util.Reflections;
public class ManagerImpl implements Manager
{
@@ -187,20 +188,29 @@
public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
- // TODO Auto-generated method stub
+ this.eventBus.addObserver(observer, eventType, bindings);
return this;
}
public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
- // TODO Auto-generated method stub
+ // TODO Using the eventType TypeLiteral<T>, the Class<T> object must be retrieved
+ this.eventBus.addObserver(observer, (Class<T>)Reflections.getActualTypeArguements(eventType.getClass())[0], bindings);
return this;
}
public void fireEvent(Object event, Annotation... bindings)
{
- // TODO Auto-generated method stub
-
+ // Check the event object for template parameters which are not allowed by the spec.
+ if (Reflections.isParameterizedType(event.getClass()))
+ {
+ throw new IllegalArgumentException("Event type " + event.getClass().getName() +
+ " is not allowed because it is a generic");
+ }
+ // Get the observers for this event. Although resolveObservers is parameterized, this
+ // method is not, so we have to use Observer<Object> for observers.
+ Set<Observer<Object>> observers = this.resolveObservers(event, bindings);
+ this.eventBus.notifyObservers(observers, event);
}
public Context getContext(Class<? extends Annotation> scopeType)
@@ -298,13 +308,14 @@
public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
- // TODO Auto-generated method stub
+ this.eventBus.removeObserver(observer, eventType, bindings);
return this;
}
public <T> Manager removeObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
- // TODO Auto-generated method stub
+ // TODO The Class<T> for the event type must be retrieved from the TypeLiteral<T> instance
+ this.eventBus.removeObserver(observer, (Class<T>)Reflections.getActualTypeArguements(eventType.getClass())[0], bindings);
return this;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-28 08:25:21 UTC (rev 191)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-28 10:51:40 UTC (rev 192)
@@ -106,12 +106,52 @@
}
/**
+ * Notifies each observer immediately of the event unless a transaction is currently in
+ * progress, in which case a deferred event is created and registered.
+ * @param <T>
+ * @param observers
+ * @param event
+ */
+ public <T> void notifyObservers(Set<Observer<T>> observers, T event)
+ {
+ for (Observer<T> observer : observers)
+ {
+ // TODO Replace this with the correct transaction code
+ Transaction transaction = null;
+ try
+ {
+ transaction = transactionManager.getTransaction();
+ } catch (SystemException e)
+ {
+ }
+ if (transaction != null)
+ {
+ try
+ {
+ deferEvent(event, observer);
+ } catch (IllegalStateException e)
+ {
+ } catch (SystemException e)
+ {
+ } catch (RollbackException e)
+ {
+ // TODO If transaction is being rolled back, perhaps notification should terminate now
+ }
+ } else
+ {
+ // Notify observer immediately in the same context as this method
+ observer.notify(event);
+ }
+ }
+ }
+
+ /**
* Removes an observer from the event bus.
*
* @param observer
* The observer to remove
*/
- public <T> void removeObserver(Observer<T> observer, Class<T> eventType)
+ public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
ArrayList<EventObserver<?>> observers = registeredObservers.get(eventType);
for (int i = 0; i < observers.size(); i++)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-28 08:25:21 UTC (rev 191)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-28 10:51:40 UTC (rev 192)
@@ -95,6 +95,8 @@
final int prime = 31;
int result = 1;
result = prime * result
+ + ((eventBindings == null) ? 0 : eventBindings.hashCode());
+ result = prime * result
+ ((eventType == null) ? 0 : eventType.hashCode());
result = prime * result + ((observer == null) ? 0 : observer.hashCode());
return result;
@@ -113,6 +115,12 @@
if (getClass() != obj.getClass())
return false;
EventObserver<?> other = (EventObserver<?>) obj;
+ if (eventBindings == null)
+ {
+ if (other.eventBindings != null)
+ return false;
+ } else if (!eventBindings.equals(other.eventBindings))
+ return false;
if (eventType == null)
{
if (other.eventType != null)
16 years, 1 month
[webbeans-commits] Webbeans SVN: r191 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-28 04:25:21 -0400 (Tue, 28 Oct 2008)
New Revision: 191
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
Log:
Context tests
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-28 08:17:00 UTC (rev 190)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-10-28 08:25:21 UTC (rev 191)
@@ -11,7 +11,37 @@
{
assert false;
}
+
+ @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ public void testAddContext()
+ {
+ assert false;
+ }
+ @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ public void testGetContextWithNoActiveContextsFails()
+ {
+ assert false;
+ }
+
+ @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ public void testGetContextWithTooManyActiveContextsFails()
+ {
+ assert false;
+ }
+
+ @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ public void testGetContextWithNoRegisteredContextsFails()
+ {
+ assert false;
+ }
+
+ @Test(groups={"manager"}) @SpecAssertion(section="8.6")
+ public void testGetContextReturnsActiveContext()
+ {
+ assert false;
+ }
+
@Test(groups={"manager", "ejb3"}) @SpecAssertion(section="4.8")
public void testManagerLookupInJndi()
{
16 years, 1 month
[webbeans-commits] Webbeans SVN: r190 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-28 04:17:00 -0400 (Tue, 28 Oct 2008)
New Revision: 190
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
Log:
Context support for manager
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 2008-10-28 07:15:16 UTC (rev 189)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-28 08:17:00 UTC (rev 190)
@@ -3,11 +3,13 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.webbeans.AmbiguousDependencyException;
+import javax.webbeans.ContextNotActiveException;
import javax.webbeans.DeploymentException;
import javax.webbeans.Observer;
import javax.webbeans.Production;
@@ -29,20 +31,38 @@
import org.jboss.webbeans.injectable.Injectable;
import org.jboss.webbeans.injectable.ResolverInjectable;
import org.jboss.webbeans.util.ClientProxy;
+import org.jboss.webbeans.util.MapWrapper;
public class ManagerImpl implements Manager
{
-
+ private class ContextMap extends MapWrapper<Class<? extends Annotation>, List<Context>>
+ {
+
+ public ContextMap()
+ {
+ super(new HashMap<Class<? extends Annotation>, List<Context>>());
+ }
+
+ public List<Context> get(Class<? extends Annotation> key)
+ {
+ return (List<Context>) super.get(key);
+ }
+
+ }
+
private List<Class<? extends Annotation>> enabledDeploymentTypes;
private ModelManager modelManager;
private EjbManager ejbLookupManager;
private EventBus eventBus;
private ResolutionManager resolutionManager;
+ private ContextMap contextMap;
private Set<Bean<?>> beans;
public ManagerImpl(List<Class<? extends Annotation>> enabledDeploymentTypes)
{
+ contextMap = new ContextMap();
+ // TODO Are there any contexts that should be initialized here?
initEnabledDeploymentTypes(enabledDeploymentTypes);
this.modelManager = new ModelManager();
this.ejbLookupManager = new EjbManager();
@@ -51,22 +71,20 @@
this.resolutionManager = new ResolutionManager(this);
}
- private void initEnabledDeploymentTypes(
- List<Class<? extends Annotation>> enabledDeploymentTypes)
+ private void initEnabledDeploymentTypes(List<Class<? extends Annotation>> enabledDeploymentTypes)
{
this.enabledDeploymentTypes = new ArrayList<Class<? extends Annotation>>();
if (enabledDeploymentTypes == null)
{
this.enabledDeploymentTypes.add(0, Standard.class);
this.enabledDeploymentTypes.add(1, Production.class);
- } else
+ }
+ else
{
this.enabledDeploymentTypes.addAll(enabledDeploymentTypes);
- if (!this.enabledDeploymentTypes.get(0).equals(
- Standard.class))
+ if (!this.enabledDeploymentTypes.get(0).equals(Standard.class))
{
- throw new DeploymentException(
- "@Standard must be the lowest precedence deployment type");
+ throw new DeploymentException("@Standard must be the lowest precedence deployment type");
}
}
}
@@ -83,8 +101,7 @@
}
- public <T> Set<Method> resolveDisposalMethods(Class<T> apiType,
- Annotation... bindingTypes)
+ public <T> Set<Method> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
{
return new HashSet<Method>();
}
@@ -109,18 +126,16 @@
return ejbLookupManager;
}
- public <T> Set<Bean<T>> resolveByType(Class<T> type,
- Annotation... bindingTypes)
+ public <T> Set<Bean<T>> resolveByType(Class<T> type, Annotation... bindingTypes)
{
return resolveByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
}
- public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType,
- Annotation... bindingTypes)
+ public <T> Set<Bean<T>> resolveByType(TypeLiteral<T> apiType, Annotation... bindingTypes)
{
return resolveByType(new ResolverInjectable<T>(apiType, bindingTypes, getModelManager()));
}
-
+
private <T> Set<Bean<T>> resolveByType(Injectable<T, ?> injectable)
{
Set<Bean<T>> beans = getResolutionManager().get(injectable);
@@ -132,7 +147,7 @@
{
return beans;
}
-
+
}
public ResolutionManager getResolutionManager()
@@ -147,7 +162,14 @@
public Manager addContext(Context context)
{
- // TODO Auto-generated method stub
+ List<Context> sameScopeTypeContexts = contextMap.get(context.getScopeType());
+ if (sameScopeTypeContexts == null)
+ {
+ sameScopeTypeContexts = new ArrayList<Context>();
+ contextMap.put(context.getScopeType(), sameScopeTypeContexts);
+ }
+ sameScopeTypeContexts.add(context);
+ // TODO: why manager? fluent interfaces?
return this;
}
@@ -163,15 +185,13 @@
return null;
}
- public <T> Manager addObserver(Observer<T> observer, Class<T> eventType,
- Annotation... bindings)
+ public <T> Manager addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
// TODO Auto-generated method stub
return this;
}
- public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType,
- Annotation... bindings)
+ public <T> Manager addObserver(Observer<T> observer, TypeLiteral<T> eventType, Annotation... bindings)
{
// TODO Auto-generated method stub
return this;
@@ -185,8 +205,30 @@
public Context getContext(Class<? extends Annotation> scopeType)
{
- // TODO Auto-generated method stub
- return null;
+ List<Context> contexts = contextMap.get(scopeType);
+ if (contexts == null)
+ {
+ throw new ContextNotActiveException("No contexts for " + scopeType.getName());
+ }
+ // TODO performance? Just flag found=true and continue loop, failing when
+ // found=already true etc?
+ List<Context> activeContexts = new ArrayList<Context>();
+ for (Context context : contexts)
+ {
+ if (context.isActive())
+ {
+ activeContexts.add(context);
+ }
+ }
+ if (activeContexts.isEmpty())
+ {
+ throw new ContextNotActiveException("No active contexts for scope type " + scopeType.getName());
+ }
+ if (activeContexts.size() > 1)
+ {
+ throw new IllegalArgumentException("More than one context active for scope type " + scopeType.getName());
+ }
+ return activeContexts.get(0);
}
public <T> T getInstance(Bean<T> bean)
@@ -228,7 +270,7 @@
{
return getInstanceByType(new ResolverInjectable<T>(type, bindingTypes, getModelManager()));
}
-
+
private <T> T getInstanceByType(Injectable<T, ?> injectable)
{
Set<Bean<T>> beans = resolveByType(injectable);
@@ -253,8 +295,6 @@
}
}
}
-
-
public <T> Manager removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
@@ -273,15 +313,13 @@
return getResolutionManager().get(name);
}
- public List<Decorator> resolveDecorators(Set<Class<?>> types,
- Annotation... bindingTypes)
+ public List<Decorator> resolveDecorators(Set<Class<?>> types, Annotation... bindingTypes)
{
// TODO Auto-generated method stub
return null;
}
- public List<Interceptor> resolveInterceptors(InterceptionType type,
- Annotation... interceptorBindings)
+ public List<Interceptor> resolveInterceptors(InterceptionType type, Annotation... interceptorBindings)
{
// TODO Auto-generated method stub
return null;
16 years, 1 month
[webbeans-commits] Webbeans SVN: r189 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-10-28 03:15:16 -0400 (Tue, 28 Oct 2008)
New Revision: 189
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
Log:
context hierarchy changes
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-10-28 00:54:40 UTC (rev 188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/AbstractContext.java 2008-10-28 07:15:16 UTC (rev 189)
@@ -3,7 +3,6 @@
import java.lang.annotation.Annotation;
import java.util.HashMap;
-import javax.webbeans.ContextNotActiveException;
import javax.webbeans.manager.Bean;
import javax.webbeans.manager.Context;
import javax.webbeans.manager.Manager;
@@ -21,7 +20,7 @@
public abstract class AbstractContext implements Context
{
- private class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
+ protected class BeanMap extends MapWrapper<Bean<? extends Object>, Object>
{
public BeanMap()
@@ -37,50 +36,18 @@
}
- private BeanMap beans;
+ protected BeanMap beans;
private Class<? extends Annotation> scopeType;
- private boolean active;
+ protected boolean active;
public AbstractContext(Class<? extends Annotation> scopeType)
{
this.scopeType = scopeType;
beans = new BeanMap();
- active = true;
}
- public <T> T get(Bean<T> bean, boolean create)
- {
- if (!active)
- {
- throw new ContextNotActiveException();
- }
-
- if (beans == null)
- {
- // Context has been destroyed
- return null;
- }
-
- T instance = beans.get(bean);
-
- if (instance != null)
- {
- return instance;
- }
+ public abstract <T> T get(Bean<T> bean, boolean create);
- if (!create)
- {
- return null;
- }
-
- // TODO should bean creation be synchronized?
-
- instance = bean.create();
-
- beans.put(bean, instance);
- return instance;
- }
-
public Class<? extends Annotation> getScopeType()
{
return scopeType;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-28 00:54:40 UTC (rev 188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/DependentContext.java 2008-10-28 07:15:16 UTC (rev 189)
@@ -2,7 +2,9 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.ContextNotActiveException;
import javax.webbeans.Dependent;
+import javax.webbeans.manager.Bean;
public class DependentContext extends PseudoContext
{
@@ -10,12 +12,23 @@
public DependentContext(Class<? extends Annotation> scopeType)
{
super(Dependent.class);
+ active = false;
}
@Override
+ public <T> T get(Bean<T> bean, boolean create)
+ {
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
+
+ return create == false ? null : bean.create();
+ }
+
+ @Override
public String toString()
{
return "Dependent context";
}
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-28 00:54:40 UTC (rev 188)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/NormalContext.java 2008-10-28 07:15:16 UTC (rev 189)
@@ -2,12 +2,49 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.ContextNotActiveException;
+import javax.webbeans.manager.Bean;
+
public abstract class NormalContext extends AbstractContext
{
public NormalContext(Class<? extends Annotation> scopeType)
{
super(scopeType);
+ active = true;
}
+
+ public <T> T get(Bean<T> bean, boolean create)
+ {
+ if (!active)
+ {
+ throw new ContextNotActiveException();
+ }
+
+ if (beans == null)
+ {
+ // Context has been destroyed
+ return null;
+ }
+
+ T instance = beans.get(bean);
+
+ if (instance != null)
+ {
+ return instance;
+ }
+ if (!create)
+ {
+ return null;
+ }
+
+ // TODO should bean creation be synchronized?
+
+ instance = bean.create();
+
+ beans.put(bean, instance);
+ return instance;
+ }
+
}
16 years, 1 month
[webbeans-commits] Webbeans SVN: r188 - in ri/trunk/webbeans-ri: src/main/java/org/jboss/webbeans/event and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 20:54:40 -0400 (Mon, 27 Oct 2008)
New Revision: 188
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
ri/trunk/webbeans-ri/testng.xml
Log:
Enable event tests
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -1,8 +1,6 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collection;
@@ -79,7 +77,7 @@
eventBindings.addAll(this.getBindingTypes());
addAnnotationBindings(eventBindings, bindings);
Type[] observerTypeArguments = Reflections.getActualTypeArguements(observer.getClass());
- webBeansManager.addObserver(observer, (Class<T>)observerTypeArguments[0], bindings);
+ webBeansManager.addObserver(observer, (Class<T>) observerTypeArguments[0], bindings);
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/bean/EventBeanModel.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -116,6 +116,12 @@
}
@Override
+ protected void checkDeploymentType()
+ {
+ // No - op
+ }
+
+ @Override
protected void initName()
{
// No name per 7.4
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -55,7 +55,7 @@
* {@link org.jboss.webbeans.event.DeferredEventNotification#beforeCompletion()}
* .
*/
- @Test(groups="eventbus")
+ @Test(groups="deferredEvent")
public final void testBeforeCompletion() throws Exception
{
// When the transaction is committed, the beforeCompletion() method is
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -23,7 +23,7 @@
assert false;
}
- @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "observerMethod"}) @SpecAssertion(section="8.3")
public void testInstanceUsedForObserverMethodNotShared()
{
assert false;
@@ -53,7 +53,7 @@
assert false;
}
- @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "observerMethod"}) @SpecAssertion(section="8.3")
public void testContextIsActiveWhenInvokingObserverMethod()
{
assert false;
@@ -138,7 +138,7 @@
assert false;
}
- @Test(groups={"contexts", "eventbus"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "observerMethod"}) @SpecAssertion(section="8.3")
public void testDependentsDestroyedWhenObserverMethodEvaluationCompletes()
{
assert false;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBeanModelTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -51,7 +51,7 @@
/**
* The name should always be null since this type of bean is not allowed to have a name.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "event")
public void testName()
{
assert eventBeanModel.getName() == null;
@@ -60,7 +60,7 @@
/**
* The scope type should always be @Dependent
*/
- @Test(groups = "eventbus")
+ @Test(groups = "event")
public void testScopeType()
{
assert eventBeanModel.getScopeType().equals(Dependent.class);
@@ -69,13 +69,13 @@
/**
* The deployment type should always be @Standard
*/
- @Test(groups = "eventbus")
+ @Test(groups = "event")
public void testDeploymentType()
{
assert eventBeanModel.getDeploymentType().equals(Standard.class);
}
- @Test(groups = "eventbus")
+ @Test(groups = "event")
public void testApiTypes()
{
Set<Class<?>> apis = eventBeanModel.getApiTypes();
@@ -86,7 +86,7 @@
}
}
- @Test(groups = "eventbus")
+ @Test(groups = "event")
public void testConstructor()
{
BeanConstructor<EventImpl<DangerCall>> constructor = eventBeanModel.getConstructor();
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -26,7 +26,7 @@
* @author David Allen
*
*/
-@SpecVersion("20081024-PDR")
+@SpecVersion("PDR")
public class EventBusTest extends AbstractTest
{
public class AnObserver<T> implements Observer<T>
@@ -42,7 +42,7 @@
* Tests adding an observer to the event bus and verified that it can still
* be retrieved for a corresponding event.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "observerMethod")
public void testAddObserver()
{
EventBus eventBus = new EventBus();
@@ -67,7 +67,7 @@
* Tests the remove operation and verifies that the observer is no longer
* registered for events.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "observerMethod")
public void testRemoveObserver()
{
EventBus eventBus = new EventBus();
@@ -80,7 +80,7 @@
/**
* Tests the deferred event feature associated with transactions.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "deferredEvent")
public void testDeferEvent()
{
// Setup a transaction manager for this test and inject into the event bus
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -3,10 +3,10 @@
import javax.webbeans.Observer;
import org.jboss.webbeans.event.EventObserver;
+import org.jboss.webbeans.test.beans.DangerCall;
import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.RoleBinding;
import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
-import org.jboss.webbeans.test.beans.DangerCall;
import org.testng.annotations.Test;
/**
@@ -17,7 +17,7 @@
* @author David Allen
*
*/
-@SpecVersion("20081024-PDR")
+@SpecVersion("PDR")
public class EventObserverTest
{
public class AnObserver<T> implements Observer<T>
@@ -32,7 +32,7 @@
* Tests different annotation literals as event bindings to make sure the wrapper
* properly detects when an observer matches the given event bindings.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "event")
@SpecAssertion(section = "7.7.1")
public void testIsObserverInterested()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -13,11 +13,11 @@
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.Synchronous;
import org.jboss.webbeans.test.annotations.Tame;
+import org.jboss.webbeans.test.beans.DangerCall;
import org.jboss.webbeans.test.bindings.FishStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.RiverFishStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.SynchronousAnnotationLiteral;
import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
-import org.jboss.webbeans.test.beans.DangerCall;
import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.util.Reflections;
import org.testng.annotations.BeforeMethod;
@@ -29,7 +29,7 @@
* @author David Allen
*
*/
-@SpecVersion("20081024-PDR")
+@SpecVersion("PDR")
public class EventTest
{
private MockManagerImpl manager = null;
@@ -62,7 +62,7 @@
* instantiated implementation.
*/
@SuppressWarnings("unchecked")
- @Test(groups = "eventbus")
+ @Test(groups = "event")
@SpecAssertion(section = "7.6")
public void testFireEvent()
{
@@ -106,7 +106,7 @@
* Tests the {@link Event#observe(javax.webbeans.Observer, Annotation...)}
* method with a locally instantiated implementation.
*/
- @Test(groups = "eventbus")
+ @Test(groups = "event")
@SpecAssertion(section = "7.6")
public void testObserve()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -74,7 +74,7 @@
* {@link org.jboss.webbeans.event.ObserverImpl#notify(javax.webbeans.Container, java.lang.Object)}
* .
*/
- @Test(groups = "eventbus") @SpecAssertion(section={"7.5.7"})
+ @Test(groups = "observerMethod") @SpecAssertion(section={"7.5.7"})
public final void testNotify() throws Exception
{
AnObserver observerInstance = new AnObserver();
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-10-28 00:54:40 UTC (rev 188)
@@ -100,7 +100,7 @@
assert false;
}
- @Test(groups="eventbus") @SpecAssertion(section="3.2.4")
+ @Test(groups="observerMethod") @SpecAssertion(section="3.2.4")
public void testBeanDeclaredInXmlIgnoresObserverMethodDeclaredInJava()
{
assert false;
@@ -199,7 +199,7 @@
new SimpleBeanModel<Chicken>(new SimpleAnnotatedType<Chicken>(Chicken.class), getEmptyAnnotatedType(Chicken.class), manager);
}
- @Test(expectedExceptions=DefinitionException.class, groups="eventbus") @SpecAssertion(section="3.2.5.1")
+ @Test(expectedExceptions=DefinitionException.class, groups="observerMethod") @SpecAssertion(section="3.2.5.1")
public void testConstructorHasObservesParameter()
{
new SimpleBeanModel<Chicken>(new SimpleAnnotatedType<Chicken>(Chicken.class), getEmptyAnnotatedType(Chicken.class), manager);
Modified: ri/trunk/webbeans-ri/testng.xml
===================================================================
--- ri/trunk/webbeans-ri/testng.xml 2008-10-28 00:41:01 UTC (rev 187)
+++ ri/trunk/webbeans-ri/testng.xml 2008-10-28 00:54:40 UTC (rev 188)
@@ -10,7 +10,8 @@
<exclude name="deployment" />
<exclude name="disposalMethod" />
<exclude name="producerMethod" />
- <exclude name="eventbus" />
+ <exclude name="observerMethod" />
+ <exclude name="deferredEvent" />
<exclude name="injection" />
<exclude name="ejb3" />
<exclude name="annotationDefinition" />
16 years, 1 month
[webbeans-commits] Webbeans SVN: r187 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/injectable and 8 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 20:41:01 -0400 (Mon, 27 Oct 2008)
New Revision: 187
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Expensive.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingAnnotationMember.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingArrayTypeMember.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Halibut.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RoundWhitefish.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingAnnotationMemberAnnotationLiteral.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingArrayTypeMemberAnnotationLiteral.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ExpensiveAnnotationLiteral.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FishFarm.java
Log:
Remaining tests for Chapter 4
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -58,7 +58,7 @@
private void registerInjectionPoint(Injectable<?, ?> injectable)
{
- resolvedInjectionPoints.put(injectable, retainHighestPrecedenceBeans(injectable.getMatchingBeans(manager.getBeans()), manager.getEnabledDeploymentTypes()));
+ resolvedInjectionPoints.put(injectable, retainHighestPrecedenceBeans(injectable.getMatchingBeans(manager.getBeans(), manager.getModelManager()), manager.getEnabledDeploymentTypes()));
}
public void clear()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/Injectable.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -8,7 +8,9 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.ModelManager;
import org.jboss.webbeans.introspector.AnnotatedItem;
+import org.jboss.webbeans.model.BindingTypeModel;
/**
* Abstraction of java reflection for Web Beans, represent's something that can
@@ -60,12 +62,12 @@
return annotatedItem;
}
- public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> beans)
+ public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> beans, ModelManager modelManager)
{
Set<Bean<?>> resolvedBeans = new HashSet<Bean<?>>();
for (Bean<?> bean : beans)
{
- if (getAnnotatedItem().isAssignableFrom(bean.getTypes()) && bean.getBindingTypes().containsAll(getBindingTypes()))
+ if (getAnnotatedItem().isAssignableFrom(bean.getTypes()) && containsAllBindingBindingTypes(bean.getBindingTypes(), modelManager))
{
resolvedBeans.add(bean);
}
@@ -96,6 +98,32 @@
return 0;
}
+ private boolean containsAllBindingBindingTypes(Set<Annotation> bindingTypes, ModelManager modelManager)
+ {
+ for (Annotation bindingType : getBindingTypes())
+ {
+ BindingTypeModel<?> bindingTypeModel = modelManager.getBindingTypeModel(bindingType.annotationType());
+ if (bindingTypeModel.getNonBindingTypes().size() > 0)
+ {
+ boolean matchFound = false;
+ for (Annotation otherBindingType : bindingTypes)
+ {
+ if (bindingTypeModel.isEqual(bindingType, otherBindingType))
+ {
+ matchFound = true;
+ }
+ }
+ if (!matchFound)
+ {
+ return false;
+ }
+ }
+ else if (!bindingTypes.contains(bindingType))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
-
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableParameterWrapper.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -6,6 +6,7 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.ModelManager;
public class InjectableParameterWrapper<T> extends InjectableParameter<T>
{
@@ -24,9 +25,9 @@
}
@Override
- public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans)
+ public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans, ModelManager modelManager)
{
- return delegate.getMatchingBeans(possibleBeans);
+ return delegate.getMatchingBeans(possibleBeans, modelManager);
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/injectable/InjectableWrapper.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -6,6 +6,7 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.ModelManager;
public class InjectableWrapper<T, S> extends Injectable<T, S>
{
@@ -24,9 +25,9 @@
}
@Override
- public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans)
+ public Set<Bean<?>> getMatchingBeans(Set<Bean<?>> possibleBeans, ModelManager modelManager)
{
- return delegate.getMatchingBeans(possibleBeans);
+ return delegate.getMatchingBeans(possibleBeans, modelManager);
}
@Override
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -12,4 +12,10 @@
*/
public Set<AnnotatedMethod<?>> getMembers();
+ /**
+ * Get all annotation members
+ * @return
+ */
+ public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> annotationType);
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/SimpleAnnotatedAnnotation.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -3,12 +3,16 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
public class SimpleAnnotatedAnnotation<T extends Annotation> extends AbstractAnnotatedItem<T, Class<T>> implements AnnotatedAnnotation<T>
{
+ private Map<Class<? extends Annotation>, Set<AnnotatedMethod<?>>> annotatedMembers;
+
private Class<T> clazz;
private Set<AnnotatedMethod<?>> members;
@@ -51,5 +55,42 @@
members.add(new SimpleAnnotatedMethod<Object>(member));
}
}
+
+ public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> annotationType)
+ {
+ if (annotatedMembers == null)
+ {
+ initAnnotatedMembers();
+ }
+
+ if (!annotatedMembers.containsKey(annotationType))
+ {
+ return new HashSet<AnnotatedMethod<?>>();
+ }
+ else
+ {
+ return annotatedMembers.get(annotationType);
+ }
+ }
+
+ private void initAnnotatedMembers()
+ {
+ if (members == null)
+ {
+ initMembers();
+ }
+ annotatedMembers = new HashMap<Class<? extends Annotation>, Set<AnnotatedMethod<?>>>();
+ for (AnnotatedMethod<?> member : members)
+ {
+ for (Annotation annotation : member.getAnnotations())
+ {
+ if (!annotatedMembers.containsKey(annotation))
+ {
+ annotatedMembers.put(annotation.annotationType(), new HashSet<AnnotatedMethod<?>>());
+ }
+ annotatedMembers.get(annotation.annotationType()).add(member);
+ }
+ }
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/AnnotationModel.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -55,4 +55,10 @@
return annotatedAnnotation;
}
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + "[" + getAnnotatedAnnotation().toString() + "]";
+ }
+
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/model/BindingTypeModel.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -19,9 +19,15 @@
package org.jboss.webbeans.model;
import java.lang.annotation.Annotation;
+import java.util.Set;
import javax.webbeans.BindingType;
+import javax.webbeans.DefinitionException;
+import javax.webbeans.NonBinding;
+import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.util.Reflections;
+
/**
*
* Model of a binding type
@@ -32,15 +38,74 @@
public class BindingTypeModel<T extends Annotation> extends AnnotationModel<T>
{
- public BindingTypeModel(Class<T> scope)
+ private Set<AnnotatedMethod<?>> nonBindingTypes;
+ private Integer hashCode;
+
+ public BindingTypeModel(Class<T> type)
{
- super(scope);
+ super(type);
}
@Override
+ protected void init()
+ {
+ super.init();
+ initNonBindingTypes();
+ checkArrayAndAnnotationValuedMembers();
+ }
+
+ private void checkArrayAndAnnotationValuedMembers()
+ {
+ for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
+ {
+ if ((Reflections.isArrayType(annotatedMethod.getType()) || Annotation.class.isAssignableFrom(annotatedMethod.getType())) && !nonBindingTypes.contains(annotatedMethod))
+ {
+ throw new DefinitionException("Member of array type or annotation type must be annotated @NonBinding " + annotatedMethod);
+ }
+ }
+
+ }
+
+ @Override
protected Class<? extends Annotation> getMetaAnnotation()
{
return BindingType.class;
}
+ public boolean hasNonBindingTypes()
+ {
+ return nonBindingTypes.size() > 0;
+ }
+
+ public Set<AnnotatedMethod<?>> getNonBindingTypes()
+ {
+ return nonBindingTypes;
+ }
+
+ protected void initNonBindingTypes()
+ {
+ nonBindingTypes = getAnnotatedAnnotation().getAnnotatedMembers(NonBinding.class);
+ }
+
+ public boolean isEqual(Annotation instance, Annotation other)
+ {
+ if (instance.annotationType().equals(getType()) && other.annotationType().equals(getType()))
+ {
+ for (AnnotatedMethod<?> annotatedMethod : getAnnotatedAnnotation().getMembers())
+ {
+ if (!nonBindingTypes.contains(annotatedMethod))
+ {
+ Object thisValue = Reflections.invokeAndWrap(annotatedMethod.getDelegate(), instance);
+ Object thatValue = Reflections.invokeAndWrap(annotatedMethod.getDelegate(), other);
+ if (!thisValue.equals(thatValue))
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -3,6 +3,7 @@
import java.beans.Introspector;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
@@ -12,7 +13,9 @@
import java.util.List;
import java.util.Set;
+import javax.webbeans.ExecutionException;
+
public class Reflections
{
@@ -232,4 +235,25 @@
{
return type.getTypeParameters().length > 0;
}
+
+ public static Object invokeAndWrap(Method method, Object instance)
+ {
+ try
+ {
+ return method.invoke(instance);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw new ExecutionException("Error checking value of member method " + method.getName() + " on " + method.getDeclaringClass(), e);
+ }
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -1,5 +1,6 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.test.util.Util.createSimpleWebBean;
import static org.jboss.webbeans.test.util.Util.getEmptyAnnotatedType;
import java.util.HashSet;
@@ -17,6 +18,7 @@
import org.jboss.webbeans.injectable.InjectableField;
import org.jboss.webbeans.introspector.SimpleAnnotatedType;
import org.jboss.webbeans.model.bean.SimpleBeanModel;
+import org.jboss.webbeans.test.annotations.Expensive;
import org.jboss.webbeans.test.annotations.Whitefish;
import org.jboss.webbeans.test.beans.Animal;
import org.jboss.webbeans.test.beans.AnimalFarmer;
@@ -24,7 +26,9 @@
import org.jboss.webbeans.test.beans.Farmer;
import org.jboss.webbeans.test.beans.FishFarm;
import org.jboss.webbeans.test.beans.Haddock;
+import org.jboss.webbeans.test.beans.Halibut;
import org.jboss.webbeans.test.beans.Plaice;
+import org.jboss.webbeans.test.beans.RoundWhitefish;
import org.jboss.webbeans.test.beans.Salmon;
import org.jboss.webbeans.test.beans.ScottishFish;
import org.jboss.webbeans.test.beans.ScottishFishFarmer;
@@ -32,7 +36,10 @@
import org.jboss.webbeans.test.beans.Sole;
import org.jboss.webbeans.test.beans.Tuna;
import org.jboss.webbeans.test.bindings.AnotherDeploymentTypeAnnotationLiteral;
+import org.jboss.webbeans.test.bindings.BindingTypeWithBindingAnnotationMemberAnnotationLiteral;
+import org.jboss.webbeans.test.bindings.BindingTypeWithBindingArrayTypeMemberAnnotationLiteral;
import org.jboss.webbeans.test.bindings.ChunkyAnnotationLiteral;
+import org.jboss.webbeans.test.bindings.ExpensiveAnnotationLiteral;
import org.testng.annotations.Test;
@SpecVersion("PDR")
@@ -56,7 +63,7 @@
Bean<Tuna> tunaBean = new BeanImpl<Tuna>(new SimpleBeanModel<Tuna>(new SimpleAnnotatedType<Tuna>(Tuna.class), getEmptyAnnotatedType(Tuna.class), super.manager), manager);
Set<Bean<?>> beans = new HashSet<Bean<?>>();
beans.add(tunaBean);
- Set<Bean<?>> possibleTargets = tunaField.getMatchingBeans(beans);
+ Set<Bean<?>> possibleTargets = tunaField.getMatchingBeans(beans, manager.getModelManager());
assert possibleTargets.size() == 1;
assert possibleTargets.contains(tunaBean);
}
@@ -84,7 +91,7 @@
beans.add(codBean);
beans.add(salmonBean);
beans.add(soleBean);
- Set<Bean<?>> possibleTargets = whiteScottishFishField.getMatchingBeans(beans);
+ Set<Bean<?>> possibleTargets = whiteScottishFishField.getMatchingBeans(beans, manager.getModelManager());
assert possibleTargets.size() == 2;
assert possibleTargets.contains(codBean);
assert possibleTargets.contains(soleBean);
@@ -101,7 +108,7 @@
beans.add(codBean);
beans.add(salmonBean);
beans.add(soleBean);
- Set<Bean<?>> possibleTargets = whiteChunkyFishField.getMatchingBeans(beans);
+ Set<Bean<?>> possibleTargets = whiteChunkyFishField.getMatchingBeans(beans, manager.getModelManager());
assert possibleTargets.size() == 1;
assert possibleTargets.contains(codBean);
}
@@ -115,7 +122,7 @@
Set<Bean<?>> beans = new HashSet<Bean<?>>();
beans.add(seaBassBean);
beans.add(haddockBean);
- Set<Bean<?>> possibleTargets = animalField.getMatchingBeans(beans);
+ Set<Bean<?>> possibleTargets = animalField.getMatchingBeans(beans, manager.getModelManager());
assert possibleTargets.size() == 2;
assert possibleTargets.contains(seaBassBean);
assert possibleTargets.contains(haddockBean);
@@ -201,7 +208,7 @@
assert manager.resolveByType(new TypeLiteral<Farmer<ScottishFish>>(){}).contains(scottishFishFarmerBean);
}
- @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ @Test(groups={"resolution", "producerMethod"}) @SpecAssertion(section="4.9.2")
public void testResolveByTypeWithArray()
{
assert false;
@@ -230,9 +237,36 @@
}
@Test(groups="resolution") @SpecAssertion(section="4.9.2")
- public void testResolveByTypeNonBindingParameters()
+ public void testResolveByTypeWithNonBindingMembers() throws Exception
{
- assert false;
+ InjectableField<Animal> veryExpensiveWhitefishField = new InjectableField<Animal>(FishFarm.class.getDeclaredField("veryExpensiveWhitefish"));
+ Bean<Halibut> halibutBean = createSimpleWebBean(Halibut.class, manager);
+ Bean<RoundWhitefish> roundWhiteFishBean = createSimpleWebBean(RoundWhitefish.class, manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ manager.addBean(halibutBean);
+ manager.addBean(roundWhiteFishBean);
+ manager.addBean(soleBean);
+
+ ResolutionManager resolutionManager = manager.getResolutionManager();
+ resolutionManager.addInjectionPoint(veryExpensiveWhitefishField);
+
+ Set<Bean<Animal>> beans = manager.resolveByType(Animal.class, new ExpensiveAnnotationLiteral()
+ {
+
+ public int cost()
+ {
+ return 60;
+ }
+
+ public boolean veryExpensive()
+ {
+ return true;
+ }
+
+ }, new AnnotationLiteral<Whitefish>() {});
+ assert beans.size() == 2;
+ assert beans.contains(halibutBean);
+ assert beans.contains(roundWhiteFishBean);
}
@Test(groups="resolution") @SpecAssertion(section="4.9.2")
@@ -272,13 +306,39 @@
@Test(groups="resolution", expectedExceptions=DefinitionException.class) @SpecAssertion(section="4.9.2.1")
public void testArrayValuedAnnotationMemberWithoutNonBinding()
{
- assert false;
+ manager.resolveByType(Animal.class, new BindingTypeWithBindingArrayTypeMemberAnnotationLiteral() {
+
+ public boolean[] bool()
+ {
+ return new boolean[0];
+ }
+
+ });
}
@Test(groups="resolution", expectedExceptions=DefinitionException.class) @SpecAssertion(section="4.9.2.1")
public void testAnnotationValuedAnnotationMemberWithoutNonBinding()
{
- assert false;
+ manager.resolveByType(Animal.class, new BindingTypeWithBindingAnnotationMemberAnnotationLiteral()
+ {
+
+ public Expensive expensive()
+ {
+ return new ExpensiveAnnotationLiteral()
+ {
+ public int cost()
+ {
+ return 0;
+ }
+
+ public boolean veryExpensive()
+ {
+ return false;
+ }
+ };
+ }
+
+ });
}
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Expensive.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Expensive.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Expensive.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,28 @@
+package org.jboss.webbeans.test.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+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.BindingType;
+import javax.webbeans.NonBinding;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface Expensive
+{
+
+ boolean veryExpensive();
+
+ @NonBinding
+ int cost();
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Expensive.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingAnnotationMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingAnnotationMember.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingAnnotationMember.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,26 @@
+package org.jboss.webbeans.test.annotations.broken;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+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.BindingType;
+
+import org.jboss.webbeans.test.annotations.Expensive;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface BindingTypeWithBindingAnnotationMember
+{
+
+ Expensive expensive();
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingAnnotationMember.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingArrayTypeMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingArrayTypeMember.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingArrayTypeMember.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,24 @@
+package org.jboss.webbeans.test.annotations.broken;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+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.BindingType;
+
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+@BindingType
+public @interface BindingTypeWithBindingArrayTypeMember
+{
+
+ boolean[] bool();
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/broken/BindingTypeWithBindingArrayTypeMember.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FishFarm.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FishFarm.java 2008-10-27 22:25:28 UTC (rev 186)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/FishFarm.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -4,6 +4,7 @@
import javax.webbeans.Production;
import org.jboss.webbeans.test.annotations.Chunky;
+import org.jboss.webbeans.test.annotations.Expensive;
import org.jboss.webbeans.test.annotations.Whitefish;
@Production
@@ -34,4 +35,7 @@
@Current
private Farmer<ScottishFish> scottishFishFarmer;
+ @Expensive(cost=60, veryExpensive=true) @Whitefish
+ private Animal veryExpensiveWhitefish;
+
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Halibut.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Halibut.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Halibut.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.beans;
+
+import org.jboss.webbeans.test.annotations.Expensive;
+import org.jboss.webbeans.test.annotations.Whitefish;
+
+@Expensive(cost=50, veryExpensive=true)
+@Whitefish
+public class Halibut implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Halibut.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RoundWhitefish.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RoundWhitefish.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RoundWhitefish.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.beans;
+
+import org.jboss.webbeans.test.annotations.Expensive;
+import org.jboss.webbeans.test.annotations.Whitefish;
+
+@Expensive(cost=60, veryExpensive=true)
+@Whitefish
+public class RoundWhitefish implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/RoundWhitefish.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingAnnotationMemberAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingAnnotationMemberAnnotationLiteral.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingAnnotationMemberAnnotationLiteral.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+
+import org.jboss.webbeans.test.annotations.broken.BindingTypeWithBindingAnnotationMember;
+
+public abstract class BindingTypeWithBindingAnnotationMemberAnnotationLiteral extends AnnotationLiteral<BindingTypeWithBindingAnnotationMember> implements BindingTypeWithBindingAnnotationMember
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingAnnotationMemberAnnotationLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingArrayTypeMemberAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingArrayTypeMemberAnnotationLiteral.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingArrayTypeMemberAnnotationLiteral.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+
+import org.jboss.webbeans.test.annotations.broken.BindingTypeWithBindingArrayTypeMember;
+
+public abstract class BindingTypeWithBindingArrayTypeMemberAnnotationLiteral extends AnnotationLiteral<BindingTypeWithBindingArrayTypeMember> implements BindingTypeWithBindingArrayTypeMember
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/BindingTypeWithBindingArrayTypeMemberAnnotationLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ExpensiveAnnotationLiteral.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ExpensiveAnnotationLiteral.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ExpensiveAnnotationLiteral.java 2008-10-28 00:41:01 UTC (rev 187)
@@ -0,0 +1,10 @@
+package org.jboss.webbeans.test.bindings;
+
+import javax.webbeans.AnnotationLiteral;
+
+import org.jboss.webbeans.test.annotations.Expensive;
+
+public abstract class ExpensiveAnnotationLiteral extends AnnotationLiteral<Expensive> implements Expensive
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/bindings/ExpensiveAnnotationLiteral.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 1 month
[webbeans-commits] Webbeans SVN: r186 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-10-27 18:25:28 -0400 (Mon, 27 Oct 2008)
New Revision: 186
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
Log:
Removed unnecessary code from EventObserver wrapper and cleaned up more event classes and unit tests; deferred event notifications are parameterized again.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -10,10 +10,10 @@
* @author David Allen
*
*/
-public class DeferredEventNotification implements Synchronization
+public class DeferredEventNotification<T> implements Synchronization
{
- private Observer<?> observer;
- private Object event;
+ private Observer<T> observer;
+ private T event;
/**
* Creates a new deferred event notifier.
@@ -22,7 +22,7 @@
* @param observer The observer to be notified
* @param event The event being fired
*/
- public DeferredEventNotification(Object event, Observer<?> observer)
+ public DeferredEventNotification(T event, Observer<T> observer)
{
this.observer = observer;
this.event = event;
@@ -31,7 +31,7 @@
/**
* @return the observer
*/
- public final Observer<?> getObserver()
+ public final Observer<T> getObserver()
{
return observer;
}
@@ -44,8 +44,7 @@
public void beforeCompletion()
{
// Execute the observer method on the event
- // TODO It is impossible to use a template variable for this observer, so notify cannot be called
- //observer.notify(event);
+ observer.notify(event);
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -40,7 +40,7 @@
/**
* Adds an observer to the event bus so that it receives event notifications.
*
- * @param o
+ * @param observer
* The observer that should receive events
*/
public <T> void addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
@@ -64,13 +64,13 @@
* The WebBeans container
* @param event
* The event object to deliver
- * @param o
+ * @param observer
* The observer to receive the event
* @throws SystemException
* @throws IllegalStateException
* @throws RollbackException
*/
- public void deferEvent(Object event, Observer<?> o)
+ public <T> void deferEvent(T event, Observer<T> observer)
throws SystemException, IllegalStateException, RollbackException
{
if (transactionManager != null)
@@ -78,8 +78,8 @@
// Get the current transaction associated with the thread
Transaction t = transactionManager.getTransaction();
if (t != null)
- t.registerSynchronization(new DeferredEventNotification(
- event, o));
+ t.registerSynchronization(new DeferredEventNotification<T>(
+ event, observer));
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -16,6 +16,8 @@
import javax.webbeans.Observer;
import javax.webbeans.manager.Manager;
+import org.jboss.webbeans.util.Reflections;
+
/**
* Implementation of the {@link Event} interface used for the container provided
* Web Bean to be injected for an observable event. See section 7.4 of the JSR
@@ -72,28 +74,12 @@
public void observe(Observer<T> observer, Annotation... bindings)
{
// Register the observer with the web beans manager
- Class<T> eventArgumentClazz = null;
- try
- {
- // TODO Fix me: Reflection can only get type variables, not the arguments used elsewhere
- Field eventTypeField = this.getClass().getDeclaredField("eventType");
- ParameterizedType genericType = (ParameterizedType) eventTypeField.getGenericType();
- Type[] eventTypeArguments = genericType.getActualTypeArguments();
- eventArgumentClazz = (Class<T>) eventTypeArguments[0];
- } catch (SecurityException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchFieldException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
Set<Annotation> eventBindings = new HashSet<Annotation>();
eventBindings.addAll(this.getBindingTypes());
addAnnotationBindings(eventBindings, bindings);
- webBeansManager.addObserver(observer, eventArgumentClazz, bindings);
+ Type[] observerTypeArguments = Reflections.getActualTypeArguements(observer.getClass());
+ webBeansManager.addObserver(observer, (Class<T>)observerTypeArguments[0], bindings);
}
/**
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -12,7 +12,9 @@
* code or by the Web Beans Manager for annotated observer methods. In all
* cases, this wrapper provides consistent object identification and hashing
* based on the type of event being observed and any event binding types
- * specified.
+ * specified. It also provides a query method to quickly determine if a
+ * set of event bindings are exactly what the observer is interested in receiving.
+ * </p>
*
* @author David Allen
*
@@ -20,11 +22,9 @@
public class EventObserver<T>
{
- // TODO This probably should be an injectable or annotated item
-
- private final Class<T> eventType;
- private final Annotation[] eventBindings;
- private final Observer<T> observer;
+ private final Class<T> eventType;
+ private final List<Annotation> eventBindings;
+ private final Observer<T> observer;
/**
* Constructs a new wrapper for an observer.
@@ -41,7 +41,7 @@
{
this.observer = observer;
this.eventType = eventType;
- this.eventBindings = eventBindings;
+ this.eventBindings = Arrays.asList(eventBindings);
}
/**
@@ -55,7 +55,7 @@
/**
* @return the eventBindings
*/
- public final Annotation[] getEventBindings()
+ public final List<Annotation> getEventBindings()
{
return eventBindings;
}
@@ -77,32 +77,12 @@
*/
public boolean isObserverInterested(Annotation... bindings)
{
- // TODO This logic needs to be in injectable
+ // Simply check that all event bindings specified by the observer are
+ // in the list provided.
+ List<Annotation> bindingsArray = Arrays.asList(bindings);
boolean result = true;
- // Check each binding specified by this observer against those provided
- if (this.eventBindings.length > 0)
- {
- if ((bindings != null) && (bindings.length > 0))
- {
- List<Annotation> bindingsArray = Arrays.asList(bindings);
- for (Annotation annotation : this.eventBindings)
- {
- int eventBindingIndex = bindingsArray.indexOf(annotation);
- if (eventBindingIndex >= 0)
- {
- //result = annotationsMatch(annotation, bindingsArray.get(eventBindingIndex));
- result = annotation.equals(bindingsArray.get(eventBindingIndex));
- } else
- {
- result = false;
- break;
- }
- }
- } else
- {
- result = false;
- }
- }
+ if (!this.eventBindings.isEmpty())
+ result = bindingsArray.containsAll(this.eventBindings);
return result;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -80,7 +80,7 @@
Observer<Event> observer = new MockObserverImpl<Event>(tuna, om, Event.class);
((MockObserverImpl<Event>) observer).setInstance(observerInstance);
Event event = new Event();
- DeferredEventNotification deferredNotification = new DeferredEventNotification(event, observer);
+ DeferredEventNotification<Event> deferredNotification = new DeferredEventNotification<Event>(event, observer);
deferredNotification.beforeCompletion();
assert observerInstance.notified;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-27 21:55:36 UTC (rev 185)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-27 22:25:28 UTC (rev 186)
@@ -38,7 +38,7 @@
{
Observer<DangerCall> observer = new AnObserver<DangerCall>();
EventObserver<DangerCall> wrappedObserver = new EventObserver<DangerCall>(observer, DangerCall.class, new TameAnnotationLiteral());
- assert wrappedObserver.getEventBindings().length == 1;
+ assert wrappedObserver.getEventBindings().size() == 1;
assert wrappedObserver.isObserverInterested(new TameAnnotationLiteral());
assert !wrappedObserver.isObserverInterested(new AnimalStereotypeAnnotationLiteral());
assert !wrappedObserver.isObserverInterested();
@@ -46,7 +46,7 @@
// Perform some tests with binding values (7.7.1)
wrappedObserver = new EventObserver<DangerCall>(observer, DangerCall.class, new RoleBinding("Admin"));
- assert wrappedObserver.getEventBindings().length == 1;
+ assert wrappedObserver.getEventBindings().size() == 1;
assert wrappedObserver.isObserverInterested(new RoleBinding("Admin"));
assert !wrappedObserver.isObserverInterested(new RoleBinding("User"));
}
16 years, 1 month
[webbeans-commits] Webbeans SVN: r185 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-10-27 17:55:36 -0400 (Mon, 27 Oct 2008)
New Revision: 185
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
Log:
support resolution of Object.class
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 2008-10-27 19:46:07 UTC (rev 184)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-10-27 21:55:36 UTC (rev 185)
@@ -140,7 +140,7 @@
return resolutionManager;
}
- public Set<Bean<?>> getBeans()
+ public Set<Bean<? extends Object>> getBeans()
{
return beans;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java 2008-10-27 19:46:07 UTC (rev 184)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ResolutionManager.java 2008-10-27 21:55:36 UTC (rev 185)
@@ -81,8 +81,15 @@
public <T> Set<Bean<T>> get(Injectable<T, ?> key)
{
- resolveBeans();
- return resolvedInjectionPoints.get(key);
+ if (key.getType().equals(Object.class))
+ {
+ return (Set<Bean<T>>) (Set) manager.getBeans();
+ }
+ else
+ {
+ resolveBeans();
+ return resolvedInjectionPoints.get(key);
+ }
}
public Set<Bean<?>> get(String name)
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 19:46:07 UTC (rev 184)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-10-27 21:55:36 UTC (rev 185)
@@ -253,9 +253,20 @@
}
@Test(groups="resolution") @SpecAssertion(section="4.9.2")
- public void testResolveObject()
+ public void testResolveObject() throws Exception
{
- assert false;
+ Bean<Cod> plaiceBean = new BeanImpl<Cod>(new SimpleBeanModel<Cod>(new SimpleAnnotatedType<Cod>(Cod.class), getEmptyAnnotatedType(Cod.class), super.manager), manager);
+ Bean<Salmon> salmonBean = new BeanImpl<Salmon>(new SimpleBeanModel<Salmon>(new SimpleAnnotatedType<Salmon>(Salmon.class), getEmptyAnnotatedType(Salmon.class), super.manager), manager);
+ Bean<Sole> soleBean = new BeanImpl<Sole>(new SimpleBeanModel<Sole>(new SimpleAnnotatedType<Sole>(Sole.class), getEmptyAnnotatedType(Sole.class), super.manager), manager);
+ manager.addBean(plaiceBean);
+ manager.addBean(salmonBean);
+ manager.addBean(soleBean);
+
+ assert manager.resolveByType(Object.class).size() == 3;
+ assert manager.resolveByType(Object.class).contains(plaiceBean);
+ assert manager.resolveByType(Object.class).contains(salmonBean);
+ assert manager.resolveByType(Object.class).contains(soleBean);
+
}
@Test(groups="resolution", expectedExceptions=DefinitionException.class) @SpecAssertion(section="4.9.2.1")
16 years, 1 month
[webbeans-commits] Webbeans SVN: r184 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-10-27 15:46:07 -0400 (Mon, 27 Oct 2008)
New Revision: 184
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
Log:
Completed the unit test for EventBus and cleaned up some of the other event related code.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -10,10 +10,10 @@
* @author David Allen
*
*/
-public class DeferredEventNotification<T> implements Synchronization
+public class DeferredEventNotification implements Synchronization
{
- private Observer<T> observer;
- private T event;
+ private Observer<?> observer;
+ private Object event;
/**
* Creates a new deferred event notifier.
@@ -22,12 +22,20 @@
* @param observer The observer to be notified
* @param event The event being fired
*/
- public DeferredEventNotification(T event, Observer<T> observer)
+ public DeferredEventNotification(Object event, Observer<?> observer)
{
this.observer = observer;
this.event = event;
}
+ /**
+ * @return the observer
+ */
+ public final Observer<?> getObserver()
+ {
+ return observer;
+ }
+
public void afterCompletion(int arg0)
{
// The event is already delivered before completion
@@ -36,7 +44,8 @@
public void beforeCompletion()
{
// Execute the observer method on the event
- observer.notify(event);
+ // TODO It is impossible to use a template variable for this observer, so notify cannot be called
+ //observer.notify(event);
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventBus.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -11,10 +11,9 @@
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import javax.webbeans.Current;
import javax.webbeans.Observer;
-import org.jboss.webbeans.util.JNDI;
-
/**
* The event bus is where observers are registered and events are fired.
*
@@ -24,31 +23,27 @@
public class EventBus
{
private final Map<Class<?>, ArrayList<EventObserver<?>>> registeredObservers;
- private final TransactionManager tm;
- private String tmName = "java:/TransactionManager";
+
+ @Current
+ private TransactionManager transactionManager;
/**
* Initializes a new instance of the EventBus. This includes looking up the
* transaction manager which is needed to defer events till the end of a
- * transaction. TODO Should be able to configure JNDI name of transaction
- * manager
- *
+ * transaction.
*/
public EventBus()
{
registeredObservers = new HashMap<Class<?>, ArrayList<EventObserver<?>>>();
- tm = JNDI.lookup(tmName, TransactionManager.class);
}
/**
* Adds an observer to the event bus so that it receives event notifications.
- * The event information is already encapsulated as part of the observer.
*
* @param o
* The observer that should receive events
*/
- public <T> void addObserver(Observer<T> o, Class<T> eventType,
- Annotation... bindings)
+ public <T> void addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
ArrayList<EventObserver<?>> l = registeredObservers.get(eventType);
if (l == null)
@@ -56,7 +51,7 @@
l = new ArrayList<EventObserver<?>>();
registeredObservers.put(eventType, l);
}
- EventObserver<T> eventObserver = new EventObserver<T>(o, eventType, bindings);
+ EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
if (!l.contains(eventObserver))
l.add(eventObserver);
}
@@ -75,15 +70,15 @@
* @throws IllegalStateException
* @throws RollbackException
*/
- public void deferEvent(Object event, Observer<Object> o)
+ public void deferEvent(Object event, Observer<?> o)
throws SystemException, IllegalStateException, RollbackException
{
- if (tm != null)
+ if (transactionManager != null)
{
// Get the current transaction associated with the thread
- Transaction t = tm.getTransaction();
+ Transaction t = transactionManager.getTransaction();
if (t != null)
- t.registerSynchronization(new DeferredEventNotification<Object>(
+ t.registerSynchronization(new DeferredEventNotification(
event, o));
}
}
@@ -104,8 +99,8 @@
Set<Observer<T>> results = new HashSet<Observer<T>>();
for (EventObserver<?> observer : registeredObservers.get(event.getClass()))
{
- // TODO Verify bindings match before adding
- results.add((Observer<T>) observer.getObserver());
+ if (observer.isObserverInterested(bindings))
+ results.add((Observer<T>) observer.getObserver());
}
return results;
}
@@ -129,4 +124,13 @@
}
}
}
+
+ /**
+ * TODO Remove this once injection of the transaction manager works.
+ * @param transactionManager the TransactionManager to set
+ */
+ public final void setTransactionManager(TransactionManager transactionManager)
+ {
+ this.transactionManager = transactionManager;
+ }
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -1,7 +1,6 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
@@ -81,7 +80,7 @@
// TODO This logic needs to be in injectable
boolean result = true;
// Check each binding specified by this observer against those provided
- if (this.eventBindings != null)
+ if (this.eventBindings.length > 0)
{
if ((bindings != null) && (bindings.length > 0))
{
@@ -91,52 +90,62 @@
int eventBindingIndex = bindingsArray.indexOf(annotation);
if (eventBindingIndex >= 0)
{
- // TODO Use annotation equality
- result = annotationsMatch(annotation, bindingsArray.get(eventBindingIndex));
+ //result = annotationsMatch(annotation, bindingsArray.get(eventBindingIndex));
+ result = annotation.equals(bindingsArray.get(eventBindingIndex));
} else
{
result = false;
break;
}
}
+ } else
+ {
+ result = false;
}
}
return result;
}
- /**
- * Compares two annotation bindings for equivalence. This means that all member values, if any,
- * must match.
- * @param annotation The first annotation to compare
- * @param annotation2 The second annotation to compare
- * @return
- *
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
*/
- private boolean annotationsMatch(Annotation annotation,
- Annotation annotation2)
+ @Override
+ public int hashCode()
{
- boolean result = true;
- if (annotation.getClass().getDeclaredMethods().length > 0)
- {
- for (Method annotationValue : annotation.getClass().getDeclaredMethods())
- {
- try
- {
- if (!annotationValue.invoke(annotation).equals(annotationValue.invoke(annotation2)))
- {
- result = false;
- break;
- }
- } catch (Exception e)
- {
- result = false;
- break;
- }
- }
- }
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((eventType == null) ? 0 : eventType.hashCode());
+ result = prime * result + ((observer == null) ? 0 : observer.hashCode());
return result;
}
- // TODO Implement equals and hashCode
-
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ EventObserver<?> other = (EventObserver<?>) obj;
+ if (eventType == null)
+ {
+ if (other.eventType != null)
+ return false;
+ } else if (!eventType.equals(other.eventType))
+ return false;
+ if (observer == null)
+ {
+ if (other.observer != null)
+ return false;
+ } else if (!observer.equals(other.observer))
+ return false;
+ return true;
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeferredEventNotificationTest.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -80,7 +80,7 @@
Observer<Event> observer = new MockObserverImpl<Event>(tuna, om, Event.class);
((MockObserverImpl<Event>) observer).setInstance(observerInstance);
Event event = new Event();
- DeferredEventNotification<Event> deferredNotification = new DeferredEventNotification<Event>(event, observer);
+ DeferredEventNotification deferredNotification = new DeferredEventNotification(event, observer);
deferredNotification.beforeCompletion();
assert observerInstance.notified;
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventBusTest.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -1,12 +1,190 @@
package org.jboss.webbeans.test;
+import java.util.Set;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+import javax.webbeans.Observer;
+
+import org.jboss.webbeans.event.DeferredEventNotification;
+import org.jboss.webbeans.event.EventBus;
+import org.jboss.webbeans.test.beans.DangerCall;
+import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
+import org.testng.annotations.Test;
+
/**
* Tests for the EventBus implementation used by the Web Beans RI.
*
* @author David Allen
*
*/
+@SpecVersion("20081024-PDR")
public class EventBusTest extends AbstractTest
{
+ public class AnObserver<T> implements Observer<T>
+ {
+ public void notify(T event)
+ {
+ }
+ }
+ private Synchronization registeredSynch;
+
+ /**
+ * Tests adding an observer to the event bus and verified that it can still
+ * be retrieved for a corresponding event.
+ */
+ @Test(groups = "eventbus")
+ public void testAddObserver()
+ {
+ EventBus eventBus = new EventBus();
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ eventBus.addObserver(observer, DangerCall.class);
+ DangerCall event = new DangerCall();
+
+ Set<Observer<DangerCall>> observerSet = eventBus.getObservers(event);
+ assert observerSet.size() == 1;
+ assert observerSet.iterator().next().equals(observer);
+
+ // Add another observer for the same event, but with an event binding
+ observer = new AnObserver<DangerCall>();
+ eventBus.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
+ observerSet = eventBus.getObservers(event);
+ assert observerSet.size() == 1;
+ observerSet = eventBus.getObservers(event, new TameAnnotationLiteral());
+ assert observerSet.size() == 2;
+ }
+
+ /**
+ * Tests the remove operation and verifies that the observer is no longer
+ * registered for events.
+ */
+ @Test(groups = "eventbus")
+ public void testRemoveObserver()
+ {
+ EventBus eventBus = new EventBus();
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ eventBus.addObserver(observer, DangerCall.class);
+ eventBus.removeObserver(observer, DangerCall.class);
+ assert eventBus.getObservers(new DangerCall()).isEmpty();
+ }
+
+ /**
+ * Tests the deferred event feature associated with transactions.
+ */
+ @Test(groups = "eventbus")
+ public void testDeferEvent()
+ {
+ // Setup a transaction manager for this test and inject into the event bus
+ TransactionManager tm = new TransactionManager() {
+ public void begin() throws NotSupportedException, SystemException
+ {
+ }
+
+ public void commit() throws RollbackException,
+ HeuristicMixedException, HeuristicRollbackException,
+ SecurityException, IllegalStateException, SystemException
+ {
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return 0;
+ }
+
+ public Transaction getTransaction() throws SystemException
+ {
+ return new Transaction() {
+
+ public void commit() throws RollbackException,
+ HeuristicMixedException, HeuristicRollbackException,
+ SecurityException, IllegalStateException, SystemException
+ {
+ }
+
+ public boolean delistResource(XAResource arg0, int arg1)
+ throws IllegalStateException, SystemException
+ {
+ return false;
+ }
+
+ public boolean enlistResource(XAResource arg0)
+ throws RollbackException, IllegalStateException,
+ SystemException
+ {
+ return false;
+ }
+
+ public int getStatus() throws SystemException
+ {
+ return 0;
+ }
+
+ public void registerSynchronization(Synchronization synchronization)
+ throws RollbackException, IllegalStateException,
+ SystemException
+ {
+ registeredSynch = synchronization;
+ }
+
+ public void rollback() throws IllegalStateException,
+ SystemException
+ {
+ }
+
+ public void setRollbackOnly() throws IllegalStateException,
+ SystemException
+ {
+ }
+
+ };
+ }
+
+ public void resume(Transaction arg0)
+ throws InvalidTransactionException, IllegalStateException,
+ SystemException
+ {
+ }
+
+ public void rollback() throws IllegalStateException,
+ SecurityException, SystemException
+ {
+ }
+
+ public void setRollbackOnly() throws IllegalStateException,
+ SystemException
+ {
+ }
+
+ public void setTransactionTimeout(int arg0) throws SystemException
+ {
+ }
+
+ public Transaction suspend() throws SystemException
+ {
+ return null;
+ }
+
+ };
+ EventBus eventBus = new EventBus();
+ eventBus.setTransactionManager(tm);
+ Observer<DangerCall> observer = new AnObserver<DangerCall>();
+ try
+ {
+ eventBus.deferEvent(new DangerCall(), observer);
+ } catch (Exception e)
+ {
+ }
+
+ assert this.registeredSynch != null;
+ assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
+ }
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-27 18:47:42 UTC (rev 183)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventObserverTest.java 2008-10-27 19:46:07 UTC (rev 184)
@@ -41,6 +41,7 @@
assert wrappedObserver.getEventBindings().length == 1;
assert wrappedObserver.isObserverInterested(new TameAnnotationLiteral());
assert !wrappedObserver.isObserverInterested(new AnimalStereotypeAnnotationLiteral());
+ assert !wrappedObserver.isObserverInterested();
assert wrappedObserver.isObserverInterested(new TameAnnotationLiteral(), new RoleBinding("Admin"));
// Perform some tests with binding values (7.7.1)
16 years, 1 month