You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ar...@apache.org on 2012/10/15 20:23:30 UTC
svn commit: r1398435 - in /openwebbeans/trunk/webbeans-impl/src:
main/java/org/apache/webbeans/component/ main/java/org/apache/webbeans/event/
test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/
test/java/org/apache/webbeans/newtests...
Author: arne
Date: Mon Oct 15 18:23:29 2012
New Revision: 1398435
URL: http://svn.apache.org/viewvc?rev=1398435&view=rev
Log:
OWB-714 Fixed injection of InjectionPoint into observer methods
Added:
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/AbstractInjectionPointOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/FieldInjectionPointOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointBeansOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointObserver.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MethodInjectionPointOwner.java
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EventBean.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EventBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EventBean.java?rev=1398435&r1=1398434&r2=1398435&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EventBean.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/EventBean.java Mon Oct 15 18:23:29 2012
@@ -79,7 +79,7 @@ public class EventBean<T> extends Abstra
try
{
- instance = new EventImpl<T>(qualifiers, eventType, getWebBeansContext());
+ instance = new EventImpl<T>(qualifiers, eventType, injectionPoint, getWebBeansContext());
}
catch (Exception e)
{
Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java?rev=1398435&r1=1398434&r2=1398435&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/EventImpl.java Mon Oct 15 18:23:29 2012
@@ -28,8 +28,10 @@ import java.util.HashSet;
import java.util.Set;
import javax.enterprise.event.Event;
+import javax.enterprise.inject.spi.InjectionPoint;
import javax.enterprise.util.TypeLiteral;
+import org.apache.webbeans.component.InjectionPointBean;
import org.apache.webbeans.config.WebBeansContext;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.OwbCustomObjectInputStream;
@@ -50,6 +52,9 @@ public class EventImpl<T> implements Eve
/**Event types*/
private Type eventType;
+
+ /**injection point of the event*/
+ private InjectionPoint injectionPoint;
private transient WebBeansContext webBeansContext;
@@ -60,11 +65,12 @@ public class EventImpl<T> implements Eve
* @param eventType event type
* @param webBeansContext
*/
- public EventImpl(Annotation[] injectedBindings, Type eventType, WebBeansContext webBeansContext)
+ public EventImpl(Annotation[] injectedBindings, Type eventType, InjectionPoint injectionPoint, WebBeansContext webBeansContext)
{
this.webBeansContext = webBeansContext;
this.injectedBindings = injectedBindings;
this.eventType = eventType;
+ this.injectionPoint = injectionPoint;
}
/**
@@ -72,7 +78,15 @@ public class EventImpl<T> implements Eve
*/
public void fire(T event)
{
- webBeansContext.getBeanManagerImpl().fireEvent(event, injectedBindings);
+ InjectionPointBean.setThreadLocal(injectionPoint);
+ try
+ {
+ webBeansContext.getBeanManagerImpl().fireEvent(event, injectedBindings);
+ }
+ finally
+ {
+ InjectionPointBean.setThreadLocal(injectionPoint);
+ }
}
/**
@@ -111,7 +125,7 @@ public class EventImpl<T> implements Eve
*/
public Event<T> select(Annotation... bindings)
{
- Event<T> sub = new EventImpl<T>(getEventBindings(bindings), eventType, webBeansContext);
+ Event<T> sub = new EventImpl<T>(getEventBindings(bindings), eventType, injectionPoint, webBeansContext);
return sub;
}
@@ -133,7 +147,7 @@ public class EventImpl<T> implements Eve
sub = eventType;
}
- Event<U> subEvent = new EventImpl<U>(getEventBindings(bindings),sub, webBeansContext);
+ Event<U> subEvent = new EventImpl<U>(getEventBindings(bindings),sub, injectionPoint, webBeansContext);
return subEvent;
}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/AbstractInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/AbstractInjectionPointOwner.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/AbstractInjectionPointOwner.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/AbstractInjectionPointOwner.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+
+public abstract class AbstractInjectionPointOwner {
+
+ protected InjectionPoint injectionPoint;
+
+ public String getName() {
+ return injectionPoint.getMember().getName();
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/ConstructorInjectionPointOwner.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+public class ConstructorInjectionPointOwner extends AbstractInjectionPointOwner {
+
+ @Inject
+ public ConstructorInjectionPointOwner(InjectionPoint ip) {
+ injectionPoint = ip;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/FieldInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/FieldInjectionPointOwner.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/FieldInjectionPointOwner.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/FieldInjectionPointOwner.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+public class FieldInjectionPointOwner extends AbstractInjectionPointOwner {
+
+ @Inject
+ private InjectionPoint ip;
+
+ @PostConstruct
+ public void setInjectionPoint() {
+ injectionPoint = ip;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointBeansOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointBeansOwner.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointBeansOwner.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointBeansOwner.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+public class InjectionPointBeansOwner {
+
+ @Inject
+ private ConstructorInjectionPointOwner constructorInjection;
+ @Inject
+ private FieldInjectionPointOwner fieldInjection;
+ @Inject
+ private MethodInjectionPointOwner methodInjection;
+ @Inject
+ private Instance<ConstructorInjectionPointOwner> constructorInjectionInstance;
+ @Inject
+ private Instance<FieldInjectionPointOwner> fieldInjectionInstance;
+ @Inject
+ private Instance<MethodInjectionPointOwner> methodInjectionInstance;
+ @Inject
+ private Event<StringBuilder> observerInjection;
+
+ public String getConstructorInjectionName() {
+ return constructorInjection.getName();
+ }
+
+ public String getFieldInjectionName() {
+ return fieldInjection.getName();
+ }
+
+ public String getMethodInjectionName() {
+ return methodInjection.getName();
+ }
+
+ public String getConstructorInjectionInstanceName() {
+ return constructorInjectionInstance.get().getName();
+ }
+
+ public String getFieldInjectionInstanceName() {
+ return fieldInjectionInstance.get().getName();
+ }
+
+ public String getMethodInjectionInstanceName() {
+ return methodInjectionInstance.get().getName();
+ }
+
+ public String getObserverInjectionName() {
+ StringBuilder name = new StringBuilder();
+ observerInjection.fire(name);
+ return name.toString();
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointObserver.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointObserver.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointObserver.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/InjectionPointObserver.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.InjectionPoint;
+
+public class InjectionPointObserver extends AbstractInjectionPointOwner {
+
+ public void observeInjectionPoint(@Observes StringBuilder builder, InjectionPoint ip) {
+ injectionPoint = ip;
+ builder.append(getName());
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MethodInjectionPointOwner.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MethodInjectionPointOwner.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MethodInjectionPointOwner.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/beans/MethodInjectionPointOwner.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.beans;
+
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.inject.Inject;
+
+public class MethodInjectionPointOwner extends AbstractInjectionPointOwner {
+
+ @Inject
+ public void setInjectionPoint(InjectionPoint ip) {
+ injectionPoint = ip;
+ }
+}
Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java?rev=1398435&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java (added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/newtests/injection/injectionpoint/tests/InjectionPointInjectionTest.java Mon Oct 15 18:23:29 2012
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2012 The Apache Software Foundation.
+ *
+ * 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.apache.webbeans.newtests.injection.injectionpoint.tests;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+
+import org.apache.webbeans.newtests.AbstractUnitTest;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.ConstructorInjectionPointOwner;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.FieldInjectionPointOwner;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.InjectionPointBeansOwner;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.InjectionPointObserver;
+import org.apache.webbeans.newtests.injection.injectionpoint.beans.MethodInjectionPointOwner;
+import org.junit.Test;
+
+public class InjectionPointInjectionTest extends AbstractUnitTest {
+
+ @Test
+ public void testInjectionPointInjection() {
+ Collection<Class<?>> beanClasses = new ArrayList<Class<?>>();
+ beanClasses.add(ConstructorInjectionPointOwner.class);
+ beanClasses.add(FieldInjectionPointOwner.class);
+ beanClasses.add(MethodInjectionPointOwner.class);
+ beanClasses.add(InjectionPointObserver.class);
+ beanClasses.add(InjectionPointBeansOwner.class);
+ startContainer(beanClasses, null);
+
+ Bean<InjectionPointBeansOwner> bean = (Bean<InjectionPointBeansOwner>) getBeanManager().getBeans(InjectionPointBeansOwner.class).iterator().next();
+ CreationalContext<InjectionPointBeansOwner> cc = getBeanManager().createCreationalContext(bean);
+ InjectionPointBeansOwner owner = (InjectionPointBeansOwner) getBeanManager().getReference(bean, InjectionPointBeansOwner.class, cc);
+
+ assertThat(owner.getConstructorInjectionName(), is("constructorInjection"));
+ assertThat(owner.getFieldInjectionName(), is("fieldInjection"));
+ assertThat(owner.getMethodInjectionName(), is("methodInjection"));
+ assertThat(owner.getConstructorInjectionInstanceName(), is("constructorInjectionInstance"));
+ assertThat(owner.getFieldInjectionInstanceName(), is("fieldInjectionInstance"));
+ assertThat(owner.getMethodInjectionInstanceName(), is("methodInjectionInstance"));
+ assertThat(owner.getObserverInjectionName(), is("observerInjection"));
+
+ shutDownContainer();
+ }
+}