[weld-commits] Weld SVN: r4693 - in core/trunk: impl/src/main/java/org/jboss/weld/bean and 6 other directories.
weld-commits at lists.jboss.org
weld-commits at lists.jboss.org
Wed Nov 4 20:10:46 EST 2009
Author: pete.muir at jboss.org
Date: 2009-11-04 20:10:45 -0500 (Wed, 04 Nov 2009)
New Revision: 4693
Added:
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleConsumer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleGenerator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/InjectionPointTest.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntConsumer.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntGenerator.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/TimerManager.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/
core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/Foo.java
Removed:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyInstance.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/facade/InstanceImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/circular/CircularDependencyTest.java
Log:
WELD-239
Modified: core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/BeanManagerImpl.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -18,6 +18,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
+import java.lang.reflect.Member;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
@@ -45,6 +46,7 @@
import javax.enterprise.inject.InjectionException;
import javax.enterprise.inject.UnproxyableResolutionException;
import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.Annotated;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.Decorator;
@@ -165,8 +167,44 @@
private static final long serialVersionUID = 3021562879133838561L;
- // The JNDI key to place the manager under
- public static final String JNDI_KEY = "java:app/Manager";
+ public static final InjectionPoint DUMMY_INJECTION_POINT = new InjectionPoint()
+ {
+
+ public boolean isTransient()
+ {
+ return true;
+ }
+
+ public boolean isDelegate()
+ {
+ return false;
+ }
+
+ public Type getType()
+ {
+ return InjectionPoint.class;
+ }
+
+ public Set<Annotation> getQualifiers()
+ {
+ return Collections.emptySet();
+ }
+
+ public Member getMember()
+ {
+ return null;
+ }
+
+ public Bean<?> getBean()
+ {
+ return null;
+ }
+
+ public Annotated getAnnotated()
+ {
+ return null;
+ }
+ };
/*
* Application scoped services
@@ -1235,6 +1273,19 @@
currentInjectionPoint.get().push(injectionPoint);
return originalInjectionPoint;
}
+
+ public void pushDummyInjectionPoint()
+ {
+ currentInjectionPoint.get().push(DUMMY_INJECTION_POINT);
+ }
+
+ public void popDummyInjectionPoint()
+ {
+ if (!currentInjectionPoint.get().isEmpty() && DUMMY_INJECTION_POINT.equals(currentInjectionPoint.get().peek()))
+ {
+ currentInjectionPoint.get().pop();
+ }
+ }
/**
*
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractProducerBean.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -179,7 +179,7 @@
throw new IllegalProductException("Producers cannot declare passivating scope and return a non-serializable class");
}
InjectionPoint injectionPoint = manager.getCurrentInjectionPoint();
- if (injectionPoint == null)
+ if (injectionPoint == null || injectionPoint.equals(BeanManagerImpl.DUMMY_INJECTION_POINT))
{
return;
}
@@ -187,7 +187,7 @@
{
if (injectionPoint.getMember() instanceof Field)
{
- if (!Reflections.isTransient(injectionPoint.getMember()) && instance != null && !Reflections.isSerializable(instance.getClass()))
+ if (!injectionPoint.isTransient() && instance != null && !Reflections.isSerializable(instance.getClass()))
{
throw new IllegalProductException("Producers cannot produce non-serializable instances for injection into non-transient fields of passivating beans\n\nProducer: " + this.toString() + "\nInjection Point: " + injectionPoint.toString());
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/facade/InstanceImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/facade/InstanceImpl.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/facade/InstanceImpl.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -63,10 +63,18 @@
{
Annotation[] annotations = mergeInBindings(bindings);
Bean<T> bean = getManager().getBean(ResolvableWeldClass.<T>of(getType(), annotations, getManager()), annotations);
-
- @SuppressWarnings("unchecked")
- T instance = (T) getManager().getReference(bean, getType(), getManager().createCreationalContext(bean));
- return instance;
+ // Push in an empty CC to ensure that we don't get the CC of whatever is injecting the bean containing the Instance injection point
+ try
+ {
+ getManager().pushDummyInjectionPoint();
+ @SuppressWarnings("unchecked")
+ T instance = (T) getManager().getReference(bean, getType(), getManager().createCreationalContext(bean));
+ return instance;
+ }
+ finally
+ {
+ getManager().popDummyInjectionPoint();
+ }
}
public T get()
Deleted: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyInstance.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyInstance.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -1,28 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * 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.jboss.weld.bean.proxy;
-
-/**
- * @author pmuir
- *
- */
-public interface ClientProxyInstance
-{
-
- public void touch(Marker marker);
-
-}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyMethodHandler.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -99,13 +99,6 @@
bean = Container.instance().deploymentServices().get(ContextualStore.class).<Bean<Object>, Object>getContextual(id);
}
Object proxiedInstance = getProxiedInstance(bean);
- if ("touch".equals(proxiedMethod.getName()) && Marker.isMarker(0, proxiedMethod, args))
- {
- // Our "touch" method, which simply ensures the proxy does any object
- // instantiation needed, to avoid the annoying side effect of an object
- // getting lazy created
- return null;
- }
if (proxiedInstance == null)
{
// TODO not sure if this right PLM
@@ -145,10 +138,13 @@
try
{
Context context = manager.getContext(bean.getScope());
+ // Ensure that there is no injection point associated
+ manager.pushDummyInjectionPoint();
return context.get(bean, creationalContext);
}
finally
{
+ manager.popDummyInjectionPoint();
if (outer)
{
currentCreationalContext.remove();
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -79,7 +79,6 @@
{
ClientProxyMethodHandler proxyMethodHandler = new ClientProxyMethodHandler(bean, manager, id);
Set<Type> classes = new LinkedHashSet<Type>(bean.getTypes());
- //classes.add(ClientProxyInstance.class);
classes.add(Serializable.class);
ProxyFactory proxyFactory = Proxies.getProxyFactory(classes);
proxyFactory.setHandler(proxyMethodHandler);
@@ -125,8 +124,6 @@
}
});
- // TODO Break circular injection. Can we somehow support both?
- //((ClientProxyInstance) instance).touch(Marker.INSTANCE);
return instance;
}
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleConsumer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleConsumer.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+ at Named
+ at SessionScoped
+public class DoubleConsumer implements Serializable
+{
+
+ private static final long serialVersionUID = 6619645042310126425L;
+
+ @Inject
+ private double maxNumber;
+
+ public DoubleConsumer()
+ {
+ }
+
+ public void ping()
+ {
+
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleConsumer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleGenerator.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleGenerator.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleGenerator.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,25 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import java.io.Serializable;
+import java.util.Timer;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+ at ApplicationScoped
+public class DoubleGenerator implements Serializable
+{
+
+ private static final long serialVersionUID = -7213673465118041882L;
+
+ @Inject Timer timer;
+
+ @Produces
+ double getDouble()
+ {
+ timer.cancel();
+ return 11.1;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/DoubleGenerator.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/InjectionPointTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/InjectionPointTest.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/InjectionPointTest.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import javax.enterprise.inject.IllegalProductException;
+
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.weld.test.AbstractWeldTest;
+import org.testng.annotations.Test;
+
+ at Artifact
+public class InjectionPointTest extends AbstractWeldTest
+{
+
+ @Test(description="WELD-239")
+ public void testCorrectInjectionPointUsed()
+ {
+ getCurrentManager().getInstanceByType(IntConsumer.class).ping();
+
+ try
+ {
+ getCurrentManager().getInstanceByType(DoubleConsumer.class).ping();
+ }
+ catch (IllegalProductException e)
+ {
+ assert e.getMessage().contains("Injection Point: field org.jboss.weld.tests.injectionPoint.DoubleGenerator.timer");
+ }
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/InjectionPointTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntConsumer.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntConsumer.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntConsumer.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,28 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+ at Named
+ at SessionScoped
+public class IntConsumer implements Serializable
+{
+
+ private static final long serialVersionUID = 6619645042310126425L;
+
+ @Inject
+ private int maxNumber;
+
+ public IntConsumer()
+ {
+ }
+
+ public void ping()
+ {
+
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntConsumer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntGenerator.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntGenerator.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntGenerator.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,29 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import java.io.Serializable;
+import java.util.Timer;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+ at ApplicationScoped
+public class IntGenerator implements Serializable
+{
+
+ private static final long serialVersionUID = -7213673465118041882L;
+
+ @Inject
+ private Instance<Timer> timerInstance;
+
+ @Produces
+ int getInt()
+ {
+ // This has no purpose other than to invoke a method on the proxy so that the proxy instance
+ // is retrieved via the producer method
+ timerInstance.get().cancel();
+ return 100;
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/IntGenerator.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/TimerManager.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/TimerManager.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/TimerManager.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,21 @@
+package org.jboss.weld.tests.injectionPoint;
+
+import java.io.Serializable;
+import java.util.Timer;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+
+public class TimerManager implements Serializable
+{
+
+ private static final long serialVersionUID = 5156835887786174326L;
+
+ @Produces
+ @RequestScoped
+ public Timer getTimer()
+ {
+ return new Timer();
+ }
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/TimerManager.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/Foo.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/Foo.java (rev 0)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/Foo.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -0,0 +1,8 @@
+package org.jboss.weld.tests.injectionPoint.other;
+
+public class Foo
+{
+
+ public void ping() {}
+
+}
Property changes on: core/trunk/tests/src/test/java/org/jboss/weld/tests/injectionPoint/other/Foo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/circular/CircularDependencyTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/circular/CircularDependencyTest.java 2009-11-04 23:09:25 UTC (rev 4692)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/resolution/circular/CircularDependencyTest.java 2009-11-05 01:10:45 UTC (rev 4693)
@@ -28,15 +28,4 @@
getCurrentManager().getInstanceByType(Violation.class).ping();
}
- @Test(groups="broken", timeOut=1000)
- public void testDependentCircularConstructors() throws Exception
- {
- getCurrentManager().getInstanceByType(Fish.class);
- }
-
- @Test(groups="broken", timeOut=1000)
- public void testSelfConsumingConstructorsOnDependentBean() throws Exception
- {
- getCurrentManager().getInstanceByType(Farm.class);
- }
}
More information about the weld-commits
mailing list