You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2010/02/13 00:00:57 UTC
svn commit: r909647 [2/2] - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/
main/java/org/apache/webbeans/component/creation/
main/java/org/apache/webbeans/config/
main/java/org/apache/webbeans/container/ main/java/or...
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/WebBeansInterceptorConfig.java Fri Feb 12 23:00:52 2010
@@ -24,11 +24,13 @@
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Interceptor;
import javax.interceptor.AroundInvoke;
import org.apache.webbeans.component.AbstractBean;
-import org.apache.webbeans.component.BaseBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.config.inheritance.IBeanInheritedMetaData;
import org.apache.webbeans.config.OWBLogConst;
import org.apache.webbeans.container.BeanManagerImpl;
@@ -62,7 +64,7 @@
*
* @param interceptorClazz interceptor class
*/
- public static <T> void configureInterceptorClass(AbstractBean<T> delegate, Annotation[] interceptorBindingTypes)
+ public static <T> void configureInterceptorClass(AbstractInjectionTargetBean<T> delegate, Annotation[] interceptorBindingTypes)
{
logger.info(OWBLogConst.INFO_0011, new Object[]{logger.getTokenString(OWBLogConst.TEXT_INTERCEPT_CLASS), delegate.getReturnType()});
@@ -84,17 +86,33 @@
*
* @param clazz configuration interceptors for this
*/
- public static void configure(BaseBean<?> component, List<InterceptorData> stack)
+ public static void configure(AbstractInjectionTargetBean<?> component, List<InterceptorData> stack)
{
- Class<?> clazz = component.getReturnType();
+ Class<?> clazz = ((AbstractBean<?>)component).getReturnType();
+ AnnotatedType<?> annotatedType = component.getAnnotatedType();
+ Set<Annotation> annotations = null;
+
+ if(annotatedType != null)
+ {
+ annotations = annotatedType.getAnnotations();
+ }
+
Set<Interceptor<?>> componentInterceptors = null;
Set<Annotation> bindingTypeSet = new HashSet<Annotation>();
Annotation[] anns = new Annotation[0];
-
- if (AnnotationUtil.hasInterceptorBindingMetaAnnotation(clazz.getDeclaredAnnotations()))
+ Annotation[] typeAnns = null;
+ if(annotations != null)
+ {
+ typeAnns = annotations.toArray(new Annotation[0]);
+ }
+ else
+ {
+ typeAnns = clazz.getDeclaredAnnotations();
+ }
+ if (AnnotationUtil.hasInterceptorBindingMetaAnnotation(typeAnns))
{
- anns = AnnotationUtil.getInterceptorBindingMetaAnnotations(clazz.getDeclaredAnnotations());
+ anns = AnnotationUtil.getInterceptorBindingMetaAnnotations(typeAnns);
for (Annotation ann : anns)
{
@@ -103,7 +121,7 @@
}
//check for stereotypes
- Annotation[] stereoTypes = AnnotationUtil.getStereotypeMetaAnnotations(clazz.getDeclaredAnnotations());
+ Annotation[] stereoTypes = AnnotationUtil.getStereotypeMetaAnnotations(typeAnns);
for (Annotation stero : stereoTypes)
{
if (AnnotationUtil.hasInterceptorBindingMetaAnnotation(stero.annotationType().getDeclaredAnnotations()))
@@ -141,7 +159,15 @@
// Method level interceptors.
- addMethodInterceptors(clazz, stack, componentInterceptors);
+ if(annotatedType == null)
+ {
+ addMethodInterceptors(clazz, stack, componentInterceptors);
+ }
+ else
+ {
+ addMethodInterceptors(annotatedType, stack, componentInterceptors);
+ }
+
Collections.sort(stack, new InterceptorDataComparator());
}
@@ -152,12 +178,22 @@
while (it.hasNext())
{
WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
-
- // interceptor binding
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), AroundInvoke.class, true, false, stack, null, true);
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PostConstruct.class, true, false, stack, null, true);
- WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PreDestroy.class, true, false, stack, null, true);
-
+
+ AnnotatedType<?> annotatedType = null;
+ if((annotatedType = interceptor.getAnnotatedType()) != null)
+ {
+ // interceptor binding
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, AroundInvoke.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, PostConstruct.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, PreDestroy.class, true, false, stack, null, true);
+ }
+ else
+ {
+ // interceptor binding
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), AroundInvoke.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PostConstruct.class, true, false, stack, null, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, interceptor.getClazz(), PreDestroy.class, true, false, stack, null, true);
+ }
}
}
@@ -226,6 +262,75 @@
}
}
+
+ @SuppressWarnings("unchecked")
+ private static <T> void addMethodInterceptors(AnnotatedType<T> annotatedType, List<InterceptorData> stack, Set<Interceptor<?>> componentInterceptors)
+ {
+
+ Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
+ for(AnnotatedMethod<? super T> methodA : methods)
+ {
+ AnnotatedMethod<T> methodB = (AnnotatedMethod<T>)methodA;
+ Method method = methodB.getJavaMember();
+ Set<Annotation> interceptorAnns = new HashSet<Annotation>();
+
+ Annotation[] methodAnns = AnnotationUtil.getAnnotationsFromSet(methodB.getAnnotations());
+ if (AnnotationUtil.hasInterceptorBindingMetaAnnotation(methodAnns))
+ {
+ Annotation[] anns = AnnotationUtil.getInterceptorBindingMetaAnnotations(methodAnns);
+ Annotation[] annsClazz = AnnotationUtil.getInterceptorBindingMetaAnnotations(AnnotationUtil.getAnnotationsFromSet(annotatedType.getAnnotations()));
+
+ for (Annotation ann : anns)
+ {
+ interceptorAnns.add(ann);
+ }
+
+ for (Annotation ann : annsClazz)
+ {
+ interceptorAnns.add(ann);
+ }
+ }
+
+ Annotation[] stereoTypes = AnnotationUtil.getStereotypeMetaAnnotations(AnnotationUtil.getAnnotationsFromSet(annotatedType.getAnnotations()));
+ for (Annotation stero : stereoTypes)
+ {
+ if (AnnotationUtil.hasInterceptorBindingMetaAnnotation(stero.annotationType().getDeclaredAnnotations()))
+ {
+ Annotation[] steroInterceptorBindings = AnnotationUtil.getInterceptorBindingMetaAnnotations(stero.annotationType().getDeclaredAnnotations());
+
+ for (Annotation ann : steroInterceptorBindings)
+ {
+ interceptorAnns.add(ann);
+ }
+ }
+ }
+
+ if (!interceptorAnns.isEmpty())
+ {
+ Annotation[] result = new Annotation[interceptorAnns.size()];
+ result = interceptorAnns.toArray(result);
+
+ Set<Interceptor<?>> setInterceptors = findDeployedWebBeansInterceptor(result);
+
+ if(componentInterceptors != null)
+ {
+ setInterceptors.removeAll(componentInterceptors);
+ }
+
+ Iterator<Interceptor<?>> it = setInterceptors.iterator();
+
+ while (it.hasNext())
+ {
+ WebBeansInterceptor<?> interceptor = (WebBeansInterceptor<?>) it.next();
+
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, AroundInvoke.class, true, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, PostConstruct.class, true, true, stack, method, true);
+ WebBeansUtil.configureInterceptorMethods(interceptor, annotatedType, PreDestroy.class, true, true, stack, method, true);
+ }
+ }
+ }
+
+ }
/**
* Gets the configured webbeans interceptors.
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/webbeans/WebBeansInterceptor.java Fri Feb 12 23:00:52 2010
@@ -26,6 +26,7 @@
import javax.enterprise.context.spi.Context;
import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InterceptionType;
@@ -34,6 +35,7 @@
import javax.interceptor.InvocationContext;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.container.BeanManagerImpl;
@@ -72,9 +74,9 @@
private Class<?> clazz;
/**Delegate Bean*/
- private AbstractBean<T> delegateBean;
+ private AbstractInjectionTargetBean<T> delegateBean;
- public WebBeansInterceptor(AbstractBean<T> delegateBean)
+ public WebBeansInterceptor(AbstractInjectionTargetBean<T> delegateBean)
{
super(WebBeansType.INTERCEPTOR,delegateBean.getReturnType());
@@ -87,6 +89,12 @@
{
return this.delegateBean;
}
+
+ public AnnotatedType<T> getAnnotatedType()
+ {
+ return this.delegateBean.getAnnotatedType();
+ }
+
/**
* Add new binding type to the interceptor.
@@ -454,4 +462,5 @@
{
return this.delegateBean.isAlternative();
}
+
}
\ No newline at end of file
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/DefaultInjectionTargetImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/DefaultInjectionTargetImpl.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/DefaultInjectionTargetImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/creation/DefaultInjectionTargetImpl.java Fri Feb 12 23:00:52 2010
@@ -20,15 +20,15 @@
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
-import org.apache.webbeans.config.ManagedBeanConfigurator;
+import org.apache.webbeans.util.WebBeansAnnotatedTypeUtil;
public class DefaultInjectionTargetImpl<T> implements InjectionTarget<T>
{
private InjectionTargetProducer<T> target;
- private DefaultInjectionTargetImpl(AnnotatedType<T> annotatedType)
+ public DefaultInjectionTargetImpl(AnnotatedType<T> annotatedType)
{
- target = new InjectionTargetProducer<T>(ManagedBeanConfigurator.defineFromAnnotatedType(annotatedType));
+ target = new InjectionTargetProducer<T>(WebBeansAnnotatedTypeUtil.defineManagedBean(annotatedType));
}
@Override
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java Fri Feb 12 23:00:52 2010
@@ -29,6 +29,7 @@
import org.apache.webbeans.annotation.WebBeansAnnotation;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.InjectionTargetBean;
import org.apache.webbeans.decorator.WebBeansDecorator;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.intercept.DependentScopedBeanInterceptorHandler;
@@ -44,7 +45,7 @@
}
- public static Object createNormalScopedBeanProxy(Bean<?> bean, CreationalContext<?> creationalContext)
+ public static Object createNormalScopedBeanProxy(AbstractBean<?> bean, CreationalContext<?> creationalContext)
{
Object result = null;
try
@@ -66,19 +67,27 @@
return result;
}
- public static Object createDependentScopedBeanProxy(Bean<?> bean, Object actualInstance)
+ public static Object createDependentScopedBeanProxy(AbstractBean<?> bean, Object actualInstance)
{
Object result = null;
- List<InterceptorData> interceptors = ((AbstractBean<?>) bean).getInterceptorStack();
- List<Decorator<?>> decorators = ((AbstractBean<?>) bean).getDecorators();
- if(interceptors.isEmpty() && decorators.isEmpty())
+ List<InterceptorData> interceptors = null;
+ List<Decorator<?>> decorators = null;
+ InjectionTargetBean<?> injectionTargetBean = null;
+ if(bean instanceof InjectionTargetBean)
+ {
+ injectionTargetBean = (InjectionTargetBean<?>)bean;
+ interceptors = injectionTargetBean.getInterceptorStack();
+ decorators = injectionTargetBean.getDecoratorStack();
+ }
+
+ if(interceptors == null && decorators == null)
{
return actualInstance;
}
boolean notInInterceptorClassAndLifecycle = false;
- if(!interceptors.isEmpty())
+ if(interceptors != null)
{
Iterator<InterceptorData> its = interceptors.iterator();
while(its.hasNext())
@@ -108,7 +117,7 @@
if (!(bean instanceof WebBeansDecorator) && !(bean instanceof WebBeansInterceptor))
{
- fact.setHandler(new DependentScopedBeanInterceptorHandler((AbstractBean<?>) bean, actualInstance));
+ fact.setHandler(new DependentScopedBeanInterceptorHandler(bean, actualInstance));
}
result = fact.createClass().newInstance();
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java Fri Feb 12 23:00:52 2010
@@ -65,9 +65,14 @@
import org.apache.webbeans.config.OpenWebBeansConfiguration;
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.decorator.DecoratorUtil;
+import org.apache.webbeans.decorator.DecoratorsManager;
+import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
import org.apache.webbeans.event.NotificationManager;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.inject.impl.InjectionPointFactory;
+import org.apache.webbeans.intercept.InterceptorUtil;
+import org.apache.webbeans.intercept.InterceptorsManager;
+import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
import org.apache.webbeans.logger.WebBeansLogger;
public final class WebBeansAnnotatedTypeUtil
@@ -758,8 +763,6 @@
managedBeanCreator.defineProducerFields();
managedBeanCreator.defineInjectedFields();
managedBeanCreator.defineInjectedMethods();
- managedBeanCreator.defineDecoratorStack();
- managedBeanCreator.defineInterceptorStack();
managedBeanCreator.defineObserverMethods();
@@ -769,5 +772,115 @@
return managedBean;
}
+ /**
+ * Return true if this annotated type represents a decorator.
+ * @param annotatedType annotated type
+ * @return true if decorator
+ */
+ public static boolean isAnnotatedTypeDecorator(AnnotatedType<?> annotatedType)
+ {
+ if(annotatedType.isAnnotationPresent(Decorator.class))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Return true if this annotated type represents a decorator.
+ * @param annotatedType annotated type
+ * @return true if decorator
+ */
+ public static boolean isAnnotatedTypeDecoratorOrInterceptor(AnnotatedType<?> annotatedType)
+ {
+ if(isAnnotatedTypeDecorator(annotatedType) ||
+ isAnnotatedTypeInterceptor(annotatedType))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Return true if this annotated type represents a decorator.
+ * @param annotatedType annotated type
+ * @return true if decorator
+ */
+ public static boolean isAnnotatedTypeInterceptor(AnnotatedType<?> annotatedType)
+ {
+ if(annotatedType.isAnnotationPresent(Interceptor.class))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+
+ /**
+ * Define decorator bean.
+ * @param <T> type info
+ * @param clazz decorator class
+ */
+ public static <T> void defineDecorator(AnnotatedType<T> annotatedType)
+ {
+ if (DecoratorsManager.getInstance().isDecoratorEnabled(annotatedType.getJavaClass()))
+ {
+ ManagedBean<T> delegate = null;
+
+ Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
+ for(AnnotatedMethod<? super T> methodA : methods)
+ {
+ Method method = methodA.getJavaMember();
+ if(AnnotationUtil.hasMethodAnnotation(method, Produces.class))
+ {
+ throw new WebBeansConfigurationException("Decorator class : " + annotatedType.getJavaClass() + " can not have producer methods but it has one with name : " + method.getName());
+ }
+
+ if(AnnotationUtil.hasMethodParameterAnnotation(method, Observes.class))
+ {
+ throw new WebBeansConfigurationException("Decorator class : " + annotatedType.getJavaClass() + " can not have observer methods but it has one with name : " + method.getName());
+ }
+
+ }
+
+ delegate = defineManagedBean(annotatedType);
+
+ if (delegate != null)
+ {
+ WebBeansDecoratorConfig.configureDecoratorClass(delegate);
+ }
+ else
+ {
+ logger.trace("Unable to configure decorator with class : " + annotatedType.getJavaClass());
+ }
+ }
+ }
+
+ public static <T> void defineInterceptor(AnnotatedType<T> annotatedType)
+ {
+ Class<?> clazz = annotatedType.getJavaClass();
+ if (InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
+ {
+ ManagedBean<T> delegate = null;
+
+ InterceptorUtil.checkAnnotatedTypeInterceptorConditions(annotatedType);
+ delegate = defineManagedBean(annotatedType);
+
+ if (delegate != null)
+ {
+ WebBeansInterceptorConfig.configureInterceptorClass(delegate,
+ AnnotationUtil.getInterceptorBindingMetaAnnotations(annotatedType.getAnnotations().toArray(new Annotation[0])));
+ }
+ else
+ {
+ logger.trace("Unable to configure interceptor with class : " + annotatedType.getJavaClass());
+ }
+ }
+
+ }
}
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Fri Feb 12 23:00:52 2010
@@ -30,6 +30,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -62,6 +63,7 @@
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -81,6 +83,7 @@
import javax.enterprise.inject.spi.ProcessProducerField;
import javax.enterprise.inject.spi.ProcessProducerMethod;
import javax.enterprise.inject.spi.ProcessSessionBean;
+import javax.enterprise.inject.spi.Producer;
import javax.enterprise.util.TypeLiteral;
import javax.inject.Inject;
import javax.inject.Named;
@@ -112,9 +115,11 @@
import org.apache.webbeans.component.ProducerFieldBean;
import org.apache.webbeans.component.ProducerMethodBean;
import org.apache.webbeans.component.WebBeansType;
+import org.apache.webbeans.component.creation.ManagedBeanCreatorImpl;
import org.apache.webbeans.config.DefinitionUtil;
import org.apache.webbeans.config.EJBWebBeansConfigurator;
import org.apache.webbeans.config.ManagedBeanConfigurator;
+import org.apache.webbeans.config.OWBLogConst;
import org.apache.webbeans.container.BeanManagerImpl;
import org.apache.webbeans.container.ExternalScope;
import org.apache.webbeans.context.creational.CreationalContextImpl;
@@ -122,6 +127,7 @@
import org.apache.webbeans.decorator.DecoratorUtil;
import org.apache.webbeans.decorator.DecoratorsManager;
import org.apache.webbeans.decorator.WebBeansDecoratorConfig;
+import org.apache.webbeans.event.ObserverMethodImpl;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.exception.WebBeansException;
import org.apache.webbeans.exception.WebBeansPassivationException;
@@ -135,10 +141,14 @@
import org.apache.webbeans.intercept.InterceptorUtil;
import org.apache.webbeans.intercept.InterceptorsManager;
import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
+import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.plugins.OpenWebBeansPlugin;
import org.apache.webbeans.plugins.PluginLoader;
import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.portable.creation.InjectionTargetProducer;
+import org.apache.webbeans.portable.events.ProcessBeanImpl;
+import org.apache.webbeans.portable.events.ProcessInjectionTargetImpl;
+import org.apache.webbeans.portable.events.ProcessProducerImpl;
import org.apache.webbeans.portable.events.discovery.ErrorStack;
import org.apache.webbeans.portable.events.generics.GProcessAnnotatedType;
import org.apache.webbeans.portable.events.generics.GProcessBean;
@@ -158,6 +168,8 @@
@SuppressWarnings("unchecked")
public final class WebBeansUtil
{
+ private static final WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansUtil.class);
+
// No instantiate
private WebBeansUtil()
{
@@ -874,6 +886,82 @@
return result;
}
+
+ public static <T> Method checkCommonAnnotationCriterias(AnnotatedType<T> annotatedType, Class<? extends Annotation> commonAnnotation, boolean invocationContext)
+ {
+ Class<?> clazz = annotatedType.getJavaClass();
+
+ Method result = null;
+ boolean found = false;
+ Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
+ for(AnnotatedMethod<? super T> methodA : methods)
+ {
+ AnnotatedMethod<T> methodB = (AnnotatedMethod<T>)methodA;
+ Method method = methodB.getJavaMember();
+ if (method.isAnnotationPresent(commonAnnotation))
+ {
+ if (ClassUtil.isMoreThanOneMethodWithName(method.getName(), clazz))
+ {
+ continue;
+ }
+
+ if (found == true)
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotation is declared more than one method in the class : " + clazz.getName());
+ }
+ else
+ {
+ found = true;
+ result = method;
+
+ // Check method criterias
+ if (methodB.getParameters().isEmpty())
+ {
+ if (!invocationContext)
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not take any formal arguments");
+ }
+ else
+ {
+ List<AnnotatedParameter<T>> parameters = methodB.getParameters();
+ List<Class<?>> clazzParameters = new ArrayList<Class<?>>();
+ for(AnnotatedParameter<T> parameter : parameters)
+ {
+ clazzParameters.add(ClassUtil.getClazz(parameter.getBaseType()));
+ }
+
+ Class<?>[] params = clazzParameters.toArray(new Class<?>[0]);
+ if (params.length != 1 || !params[0].equals(InvocationContext.class))
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not take any formal arguments other than InvocationContext");
+ }
+ }
+ else if(invocationContext)
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " must take a parameter with class type javax.interceptor.InvocationContext.");
+ }
+
+ if (!ClassUtil.getReturnType(method).equals(Void.TYPE))
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " must return void type");
+ }
+
+ if (ClassUtil.isMethodHasCheckedException(method))
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not throw any checked exception");
+ }
+
+ if (ClassUtil.isStatic(method.getModifiers()))
+ {
+ throw new WebBeansConfigurationException("@" + commonAnnotation.getSimpleName() + " annotated method : " + method.getName() + " in class : " + clazz.getName() + " can not be static");
+ }
+ }
+ }
+
+ }
+
+
+ return result;
+ }
/**
* Check the {@link AroundInvoke} annotated method criterias, and return
@@ -938,6 +1026,66 @@
return result;
}
+
+ public static <T> Method checkAroundInvokeAnnotationCriterias(AnnotatedType<T> annotatedType)
+ {
+ Method result = null;
+ boolean found = false;
+ Set<AnnotatedMethod<? super T>> methods = annotatedType.getMethods();
+ for(AnnotatedMethod<? super T> methodA : methods)
+ {
+ AnnotatedMethod<T> method = (AnnotatedMethod<T>)methodA;
+
+ if (method.isAnnotationPresent(AroundInvoke.class))
+ {
+ // Overriden methods
+ if (ClassUtil.isMoreThanOneMethodWithName(method.getJavaMember().getName(), annotatedType.getJavaClass()))
+ {
+ continue;
+ }
+
+ if (found == true)
+ {
+ throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotation is declared more than one method in the class : " + annotatedType.getJavaClass().getName());
+ }
+ else
+ {
+ found = true;
+ result = method.getJavaMember();
+
+ List<AnnotatedParameter<T>> parameters = method.getParameters();
+ List<Class<?>> clazzParameters = new ArrayList<Class<?>>();
+ for(AnnotatedParameter<T> parameter : parameters)
+ {
+ clazzParameters.add(ClassUtil.getClazz(parameter.getBaseType()));
+ }
+
+ Class<?>[] params = clazzParameters.toArray(new Class<?>[0]);
+
+ if (params.length != 1 || !params[0].equals(InvocationContext.class))
+ throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getJavaMember().getName() + " in class : " + annotatedType.getJavaClass().getName() + " can not take any formal arguments other than InvocationContext");
+
+ if (!ClassUtil.getReturnType(method.getJavaMember()).equals(Object.class))
+ {
+ throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getJavaMember().getName()+ " in class : " + annotatedType.getJavaClass().getName() + " must return Object type");
+ }
+
+ if (!ClassUtil.isMethodHasException(method.getJavaMember()))
+ {
+ throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getJavaMember().getName( )+ " in class : " + annotatedType.getJavaClass().getName() + " must throw Exception");
+ }
+
+ if (ClassUtil.isStatic(method.getJavaMember().getModifiers()) || ClassUtil.isFinal(method.getJavaMember().getModifiers()))
+ {
+ throw new WebBeansConfigurationException("@" + AroundInvoke.class.getSimpleName() + " annotated method : " + method.getJavaMember().getName( )+ " in class : " + annotatedType.getJavaClass().getName() + " can not be static or final");
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
/**
* Configures the interceptor stack of the web beans component.
@@ -1020,6 +1168,73 @@
stack.add(intData);
}
}
+
+
+ public static <T> void configureInterceptorMethods(Interceptor<?> webBeansInterceptor, AnnotatedType<T> annotatedType, Class<? extends Annotation> annotation, boolean definedInInterceptorClass, boolean definedInMethod, List<InterceptorData> stack, Method annotatedInterceptorClassMethod, boolean isDefinedWithWebBeans)
+ {
+ InterceptorData intData = null;
+ Method method = null;
+
+ if (annotation.equals(AroundInvoke.class))
+ {
+ method = WebBeansUtil.checkAroundInvokeAnnotationCriterias(annotatedType);
+ }
+ else if (annotation.equals(PostConstruct.class))
+ {
+ if (definedInInterceptorClass)
+ {
+ method = WebBeansUtil.checkCommonAnnotationCriterias(annotatedType, PostConstruct.class, true);
+ }
+ else
+ {
+ method = WebBeansUtil.checkCommonAnnotationCriterias(annotatedType, PostConstruct.class, false);
+ }
+ }
+ else if (annotation.equals(PreDestroy.class))
+ {
+ if (definedInInterceptorClass)
+ {
+ method = WebBeansUtil.checkCommonAnnotationCriterias(annotatedType, PreDestroy.class, true);
+ }
+ else
+ {
+ method = WebBeansUtil.checkCommonAnnotationCriterias(annotatedType, PreDestroy.class, false);
+ }
+ }
+
+ if (method != null)
+ {
+ intData = new InterceptorDataImpl(isDefinedWithWebBeans);
+ intData.setDefinedInInterceptorClass(definedInInterceptorClass);
+ intData.setDefinedInMethod(definedInMethod);
+ intData.setAnnotatedMethod(annotatedInterceptorClassMethod);
+ intData.setWebBeansInterceptor(webBeansInterceptor);
+
+ if (definedInInterceptorClass)
+ {
+ try
+ {
+ if (!isDefinedWithWebBeans)
+ {
+ intData.setInterceptorInstance(newInstanceForced(annotatedType.getJavaClass()));
+ }
+ }
+ catch (WebBeansConfigurationException e1)
+ {
+ throw e1;
+ }
+ catch (Exception e)
+ {
+ throw new WebBeansException(e);
+ }
+ }
+
+ intData.setInterceptor(method, annotation);
+
+ stack.add(intData);
+ }
+ }
+
/**
* Create a new instance of the given class using it's default constructor
@@ -1772,14 +1987,15 @@
}
- public static <T> void defineInterceptors(Class<T> clazz)
+ public static <T> void defineInterceptor(ManagedBeanCreatorImpl<T> managedBeanCreator, AnnotatedType<T> annotatedType)
{
+ Class<?> clazz = annotatedType.getJavaClass();
if (InterceptorsManager.getInstance().isInterceptorEnabled(clazz))
{
ManagedBean<T> component = null;
InterceptorUtil.checkInterceptorConditions(clazz);
- component = ManagedBeanConfigurator.define(clazz, WebBeansType.INTERCEPTOR);
+ component = defineManagedBean(managedBeanCreator, annotatedType);
if (component != null)
{
@@ -1791,18 +2007,28 @@
}
- public static <T> void defineDecorators(Class<T> clazz)
+ /**
+ * Define decorator bean.
+ * @param <T> type info
+ * @param clazz decorator class
+ */
+ public static <T> void defineDecorator(ManagedBeanCreatorImpl<T> creator, AnnotatedType<T> annotatedType)
{
+ Class<T> clazz = annotatedType.getJavaClass();
if (DecoratorsManager.getInstance().isDecoratorEnabled(clazz))
{
- ManagedBean<T> component = null;
+ ManagedBean<T> delegate = null;
DecoratorUtil.checkDecoratorConditions(clazz);
- component = ManagedBeanConfigurator.define(clazz, WebBeansType.DECORATOR);
+ delegate = defineManagedBean(creator, annotatedType);
- if (component != null)
+ if (delegate != null)
+ {
+ WebBeansDecoratorConfig.configureDecoratorClass((ManagedBean<Object>) delegate);
+ }
+ else
{
- WebBeansDecoratorConfig.configureDecoratorClass((ManagedBean<Object>) component);
+ logger.trace("Unable to configure decorator with class : " + clazz);
}
}
}
@@ -2388,4 +2614,125 @@
return null;
}
+
+
+ public static <T> ManagedBean<T> defineManagedBean(ManagedBeanCreatorImpl<T> managedBeanCreator,AnnotatedType<T> annotatedType)
+ {
+ ManagedBean<T> managedBean = managedBeanCreator.getBean();
+
+ Class<T> clazz = annotatedType.getJavaClass();
+
+ managedBeanCreator.defineSerializable();
+
+ //Define meta-data
+ managedBeanCreator.defineStereoTypes();
+ //Scope type
+ managedBeanCreator.defineScopeType(logger.getTokenString(OWBLogConst.TEXT_MB_IMPL) + clazz.getName() + logger.getTokenString(OWBLogConst.TEXT_SAME_SCOPE));
+ //Check for Enabled via Alternative
+ WebBeansUtil.setInjectionTargetBeanEnableFlag(managedBean);
+
+ managedBeanCreator.defineApiType();
+ managedBeanCreator.checkCreateConditions();
+ managedBeanCreator.defineQualifier();
+ managedBeanCreator.defineName(WebBeansUtil.getManagedBeanDefaultName(clazz.getSimpleName()));
+ managedBeanCreator.defineConstructor();
+ Set<ProducerMethodBean<?>> producerMethods = managedBeanCreator.defineProducerMethods();
+ Set<ProducerFieldBean<?>> producerFields = managedBeanCreator.defineProducerFields();
+ managedBeanCreator.defineInjectedFields();
+ managedBeanCreator.defineInjectedMethods();
+
+ Set<ObserverMethod<?>> observerMethods = new HashSet<ObserverMethod<?>>();
+ if(managedBean.isEnabled())
+ {
+ observerMethods = managedBeanCreator.defineObserverMethods();
+ }
+
+ //Fires ProcessInjectionTarget
+ ProcessInjectionTargetImpl<T> processInjectionTargetEvent = WebBeansUtil.fireProcessInjectionTargetEvent(managedBean);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessInjectionTarget event observers. Look at logs for further details");
+
+ if(processInjectionTargetEvent.isSet())
+ {
+ managedBeanCreator.setInjectedTarget(processInjectionTargetEvent.getInjectionTarget());
+ }
+
+ Map<ProducerMethodBean<?>,AnnotatedMethod<?>> annotatedMethods = new HashMap<ProducerMethodBean<?>, AnnotatedMethod<?>>();
+ for(ProducerMethodBean<?> producerMethod : producerMethods)
+ {
+ AnnotatedMethod<?> method = AnnotatedElementFactory.newAnnotatedMethod(producerMethod.getCreatorMethod(), producerMethod.getParent().getReturnType());
+ ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForMethod(producerMethod,method);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerMethods. Look at logs for further details");
+
+ annotatedMethods.put(producerMethod, method);
+
+ if(producerEvent.isProducerSet())
+ {
+ producerMethod.setProducer((Producer)managedBeanCreator);
+ }
+
+ producerEvent.setProducerSet(false);
+ }
+
+ Map<ProducerFieldBean<?>,AnnotatedField<?>> annotatedFields = new HashMap<ProducerFieldBean<?>, AnnotatedField<?>>();
+ for(ProducerFieldBean<?> producerField : producerFields)
+ {
+ AnnotatedField<?> field = AnnotatedElementFactory.newAnnotatedField(producerField.getCreatorField(), producerField.getParent().getReturnType());
+ ProcessProducerImpl<?, ?> producerEvent = WebBeansUtil.fireProcessProducerEventForField(producerField, field);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducer event observers for ProducerFields. Look at logs for further details");
+
+ annotatedFields.put(producerField, field);
+
+ if(producerEvent.isProducerSet())
+ {
+ producerField.setProducer((Producer) managedBeanCreator);
+ }
+
+ producerEvent.setProducerSet(false);
+ }
+
+ Map<ObserverMethod<?>,AnnotatedMethod<?>> observerMethodsMap = new HashMap<ObserverMethod<?>, AnnotatedMethod<?>>();
+ for(ObserverMethod<?> observerMethod : observerMethods)
+ {
+ ObserverMethodImpl<?> impl = (ObserverMethodImpl<?>)observerMethod;
+ AnnotatedMethod<?> method = AnnotatedElementFactory.newAnnotatedMethod(impl.getObserverMethod(), impl.getBeanClass());
+
+ observerMethodsMap.put(observerMethod, method);
+ }
+
+ //Fires ProcessManagedBean
+ ProcessBeanImpl<T> processBeanEvent = new GProcessManagedBean(managedBean,annotatedType);
+ BeanManagerImpl.getManager().fireEvent(processBeanEvent, new Annotation[0]);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessManagedBean event observers for managed beans. Look at logs for further details");
+
+ //Fires ProcessProducerMethod
+ WebBeansUtil.fireProcessProducerMethodBeanEvent(annotatedMethods);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerMethod event observers for producer method beans. Look at logs for further details");
+
+ //Fires ProcessProducerField
+ WebBeansUtil.fireProcessProducerFieldBeanEvent(annotatedFields);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessProducerField event observers for producer field beans. Look at logs for further details");
+
+ //Fire ObservableMethods
+ WebBeansUtil.fireProcessObservableMethodBeanEvent(observerMethodsMap);
+ WebBeansUtil.inspectErrorStack("There are errors that are added by ProcessObserverMethod event observers for observer methods. Look at logs for further details");
+
+ //Set InjectionTarget that is used by the container to inject dependencies!
+ if(managedBeanCreator.isInjectionTargetSet())
+ {
+ managedBean.setInjectionTarget(managedBeanCreator);
+ }
+
+ BeanManagerImpl.getManager().addBean(WebBeansUtil.createNewBean(managedBean));
+ if(!WebBeansAnnotatedTypeUtil.isAnnotatedTypeDecoratorOrInterceptor(annotatedType))
+ {
+ DecoratorUtil.checkManagedBeanDecoratorConditions(managedBean);
+ BeanManagerImpl.getManager().addBean(managedBean);
+ BeanManagerImpl.getManager().getBeans().addAll(producerMethods);
+ managedBeanCreator.defineDisposalMethods();//Define disposal method after adding producers
+ BeanManagerImpl.getManager().getBeans().addAll(producerFields);
+ }
+
+ return managedBean;
+ }
+
}
\ No newline at end of file
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java Fri Feb 12 23:00:52 2010
@@ -38,6 +38,7 @@
import org.apache.webbeans.WebBeansConstants;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.component.xml.XMLManagedBean;
import org.apache.webbeans.component.xml.XMLProducerBean;
import org.apache.webbeans.container.InjectionResolver;
@@ -426,7 +427,7 @@
XMLInjectionPointModel model = XMLUtil.getInjectionPointModel(type, errorMessage);
- WebBeansDecoratorConfig.configureXMLDecoratorClass((AbstractBean<Object>) component, model);
+ WebBeansDecoratorConfig.configureXMLDecoratorClass((AbstractInjectionTargetBean<Object>) component, model);
}
else
{
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/InterceptorExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/InterceptorExtension.java?rev=909647&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/InterceptorExtension.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/InterceptorExtension.java Fri Feb 12 23:00:52 2010
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.interceptors.lifecycle;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.util.AnnotationLiteral;
+
+public class InterceptorExtension implements Extension
+{
+ @SuppressWarnings("serial")
+ public void observe(@Observes ProcessAnnotatedType<NotAnnotatedBean> process)
+ {
+ process.getAnnotatedType().getAnnotations().add(new AnnotationLiteral<LifecycleBinding>(){});
+ process.setAnnotatedType(process.getAnnotatedType());
+ }
+
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/InterceptorExtension.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleInterceptor.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleInterceptor.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleInterceptor.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleInterceptor.java Fri Feb 12 23:00:52 2010
@@ -30,11 +30,13 @@
public void postConstruct(InvocationContext context)
{
POST_CONSTRUCT = true;
+ NotAnnotatedBean.PC = true;
}
@PreDestroy
public void preDestroy(InvocationContext context)
{
PRE_DESTROY = true;
+ NotAnnotatedBean.PC = true;
}
}
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleTest.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/LifecycleTest.java Fri Feb 12 23:00:52 2010
@@ -73,4 +73,35 @@
}
+ @Test
+ public void testNotannotated()
+ {
+ Collection<URL> beanXmls = new ArrayList<URL>();
+ beanXmls.add(getXMLUrl(PACKAGE_NAME, "LifecycleTest"));
+
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(NotAnnotatedBean.class);
+ beanClasses.add(LifecycleInterceptor.class);
+
+
+ addExtension(new InterceptorExtension());
+
+ startContainer(beanClasses, beanXmls);
+
+ Set<Bean<?>> beans = getBeanManager().getBeans(NotAnnotatedBean.class.getName());
+ Assert.assertNotNull(beans);
+ Bean<NotAnnotatedBean> notAnnotatedBean = (Bean<NotAnnotatedBean>)beans.iterator().next();
+
+ CreationalContext<NotAnnotatedBean> ctx = getBeanManager().createCreationalContext(notAnnotatedBean);
+
+ Object reference = getBeanManager().getReference(notAnnotatedBean, NotAnnotatedBean.class, ctx);
+ Assert.assertNotNull(reference);
+
+ NotAnnotatedBean nab = (NotAnnotatedBean)reference;
+ nab.sayHello();
+ Assert.assertTrue(NotAnnotatedBean.PC);
+
+ shutDownContainer();
+ }
+
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/NotAnnotatedBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/NotAnnotatedBean.java?rev=909647&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/NotAnnotatedBean.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/NotAnnotatedBean.java Fri Feb 12 23:00:52 2010
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.webbeans.newtests.interceptors.lifecycle;
+
+import javax.inject.Named;
+
+@Named("org.apache.webbeans.newtests.interceptors.lifecycle.NotAnnotatedBean")
+public class NotAnnotatedBean
+{
+ public static boolean PC = false;
+
+ public void sayHello()
+ {
+
+ }
+}
Propchange: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/interceptors/lifecycle/NotAnnotatedBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/TestContext.java Fri Feb 12 23:00:52 2010
@@ -36,6 +36,7 @@
import org.apache.log4j.Logger;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.component.WebBeansType;
import org.apache.webbeans.component.xml.XMLManagedBean;
@@ -306,7 +307,7 @@
* @param clazz simple webbeans class
* @return simple webbean
*/
- protected <T> AbstractBean<T> defineManagedBean(Class<T> clazz)
+ protected <T> AbstractInjectionTargetBean<T> defineManagedBean(Class<T> clazz)
{
ManagedBean<T> bean = null;
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/exception/ExceptionComponentTest.java Fri Feb 12 23:00:52 2010
@@ -19,6 +19,7 @@
import junit.framework.Assert;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.intercept.ejb.EJBInterceptorConfig;
import org.apache.webbeans.test.TestContext;
@@ -210,7 +211,7 @@
try
{
clear();
- AbstractBean<MoreThanOnePostConstructComponent> component = defineManagedBean(MoreThanOnePostConstructComponent.class);
+ AbstractInjectionTargetBean<MoreThanOnePostConstructComponent> component = defineManagedBean(MoreThanOnePostConstructComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -227,7 +228,7 @@
try
{
clear();
- AbstractBean<PostContructMethodHasParameterComponent> component = defineManagedBean(PostContructMethodHasParameterComponent.class);
+ AbstractInjectionTargetBean<PostContructMethodHasParameterComponent> component = defineManagedBean(PostContructMethodHasParameterComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -244,7 +245,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(PostContructMethodHasReturnTypeComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(PostContructMethodHasReturnTypeComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -261,7 +262,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(PostContructMethodHasCheckedExceptionComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(PostContructMethodHasCheckedExceptionComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -278,7 +279,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(PostContructMethodHasStaticComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(PostContructMethodHasStaticComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -295,7 +296,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(MoreThanOneAroundInvokeComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(MoreThanOneAroundInvokeComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -313,7 +314,7 @@
defineManagedBean(AroundInvokeWithSameMethodNameComponent.class);
Bean<?> comp = getComponents().get(0);
- Assert.assertEquals(0, ((AbstractBean<?>) comp).getInterceptorStack().size());
+ Assert.assertEquals(0, ((AbstractInjectionTargetBean<?>) comp).getInterceptorStack().size());
}
@Test
@@ -322,7 +323,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithoutParameterComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithoutParameterComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -339,7 +340,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithoutReturnTypeComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithoutReturnTypeComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -356,7 +357,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithWrongReturnTypeComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithWrongReturnTypeComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -373,7 +374,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithoutExceptionComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithoutExceptionComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -390,7 +391,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithStaticMethodComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithStaticMethodComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -407,7 +408,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(AroundInvokeWithFinalMethodComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(AroundInvokeWithFinalMethodComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
@@ -424,7 +425,7 @@
try
{
clear();
- AbstractBean<?> component = defineManagedBean(NoArgConstructorInterceptorComponent.class);
+ AbstractInjectionTargetBean<?> component = defineManagedBean(NoArgConstructorInterceptorComponent.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}
catch (WebBeansConfigurationException e)
Modified: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/EJBInterceptorExceptionComponentTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/EJBInterceptorExceptionComponentTest.java?rev=909647&r1=909646&r2=909647&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/EJBInterceptorExceptionComponentTest.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/unittests/intercept/EJBInterceptorExceptionComponentTest.java Fri Feb 12 23:00:52 2010
@@ -16,6 +16,7 @@
import junit.framework.Assert;
import org.apache.webbeans.component.AbstractBean;
+import org.apache.webbeans.component.AbstractInjectionTargetBean;
import org.apache.webbeans.exception.WebBeansConfigurationException;
import org.apache.webbeans.intercept.ejb.EJBInterceptorConfig;
import org.apache.webbeans.test.TestContext;
@@ -42,7 +43,7 @@
{
try
{
- AbstractBean<MultpleInterceptor> component = defineManagedBean(MultpleInterceptor.class);
+ AbstractInjectionTargetBean<MultpleInterceptor> component = defineManagedBean(MultpleInterceptor.class);
EJBInterceptorConfig.configure(component.getReturnType(), component.getInterceptorStack());
}