You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2014/07/01 19:14:39 UTC
svn commit: r1607148 - in /openwebbeans/trunk:
webbeans-impl/src/main/java/org/apache/webbeans/component/
webbeans-impl/src/main/java/org/apache/webbeans/container/
webbeans-impl/src/main/java/org/apache/webbeans/portable/ webbeans-tck/
Author: rmannibucau
Date: Tue Jul 1 17:14:39 2014
New Revision: 1607148
URL: http://svn.apache.org/r1607148
Log:
interceptor for bm.createInjectionTarget
Added:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/InjectionTargetFactoryImpl.java
openwebbeans/trunk/webbeans-tck/testng-dev.xml
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java?rev=1607148&r1=1607147&r2=1607148&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/InjectionTargetBean.java Tue Jul 1 17:14:39 2014
@@ -32,6 +32,7 @@ import java.io.NotSerializableException;
import java.io.ObjectStreamException;
import java.io.Serializable;
+import org.apache.webbeans.portable.AbstractProducer;
import org.apache.webbeans.util.Asserts;
/**
@@ -73,6 +74,16 @@ public class InjectionTargetBean<T> exte
setEnabled(true);
}
+ // call it only if you know what you do, basically only useful when creating a bean manually and not using child classes
+ public void defineInterceptorsIfNeeded()
+ {
+ if (getProducer() instanceof AbstractProducer)
+ {
+ AbstractProducer<T> producer = (AbstractProducer<T>)getProducer();
+ producer.defineInterceptorStack(this, annotatedType, webBeansContext);
+ }
+ }
+
@Override
public InjectionTarget<T> getProducer()
{
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=1607148&r1=1607147&r2=1607148&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java Tue Jul 1 17:14:39 2014
@@ -78,6 +78,7 @@ import org.apache.webbeans.intercept.Int
import org.apache.webbeans.plugins.OpenWebBeansJmsPlugin;
import org.apache.webbeans.portable.AnnotatedElementFactory;
import org.apache.webbeans.portable.InjectionTargetImpl;
+import org.apache.webbeans.portable.LazyInterceptorDefinedInjectionTarget;
import org.apache.webbeans.portable.events.discovery.ErrorStack;
import org.apache.webbeans.spi.adaptor.ELAdaptor;
import org.apache.webbeans.spi.plugins.OpenWebBeansEjbPlugin;
@@ -783,18 +784,29 @@ public class BeanManagerImpl implements
public <T> Bean<T> createBean(BeanAttributes<T> attributes, Class<T> type, InjectionTargetFactory<T> factory)
{
+ final InjectionTargetBean<T> bean = new InjectionTargetBean<T>(
+ webBeansContext,
+ WebBeansType.THIRDPARTY,
+ InjectionTargetFactoryImpl.class.isInstance(factory)?
+ InjectionTargetFactoryImpl.class.cast(factory).getAnnotatedType() : getOrCreateAnnotatedType(type),
+ attributes, type, factory);
+
+ if (webBeansContext.getOpenWebBeansConfiguration().supportsInterceptionOnProducers())
+ {
+ bean.defineInterceptorsIfNeeded();
+ }
+
+ return bean;
+ }
+
+ private <T> AnnotatedType<T> getOrCreateAnnotatedType(final Class<T> type)
+ {
AnnotatedType<T> annotatedType = webBeansContext.getAnnotatedElementFactory().getAnnotatedType(type);
if (annotatedType == null)
{
annotatedType = webBeansContext.getAnnotatedElementFactory().newAnnotatedType(type);
}
- return new InjectionTargetBean<T>(
- webBeansContext,
- WebBeansType.THIRDPARTY,
- annotatedType,
- attributes,
- type,
- factory);
+ return annotatedType;
}
@@ -1076,7 +1088,7 @@ public class BeanManagerImpl implements
{
final InjectionTargetFactoryImpl<T> factory = new InjectionTargetFactoryImpl<T>(type, webBeansContext);
final InterceptorUtil interceptorUtil = webBeansContext.getInterceptorUtil();
- final InjectionTargetImpl<T> injectionTarget = new InjectionTargetImpl<T>(
+ final InjectionTargetImpl<T> injectionTarget = new LazyInterceptorDefinedInjectionTarget<T>(
type,
factory.createInjectionPoints(null),
webBeansContext,
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=1607148&r1=1607147&r2=1607148&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 Tue Jul 1 17:14:39 2014
@@ -71,7 +71,7 @@ public class InjectionTargetFactoryImpl<
return injectionPoints;
}
- protected AnnotatedType<T> getAnnotatedType()
+ public AnnotatedType<T> getAnnotatedType()
{
return annotatedType;
}
Added: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java?rev=1607148&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/portable/LazyInterceptorDefinedInjectionTarget.java Tue Jul 1 17:14:39 2014
@@ -0,0 +1,67 @@
+/*
+ * 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.portable;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.creational.CreationalContextImpl;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.AnnotatedMethod;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.util.List;
+import java.util.Set;
+
+public class LazyInterceptorDefinedInjectionTarget<T> extends InjectionTargetImpl<T>
+{
+ private volatile boolean interceptorsDefined;
+
+ public LazyInterceptorDefinedInjectionTarget(final AnnotatedType<T> annotatedType,
+ final Set<InjectionPoint> injectionPoints,
+ final WebBeansContext webBeansContext,
+ final List<AnnotatedMethod<?>> postConstructMethods,
+ final List<AnnotatedMethod<?>> preDestroyMethods)
+ {
+ super(annotatedType, injectionPoints, webBeansContext, postConstructMethods, preDestroyMethods);
+ interceptorsDefined = false;
+ }
+
+ @Override
+ public T produce(final CreationalContext<T> creationalContext)
+ {
+ final CreationalContextImpl<T> creationalContextImpl = (CreationalContextImpl<T>) creationalContext;
+ if (interceptorInfo == null && !interceptorsDefined)
+ {
+ final Bean<T> bean = creationalContextImpl.getBean();
+ if (bean != null)
+ {
+ synchronized (this)
+ {
+ if (!interceptorsDefined)
+ {
+ defineInterceptorStack(bean, annotatedType, webBeansContext);
+ interceptorsDefined = true;
+ }
+ }
+ }
+ }
+ return super.produce(creationalContext);
+ }
+}
Modified: openwebbeans/trunk/webbeans-tck/testng-dev.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-tck/testng-dev.xml?rev=1607148&r1=1607147&r2=1607148&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-tck/testng-dev.xml (original)
+++ openwebbeans/trunk/webbeans-tck/testng-dev.xml Tue Jul 1 17:14:39 2014
@@ -19,7 +19,7 @@
<test name="JSR-346 TCK">
<classes>
<class
- name="org.jboss.cdi.tck.interceptors.tests.contract.lifecycleCallback.LifecycleCallbackInterceptorTest" />
+ name="org.jboss.cdi.tck.tests.event.select.SelectEventTest" />
</classes>
<groups>
<run>