Author: gavin.king(a)jboss.com
Date: 2008-12-07 20:07:34 -0500 (Sun, 07 Dec 2008)
New Revision: 464
Added:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/FacadeBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InstanceBean.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
Log:
support for @Obtainable Instance, w/o tests
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java
(rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/FacadeImpl.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -0,0 +1,79 @@
+package org.jboss.webbeans;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.webbeans.DuplicateBindingTypeException;
+import javax.webbeans.Observable;
+
+import org.jboss.webbeans.util.Reflections;
+
+public class FacadeImpl<T> {
+
+ protected final Set<? extends Annotation> bindingTypes;
+ protected final ManagerImpl manager;
+ protected final Class<T> type;
+
+ /**
+ * Validates the binding types
+ *
+ * Removes @Observable from the list
+ *
+ * @param annotations The annotations to validate
+ * @return A set of binding type annotations (minus @Observable, if it was
+ * present)
+ */
+ protected static Set<Annotation> getBindingTypes(Annotation... annotations) {
+ Set<Annotation> result = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (!Reflections.isBindingType(annotation))
+ {
+ throw new IllegalArgumentException(annotation + " is not a binding
type");
+ }
+ if (!annotation.annotationType().equals(Observable.class))
+ {
+ result.add(annotation);
+ }
+ }
+ return result;
+ }
+
+ protected FacadeImpl(ManagerImpl manager, Class<T> eventType, Annotation...
bindingTypes) {
+ this.manager = manager;
+ this.type = eventType;
+ this.bindingTypes = getBindingTypes(bindingTypes);
+ }
+
+ /**
+ * Validates the binding types and checks for duplicates among the annotations.
+ *
+ * @param annotations The annotations to validate
+ * @return A set of unique binding type annotations
+ */
+ protected Set<Annotation> checkBindingTypes(Annotation... annotations) {
+ Set<Annotation> result = new HashSet<Annotation>();
+ for (Annotation annotation : annotations)
+ {
+ if (!Reflections.isBindingType(annotation))
+ {
+ throw new IllegalArgumentException(annotation + " is not a binding type
for " + this);
+ }
+ if (result.contains(annotation) || this.bindingTypes.contains(annotation))
+ {
+ throw new DuplicateBindingTypeException(annotation + " is already
present in the bindings list for " + this);
+ }
+ result.add(annotation);
+ }
+ return result;
+ }
+
+ protected Annotation[] mergeBindings(Annotation... bindingTypes) {
+ Set<Annotation> bindingParameters = checkBindingTypes(bindingTypes);
+ bindingParameters.addAll(this.bindingTypes);
+ Annotation[] bindings = bindingParameters.toArray(new Annotation[0]);
+ return bindings;
+ }
+
+}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java
(rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/InstanceImpl.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import java.lang.annotation.Annotation;
+
+import javax.webbeans.Instance;
+
+import org.jboss.webbeans.util.Strings;
+
+/**
+ * Implementation of the Event interface
+ *
+ * @author David Allen
+ *
+ * @param <T>
+ * @see javax.webbeans.Event
+ */
+public class InstanceImpl<T> extends FacadeImpl<T> implements
Instance<T>
+{
+ /**
+ * Constructor
+ *
+ * @param bindingTypes The binding types
+ */
+ public InstanceImpl(ManagerImpl manager, Class<T> type, Annotation...
bindingTypes)
+ {
+ super(manager, type, bindingTypes);
+ }
+
+ public T get(Annotation... bindingTypes)
+ {
+ return manager.getInstanceByType(type, mergeBindings(bindingTypes));
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Obtainable Instance:\n");
+ buffer.append(Strings.collectionToString(" Bindings: ", bindingTypes));
+ return buffer.toString();
+ }
+
+}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-08
01:02:40 UTC (rev 463)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -26,7 +26,6 @@
import javax.webbeans.Destructor;
import javax.webbeans.Disposes;
import javax.webbeans.Initializer;
-import javax.webbeans.Observable;
import javax.webbeans.Observes;
import javax.webbeans.Produces;
import javax.webbeans.Production;
@@ -113,17 +112,6 @@
{
return getAnnotatedItem().getAnnotatedFields(Produces.class);
}
-
- /**
- * Returns @Observer annotated fields.
- *
- * @return A set of observing fields. An empty set is returned if there are
- * none present.
- */
- public Set<AnnotatedField<Object>> getEventFields()
- {
- return getAnnotatedItem().getAnnotatedFields(Observable.class);
- }
public Set<AnnotatedMethod<Object>> getObserverMethods()
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-12-08
01:02:40 UTC (rev 463)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -17,19 +17,11 @@
package org.jboss.webbeans.bean;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-import javax.webbeans.DefinitionException;
-import javax.webbeans.Dependent;
import javax.webbeans.Event;
-import javax.webbeans.Production;
-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;
/**
@@ -39,105 +31,25 @@
*
* @param <T>
*/
-public class EventBean<T> extends AbstractBean<Event<T>, Field>
+public class EventBean<T, S> extends FacadeBean<Event<T>, S, T>
{
- // The underlying annotated item
- private AnnotatedField<Event<T>> annotatedItem;
-
/**
* Constructor
*
* @param field The underlying field abstraction
*/
@SuppressWarnings("unchecked")
- public EventBean(AnnotatedField<T> field, ManagerImpl manager)
+ public EventBean(AnnotatedItem<Event<T>, S> field, ManagerImpl manager)
{
- super(manager);
- this.annotatedItem = (AnnotatedField<Event<T>>) field;
- init();
+ super(field, manager);
}
- /**
- * Initializes the bean
- *
- * Calls super method and validates the annotated item
- */
- protected void init()
- {
- super.init();
- checkAnnotatedItem();
- }
-
- /**
- * Validates the annotated item
- */
- private void checkAnnotatedItem()
- {
- Type[] actualTypeArguments = annotatedItem.getActualTypeArguments();
- if (actualTypeArguments.length != 1)
- {
- throw new DefinitionException("Event must have type arguments");
- }
- if (!(actualTypeArguments[0] instanceof Class))
- {
- throw new DefinitionException("Event must have concrete type
argument");
- }
- }
-
- @Override
- protected void initScopeType()
- {
- this.scopeType = Dependent.class;
- }
-
- @Override
- protected void initDeploymentType()
- {
- this.deploymentType = Standard.class;
- }
-
- @Override
- protected AnnotatedItem<Event<T>, Field> getAnnotatedItem()
- {
- return annotatedItem;
- }
-
- @Override
- protected String getDefaultName()
- {
- return null;
- }
-
- @Override
- protected void initType()
- {
- try
- {
- if (getAnnotatedItem() != null)
- {
- this.type = getAnnotatedItem().getType();
- }
- }
- catch (ClassCastException e)
- {
- // TODO: Expand error
- throw new IllegalArgumentException("Type mismatch");
- }
- }
-
@SuppressWarnings("unchecked")
@Override
public Event<T> create()
{
- Class<T> eventType = (Class<T>)
annotatedItem.getType().getTypeParameters()[0].getClass();
- return new EventImpl<T>(manager, eventType,
annotatedItem.getBindingTypesAsArray());
+ return new EventImpl<T>(manager, getTypeParameter(),
getBindingTypesArray());
}
-
- @Override
- protected Class<? extends Annotation> getDefaultDeploymentType()
- {
- return Production.class;
- }
}
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/FacadeBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/FacadeBean.java
(rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/FacadeBean.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -0,0 +1,98 @@
+package org.jboss.webbeans.bean;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.webbeans.DefinitionException;
+import javax.webbeans.Dependent;
+import javax.webbeans.Production;
+import javax.webbeans.Standard;
+
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+
+public abstract class FacadeBean<T, S, P> extends AbstractBean<T, S> {
+
+ protected AnnotatedItem<T, S> annotatedItem;
+
+ public FacadeBean(AnnotatedItem<T, S> field, ManagerImpl manager) {
+ super(manager);
+ this.annotatedItem = field;
+ init();
+ }
+
+ /**
+ * Initializes the bean
+ *
+ * Calls super method and validates the annotated item
+ */
+ protected void init() {
+ super.init();
+ checkAnnotatedItem();
+ }
+
+ /**
+ * Validates the annotated item
+ */
+ private void checkAnnotatedItem() {
+ Type[] actualTypeArguments = annotatedItem.getActualTypeArguments();
+ if (actualTypeArguments.length != 1)
+ {
+ throw new DefinitionException("Event must have type arguments");
+ }
+ if (!(actualTypeArguments[0] instanceof Class))
+ {
+ throw new DefinitionException("Event must have concrete type
argument");
+ }
+ }
+
+ protected Annotation[] getBindingTypesArray() {
+ return annotatedItem.getBindingTypesAsArray();
+ }
+
+ protected Class<P> getTypeParameter() {
+ return (Class<P>) annotatedItem.getType().getTypeParameters()[0].getClass();
+ }
+
+ @Override
+ protected void initScopeType() {
+ this.scopeType = Dependent.class;
+ }
+
+ @Override
+ protected void initDeploymentType() {
+ this.deploymentType = Standard.class;
+ }
+
+ @Override
+ protected AnnotatedItem<T, S> getAnnotatedItem() {
+ return annotatedItem;
+ }
+
+ @Override
+ protected String getDefaultName() {
+ return null;
+ }
+
+ @Override
+ protected void initType() {
+ try
+ {
+ if (getAnnotatedItem() != null)
+ {
+ this.type = getAnnotatedItem().getType();
+ }
+ }
+ catch (ClassCastException e)
+ {
+ // TODO: Expand error
+ throw new IllegalArgumentException("Type mismatch");
+ }
+ }
+
+ @Override
+ protected Class<? extends Annotation> getDefaultDeploymentType() {
+ return Production.class;
+ }
+
+}
\ No newline at end of file
Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InstanceBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InstanceBean.java
(rev 0)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/InstanceBean.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -0,0 +1,55 @@
+/*
+ * 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.bean;
+
+
+import javax.webbeans.Instance;
+
+import org.jboss.webbeans.InstanceImpl;
+import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.introspector.AnnotatedItem;
+
+/**
+ * An event bean representation
+ *
+ * @author David Allen
+ *
+ * @param <T>
+ */
+public class InstanceBean<T, S> extends FacadeBean<Instance<T>, S, T>
+{
+
+ /**
+ * Constructor
+ *
+ * @param field The underlying field abstraction
+ */
+ @SuppressWarnings("unchecked")
+ public InstanceBean(AnnotatedItem<Instance<T>, S> field, ManagerImpl
manager)
+ {
+ super(field, manager);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Instance<T> create()
+ {
+ return new InstanceImpl<T>(manager, getTypeParameter(),
getBindingTypesArray());
+ }
+
+}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-08
01:02:40 UTC (rev 463)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -26,19 +26,23 @@
import static org.jboss.webbeans.servlet.Servlet.SERVLET_REQUEST_LISTENER_CLASS;
import static org.jboss.webbeans.util.BeanFactory.createEnterpriseBean;
import static org.jboss.webbeans.util.BeanFactory.createEventBean;
+import static org.jboss.webbeans.util.BeanFactory.createInstanceBean;
import static org.jboss.webbeans.util.BeanFactory.createObserver;
import static org.jboss.webbeans.util.BeanFactory.createProducerFieldBean;
import static org.jboss.webbeans.util.BeanFactory.createProducerMethodBean;
import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.webbeans.DefinitionException;
+import javax.webbeans.Observable;
import javax.webbeans.Observer;
import javax.webbeans.Observes;
+import javax.webbeans.Obtainable;
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.ManagerImpl;
@@ -46,12 +50,14 @@
import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.EventBean;
+import org.jboss.webbeans.bean.InstanceBean;
import org.jboss.webbeans.bean.ProducerFieldBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.bootstrap.spi.WebBeanDiscovery;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -161,12 +167,22 @@
beans.add(producerFieldBean);
log.info("Web Bean: " + producerFieldBean);
}
- for (AnnotatedField<Object> eventField : bean.getEventFields())
+ for (AnnotatedItem injectionPoint : bean.getInjectionPoints())
{
- EventBean<?> eventBean = createEventBean(eventField);
- beans.add(eventBean);
-
CurrentManager.rootManager().getResolver().addInjectionPoints(eventBean.getInjectionPoints());
- log.info("Web Bean: " + eventBean);
+ if ( injectionPoint.isAnnotationPresent(Observable.class) )
+ {
+ EventBean<Object, Field> eventBean = createEventBean(injectionPoint);
+ beans.add(eventBean);
+
//CurrentManager.rootManager().getResolver().addInjectionPoints(eventBean.getInjectionPoints());
+ log.info("Web Bean: " + eventBean);
+ }
+ if ( injectionPoint.isAnnotationPresent(Obtainable.class) )
+ {
+ InstanceBean<Object, Field> instanceBean =
createInstanceBean(injectionPoint);
+ beans.add(instanceBean);
+
//CurrentManager.rootManager().getResolver().addInjectionPoints(eventBean.getInjectionPoints());
+ log.info("Web Bean: " + instanceBean);
+ }
}
for (AnnotatedMethod<Object> observerMethod : bean.getObserverMethods())
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-12-08
01:02:40 UTC (rev 463)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -18,16 +18,12 @@
package org.jboss.webbeans.event;
import java.lang.annotation.Annotation;
-import java.util.HashSet;
-import java.util.Set;
-import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
-import javax.webbeans.Observable;
import javax.webbeans.Observer;
+import org.jboss.webbeans.FacadeImpl;
import org.jboss.webbeans.ManagerImpl;
-import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
/**
@@ -38,14 +34,8 @@
* @param <T>
* @see javax.webbeans.Event
*/
-public class EventImpl<T> implements Event<T>
+public class EventImpl<T> extends FacadeImpl<T> implements Event<T>
{
- // The set of binding types
- private final Set<? extends Annotation> bindingTypes;
- // The event type
- private final Class<T> eventType;
- private final ManagerImpl manager;
-
/**
* Constructor
*
@@ -53,62 +43,10 @@
*/
public EventImpl(ManagerImpl manager, Class<T> eventType, Annotation...
bindingTypes)
{
- this.manager = manager;
- this.bindingTypes = getBindingTypes(bindingTypes);
- this.eventType = eventType;
+ super(manager, eventType, bindingTypes);
}
/**
- * Validates the binding types
- *
- * Removes @Observable from the list
- *
- * @param annotations The annotations to validate
- * @return A set of binding type annotations (minus @Observable, if it was
- * present)
- */
- private static Set<Annotation> getBindingTypes(Annotation... annotations)
- {
- Set<Annotation> result = new HashSet<Annotation>();
- for (Annotation annotation : annotations)
- {
- if (!Reflections.isBindingType(annotation))
- {
- throw new IllegalArgumentException(annotation + " is not a binding
type");
- }
- if (!annotation.annotationType().equals(Observable.class))
- {
- result.add(annotation);
- }
- }
- return result;
- }
-
- /**
- * Validates the binding types and checks for duplicates among the annotations.
- *
- * @param annotations The annotations to validate
- * @return A set of unique binding type annotations
- */
- private Set<Annotation> checkBindingTypes(Annotation... annotations)
- {
- Set<Annotation> result = new HashSet<Annotation>();
- for (Annotation annotation : annotations)
- {
- if (!Reflections.isBindingType(annotation))
- {
- throw new IllegalArgumentException(annotation + " is not a binding type
for " + this);
- }
- if (result.contains(annotation) || this.bindingTypes.contains(annotation))
- {
- throw new DuplicateBindingTypeException(annotation + " is already
present in the bindings list for " + this);
- }
- result.add(annotation);
- }
- return result;
- }
-
- /**
* Fires an event
*
* @param event The event object
@@ -116,9 +54,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]));
+ manager.fireEvent(event, mergeBindings(bindingTypes));
}
/**
@@ -129,9 +65,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]));
+ manager.addObserver(observer, type, mergeBindings(bindingTypes));
}
@Override
@@ -139,7 +73,7 @@
{
StringBuilder buffer = new StringBuilder();
buffer.append("Observable Event:\n");
- buffer.append(" Event Type: " + eventType.getName() +"\n");
+ buffer.append(" Event Type: " + type.getName() +"\n");
buffer.append(Strings.collectionToString(" Event Bindings: ",
bindingTypes));
return buffer.toString();
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-08
01:02:40 UTC (rev 463)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -20,15 +20,20 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import javax.webbeans.Event;
+import javax.webbeans.Instance;
+
import org.jboss.webbeans.CurrentManager;
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.EnterpriseBean;
import org.jboss.webbeans.bean.EventBean;
+import org.jboss.webbeans.bean.InstanceBean;
import org.jboss.webbeans.bean.ProducerFieldBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
+import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
/**
@@ -117,15 +122,27 @@
/**
* Creates an event Web Bean
*
- * @param field The observer field abstraction
+ * @param field The event injection point abstraction
* @param declaringBean The declaring bean abstraction
* @return An event Web Bean
*/
- public static <T> EventBean<T> createEventBean(AnnotatedField<T>
field)
+ public static <T, S> EventBean<T, S>
createEventBean(AnnotatedItem<Event<T>, S> field)
{
- return new EventBean<T>(field, CurrentManager.rootManager());
+ return new EventBean<T, S>(field, CurrentManager.rootManager());
}
+ /**
+ * Creates an instance Web Bean
+ *
+ * @param field The instance injection point abstraction
+ * @param declaringBean The declaring bean abstraction
+ * @return An event Web Bean
+ */
+ public static <T, S> InstanceBean<T, S>
createInstanceBean(AnnotatedItem<Instance<T>, S> field)
+ {
+ return new InstanceBean<T, S>(field, CurrentManager.rootManager());
+ }
+
public static <T> ObserverImpl<T>
createObserver(AnnotatedMethod<Object> method, AbstractClassBean<?>
declaringBean)
{
return new ObserverImpl<T>(method, declaringBean,
CurrentManager.rootManager());
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-08
01:02:40 UTC (rev 463)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-08
01:07:34 UTC (rev 464)
@@ -6,6 +6,7 @@
import javax.webbeans.DefinitionException;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
+import javax.webbeans.Observable;
import javax.webbeans.Observer;
import javax.webbeans.TypeLiteral;
@@ -74,12 +75,17 @@
public void testEventBeanCreation()
{
SimpleBean<MyTest> myTestBean = BeanFactory.createSimpleBean(MyTest.class);
- for (AnnotatedField<Object> field : myTestBean.getEventFields())
- {
- EventBean eventBean = BeanFactory.createEventBean(field);
- Event<Param> event = eventBean.create();
- assert event != null;
+ boolean found = false;
+ for (AnnotatedField field : myTestBean.getInjectableFields()) {
+ if ( field.isAnnotationPresent(Observable.class) )
+ {
+ EventBean eventBean = BeanFactory.createEventBean(field);
+ Event<Param> event = eventBean.create();
+ assert event != null;
+ found = true;
+ }
}
+ assert found;
}
@Test(groups = { "stub", "events" })