Author: struberg
Date: Wed Jun 14 17:44:16 2017
New Revision: 1798732
URL: http://svn.apache.org/viewvc?rev=1798732&view=rev
Log:
OWB-1186 InjectionTargetFactory must only be used once
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java?rev=1798732&r1=1798731&r2=1798732&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
Wed Jun 14 17:44:16 2017
@@ -22,6 +22,7 @@ import javax.enterprise.inject.spi.Injec
import org.apache.webbeans.component.ManagedBean;
import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.configurator.AnnotatedTypeConfiguratorImpl;
import org.apache.webbeans.portable.InjectionTargetImpl;
import org.apache.webbeans.portable.events.generics.GProcessInjectionTarget;
import org.apache.webbeans.util.Asserts;
@@ -33,21 +34,23 @@ import javax.enterprise.inject.spi.Annot
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.configurator.AnnotatedTypeConfigurator;
import java.util.List;
import java.util.Set;
public class InjectionTargetFactoryImpl<T> implements InjectionTargetFactory<T>
{
+ private final WebBeansContext webBeansContext;
private AnnotatedType<T> annotatedType;
- private WebBeansContext webBeansContext;
+ private AnnotatedTypeConfiguratorImpl<T> annotatedTypeConfigurator;
public InjectionTargetFactoryImpl(AnnotatedType<T> annotatedType,
WebBeansContext webBeansContext)
{
Asserts.assertNotNull(annotatedType, "AnnotatedType");
Asserts.assertNotNull(webBeansContext,
Asserts.PARAM_NAME_WEBBEANSCONTEXT);
- this.annotatedType = annotatedType;
this.webBeansContext = webBeansContext;
+ this.annotatedType = annotatedType;
}
public InjectionTarget<T> createInjectionTarget()
@@ -58,25 +61,35 @@ public class InjectionTargetFactoryImpl<
@Override
public InjectionTarget<T> createInjectionTarget(Bean<T> bean)
{
+ AnnotatedType<T> at = getAnnotatedType();
final InjectionTargetImpl<T> injectionTarget
- = new InjectionTargetImpl<T>(annotatedType,
createInjectionPoints(bean), webBeansContext, getPostConstructMethods(),
getPreDestroyMethods());
+ = new InjectionTargetImpl<T>(at, createInjectionPoints(bean),
webBeansContext, getPostConstructMethods(), getPreDestroyMethods());
if (ManagedBean.class.isInstance(bean))
{
ManagedBean.class.cast(bean).setOriginalInjectionTarget(injectionTarget);
}
- final GProcessInjectionTarget event =
webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget,
annotatedType);
+ final GProcessInjectionTarget event =
webBeansContext.getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget,
at);
final InjectionTarget it = event.getInjectionTarget();
event.setStarted();
+
+ // creating the InjectionTarget must only be done once.
+ this.annotatedType = null;
+ this.annotatedTypeConfigurator = null;
+
return it;
}
public Set<InjectionPoint> createInjectionPoints(Bean<T> bean)
{
- return
webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
annotatedType);
+ return
webBeansContext.getInjectionPointFactory().buildInjectionPoints(bean,
getAnnotatedType());
}
public AnnotatedType<T> getAnnotatedType()
{
+ if (annotatedTypeConfigurator != null)
+ {
+ return annotatedTypeConfigurator.getNewAnnotatedType();
+ }
return annotatedType;
}
@@ -94,4 +107,15 @@ public class InjectionTargetFactoryImpl<
{
return
webBeansContext.getInterceptorUtil().getLifecycleMethods(annotatedType,
PreDestroy.class);
}
+
+ @Override
+ public AnnotatedTypeConfigurator<T> configure()
+ {
+ if (annotatedType == null)
+ {
+ throw new IllegalStateException("InjectionTargetFactora can only
be used once");
+ }
+ annotatedTypeConfigurator = new
AnnotatedTypeConfiguratorImpl<>(webBeansContext, annotatedType);
+ return annotatedTypeConfigurator;
+ }
}