[webbeans-commits] Webbeans SVN: r443 - ri/trunk.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-07 12:44:40 -0500 (Sun, 07 Dec 2008)
New Revision: 443
Modified:
ri/trunk/pom.xml
Log:
add jsf dep
Modified: ri/trunk/pom.xml
===================================================================
--- ri/trunk/pom.xml 2008-12-07 17:42:55 UTC (rev 442)
+++ ri/trunk/pom.xml 2008-12-07 17:44:40 UTC (rev 443)
@@ -138,6 +138,12 @@
<artifactId>el-api</artifactId>
<version>1.0</version>
</dependency>
+
+ <dependency>
+ <groupId>javax.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <version>1.2_10</version>
+ </dependency>
<dependency>
<groupId>com.google.collections</groupId>
16 years
[webbeans-commits] Webbeans SVN: r442 - 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 12:42:55 -0500 (Sun, 07 Dec 2008)
New Revision: 442
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
Log:
fields annotated @Produces are not injection points
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-07 17:16:58 UTC (rev 441)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07 17:42:55 UTC (rev 442)
@@ -140,6 +140,8 @@
injectableFields = new HashSet<AnnotatedField<Object>>();
for (AnnotatedField<Object> annotatedField : annotatedItem.getMetaAnnotatedFields(BindingType.class))
{
+ if ( !annotatedField.isAnnotationPresent(Produces.class) )
+ {
if (annotatedField.isStatic())
{
throw new DefinitionException("Don't place binding annotations on static fields " + annotatedField);
@@ -150,6 +152,7 @@
}
injectableFields.add(annotatedField);
super.injectionPoints.add(annotatedField);
+ }
}
}
16 years
[webbeans-commits] Webbeans SVN: r441 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bootstrap and 1 other directories.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-12-07 12:16:58 -0500 (Sun, 07 Dec 2008)
New Revision: 441
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
Log:
scan for producer fields
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-07 17:14:53 UTC (rev 440)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07 17:16:58 UTC (rev 441)
@@ -104,6 +104,17 @@
}
/**
+ * Returns the producer fields
+ *
+ * @return A set of producer fields. An empty set is returned if there are
+ * none present
+ */
+ public Set<AnnotatedField<Object>> getProducerFields()
+ {
+ return getAnnotatedItem().getAnnotatedFields(Produces.class);
+ }
+
+ /**
* Returns @Observer annotated fields.
*
* @return A set of observing fields. An empty set is returned if there are
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-07 17:14:53 UTC (rev 440)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bootstrap/Bootstrap.java 2008-12-07 17:16:58 UTC (rev 441)
@@ -20,6 +20,7 @@
import static org.jboss.webbeans.util.BeanFactory.createEnterpriseBean;
import static org.jboss.webbeans.util.BeanFactory.createEventBean;
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;
@@ -38,6 +39,7 @@
import org.jboss.webbeans.bean.AbstractBean;
import org.jboss.webbeans.bean.AbstractClassBean;
import org.jboss.webbeans.bean.EventBean;
+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;
@@ -141,6 +143,12 @@
CurrentManager.rootManager().getResolver().addInjectionPoints(producerMethodBean.getInjectionPoints());
log.info("Web Bean: " + producerMethodBean);
}
+ for (AnnotatedField<Object> producerField : bean.getProducerFields())
+ {
+ ProducerFieldBean<?> producerFieldBean = createProducerFieldBean(producerField, bean);
+ beans.add(producerFieldBean);
+ log.info("Web Bean: " + producerFieldBean);
+ }
for (AnnotatedField<Object> eventField : bean.getEventFields())
{
EventBean<?> eventBean = createEventBean(eventField);
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-07 17:14:53 UTC (rev 440)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-07 17:16:58 UTC (rev 441)
@@ -17,12 +17,14 @@
package org.jboss.webbeans.util;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
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.ProducerFieldBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.event.ObserverImpl;
@@ -75,6 +77,32 @@
}
/**
+ * Creates a producer field Web Bean
+ *
+ * @param <T> The type
+ * @param type The class
+ * @param field The underlying field
+ * @param declaringBean The declaring bean abstraction
+ * @return A producer Web Bean
+ */
+ public static <T> ProducerFieldBean<T> createProducerFieldBean(Class<T> type, Field field, AbstractClassBean<?> declaringBean)
+ {
+ return new ProducerFieldBean<T>(field, declaringBean, CurrentManager.rootManager());
+ }
+
+ /**
+ * Creates a producer field Web Bean
+ *
+ * @param field The underlying method abstraction
+ * @param declaringBean The declaring bean abstraction
+ * @return A producer Web Bean
+ */
+ public static <T> ProducerFieldBean<T> createProducerFieldBean(AnnotatedField<T> field, AbstractClassBean<?> declaringBean)
+ {
+ return new ProducerFieldBean<T>(field, declaringBean, CurrentManager.rootManager());
+ }
+
+ /**
* Creates a producer method Web Bean
*
* @param method The underlying method abstraction
16 years
[webbeans-commits] Webbeans SVN: r440 - 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 12:14:53 -0500 (Sun, 07 Dec 2008)
New Revision: 440
Modified:
ri/trunk/webbeans-api/src/main/java/javax/webbeans/Produces.java
Log:
@Produces now allowed on fields
Modified: ri/trunk/webbeans-api/src/main/java/javax/webbeans/Produces.java
===================================================================
--- ri/trunk/webbeans-api/src/main/java/javax/webbeans/Produces.java 2008-12-07 17:08:46 UTC (rev 439)
+++ ri/trunk/webbeans-api/src/main/java/javax/webbeans/Produces.java 2008-12-07 17:14:53 UTC (rev 440)
@@ -18,6 +18,7 @@
package javax.webbeans;
import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Documented;
@@ -33,7 +34,7 @@
* @author Pete Muir
*/
-@Target(METHOD)
+@Target({METHOD, FIELD})
@Retention(RUNTIME)
@Documented
public @interface Produces
16 years
[webbeans-commits] Webbeans SVN: r439 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: introspector and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: gavin.king(a)jboss.com
Date: 2008-12-07 12:08:46 -0500 (Sun, 07 Dec 2008)
New Revision: 439
Added:
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
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
Log:
basic support for producer fields (untested)
Added: 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 (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerBean.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -0,0 +1,72 @@
+package org.jboss.webbeans.bean;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+
+import org.jboss.webbeans.ManagerImpl;
+
+public abstract class ProducerBean<T, S> extends AbstractBean<T, S> {
+
+ protected AbstractClassBean<?> declaringBean;
+
+ public ProducerBean(ManagerImpl manager, AbstractClassBean<?> declaringBean) {
+ super(manager);
+ this.declaringBean = declaringBean;
+ }
+
+ @Override
+ protected Class<? extends Annotation> getDefaultDeploymentType() {
+ return deploymentType = declaringBean.getDeploymentType();
+ }
+
+ /**
+ * Initializes the API types
+ */
+ @Override
+ protected void initApiTypes() {
+ if (getType().isArray() || getType().isPrimitive())
+ {
+ apiTypes = new HashSet<Class<?>>();
+ apiTypes.add(getType());
+ apiTypes.add(Object.class);
+ }
+ else if (getType().isInterface())
+ {
+ super.initApiTypes();
+ apiTypes.add(Object.class);
+ }
+ else
+ {
+ super.initApiTypes();
+ }
+ }
+
+ /**
+ * Initializes the type
+ */
+ @Override
+ protected void initType()
+ {
+ try
+ {
+ if (getAnnotatedItem() != null)
+ {
+ this.type = getAnnotatedItem().getType();
+ }
+ }
+ catch (ClassCastException e)
+ {
+ throw new RuntimeException(" Cannot cast producer type " + getAnnotatedItem().getType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
+ }
+ }
+
+ /**
+ * Returns the declaring bean
+ *
+ * @return The bean representation
+ */
+ public AbstractClassBean<?> getDeclaringBean() {
+ return declaringBean;
+ }
+
+}
\ No newline at end of file
Added: 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 (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerFieldBean.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -0,0 +1,149 @@
+/*
+ * 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 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;
+
+/**
+ * Represents a producer method bean
+ *
+ * @author Pete Muir
+ *
+ * @param <T>
+ */
+public class ProducerFieldBean<T> extends ProducerBean<T, Field>
+{
+
+ private AnnotatedField<T> field;
+
+ /**
+ * Constructor
+ *
+ * @param method The producer method
+ * @param declaringBean The declaring bean instance
+ */
+ public ProducerFieldBean(Field field, AbstractClassBean<?> declaringBean, ManagerImpl manager)
+ {
+ this(new AnnotatedFieldImpl<T>(field, declaringBean.getAnnotatedItem()), declaringBean, manager);
+ }
+
+ /**
+ * Constructor
+ *
+ * @param method The producer method abstraction
+ * @param declaringBean The declaring bean
+ */
+ public ProducerFieldBean(AnnotatedField<T> field, AbstractClassBean<?> declaringBean, ManagerImpl manager)
+ {
+ super(manager, declaringBean);
+ this.field = field;
+ init();
+ }
+
+ /**
+ * Creates an instance of the bean
+ *
+ * @returns The instance
+ */
+ @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");
+ }
+ 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
+ */
+ @Override
+ protected AnnotatedField<T> getAnnotatedItem()
+ {
+ return field;
+ }
+
+ /**
+ * Returns the default name
+ *
+ * @return The default name
+ */
+ @Override
+ protected String getDefaultName()
+ {
+ return field.getPropertyName();
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("ProducerFieldBean:\n");
+ buffer.append(super.toString() + "\n");
+ buffer.append("Declaring bean: " + declaringBean.toString() + "\n");
+ buffer.append("Field: " + field.toString() + "\n");
+ return buffer.toString();
+ }
+
+
+}
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 16:46:10 UTC (rev 438)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -20,7 +20,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
-import java.util.HashSet;
import java.util.Set;
import javax.webbeans.DefinitionException;
@@ -42,11 +41,10 @@
*
* @param <T>
*/
-public class ProducerMethodBean<T> extends AbstractBean<T, Method>
+public class ProducerMethodBean<T> extends ProducerBean<T, Method>
{
private AnnotatedMethod<T> method;
- private AbstractClassBean<?> declaringBean;
/**
* Constructor
@@ -67,9 +65,8 @@
*/
public ProducerMethodBean(AnnotatedMethod<T> method, AbstractClassBean<?> declaringBean, ManagerImpl manager)
{
- super(manager);
+ super(manager, declaringBean);
this.method = method;
- this.declaringBean = declaringBean;
init();
}
@@ -84,7 +81,7 @@
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 method");
+ throw new IllegalProductException("Cannot return null from a non-dependent producer method");
}
return instance;
}
@@ -121,12 +118,6 @@
}
}
- @Override
- protected Class<? extends Annotation> getDefaultDeploymentType()
- {
- return deploymentType = declaringBean.getDeploymentType();
- }
-
/**
* Validates the producer method
*/
@@ -154,7 +145,7 @@
{
if (!(type instanceof Class))
{
- throw new DefinitionException("Producer method cannot return type parameterized with type parameter or wildcard");
+ throw new DefinitionException("Producer method return type cannot be parameterized with type parameter or wildcard");
}
}
}
@@ -201,48 +192,6 @@
}
/**
- * Initializes the type
- */
- @Override
- protected void initType()
- {
- try
- {
- if (getAnnotatedItem() != null)
- {
- this.type = getAnnotatedItem().getType();
- }
- }
- catch (ClassCastException e)
- {
- throw new RuntimeException(" Cannot cast producer method return type " + method.getType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
- }
- }
-
- /**
- * Initializes the API types
- */
- @Override
- protected void initApiTypes()
- {
- if (getType().isArray() || getType().isPrimitive())
- {
- super.apiTypes = new HashSet<Class<?>>();
- super.apiTypes.add(getType());
- super.apiTypes.add(Object.class);
- }
- else if (getType().isInterface())
- {
- super.initApiTypes();
- super.apiTypes.add(Object.class);
- }
- else
- {
- super.initApiTypes();
- }
- }
-
- /**
* Returns the disposal method
*
* @return The method representation
@@ -251,16 +200,6 @@
{
return removeMethod;
}
-
- /**
- * Returns the declaring bean
- *
- * @return The bean representation
- */
- public AbstractClassBean<?> getDeclaringBean()
- {
- return declaringBean;
- }
@Override
public String toString()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java 2008-12-07 16:46:10 UTC (rev 438)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/AnnotatedField.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -46,6 +46,13 @@
public void inject(Manager manager, Object instance);
/**
+ * Injects an instance
+ *
+ * @param instance The instance to inject
+ */
+ public T get(Object instance);
+
+ /**
* Gets an abstraction of the declaring class
*
* @return The declaring class
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-12-07 16:46:10 UTC (rev 438)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AbstractAnnotatedMember.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -27,7 +27,6 @@
import javax.webbeans.BindingType;
import javax.webbeans.manager.Manager;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-12-07 16:46:10 UTC (rev 438)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/introspector/jlr/AnnotatedFieldImpl.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -126,6 +126,10 @@
{
Reflections.setAndWrap(getDelegate(), instance, getValue(manager));
}
+
+ public T get(Object instance) {
+ return (T) Reflections.getAndWrap(getDelegate(), instance);
+ }
/**
* Gets the property name
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-07 16:46:10 UTC (rev 438)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-07 17:08:46 UTC (rev 439)
@@ -469,6 +469,29 @@
}
/**
+ * Gets value of a field and wraps exceptions
+ *
+ * @param field The field to set on
+ * @param target The instance to set on
+ * @return The value to set
+ */
+ public static Object getAndWrap(Field field, Object target)
+ {
+ try
+ {
+ return field.get(target);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new ExecutionException("Error getting field " + field.getName() + " on " + field.getDeclaringClass(), e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new ExecutionException("Error getting field " + field.getName() + " on " + field.getDeclaringClass(), e);
+ }
+ }
+
+ /**
* Looks up a method in the type hierarchy of an instance
*
* @param method The method to look for
16 years
[webbeans-commits] Webbeans SVN: r438 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-07 11:46:10 -0500 (Sun, 07 Dec 2008)
New Revision: 438
Removed:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/Location.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/NameResolutionLocation.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java
Log:
Remove XML stuff, there is a new way of doing it, other tidy ups
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -52,7 +52,6 @@
import org.jboss.webbeans.contexts.DependentContext;
import org.jboss.webbeans.ejb.DefaultEnterpriseBeanLookup;
import org.jboss.webbeans.event.EventManager;
-import org.jboss.webbeans.exceptions.NameResolutionLocation;
import org.jboss.webbeans.introspector.AnnotatedItem;
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
@@ -474,7 +473,7 @@
}
else if (beans.size() > 1)
{
- throw new AmbiguousDependencyException(new NameResolutionLocation(name) + "Resolved multiple Web Beans");
+ throw new AmbiguousDependencyException("Resolved multiple Web Beans with " + name);
}
else
{
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -146,42 +146,23 @@
protected void initBindingTypes()
{
this.bindingTypes = new HashSet<Annotation>();
- if (isDefinedInXml())
+ boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
+ this.bindingTypes.addAll(getAnnotatedItem().getMetaAnnotations(BindingType.class));
+ if (specialization)
{
- boolean xmlSpecialization = false;
- Set<Annotation> xmlBindingTypes = null;
- this.bindingTypes.addAll(xmlBindingTypes);
- if (xmlSpecialization)
- {
- this.bindingTypes.addAll(bindingTypes);
- log.trace("Using binding types " + this.bindingTypes + " specified in XML and specialized type");
- }
- else
- {
- log.trace("Using binding types " + this.bindingTypes + " specified in XML");
- }
- return;
+ this.bindingTypes.addAll(getSpecializedType().getBindingTypes());
+ log.trace("Using binding types " + bindingTypes + " specified by annotations and specialized supertype");
}
- else if (!mergedStereotypes.isDeclaredInXml())
+ else if (bindingTypes.size() == 0)
{
- boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
- this.bindingTypes.addAll(getAnnotatedItem().getMetaAnnotations(BindingType.class));
- if (specialization)
- {
- this.bindingTypes.addAll(getSpecializedType().getBindingTypes());
- log.trace("Using binding types " + bindingTypes + " specified by annotations and specialized supertype");
- }
- else if (bindingTypes.size() == 0)
- {
- log.trace("Adding default @Current binding type");
- this.bindingTypes.add(new CurrentAnnotationLiteral());
- }
- else
- {
- log.trace("Using binding types " + bindingTypes + " specified by annotations");
- }
- return;
+ log.trace("Adding default @Current binding type");
+ this.bindingTypes.add(new CurrentAnnotationLiteral());
}
+ else
+ {
+ log.trace("Using binding types " + bindingTypes + " specified by annotations");
+ }
+ return;
}
/**
@@ -190,42 +171,24 @@
@SuppressWarnings("null")
protected void initDeploymentType()
{
- if (isDefinedInXml())
- {
- Set<Annotation> xmlDeploymentTypes = null;
- if (xmlDeploymentTypes.size() > 1)
- {
- throw new DefinitionException("At most one deployment type may be specified (" + xmlDeploymentTypes + " are specified)");
- }
+ Set<Annotation> deploymentTypes = getAnnotatedItem().getMetaAnnotations(DeploymentType.class);
- if (xmlDeploymentTypes.size() == 1)
- {
- this.deploymentType = xmlDeploymentTypes.iterator().next().annotationType();
- log.trace("Deployment type " + deploymentType + " specified in XML");
- return;
- }
+ if (deploymentTypes.size() > 1)
+ {
+ throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
}
- else
+ if (deploymentTypes.size() == 1)
{
- Set<Annotation> deploymentTypes = getAnnotatedItem().getMetaAnnotations(DeploymentType.class);
+ this.deploymentType = deploymentTypes.iterator().next().annotationType();
+ log.trace("Deployment type " + deploymentType + " specified by annotation");
+ return;
+ }
- if (deploymentTypes.size() > 1)
- {
- throw new DefinitionException("At most one deployment type may be specified (" + deploymentTypes + " are specified) on " + getAnnotatedItem().toString());
- }
- if (deploymentTypes.size() == 1)
- {
- this.deploymentType = deploymentTypes.iterator().next().annotationType();
- log.trace("Deployment type " + deploymentType + " specified by annotation");
- return;
- }
-
- if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
- {
- this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
- log.trace("Deployment type " + deploymentType + " specified by stereotype");
- return;
- }
+ if (getMergedStereotypes().getPossibleDeploymentTypes().size() > 0)
+ {
+ this.deploymentType = getDeploymentType(manager.getEnabledDeploymentTypes(), getMergedStereotypes().getPossibleDeploymentTypes());
+ log.trace("Deployment type " + deploymentType + " specified by stereotype");
+ return;
}
this.deploymentType = getDefaultDeploymentType();
@@ -256,54 +219,31 @@
protected void initName()
{
boolean beanNameDefaulted = false;
- if (isDefinedInXml())
+ boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
+ if (getAnnotatedItem().isAnnotationPresent(Named.class))
{
- boolean xmlSpecialization = false;
- if (xmlSpecialization)
+ if (specialization)
{
- throw new DefinitionException("Name specified for specialized bean (declared in XML)");
+ throw new DefinitionException("Name specified for specialized bean");
}
- String xmlName = "";
- if ("".equals(xmlName))
+ String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
+ if ("".equals(javaName))
{
- log.trace("Using default name (specified in XML)");
+ log.trace("Using default name (specified by annotations)");
beanNameDefaulted = true;
}
else
{
- log.trace("Using name " + xmlName + " specified in XML");
- this.name = xmlName;
+ log.trace("Using name " + javaName + " specified by annotations");
+ this.name = javaName;
return;
}
}
- else
+ else if (specialization)
{
- boolean specialization = getAnnotatedItem().isAnnotationPresent(Specializes.class);
- if (getAnnotatedItem().isAnnotationPresent(Named.class))
- {
- if (specialization)
- {
- throw new DefinitionException("Name specified for specialized bean");
- }
- String javaName = getAnnotatedItem().getAnnotation(Named.class).value();
- if ("".equals(javaName))
- {
- log.trace("Using default name (specified by annotations)");
- beanNameDefaulted = true;
- }
- else
- {
- log.trace("Using name " + javaName + " specified by annotations");
- this.name = javaName;
- return;
- }
- }
- else if (specialization)
- {
- this.name = getSpecializedType().getName();
- log.trace("Using supertype name");
- return;
- }
+ this.name = getSpecializedType().getName();
+ log.trace("Using supertype name");
+ return;
}
if (beanNameDefaulted || getMergedStereotypes().isBeanNameDefaulted())
@@ -327,34 +267,16 @@
@SuppressWarnings("null")
protected void initScopeType()
{
- if (isDefinedInXml())
+ if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() > 1)
{
- Set<Class<? extends Annotation>> scopeTypes = null;
- if (scopeTypes.size() > 1)
- {
- throw new DefinitionException("At most one scope may be specified in XML");
- }
-
- if (scopeTypes.size() == 1)
- {
- this.scopeType = scopeTypes.iterator().next();
- log.trace("Scope " + scopeType + " specified in XML");
- return;
- }
+ throw new DefinitionException("At most one scope may be specified");
}
- else
- {
- if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() > 1)
- {
- throw new DefinitionException("At most one scope may be specified");
- }
- if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() == 1)
- {
- this.scopeType = getAnnotatedItem().getMetaAnnotations(ScopeType.class).iterator().next().annotationType();
- log.trace("Scope " + scopeType + " specified by annotation");
- return;
- }
+ if (getAnnotatedItem().getMetaAnnotations(ScopeType.class).size() == 1)
+ {
+ this.scopeType = getAnnotatedItem().getMetaAnnotations(ScopeType.class).iterator().next().annotationType();
+ log.trace("Scope " + scopeType + " specified by annotation");
+ return;
}
if (getMergedStereotypes().getPossibleScopeTypes().size() == 1)
@@ -580,16 +502,6 @@
}
/**
- * Indicates if bean was defined in XML
- *
- * @return True if defined in XML, false if defined with annotations
- */
- protected boolean isDefinedInXml()
- {
- return false;
- }
-
- /**
* Inicates if bean is nullable
*
* @return True if nullable, false otherwise
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-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -88,15 +88,8 @@
*/
protected void initType()
{
- if (isDefinedInXml())
- {
- log.trace("Bean type specified in Java");
- }
- else
- {
- log.trace("Bean type specified in Java");
- this.type = getAnnotatedItem().getType();
- }
+ log.trace("Bean type specified in Java");
+ this.type = getAnnotatedItem().getType();
}
/**
@@ -154,40 +147,33 @@
*/
protected void initInitializerMethods()
{
- if (isDefinedInXml())
+ initializerMethods = new HashSet<AnnotatedMethod<Object>>();
+ for (AnnotatedMethod<Object> annotatedMethod : annotatedItem.getAnnotatedMethods(Initializer.class))
{
-
- }
- else
- {
- initializerMethods = new HashSet<AnnotatedMethod<Object>>();
- for (AnnotatedMethod<Object> annotatedMethod : annotatedItem.getAnnotatedMethods(Initializer.class))
+ if (annotatedMethod.isStatic())
{
- if (annotatedMethod.isStatic())
- {
- throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be static");
- }
- else if (annotatedMethod.getAnnotation(Produces.class) != null)
- {
- throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Produces");
- }
- else if (annotatedMethod.getAnnotation(Destructor.class) != null)
- {
- throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Destructor");
- }
- else if (annotatedMethod.getAnnotatedParameters(Disposes.class).size() > 0)
- {
- throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot have parameters annotated @Disposes");
- }
- else if (annotatedMethod.getAnnotatedParameters(Observes.class).size() > 0)
- {
- throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Observes");
- }
- else
- {
- initializerMethods.add(annotatedMethod);
- }
+ throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be static");
}
+ else if (annotatedMethod.getAnnotation(Produces.class) != null)
+ {
+ throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Produces");
+ }
+ else if (annotatedMethod.getAnnotation(Destructor.class) != null)
+ {
+ throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Destructor");
+ }
+ else if (annotatedMethod.getAnnotatedParameters(Disposes.class).size() > 0)
+ {
+ throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot have parameters annotated @Disposes");
+ }
+ else if (annotatedMethod.getAnnotatedParameters(Observes.class).size() > 0)
+ {
+ throw new DefinitionException("Initializer method " + annotatedMethod.toString() + " cannot be annotated @Observes");
+ }
+ else
+ {
+ initializerMethods.add(annotatedMethod);
+ }
}
}
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EnterpriseBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -50,8 +50,6 @@
public class EnterpriseBean<T> extends AbstractClassBean<T>
{
- private String location;
-
private EjbMetaData<T> ejbMetaData;
/**
@@ -138,20 +136,10 @@
{
return;
}
- if (!isDefinedInXml())
+ if (!MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
{
- if (!MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
- {
- throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
- }
+ throw new DefinitionException("Annotation defined specializing EJB must have EJB superclass");
}
- else
- {
- if (MetaDataCache.instance().getEjbMetaData(getAnnotatedItem().getSuperclass().getType()).isEjb())
- {
- throw new DefinitionException("XML defined specializing EJB must have annotation defined EJB implementation");
- }
- }
}
/**
@@ -281,20 +269,6 @@
}
/**
- * Gets the debugging location info
- *
- * @return The location string
- */
- public String getLocation()
- {
- if (location == null)
- {
- location = "type: Enterprise Bean; declaring class: " + getType() + ";";
- }
- return location;
- }
-
- /**
* Returns the specializes type of the bean
*
* @return The specialized type
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 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -47,9 +47,6 @@
private AnnotatedMethod<T> method;
private AbstractClassBean<?> declaringBean;
-
- // Cached values
- private String location;
/**
* Constructor
@@ -176,7 +173,7 @@
else if (disposalMethods.size() > 1)
{
// TODO List out found disposal methods
- throw new DefinitionException (getLocation() + "Cannot declare multiple disposal methods for this producer method");
+ throw new DefinitionException ("Cannot declare multiple disposal methods for this producer method");
}
}
@@ -218,7 +215,7 @@
}
catch (ClassCastException e)
{
- throw new RuntimeException(getLocation() + " Cannot cast producer method return type " + method.getType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
+ throw new RuntimeException(" Cannot cast producer method return type " + method.getType() + " to bean type " + (getDeclaredBeanType() == null ? " unknown " : getDeclaredBeanType()), e);
}
}
@@ -246,20 +243,6 @@
}
/**
- * Gets the debugging location info
- *
- * @return The location string
- */
- public String getLocation()
- {
- if (location == null)
- {
- location = "type: Producer Method; declaring class: " + method.getDeclaringClass() +"; producer method: " + method.toString() + ";";
- }
- return location;
- }
-
- /**
* Returns the disposal method
*
* @return The method representation
@@ -285,7 +268,6 @@
StringBuilder buffer = new StringBuilder();
buffer.append("ProducerMethodBean:\n");
buffer.append(super.toString() + "\n");
- buffer.append("Location: " + location + "\n");
buffer.append("Declaring bean: " + declaringBean.toString() + "\n");
buffer.append("Method: " + method.toString() + "\n");
return buffer.toString();
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -51,7 +51,6 @@
private static List<Class<?>> NO_ARGUMENTS = Collections.emptyList();
private AnnotatedConstructor<T> constructor;
- private String location;
private AnnotatedMethod<Object> postConstruct;
private AnnotatedMethod<Object> preDestroy;
@@ -306,20 +305,6 @@
}
/**
- * Gets the debugging location info
- *
- * @return The location string
- */
- public String getLocation()
- {
- if (location == null)
- {
- location = "type: Simple Bean; declaring class: " + getType() + ";";
- }
- return location;
- }
-
- /**
* Returns the specializes type of the bean
*
* @return The specialized type
@@ -383,7 +368,6 @@
StringBuilder buffer = new StringBuilder();
buffer.append("SimpleBean\n");
buffer.append(super.toString() + "\n");
- buffer.append("Location: " + location + "\n");
buffer.append("Constructor: " + constructor.toString() + "\n");
buffer.append("Post-construct: " + (postConstruct == null ? "null" : postConstruct.toString()) + "\n");
buffer.append("Pre-destroy: " + (preDestroy == null ? "null" : preDestroy.toString()) + "\n");
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlEnterpriseBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -1,59 +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.bean;
-
-import org.jboss.webbeans.ManagerImpl;
-
-
-/**
- * Represents an XML defined enterprise bean
- *
- * @author Pete Muir
- *
- * @param <T>
- */
-public class XmlEnterpriseBean<T> extends EnterpriseBean<T>
-{
-
- /**
- * Constructor
- *
- * @param type The type of the bean
- */
- public XmlEnterpriseBean(Class<T> type, ManagerImpl manager)
- {
- super(type, manager);
- }
-
- /**
- * Indicates the bean was defined in XML
- */
- protected boolean isDefinedInXml()
- {
- return true;
- }
-
- @Override
- public String toString()
- {
- StringBuilder buffer = new StringBuilder();
- buffer.append("XmlEnterpriseBean\n");
- buffer.append(super.toString() + "\n");
- return buffer.toString();
- }
-}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/XmlSimpleBean.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -1,59 +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.bean;
-
-import org.jboss.webbeans.ManagerImpl;
-
-
-/**
- * Represents a simple, XML defined bean
- *
- * @author Pete Muir
- *
- * @param <T>
- */
-public class XmlSimpleBean<T> extends SimpleBean<T>
-{
-
- /**
- * Constructor
- *
- * @param type The type of the bean
- */
- public XmlSimpleBean(Class<T> type, ManagerImpl manager)
- {
- super(type, manager);
- }
-
- /**
- * Indicates the bean was defined in XML
- */
- protected boolean isDefinedInXml()
- {
- return true;
- }
-
- @Override
- public String toString()
- {
- StringBuilder buffer = new StringBuilder();
- buffer.append("XmlLSimpleBean\n");
- buffer.append(super.toString() + "\n");
- return buffer.toString();
- }
-}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/Location.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/Location.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/Location.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -1,138 +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.exceptions;
-
-/**
- * Helper superclass for exception information
- *
- * @author Pete Muir
- */
-public class Location
-{
- // The category of the exception
- private String type;
- // The bean the exception occurred in
- private String bean;
- // The element the exception occurred in
- private String element;
-
- /**
- * Constructor
- *
- * @param type The category
- * @param bean The bean
- * @param element The element
- */
- public Location(String type, String bean, String element)
- {
- super();
- this.type = type;
- this.bean = bean;
- this.element = element;
- }
-
- /**
- * Gets the type of the exception
- *
- * @return The type
- */
- public String getType()
- {
- return type;
- }
-
- /**
- * Sets the type of the exception
- *
- * @param type The type
- */
- public void setType(String type)
- {
- this.type = type;
- }
-
- /**
- * Gets the bean the exception occurred in
- *
- * @return The bean
- */
- public String getBean()
- {
- return bean;
- }
-
- /**
- * Sets the bean the exception occurred in
- *
- * @param bean The bean
- */
- public void setBean(String bean)
- {
- this.bean = bean;
- }
-
- /**
- * Gets the element the exception occurred in
- *
- * @return The element
- */
- public String getElement()
- {
- return element;
- }
-
- /**
- * Sets the element the exception occurred in
- *
- * @param element The element
- */
- public void setElement(String element)
- {
- this.element = element;
- }
-
- /**
- * Gets the summarizing message
- *
- * @return The message
- */
- protected String getMessage()
- {
- String location = "";
- if (getType() != null)
- {
- location += "type: " + getType() + "; ";
- }
- if (getBean() != null)
- {
- location += "bean: " + getBean() + "; ";
- }
- if (getElement() != null)
- {
- location += "element: " + getElement() + "; ";
- }
- return location;
- }
-
- @Override
- public String toString()
- {
- return getMessage();
- }
-
-}
Deleted: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/NameResolutionLocation.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/NameResolutionLocation.java 2008-12-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/exceptions/NameResolutionLocation.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -1,77 +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.exceptions;
-
-/**
- * Exception location info for name resolution exceptions
- *
- * @author Pete Muir
- */
-public class NameResolutionLocation extends Location
-{
- // The target of the failure
- private String target;
-
- /**
- * Constructor
- *
- * @param target The target of the failure
- */
- public NameResolutionLocation(String target)
- {
- super("Named Based Resolution", null, null);
-
- }
-
- /**
- * Gets the target
- *
- * @return The target
- */
- public String getTarget()
- {
- return target;
- }
-
- /**
- * Sets the target
- *
- * @param target The target
- */
- public void setTarget(String target)
- {
- this.target = target;
- }
-
- /**
- * Gets the exception message
- *
- * @return The message
- */
- @Override
- protected String getMessage()
- {
- String location = super.getMessage();
- if (getTarget() != null)
- {
- location += "target: " + getTarget() + ";";
- }
- return location;
- }
-
-}
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-07 16:37:02 UTC (rev 437)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/BeanFactory.java 2008-12-07 16:46:10 UTC (rev 438)
@@ -25,8 +25,6 @@
import org.jboss.webbeans.bean.EventBean;
import org.jboss.webbeans.bean.ProducerMethodBean;
import org.jboss.webbeans.bean.SimpleBean;
-import org.jboss.webbeans.bean.XmlEnterpriseBean;
-import org.jboss.webbeans.bean.XmlSimpleBean;
import org.jboss.webbeans.event.ObserverImpl;
import org.jboss.webbeans.introspector.AnnotatedField;
import org.jboss.webbeans.introspector.AnnotatedMethod;
@@ -51,18 +49,6 @@
}
/**
- * Creates a simple, XML defined Web Bean
- *
- * @param <T> The type
- * @param clazz The class
- * @return A Web Bean
- */
- public static <T> XmlSimpleBean<T> createXmlSimpleBean(Class<T> clazz)
- {
- return new XmlSimpleBean<T>(clazz, CurrentManager.rootManager());
- }
-
- /**
* Creates a simple, annotation defined Enterprise Web Bean
*
* @param <T> The type
@@ -75,18 +61,6 @@
}
/**
- * Creates a simple, XML defined Enterprise Web Bean
- *
- * @param <T> The type
- * @param clazz The class
- * @return An Enterprise Web Bean
- */
- public static <T> XmlEnterpriseBean<T> createXmlEnterpriseBean(Class<T> clazz)
- {
- return new XmlEnterpriseBean<T>(clazz, CurrentManager.rootManager());
- }
-
- /**
* Creates a producer method Web Bean
*
* @param <T> The type
16 years
[webbeans-commits] Webbeans SVN: r437 - ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-12-07 11:37:02 -0500 (Sun, 07 Dec 2008)
New Revision: 437
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
Log:
Fixed observer test which had invalid bindings that are now detected.
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-12-07 16:07:58 UTC (rev 436)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ObserverTest.java 2008-12-07 16:37:02 UTC (rev 437)
@@ -1,8 +1,7 @@
package org.jboss.webbeans.test;
-import java.lang.annotation.Annotation;
+
import java.lang.reflect.Method;
-import javax.webbeans.AnnotationLiteral;
import javax.webbeans.Observer;
import javax.webbeans.Observes;
@@ -11,7 +10,8 @@
import org.jboss.webbeans.introspector.AnnotatedMethod;
import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
import org.jboss.webbeans.introspector.jlr.AnnotatedMethodImpl;
-import org.jboss.webbeans.test.annotations.Asynchronous;
+import org.jboss.webbeans.test.annotations.Role;
+import org.jboss.webbeans.test.bindings.RoleBinding;
import org.jboss.webbeans.test.mock.MockManagerImpl;
import org.jboss.webbeans.util.BeanFactory;
import org.testng.annotations.BeforeMethod;
@@ -27,7 +27,7 @@
public class ObserverTest
{
private MockManagerImpl manager;
- //private SimpleBean<Tuna> tuna;
+ // private SimpleBean<Tuna> tuna;
private SimpleBean<SampleObserver> ob;
private AnnotatedMethod<Object> om;
Observer<SampleEvent> observer;
@@ -42,16 +42,18 @@
public static class SampleObserver
{
- public void observe(@Observes @Asynchronous SampleEvent e)
+ public void observe(@Observes @Role("Admin") SampleEvent e)
{
// An observer method
notified = true;
}
-
+
}
-
- public static @interface Foo {}
+ public static @interface Foo
+ {
+ }
+
@BeforeMethod
public void before() throws Exception
{
@@ -61,9 +63,8 @@
manager.addBean(ob);
Method method = SampleObserver.class.getMethod("observe", SampleEvent.class);
om = new AnnotatedMethodImpl<Object>(method, new AnnotatedClassImpl<SampleObserver>(SampleObserver.class));
- observer = BeanFactory.createObserver( om, ob);
- Annotation annotation = method.getParameterAnnotations()[0][1];
- manager.addObserver(observer, SampleEvent.class, annotation);
+ observer = BeanFactory.createObserver(om, ob);
+ manager.addObserver(observer, SampleEvent.class, new RoleBinding("Admin"));
notified = false;
}
@@ -72,29 +73,32 @@
* {@link org.jboss.webbeans.event.ObserverImpl#notify(javax.webbeans.Container, java.lang.Object)}
* .
*/
- @Test(groups = "observerMethod") @SpecAssertion(section={"7.5.7"})
+ @Test(groups = "observerMethod")
+ @SpecAssertion(section = { "7.5.7" })
public final void testNotify() throws Exception
{
- SampleEvent event = new SampleEvent();
- notified = false;
+ SampleEvent event = new SampleEvent();
+ notified = false;
observer.notify(event);
assert notified == true;
}
- @Test(groups = "observerMethod") @SpecAssertion(section={"7.5.7"})
+ @Test(groups = "observerMethod")
+ @SpecAssertion(section = { "7.5.7" })
public final void testNotifyViaManager() throws Exception
{
- notified = false;
+ notified = false;
manager.fireEvent(new SampleEvent());
assert notified == false;
- manager.fireEvent(new Object(), new AnnotationLiteral<Asynchronous>() {});
+ manager.fireEvent(new Object(), new RoleBinding("Admin"));
assert notified == false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Foo>() {});
- assert notified == false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>() {});
+ manager.fireEvent(new SampleEvent(), new RoleBinding("Admin"));
assert notified == true;
notified = false;
- manager.fireEvent(new SampleEvent(), new AnnotationLiteral<Asynchronous>() {}, new AnnotationLiteral<Foo>() {});
+ manager.fireEvent(new SampleEvent(), new RoleBinding("User"));
+ assert notified == false;
+ notified = false;
+ manager.fireEvent(new SampleEvent(), new RoleBinding("Admin"), new RoleBinding("User"));
assert notified == true;
}
16 years
[webbeans-commits] Webbeans SVN: r436 - 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 11:07:58 -0500 (Sun, 07 Dec 2008)
New Revision: 436
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
Log:
ws
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 15:43:13 UTC (rev 435)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 16:07:58 UTC (rev 436)
@@ -145,7 +145,6 @@
*/
protected void initBindingTypes()
{
-
this.bindingTypes = new HashSet<Annotation>();
if (isDefinedInXml())
{
16 years
[webbeans-commits] Webbeans SVN: r435 - in ri/trunk/webbeans-ri/src: test/java/org/jboss/webbeans/test and 2 other directories.
by webbeans-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2008-12-07 10:43:13 -0500 (Sun, 07 Dec 2008)
New Revision: 435
Added:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Grayling.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Minnow.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Pollock.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Scallop.java
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/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/bean/ProducerMethodBean.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ScopeTypeTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Spider.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
Log:
Start to update to 20081206
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractBean.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -31,7 +31,6 @@
import javax.webbeans.DeploymentType;
import javax.webbeans.Event;
import javax.webbeans.Named;
-import javax.webbeans.Production;
import javax.webbeans.ScopeType;
import javax.webbeans.Specializes;
import javax.webbeans.Standard;
@@ -230,10 +229,12 @@
}
}
- this.deploymentType = Production.class;
+ this.deploymentType = getDefaultDeploymentType();
log.trace("Using default @Production deployment type");
return;
}
+
+ protected abstract Class<? extends Annotation> getDefaultDeploymentType();
/**
* Initializes the injection points
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-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractClassBean.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -17,6 +17,7 @@
package org.jboss.webbeans.bean;
+import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;
@@ -28,6 +29,7 @@
import javax.webbeans.Observable;
import javax.webbeans.Observes;
import javax.webbeans.Produces;
+import javax.webbeans.Production;
import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.introspector.AnnotatedClass;
@@ -287,4 +289,10 @@
buffer.append(Strings.collectionToString("Producer methods: ", getProducerMethods()));
return buffer.toString();
}
+
+ @Override
+ protected Class<? extends Annotation> getDefaultDeploymentType()
+ {
+ return Production.class;
+ }
}
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-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/EventBean.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -17,12 +17,14 @@
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;
@@ -131,5 +133,11 @@
Class<T> eventType = (Class<T>) annotatedItem.getType().getTypeParameters()[0].getClass();
return new EventImpl<T>(manager, eventType, annotatedItem.getBindingTypesAsArray());
}
+
+ @Override
+ protected Class<? extends Annotation> getDefaultDeploymentType()
+ {
+ return Production.class;
+ }
}
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 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/ProducerMethodBean.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -124,17 +124,10 @@
}
}
- /**
- * Initializes the deployment type
- */
@Override
- protected void initDeploymentType()
+ protected Class<? extends Annotation> getDefaultDeploymentType()
{
- super.initDeploymentType();
- if (getDeploymentType() == null)
- {
- deploymentType = declaringBean.getDeploymentType();
- }
+ return deploymentType = declaringBean.getDeploymentType();
}
/**
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/CommonWebBeanTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -10,9 +10,14 @@
import javax.webbeans.manager.Bean;
import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.test.beans.Animal;
+import org.jboss.webbeans.test.beans.DeadlyAnimal;
+import org.jboss.webbeans.test.beans.DeadlySpider;
+import org.jboss.webbeans.test.beans.FinalTuna;
import org.jboss.webbeans.test.beans.RedSnapper;
import org.jboss.webbeans.test.beans.Spider;
import org.jboss.webbeans.test.beans.SpiderProducer;
+import org.jboss.webbeans.test.beans.Tarantula;
import org.testng.annotations.Test;
/**
@@ -21,6 +26,7 @@
* @author Pete Muir
*
*/
+@SpecVersion("20081206")
public class CommonWebBeanTest extends AbstractTest
{
@@ -54,7 +60,7 @@
assert model.getDeploymentType().equals(Production.class);
}
- @Test(groups="producerMethod") @SpecAssertion(section="4.2")
+ @Test(groups="producerMethod") @SpecAssertion(section="5.2")
public void testIsNullable() throws Exception
{
SimpleBean<SpiderProducer> spiderProducerBean = createSimpleBean(SpiderProducer.class);
@@ -67,4 +73,24 @@
assert spiderBean.isNullable();
}
+
+ @Test @SpecAssertion(section={"3.2.2", "2.2"})
+ public void testApiTypes()
+ {
+ Bean<Tarantula> bean = createSimpleBean(Tarantula.class);
+ assert bean.getTypes().size() == 6;
+ assert bean.getTypes().contains(Tarantula.class);
+ assert bean.getTypes().contains(Spider.class);
+ assert bean.getTypes().contains(Animal.class);
+ assert bean.getTypes().contains(Object.class);
+ assert bean.getTypes().contains(DeadlySpider.class);
+ assert bean.getTypes().contains(DeadlyAnimal.class);
+ }
+
+ @Test @SpecAssertion(section="2.2")
+ public void testFinalApiType()
+ {
+ createSimpleBean(FinalTuna.class);
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/DeploymentTypeTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -1,7 +1,10 @@
package org.jboss.webbeans.test;
+import static org.jboss.webbeans.util.BeanFactory.createProducerMethodBean;
import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
+import java.lang.reflect.Method;
+
import javax.webbeans.DefinitionException;
import javax.webbeans.DeploymentException;
import javax.webbeans.Production;
@@ -9,16 +12,20 @@
import javax.webbeans.UnsatisfiedDependencyException;
import javax.webbeans.manager.Bean;
+import org.jboss.webbeans.bean.ProducerMethodBean;
+import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.test.annotations.AnotherDeploymentType;
import org.jboss.webbeans.test.annotations.HornedAnimalDeploymentType;
+import org.jboss.webbeans.test.beans.BlackWidow;
import org.jboss.webbeans.test.beans.RedSnapper;
import org.jboss.webbeans.test.beans.Reindeer;
import org.jboss.webbeans.test.beans.Rhinoceros;
+import org.jboss.webbeans.test.beans.SpiderProducer;
import org.jboss.webbeans.test.beans.broken.BeanWithTooManyDeploymentTypes;
import org.jboss.webbeans.test.beans.broken.Gazelle;
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("20081206")
public class DeploymentTypeTest extends AbstractTest
{
@@ -52,6 +59,16 @@
createSimpleBean(BeanWithTooManyDeploymentTypes.class);
}
+ @Test @SpecAssertion(section="2.5.3")
+ public void testDeploymentTypeInhertitedFromDeclaringBean() throws Exception
+ {
+ SimpleBean<SpiderProducer> bean = createSimpleBean(SpiderProducer.class);
+ manager.addBean(bean);
+ Method method = SpiderProducer.class.getMethod("produceBlackWidow");
+ ProducerMethodBean<BlackWidow> blackWidowSpiderModel = createProducerMethodBean(BlackWidow.class, method, bean);
+ assert blackWidowSpiderModel.getDeploymentType().equals(AnotherDeploymentType.class);
+ }
+
@Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.5.4")
public void testXmlDeploymentTypeOverridesJava()
{
@@ -91,17 +108,6 @@
assert bean.getDeploymentType().equals(HornedAnimalDeploymentType.class);
}
- @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.5.5")
- public void testDeploymentTypeSpecifiedAndStereotyped()
- {
- //Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
- //annotations.put(FishStereotype.class, new FishStereotypeAnnotationLiteral());
- //AnnotatedClass<SeaBass> annotatedItem = new SimpleAnnotatedClass<SeaBass>(SeaBass.class, annotations);
- //SimpleBean<SeaBass> trout = createSimpleBean(SeaBass.class, annotatedItem, manager);
- //assert trout.getScopeType().equals(RequestScoped.class);
- assert false;
- }
-
@Test(groups="beanLifecycle", expectedExceptions=UnsatisfiedDependencyException.class) @SpecAssertion(section="2.5.6")
public void testBeanWithDisabledDeploymentTypeNotInstantiated()
{
@@ -143,7 +149,7 @@
}
- @Test @SpecAssertion(section="2.7.2")
+ @Test @SpecAssertion(section={"2.5.5", "2.7.2"})
public void testWebBeanDeploymentTypeOverridesStereotype()
{
Bean<Reindeer> bean = createSimpleBean(Reindeer.class);
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NameTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -6,16 +6,17 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.test.beans.Haddock;
+import org.jboss.webbeans.test.beans.Minnow;
import org.jboss.webbeans.test.beans.Moose;
import org.jboss.webbeans.test.beans.RedSnapper;
import org.jboss.webbeans.test.beans.SeaBass;
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("20081206")
public class NameTest extends AbstractTest
{
- @Test(groups={"stub", "el"}, expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.6")
+ @Test(groups="stub", expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.6")
public void testInvalidElIdentifierUsedAsWebBeanName()
{
assert false;
@@ -127,15 +128,11 @@
assert model.getName() == null;
}
- @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.6.4")
+ @Test @SpecAssertion(section="2.6.4")
public void testNotNamedInStereotype()
{
- /*Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
- annotations.put(RiverFishStereotype.class, new RiverFishStereotypeAnnotationLiteral());
- AnnotatedClass<SeaBass> annotatedItem = new SimpleAnnotatedClass<SeaBass>(SeaBass.class, annotations);*/
- //SimpleBean<SeaBass> model = createSimpleBean(SeaBass.class, annotatedItem, manager);
- //assert model.getName() == null;
- assert false;
+ SimpleBean<Minnow> model = createSimpleBean(Minnow.class);
+ assert model.getName() == null;
}
}
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 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ProducerMethodBeanModelTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -7,6 +7,7 @@
import javax.webbeans.Current;
import javax.webbeans.DefinitionException;
+import javax.webbeans.Production;
import javax.webbeans.RequestScoped;
import org.jboss.webbeans.bean.ProducerMethodBean;
@@ -140,7 +141,7 @@
assert intModel.getTypes().contains(Object.class);
}
- @Test(groups="producerMethod") @SpecAssertion(section="3.4.1")
+ @Test(groups="producerMethod") @SpecAssertion(section={"3.4.1", "2.2"})
public void testApiTypeForArrayTypeReturn() throws Exception
{
SimpleBean<SpiderProducer> bean = createSimpleBean(SpiderProducer.class);
@@ -182,7 +183,7 @@
manager.addBean(bean);
Method method = SpiderProducer.class.getMethod("getLadybirdSpider");
ProducerMethodBean<LadybirdSpider> ladybirdSpiderModel = createProducerMethodBean(LadybirdSpider.class, method, bean);
- assert ladybirdSpiderModel.getDeploymentType().equals(AnotherDeploymentType.class);
+ assert ladybirdSpiderModel.getDeploymentType().equals(Production.class);
}
@Test(groups="producerMethod") @SpecAssertion(section="3.4.2")
@@ -292,7 +293,7 @@
assert false;
}
- @Test(groups="producerMethod") @SpecAssertion(section={"2.7.2", "3.4.2"})
+ @Test(groups="producerMethod") @SpecAssertion(section={"2.7.2", "3.4.2", "2.2"})
public void testStereotype() throws Exception
{
SimpleBean<SpiderProducer> bean = createSimpleBean(SpiderProducer.class);
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ResolutionByTypeTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -280,7 +280,7 @@
assert manager.resolveByType(Tuna.class, new CurrentAnnotationLiteral()).size() == 0;
}
- @Test(groups="resolution") @SpecAssertion(section="4.9.2")
+ @Test(groups="resolution") @SpecAssertion(section={"4.9.2", "2.2"})
public void testResolveObject() throws Exception
{
Bean<Salmon> salmonBean = createSimpleBean(Salmon.class);
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ScopeTypeTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ScopeTypeTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ScopeTypeTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -2,6 +2,7 @@
import static org.jboss.webbeans.util.BeanFactory.createSimpleBean;
+import javax.webbeans.ApplicationScoped;
import javax.webbeans.DefinitionException;
import javax.webbeans.Dependent;
import javax.webbeans.RequestScoped;
@@ -10,13 +11,17 @@
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.test.annotations.AnotherScopeType;
import org.jboss.webbeans.test.beans.BeanWithTooManyScopeTypes;
+import org.jboss.webbeans.test.beans.Grayling;
+import org.jboss.webbeans.test.beans.Minnow;
import org.jboss.webbeans.test.beans.Mullet;
import org.jboss.webbeans.test.beans.Order;
+import org.jboss.webbeans.test.beans.Pollock;
import org.jboss.webbeans.test.beans.RedSnapper;
import org.jboss.webbeans.test.beans.SeaBass;
+import org.jboss.webbeans.test.beans.broken.Scallop;
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("20081206")
public class ScopeTypeTest extends AbstractTest
{
@@ -109,47 +114,31 @@
assert order.getScopeType().equals(Dependent.class);
}
- @Test(groups={"stub", "webbeansxml"})@SpecAssertion(section={"2.4.5", "2.7.2"})
+ @Test @SpecAssertion(section={"2.4.5", "2.7.2"})
public void testScopeSpecifiedAndStereotyped()
{
- //Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
- //annotations.put(FishStereotype.class, new FishStereotypeAnnotationLiteral());
- //AnnotatedClass<SeaBass> annotatedItem = new SimpleAnnotatedClass<SeaBass>(SeaBass.class, annotations);
- //SimpleBean<SeaBass> trout = createSimpleBean(SeaBass.class, annotatedItem, manager);
- //assert trout.getScopeType().equals(RequestScoped.class);
- assert false;
+ Bean<Minnow> minnow = createSimpleBean(Minnow.class);
+ assert minnow.getScopeType().equals(RequestScoped.class);
}
- @Test(groups={"webbeansxml", "stub"}) @SpecAssertion(section="2.4.5")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.4.5")
public void testMutipleIncompatibleScopeStereotypes()
{
- assert false;
+ createSimpleBean(Scallop.class);
}
- @Test(groups={"stub", "webbeansxml"}) @SpecAssertion(section="2.4.5")
+ @Test @SpecAssertion(section="2.4.5")
public void testMutipleIncompatibleScopeStereotypesWithScopeSpecified()
{
- /*Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
- annotations.put(FishStereotype.class, new FishStereotypeAnnotationLiteral());
- annotations.put(AnimalStereotype.class, new AnimalStereotypeAnnotationLiteral());
- AnnotatedClass<SeaBass> annotatedItem = new SimpleAnnotatedClass<SeaBass>(SeaBass.class, annotations);*/
-
- //SimpleBean<SeaBass> trout = createSimpleBean(SeaBass.class, annotatedItem, manager);
- //assert trout.getScopeType().equals(RequestScoped.class);
- assert false;
+ Bean<Pollock> pollock = createSimpleBean(Pollock.class);
+ assert pollock.getScopeType().equals(Dependent.class);
}
- @Test(groups={"stub", "webbeansxml"})@SpecAssertion(section="2.4.5")
+ @Test @SpecAssertion(section="2.4.5")
public void testMutipleCompatibleScopeStereotypes()
{
- /*Map<Class<? extends Annotation>, Annotation> annotations = new HashMap<Class<? extends Annotation>, Annotation>();
- annotations.put(FishStereotype.class, new FishStereotypeAnnotationLiteral());
- annotations.put(RiverFishStereotype.class, new RiverFishStereotypeAnnotationLiteral());
- AnnotatedClass<Haddock> annotatedItem = new SimpleAnnotatedClass<Haddock>(Haddock.class, annotations);*/
-
- //SimpleBean<Haddock> haddock = createSimpleBean(Haddock.class, annotatedItem, manager);
- //assert haddock.getScopeType().equals(ApplicationScoped.class);
- assert false;
+ Bean<Grayling> grayling = createSimpleBean(Grayling.class);
+ assert grayling.getScopeType().equals(ApplicationScoped.class);
}
@Test @SpecAssertion(section="2.7.2")
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/SimpleBeanModelTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -10,7 +10,6 @@
import javax.webbeans.AnnotationLiteral;
import javax.webbeans.DefinitionException;
import javax.webbeans.NonexistentConstructorException;
-import javax.webbeans.manager.Bean;
import org.jboss.webbeans.bean.SimpleBean;
import org.jboss.webbeans.bindings.CurrentAnnotationLiteral;
@@ -18,16 +17,11 @@
import org.jboss.webbeans.introspector.AnnotatedParameter;
import org.jboss.webbeans.test.annotations.HeavyDuty;
import org.jboss.webbeans.test.annotations.Motorized;
-import org.jboss.webbeans.test.beans.Animal;
import org.jboss.webbeans.test.beans.Cow;
-import org.jboss.webbeans.test.beans.DeadlyAnimal;
-import org.jboss.webbeans.test.beans.DeadlySpider;
import org.jboss.webbeans.test.beans.Donkey;
import org.jboss.webbeans.test.beans.Duck;
import org.jboss.webbeans.test.beans.Order;
import org.jboss.webbeans.test.beans.Sheep;
-import org.jboss.webbeans.test.beans.Spider;
-import org.jboss.webbeans.test.beans.Tarantula;
import org.jboss.webbeans.test.beans.Tractor;
import org.jboss.webbeans.test.beans.Turkey;
import org.jboss.webbeans.test.beans.broken.Goose;
@@ -80,19 +74,6 @@
}
- @Test @SpecAssertion(section="3.2.2")
- public void testApiTypes()
- {
- Bean<Tarantula> bean = createSimpleBean(Tarantula.class);
- assert bean.getTypes().size() == 6;
- assert bean.getTypes().contains(Tarantula.class);
- assert bean.getTypes().contains(Spider.class);
- assert bean.getTypes().contains(Animal.class);
- assert bean.getTypes().contains(Object.class);
- assert bean.getTypes().contains(DeadlySpider.class);
- assert bean.getTypes().contains(DeadlyAnimal.class);
- }
-
@Test(groups={"stub", "producerMethod", "webbeansxml"}) @SpecAssertion(section="3.2.4")
public void testBeanDeclaredInXmlIgnoresProducerMethodDeclaredInJava()
{
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/StereotypesTest.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -27,7 +27,7 @@
import org.jboss.webbeans.test.beans.broken.Carp;
import org.testng.annotations.Test;
-@SpecVersion("PDR")
+@SpecVersion("20081206")
public class StereotypesTest extends AbstractTest
{
@@ -90,46 +90,46 @@
assert animalStereotype.getDefaultDeploymentType() == null;
}
- @Test @SpecAssertion(section="2.7.1")
+ @Test @SpecAssertion(section="2.7.1.1")
public void testStereotypeWithScopeType()
{
StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(AnimalStereotype.class);
assert animalStereotype.getDefaultScopeType().annotationType().equals(RequestScoped.class);
}
- @Test @SpecAssertion(section="2.7.1")
+ @Test @SpecAssertion(section="2.7.1.1")
public void testStereotypeWithoutScopeType()
{
StereotypeModel<HornedMammalStereotype> animalStereotype = new StereotypeModel<HornedMammalStereotype>(HornedMammalStereotype.class);
assert animalStereotype.getDefaultScopeType() == null;
}
- @Test @SpecAssertion(section="2.7.1")
+ @Test @SpecAssertion(section="2.7.1.2")
public void testStereotypeWithoutInterceptors()
{
StereotypeModel<AnimalStereotype> animalStereotype = new StereotypeModel<AnimalStereotype>(AnimalStereotype.class);
assert animalStereotype.getInterceptorBindings().size() == 0;
}
- @Test(groups={"stub", "interceptors"}) @SpecAssertion(section="2.7.1")
+ @Test(groups={"stub", "interceptors"}) @SpecAssertion(section="2.7.1.2")
public void testStereotypeWithInterceptors()
{
assert false;
}
- @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1.1")
public void testStereotypeWithTooManyScopeTypes()
{
new StereotypeModel<StereotypeWithTooManyScopeTypes>(StereotypeWithTooManyScopeTypes.class);
}
- @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1.1")
public void testStereotypeWithTooManyDeploymentTypes()
{
new StereotypeModel<StereotypeWithTooManyDeploymentTypes>(StereotypeWithTooManyDeploymentTypes.class);
}
- @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.1.3")
public void testStereotypeWithNonEmptyNamed()
{
new StereotypeModel<StereotypeWithNonEmptyNamed>(StereotypeWithNonEmptyNamed.class);
@@ -186,28 +186,30 @@
}
- @Test@SpecAssertion(section="2.7.4")
+ @Test@SpecAssertion(section={"2.7.1.4", "2.7.4"})
public void testRequiredTypeIsImplemented()
{
createSimpleBean(HighlandCow.class);
}
- @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.4")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section={"2.7.1.4", "2.7.4"})
public void testRequiredTypeIsNotImplemented()
{
createSimpleBean(Chair.class);
}
- @Test @SpecAssertion(section="2.7.4")
+ @Test @SpecAssertion(section={"2.7.1.4", "2.7.4"})
public void testScopeIsSupported()
{
createSimpleBean(Goldfish.class);
}
- @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section="2.7.4")
+ @Test(expectedExceptions=DefinitionException.class) @SpecAssertion(section={"2.7.1.4", "2.7.4"})
public void testScopeIsNotSupported()
{
createSimpleBean(Carp.class);
}
+ // TODO Stereotype inheritance tests
+
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Grayling.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Grayling.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Grayling.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.test.beans;
+
+import org.jboss.webbeans.test.annotations.FishStereotype;
+import org.jboss.webbeans.test.annotations.RiverFishStereotype;
+
+
+@RiverFishStereotype
+@FishStereotype
+public class Grayling implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Grayling.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Minnow.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Minnow.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Minnow.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -0,0 +1,12 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.RequestScoped;
+
+import org.jboss.webbeans.test.annotations.RiverFishStereotype;
+
+@RiverFishStereotype
+@RequestScoped
+public class Minnow implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Minnow.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Pollock.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Pollock.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Pollock.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -0,0 +1,14 @@
+package org.jboss.webbeans.test.beans;
+
+import javax.webbeans.Dependent;
+
+import org.jboss.webbeans.test.annotations.AnimalStereotype;
+import org.jboss.webbeans.test.annotations.FishStereotype;
+
+@AnimalStereotype
+@FishStereotype
+@Dependent
+public class Pollock implements Animal
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Pollock.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Spider.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Spider.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/Spider.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -3,4 +3,9 @@
public class Spider implements Animal
{
+ public final void layEggs()
+ {
+
+ }
+
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-12-07 15:27:01 UTC (rev 434)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/SpiderProducer.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -3,6 +3,7 @@
import javax.webbeans.Dependent;
import javax.webbeans.Named;
import javax.webbeans.Produces;
+import javax.webbeans.Production;
import javax.webbeans.RequestScoped;
import org.jboss.webbeans.test.annotations.AnimalStereotype;
@@ -40,7 +41,7 @@
return new DaddyLongLegs();
}
- @Produces @Named @AnotherDeploymentType public LadybirdSpider getLadybirdSpider()
+ @Produces @Named @Production public LadybirdSpider getLadybirdSpider()
{
return new LadybirdSpider();
}
Added: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Scallop.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Scallop.java (rev 0)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Scallop.java 2008-12-07 15:43:13 UTC (rev 435)
@@ -0,0 +1,11 @@
+package org.jboss.webbeans.test.beans.broken;
+
+import org.jboss.webbeans.test.annotations.AnimalStereotype;
+import org.jboss.webbeans.test.annotations.FishStereotype;
+
+@AnimalStereotype
+@FishStereotype
+public class Scallop
+{
+
+}
Property changes on: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/beans/broken/Scallop.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years
[webbeans-commits] Webbeans SVN: r434 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/event and 3 other directories.
by webbeans-commits@lists.jboss.org
Author: dallen6
Date: 2008-12-07 10:27:01 -0500 (Sun, 07 Dec 2008)
New Revision: 434
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Role.java
Log:
Some new tests added and functionality for detection of errors related to events and observers.
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-07 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -365,9 +365,18 @@
{
throw new IllegalArgumentException("Event type " + event.getClass().getName() + " is not allowed because it is a generic");
}
+ // Also check that the binding types are truly binding types
+ for (Annotation binding : bindings)
+ {
+ if (!Reflections.isBindingType(binding))
+ {
+ throw new IllegalArgumentException("Event type " + event.getClass().getName() + " cannot be fired with non-binding type " + binding.getClass().getName() + " specified");
+ }
+ }
+
// Get the observers for this event. Although resolveObservers is
- // parameterized, this
- // method is not, so we have to use Observer<Object> for observers.
+ // parameterized, this method is not, so we have to use
+ // Observer<Object> for observers.
Set<Observer<Object>> observers = this.resolveObservers(event, bindings);
this.eventManager.notifyObservers(observers, event);
}
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-07 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventImpl.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -21,13 +21,14 @@
import java.util.HashSet;
import java.util.Set;
-import javax.webbeans.BindingType;
import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.Observable;
import javax.webbeans.Observer;
import org.jboss.webbeans.ManagerImpl;
+import org.jboss.webbeans.util.Reflections;
+import org.jboss.webbeans.util.Strings;
/**
* Implementation of the Event interface
@@ -71,7 +72,7 @@
Set<Annotation> result = new HashSet<Annotation>();
for (Annotation annotation : annotations)
{
- if (!annotation.annotationType().isAnnotationPresent(BindingType.class))
+ if (!Reflections.isBindingType(annotation))
{
throw new IllegalArgumentException(annotation + " is not a binding type");
}
@@ -84,7 +85,7 @@
}
/**
- * Validates the binding types and checks for dupes
+ * 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
@@ -94,16 +95,13 @@
Set<Annotation> result = new HashSet<Annotation>();
for (Annotation annotation : annotations)
{
- if (!annotation.annotationType().isAnnotationPresent(BindingType.class))
+ if (!Reflections.isBindingType(annotation))
{
- throw new IllegalArgumentException(annotation + " is not a binding type");
+ throw new IllegalArgumentException(annotation + " is not a binding type for " + this);
}
- for (Annotation bindingAnnotation : this.bindingTypes)
+ if (result.contains(annotation) || this.bindingTypes.contains(annotation))
{
- if (bindingAnnotation.annotationType().equals(annotation.annotationType()))
- {
- throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list");
- }
+ throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list for " + this);
}
result.add(annotation);
}
@@ -136,4 +134,14 @@
manager.addObserver(observer, eventType, bindingParameters.toArray(new Annotation[0]));
}
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("Observable Event:\n");
+ buffer.append(" Event Type: " + eventType.getName() +"\n");
+ buffer.append(Strings.collectionToString(" Event Bindings: ", bindingTypes));
+ return buffer.toString();
+ }
+
}
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 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/event/EventObserver.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -19,11 +19,15 @@
import java.lang.annotation.Annotation;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
+import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Observer;
import org.jboss.webbeans.MetaDataCache;
+import org.jboss.webbeans.util.Reflections;
import org.jboss.webbeans.util.Strings;
/**
@@ -58,9 +62,34 @@
this.observer = observer;
this.eventType = eventType;
this.eventBindings = Arrays.asList(eventBindings);
+ checkEventBindings(eventBindings);
}
/**
+ * 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
+ */
+ private void checkEventBindings(Annotation[] observerEventBindings)
+ {
+ Set<Annotation> checkedBindings = new HashSet<Annotation>();
+ for (Annotation annotation : observerEventBindings)
+ {
+ if (!Reflections.isBindingType(annotation))
+ {
+ throw new IllegalArgumentException(annotation + " is not a binding type for " + this);
+ }
+ if (checkedBindings.contains(annotation))
+ {
+ throw new DuplicateBindingTypeException(annotation + " is already present in the bindings list for " + this);
+ }
+ checkedBindings.add(annotation);
+ }
+ }
+
+ /**
* @return the eventType
*/
public final Class<T> getEventType()
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-07 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/util/Reflections.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.Set;
+import javax.webbeans.BindingType;
import javax.webbeans.ExecutionException;
/**
@@ -532,4 +533,20 @@
return classes;
}
+ /**
+ * Checks the bindingType to make sure the annotation was declared properly
+ * as a binding type (annotated with @BindingType).
+ *
+ * @param bindingType The binding type to check
+ * @return true only if the annotation is really a binding type
+ */
+ public static boolean isBindingType(Annotation bindingType)
+ {
+ boolean isBindingAnnotation = false;
+ if (bindingType.annotationType().isAnnotationPresent(BindingType.class))
+ {
+ isBindingAnnotation = true;
+ }
+ return isBindingAnnotation;
+ }
}
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 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NewEventTest.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -3,6 +3,7 @@
import java.lang.annotation.Annotation;
import java.util.Set;
+import javax.webbeans.DuplicateBindingTypeException;
import javax.webbeans.Event;
import javax.webbeans.Observer;
import javax.webbeans.TypeLiteral;
@@ -10,7 +11,9 @@
import org.jboss.webbeans.bean.EventBean;
import org.jboss.webbeans.bean.SimpleBean;
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.util.BeanFactory;
import org.testng.annotations.Test;
@@ -27,6 +30,10 @@
{
}
+ public static class ATemplatedEventType<T>
+ {
+ }
+
public static class AnObserver implements Observer<AnEventType>
{
@@ -37,13 +44,13 @@
}
@SuppressWarnings("unchecked")
- @Test
- public void create() {
+ @Test(groups="events")
+ public void testEventBeanCreation() {
SimpleBean<MyTest> myTestBean = BeanFactory.createSimpleBean(MyTest.class);
for (AnnotatedField<Object> field : myTestBean.getEventFields()) {
EventBean eventBean = BeanFactory.createEventBean(field);
- @SuppressWarnings("unused")
Event<Param> event = eventBean.create();
+ assert event != null;
}
}
@@ -56,32 +63,73 @@
@Test(groups={"stub", "events"})
@SpecAssertion(section="7.1")
- public void testEventObjectWithTypeVariablesFails()
+ public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
{
assert false;
}
-
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.1")
- public void testEventObjectWithWildcardsFails()
+
+ @Test(groups={"events"})
+ @SpecAssertion(section="7.2")
+ public void testManagerFireEvent()
{
- assert false;
+ // First a simple event with no bindings is fired
+ AnEventType anEvent = new AnEventType();
+ manager.fireEvent(anEvent);
+
+ // Next an event with some event bindings is fired
+ manager.fireEvent(anEvent, new RoleBinding("Admin"));
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.1")
- public void testConsumerNotifiedWhenEventTypeAndAllBindingsMatch()
+ @Test(groups={"events"})
+ @SpecAssertion(section="7.1,7.2")
+ public void testManagerFireEventWithParametersFails()
{
- assert false;
+ 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.
+ fireEventFailed = false;
+ try
+ {
+ ATemplatedEventType<?> anEventOnAnyType = new ATemplatedEventType<String>();
+ manager.fireEvent(anEventOnAnyType);
+ }
+ catch (IllegalArgumentException e)
+ {
+ fireEventFailed = true;
+ }
+ assert fireEventFailed;
}
- @Test(groups={"stub", "events"})
- @SpecAssertion(section="7.2")
- public void testManagerFireEvent()
+ @Test(groups={"events"})
+ @SpecAssertion(section="7.1,7.2")
+ public void testManagerFireEventWithNonBindingAnnotationsFails()
{
- assert false;
+ // 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;
}
-
+
@Test(groups={"events"})
@SpecAssertion(section="7.3")
public void testManagerAddObserver()
@@ -161,18 +209,39 @@
assert resolvedObservers.isEmpty();
}
- @Test(groups={"stub", "events"})
+ @Test(groups={"events"})
@SpecAssertion(section="7.3")
public void testMultipleInstancesOfSameBindingTypeWhenAddingObserverFails()
{
- assert false;
+ 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={"stub", "events"})
+ @Test(groups={"events"})
@SpecAssertion(section="7.3")
public void testMultipleInstancesOfSameBindingTypeWhenRemovingObserverFails()
{
- assert false;
+ 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;
}
@Test(groups={"stub", "events"})
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Role.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Role.java 2008-12-07 14:32:47 UTC (rev 433)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/annotations/Role.java 2008-12-07 15:27:01 UTC (rev 434)
@@ -1,5 +1,8 @@
package org.jboss.webbeans.test.annotations;
+import javax.webbeans.BindingType;
+
+@BindingType
public @interface Role
{
String value();
16 years