Skip to content

Commit

Permalink
minor manager singleton cleanups
Browse files Browse the repository at this point in the history
git-svn-id: http://anonsvn.jboss.org/repos/weld/ri/trunk@422 1c488680-804c-0410-94cd-c6b725194a0e
  • Loading branch information
nickarls committed Dec 5, 2008
1 parent f5df52f commit 9f1af81
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
Expand Up @@ -25,7 +25,6 @@
import javax.webbeans.Event;
import javax.webbeans.Standard;

import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.event.EventImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedItem;
Expand Down Expand Up @@ -162,11 +161,12 @@ private String getLocation()
/**
* @see javax.webbeans.manager.Bean#create()
*/
@SuppressWarnings("unchecked")
@Override
public Event<T> create()
{
Class<T> eventType = (Class<T>) annotatedItem.getType().getTypeParameters()[0].getClass();
return new EventImpl<T>(ManagerImpl.instance(), eventType, annotatedItem.getBindingTypesAsArray());
return new EventImpl<T>(eventType, annotatedItem.getBindingTypesAsArray());
}

}
Expand Up @@ -126,13 +126,13 @@ public void registerBeans(Iterable<Class<?>> classes)
ManagerImpl.instance().getResolver().addInjectionPoints(bean.getInjectionPoints());
for (AnnotatedMethod<Object> producerMethod : bean.getProducerMethods())
{
ProducerMethodBean<?> producerMethodBean = createProducerMethodBean(producerMethod.getType(), producerMethod, bean);
ProducerMethodBean<?> producerMethodBean = createProducerMethodBean(producerMethod, bean);
beans.add(producerMethodBean);
ManagerImpl.instance().getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
}
for (AnnotatedField<Object> eventField : bean.getEventFields())
{
EventBean<?> eventBean = createEventBean(eventField.getType(), eventField);
EventBean<?> eventBean = createEventBean(eventField);
beans.add(eventBean);
ManagerImpl.instance().getResolver().addInjectionPoints(eventBean.getInjectionPoints());
}
Expand Down
25 changes: 11 additions & 14 deletions webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
Expand Up @@ -39,27 +39,22 @@
* @param <T>
* @see javax.webbeans.Event
*/
@Standard
@Dependent
public class EventImpl<T> implements Event<T>
{
// The set of binding types
private final Set<? extends Annotation> bindingTypes;
// The event type
private final Class<T> eventType;
// The Web Beans manager
protected final ManagerImpl manager;

/**
* Constructor
*
* @param bindingTypes The binding types
*/
public EventImpl(ManagerImpl manager, Class<T> eventType, Annotation... bindingTypes)
public EventImpl(Class<T> eventType, Annotation... bindingTypes)
{
this.bindingTypes = getBindingTypes(bindingTypes);
this.eventType = eventType;
this.manager = manager;
}

/**
Expand All @@ -68,8 +63,8 @@ public EventImpl(ManagerImpl manager, Class<T> eventType, Annotation... bindingT
* Removes @Observable from the list
*
* @param annotations The annotations to validate
* @return A set of binding type annotations (minus @Observable, if it
* was present)
* @return A set of binding type annotations (minus @Observable, if it was
* present)
*/
private static Set<Annotation> getBindingTypes(Annotation... annotations)
{
Expand Down Expand Up @@ -103,10 +98,12 @@ private Set<Annotation> checkBindingTypes(Annotation... annotations)
{
throw new IllegalArgumentException(annotation + " is not a binding type");
}
for (Annotation bindingAnnotation: this.bindingTypes) {
if (bindingAnnotation.annotationType().equals(annotation.annotationType())) {
for (Annotation bindingAnnotation : this.bindingTypes)
{
if (bindingAnnotation.annotationType().equals(annotation.annotationType()))
{
throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list");
}
}
}
result.add(annotation);
}
Expand All @@ -123,7 +120,7 @@ public void fire(T event, Annotation... bindingTypes)
{
Set<Annotation> bindingParameters = checkBindingTypes(bindingTypes);
bindingParameters.addAll(this.bindingTypes);
manager.fireEvent(event, bindingParameters.toArray(new Annotation[0]));
ManagerImpl.instance().fireEvent(event, bindingParameters.toArray(new Annotation[0]));
}

/**
Expand All @@ -136,7 +133,7 @@ public void observe(Observer<T> observer, Annotation... bindingTypes)
{
Set<Annotation> bindingParameters = checkBindingTypes(bindingTypes);
bindingParameters.addAll(this.bindingTypes);
manager.addObserver(observer, eventType, bindingParameters.toArray(new Annotation[0]));
ManagerImpl.instance().addObserver(observer, eventType, bindingParameters.toArray(new Annotation[0]));
}

}
Expand Up @@ -60,7 +60,7 @@ public interface AnnotatedMethod<T> extends AnnotatedItem<T, Method>
* Invokes the observer method
*
* @param instance The instance to invoke
* @param event the event object
* @param event the event object
* @return A reference to the instance
*/
public T invokeWithSpecialValue(Object instance, Class<? extends Annotation> specialParam, Object specialVal);
Expand Down
Expand Up @@ -101,26 +101,23 @@ public static <T> ProducerMethodBean<T> createProducerMethodBean(Class<T> type,
/**
* Creates a producer method Web Bean
*
* @param type The type
* @param method The underlying method abstraction
* @param declaringBean The declaring bean abstraction
* @return A producer Web Bean
*/
public static <T> ProducerMethodBean<T> createProducerMethodBean(Class<T> type, AnnotatedMethod<T> method, AbstractClassBean<?> declaringBean)
public static <T> ProducerMethodBean<T> createProducerMethodBean(AnnotatedMethod<T> method, AbstractClassBean<?> declaringBean)
{
return new ProducerMethodBean<T>(method, declaringBean);
}

/**
* Creates an event Web Bean
*
* @param <T>
* @param type The type
* @param field The observer field abstraction
* @param declaringBean The declaring bean abstraction
* @return An event Web Bean
*/
public static <T> EventBean<T> createEventBean(Class<T> type, AnnotatedField<T> field)
public static <T> EventBean<T> createEventBean(AnnotatedField<T> field)
{
return new EventBean<T>(field);
}
Expand Down
Expand Up @@ -56,6 +56,7 @@ public void before() throws Exception
enabledDeploymentTypes.add(Standard.class);
enabledDeploymentTypes.add(AnotherDeploymentType.class);
manager = new MockManagerImpl();
MockManagerImpl.setInstance(manager);
manager.setEnabledDeploymentTypes(Standard.class, AnotherDeploymentType.class);
}

Expand All @@ -72,7 +73,7 @@ public void testFireEvent()
//Create a test annotation for the event and use it to construct the
//event object
Annotation[] annotations = new Annotation[] { new TameAnnotationLiteral() };
EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(manager, DangerCall.class, annotations);
EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(DangerCall.class, annotations);
eventComponent.fire(anEvent, new SynchronousAnnotationLiteral());
assert anEvent.equals(manager.getEvent());
assert Reflections.annotationSetMatches(manager.getEventBindings(),
Expand Down Expand Up @@ -113,7 +114,7 @@ public void testObserve()
//Create a test annotation for the event and use it to construct the
//event object
Annotation[] annotations = new Annotation[] { new TameAnnotationLiteral() };
EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(manager, DangerCall.class, annotations);
EventImpl<DangerCall> eventComponent = new EventImpl<DangerCall>(DangerCall.class, annotations);
Observer<DangerCall> observer = new AnObserver<DangerCall>();
eventComponent.observe(observer, new SynchronousAnnotationLiteral());
assert manager.getObservedEventType().equals(DangerCall.class);
Expand Down

0 comments on commit 9f1af81

Please sign in to comment.