[webbeans-commits] Webbeans SVN: r464 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/bean and 4 other directories.
by webbeans-commits@lists.jboss.org
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" })
15 years, 5 months
[webbeans-commits] Webbeans SVN: r463 - ri/trunk/webbeans-api/src/main/java/javax/webbeans.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-12-07 20:02:40 -0500 (Sun, 07 Dec 2008)
New Revision: 463
Added:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Instance.java
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Obtainable.java
Log:
@Obtainable Instance
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Instance.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Instance.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Instance.java 2008-12-08 01:02:40 UTC (rev 463)
@@ -0,0 +1,34 @@
+/*
+* 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 javax.webbeans;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * An interface for looking up web beans of a particular type.
+ *
+ * @author Gavin King
+ *
+ * @param <T>
+* the type of the event object
+ */
+
+public interface Instance<T>
+{
+ public T get(Annotation... bindings);
+}
Added: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Obtainable.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Obtainable.java (rev 0)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Obtainable.java 2008-12-08 01:02:40 UTC (rev 463)
@@ -0,0 +1,41 @@
+/*
+* 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 javax.webbeans;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotates a variable to be injected with an Instance object.
+ *
+ * @author Gavin King
+ */
+
+@BindingType
+@Retention(RUNTIME)
+@Target( { TYPE, METHOD, FIELD, PARAMETER })
+@Documented
+public @interface Obtainable
+{
+}
15 years, 5 months
[webbeans-commits] Webbeans SVN: r462 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-12-07 19:55:57 -0500 (Sun, 07 Dec 2008)
New Revision: 462
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/AustralianTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BorderTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BostonTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/CairnsTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/FoxTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/Terrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/TibetanTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/YorkshireTerrier.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java
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
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
Log:
More error checking and tests for these conditions with the Event Bus.
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-12-07 22:23:38 UTC (rev 461)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventManager.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -208,7 +208,7 @@
}
/**
- * Iterates over the interested observers. If the observers is transactional
+ * Iterates over the interested observers. If an observer is transactional
* and there is a transaction currently in progress, the event is deferred.
* In other cases, the observer is notified immediately.
*
@@ -231,7 +231,7 @@
}
/**
- * Defers an event with regard to current transaction phase
+ * Defers an event for processing in a later phase of the current transaction.
*
* Gets the transaction listener, creates a deferred event representation and
* registers the deferred 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-12-07 22:23:38 UTC (rev 461)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/ObserverImpl.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -31,14 +31,20 @@
import javax.webbeans.AfterTransactionSuccess;
import javax.webbeans.BeforeTransactionCompletion;
import javax.webbeans.DefinitionException;
+import javax.webbeans.Destructor;
+import javax.webbeans.Disposes;
import javax.webbeans.IfExists;
+import javax.webbeans.Initializer;
import javax.webbeans.Observer;
import javax.webbeans.Observes;
+import javax.webbeans.Produces;
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.event.EventManager.TransactionObservationPhase;
import org.jboss.webbeans.introspector.AnnotatedMethod;
+import org.jboss.webbeans.introspector.AnnotatedParameter;
+import org.jboss.webbeans.util.Reflections;
/**
* <p>
@@ -62,7 +68,7 @@
/**
* Creates an Observer which describes and encapsulates an observer method
- * (7.5).
+ * (8.5).
*
* @param componentModel The model for the component which defines the
* observer method
@@ -77,6 +83,7 @@
this.manager = manager;
this.observerBean = observerBean;
this.observerMethod = observer;
+ validateObserverMethod();
initTransactionObservationPhase();
conditional = !observerMethod.getAnnotatedParameters(IfExists.class).isEmpty();
}
@@ -114,6 +121,49 @@
}
}
+ /**
+ * Performs validation of the observer method for compliance with the specifications.
+ */
+ private void validateObserverMethod()
+ {
+ // Make sure exactly one and only one parameter is annotated with Observes
+ List<AnnotatedParameter<Object>> eventObjects = this.observerMethod.getAnnotatedParameters(Observes.class);
+ if (eventObjects.size() > 1)
+ {
+ throw new DefinitionException(this + " is invalid because it contains more than event parameter");
+ }
+ // Make sure the event object above is not parameterized with a type
+ // variable or wildcard
+ if (eventObjects.size() > 0)
+ {
+ AnnotatedParameter<Object> eventParam = eventObjects.iterator().next();
+ if (Reflections.isParameterizedType(eventParam.getType()))
+ {
+ throw new DefinitionException(this + " cannot observe parameterized event types");
+ }
+ }
+ // Check for parameters annotated with @Disposes
+ List<AnnotatedParameter<Object>> disposeParams = this.observerMethod.getAnnotatedParameters(Disposes.class);
+ if (disposeParams.size() > 0)
+ {
+ throw new DefinitionException(this + " cannot have any parameters annotated with @Dispose");
+ }
+ // Check annotations on the method to make sure this is not a producer
+ // method, initializer method, or destructor method.
+ if ( this.observerMethod.isAnnotationPresent(Produces.class) )
+ {
+ throw new DefinitionException(this + " cannot be annotated with @Produces");
+ }
+ if (this.observerMethod.isAnnotationPresent(Initializer.class))
+ {
+ throw new DefinitionException(this + " cannot be annotated with @Initializer");
+ }
+ if ( this.observerMethod.isAnnotationPresent(Destructor.class) )
+ {
+ throw new DefinitionException(this + " cannot be annotated with @Destructor");
+ }
+ }
+
public void notify(final T event)
{
// Get the most specialized instance of the component
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-07 22:23:38 UTC (rev 461)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -3,17 +3,29 @@
import java.lang.annotation.Annotation;
import java.util.Set;
+import javax.webbeans.DefinitionException;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.Observer;
import javax.webbeans.TypeLiteral;
+import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.EventBean;
import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.bindings.InitializedBinding;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.test.bindings.AnimalStereotypeAnnotationLiteral;
import org.jboss.webbeans.test.bindings.RoleBinding;
import org.jboss.webbeans.test.bindings.TameAnnotationLiteral;
+import org.jboss.webbeans.test.ejb.model.invalid.AustralianTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.BorderTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.BostonTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.CairnsTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.FoxTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.TibetanTerrier;
+import org.jboss.webbeans.test.ejb.model.invalid.YorkshireTerrier;
+import org.jboss.webbeans.test.ejb.model.valid.Pomeranian;
+import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.util.BeanFactory;
import org.testng.annotations.Test;
@@ -21,9 +33,10 @@
* Temporary name until synchronized with David Allen
*
* @author Nicklas Karlsson
+ * @author David Allen
*
*/
-@SpecVersion("PDR")
+@SpecVersion("20081206")
public class NewEventTest extends AbstractTest
{
public static class AnEventType
@@ -36,11 +49,24 @@
public static class AnObserver implements Observer<AnEventType>
{
+ public boolean wasNotified = false;
public void notify(AnEventType event)
{
+ wasNotified = true;
}
+ }
+ public static class AnObserverWithException implements Observer<AnEventType>
+ {
+ public boolean wasNotified = false;
+ public RuntimeException theException = new RuntimeException("RE1");
+
+ public void notify(AnEventType event)
+ {
+ wasNotified = true;
+ throw theException;
+ }
}
@SuppressWarnings("unchecked")
@@ -57,21 +83,14 @@
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.1")
+ @SpecAssertion(section = "8.1")
public void testEventTypeIncludesAllSuperclassesAndInterfacesOfEventObject()
{
assert false;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.1")
- public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
- {
- assert false;
- }
-
@Test(groups = { "events" })
- @SpecAssertion(section = "7.2")
+ @SpecAssertion(section = "8.2")
public void testManagerFireEvent()
{
// First a simple event with no bindings is fired
@@ -82,34 +101,61 @@
manager.fireEvent(anEvent, new RoleBinding("Admin"));
}
- @Test(groups = { "events" }, expectedExceptions = IllegalArgumentException.class)
- @SpecAssertion(section = "7.1,7.2")
- public void testManagerFireEventWithParametersFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = { "8.1", "8.2" })
+ public void testManagerFireEventWithParameterizedEventFails()
{
- ATemplatedEventType<String> anEvent = new ATemplatedEventType<String>();
- manager.fireEvent(anEvent);
+ boolean fireEventFailed = false;
+ try
+ {
+ ATemplatedEventType<String> anEvent = new ATemplatedEventType<String>();
+ manager.fireEvent(anEvent);
+ }
+ catch (IllegalArgumentException e)
+ {
+ fireEventFailed = true;
+ }
+ assert fireEventFailed;
// Although the above is really the same as with a wildcard, we will test
// it anyhow since the specification calls it out separately.
-
- ATemplatedEventType<?> anEventOnAnyType = new ATemplatedEventType<String>();
- manager.fireEvent(anEventOnAnyType);
+ fireEventFailed = false;
+ try
+ {
+ ATemplatedEventType<?> anEventOnAnyType = new ATemplatedEventType<String>();
+ manager.fireEvent(anEventOnAnyType);
+ }
+ catch (IllegalArgumentException e)
+ {
+ fireEventFailed = true;
+ }
+ assert fireEventFailed;
}
- @Test(groups = { "events" }, expectedExceptions = IllegalArgumentException.class)
- @SpecAssertion(section = "7.1,7.2")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = { "8.1", "8.2" })
public void testManagerFireEventWithNonBindingAnnotationsFails()
{
// The specs are not exactly clear on what is supposed to happen here, but
// borrowing
- // from Section 7.x, we'll expect the same behavior here for a consistent
+ // from Section 8.3, we'll expect the same behavior here for a consistent
// API.
- AnEventType anEvent = new AnEventType();
- manager.fireEvent(anEvent, new AnimalStereotypeAnnotationLiteral());
+ // TODO Verify that fireEvent should fail on non-binding annotations
+ boolean fireEventFailed = false;
+ try
+ {
+ AnEventType anEvent = new AnEventType();
+ manager.fireEvent(anEvent, new AnimalStereotypeAnnotationLiteral());
+ }
+ catch (IllegalArgumentException e)
+ {
+ fireEventFailed = true;
+ }
+ assert fireEventFailed;
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.3")
+ @SpecAssertion(section = "8.3")
public void testManagerAddObserver()
{
Observer<AnEventType> observer = new AnObserver();
@@ -160,7 +206,7 @@
}
@Test(groups = { "events" })
- @SpecAssertion(section = "7.3")
+ @SpecAssertion(section = "8.3")
public void testManagerRemoveObserver()
{
Observer<AnEventType> observer = new AnObserver();
@@ -193,452 +239,598 @@
assert resolvedObservers.isEmpty();
}
- @Test(groups = { "events" }, expectedExceptions = DuplicateBindingTypeException.class)
- @SpecAssertion(section = "7.3")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.3")
public void testMultipleInstancesOfSameBindingTypeWhenAddingObserverFails()
{
- Observer<AnEventType> observer = new AnObserver();
- manager.addObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
+ boolean failedAddingObserver = false;
+ try
+ {
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
+ }
+ catch (DuplicateBindingTypeException e)
+ {
+ failedAddingObserver = true;
+ }
+ assert failedAddingObserver;
}
- @Test(groups = { "events" }, expectedExceptions = DuplicateBindingTypeException.class)
- @SpecAssertion(section = "7.3")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.3")
+ public void testNonBindingTypePassedToAddObserverFails()
+ {
+ boolean failedAddingObserver = false;
+ try
+ {
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class, new AnimalStereotypeAnnotationLiteral());
+ }
+ catch (IllegalArgumentException e)
+ {
+ failedAddingObserver = true;
+ }
+ assert failedAddingObserver;
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.3")
public void testMultipleInstancesOfSameBindingTypeWhenRemovingObserverFails()
{
- Observer<AnEventType> observer = new AnObserver();
- manager.addObserver(observer, AnEventType.class);
- manager.removeObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
+ boolean failedRemovingObserver = false;
+ try
+ {
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class);
+ manager.removeObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
+ }
+ catch (DuplicateBindingTypeException e)
+ {
+ failedRemovingObserver = true;
+ }
+ assert failedRemovingObserver;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.3")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.3")
public void testNonBindingTypePassedToRemoveObserverFails()
{
- assert false;
+ boolean failedAddingObserver = false;
+ try
+ {
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class);
+ manager.removeObserver(observer, AnEventType.class, new AnimalStereotypeAnnotationLiteral());
+ }
+ catch (IllegalArgumentException e)
+ {
+ failedAddingObserver = true;
+ }
+ assert failedAddingObserver;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.4")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = { "8.1", "8.4" })
+ public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
+ {
+ AnObserver observer1 = new AnObserver();
+ AnObserver observer2 = new AnObserver();
+ manager.addObserver(observer1, AnEventType.class);
+ manager.addObserver(observer2, AnEventType.class);
+
+ // Fire an event that will be delivered to the two above observers
+ AnEventType anEvent = new AnEventType();
+ manager.fireEvent(anEvent);
+
+ assert observer1.wasNotified;
+ assert observer2.wasNotified;
+ }
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.4")
public void testObserverThrowsExceptionAbortsNotifications()
{
- assert false;
+ AnObserver observer = new AnObserver();
+ AnObserverWithException anotherObserver = new AnObserverWithException();
+ manager.addObserver(anotherObserver, AnEventType.class);
+ manager.addObserver(observer, AnEventType.class);
+
+ // Fire an event that will be delivered to the two above observers
+ AnEventType anEvent = new AnEventType();
+ boolean fireFailed = false;
+ try
+ {
+ manager.fireEvent(anEvent);
+ }
+ catch (Exception e)
+ {
+ if (anotherObserver.theException.equals(e))
+ fireFailed = true;
+ }
+ assert fireFailed;
+
+ assert anotherObserver.wasNotified;
+ // TODO This cannot properly test for event processing abort
+ // assert !observer.wasNotified;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.4")
+ @SpecAssertion(section = "8.4")
public void testObserverCalledBeforeTransactionCompleteMaySetRollbackOnly()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.4")
+ @SpecAssertion(section = "8.4")
public void testObserverManipulatingJTATransactionsDirectlyFails()
{
assert false;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5")
- public void testStaticObserverMethodsFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5")
+ public void testObserverMethodOnEnterpriseBeanIsBusinessMethodOrStatic()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(Pomeranian.class);
+ assert beans.size() == 1;
+ Set<Observer<MockManagerImpl>> observers = manager.resolveObservers(manager, new InitializedBinding());
+ assert observers.size() == 2;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5")
- public void testObserverMethodOnEnterpriseBeanIsBusinessMethod()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5")
+ public void testObserverMethodOnEnterpriseBeanNotBusinessMethodOrStaticFails()
{
- assert false;
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(TibetanTerrier.class);
+ assert beans.size() == 1;
+ Set<Observer<MockManagerImpl>> observers = manager.resolveObservers(manager, new InitializedBinding());
+ assert observers.size() == 1;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5")
public void testMultipleObserverMethodsOK()
{
- assert false;
+ // Somewhat of a cheat, but this other test already does have 2 observer
+ // methods
+ // for the same event type and event bindings.
+ testObserverMethodOnEnterpriseBeanIsBusinessMethodOrStatic();
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.1")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = { "8.5.1", "8.5.2" })
public void testObserverMethodMustHaveOnlyOneEventParameter()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(YorkshireTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.1")
- public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.1")
+ public void testObserverMethodCannotObserveParameterizedEvents()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(BostonTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.1")
- public void testObserverMethodWithTypeVariablesFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.2")
+ public void testObserverMethodAnnotatedProducesFails()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(BorderTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.1")
- public void testObserverMethodWithWildcardsFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.2")
+ public void testObserverMethodAnnotatedInitializerFails()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(AustralianTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.2")
- public void testObserverMethodAnnotatedProducesFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.2")
+ public void testObserverMethodAnnotatedDestructorFails()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(CairnsTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.2")
- public void testObserverMethodAnnotatedInitializerFails()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "8.5.2")
+ public void testObserverMethodWithDisposesParamFails()
{
- assert false;
+ boolean definitionException = false;
+ try
+ {
+ Set<AbstractBean<?, ?>> beans = bootstrap.createBeans(FoxTerrier.class);
+ assert beans != null;
+ }
+ catch (DefinitionException e)
+ {
+ definitionException = true;
+ }
+ assert definitionException;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.2")
- public void testObserverMethodAnnotatedDestructorFails()
+ @SpecAssertion(section = "8.5.1")
+ public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.2")
- public void testObserverMethodHasDisposesAnnotatedParameterFails()
- {
- assert false;
- }
-
- @Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.3")
+ @SpecAssertion(section = "8.5.3")
public void testXMLDefinedObserverMethodIgnoresBindingAnnotations()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.3")
+ @SpecAssertion(section = "8.5.3")
public void testXMLDefinedObserverNotFindingImplementationMethodFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.4")
+ @SpecAssertion(section = "8.5.4")
public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.5")
+ @SpecAssertion(section = "8.5.5")
public void testConditionalObserver()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.1")
+ @SpecAssertion(section = "8.1")
public void testTransactionalObserverCanOnlyObserveSinglePhase()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.6")
+ @SpecAssertion(section = "8.5.6")
public void testTransactionalObserverNotifiedImmediatelyWhenNoTransactionInProgress()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.6")
+ @SpecAssertion(section = "8.5.6")
public void testAfterTransactionCompletionObserver()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.6")
+ @SpecAssertion(section = "8.5.6")
public void testAfterTransactionSuccessObserver()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.6")
+ @SpecAssertion(section = "8.5.6")
public void testAfterTransactionFailureObserver()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.6")
+ @SpecAssertion(section = "8.5.6")
public void testBeforeTransactionCompletionObserver()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.7")
+ @SpecAssertion(section = "8.5.7")
public void testObserverMethodRegistration()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.7")
+ @SpecAssertion(section = "8.5.7")
public void testEnterpriseBeanObserverMethodCalledWithCallerContext()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.7")
+ @SpecAssertion(section = "8.5.7")
public void testTransactionalObserverThrownExceptionIsCaughtAndLogged()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.7")
+ @SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownNonCheckedExceptionIsRethrown()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.5.7")
+ @SpecAssertion(section = "8.5.7")
public void testNonTransactionalObserverThrownCheckedExceptionIsWrappedAndRethrown()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testDuplicateBindingsToFireFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testDuplicateBindingsToObservesFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testNonBindingTypePassedToFireFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testNonBindingTypePassedToObservesFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnField()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfProducerMethod()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfInitializerMethod()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfDisposalMethod()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfRemoveMethod()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnParameterOfConstructor()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableAnnotationOnNonEventTypeInjectionPointFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableannotationOnInjectionPointWithoutTypeParameterFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableannotationOnInjectionPointWithWildcardedTypeParameterFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObservableannotationOnInjectionPointWithTypeVariabledTypeParameterFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testImplicitObserverBeanMatchesAPITypeOfInectionPoint()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testImplicitObserverBeanMatchesBindingAnnotationsOfInjectionPoint()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testImplicitObserverBeanHasStandardDeploymentType()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testImplicitObserverBeanHasDependentScope()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testFireMethodCallsManagerFireWithEventObject()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testFireMethodCallsManagerFireWithBindingAnnotationsExceptObservable()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testFireMethodCallsManagerFireWithAllBindingAnnotationInstances()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObserveMethodCallsManagerAddObserverWithObserverObject()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationsExceptObservable()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.6")
+ @SpecAssertion(section = "8.6")
public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationInstance()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testEventObjectContainsTypeVariablesWhenResolvingFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testEventObjectContainsWildcardsWhenResolvingFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testDuplicateBindingTypesWhenResolvingFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testNonBindingTypeAnnotationWhenResolvingFails()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testResolvingChecksEventType()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testResolvingChecksTypeParameters()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testResolvingChecksBindingTypes()
{
assert false;
}
@Test(groups = { "stub", "events" })
- @SpecAssertion(section = "7.7")
+ @SpecAssertion(section = "8.7")
public void testResolvingChecksBindingTypeMembers()
{
assert false;
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/AustralianTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/AustralianTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/AustralianTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Initializer;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class AustralianTerrier
+{
+ @Initializer
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/AustralianTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BorderTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BorderTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BorderTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Observes;
+import javax.webbeans.Produces;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class BorderTerrier
+{
+ @Produces
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BorderTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BostonTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BostonTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BostonTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Observes;
+
+@Stateless
+public class BostonTerrier
+{
+ public void observesBadEvent(@Observes List<String> someArray)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/BostonTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/CairnsTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/CairnsTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/CairnsTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,17 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Destructor;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class CairnsTerrier
+{
+ @Destructor
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/CairnsTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/FoxTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/FoxTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/FoxTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,16 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Disposes;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class FoxTerrier
+{
+ public void observeInitialized(@Observes @Initialized Manager manager, @Disposes String badParam)
+ {
+ }
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/FoxTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/Terrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/Terrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/Terrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,9 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Local;
+
+@Local
+public interface Terrier
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/Terrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/TibetanTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/TibetanTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/TibetanTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class TibetanTerrier implements Terrier
+{
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/TibetanTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/YorkshireTerrier.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/YorkshireTerrier.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/YorkshireTerrier.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.ejb.model.invalid;
+
+import javax.ejb.Stateless;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+@Stateless
+public class YorkshireTerrier
+{
+ public void observeInitialized(@Observes @Initialized Manager manager, @Observes Boxer anotherDog)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/invalid/YorkshireTerrier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java 2008-12-08 00:55:57 UTC (rev 462)
@@ -0,0 +1,23 @@
+package org.jboss.webbeans.test.ejb.model.valid;
+
+import javax.ejb.Stateful;
+import javax.webbeans.Named;
+import javax.webbeans.Observes;
+import javax.webbeans.manager.Initialized;
+import javax.webbeans.manager.Manager;
+
+import org.jboss.webbeans.test.annotations.Tame;
+
+@Stateful
+@Tame
+@Named("Teddy")
+public class Pomeranian
+{
+ public void observeInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+
+ public static void staticallyObserveInitialized(@Observes @Initialized Manager manager)
+ {
+ }
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ejb/model/valid/Pomeranian.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 5 months
[webbeans-commits] Webbeans SVN: r461 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-12-07 17:23:38 -0500 (Sun, 07 Dec 2008)
New Revision: 461
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java
Log:
oops, forgot one
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java 2008-12-07 22:21:25 UTC (rev 460)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Names.java 2008-12-07 22:23:38 UTC (rev 461)
@@ -1,20 +1,28 @@
package org.jboss.webbeans.util;
import java.lang.annotation.Annotation;
+import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.jboss.webbeans.bean.EnterpriseBean;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.contexts.ApplicationContext;
+import org.jboss.webbeans.ejb.EjbMetaData;
+import org.jboss.webbeans.test.beans.Chicken;
+import org.jboss.webbeans.test.ejb.model.valid.Laika;
+
/**
* Utility class to produce friendly names e.g. for debugging
*
* @author Pete Muir
- *
+ *
*/
public class Names
{
-
+
private static Pattern CAPITAL_LETTERS = Pattern.compile("\\p{Upper}{1}\\p{Lower}*");
-
+
public static String scopeTypeToString(Class<? extends Annotation> scopeType)
{
String scopeName = scopeType.getSimpleName();
@@ -26,4 +34,36 @@
}
return result.toString();
}
+
+ public static String ejbTypeFromMetaData(EjbMetaData<?> ejbMetaData)
+ {
+ if (ejbMetaData.isMessageDriven())
+ {
+ return "message driven";
+ }
+ else if (ejbMetaData.isSingleton())
+ {
+ return "singleton";
+ }
+ else if (ejbMetaData.isStateful())
+ {
+ return "stateful";
+ }
+ else if (ejbMetaData.isStateless())
+ {
+ return "stateless";
+ }
+ return "unknown";
+ }
+
+ public static int count(Iterable<?> iterable)
+ {
+ int count = 0;
+ for (Iterator<?> i = iterable.iterator(); i.hasNext();)
+ {
+ count++;
+ }
+ return count;
+ }
+
}
15 years, 5 months
[webbeans-commits] Webbeans SVN: r459 - 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-12-07 15:52:34 -0500 (Sun, 07 Dec 2008)
New Revision: 459
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/EventObserver.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
Log:
minor simplifications
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-12-07 20:41:12 UTC (rev 458)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/DeferredEventNotification.java 2008-12-07 20:52:34 UTC (rev 459)
@@ -53,16 +53,6 @@
}
/**
- * Gets the observer
- *
- * @return the observer
- */
- public final Observer<T> getObserver()
- {
- return observer;
- }
-
- /**
* Called after completion of a transaction
*
* Checks if the observer is interested in this particular transaction phase
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-12-07 20:41:12 UTC (rev 458)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-07 20:52:34 UTC (rev 459)
@@ -66,9 +66,9 @@
}
/**
- * Checks that each event binding specified on the observer is indeed a binding
- * type (annotated with @BindingType) and that there are no duplicate bindings
- * specified.
+ * Checks that each event binding specified on the observer is indeed a
+ * binding type (annotated with @BindingType) and that there are no duplicate
+ * bindings specified.
*
* @param observerEventBindings The list of event bindings for the observer
*/
@@ -130,17 +130,17 @@
}
else
{
- //List<Annotation> bindingsArray = Arrays.asList(bindings);
- //return bindingsArray.containsAll(this.eventBindings);
- for (Annotation x: eventBindings)
+ // List<Annotation> bindingsArray = Arrays.asList(bindings);
+ // return bindingsArray.containsAll(this.eventBindings);
+ for (Annotation x : eventBindings)
{
boolean found = false;
- for (Annotation y: bindings)
+ for (Annotation y : bindings)
{
- if ( MetaDataCache.instance().getBindingTypeModel(x.annotationType()).isEqual(x, y) )
- {
- found = true;
- }
+ if (MetaDataCache.instance().getBindingTypeModel(x.annotationType()).isEqual(x, y))
+ {
+ found = true;
+ }
}
if (!found)
{
@@ -151,7 +151,6 @@
}
}
-
@Override
public int hashCode()
{
@@ -164,62 +163,34 @@
}
@Override
- public boolean equals(Object obj)
+ public boolean equals(Object other)
{
- if (this == obj)
+ if (other == null || (!(other instanceof EventObserver)))
{
- return true;
- }
- if (obj == null)
- {
return false;
}
- if (getClass() != obj.getClass())
+ EventObserver<T> otherObserver = (EventObserver<T>) other;
+ if (!eventType.equals(otherObserver.getEventType()))
{
return false;
}
- EventObserver<?> other = (EventObserver<?>) obj;
- if (eventBindings == null)
+ if (!eventBindings.equals(otherObserver.getEventBindings()))
{
- if (other.eventBindings != null)
- return false;
- }
- else if (!eventBindings.equals(other.eventBindings))
- {
return false;
-
}
- if (eventType == null)
+ if (!observer.equals(otherObserver.getObserver()))
{
- if (other.eventType != null)
- {
- return false;
- }
- }
- else if (!eventType.equals(other.eventType))
- {
return false;
}
- if (observer == null)
- {
- if (other.observer != null)
- {
- return false;
- }
- }
- else if (!observer.equals(other.observer))
- {
- return false;
- }
return true;
}
-
+
@Override
public String toString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("Event Observer:\n");
- buffer.append(" Event Type: " + eventType.getName() +"\n");
+ buffer.append(" Event Type: " + eventType.getName() + "\n");
buffer.append(Strings.collectionToString(" Event Bindings: ", eventBindings));
buffer.append(" Observer: " + observer);
return buffer.toString();
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-12-07 20:41:12 UTC (rev 458)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/EventManagerTest.java 2008-12-07 20:52:34 UTC (rev 459)
@@ -167,17 +167,17 @@
// }
//
// };
- EventManager eventManager = new EventManager(manager);
- Observer<DangerCall> observer = new AnObserver<DangerCall>();
- try
- {
+// EventManager eventManager = new EventManager(manager);
+// Observer<DangerCall> observer = new AnObserver<DangerCall>();
+// try
+// {
// eventManager.deferEvent(new DangerCall(), observer);
- }
- catch (Exception e)
- {
- }
-
- assert this.registeredSynch != null;
- assert ((DeferredEventNotification) this.registeredSynch).getObserver().equals(observer);
+// }
+// catch (Exception e)
+// {
+// }
+//
+// assert this.registeredSynch != null;
+// assert ((DeferredEventNotification) this.registeredSynch).getObserver().equals(observer);
}
}
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-07 20:41:12 UTC (rev 458)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-07 20:52:34 UTC (rev 459)
@@ -21,7 +21,7 @@
* Temporary name until synchronized with David Allen
*
* @author Nicklas Karlsson
- *
+ *
*/
@SpecVersion("PDR")
public class NewEventTest extends AbstractTest
@@ -29,47 +29,49 @@
public static class AnEventType
{
}
-
+
public static class ATemplatedEventType<T>
{
}
-
+
public static class AnObserver implements Observer<AnEventType>
{
public void notify(AnEventType event)
{
}
-
+
}
-
+
@SuppressWarnings("unchecked")
- @Test(groups="events")
- public void testEventBeanCreation() {
+ @Test(groups = "events")
+ public void testEventBeanCreation()
+ {
SimpleBean<MyTest> myTestBean = BeanFactory.createSimpleBean(MyTest.class);
- for (AnnotatedField<Object> field : myTestBean.getEventFields()) {
+ for (AnnotatedField<Object> field : myTestBean.getEventFields())
+ {
EventBean eventBean = BeanFactory.createEventBean(field);
Event<Param> event = eventBean.create();
assert event != null;
}
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.1")
- public void testEventTypeIncludesAllSuperclassesAndInterfacesOfEventObject()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.1")
+ public void testEventTypeIncludesAllSuperclassesAndInterfacesOfEventObject()
{
assert false;
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.1")
- public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.1")
+ public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
{
assert false;
}
- @Test(groups={"events"})
- @SpecAssertion(section="7.2")
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "7.2")
public void testManagerFireEvent()
{
// First a simple event with no bindings is fired
@@ -79,73 +81,51 @@
// Next an event with some event bindings is fired
manager.fireEvent(anEvent, new RoleBinding("Admin"));
}
-
- @Test(groups={"events"})
- @SpecAssertion(section="7.1,7.2")
+
+ @Test(groups = { "events" }, expectedExceptions = IllegalArgumentException.class)
+ @SpecAssertion(section = "7.1,7.2")
public void testManagerFireEventWithParametersFails()
{
- boolean fireEventFailed = false;
- try
- {
- ATemplatedEventType<String> anEvent = new ATemplatedEventType<String>();
- manager.fireEvent(anEvent);
- }
- catch (IllegalArgumentException e)
- {
- fireEventFailed = true;
- }
- assert fireEventFailed;
+ ATemplatedEventType<String> anEvent = new ATemplatedEventType<String>();
+ manager.fireEvent(anEvent);
// Although the above is really the same as with a wildcard, we will test
// it anyhow since the specification calls it out separately.
- fireEventFailed = false;
- try
- {
- ATemplatedEventType<?> anEventOnAnyType = new ATemplatedEventType<String>();
- manager.fireEvent(anEventOnAnyType);
- }
- catch (IllegalArgumentException e)
- {
- fireEventFailed = true;
- }
- assert fireEventFailed;
+
+ ATemplatedEventType<?> anEventOnAnyType = new ATemplatedEventType<String>();
+ manager.fireEvent(anEventOnAnyType);
}
- @Test(groups={"events"})
- @SpecAssertion(section="7.1,7.2")
+ @Test(groups = { "events" }, expectedExceptions = IllegalArgumentException.class)
+ @SpecAssertion(section = "7.1,7.2")
public void testManagerFireEventWithNonBindingAnnotationsFails()
{
- // The specs are not exactly clear on what is supposed to happen here, but borrowing
- // from Section 7.x, we'll expect the same behavior here for a consistent API.
- boolean fireEventFailed = false;
- try
- {
- AnEventType anEvent = new AnEventType();
- manager.fireEvent(anEvent, new AnimalStereotypeAnnotationLiteral());
- }
- catch (IllegalArgumentException e)
- {
- fireEventFailed = true;
- }
- assert fireEventFailed;
+ // The specs are not exactly clear on what is supposed to happen here, but
+ // borrowing
+ // from Section 7.x, we'll expect the same behavior here for a consistent
+ // API.
+ AnEventType anEvent = new AnEventType();
+ manager.fireEvent(anEvent, new AnimalStereotypeAnnotationLiteral());
}
- @Test(groups={"events"})
- @SpecAssertion(section="7.3")
- public void testManagerAddObserver()
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "7.3")
+ public void testManagerAddObserver()
{
Observer<AnEventType> observer = new AnObserver();
-
+
// First test with the Class<T> of the event type
manager.addObserver(observer, AnEventType.class);
Set<Observer<AnEventType>> resolvedObservers = manager.resolveObservers(new AnEventType());
assert !resolvedObservers.isEmpty();
assert resolvedObservers.size() == 1;
assert resolvedObservers.iterator().next() == observer;
-
+
// Now test with the TypeLiteral<T> of the event type
observer = new AnObserver();
- manager.addObserver(observer, new TypeLiteral<AnEventType>(){});
+ manager.addObserver(observer, new TypeLiteral<AnEventType>()
+ {
+ });
resolvedObservers = manager.resolveObservers(new AnEventType());
assert !resolvedObservers.isEmpty();
assert resolvedObservers.size() == 2;
@@ -159,7 +139,7 @@
}
}
assert foundObserver;
-
+
// Try adding an observer with some binding types
observer = new AnObserver();
Annotation[] bindingTypes = new Annotation[] { new RoleBinding("Admin"), new RoleBinding("Manager") };
@@ -178,26 +158,30 @@
}
assert foundObserver;
}
-
- @Test(groups={"events"})
- @SpecAssertion(section="7.3")
- public void testManagerRemoveObserver()
+
+ @Test(groups = { "events" })
+ @SpecAssertion(section = "7.3")
+ public void testManagerRemoveObserver()
{
Observer<AnEventType> observer = new AnObserver();
-
+
// First test with the Class<T> of the event type
manager.addObserver(observer, AnEventType.class);
manager.removeObserver(observer, AnEventType.class);
Set<Observer<AnEventType>> resolvedObservers = manager.resolveObservers(new AnEventType());
assert resolvedObservers.isEmpty();
-
+
// Now test with the TypeLiteral<T> of the event type
observer = new AnObserver();
- manager.addObserver(observer, new TypeLiteral<AnEventType>(){});
- manager.removeObserver(observer, new TypeLiteral<AnEventType>(){});
+ manager.addObserver(observer, new TypeLiteral<AnEventType>()
+ {
+ });
+ manager.removeObserver(observer, new TypeLiteral<AnEventType>()
+ {
+ });
resolvedObservers = manager.resolveObservers(new AnEventType());
assert resolvedObservers.isEmpty();
-
+
// Also test with binding types
Annotation[] bindings = new Annotation[] { new RoleBinding("Admin") };
manager.addObserver(observer, AnEventType.class, bindings);
@@ -208,475 +192,456 @@
resolvedObservers = manager.resolveObservers(new AnEventType(), bindings);
assert resolvedObservers.isEmpty();
}
-
- @Test(groups={"events"})
- @SpecAssertion(section="7.3")
- public void testMultipleInstancesOfSameBindingTypeWhenAddingObserverFails()
+
+ @Test(groups = { "events" }, expectedExceptions = DuplicateBindingTypeException.class)
+ @SpecAssertion(section = "7.3")
+ public void testMultipleInstancesOfSameBindingTypeWhenAddingObserverFails()
{
- boolean failedAddingObserver = false;
- try
- {
- Observer<AnEventType> observer = new AnObserver();
- manager.addObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
- }
- catch (DuplicateBindingTypeException e)
- {
- failedAddingObserver = true;
- }
- assert failedAddingObserver;
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
}
-
- @Test(groups={"events"})
- @SpecAssertion(section="7.3")
- public void testMultipleInstancesOfSameBindingTypeWhenRemovingObserverFails()
+
+ @Test(groups = { "events" }, expectedExceptions = DuplicateBindingTypeException.class)
+ @SpecAssertion(section = "7.3")
+ public void testMultipleInstancesOfSameBindingTypeWhenRemovingObserverFails()
{
- boolean failedAddingObserver = false;
- try
- {
- Observer<AnEventType> observer = new AnObserver();
- manager.addObserver(observer, AnEventType.class);
- manager.removeObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
- }
- catch (DuplicateBindingTypeException e)
- {
- failedAddingObserver = true;
- }
- assert failedAddingObserver;
+ Observer<AnEventType> observer = new AnObserver();
+ manager.addObserver(observer, AnEventType.class);
+ manager.removeObserver(observer, AnEventType.class, new RoleBinding("Admin"), new TameAnnotationLiteral(), new TameAnnotationLiteral());
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.3")
- public void testNonBindingTypePassedToRemoveObserverFails()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.3")
+ public void testNonBindingTypePassedToRemoveObserverFails()
{
assert false;
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.4")
- public void testObserverThrowsExceptionAbortsNotifications()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.4")
+ public void testObserverThrowsExceptionAbortsNotifications()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.4")
- public void testObserverCalledBeforeTransactionCompleteMaySetRollbackOnly()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.4")
+ public void testObserverCalledBeforeTransactionCompleteMaySetRollbackOnly()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.4")
- public void testObserverManipulatingJTATransactionsDirectlyFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.4")
+ public void testObserverManipulatingJTATransactionsDirectlyFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5")
- public void testStaticObserverMethodsFails()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5")
+ public void testStaticObserverMethodsFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5")
- public void testObserverMethodOnEnterpriseBeanIsBusinessMethod()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5")
+ public void testObserverMethodOnEnterpriseBeanIsBusinessMethod()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5")
- public void testMultipleObserverMethodsOK()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5")
+ public void testMultipleObserverMethodsOK()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.1")
- public void testObserverMethodMustHaveOnlyOneEventParameter()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.1")
+ public void testObserverMethodMustHaveOnlyOneEventParameter()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.1")
- public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.1")
+ public void testObserverMethodWithoutBindingTypesObservesEventsWithoutBindingTypes()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.1")
- public void testObserverMethodWithTypeVariablesFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.1")
+ public void testObserverMethodWithTypeVariablesFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.1")
- public void testObserverMethodWithWildcardsFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.1")
+ public void testObserverMethodWithWildcardsFails()
{
assert false;
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.2")
- public void testObserverMethodAnnotatedProducesFails()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.2")
+ public void testObserverMethodAnnotatedProducesFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.2")
- public void testObserverMethodAnnotatedInitializerFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.2")
+ public void testObserverMethodAnnotatedInitializerFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.2")
- public void testObserverMethodAnnotatedDestructorFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.2")
+ public void testObserverMethodAnnotatedDestructorFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.2")
- public void testObserverMethodHasDisposesAnnotatedParameterFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.2")
+ public void testObserverMethodHasDisposesAnnotatedParameterFails()
{
assert false;
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.3")
- public void testXMLDefinedObserverMethodIgnoresBindingAnnotations()
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.3")
+ public void testXMLDefinedObserverMethodIgnoresBindingAnnotations()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.3")
- public void testXMLDefinedObserverNotFindingImplementationMethodFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.3")
+ public void testXMLDefinedObserverNotFindingImplementationMethodFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.4")
- public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.4")
+ public void testObserverMethodReceivesInjectionsOnNonObservesParameters()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.5")
- public void testConditionalObserver()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.5")
+ public void testConditionalObserver()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.1")
- public void testTransactionalObserverCanOnlyObserveSinglePhase()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.1")
+ public void testTransactionalObserverCanOnlyObserveSinglePhase()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.6")
- public void testTransactionalObserverNotifiedImmediatelyWhenNoTransactionInProgress()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.6")
+ public void testTransactionalObserverNotifiedImmediatelyWhenNoTransactionInProgress()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.6")
- public void testAfterTransactionCompletionObserver()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.6")
+ public void testAfterTransactionCompletionObserver()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.6")
- public void testAfterTransactionSuccessObserver()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.6")
+ public void testAfterTransactionSuccessObserver()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.6")
- public void testAfterTransactionFailureObserver()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.6")
+ public void testAfterTransactionFailureObserver()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.6")
- public void testBeforeTransactionCompletionObserver()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.6")
+ public void testBeforeTransactionCompletionObserver()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.7")
- public void testObserverMethodRegistration()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.7")
+ public void testObserverMethodRegistration()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.7")
- public void testEnterpriseBeanObserverMethodCalledWithCallerContext()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.7")
+ public void testEnterpriseBeanObserverMethodCalledWithCallerContext()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.7")
- public void testTransactionalObserverThrownExceptionIsCaughtAndLogged()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.7")
+ public void testTransactionalObserverThrownExceptionIsCaughtAndLogged()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.7")
- public void testNonTransactionalObserverThrownNonCheckedExceptionIsRethrown()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.7")
+ public void testNonTransactionalObserverThrownNonCheckedExceptionIsRethrown()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.5.7")
- public void testNonTransactionalObserverThrownCheckedExceptionIsWrappedAndRethrown()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.5.7")
+ public void testNonTransactionalObserverThrownCheckedExceptionIsWrappedAndRethrown()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testDuplicateBindingsToFireFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testDuplicateBindingsToFireFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testDuplicateBindingsToObservesFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testDuplicateBindingsToObservesFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testNonBindingTypePassedToFireFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testNonBindingTypePassedToFireFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testNonBindingTypePassedToObservesFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testNonBindingTypePassedToObservesFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnField()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnField()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnParameterOfProducerMethod()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnParameterOfProducerMethod()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnParameterOfInitializerMethod()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnParameterOfInitializerMethod()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnParameterOfDisposalMethod()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnParameterOfDisposalMethod()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnParameterOfRemoveMethod()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnParameterOfRemoveMethod()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnParameterOfConstructor()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnParameterOfConstructor()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableAnnotationOnNonEventTypeInjectionPointFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableAnnotationOnNonEventTypeInjectionPointFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableannotationOnInjectionPointWithoutTypeParameterFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableannotationOnInjectionPointWithoutTypeParameterFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableannotationOnInjectionPointWithWildcardedTypeParameterFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableannotationOnInjectionPointWithWildcardedTypeParameterFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObservableannotationOnInjectionPointWithTypeVariabledTypeParameterFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObservableannotationOnInjectionPointWithTypeVariabledTypeParameterFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testImplicitObserverBeanMatchesAPITypeOfInectionPoint()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testImplicitObserverBeanMatchesAPITypeOfInectionPoint()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testImplicitObserverBeanMatchesBindingAnnotationsOfInjectionPoint()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testImplicitObserverBeanMatchesBindingAnnotationsOfInjectionPoint()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testImplicitObserverBeanHasStandardDeploymentType()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testImplicitObserverBeanHasStandardDeploymentType()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testImplicitObserverBeanHasDependentScope()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testImplicitObserverBeanHasDependentScope()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testFireMethodCallsManagerFireWithEventObject()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testFireMethodCallsManagerFireWithEventObject()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testFireMethodCallsManagerFireWithBindingAnnotationsExceptObservable()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testFireMethodCallsManagerFireWithBindingAnnotationsExceptObservable()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testFireMethodCallsManagerFireWithAllBindingAnnotationInstances()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testFireMethodCallsManagerFireWithAllBindingAnnotationInstances()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObserveMethodCallsManagerAddObserverWithObserverObject()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObserveMethodCallsManagerAddObserverWithObserverObject()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationsExceptObservable()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationsExceptObservable()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.6")
- public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationInstance()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.6")
+ public void testObserveMethodCallsManagerAddObserverWithAllBindingAnnotationInstance()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testEventObjectContainsTypeVariablesWhenResolvingFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testEventObjectContainsTypeVariablesWhenResolvingFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testEventObjectContainsWildcardsWhenResolvingFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testEventObjectContainsWildcardsWhenResolvingFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testDuplicateBindingTypesWhenResolvingFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testDuplicateBindingTypesWhenResolvingFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testNonBindingTypeAnnotationWhenResolvingFails()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testNonBindingTypeAnnotationWhenResolvingFails()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testResolvingChecksEventType()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testResolvingChecksEventType()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testResolvingChecksTypeParameters()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testResolvingChecksTypeParameters()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testResolvingChecksBindingTypes()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testResolvingChecksBindingTypes()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.7")
- public void testResolvingChecksBindingTypeMembers()
+
+ @Test(groups = { "stub", "events" })
+ @SpecAssertion(section = "7.7")
+ public void testResolvingChecksBindingTypeMembers()
{
assert false;
}
-
+
}
15 years, 5 months
[webbeans-commits] Webbeans SVN: r458 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-12-07 15:41:12 -0500 (Sun, 07 Dec 2008)
New Revision: 458
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
Log:
static methods now allowed
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java 2008-12-07 20:38:40 UTC (rev 457)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java 2008-12-07 20:41:12 UTC (rev 458)
@@ -43,7 +43,7 @@
tarantulaModel.getDeploymentType().equals(AnotherDeploymentType.class);
}
- @Test(groups="producerMethod", expectedExceptions=DefinitionException.class) @SpecAssertion(section="3.4")
+ @Test(groups="producerMethod") @SpecAssertion(section="3.4")
public void testStaticMethod() throws Exception
{
SimpleBean<BeanWithStaticProducerMethod> bean = createSimpleBean(BeanWithStaticProducerMethod.class);
15 years, 5 months
[webbeans-commits] Webbeans SVN: r457 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-12-07 15:38:40 -0500 (Sun, 07 Dec 2008)
New Revision: 457
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
Log:
allow static producer methods/fields and refactor slightly
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-12-07 20:21:17 UTC (rev 456)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-12-07 20:38:40 UTC (rev 457)
@@ -1,8 +1,13 @@
package org.jboss.webbeans.bean;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import java.util.HashSet;
+import javax.webbeans.DefinitionException;
+import javax.webbeans.Dependent;
+import javax.webbeans.IllegalProductException;
+
import org.jboss.webbeans.ManagerImpl;
public abstract class ProducerBean<T, S> extends AbstractBean<T, S> {
@@ -69,4 +74,38 @@
return declaringBean;
}
+ /**
+ * Validates the producer method
+ */
+ protected void checkProducerReturnType() {
+ for (Type type : getAnnotatedItem().getActualTypeArguments())
+ {
+ if (!(type instanceof Class))
+ {
+ throw new DefinitionException("Producer type cannot be parameterized with type parameter or wildcard");
+ }
+ }
+ }
+
+ /**
+ * Initializes the bean and its metadata
+ */
+ @Override
+ protected void init() {
+ super.init();
+ checkProducerReturnType();
+ }
+
+ protected void checkReturnValue(T instance) {
+ if (instance == null && !getScopeType().equals(Dependent.class))
+ {
+ throw new IllegalProductException("Cannot return null from a non-dependent producer method");
+ }
+ }
+
+ protected Object getReceiver() {
+ return getAnnotatedItem().isStatic() ?
+ null : manager.getInstance(getDeclaringBean());
+ }
+
}
\ No newline at end of file
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java 2008-12-07 20:21:17 UTC (rev 456)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java 2008-12-07 20:38:40 UTC (rev 457)
@@ -18,12 +18,7 @@
package org.jboss.webbeans.bean;
import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-import javax.webbeans.DefinitionException;
-import javax.webbeans.Dependent;
-import javax.webbeans.IllegalProductException;
-
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.jlr.AnnotatedFieldImpl;
@@ -72,47 +67,12 @@
@Override
public T create()
{
- T instance = field.get(manager.getInstance(getDeclaringBean()));
- if (instance == null && !getScopeType().equals(Dependent.class))
- {
- throw new IllegalProductException("Cannot return null from a non-dependent producer field");
- }
+ T instance = field.get(getReceiver());
+ checkReturnValue(instance);
return instance;
}
/**
- * Initializes the bean and its metadata
- */
- @Override
- protected void init()
- {
- super.init();
- checkProducerField();
- }
-
-
- /**
- * Validates the producer method
- */
- protected void checkProducerField()
- {
- if (getAnnotatedItem().isStatic())
- {
- throw new DefinitionException("Producer method cannot be static " + field);
- }
- else if (getAnnotatedItem().getActualTypeArguments().length > 0)
- {
- for (Type type : getAnnotatedItem().getActualTypeArguments())
- {
- if (!(type instanceof Class))
- {
- throw new DefinitionException("Producer field type cannot be parameterized with type parameter or wildcard");
- }
- }
- }
- }
-
- /**
* Gets the annotated item representing the method
*
* @return The annotated item
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-12-07 20:21:17 UTC (rev 456)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-07 20:38:40 UTC (rev 457)
@@ -19,14 +19,11 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.Set;
import javax.webbeans.DefinitionException;
-import javax.webbeans.Dependent;
import javax.webbeans.Destructor;
import javax.webbeans.Disposes;
-import javax.webbeans.IllegalProductException;
import javax.webbeans.Observes;
import org.jboss.webbeans.ManagerImpl;
@@ -78,11 +75,8 @@
@Override
public T create()
{
- T instance = method.invoke(manager, manager.getInstance(getDeclaringBean()));
- if (instance == null && !getScopeType().equals(Dependent.class))
- {
- throw new IllegalProductException("Cannot return null from a non-dependent producer method");
- }
+ T instance = method.invoke(manager, getReceiver());
+ checkReturnValue(instance);
return instance;
}
@@ -94,7 +88,7 @@
{
super.init();
checkProducerMethod();
- initRemoveMethod();
+ initDisposalMethod();
initInjectionPoints();
}
@@ -123,12 +117,8 @@
*/
protected void checkProducerMethod()
{
- if (getAnnotatedItem().isStatic())
+ if (getAnnotatedItem().isAnnotationPresent(Destructor.class))
{
- throw new DefinitionException("Producer method cannot be static " + method);
- }
- else if (getAnnotatedItem().isAnnotationPresent(Destructor.class))
- {
throw new DefinitionException("Producer method cannot be annotated @Destructor");
}
else if (getAnnotatedItem().getAnnotatedParameters(Observes.class).size() > 0)
@@ -139,22 +129,12 @@
{
throw new DefinitionException("Producer method cannot have parameter annotated @Disposes");
}
- else if (getAnnotatedItem().getActualTypeArguments().length > 0)
- {
- for (Type type : getAnnotatedItem().getActualTypeArguments())
- {
- if (!(type instanceof Class))
- {
- throw new DefinitionException("Producer method return type cannot be parameterized with type parameter or wildcard");
- }
- }
- }
}
/**
* Initializes the remove method
*/
- protected void initRemoveMethod()
+ protected void initDisposalMethod()
{
Set<AnnotatedMethod<Object>> disposalMethods = manager.resolveDisposalMethods(getType(), getBindingTypes().toArray(new Annotation[0]));
if (disposalMethods.size() == 1)
15 years, 5 months
[webbeans-commits] Webbeans SVN: r456 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts.
by webbeans-commits@lists.jboss.org
Author: nickarls
Date: 2008-12-07 15:21:17 -0500 (Sun, 07 Dec 2008)
New Revision: 456
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
Log:
Not used anymore
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-12-07 19:11:03 UTC (rev 455)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java 2008-12-07 20:21:17 UTC (rev 456)
@@ -1,231 +0,0 @@
-/*
- * 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.contexts;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-import javax.servlet.http.HttpSession;
-import javax.webbeans.manager.Bean;
-import javax.webbeans.manager.Contextual;
-
-import org.jboss.webbeans.CurrentManager;
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-/**
- * A BeanMap that uses a HTTP session as backing map
- *
- * @author Nicklas Karlsson
- *
- * @see org.jboss.webbeans.contexts.SessionContext
- */
-public class SessionBeanMap implements BeanMap
-{
- private static LogProvider log = Logging.getLogProvider(SessionBeanMap.class);
-
- // The HTTP session to use as backing map
- private HttpSession session;
- // The storage prefix to put before names
- private String keyPrefix;
-
- /**
- * Constructor
- *
- * @param keyPrefix The storage names prefix
- */
- public SessionBeanMap(String keyPrefix)
- {
- super();
- this.keyPrefix = keyPrefix;
- log.trace("SessionBeanMap created with prefix " + keyPrefix);
- }
-
- /**
- * The SessionBeanMap requires a HTTP session to work. It is created without
- * one so this method must be called before it can be operated upon
- *
- * @param session The session to use as a backing map
- */
- public void setSession(HttpSession session)
- {
- this.session = session;
- log.trace("Session context associated with session id " + session.getId());
- }
-
- /**
- * Used to check if the session has been set and throws an exception if it's
- * null.
- */
- private void checkSession()
- {
- if (session == null)
- {
- throw new IllegalArgumentException("Session has not been initialized in SessionBeanMap");
- }
- }
-
- /**
- * Returns a map key to a bean. Uses a known prefix and appends the index of
- * the Bean in the Manager bean list.
- *
- * @param bean The bean to generate a key for.
- * @return A unique key;
- */
- private String getBeanKey(Contextual<?> bean)
- {
- return keyPrefix + CurrentManager.rootManager().getBeans().indexOf(bean);
- }
-
- /**
- * Gets a bean from the session
- *
- * First, checks that the session is present. It determines an ID for the
- * bean which and looks for it in the session. The bean instance is returned
- * (null if not found in the session).
- *
- * @param bean The bean to get from the session
- * @return An instance of the bean
- *
- * @see org.jboss.webbeans.contexts.BeanMap#get(Bean)
- */
- @SuppressWarnings("unchecked")
- public <T> T get(Contextual<? extends T> bean)
- {
- checkSession();
- String key = getBeanKey(bean);
- T instance = (T) session.getAttribute(key);
- log.trace("Searched session for key " + key + " and got " + instance);
- return instance;
- }
-
- /**
- * Removes a bean instance from the session
- *
- * First, checks that the session is present. It determines an ID for the
- * bean and that key is then removed from the session, whether it was present
- * in the first place or not.
- *
- * @param bean The bean whose instance to remove.
- * @return The instance removed
- *
- * @see org.jboss.webbeans.contexts.BeanMap#remove(Bean)
- */
- public <T> T remove(Contextual<? extends T> bean)
- {
- checkSession();
- T instance = get(bean);
- String key = getBeanKey(bean);
- session.removeAttribute(key);
- log.trace("Removed bean " + bean + " with key " + key + " from session");
- return instance;
- }
-
- /**
- * Clears the session of any beans.
- *
- * First, checks that the session is present. Then, iterates over the
- * attribute names in the session and removes them if they start with the
- * know prefix.
- *
- * @see org.jboss.webbeans.contexts.BeanMap#clear()
- */
- @SuppressWarnings("unchecked")
- public void clear()
- {
- checkSession();
- Enumeration names = session.getAttributeNames();
- while (names.hasMoreElements())
- {
- String name = (String) names.nextElement();
- session.removeAttribute(name);
- }
- log.trace("Session cleared");
- }
-
- /**
- * Gets an iterable over the beans present in the storage.
- *
- * Iterates over the names in the session. If a name starts with the known
- * prefix, strips it out to get the index to the bean in the manager bean
- * list. Retrieves the bean from that list and puts it in the result-list.
- * Finally, returns the list.
- *
- * @return An Iterable to the beans in the storage
- *
- * @see org.jboss.webbeans.contexts.BeanMap#keySet()
- */
- @SuppressWarnings("unchecked")
- public Iterable<Contextual<? extends Object>> keySet()
- {
- checkSession();
-
- List<Contextual<?>> beans = new ArrayList<Contextual<?>>();
-
- Enumeration names = session.getAttributeNames();
- while (names.hasMoreElements())
- {
- String name = (String) names.nextElement();
- if (name.startsWith(keyPrefix))
- {
- String id = name.substring(keyPrefix.length());
- Contextual<?> bean = CurrentManager.rootManager().getBeans().get(Integer.parseInt(id));
- beans.add(bean);
- }
- }
-
- return beans;
- }
-
- /**
- * Puts a bean instance in the session
- *
- * First, checks that the session is present. Generates a bean map key, puts
- * the instance in the session under that key.
- *
- * @param bean The bean to use as key
- * @param instance The bean instance to add
- *
- * @see org.jboss.webbeans.contexts.BeanMap#put(Bean, Object)
- */
- public <T> void put(Contextual<? extends T> bean, T instance)
- {
- checkSession();
- String key = getBeanKey(bean);
- session.setAttribute(key, instance);
- log.trace("Stored instance " + instance + " for bean " + bean + " under key " + key + " in session");
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public String toString()
- {
- StringBuilder buffer = new StringBuilder();
- List<Contextual<?>> beans = (List) keySet();
- buffer.append("Bean -> bean instance mappings in HTTP session: " + beans.size() + "\n");
- int i = 0;
- for (Contextual<?> bean : beans)
- {
- Object instance = get(bean);
- buffer.append(++i + " - " + getBeanKey(bean) + ": " + instance + "\n");
- }
- return buffer.toString();
- }
-
-}
15 years, 5 months
[webbeans-commits] Webbeans SVN: r455 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-07 14:11:03 -0500 (Sun, 07 Dec 2008)
New Revision: 455
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ApplicationContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
Log:
Mark updated
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ApplicationContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ApplicationContextTest.java 2008-12-07 19:09:51 UTC (rev 454)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ApplicationContextTest.java 2008-12-07 19:11:03 UTC (rev 455)
@@ -2,65 +2,65 @@
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("2001206")
public class ApplicationContextTest extends AbstractTest
{
- @Test(groups={"stub", "servlet", "contexts"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "servlet", "contexts"}) @SpecAssertion(section="9.5.3")
public void testScopeActiveDuringServiceMethod()
{
assert false;
}
- @Test(groups={"stub", "webservice", "contexts"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "webservice", "contexts"}) @SpecAssertion(section="9.5.3")
public void testScopeActiveDuringWebServiceInvocation()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
public void testScopeActiveDuringRemoteInvocationOfEjbs()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
- public void testScopeActiveDuringEjbTimeoust()
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
+ public void testScopeActiveDuringEjbTimeouts()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
public void testScopeActiveDuringMessageDelivery()
{
assert false;
}
- @Test(groups={"stub", "servlet", "contexts"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "servlet", "contexts"}) @SpecAssertion(section="9.5.3")
public void testScopeSharedAcrossRequests()
{
assert false;
}
- @Test(groups={"stub", "webservice", "contexts"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "webservice", "contexts"}) @SpecAssertion(section="9.5.3")
public void testScopeSharedAcrossWebServiceInvocations()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
public void testScopeSharedAcrossRemoteInvocationsOfEjbs()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
public void testScopeSharedAcrossEjbTimeouts()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.5.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.5.3")
public void testScopeSharedAcrossMessageDelivery()
{
assert false;
@@ -68,7 +68,7 @@
/*
- @Test @SpecAssertion(section="8.5.3")
+ @Test @SpecAssertion(section="9.5.3")
public void test
{
assert false;
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-12-07 19:09:51 UTC (rev 454)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DependentContextTest.java 2008-12-07 19:11:03 UTC (rev 455)
@@ -22,7 +22,7 @@
public class DependentContextTest extends AbstractTest
{
- @Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "injection"}) @SpecAssertion(section="9.4")
public void testInstanceNotSharedBetweenInjectionPoints()
{
Bean<FoxRun> foxRunBean = createSimpleBean(FoxRun.class);
@@ -32,13 +32,13 @@
assert !foxRun.fox.equals(foxRun.anotherFox);
}
- @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="9.4")
public void testInstanceUsedForElEvalutionNotShared()
{
assert false;
}
- @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "producerMethod"}) @SpecAssertion(section="9.4")
public void testInstanceUsedForProducerMethodNotShared() throws Exception
{
SimpleBean<SpiderProducer> spiderProducer = createSimpleBean(SpiderProducer.class);
@@ -52,13 +52,13 @@
assert tarantula != tarantula2;
}
- @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="9.4")
public void testInstanceUsedForObserverMethodNotShared()
{
assert false;
}
- @Test(groups="contexts") @SpecAssertion(section="8.3")
+ @Test(groups="contexts") @SpecAssertion(section="9.4")
public void testContextGetWithCreateTrueReturnsNewInstance()
{
Bean<Fox> foxBean = createSimpleBean(Fox.class);
@@ -69,7 +69,7 @@
assert context.get(foxBean, true) instanceof Fox;
}
- @Test(groups="contexts") @SpecAssertion(section="8.3")
+ @Test(groups="contexts") @SpecAssertion(section="9.4")
public void testContextGetWithCreateFalseReturnsNull()
{
Bean<Fox> foxBean = createSimpleBean(Fox.class);
@@ -79,26 +79,26 @@
assert context.get(foxBean, false) == null;
}
- @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="8.3")
+ @Test(groups="contexts", expectedExceptions=ContextNotActiveException.class) @SpecAssertion(section="9.4")
public void testContextIsInactive()
{
manager.getContext(Dependent.class).isActive();
}
- @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="9.4")
public void testContextIsActiveWhenInvokingObserverMethod()
{
assert false;
}
- @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="9.4")
public void testContextIsActiveWhenEvaluatingElExpression()
{
assert false;
}
- @Test(groups={"contexts", "beanLifecycle"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "beanLifecycle"}) @SpecAssertion(section="9.4")
public void testContextIsActiveDuringBeanCreation()
{
// Slightly roundabout, but I can't see a better way to test atm
@@ -109,13 +109,13 @@
assert foxRun.fox != null;
}
- @Test(groups={"stub", "contexts", "beanDestruction"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "beanDestruction"}) @SpecAssertion(section="9.4")
public void testContextIsActiveDuringBeanDestruction()
{
assert false;
}
- @Test(groups={"contexts", "injection"}) @SpecAssertion(section="8.3")
+ @Test(groups={"contexts", "injection"}) @SpecAssertion(section="9.4")
public void testContextIsActiveDuringInjection()
{
Bean<FoxRun> foxRunBean = createSimpleBean(FoxRun.class);
@@ -125,55 +125,55 @@
assert foxRun.fox != null;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.4")
public void testEjbBeanMayMayCreateInstanceFromInitializer()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.4")
public void testEjbBeanMayMayCreateInstanceFromPostConstruct()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.4")
public void testEjbBeanMayMayCreateInstanceFromPreDestroy()
{
assert false;
}
- @Test(groups={"stub", "contexts", "servlet"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "servlet"}) @SpecAssertion(section="9.4")
public void testServletBeanMayMayCreateInstanceFromInitializer()
{
assert false;
}
- @Test(groups={"stub", "contexts", "beanDestruction"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "beanDestruction"}) @SpecAssertion(section="9.4")
public void testDestroyingParentDestroysDependents()
{
assert false;
}
- @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "ejb3"}) @SpecAssertion(section="9.4")
public void testDestroyingEjbDestroysDependents()
{
assert false;
}
- @Test(groups={"stub", "contexts", "servlet"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "servlet"}) @SpecAssertion(section="9.4")
public void testDestroyingServletDestroysDependents()
{
assert false;
}
- @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "el"}) @SpecAssertion(section="9.4")
public void testDependentsDestroyedWhenElEvaluationCompletes()
{
assert false;
}
- @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="8.3")
+ @Test(groups={"stub", "contexts", "observerMethod"}) @SpecAssertion(section="9.4")
public void testDependentsDestroyedWhenObserverMethodEvaluationCompletes()
{
assert false;
15 years, 5 months
[webbeans-commits] Webbeans SVN: r454 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-07 14:09:51 -0500 (Sun, 07 Dec 2008)
New Revision: 454
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java
Log:
Mark updated
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java 2008-12-07 19:06:30 UTC (rev 453)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/BindingTypeTest.java 2008-12-07 19:09:51 UTC (rev 454)
@@ -23,7 +23,7 @@
import org.jboss.webbeans.util.Reflections;
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("2001206")
public class BindingTypeTest extends AbstractTest
{
15 years, 5 months