[webbeans-commits] Webbeans SVN: r362 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-25 14:47:31 -0500 (Tue, 25 Nov 2008)
New Revision: 362
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java
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/ObserverImpl.java
Log:
more on transactional observers
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-11-24 10:54:23 UTC (rev 361)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-11-25 19:47:31 UTC (rev 362)
@@ -1,20 +1,21 @@
package org.jboss.webbeans.event;
+import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.webbeans.Observer;
/**
- * A synchronization object which will deliver the event to the observer
- * after the JTA transaction currently in effect is committed.
+ * A synchronization object which will deliver the event to the observer after
+ * the JTA transaction currently in effect is committed.
*
* @author David Allen
- *
+ *
*/
public class DeferredEventNotification<T> implements Synchronization
{
- private Observer<T> observer;
+ private ObserverImpl<T> observer;
private T event;
-
+
/**
* Creates a new deferred event notifier.
*
@@ -24,7 +25,7 @@
*/
public DeferredEventNotification(T event, Observer<T> observer)
{
- this.observer = observer;
+ this.observer = (ObserverImpl<T>) observer;
this.event = event;
}
@@ -36,15 +37,34 @@
return observer;
}
- public void afterCompletion(int arg0)
+ public void afterCompletion(int status)
{
- // The event is already delivered before completion
+ if (observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_COMPLETION))
+ {
+ observer.notify(event);
+ }
+ switch (status)
+ {
+ case Status.STATUS_COMMITTED:
+ if (observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_SUCCESS))
+ {
+ observer.notify();
+ }
+ break;
+ case Status.STATUS_ROLLEDBACK:
+ if (observer.isInterestedInTransactionPhase(TransactionObservationPhase.AFTER_FAILURE))
+ {
+ observer.notify();
+ }
+ break;
+ }
}
public void beforeCompletion()
{
- // Execute the observer method on the event
- observer.notify(event);
+ if (observer.isInterestedInTransactionPhase(TransactionObservationPhase.BEFORE_COMPLETION))
+ {
+ observer.notify(event);
+ }
}
-
}
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 10:54:23 UTC (rev 361)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-11-25 19:47:31 UTC (rev 362)
@@ -1,6 +1,8 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
import javax.webbeans.AfterTransactionCompletion;
import javax.webbeans.AfterTransactionFailure;
@@ -26,11 +28,10 @@
*/
public class ObserverImpl<T> implements Observer<T>
{
-
private EventBean<T> eventBean;
private final AnnotatedMethod<Object> observerMethod;
private final Class<T> eventType;
- private boolean transactional;
+ private Set<TransactionObservationPhase> transactionObservationPhases;
private boolean conditional;
private ManagerImpl manager;
@@ -52,10 +53,31 @@
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();
+ initTransactionObservationPhases();
conditional = !observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
}
+ private void initTransactionObservationPhases()
+ {
+ transactionObservationPhases = new HashSet<TransactionObservationPhase>();
+ if (observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty())
+ {
+ transactionObservationPhases.add(TransactionObservationPhase.BEFORE_COMPLETION);
+ }
+ if (observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty())
+ {
+ transactionObservationPhases.add(TransactionObservationPhase.AFTER_COMPLETION);
+ }
+ if (observerMethod.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty())
+ {
+ transactionObservationPhases.add(TransactionObservationPhase.AFTER_FAILURE);
+ }
+ if (observerMethod.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty())
+ {
+ transactionObservationPhases.add(TransactionObservationPhase.AFTER_SUCCESS);
+ }
+ }
+
/*
* (non-Javadoc)
*
@@ -87,8 +109,9 @@
/**
* Uses the container to retrieve the most specialized instance of this
* observer.
- * @param conditional
*
+ * @param conditional
+ *
* @return the most specialized instance
*/
protected Object getInstance(boolean conditional)
@@ -99,11 +122,17 @@
public boolean isTransactional()
{
- return transactional;
+ return !transactionObservationPhases.isEmpty();
}
public boolean isConditional()
{
return conditional;
}
+
+ public boolean isInterestedInTransactionPhase(TransactionObservationPhase transactionObservationPhase)
+ {
+ return transactionObservationPhases.contains(transactionObservationPhase);
+ }
+
}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/TransactionObservationPhase.java 2008-11-25 19:47:31 UTC (rev 362)
@@ -0,0 +1,6 @@
+package org.jboss.webbeans.event;
+
+public enum TransactionObservationPhase
+{
+ BEFORE_COMPLETION, AFTER_COMPLETION, AFTER_FAILURE, AFTER_SUCCESS
+}
15 years, 12 months
[webbeans-commits] Webbeans SVN: r361 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test/mock and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 05:54:23 -0500 (Mon, 24 Nov 2008)
New Revision: 361
Modified:
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:
stubs for conditional observer support
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 10:30:52 UTC (rev 360)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-11-24 10:54:23 UTC (rev 361)
@@ -6,6 +6,7 @@
import javax.webbeans.AfterTransactionFailure;
import javax.webbeans.AfterTransactionSuccess;
import javax.webbeans.BeforeTransactionCompletion;
+import javax.webbeans.IfExists;
import javax.webbeans.Observer;
import org.jboss.webbeans.ManagerImpl;
@@ -30,6 +31,7 @@
private final AnnotatedMethod<Object> observerMethod;
private final Class<T> eventType;
private boolean transactional;
+ private boolean conditional;
private ManagerImpl manager;
/**
@@ -50,11 +52,8 @@
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();
+ transactional = !observerMethod.getAnnotatedParameters(AfterTransactionCompletion.class).isEmpty() || !observerMethod.getAnnotatedParameters(AfterTransactionFailure.class).isEmpty() || !observerMethod.getAnnotatedParameters(AfterTransactionSuccess.class).isEmpty() || !observerMethod.getAnnotatedParameters(BeforeTransactionCompletion.class).isEmpty();
+ conditional = !observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
}
/*
@@ -76,7 +75,7 @@
public void notify(final T event)
{
// Get the most specialized instance of the component
- Object instance = getInstance();
+ Object instance = getInstance(isConditional());
if (instance != null)
{
// TODO replace event parameter
@@ -88,10 +87,11 @@
/**
* Uses the container to retrieve the most specialized instance of this
* observer.
+ * @param conditional
*
* @return the most specialized instance
*/
- protected Object getInstance()
+ protected Object getInstance(boolean conditional)
{
// Return the most specialized instance of the component
return manager.getInstanceByType(eventBean.getType(), eventBean.getBindingTypes().toArray(new Annotation[0]));
@@ -99,6 +99,11 @@
public boolean isTransactional()
{
- return transactional;
+ return transactional;
}
+
+ public boolean isConditional()
+ {
+ return conditional;
+ }
}
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 10:30:52 UTC (rev 360)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockObserverImpl.java 2008-11-24 10:54:23 UTC (rev 361)
@@ -22,7 +22,7 @@
}
@Override
- protected final Object getInstance()
+ protected final Object getInstance(boolean conditional)
{
return specializedInstance;
}
16 years
[webbeans-commits] Webbeans SVN: r360 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 05:30:52 -0500 (Mon, 24 Nov 2008)
New Revision: 360
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
Log:
minor. brough back for deferEvent for readability
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 10:27:52 UTC (rev 359)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 10:30:52 UTC (rev 360)
@@ -48,7 +48,8 @@
private final Map<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> registeredObservers;
private ManagerImpl manager;
// TODO: can we do this?
- @Resource TransactionManager transactionManager;
+ @Resource
+ TransactionManager transactionManager;
/**
* Initializes a new instance of the EventManager. This includes looking up
@@ -81,7 +82,6 @@
}
}
-
/**
* Resolves the list of observers to be notified for a given event and
* optional event bindings.
@@ -104,7 +104,8 @@
return interestedObservers;
}
- private boolean isTransactionActive() {
+ private boolean isTransactionActive()
+ {
try
{
// TODO: Check NPE conditions;
@@ -113,9 +114,9 @@
catch (SystemException e)
{
return false;
- }
+ }
}
-
+
/**
* Notifies each observer immediately of the event unless a transaction is
* currently in progress, in which case a deferred event is created and
@@ -129,16 +130,24 @@
{
for (Observer<T> observer : observers)
{
- if (isTransactionActive() && ((ObserverImpl<?>) observer).isTransactional()) {
- TransactionListener transactionListener = manager.getInstanceByType(TransactionListener.class);
- DeferredEventNotification<T> deferredEvent = new DeferredEventNotification<T>(event, observer);
- transactionListener.registerSynhronization(deferredEvent);
- } else {
+ if (isTransactionActive() && ((ObserverImpl<?>) observer).isTransactional())
+ {
+ deferEvent(event, observer);
+ }
+ else
+ {
observer.notify(event);
}
}
}
+ private <T> void deferEvent(T event, Observer<T> observer)
+ {
+ TransactionListener transactionListener = manager.getInstanceByType(TransactionListener.class);
+ DeferredEventNotification<T> deferredEvent = new DeferredEventNotification<T>(event, observer);
+ transactionListener.registerSynhronization(deferredEvent);
+ }
+
/**
* Removes an observer from the event bus.
*
16 years
[webbeans-commits] Webbeans SVN: r359 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 05:27:52 -0500 (Mon, 24 Nov 2008)
New Revision: 359
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
minor docs + RuntimeException -> DefinitionException
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-24 09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/MetaDataCache.java 2008-11-24 10:27:52 UTC (rev 359)
@@ -66,29 +66,29 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
- buffer.append("Binding types " + bindingTypes.size() + "\n");
+ buffer.append("Binding types: " + bindingTypes.size() + "\n");
int i = 0;
for (Entry<Class<? extends Annotation>, BindingTypeModel<?>> entry : bindingTypes.entrySet())
{
buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
- buffer.append("EJB metadata " + ejbMetaDataMap.size() + "\n");
+ buffer.append("EJB metadata: " + ejbMetaDataMap.size() + "\n");
i = 0;
for (Entry<Class<?>, EjbMetaData<?>> entry : ejbMetaDataMap.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
- buffer.append("Scopes " + scopes.size() + "\n");
+ buffer.append("Scopes: " + scopes.size() + "\n");
i = 0;
for (Entry<Class<? extends Annotation>, ScopeModel<?>> entry : scopes.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
- buffer.append("Stereotypes " + stereotypes.size() + "\n");
+ buffer.append("Stereotypes: " + stereotypes.size() + "\n");
i = 0;
for (Entry<Class<? extends Annotation>, StereotypeModel<?>> entry : stereotypes.entrySet())
{
- buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString());
+ buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
return buffer.toString();
}
@@ -116,6 +116,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Scope model map\n");
+ buffer.append("--------------------\n");
buffer.append(super.toString() + "\n");
return buffer.toString();
}
@@ -143,6 +144,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("Binding type model map\n");
+ buffer.append("--------------------\n");
buffer.append(super.toString() + "\n");
return buffer.toString();
}
@@ -181,6 +183,7 @@
{
StringBuffer buffer = new StringBuffer();
buffer.append("EJB metadata: " + delegate.size() + "\n");
+ buffer.append("--------------------\n");
int i = 0;
for (Entry<Class<?>, EjbMetaData<?>> entry : delegate.entrySet())
{
@@ -228,7 +231,9 @@
public String toString()
{
StringBuffer buffer = new StringBuffer();
+ buffer.append("====================\n");
buffer.append("Metadata cache\n");
+ buffer.append("====================\n");
buffer.append(bindingTypes.toString() + "\n");
buffer.append(ejbMetaDataMap.toString() + "\n");
buffer.append(scopes.toString() + "\n");
@@ -238,6 +243,7 @@
{
buffer.append(++i + " - " + entry.getKey().getName() + ": " + entry.getValue().toString() + "\n");
}
+ buffer.append("====================\n");
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-24 09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-11-24 10:27:52 UTC (rev 359)
@@ -65,6 +65,10 @@
/**
* Helper class for getting deployment type
*
+ * Loops through the enabled deployment types (backwards) and returns the first one
+ * present in the possible deployments type, resulting in the deployment type of
+ * highest priority
+ *
* @param enabledDeploymentTypes The currently enabled deployment types
* @param possibleDeploymentTypes The possible deployment types
* @return The deployment type
@@ -193,7 +197,7 @@
Set<Annotation> xmlDeploymentTypes = null;
if (xmlDeploymentTypes.size() > 1)
{
- throw new RuntimeException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
+ throw new DefinitionException ("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
}
if (xmlDeploymentTypes.size() == 1)
@@ -361,7 +365,7 @@
}
else if (getMergedStereotypes().getPossibleScopeTypes().size() > 1)
{
- throw new RuntimeException("All stereotypes must specify the same scope OR a scope must be specified on the bean");
+ throw new DefinitionException ("All stereotypes must specify the same scope OR a scope must be specified on the bean");
}
this.scopeType = Dependent.class;
log.trace("Using default @Dependent scope");
@@ -379,7 +383,7 @@
{
if (deploymentType == null)
{
- throw new RuntimeException("type: " + getType() + " must specify a deployment type");
+ throw new DefinitionException ("type: " + getType() + " must specify a deployment type");
}
else if (deploymentType.equals(Standard.class) && !STANDARD_WEB_BEAN_CLASSES.contains(getAnnotatedItem().getType()))
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-24 09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-11-24 10:27:52 UTC (rev 359)
@@ -185,7 +185,7 @@
else if (disposalMethods.size() > 1)
{
// TODO List out found disposal methods
- throw new RuntimeException(getLocation() + "Cannot declare multiple disposal methods for this producer method");
+ throw new DefinitionException (getLocation() + "Cannot declare multiple disposal methods for this producer method");
}
}
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-11-24 09:54:56 UTC (rev 358)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-11-24 10:27:52 UTC (rev 359)
@@ -18,13 +18,12 @@
import javax.webbeans.ExecutionException;
-
public class Reflections
{
-
+
public static Class<?> classForName(String name) throws ClassNotFoundException
{
- try
+ try
{
return Thread.currentThread().getContextClassLoader().loadClass(name);
}
@@ -33,35 +32,35 @@
return Class.forName(name);
}
}
-
+
public static String getPropertyName(Method method)
{
String methodName = method.getName();
- if ( methodName.matches("^(get).*") && method.getParameterTypes().length==0 )
+ if (methodName.matches("^(get).*") && method.getParameterTypes().length == 0)
{
- return Introspector.decapitalize( methodName.substring(3) );
+ return Introspector.decapitalize(methodName.substring(3));
}
- else if (methodName.matches("^(is).*") && method.getParameterTypes().length==0 )
+ else if (methodName.matches("^(is).*") && method.getParameterTypes().length == 0)
{
- return Introspector.decapitalize( methodName.substring(2) );
+ return Introspector.decapitalize(methodName.substring(2));
}
else
{
return null;
}
-
+
}
public static boolean isFinal(Class<?> clazz)
{
return Modifier.isFinal(clazz.getModifiers());
}
-
+
public static boolean isFinal(Member member)
{
return Modifier.isFinal(member.getModifiers());
}
-
+
public static boolean isTypeOrAnyMethodFinal(Class<?> type)
{
if (isFinal(type))
@@ -77,44 +76,44 @@
}
return false;
}
-
+
public static boolean isPrimitive(Class<?> type)
{
return type.isPrimitive();
}
-
+
public static boolean isStatic(Class<?> type)
{
return Modifier.isStatic(type.getModifiers());
}
-
+
public static boolean isStatic(Member member)
{
return Modifier.isStatic(member.getModifiers());
}
-
+
public static boolean isAbstract(Class<?> clazz)
{
return Modifier.isAbstract(clazz.getModifiers());
}
-
+
public static boolean isStaticInnerClass(Class<?> clazz)
{
return clazz.isMemberClass() && isStatic(clazz);
}
-
+
public static boolean isNonStaticInnerClass(Class<?> clazz)
{
return clazz.isMemberClass() && !isStatic(clazz);
}
-
+
public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... parameterTypes)
{
try
{
return clazz.getConstructor(parameterTypes);
}
- catch (NoSuchMethodException e)
+ catch (NoSuchMethodException e)
{
return null;
}
@@ -123,8 +122,8 @@
throw new RuntimeException("Error accessing constructor (with parameters " + parameterTypes + ") of " + clazz, e);
}
}
-
- public static List<Method> getMethods(Class<?> clazz, Class<? extends Annotation> annotationType)
+
+ public static List<Method> getMethods(Class<?> clazz, Class<? extends Annotation> annotationType)
{
List<Method> methods = new ArrayList<Method>();
for (Method method : clazz.getMethods())
@@ -136,9 +135,9 @@
}
return methods;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation> annotationType)
+ public static <T> List<Constructor<T>> getAnnotatedConstructors(Class<? extends T> clazz, Class<? extends Annotation> annotationType)
{
List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -150,9 +149,9 @@
}
return constructors;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> parameterAnnotationType)
+ public static <T> List<Constructor<T>> getConstructorsForAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> parameterAnnotationType)
{
List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -170,9 +169,9 @@
}
return constructors;
}
-
+
@SuppressWarnings("unchecked")
- public static <T> List<Constructor<T>> getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> metaAnnotationType)
+ public static <T> List<Constructor<T>> getConstructorsForMetaAnnotatedParameter(Class<? extends T> clazz, Class<? extends Annotation> metaAnnotationType)
{
List<Constructor<T>> constructors = new ArrayList<Constructor<T>>();
for (Constructor<?> constructor : clazz.getConstructors())
@@ -226,12 +225,12 @@
}
return annotationTypeList.size() == 0;
}
-
+
public static Type[] getActualTypeArguments(Class<?> clazz)
{
if (clazz.getGenericSuperclass() instanceof ParameterizedType)
{
- return ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments();
+ return ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments();
}
else
{
@@ -248,7 +247,7 @@
{
return type.getTypeParameters().length > 0;
}
-
+
public static Object invokeAndWrap(Method method, Object instance, Object... parameters)
{
try
@@ -268,7 +267,7 @@
throw new ExecutionException("Error invoking method " + method.getName() + " on " + method.getDeclaringClass(), e);
}
}
-
+
public static void setAndWrap(Field field, Object target, Object value)
{
try
@@ -284,33 +283,44 @@
throw new ExecutionException("Error setting field " + field.getName() + " on " + field.getDeclaringClass(), e);
}
}
-
+
public static Method lookupMethod(Method method, Object instance)
{
for (Class<? extends Object> clazz = instance.getClass(); clazz != Object.class; clazz = clazz.getSuperclass())
{
try
{
- Method targetMethod = clazz.getDeclaredMethod(method.getName(),
- method.getParameterTypes());
+ Method targetMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes());
if (!targetMethod.isAccessible())
{
targetMethod.setAccessible(true);
}
return targetMethod;
- } catch (NoSuchMethodException nsme)
+ }
+ catch (NoSuchMethodException nsme)
{
// Expected, nothing to see here.
}
}
throw new IllegalArgumentException("Method " + method.getName() + " not implemented by instance");
- }
-
- public static boolean isProxy(Object instance)
+ }
+
+ public static boolean isProxy(Object instance)
{
return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
}
-
+
+ /**
+ * Gets the type hierarchy for a class
+ *
+ * A recursive function that adds the class to the set of type and then calls
+ * itself with the suprerclass as paramater until the top of the hierarchy is
+ * reached. For each steps, adds all interfaces of the class to the set.
+ * Since the data structure is a set, duplications are eliminated
+ *
+ * @param clazz The class to examine
+ * @return The set of classes and interfaces in the hierarchy
+ */
public static Set<Class<?>> getTypeHierachy(Class<?> clazz)
{
Set<Class<?>> classes = new HashSet<Class<?>>();
@@ -324,6 +334,6 @@
}
}
return classes;
- }
-
+ }
+
}
16 years
[webbeans-commits] Webbeans SVN: r358 - 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-11-24 04:54:56 -0500 (Mon, 24 Nov 2008)
New Revision: 358
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
Log:
Fixed runtime problem with observer registrations.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 09:11:48 UTC (rev 357)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 09:54:56 UTC (rev 358)
@@ -19,7 +19,6 @@
import java.lang.annotation.Annotation;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -148,14 +147,8 @@
public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
List<EventObserver<?>> observers = registeredObservers.get(eventType);
- for (Iterator<EventObserver<?>> i = observers.iterator(); i.hasNext();)
- {
- if (observer.equals(i.next().getObserver()))
- {
- i.remove();
- break;
- }
- }
+ EventObserver<T> eventObserver = new EventObserver<T>(observer, eventType, bindings);
+ observers.remove(eventObserver);
}
@Override
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 09:11:48 UTC (rev 357)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 09:54:56 UTC (rev 358)
@@ -24,7 +24,7 @@
* Tests for the EventManager implementation used by the Web Beans RI.
*
* @author David Allen
- *
+ *
*/
@SpecVersion("PDR")
public class EventManagerTest extends AbstractTest
@@ -37,7 +37,7 @@
}
private Synchronization registeredSynch;
-
+
/**
* Tests adding an observer to the event bus and verified that it can still
* be retrieved for a corresponding event.
@@ -49,11 +49,11 @@
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class);
DangerCall event = new DangerCall();
-
+
Set<Observer<DangerCall>> observerSet = eventManager.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>();
eventManager.addObserver(observer, DangerCall.class, new TameAnnotationLiteral());
@@ -62,12 +62,12 @@
observerSet = eventManager.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 = {"observerMethod", "broken"})
+ @Test(groups = { "observerMethod" })
public void testRemoveObserver()
{
EventManager eventManager = new EventManager(manager);
@@ -77,114 +77,115 @@
// FIXME CopyOnWrite broke remove, have to check later
assert eventManager.getObservers(new DangerCall()).isEmpty();
}
-
+
/**
* Tests the deferred event feature associated with transactions.
*/
- @Test(groups = {"deferredEvent", "broken"})
+ @Test(groups = { "deferredEvent", "broken" })
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;
-// }
-//
-// };
+ // 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;
+ // }
+ //
+ // };
EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
try
{
// eventManager.deferEvent(new DangerCall(), observer);
- } catch (Exception e)
+ }
+ catch (Exception e)
{
}
assert this.registeredSynch != null;
- assert ((DeferredEventNotification)this.registeredSynch).getObserver().equals(observer);
+ assert ((DeferredEventNotification) this.registeredSynch).getObserver().equals(observer);
}
}
16 years
[webbeans-commits] Webbeans SVN: r357 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test/mock and 1 other directory.
by webbeans-commits@lists.jboss.org
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)
16 years
[webbeans-commits] Webbeans SVN: r356 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 03:29:16 -0500 (Mon, 24 Nov 2008)
New Revision: 356
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
Log:
Unbreak my build, say you parse me again...
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-11-24 08:20:17 UTC (rev 355)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-24 08:29:16 UTC (rev 356)
@@ -87,7 +87,7 @@
{
this.metaDataCache = new MetaDataCache();
this.beans = new CopyOnWriteArrayList<Bean<?>>();
- this.eventManager = new EventManager();
+ this.eventManager = new EventManager(this);
this.resolver = new Resolver(this);
this.proxyPool = new ProxyPool(this);
this.decorators = new HashSet<Decorator>();
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 08:20:17 UTC (rev 355)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-11-24 08:29:16 UTC (rev 356)
@@ -45,7 +45,7 @@
@Test(groups = "observerMethod")
public void testAddObserver()
{
- EventManager eventManager = new EventManager();
+ EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class);
DangerCall event = new DangerCall();
@@ -70,7 +70,7 @@
@Test(groups = {"observerMethod", "broken"})
public void testRemoveObserver()
{
- EventManager eventManager = new EventManager();
+ EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventManager.addObserver(observer, DangerCall.class);
eventManager.removeObserver(observer, DangerCall.class);
@@ -175,11 +175,11 @@
// }
//
// };
- EventManager eventManager = new EventManager();
+ EventManager eventManager = new EventManager(manager);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
try
{
- eventManager.deferEvent(new DangerCall(), observer);
+// eventManager.deferEvent(new DangerCall(), observer);
} catch (Exception e)
{
}
16 years
[webbeans-commits] Webbeans SVN: r355 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 03:20:17 -0500 (Mon, 24 Nov 2008)
New Revision: 355
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java
Log:
Transactional observers modifictions.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 07:36:20 UTC (rev 354)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-11-24 08:20:17 UTC (rev 355)
@@ -27,13 +27,17 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import javax.annotation.Resource;
import javax.transaction.RollbackException;
+import javax.transaction.Status;
import javax.transaction.SystemException;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
-import javax.webbeans.Current;
import javax.webbeans.Observer;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.transaction.TransactionListener;
+
/**
* The event bus is where observers are registered and events are fired.
*
@@ -43,25 +47,25 @@
public class EventManager
{
private final Map<Class<?>, CopyOnWriteArrayList<EventObserver<?>>> registeredObservers;
-
- @Current
- private TransactionManager transactionManager;
+ private ManagerImpl manager;
+ // TODO: can we do this?
+ @Resource TransactionManager transactionManager;
/**
- * Initializes a new instance of the EventManager. This includes looking up the
- * transaction manager which is needed to defer events till the end of a
- * transaction.
+ * Initializes a new instance of the EventManager. This includes looking up
+ * the transaction manager which is needed to defer events till the end of a
+ * transaction.
*/
- public EventManager()
+ public EventManager(ManagerImpl manager)
{
registeredObservers = new ConcurrentHashMap<Class<?>, CopyOnWriteArrayList<EventObserver<?>>>();
+ this.manager = manager;
}
/**
* Adds an observer to the event bus so that it receives event notifications.
*
- * @param observer
- * The observer that should receive events
+ * @param observer The observer that should receive events
*/
public <T> void addObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
@@ -78,28 +82,6 @@
}
}
- /**
- * Defers delivery of an event till the end of the currently active
- * transaction.
- *
- * @param event The event object to deliver
- * @param observer The observer to receive the event
- * @throws SystemException
- * @throws IllegalStateException
- * @throws RollbackException
- */
- public <T> void deferEvent(T event, Observer<T> observer) throws SystemException, IllegalStateException, RollbackException
- {
- if (transactionManager != null)
- {
- // Get the current transaction associated with the thread
- Transaction transaction = transactionManager.getTransaction();
- if (transaction != null)
- {
- transaction.registerSynchronization(new DeferredEventNotification<T>(event, observer));
- }
- }
- }
/**
* Resolves the list of observers to be notified for a given event and
@@ -123,6 +105,18 @@
return interestedObservers;
}
+ private boolean isTransactionActive() {
+ try
+ {
+ // TODO: Check NPE conditions;
+ return transactionManager.getTransaction().getStatus() == Status.STATUS_ACTIVE;
+ }
+ catch (SystemException e)
+ {
+ return false;
+ }
+ }
+
/**
* Notifies each observer immediately of the event unless a transaction is
* currently in progress, in which case a deferred event is created and
@@ -136,30 +130,11 @@
{
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
+ if (isTransactionActive() && ((ObserverImpl<?>) observer).isTransactional()) {
+ TransactionListener transactionListener = manager.getInstanceByType(TransactionListener.class);
+ DeferredEventNotification<T> deferredEvent = new DeferredEventNotification<T>(event, observer);
+ transactionListener.registerSynhronization(deferredEvent);
+ } else {
observer.notify(event);
}
}
@@ -168,8 +143,7 @@
/**
* Removes an observer from the event bus.
*
- * @param observer
- * The observer to remove
+ * @param observer The observer to remove
*/
public <T> void removeObserver(Observer<T> observer, Class<T> eventType, Annotation... bindings)
{
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 07:36:20 UTC (rev 354)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-11-24 08:20:17 UTC (rev 355)
@@ -2,6 +2,10 @@
import java.lang.annotation.Annotation;
+import javax.webbeans.AfterTransactionCompletion;
+import javax.webbeans.AfterTransactionFailure;
+import javax.webbeans.AfterTransactionSuccess;
+import javax.webbeans.BeforeTransactionCompletion;
import javax.webbeans.Current;
import javax.webbeans.Observer;
@@ -97,4 +101,12 @@
// 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();
+ }
}
16 years
[webbeans-commits] Webbeans SVN: r354 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: transaction and 1 other directory.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 02:36:20 -0500 (Mon, 24 Nov 2008)
New Revision: 354
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
Log:
removed extra synchronization stuff. Needs further consultation.
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-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -44,6 +44,7 @@
import javax.webbeans.manager.Manager;
import org.jboss.webbeans.bean.AbstractBean;
+import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bean.proxy.ProxyPool;
import org.jboss.webbeans.contexts.ApplicationContext;
@@ -57,6 +58,7 @@
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
+import org.jboss.webbeans.transaction.TransactionListener;
import org.jboss.webbeans.util.Reflections;
/**
@@ -101,6 +103,8 @@
protected void initStandardBeans()
{
addBean(new SimpleBean<DefaultEnterpriseBeanLookup>(DefaultEnterpriseBeanLookup.class, this));
+// TODO: Fix tests that rely that there are a specific number of beans registered/present/matched etc.
+// addBean(new EnterpriseBean<TransactionListener>(TransactionListener.class, this));
}
/**
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java 2008-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/EjbSynchronizations.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -1,89 +0,0 @@
-package org.jboss.webbeans.transaction;
-
-import java.rmi.RemoteException;
-import java.util.LinkedList;
-
-import javax.ejb.EJBException;
-import javax.ejb.Remove;
-import javax.ejb.SessionSynchronization;
-import javax.ejb.Stateful;
-import javax.ejb.TransactionAttribute;
-import javax.ejb.TransactionAttributeType;
-import javax.transaction.Synchronization;
-import javax.webbeans.RequestScoped;
-
-@Stateful
-@RequestScoped
-(a)TransactionAttribute(TransactionAttributeType.SUPPORTS)
-public class EjbSynchronizations implements LocalEjbSynchronizations, SessionSynchronization
-{
- protected LinkedList<SynchronizationRegistry> synchronizations = new LinkedList<SynchronizationRegistry>();
- protected LinkedList<SynchronizationRegistry> committing = new LinkedList<SynchronizationRegistry>();
-
- public void afterBegin()
- {
- synchronizations.addLast(new SynchronizationRegistry());
- }
-
- public void beforeCompletion() throws EJBException, RemoteException
- {
- SynchronizationRegistry synchronization = synchronizations.removeLast();
- synchronization.beforeTransactionCompletion();
- committing.addLast(synchronization);
- }
-
- public void afterCompletion(boolean success) throws EJBException, RemoteException
- {
- if (committing.isEmpty())
- {
- if (success)
- {
- throw new IllegalStateException("beforeCompletion was never called");
- }
- else
- {
- synchronizations.removeLast().afterTransactionCompletion(false);
- }
- }
- else
- {
- committing.removeFirst().afterTransactionCompletion(success);
- }
- }
-
- public boolean isAwareOfContainerTransactions()
- {
- return true;
- }
-
- public void afterTransactionBegin()
- {
- // noop, let JTA notify us
- }
-
- public void afterTransactionCommit(boolean success)
- {
- // noop, let JTA notify us
- }
-
- public void afterTransactionRollback()
- {
- // noop, let JTA notify us
- }
-
- public void beforeTransactionCommit()
- {
- // noop, let JTA notify us
- }
-
- public void registerSynchronization(Synchronization synchronization)
- {
- synchronizations.getLast().registerSynchronization(synchronization);
- }
-
- @Remove
- public void destroy()
- {
- }
-
-}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java 2008-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalEjbSynchronizations.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -1,9 +0,0 @@
-package org.jboss.webbeans.transaction;
-
-import javax.ejb.Local;
-
-@Local
-public interface LocalEjbSynchronizations extends Synchronizations
-{
- public void destroy();
-}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/LocalTransactionListener.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.transaction;
+
+import javax.ejb.Local;
+
+@Local
+public interface LocalTransactionListener
+{
+ public void destroy();
+}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java 2008-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/SynchronizationRegistry.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -1,49 +0,0 @@
-package org.jboss.webbeans.transaction;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.transaction.Status;
-import javax.transaction.Synchronization;
-
-class SynchronizationRegistry
-{
- private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
-
- void registerSynchronization(Synchronization sync)
- {
- synchronizations.add(sync);
- }
-
- void afterTransactionCompletion(boolean success)
- {
- for (Synchronization synchronization : synchronizations)
- {
- try
- {
- synchronization.afterCompletion(success ? Status.STATUS_COMMITTED : Status.STATUS_ROLLEDBACK);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- synchronizations.clear();
- }
-
- void beforeTransactionCompletion()
- {
- for (Synchronization synchronization : synchronizations)
- {
- try
- {
- synchronization.beforeCompletion();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
-
-}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java 2008-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/Synchronizations.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -1,13 +0,0 @@
-package org.jboss.webbeans.transaction;
-
-import javax.transaction.Synchronization;
-
-public interface Synchronizations
-{
- public void afterTransactionBegin();
- public void afterTransactionCommit(boolean success);
- public void afterTransactionRollback();
- public void beforeTransactionCommit();
- public void registerSynchronization(Synchronization sync);
- public boolean isAwareOfContainerTransactions();
-}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java 2008-11-24 07:35:15 UTC (rev 353)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/transaction/TransactionListener.java 2008-11-24 07:36:20 UTC (rev 354)
@@ -5,6 +5,7 @@
import java.util.List;
import javax.ejb.EJBException;
+import javax.ejb.Remove;
import javax.ejb.SessionSynchronization;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
@@ -16,7 +17,7 @@
@Stateful
@RequestScoped
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
-public class TransactionListener implements SessionSynchronization
+public class TransactionListener implements LocalTransactionListener, SessionSynchronization
{
private List<Synchronization> synchronizations = new ArrayList<Synchronization>();
@@ -46,4 +47,9 @@
{
synchronizations.add(synchronization);
}
+
+ @Remove
+ public void destroy()
+ {
+ }
}
16 years
[webbeans-commits] Webbeans SVN: r353 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-11-24 02:35:15 -0500 (Mon, 24 Nov 2008)
New Revision: 353
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/AnnotatedClass.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedConstructor.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
Log:
Javadocs/comments
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-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedAnnotation.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -10,15 +27,19 @@
*
*/
public interface AnnotatedAnnotation<T extends Annotation> extends AnnotatedType<T>
-{
-
+{
/**
- * Get all members
+ * Gets all members
+ *
+ * @return A set of abstracted members
*/
public Set<AnnotatedMethod<?>> getMembers();
/**
- * Get all the members annotated with annotationType
+ * Gets all the members annotated with annotationType
+ *
+ * @param annotationType The annotation type to match
+ * @return A set of abstracted members with the annotation type
*/
public Set<AnnotatedMethod<?>> getAnnotatedMembers(Class<? extends Annotation> annotationType);
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedClass.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -4,61 +21,79 @@
import java.util.List;
import java.util.Set;
-
/**
* Represents a Class
*
* @author Pete Muir
- *
+ *
*/
public interface AnnotatedClass<T> extends AnnotatedType<T>
{
-
+
/**
- * Get all fields on the type
- * @return
+ * Gets all fields on the type
+ *
+ * @return A set of abstracted fields
*/
public Set<AnnotatedField<Object>> getFields();
-
+
/**
- * Get all annotations which are annotated with the given annotation
- * type
+ * Gets all annotations which are annotated with the given annotation type
*
- * If no annotations are present which are annotated with the given
- * annotation an empty set is returned
+ * @param annotationType The annotation to match
+ * @return A set of abstracted fields with the given annotation. Returns an
+ * empty set if there are no matches
*/
public Set<AnnotatedField<Object>> getAnnotatedFields(Class<? extends Annotation> annotationType);
-
+
/**
- * Get all fields which are meta-annotated with metaAnnotationType
+ * Gets all fields which are meta-annotated with metaAnnotationType
*
- * If no annotations are present which are annotated with the given meta
- * annotation an empty set is returned
+ * @param metaAnnotationType The meta annotation to match
+ * @return A set of abstracted fields with the given meta-annotation. Returns
+ * an empty set if there are no matches
*/
- public Set<AnnotatedField<Object>> getMetaAnnotatedFields(
- Class<? extends Annotation> metaAnnotationType);
-
+ public Set<AnnotatedField<Object>> getMetaAnnotatedFields(Class<? extends Annotation> metaAnnotationType);
+
/**
- * Get all constructors which are annotated with annotationType
+ * Gets all constructors which are annotated with annotationType
+ *
+ * @param annotationType The annotation type to match
+ * @return A set of abstracted fields with the given annotation. Returns an
+ * empty set if there are no matches
*/
public Set<AnnotatedConstructor<T>> getAnnotatedConstructors(Class<? extends Annotation> annotationType);
-
+
/**
- * Get all constructors
+ * Gets all constructors
*
+ * @return A set of abstracted constructors
*/
public Set<AnnotatedConstructor<T>> getConstructors();
-
+
/**
- * Get the constructor with arguments given
+ * Gets the constructor with arguments given
+ *
+ * @param arguments The list of arguments to match
+ * @return A set of abstracted constructors with the given arguments. Returns
+ * an empty set if there are no matches
*/
public AnnotatedConstructor<T> getConstructor(List<Class<?>> arguments);
-
+
/**
- * Get all the members annotated with annotationType
+ * Gets all members annotated with annotationType
+ *
+ * @param annotationType The annotation to match
+ * @return A set of abstracted methods with the given annotation. Returns an
+ * empty set if there are no matches
*/
public Set<AnnotatedMethod<Object>> getAnnotatedMethods(Class<? extends Annotation> annotationType);
-
+
+ /**
+ * Gets the superclass
+ *
+ * @return The abstracted superclass
+ */
public AnnotatedClass<Object> getSuperclass();
-
+
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedConstructor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedConstructor.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedConstructor.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -10,28 +27,41 @@
* Represents a Class Constructor
*
* @author Pete Muir
- *
+ *
*/
public interface AnnotatedConstructor<T> extends AnnotatedItem<T, Constructor<T>>
{
-
+
/**
- * Get all parameters to the constructor
+ * Gets all parameters to the constructor
+ *
+ * @return A set of abstracted parameters. Returns an empty set if there are
+ * no parameters
*/
public List<AnnotatedParameter<Object>> getParameters();
-
+
/**
- * Get all parameters to the constructor which are annotated with annotationType
+ * Gets all parameters to the constructor which are annotated with
+ * annotationType
+ *
+ * @param annotationType A annotation to match
+ * @return A list of abstracted parameters with the given annotation type.
+ * Returns an empty set if there are no matches.
*/
public List<AnnotatedParameter<Object>> getAnnotatedParameters(Class<? extends Annotation> annotationType);
-
+
/**
- * Create a new instance of the class, using this constructor
+ * Creates a new instance of the class, using this constructor
+ *
+ * @param manager The Web Beans manager
+ * @return The created instance
*/
public T newInstance(ManagerImpl manager);
-
+
/**
+ * Gets the declaring class of the annotation
*
+ * @return An abstraction of the declaring class
*/
public AnnotatedType<T> getDeclaringClass();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.reflect.Field;
@@ -14,12 +31,33 @@
public interface AnnotatedField<T> extends AnnotatedItem<T, Field>
{
+ /**
+ * Gets the annotated field
+ *
+ * @return The annotated field
+ */
public Field getAnnotatedField();
+ /**
+ * Injects an instance
+ *
+ * @param instance The instance to inject
+ * @param manager The Web Beans manager
+ */
public void inject(Object instance, ManagerImpl manager);
+ /**
+ * Gets an abstraction of the declaring class
+ *
+ * @return The declaring class
+ */
public AnnotatedType<?> getDeclaringClass();
+ /**
+ * Gets the property name of the field
+ *
+ * @return The name
+ */
public String getPropertyName();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedItem.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -4,114 +21,146 @@
import java.lang.reflect.Type;
import java.util.Set;
-
/**
* AnnotatedItem provides a uniform access to the annotations on an annotated
- * item defined either in Java or XML
+ * item defined either in Java or XML
*
* @author Pete Muir
- *
+ *
*/
public interface AnnotatedItem<T, S>
{
/**
- * Get all annotations on the item
+ * Gets all annotations on the item
*
- * An empty set is returned if no annotations are present
+ * @return A set of annotations. Returns an empty set if there are no
+ * matches.
*/
public <A extends Annotation> Set<A> getAnnotations();
/**
- * Get all annotations which are annotated with the given meta annotation
+ * Gets all annotations which are annotated with the given meta annotation
* type
*
- * If no annotations are present which are annotated with the given meta
- * annotation an empty set is returned
+ * @param The meta annotation to match
+ * @return A set of matching meta-annotations. Returns an empty set if there
+ * are no matches.
*/
- public Set<Annotation> getMetaAnnotations(
- Class<? extends Annotation> metaAnnotationType);
-
- public Annotation[] getMetaAnnotationsAsArray(
- Class<? extends Annotation> metaAnnotationType);
-
+ public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType);
+
/**
- * Get the binding types for this element
+ * Gets all annotations which are annotated with the given meta annotation
+ * type
+ *
+ * @param The meta annotation to match
+ * @return An array of matching meta-annotations. Returns an empty array if
+ * there are no matches.
*/
+ public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation> metaAnnotationType);
+
+ /**
+ * Gets the binding types for this element
+ *
+ * @returns A set of binding types present on the type. Returns an empty set
+ * if there are no matches.
+ */
public Set<Annotation> getBindingTypes();
-
+
+ /**
+ * Gets the binding types for this element
+ *
+ * @returns An array of binding types present on the type. Returns an empty
+ * array if there are no matches.
+ */
public Annotation[] getBindingTypesAsArray();
/**
- * Get an annotation for the annotation type specified.
+ * Gets an annotation for the annotation type specified.
*
- * If the annotation isn't present, null is returned
+ * @param annotationType The annotation to match
+ * @return An annotation if found, null if the annotation wasn't present.
*/
- public <A extends Annotation> A getAnnotation(
- Class<? extends A> annotationType);
+ public <A extends Annotation> A getAnnotation(Class<? extends A> annotationType);
/**
- * Return true if the annotation type specified is present
+ * Indicates if an annotation type specified is present
+ *
+ * @param annotationType The annotation to match
+ * @return True if present, false if not
*/
- public boolean isAnnotationPresent(
- Class<? extends Annotation> annotationType);
-
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType);
+
/**
- * Get the underlying element
- * @return
+ * Gets the underlying element
+ *
+ * @return The annotated item
*/
public S getDelegate();
-
+
/**
- * The type of the element
- * @return
+ * Gets the type of the element
+ *
+ * @return The type of the element
*/
public Class<T> getType();
-
+
/**
- * Extends Java Class assignability such that actual type parameters are also
+ * Extends Java Class assignability such that actual type parameters are also
* considered
+ *
+ * @param that The other item to check assignability against
+ * @return True if assignable, false otherwise.
*/
public boolean isAssignableFrom(AnnotatedItem<?, ?> that);
-
+
/**
- * Returns true if any of the types provided are assignable to this, using
+ * Checks if any of the types provided are assignable to this, using
* the extended assingablity algorithm provided by AnnotatedItem.
*
* The types are assumed to contain their own actual type parameterization.
+ *
+ * @param types The set of types to match
+ * @return True if assignable, false otherwise.
*/
public boolean isAssignableFrom(Set<Class<?>> types);
-
+
/**
- * Return the actual type arguments for any parameterized types that this
+ * Gets the actual type arguments for any parameterized types that this
* AnnotatedItem represents.
+ *
+ * @return An array of type arguments
*/
public Type[] getActualTypeArguments();
-
+
/**
- * Return true if this AnnotatedItem represents a static element
+ * Indicates if this AnnotatedItem represents a static element
+ *
+ * @return True if static, false otherwise
*/
public boolean isStatic();
-
+
/**
- * Return true if this AnnotatedItem represents a final element
+ * Indicates if this AnnotatedItem represents a final element
+ * @return True if final, false otherwise
*/
public boolean isFinal();
-
+
/**
- * Return true if this AnnotatedItem can be proxyed
- * @return
+ * Indicates if this AnnotatedItem can be proxyed
+ *
+ * @return True if proxyable, false otherwise
*/
public boolean isProxyable();
-
+
/**
- * Return the name of this AnnotatedItem
+ * Gets the name of this AnnotatedItem
*
* If it is not possible to determine the name of the underling element, a
* IllegalArgumentException is thrown
+ *
+ * @return The name
*/
public String getName();
-
-
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedMethod.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -8,24 +25,61 @@
/**
* AnnotatedType provides a uniform access to the annotations on an annotated
- * class defined either in Java or XML
+ * class defined either in Java or XML
*
* @author Pete Muir
- *
+ *
*/
public interface AnnotatedMethod<T> extends AnnotatedItem<T, Method>
{
-
+
+ /**
+ * Gets the abstracted parameters of the method
+ *
+ * @return A list of parameters. Returns an empty list if no parameters are
+ * present.
+ */
public List<AnnotatedParameter<Object>> getParameters();
-
+
+ /**
+ * Gets the list of annotated parameters for a given meta annotation
+ *
+ * @param metaAnnotationType The meta annotation to match
+ * @return A set of matching parameter abstractions. Returns an empty list if
+ * there are no matches.
+ */
public List<AnnotatedParameter<Object>> getAnnotatedParameters(Class<? extends Annotation> metaAnnotationType);
+ /**
+ * Invokes the method
+ *
+ * @param manager The Web Beans manager
+ * @param instance The instance to invoke
+ * @return A reference to the instance
+ */
public T invoke(ManagerImpl manager, Object instance);
-
- public T invoke(Object instance, Object...parameters);
-
+
+ /**
+ * Invokes the method
+ *
+ * @param instance The instance to invoke
+ * @param parameters The method parameters
+ * @return A reference to the instance
+ */
+ public T invoke(Object instance, Object... parameters);
+
+ /**
+ * Gets the declaring class
+ *
+ * @return An abstraction of the declaring class
+ */
public AnnotatedType<?> getDeclaringClass();
-
+
+ /**
+ * Gets the property name
+ *
+ * @return The name
+ */
public String getPropertyName();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedParameter.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import org.jboss.webbeans.ManagerImpl;
@@ -2,7 +19,20 @@
+/**
+ * AnnotatedParameter provides a uniform access to a method parameter defined
+ * either in Java or XML
+ *
+ * @author Pete Muir
+ * @param <T>
+ */
public interface AnnotatedParameter<T> extends AnnotatedItem<T, Object>
{
-
+
+ /**
+ * Gets the value of the parameter
+ *
+ * @param manager The Web Beans Manager
+ * @return The value
+ */
public T getValue(ManagerImpl manager);
-
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedType.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,8 +1,37 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
+/**
+ * AnnotatedType provides a uniform access to a type defined either in Java or
+ * XML
+ *
+ * @author Pete Muir
+ * @param <T>
+ */
public interface AnnotatedType<T> extends AnnotatedItem<T, Class<T>>
{
-
+
+ /**
+ * Gets the superclass of the type
+ *
+ * @return The abstracted superclass
+ */
public AnnotatedType<Object> getSuperclass();
-
+
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java 2008-11-21 22:38:06 UTC (rev 352)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/ForwardingAnnotatedItem.java 2008-11-24 07:35:15 UTC (rev 353)
@@ -1,3 +1,20 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package org.jboss.webbeans.introspector;
import java.lang.annotation.Annotation;
@@ -4,107 +21,183 @@
import java.lang.reflect.Type;
import java.util.Set;
+/**
+ * Provides an abstraction for delegating access to an annotated item
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ * @param <S>
+ */
public abstract class ForwardingAnnotatedItem<T, S> implements AnnotatedItem<T, S>
{
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Type[] getActualTypeArguments()
{
return delegate().getActualTypeArguments();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public <A extends Annotation> A getAnnotation(Class<? extends A> annotationType)
{
return delegate().getAnnotation(annotationType);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public <A extends Annotation> Set<A> getAnnotations()
{
return delegate().getAnnotations();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Set<Annotation> getMetaAnnotations(Class<? extends Annotation> metaAnnotationType)
{
return delegate().getMetaAnnotations(metaAnnotationType);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Annotation[] getMetaAnnotationsAsArray(Class<? extends Annotation> metaAnnotationType)
{
return delegate().getMetaAnnotationsAsArray(metaAnnotationType);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Set<Annotation> getBindingTypes()
{
return delegate().getBindingTypes();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Annotation[] getBindingTypesAsArray()
{
return delegate().getBindingTypesAsArray();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public S getDelegate()
{
return delegate().getDelegate();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public String getName()
{
return delegate().getName();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public Class<T> getType()
{
return delegate().getType();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
return delegate().isAnnotationPresent(annotationType);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isAssignableFrom(AnnotatedItem<?, ?> that)
{
return delegate().isAssignableFrom(that);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isAssignableFrom(Set<Class<?>> types)
{
return delegate().isAssignableFrom(types);
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isFinal()
{
return delegate().isFinal();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isStatic()
{
return delegate().isStatic();
}
-
+
+ /**
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
public boolean isProxyable()
{
return delegate().isProxyable();
}
-
+
+ /**
+ * Overridden method into delegate
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
@Override
public boolean equals(Object obj)
{
return delegate().equals(obj);
}
-
+
+ /**
+ * Overridden method into delegate
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
@Override
public int hashCode()
{
return delegate().hashCode();
}
-
+
+ /**
+ * Overridden method into delegate
+ *
+ * @see org.jboss.webbeans.introspector.AnnotatedItem
+ */
@Override
public String toString()
{
return delegate().toString();
}
-
+
+ /**
+ * Gets the annotated item
+ *
+ * @return The annotated item
+ */
public abstract AnnotatedItem<T, S> delegate();
-
+
}
16 years