[webbeans-commits] Webbeans SVN: r357 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test/mock and 1 other directory.
webbeans-commits at lists.jboss.org
webbeans-commits at lists.jboss.org
Mon Nov 24 04:11:48 EST 2008
Author: nickarls
Date: 2008-11-24 04:11:48 -0500 (Mon, 24 Nov 2008)
New Revision: 357
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/ObserverImpl.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockObserverImpl.java
Log:
minor events stuff
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-11-24 08:29:16 UTC (rev 356)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-11-24 09:11:48 UTC (rev 357)
@@ -12,8 +12,8 @@
* 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. It also provides a query method to quickly determine if a
- * set of event bindings are exactly what the observer is interested in receiving.
+ * 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
@@ -21,23 +21,19 @@
*/
public class EventObserver<T>
{
-
- private final Class<T> eventType;
+
+ private final Class<T> eventType;
private final List<Annotation> eventBindings;
- private final Observer<T> observer;
+ private final Observer<T> observer;
/**
* Constructs a new wrapper for an observer.
*
- * @param observer
- * The observer
- * @param eventType
- * The class of event being observed
- * @param eventBindings
- * The array of annotation event bindings, if any
+ * @param observer The observer
+ * @param eventType The class of event being observed
+ * @param eventBindings The array of annotation event bindings, if any
*/
- public EventObserver(final Observer<T> observer, final Class<T> eventType,
- final Annotation... eventBindings)
+ public EventObserver(final Observer<T> observer, final Class<T> eventType, final Annotation... eventBindings)
{
this.observer = observer;
this.eventType = eventType;
@@ -82,11 +78,15 @@
List<Annotation> bindingsArray = Arrays.asList(bindings);
boolean result = true;
if (!this.eventBindings.isEmpty())
+ {
result = bindingsArray.containsAll(this.eventBindings);
+ }
return result;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see java.lang.Object#hashCode()
*/
@Override
@@ -94,45 +94,65 @@
{
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 + ((eventBindings == null) ? 0 : eventBindings.hashCode());
+ result = prime * result + ((eventType == null) ? 0 : eventType.hashCode());
result = prime * result + ((observer == null) ? 0 : observer.hashCode());
return result;
}
- /* (non-Javadoc)
+ /*
+ * (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 (eventBindings == null)
{
if (other.eventBindings != null)
return false;
- } else if (!eventBindings.equals(other.eventBindings))
+ }
+ else if (!eventBindings.equals(other.eventBindings))
+ {
return false;
+
+ }
if (eventType == null)
{
if (other.eventType != null)
+ {
return false;
- } else if (!eventType.equals(other.eventType))
+ }
+ }
+ else if (!eventType.equals(other.eventType))
+ {
return false;
+ }
if (observer == null)
{
if (other.observer != null)
+ {
return false;
- } else if (!observer.equals(other.observer))
+ }
+ }
+ else if (!observer.equals(other.observer))
+ {
return false;
+ }
return true;
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-11-24 08:29:16 UTC (rev 356)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-11-24 09:11:48 UTC (rev 357)
@@ -6,7 +6,6 @@
import javax.webbeans.AfterTransactionFailure;
import javax.webbeans.AfterTransactionSuccess;
import javax.webbeans.BeforeTransactionCompletion;
-import javax.webbeans.Current;
import javax.webbeans.Observer;
import org.jboss.webbeans.ManagerImpl;
@@ -16,9 +15,9 @@
/**
* <p>
* Reference implementation for the Observer interface, which represents an
- * observer method. Each observer method has an event type which is the class of the
- * event object being observed, and event binding types that are annotations applied to
- * the event parameter to narrow the event notifications delivered.
+ * observer method. Each observer method has an event type which is the class of
+ * the event object being observed, and event binding types that are annotations
+ * applied to the event parameter to narrow the event notifications delivered.
* </p>
*
* @author David Allen
@@ -30,36 +29,32 @@
private EventBean<T> eventBean;
private final AnnotatedMethod<Object> observerMethod;
private final Class<T> eventType;
+ private boolean transactional;
+ private ManagerImpl manager;
/**
- * Injected before notify is called. This can only work with the RI since
- * InjectableMethod requires this specific implementation.
- * TODO Determine if the impl can be injected here.
- */
- @Current
- protected ManagerImpl manager;
-
- /**
* Creates an Observer which describes and encapsulates an observer method
* (7.5).
*
- * @param componentModel
- * The model for the component which defines the observer method
- * @param observer
- * The observer method to notify
- * @param eventType
- * The type of event being observed
- * @param beanModel The model for the bean which defines the
+ * @param componentModel The model for the component which defines the
* observer method
* @param observer The observer method to notify
* @param eventType The type of event being observed
+ * @param beanModel The model for the bean which defines the observer method
+ * @param observer The observer method to notify
+ * @param eventType The type of event being observed
*/
- public ObserverImpl(final EventBean<T> eventBean,
- final AnnotatedMethod<Object> observer, final Class<T> eventType)
+ public ObserverImpl(ManagerImpl manager, final EventBean<T> eventBean, final AnnotatedMethod<Object> observer, final Class<T> eventType)
{
+ this.manager = manager;
this.eventBean = eventBean;
this.observerMethod = observer;
this.eventType = eventType;
+ transactional =
+ !observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty() ||
+ !observerMethod.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty() ||
+ !observerMethod.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty() ||
+ !observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty();
}
/*
@@ -101,12 +96,9 @@
// Return the most specialized instance of the component
return manager.getInstanceByType(eventBean.getType(), eventBean.getBindingTypes().toArray(new Annotation[0]));
}
-
- public boolean isTransactional() {
- return
- !observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty() ||
- !observerMethod.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty() ||
- !observerMethod.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty() ||
- !observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty();
+
+ public boolean isTransactional()
+ {
+ return transactional;
}
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockObserverImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockObserverImpl.java 2008-11-24 08:29:16 UTC (rev 356)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockObserverImpl.java 2008-11-24 09:11:48 UTC (rev 357)
@@ -1,33 +1,35 @@
package org.jboss.webbeans.test.mock;
+import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.bean.EventBean;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedMethod;
/**
* An implementation used for unit testing only.
+ *
* @author David Allen
- *
+ *
*/
-public class MockObserverImpl<T> extends ObserverImpl<T> {
+public class MockObserverImpl<T> extends ObserverImpl<T>
+{
private Object specializedInstance;
-
-
- public MockObserverImpl(EventBean<T> beanModel,
- AnnotatedMethod<Object> observer, Class<T> eventType)
+ public MockObserverImpl(ManagerImpl manager, EventBean<T> beanModel, AnnotatedMethod<Object> observer, Class<T> eventType)
{
- super(beanModel, observer, eventType);
+ super(manager, beanModel, observer, eventType);
}
@Override
- protected final Object getInstance() {
+ protected final Object getInstance()
+ {
return specializedInstance;
}
/**
* The most specialized instance of this observer type.
+ *
* @param instance The instance to use for testing
*/
public final void setInstance(Object instance)
More information about the weld-commits
mailing list