Package org.jboss.weld.event
Class ObserverMethodImpl<T,X>
- java.lang.Object
-
- org.jboss.weld.event.ObserverMethodImpl<T,X>
-
- All Implemented Interfaces:
ObserverMethod<T>,Prioritized,EventMetadataAwareObserverMethod<T>
- Direct Known Subclasses:
ExtensionObserverMethodImpl
public class ObserverMethodImpl<T,X> extends Object implements ObserverMethod<T>, EventMetadataAwareObserverMethod<T>
Reference implementation for the ObserverMethod 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.
- Author:
- David Allen, Jozef Hartinger, Marko Luksa
-
-
Field Summary
Fields Modifier and Type Field Description protected BeanManagerImplbeanManagerprotected RIBean<X>declaringBeanstatic StringID_PREFIXstatic StringID_SEPARATORprotected MethodInjectionPoint<T,? super X>observerMethodprotected static Set<Class<? extends Annotation>>SPECIAL_PARAM_MARKERSprotected TransactionPhasetransactionPhase-
Fields inherited from interface javax.enterprise.inject.spi.ObserverMethod
DEFAULT_PRIORITY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedObserverMethodImpl(EnhancedAnnotatedMethod<T,? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync)Creates an Observer which describes and encapsulates an observer method (8.5).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckRequiredTypeAnnotations(EnhancedAnnotatedParameter<?,?> eventParameter)protected StringcreateId(EnhancedAnnotatedMethod<?,?> observer, RIBean<?> declaringBean)protected StringcreateTypeId(RIBean<?> declaringBean)booleanequals(Object obj)Class<X>getBeanClass()Obtains the class of the type that declares the observer method.RIBean<X>getDeclaringBean()protected EnhancedAnnotatedParameter<?,? super X>getEventParameter(EnhancedAnnotatedMethod<T,? super X> observer)StringgetId()Set<WeldInjectionPointAttributes<?,?>>getInjectionPoints()MethodInjectionPoint<T,? super X>getMethod()Set<Annotation>getObservedQualifiers()Obtains the set of observed event qualifiers.TypegetObservedType()Obtains the observed event type.intgetPriority()The priority that will be used by the container to determine the notification order in which event observer methods are invoked.protected ObjectgetReceiver(CreationalContext<X> creationalContext)ReceptiongetReception()Obtains the specifiedReceptionfor the observer method.TransactionPhasegetTransactionPhase()Obtains the specifiedTransactionPhasefor the observer method.inthashCode()voidinitialize(EnhancedAnnotatedMethod<T,? super X> annotated)Completes initialization of the observer and allows derived types to override behavior.protected MethodInjectionPoint<T,? super X>initMethodInjectionPoint(EnhancedAnnotatedMethod<T,? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager)booleanisAsync()Determines if this observer method is asynchronousbooleanisEventMetadataRequired()voidnotify(T event)Calls the observer method, passing the given event object.protected voidpostNotify(T event, Object receiver)protected voidpreNotify(T event, Object receiver)Hooks allowing subclasses to perform additional logic just before and just after an event is delivered to an observer method.protected voidsendEvent(T event)Invokes the observer method immediately passing the event.protected voidsendEvent(T event, Object receiver, CreationalContext<?> creationalContext)Note thatCreationalContext.release()is not invoked within this method.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.enterprise.inject.spi.ObserverMethod
notify
-
-
-
-
Field Detail
-
ID_PREFIX
public static final String ID_PREFIX
-
ID_SEPARATOR
public static final String ID_SEPARATOR
- See Also:
- Constant Field Values
-
SPECIAL_PARAM_MARKERS
protected static final Set<Class<? extends Annotation>> SPECIAL_PARAM_MARKERS
-
beanManager
protected final BeanManagerImpl beanManager
-
observerMethod
protected final MethodInjectionPoint<T,? super X> observerMethod
-
transactionPhase
protected TransactionPhase transactionPhase
-
-
Constructor Detail
-
ObserverMethodImpl
protected ObserverMethodImpl(EnhancedAnnotatedMethod<T,? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager, boolean isAsync)
Creates an Observer which describes and encapsulates an observer method (8.5).- Parameters:
observer- The observerdeclaringBean- The observer beanmanager- The Bean manager
-
-
Method Detail
-
getEventParameter
protected EnhancedAnnotatedParameter<?,? super X> getEventParameter(EnhancedAnnotatedMethod<T,? super X> observer)
-
createId
protected String createId(EnhancedAnnotatedMethod<?,?> observer, RIBean<?> declaringBean)
-
initMethodInjectionPoint
protected MethodInjectionPoint<T,? super X> initMethodInjectionPoint(EnhancedAnnotatedMethod<T,? super X> observer, RIBean<X> declaringBean, BeanManagerImpl manager)
-
getInjectionPoints
public Set<WeldInjectionPointAttributes<?,?>> getInjectionPoints()
-
checkRequiredTypeAnnotations
protected void checkRequiredTypeAnnotations(EnhancedAnnotatedParameter<?,?> eventParameter)
-
getBeanClass
public Class<X> getBeanClass()
Description copied from interface:ObserverMethodObtains the class of the type that declares the observer method.
- Specified by:
getBeanClassin interfaceObserverMethod<T>- Returns:
- the defining class
-
getReception
public Reception getReception()
Description copied from interface:ObserverMethodObtains the specifiedReceptionfor the observer method. This indicates if the observer is conditional or not.- Specified by:
getReceptionin interfaceObserverMethod<T>- Returns:
- the
Reception
-
getObservedQualifiers
public Set<Annotation> getObservedQualifiers()
Description copied from interface:ObserverMethodObtains the set of observed event qualifiers.- Specified by:
getObservedQualifiersin interfaceObserverMethod<T>- Returns:
- the observed event qualifiers
-
getObservedType
public Type getObservedType()
Description copied from interface:ObserverMethodObtains the observed event type.- Specified by:
getObservedTypein interfaceObserverMethod<T>- Returns:
- the observed event type
-
getTransactionPhase
public TransactionPhase getTransactionPhase()
Description copied from interface:ObserverMethodObtains the specifiedTransactionPhasefor the observer method.- Specified by:
getTransactionPhasein interfaceObserverMethod<T>- Returns:
- the
TransactionPhase
-
getMethod
public MethodInjectionPoint<T,? super X> getMethod()
- Returns:
- the observerMethod
-
initialize
public void initialize(EnhancedAnnotatedMethod<T,? super X> annotated)
Completes initialization of the observer and allows derived types to override behavior.
-
notify
public void notify(T event)
Description copied from interface:ObserverMethodCalls the observer method, passing the given event object.
The implementation of this method for a custom observer method is responsible for deciding whether to call the method if the
ObserverMethod.getReception()returnsReception.IF_EXISTS.- Specified by:
notifyin interfaceObserverMethod<T>- Parameters:
event- the event object
-
sendEvent
protected void sendEvent(T event)
Invokes the observer method immediately passing the event.- Parameters:
event- The event to notify observer with
-
sendEvent
protected void sendEvent(T event, Object receiver, CreationalContext<?> creationalContext)
Note thatCreationalContext.release()is not invoked within this method.- Parameters:
event-receiver-creationalContext-
-
preNotify
protected void preNotify(T event, Object receiver)
Hooks allowing subclasses to perform additional logic just before and just after an event is delivered to an observer method.
-
getReceiver
protected Object getReceiver(CreationalContext<X> creationalContext)
-
getId
public String getId()
-
getPriority
public int getPriority()
Description copied from interface:ObserverMethodThe priority that will be used by the container to determine the notification order in which event observer methods are invoked.- Specified by:
getPriorityin interfaceObserverMethod<T>- Specified by:
getPriorityin interfacePrioritized- Returns:
- The priority that will be used by the container to determine the notification order in which event observer methods are invoked.
-
isAsync
public boolean isAsync()
Description copied from interface:ObserverMethodDetermines if this observer method is asynchronous
- Specified by:
isAsyncin interfaceObserverMethod<T>- Returns:
- returns true if the method is an asynchronous observer method (i.e. defined with
ObservesAsync), otherwise returns false
-
isEventMetadataRequired
public boolean isEventMetadataRequired()
- Specified by:
isEventMetadataRequiredin interfaceEventMetadataAwareObserverMethod<T>- Returns:
trueifEventMetadatais required,falseotherwise
-
-