GERONIMO-6553 add new CDI-2.0 features
* async observers.
* prioritized elements
* configuration builders
* native literals
* Java 8 compatibility with bundles
* code style cleanup
txs to John Ament (apacheId: johndament) for the patch!
git-svn-id: https://svn.apache.org/repos/asf/geronimo/specs/trunk@1754981 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/geronimo-jcdi_2.0_spec/pom.xml b/geronimo-jcdi_2.0_spec/pom.xml
index be97dc4..3747437 100644
--- a/geronimo-jcdi_2.0_spec/pom.xml
+++ b/geronimo-jcdi_2.0_spec/pom.xml
@@ -102,7 +102,7 @@
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
- <version>2.0.1</version>
+ <version>3.0.1</version>
<configuration>
<instructions>
<Export-Package>
@@ -115,6 +115,13 @@
</instructions>
</configuration>
</plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
</plugins>
</build>
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Any.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Any.java
index d86a882..342b194 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Any.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Any.java
@@ -28,6 +28,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
/**
@@ -41,5 +42,11 @@
@Qualifier
public @interface Any
{
+ final class Literal extends AnnotationLiteral<Any> implements Any {
+ public static final Literal INSTANCE = new Literal();
+
+ private static final long serialVersionUID = 1L;
+
+ }
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Default.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Default.java
index ae58367..1ad6104 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Default.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/Default.java
@@ -28,6 +28,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
+import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
/**
@@ -41,5 +42,11 @@
@Qualifier
public @interface Default
{
+ final class Literal extends AnnotationLiteral<Default> implements Default {
+ public static final Literal INSTANCE = new Literal();
+
+ private static final long serialVersionUID = 1L;
+
+ }
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterBeanDiscovery.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterBeanDiscovery.java
index c93ac09..da0c10a 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterBeanDiscovery.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterBeanDiscovery.java
@@ -19,6 +19,8 @@
package javax.enterprise.inject.spi;
import javax.enterprise.context.spi.Context;
+import javax.enterprise.inject.spi.builder.BeanConfigurator;
+import javax.enterprise.inject.spi.builder.ObserverMethodConfigurator;
/**
* Events that are fired after discovery bean process.
@@ -34,28 +36,28 @@
*
* @param t throwable
*/
- public void addDefinitionError(Throwable t);
+ void addDefinitionError(Throwable t);
/**
* Registering the bean with container.
*
* @param bean new bean
*/
- public void addBean(Bean<?> bean);
+ void addBean(Bean<?> bean);
/**
* Registers the given observer method with container.
*
* @param observerMethod observer method
*/
- public void addObserverMethod(ObserverMethod<?> observerMethod);
+ void addObserverMethod(ObserverMethod<?> observerMethod);
/**
* Adds given context to the container.
*
* @param context new context
*/
- public void addContext(Context context);
+ void addContext(Context context);
/**
* This will return the AnnotatedType including all changes applied by CDI Extensions.
@@ -66,7 +68,7 @@
* @param <T>
* @return the AnnotatedType for the given type and id.
*/
- public <T> AnnotatedType<T> getAnnotatedType(Class<T> type, String id);
+ <T> AnnotatedType<T> getAnnotatedType(Class<T> type, String id);
/**
* Get an Iterable of all AnnotatedTypes which implement the given
@@ -74,5 +76,31 @@
* @param <T>
* @return
*/
- public <T> Iterable<AnnotatedType<T>> getAnnotatedTypes(Class<T> type);
+ <T> Iterable<AnnotatedType<T>> getAnnotatedTypes(Class<T> type);
+
+ /**
+ * Creates a bean configurator to configure a new bean.
+ *
+ * A ProcessBean is fired once the bean has been built.
+ *
+ * The bean configurator created is meant as a one time use object. Invoke this method to create new ones.
+ *
+ * @param <T>
+ * @throws IllegalStateException if used outside of the observer method's invocation
+ * @return
+ */
+ <T> BeanConfigurator<T> addBean();
+
+ /**
+ * Creates an observer method configurator to define an observer method.
+ *
+ * A ProcessObserverMethod is invoked once the observer method is built.
+ *
+ * The observer method configurator created is meant as a one time use object. Invoke this method to create new ones.
+ *
+ * @param <T>
+ * @throws IllegalStateException if used outside of the observer method's invocation
+ * @return
+ */
+ <T> ObserverMethodConfigurator<T> addObserverMethod();
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterTypeDiscovery.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterTypeDiscovery.java
index 8869462..124b4aa 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterTypeDiscovery.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AfterTypeDiscovery.java
@@ -18,6 +18,7 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.AnnotatedTypeConfigurator;
import java.util.List;
/**
@@ -34,7 +35,7 @@
* BeanArchive are not included in this list.
* @return the ordered, mutable List of enabled {@link javax.enterprise.inject.Alternative}s
*/
- public List<Class<?>> getAlternatives();
+ List<Class<?>> getAlternatives();
/**
* This method can be used to remove and add enabled CDI Interceptors,
@@ -43,7 +44,7 @@
* @return the ordered, mutable List of Classes which are annotated with {@link Interceptor}
* and globally enabled.
*/
- public List<Class<?>> getInterceptors();
+ List<Class<?>> getInterceptors();
/**
* This method can be used to remove and add enabled Decorators,
@@ -52,7 +53,7 @@
* @return the ordered, mutable List of Classes which are annotated with {@link Decorator}
* and globally enabled.
*/
- public List<Class<?>> getDecorators();
+ List<Class<?>> getDecorators();
/**
* Allows to a synthetic annotated type.
@@ -72,5 +73,15 @@
* @see AfterBeanDiscovery#getAnnotatedTypes(Class)
*
*/
- public void addAnnotatedType(AnnotatedType<?> type, String id);
+ void addAnnotatedType(AnnotatedType<?> type, String id);
+
+ /**
+ * Returns a new annotated type configurator based on a new bean id and bean class.
+ *
+ * @param id of the annotated type
+ * @param clazz
+ * @param <T>
+ * @return
+ */
+ <T> AnnotatedTypeConfigurator<T> addAnnotatedType(String id, Class<T> clazz);
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AnnotatedType.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AnnotatedType.java
index d432411..8978fad 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AnnotatedType.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/AnnotatedType.java
@@ -18,6 +18,7 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.AnnotatedTypeConfigurator;
import java.util.Set;
/**
@@ -32,26 +33,32 @@
*
* @return class of bean
*/
- public Class<X> getJavaClass();
+ Class<X> getJavaClass();
/**
* Returns set of bean constructors.
*
* @return set of constructors
*/
- public Set<AnnotatedConstructor<X>> getConstructors();
+ Set<AnnotatedConstructor<X>> getConstructors();
/**
* Returns set of bean methods.
*
* @return set of bean methods
*/
- public Set<AnnotatedMethod<? super X>> getMethods();
+ Set<AnnotatedMethod<? super X>> getMethods();
/**
* Returns set of bean fields.
*
* @return set of bean fields.
*/
- public Set<AnnotatedField<? super X>> getFields();
+ Set<AnnotatedField<? super X>> getFields();
+
+ /**
+ * Creates a configurator to configure this annotated type.
+ * @return
+ */
+ AnnotatedTypeConfigurator<X> configureAnnotatedType();
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/BeforeBeanDiscovery.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/BeforeBeanDiscovery.java
index 14f1c60..dcf232f 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/BeforeBeanDiscovery.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/BeforeBeanDiscovery.java
@@ -18,6 +18,7 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.AnnotatedTypeConfigurator;
import java.lang.annotation.Annotation;
/**
@@ -34,13 +35,13 @@
*
* @param qualifier qualifier
*/
- public void addQualifier(Class<? extends Annotation> qualifier);
+ void addQualifier(Class<? extends Annotation> qualifier);
/**
* Declare a new qualifier via the information from the given AnnotatedType.
* @param qualifier
*/
- public void addQualifier(AnnotatedType<? extends Annotation> qualifier);
+ void addQualifier(AnnotatedType<? extends Annotation> qualifier);
/**
@@ -50,7 +51,7 @@
* @param normal is normal or not
* @param passivating passivated or not
*/
- public void addScope(Class<? extends Annotation> scope, boolean normal, boolean passivating);
+ void addScope(Class<? extends Annotation> scope, boolean normal, boolean passivating);
/**
* Declares a new stereotype.
@@ -58,7 +59,7 @@
* @param stereotype stereotype class
* @param stereotypeDef meta annotations
*/
- public void addStereotype(Class<? extends Annotation> stereotype, Annotation... stereotypeDef);
+ void addStereotype(Class<? extends Annotation> stereotype, Annotation... stereotypeDef);
/**
* Declares a new interceptor binding.
@@ -66,13 +67,13 @@
* @param binding binding class
* @param bindingDef meta annotations
*/
- public void addInterceptorBinding(Class<? extends Annotation> binding, Annotation... bindingDef);
+ void addInterceptorBinding(Class<? extends Annotation> binding, Annotation... bindingDef);
/**
* Declare a new interceptor binding via the information from the given AnnotatedType.
* @param bindingType
*/
- public void addInterceptorBinding(AnnotatedType<? extends Annotation> bindingType);
+ void addInterceptorBinding(AnnotatedType<? extends Annotation> bindingType);
/**
* Adds new annotated type.
@@ -81,7 +82,7 @@
*
* @param type annotated type
*/
- public void addAnnotatedType(AnnotatedType<?> type);
+ void addAnnotatedType(AnnotatedType<?> type);
/**
* Adds new annotated type for classes which are not picked up by the CDI container
@@ -90,5 +91,15 @@
* @param type annotated type
* @param id to distinguish AnnotatedTypes for the same class.
*/
- public void addAnnotatedType(AnnotatedType<?> type, String id);
+ void addAnnotatedType(AnnotatedType<?> type, String id);
+
+ /**
+ * Returns a new annotated type configurator based on a new bean id and bean class.
+ *
+ * @param id of the annotated type
+ * @param clazz
+ * @param <T>
+ * @return
+ */
+ <T> AnnotatedTypeConfigurator<T> addAnnotatedType(String id, Class<T> clazz);
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ObserverMethod.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ObserverMethod.java
index 27c6ed1..0814b7d 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ObserverMethod.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ObserverMethod.java
@@ -65,34 +65,41 @@
*/
public interface ObserverMethod<T>
{
- public Class<?> getBeanClass();
+ Class<?> getBeanClass();
/**
* @return the type of the observed event
*/
- public Type getObservedType();
+ Type getObservedType();
/**
* @return the defined Qualifiers plus {@code javax.enterprise.inject.Any}
*/
- public Set<Annotation> getObservedQualifiers();
+ Set<Annotation> getObservedQualifiers();
/**
* @return either {@code Reception#IF_EXISTS} if the observed method must only be called if an instance
* of the bean which defines the observer method aready exists in the specified context or {@code Reception#ALWAYS}.
*/
- public Reception getReception();
+ Reception getReception();
/**
* @return the appropriate {@code TransactionPhase} for a transactional observer method or
* {@code TransactionPhase#IN_PROGRESS} otherwise.
*/
- public TransactionPhase getTransactionPhase();
+ TransactionPhase getTransactionPhase();
/**
* will actually cann the underlying observer method
* @param event
*/
- public void notify(T event);
+ void notify(T event);
+ /**
+ * Whether or not this observer method is an async observer. defaults to false for compatibility
+ * @return
+ */
+ default boolean isAsync() {
+ return false;
+ }
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessBeanAttributes.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessBeanAttributes.java
index ce5d0d1..0a3d682 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessBeanAttributes.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessBeanAttributes.java
@@ -18,6 +18,8 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.BeanAttributesConfigurator;
+
/**
* Each {@link AnnotatedType} gets scanned by the CDI container and turned
* into initial {@link BeanAttributes}. Those BeanAttributes can be modified
@@ -31,23 +33,23 @@
* @return the {@link AnnotatedType} for bean classes, {@link AnnotatedMethod} for producer methods and
* {@link AnnotatedField} for producer fields.
*/
- public Annotated getAnnotated();
+ Annotated getAnnotated();
/**
* @return the BeanAttributes parsed from the {@link Annotated}
*/
- public BeanAttributes<T> getBeanAttributes();
+ BeanAttributes<T> getBeanAttributes();
/**
* Use the given BeanAttributes to later create the {@link Bean} from it.
* @param beanAttributes
*/
- public void setBeanAttributes(BeanAttributes<T> beanAttributes);
+ void setBeanAttributes(BeanAttributes<T> beanAttributes);
/**
* Tell the container it should ignore this Bean.
*/
- public void veto();
+ void veto();
/**
* Adding definition error. Container aborts
@@ -55,5 +57,12 @@
*
* @param t throwable
*/
- public void addDefinitionError(Throwable t);
+ void addDefinitionError(Throwable t);
+
+ /**
+ * Creates a bean attributes configurator to configure this bean's attributes.
+ *
+ * @return
+ */
+ BeanAttributesConfigurator<T> configureBeanAttributes();
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessInjectionPoint.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessInjectionPoint.java
index c4272c4..80ca90c 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessInjectionPoint.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessInjectionPoint.java
@@ -18,6 +18,8 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.InjectionPointConfigurator;
+
/**
* Gets fired for each InjectionPoint.
*
@@ -29,13 +31,13 @@
/**
* @return the InjectionPoint created from originally parsing the AnnotatedType.
*/
- public InjectionPoint getInjectionPoint();
+ InjectionPoint getInjectionPoint();
/**
* Replace the original InjectionPoint point with the given one.
* @param injectionPoint
*/
- public void setInjectionPoint(InjectionPoint injectionPoint);
+ void setInjectionPoint(InjectionPoint injectionPoint);
/**
* Adding definition error. Container aborts
@@ -43,5 +45,12 @@
*
* @param t throwable
*/
- public void addDefinitionError(Throwable t);
+ void addDefinitionError(Throwable t);
+
+ /**
+ * Creates a new configurator for this injection point.
+ *
+ * @return
+ */
+ InjectionPointConfigurator configureInjectionPoint();
}
diff --git a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessObserverMethod.java b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessObserverMethod.java
index 9fc2f1b..d2db4d9 100644
--- a/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessObserverMethod.java
+++ b/geronimo-jcdi_2.0_spec/src/main/java/javax/enterprise/inject/spi/ProcessObserverMethod.java
@@ -18,6 +18,8 @@
*/
package javax.enterprise.inject.spi;
+import javax.enterprise.inject.spi.builder.ObserverMethodConfigurator;
+
/**
* Fired for each observer.
*
@@ -33,7 +35,7 @@
*
* @return annotated method
*/
- public AnnotatedMethod<X> getAnnotatedMethod();
+ AnnotatedMethod<X> getAnnotatedMethod();
/**
* Returns observer method instance that
@@ -41,13 +43,19 @@
*
* @return observer method instance
*/
- public ObserverMethod<T> getObserverMethod();
+ ObserverMethod<T> getObserverMethod();
/**
* Add throwable.
*
* @param t throwable
*/
- public void addDefinitionError(Throwable t);
+ void addDefinitionError(Throwable t);
+
+ /**
+ * Creates a configurator for this observer method
+ * @return
+ */
+ ObserverMethodConfigurator<T> configureObserverMethod();
}