Weld SVN: r6135 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-04-21 06:29:59 -0400 (Wed, 21 Apr 2010)
New Revision: 6135
Added:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java
Log:
CDITCK-142
Added: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java (rev 0)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java 2010-04-21 10:29:59 UTC (rev 6135)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.jsr299.tck.tests.context.dependent;
+
+import javax.annotation.PreDestroy;
+
+public class DomesticationKit
+{
+ private static boolean destroyed = false;
+
+ @PreDestroy
+ public void preDestroy()
+ {
+ destroyed = true;
+ }
+
+ public static boolean isDestroyed()
+ {
+ return destroyed;
+ }
+
+ public static void reset()
+ {
+ destroyed = false;
+ }
+}
14 years, 8 months
Weld SVN: r6134 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-04-21 06:29:31 -0400 (Wed, 21 Apr 2010)
New Revision: 6134
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java
Log:
CDITCK-142
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java 2010-04-21 10:24:39 UTC (rev 6133)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java 2010-04-21 10:29:31 UTC (rev 6134)
@@ -334,16 +334,23 @@
@SpecAssertion(section = "6.4.2", id = "ddd"),
@SpecAssertion(section = "6.4.1", id="h")
})
-
public void testDependentsDestroyedWhenProducerMethodCompletes()
{
- // Reset the test class
+ // Reset the test classes
SpiderProducer.reset();
Tarantula.reset();
- Tarantula spiderInstance = getInstanceByType(Tarantula.class, PET_LITERAL);
- spiderInstance.ping();
+ DomesticationKit.reset();
+
+ Bean<Tarantula> tarantulaBean = getUniqueBean(Tarantula.class, PET_LITERAL);
+ CreationalContext<Tarantula> creationalContext = getCurrentManager().createCreationalContext(tarantulaBean);
+ Tarantula tarantula = (Tarantula) getCurrentManager().getReference(tarantulaBean, Tarantula.class, creationalContext);
+ tarantula.ping();
+ // contextual instance created to receive a producer method invocation
+ // is destroyed when the invocation completes
assert SpiderProducer.isDestroyed();
- assert Tarantula.isDestroyed();
+ // DomesticationKit instance is a dependent object of the Tarantula instance
+ tarantulaBean.destroy(tarantula, creationalContext);
+ assert DomesticationKit.isDestroyed();
SpiderProducer.reset();
}
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java 2010-04-21 10:24:39 UTC (rev 6133)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java 2010-04-21 10:29:31 UTC (rev 6134)
@@ -33,7 +33,7 @@
private static SpiderProducer instanceUsedForDisposal = null;
- @Produces @Pet public Tarantula produceTarantula(Tarantula spider)
+ @Produces @Pet public Tarantula produceTarantula(Tarantula spider, DomesticationKit domesticationKit)
{
dependentContextActive = beanManager.getContext(Dependent.class).isActive();
return spider;
14 years, 8 months
Weld SVN: r6133 - cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-04-21 06:24:39 -0400 (Wed, 21 Apr 2010)
New Revision: 6133
Added:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java
Modified:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java
Log:
CDITCK-142
Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java 2010-04-21 10:23:37 UTC (rev 6132)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DependentContextTest.java 2010-04-21 10:24:39 UTC (rev 6133)
@@ -334,16 +334,23 @@
@SpecAssertion(section = "6.4.2", id = "ddd"),
@SpecAssertion(section = "6.4.1", id="h")
})
-
public void testDependentsDestroyedWhenProducerMethodCompletes()
{
- // Reset the test class
+ // Reset the test classes
SpiderProducer.reset();
Tarantula.reset();
- Tarantula spiderInstance = getInstanceByType(Tarantula.class, PET_LITERAL);
- spiderInstance.ping();
+ DomesticationKit.reset();
+
+ Bean<Tarantula> tarantulaBean = getUniqueBean(Tarantula.class, PET_LITERAL);
+ CreationalContext<Tarantula> creationalContext = getCurrentManager().createCreationalContext(tarantulaBean);
+ Tarantula tarantula = (Tarantula) getCurrentManager().getReference(tarantulaBean, Tarantula.class, creationalContext);
+ tarantula.ping();
+ // contextual instance created to receive a producer method invocation
+ // is destroyed when the invocation completes
assert SpiderProducer.isDestroyed();
- assert Tarantula.isDestroyed();
+ // DomesticationKit instance is a dependent object of the Tarantula instance
+ tarantulaBean.destroy(tarantula, creationalContext);
+ assert DomesticationKit.isDestroyed();
SpiderProducer.reset();
}
Added: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java (rev 0)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/DomesticationKit.java 2010-04-21 10:24:39 UTC (rev 6133)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., 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.jsr299.tck.tests.context.dependent;
+
+import javax.annotation.PreDestroy;
+
+public class DomesticationKit
+{
+ private static boolean destroyed = false;
+
+ @PreDestroy
+ public void preDestroy()
+ {
+ destroyed = true;
+ }
+
+ public static boolean isDestroyed()
+ {
+ return destroyed;
+ }
+
+ public static void reset()
+ {
+ destroyed = false;
+ }
+}
Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java 2010-04-21 10:23:37 UTC (rev 6132)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/context/dependent/SpiderProducer.java 2010-04-21 10:24:39 UTC (rev 6133)
@@ -33,7 +33,7 @@
private static SpiderProducer instanceUsedForDisposal = null;
- @Produces @Pet public Tarantula produceTarantula(Tarantula spider)
+ @Produces @Pet public Tarantula produceTarantula(Tarantula spider, DomesticationKit domesticationKit)
{
dependentContextActive = beanManager.getContext(Dependent.class).isActive();
return spider;
14 years, 8 months
Weld SVN: r6132 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-04-21 06:23:37 -0400 (Wed, 21 Apr 2010)
New Revision: 6132
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java
Log:
CDITCK-136
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java 2010-04-21 10:22:59 UTC (rev 6131)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java 2010-04-21 10:23:37 UTC (rev 6132)
@@ -58,8 +58,9 @@
public void testDefaultQualifierForInjectionPoint()
{
Bean<Order> order = getBeans(Order.class).iterator().next();
+ assert order.getInjectionPoints().size() == 1;
InjectionPoint injectionPoint = order.getInjectionPoints().iterator().next();
- assert injectionPoint.getBean().getQualifiers().contains(new DefaultLiteral());
+ assert injectionPoint.getQualifiers().contains(new DefaultLiteral());
}
@Test
14 years, 8 months
Weld SVN: r6131 - cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier.
by weld-commits@lists.jboss.org
Author: jharting
Date: 2010-04-21 06:22:59 -0400 (Wed, 21 Apr 2010)
New Revision: 6131
Modified:
cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java
Log:
CDITCK-136
Modified: cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java
===================================================================
--- cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java 2010-04-20 20:08:13 UTC (rev 6130)
+++ cdi-tck/branches/1.0/impl/src/main/java/org/jboss/jsr299/tck/tests/definition/qualifier/QualifierDefinitionTest.java 2010-04-21 10:22:59 UTC (rev 6131)
@@ -58,8 +58,9 @@
public void testDefaultQualifierForInjectionPoint()
{
Bean<Order> order = getBeans(Order.class).iterator().next();
+ assert order.getInjectionPoints().size() == 1;
InjectionPoint injectionPoint = order.getInjectionPoints().iterator().next();
- assert injectionPoint.getBean().getQualifiers().contains(new DefaultLiteral());
+ assert injectionPoint.getQualifiers().contains(new DefaultLiteral());
}
@Test
14 years, 8 months
Weld SVN: r6130 - core/trunk/impl/src/main/java/org/jboss/weld/literal.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-20 16:08:13 -0400 (Tue, 20 Apr 2010)
New Revision: 6130
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/literal/AnyLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/DefaultLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/InterceptorBindingTypeLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/NewLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/NormalScopeLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/QualifierLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/ScopeLiteral.java
core/trunk/impl/src/main/java/org/jboss/weld/literal/StereotypeLiteral.java
Log:
javadocs
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/AnyLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/AnyLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/AnyLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.inject.Any;
import javax.enterprise.util.AnnotationLiteral;
+/**
+ * Annotation literal for {@link Any}?
+ *
+ * @author Pete Muir
+ */
public class AnyLiteral extends AnnotationLiteral<Any> implements Any
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/DefaultLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/DefaultLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/DefaultLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -20,7 +20,7 @@
import javax.enterprise.util.AnnotationLiteral;
/**
- * Annotation literal for @Current
+ * Annotation literal for {@link Default}?
*
* @author Pete Muir
*/
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/InterceptorBindingTypeLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/InterceptorBindingTypeLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/InterceptorBindingTypeLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.util.AnnotationLiteral;
import javax.interceptor.InterceptorBinding;
+/**
+ * Annotation literal for {@link InterceptorBinding}?
+ *
+ * @author Pete Muir
+ */
public class InterceptorBindingTypeLiteral extends AnnotationLiteral<InterceptorBinding> implements InterceptorBinding
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/NamedLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -20,7 +20,7 @@
import javax.inject.Named;
/**
- * Annotation literal for @Current
+ * Annotation literal for {@link Named}?
*
* @author Pete Muir
*/
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/NewLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/NewLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/NewLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -20,7 +20,7 @@
import javax.enterprise.util.AnnotationLiteral;
/**
- * Annotation literal for @Current
+ * Annotation literal for {@link New}?
*
* @author Pete Muir
*/
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/NormalScopeLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/NormalScopeLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/NormalScopeLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.context.NormalScope;
import javax.enterprise.util.AnnotationLiteral;
+/**
+ * Annotation literal for {@link NormalScope}?
+ *
+ * @author Pete Muir
+ */
public class NormalScopeLiteral extends AnnotationLiteral<NormalScope> implements NormalScope
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/QualifierLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/QualifierLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/QualifierLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Qualifier;
+/**
+ * Annotation literal for {@link Qualifier}?
+ *
+ * @author Pete Muir
+ */
public class QualifierLiteral extends AnnotationLiteral<Qualifier> implements Qualifier
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/ScopeLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/ScopeLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/ScopeLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Scope;
+/**
+ * Annotation literal for {@link Scope}?
+ *
+ * @author Pete Muir
+ */
public class ScopeLiteral extends AnnotationLiteral<Scope> implements Scope
{
Modified: core/trunk/impl/src/main/java/org/jboss/weld/literal/StereotypeLiteral.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/literal/StereotypeLiteral.java 2010-04-20 19:59:08 UTC (rev 6129)
+++ core/trunk/impl/src/main/java/org/jboss/weld/literal/StereotypeLiteral.java 2010-04-20 20:08:13 UTC (rev 6130)
@@ -19,6 +19,11 @@
import javax.enterprise.inject.Stereotype;
import javax.enterprise.util.AnnotationLiteral;
+/**
+ * Annotation literal for {@link Stereotype}?
+ *
+ * @author Pete Muir
+ */
public class StereotypeLiteral extends AnnotationLiteral<Stereotype> implements Stereotype
{
14 years, 8 months
Weld SVN: r6129 - core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider.
by weld-commits@lists.jboss.org
Author: nickarls
Date: 2010-04-20 15:59:08 -0400 (Tue, 20 Apr 2010)
New Revision: 6129
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java
Log:
warn instead of abort for problems loading services
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java 2010-04-20 18:39:00 UTC (rev 6128)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/serviceProvider/DefaultServiceLoader.java 2010-04-20 19:59:08 UTC (rev 6129)
@@ -63,7 +63,7 @@
{
private static LocLogger log = loggerFactory().getLogger(UTIL);
private static XLogger logX = loggerFactory().getXLogger(UTIL);
-
+
private static final String SERVICES = "META-INF/services";
/**
@@ -240,8 +240,15 @@
private void loadService(String serviceClassName)
{
Class<? extends S> serviceClass = loadClass(serviceClassName);
- S serviceInstance = prepareInstance(serviceClass);
- providers.add(serviceInstance);
+ S serviceInstance = null;
+ if (serviceClass != null)
+ {
+ serviceInstance = prepareInstance(serviceClass);
+ }
+ if (serviceInstance != null)
+ {
+ providers.add(serviceInstance);
+ }
}
private Class<? extends S> loadClass(String serviceClassName)
@@ -255,13 +262,11 @@
}
catch (ClassNotFoundException e)
{
- logX.throwing(Level.ERROR, e);
- throw new ForbiddenStateException(EXTENSION_CLASS_NOT_FOUND, serviceClassName);
+ log.warn(EXTENSION_CLASS_NOT_FOUND, serviceClassName);
}
catch (ClassCastException e)
{
- logX.throwing(Level.ERROR, e);
- throw new ForbiddenStateException(DECLARED_EXTENSION_DOES_NOT_IMPLEMENT_EXTENSION, serviceClassName);
+ log.warn(DECLARED_EXTENSION_DOES_NOT_IMPLEMENT_EXTENSION, serviceClassName);
}
return serviceClass;
}
@@ -275,9 +280,9 @@
}
catch (Exception e)
{
- logX.throwing(Level.ERROR, e);
- throw new ForbiddenStateException(SECURITY_EXCEPTION_SCANNING, serviceClass, e);
+ log.warn(SECURITY_EXCEPTION_SCANNING, serviceClass.getName());
}
+ return null;
}
/**
14 years, 8 months
Weld SVN: r6128 - examples/trunk.
by weld-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-04-20 14:39:00 -0400 (Tue, 20 Apr 2010)
New Revision: 6128
Modified:
examples/trunk/build.xml
Log:
restore properties
Modified: examples/trunk/build.xml
===================================================================
--- examples/trunk/build.xml 2010-04-20 17:58:13 UTC (rev 6127)
+++ examples/trunk/build.xml 2010-04-20 18:39:00 UTC (rev 6128)
@@ -27,6 +27,14 @@
<condition property="artifact.target.dir" value="${basedir}/ear/target">
<equals arg1="${type}" arg2="ear" />
</condition>
+ <condition property="war">
+ <equals arg1="${type}" arg2="war" />
+ </condition>
+ <condition property="ear">
+ <equals arg1="${type}" arg2="ear" />
+ </condition>
+
+
<property name="ds.file" location="${basedir}/${example.name}-ds.xml" />
@@ -109,7 +117,6 @@
</target>
<target name="restart.war" depends="explode" if="war">
- <touch file="${jboss.home}/server/default/deploy/${example.name}.war" />
<touch file="${jboss.home}/server/default/deploy/${example.name}.war/WEB-INF/web.xml" />
</target>
14 years, 8 months
Weld SVN: r6127 - in core/trunk: impl/src/main/java/org/jboss/weld/bean/builtin/ee and 8 other directories.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-20 13:58:13 -0400 (Tue, 20 Apr 2010)
New Revision: 6127
Added:
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractBeanInstance.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/BeanInstance.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ContextBeanInstance.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseTargetBeanInstance.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/Proxy.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/TargetBeanInstance.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java
Removed:
core/trunk/impl/src/main/java/org/jboss/weld/util/CleanableMethodHandler.java
core/trunk/impl/src/main/java/org/jboss/weld/util/JavassistCleaner.java
Modified:
core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/AbstractEEBean.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java
core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java
core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java
core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java
core/trunk/tests/src/main/java/org/jboss/weld/test/Utils.java
core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/enterprise/EnterpriseBeanProxyTest.java
Log:
WELD-453 WELD-482 WELD-483 Mostly changes to our proxy class generation process
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/AbstractClassBean.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -52,10 +52,11 @@
import org.jboss.interceptor.model.InterceptionModelBuilder;
import org.jboss.interceptor.model.InterceptorMetadata;
import org.jboss.interceptor.util.InterceptionUtils;
-import org.jboss.interceptor.util.proxy.TargetInstanceProxy;
import org.jboss.weld.bean.interceptor.InterceptionMetadataService;
import org.jboss.weld.bean.interceptor.WeldClassReference;
import org.jboss.weld.bean.proxy.DecorationHelper;
+import org.jboss.weld.bean.proxy.ProxyFactory;
+import org.jboss.weld.bean.proxy.TargetBeanInstance;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.context.SerializableContextualImpl;
import org.jboss.weld.ejb.EJBApiAbstraction;
@@ -71,8 +72,6 @@
import org.jboss.weld.metadata.cache.MetaAnnotationStore;
import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.jboss.weld.util.Beans;
-import org.jboss.weld.util.Proxies;
-import org.jboss.weld.util.Proxies.TypeInfo;
import org.jboss.weld.util.reflection.SecureReflections;
import org.slf4j.cal10n.LocLogger;
@@ -184,10 +183,6 @@
public void initializeAfterBeanDiscovery()
{
initDecorators();
- if (hasDecorators())
- {
- initProxyClassForDecoratedBean();
- }
super.initializeAfterBeanDiscovery();
}
@@ -201,15 +196,12 @@
return this.decorators != null && this.decorators.size() > 0;
}
- protected void initProxyClassForDecoratedBean()
- {
- this.proxyClassForDecorators = Proxies.createProxyClass(TypeInfo.of(getTypes()).add(TargetInstanceProxy.class));
- }
-
protected T applyDecorators(T instance, CreationalContext<T> creationalContext, InjectionPoint originalInjectionPoint)
{
T proxy = null;
- DecorationHelper<T> decorationHelper = new DecorationHelper(instance, proxyClassForDecorators, beanManager, decorators);
+ TargetBeanInstance beanInstance = new TargetBeanInstance(this, instance);
+ ProxyFactory<T> proxyFactory = new ProxyFactory<T>(beanInstance);
+ DecorationHelper<T> decorationHelper = new DecorationHelper<T>(beanInstance, proxyFactory.getProxyClass(), beanManager, decorators);
DecorationHelper.getHelperStack().push(decorationHelper);
proxy = decorationHelper.getNextDelegate(originalInjectionPoint, creationalContext);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/DecoratorImpl.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -29,7 +29,6 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -39,6 +38,9 @@
import javax.inject.Inject;
import org.jboss.weld.bean.proxy.AbstractDecoratorMethodHandler;
+import org.jboss.weld.bean.proxy.DecoratorProxyFactory;
+import org.jboss.weld.bean.proxy.ProxyFactory;
+import org.jboss.weld.bean.proxy.TargetBeanInstance;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.injection.MethodInjectionPoint;
@@ -53,7 +55,6 @@
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.util.Decorators;
-import org.jboss.weld.util.Proxies;
import org.jboss.weld.util.reflection.Reflections;
public class DecoratorImpl<T> extends ManagedBean<T> implements WeldDecorator<T>
@@ -141,6 +142,15 @@
protected void initDelegateInjectionPoint()
{
this.delegateInjectionPoint = getDelegateInjectionPoints().iterator().next();
+ if (getWeldAnnotated().isAbstract())
+ {
+ Class<T> clazz = new DecoratorProxyFactory<T>(getWeldAnnotated().getJavaClass(), delegateInjectionPoint).getProxyClass();
+ proxyClassForAbstractDecorators = beanManager.getServices().get(ClassTransformer.class).loadClass(clazz);
+ constructorForAbstractDecorator = WeldConstructorImpl.of(
+ proxyClassForAbstractDecorators.getDeclaredWeldConstructor(getConstructor().getSignature()),
+ proxyClassForAbstractDecorators,
+ beanManager.getServices().get(ClassTransformer.class));
+ }
}
@Override
@@ -250,31 +260,6 @@
}
@Override
- protected void initType()
- {
- super.initType();
- if (getWeldAnnotated().isAbstract())
- {
- Proxies.TypeInfo typeInfo = Proxies.TypeInfo.of(Collections.singleton(getWeldAnnotated().getJavaClass()));
- Class<T> clazz = Proxies.createProxyClass(null, typeInfo);
- proxyClassForAbstractDecorators = beanManager.getServices().get(ClassTransformer.class).loadClass(clazz);
- }
- }
-
- @Override
- protected void initConstructor()
- {
- super.initConstructor();
- if (getWeldAnnotated().isAbstract())
- {
- constructorForAbstractDecorator = WeldConstructorImpl.of(
- proxyClassForAbstractDecorators.getDeclaredWeldConstructor(getConstructor().getSignature()),
- proxyClassForAbstractDecorators,
- beanManager.getServices().get(ClassTransformer.class));
- }
- }
-
- @Override
public void initDecorators()
{
// No-op, decorators can't have decorators
@@ -291,7 +276,6 @@
{
ProxyClassConstructorInjectionPointWrapper<T> constructorInjectionPointWrapper = new ProxyClassConstructorInjectionPointWrapper<T>(this, constructorForAbstractDecorator, getConstructor());
T instance = constructorInjectionPointWrapper.newInstance(beanManager, ctx);
- Proxies.attachMethodHandler(instance, new AbstractDecoratorMethodHandler(annotatedDelegateItem, getDelegateInjectionPoint(), constructorInjectionPointWrapper.getInjectedDelegate()));
return instance;
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/ManagedBean.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -52,6 +52,8 @@
import org.jboss.weld.bean.interceptor.ClassInterceptionHandlerFactory;
import org.jboss.weld.bean.interceptor.InterceptionMetadataService;
import org.jboss.weld.bean.interceptor.WeldClassReference;
+import org.jboss.weld.bean.proxy.ProxyFactory;
+import org.jboss.weld.bean.proxy.TargetBeanInstance;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.exceptions.DefinitionException;
import org.jboss.weld.exceptions.DeploymentException;
@@ -67,7 +69,6 @@
import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.Beans;
-import org.jboss.weld.util.CleanableMethodHandler;
import org.jboss.weld.util.reflection.Reflections;
import org.slf4j.cal10n.LocLogger;
import org.slf4j.ext.XLogger;
@@ -581,8 +582,10 @@
if (interceptionRegistries.size() > 0)
{
InterceptorProxyCreatorImpl interceptorProxyCreator = new InterceptorProxyCreatorImpl(interceptionRegistries, interceptionHandlerFactories);
- MethodHandler methodHandler = new CleanableMethodHandler(interceptorProxyCreator.createMethodHandler(instance, getType(), getBeanManager().getServices().get(InterceptionMetadataService.class).getInterceptorMetadataRegistry().getInterceptorClassMetadata(WeldClassReference.of(getWeldAnnotated()), true)));
- instance = interceptorProxyCreator.createProxyInstance(InterceptionUtils.createProxyClassWithHandler(getType(), methodHandler), methodHandler);
+ MethodHandler methodHandler = interceptorProxyCreator.createMethodHandler(instance, getType(), getBeanManager().getServices().get(InterceptionMetadataService.class).getInterceptorMetadataRegistry().getInterceptorClassMetadata(WeldClassReference.of(getWeldAnnotated()), true));
+ TargetBeanInstance targetInstance = new TargetBeanInstance(this, instance);
+ targetInstance.setInterceptorsHandler(methodHandler);
+ instance = new ProxyFactory<T>(targetInstance).create(targetInstance);
}
}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/SessionBean.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -30,7 +30,6 @@
import static org.jboss.weld.logging.messages.BeanMessage.SCOPE_NOT_ALLOWED_ON_STATELESS_SESSION_BEAN;
import static org.jboss.weld.logging.messages.BeanMessage.SPECIALIZING_ENTERPRISE_BEAN_MUST_EXTEND_AN_ENTERPRISE_BEAN;
-import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -55,7 +54,10 @@
import org.jboss.weld.bean.interceptor.InterceptorBindingsAdapter;
import org.jboss.weld.bean.proxy.EnterpriseBeanInstance;
import org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler;
+import org.jboss.weld.bean.proxy.EnterpriseProxyFactory;
+import org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance;
import org.jboss.weld.bean.proxy.Marker;
+import org.jboss.weld.bean.proxy.ProxyFactory;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.ejb.InternalEjbDescriptor;
import org.jboss.weld.ejb.api.SessionObjectReference;
@@ -74,8 +76,6 @@
import org.jboss.weld.serialization.spi.helpers.SerializableContextual;
import org.jboss.weld.util.AnnotatedTypes;
import org.jboss.weld.util.Beans;
-import org.jboss.weld.util.Proxies;
-import org.jboss.weld.util.Proxies.TypeInfo;
import org.jboss.weld.util.reflection.HierarchyDiscovery;
import org.jboss.weld.util.reflection.SecureReflections;
@@ -245,7 +245,7 @@
protected void initProxyClass()
{
- this.proxyClass = Proxies.createProxyClass(TypeInfo.of(getTypes()).add(EnterpriseBeanInstance.class).add(Serializable.class));
+ this.proxyClass = new EnterpriseProxyFactory<T>(getWeldAnnotated().getJavaClass()).getProxyClass();
}
/**
@@ -322,7 +322,7 @@
{
T instance = SecureReflections.newInstance(proxyClass);
creationalContext.push(instance);
- Proxies.attachMethodHandler(instance, new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext));
+ ProxyFactory.setBeanInstance(instance, new EnterpriseTargetBeanInstance(getWeldAnnotated().getJavaClass(), new EnterpriseBeanProxyMethodHandler<T>(SessionBean.this, creationalContext)));
if (hasDecorators())
{
instance = applyDecorators(instance, creationalContext, null);
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/AbstractEEBean.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/AbstractEEBean.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/AbstractEEBean.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -16,10 +16,6 @@
*/
package org.jboss.weld.bean.builtin.ee;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
-
-import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;
@@ -29,16 +25,15 @@
import org.jboss.weld.bean.builtin.AbstractBuiltInBean;
import org.jboss.weld.bean.builtin.CallableMethodHandler;
-import org.jboss.weld.exceptions.DefinitionException;
+import org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance;
+import org.jboss.weld.bean.proxy.ProxyFactory;
import org.jboss.weld.manager.BeanManagerImpl;
-import org.jboss.weld.util.Proxies;
-import org.jboss.weld.util.Proxies.TypeInfo;
public abstract class AbstractEEBean<T> extends AbstractBuiltInBean<T>
{
-
- private final T proxy;
- private final Class<T> type;
+
+ private final T proxy;
+ private final Class<T> type;
private final Set<Type> types;
protected AbstractEEBean(Class<T> type, Callable<T> callable, BeanManagerImpl beanManager)
@@ -48,36 +43,25 @@
this.types = new HashSet<Type>();
this.types.add(Object.class);
this.types.add(type);
- try
- {
- this.proxy = Proxies.<T>createProxy(new CallableMethodHandler(callable), TypeInfo.of(getTypes()).add(Serializable.class));
- }
- catch (InstantiationException e)
- {
- throw new DefinitionException(PROXY_INSTANTIATION_FAILED, e, this);
- }
- catch (IllegalAccessException e)
- {
- throw new DefinitionException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
- }
+ this.proxy = new ProxyFactory<T>(type).create(new EnterpriseTargetBeanInstance(type, new CallableMethodHandler(callable)));
}
public T create(CreationalContext<T> creationalContext)
{
return proxy;
}
-
- public void destroy(T instance, CreationalContext<T> creationalContext)
+
+ public void destroy(T instance, CreationalContext<T> creationalContext)
{
// no-op
}
-
+
@Override
public Class<T> getType()
{
return type;
}
-
+
public Set<Type> getTypes()
{
return types;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/builtin/ee/EEResourceProducerField.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -18,8 +18,6 @@
import static org.jboss.weld.logging.messages.BeanMessage.BEAN_NOT_EE_RESOURCE_PRODUCER;
import static org.jboss.weld.logging.messages.BeanMessage.INVALID_RESOURCE_PRODUCER_FIELD;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
import java.io.Serializable;
@@ -30,34 +28,32 @@
import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.bean.ProducerField;
import org.jboss.weld.bean.builtin.CallableMethodHandler;
+import org.jboss.weld.bean.proxy.BeanInstance;
+import org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance;
+import org.jboss.weld.bean.proxy.ProxyFactory;
import org.jboss.weld.bootstrap.BeanDeployerEnvironment;
import org.jboss.weld.ejb.EJBApiAbstraction;
import org.jboss.weld.exceptions.ForbiddenStateException;
-import org.jboss.weld.exceptions.WeldException;
import org.jboss.weld.introspector.WeldField;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.persistence.PersistenceApiAbstraction;
import org.jboss.weld.serialization.spi.ContextualStore;
-import org.jboss.weld.util.Proxies;
-import org.jboss.weld.util.Proxies.TypeInfo;
import org.jboss.weld.util.reflection.Reflections;
import org.jboss.weld.ws.WSApiAbstraction;
/**
* @author pmuir
- *
*/
public class EEResourceProducerField<X, T> extends ProducerField<X, T>
{
-
-
+
private static class EEResourceCallable<T> extends AbstractEECallable<T>
{
-
- private static final long serialVersionUID = 6287931036073200963L;
-
- private final String beanId;
- private transient T instance;
+
+ private static final long serialVersionUID = 6287931036073200963L;
+
+ private final String beanId;
+ private transient T instance;
private final CreationalContext<T> creationalContext;
public EEResourceCallable(BeanManagerImpl beanManager, ProducerField<?, T> producerField, CreationalContext<T> creationalContext)
@@ -71,12 +67,12 @@
{
if (instance == null)
{
- Contextual<T> contextual = Container.instance().services().get(ContextualStore.class).<Contextual<T>, T>getContextual(beanId);
+ Contextual<T> contextual = Container.instance().services().get(ContextualStore.class).<Contextual<T>, T> getContextual(beanId);
if (contextual instanceof EEResourceProducerField<?, ?>)
{
@SuppressWarnings("unchecked")
EEResourceProducerField<?, T> bean = (EEResourceProducerField<?, T>) contextual;
-
+
this.instance = bean.createUnderlying(creationalContext);
}
else
@@ -86,15 +82,15 @@
}
return instance;
}
-
+
@Override
public String toString()
{
return beanId;
}
-
+
}
-
+
/**
* Creates an EE resource producer field
*
@@ -112,7 +108,7 @@
{
super(field, declaringBean, manager);
}
-
+
@Override
public void initialize(BeanDeployerEnvironment environment)
{
@@ -122,7 +118,7 @@
checkEEResource();
}
}
-
+
protected void checkEEResource()
{
EJBApiAbstraction ejbApiAbstraction = beanManager.getServices().get(EJBApiAbstraction.class);
@@ -133,31 +129,21 @@
throw new ForbiddenStateException(INVALID_RESOURCE_PRODUCER_FIELD, getWeldAnnotated());
}
}
-
+
@Override
public T create(CreationalContext<T> creationalContext)
{
- try
+ if (Reflections.isFinal(getWeldAnnotated().getJavaClass()) || Serializable.class.isAssignableFrom(getWeldAnnotated().getJavaClass()))
{
- if (Reflections.isFinal(getWeldAnnotated().getJavaClass()) || Serializable.class.isAssignableFrom(getWeldAnnotated().getJavaClass()))
- {
- return createUnderlying(creationalContext);
- }
- else
- {
- return Proxies.<T>createProxy(new CallableMethodHandler(new EEResourceCallable<T>(getBeanManager(), this, creationalContext)), TypeInfo.of(getTypes()).add(Serializable.class));
- }
+ return createUnderlying(creationalContext);
}
- catch (InstantiationException e)
+ else
{
- throw new WeldException(PROXY_INSTANTIATION_FAILED, e, this);
+ BeanInstance proxyBeanInstance = new EnterpriseTargetBeanInstance(getTypes(), new CallableMethodHandler(new EEResourceCallable<T>(getBeanManager(), this, creationalContext)));
+ return new ProxyFactory<T>(proxyBeanInstance).create(proxyBeanInstance);
}
- catch (IllegalAccessException e)
- {
- throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
- }
}
-
+
/**
* Access to the underlying producer field
*/
@@ -165,12 +151,11 @@
{
return super.create(creationalContext);
}
-
+
@Override
public boolean isPassivationCapableBean()
{
return true;
}
-
}
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractBeanInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractBeanInstance.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractBeanInstance.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import static org.jboss.weld.logging.Category.BEAN;
+import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.weld.util.Proxies.TypeInfo;
+import org.jboss.weld.util.reflection.SecureReflections;
+import org.slf4j.cal10n.LocLogger;
+
+/**
+ * @author David Allen
+ */
+public abstract class AbstractBeanInstance implements BeanInstance
+{
+ // The log provider
+ protected static final LocLogger log = loggerFactory().getLogger(BEAN);
+
+ public Object invoke(Method method, Object... arguments) throws Throwable
+ {
+ Object result = null;
+ try
+ {
+ SecureReflections.ensureAccessible(method);
+ result = method.invoke(getInstance(), arguments);
+ }
+ catch (InvocationTargetException e)
+ {
+ throw e.getCause();
+ }
+ return result;
+ }
+
+ protected Class<?> computeInstanceType(Bean<?> bean)
+ {
+ return computeInstanceType(bean.getTypes());
+ }
+
+ protected Class<?> computeInstanceType(Set<Type> types)
+ {
+ TypeInfo typeInfo = TypeInfo.of(types);
+ Class<?> superClass = typeInfo.getSuperClass();
+ if (superClass.equals(Object.class))
+ {
+ superClass = typeInfo.getSuperInterface();
+ }
+ return superClass;
+ }
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/AbstractBeanInstance.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/BeanInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/BeanInstance.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/BeanInstance.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import java.lang.reflect.Method;
+
+/**
+ * Each proxy maintains a single bean instance on which methods
+ * are invoked. Different types of bean instances can also
+ * be used to provide varying methods of obtaining the actual
+ * instance from the container.
+ *
+ * @author David Allen
+ *
+ */
+public interface BeanInstance
+{
+ /**
+ * Returns the current instance for a proxy.
+ *
+ * @return the current bean instance
+ */
+ public Object getInstance();
+
+ public Class<?> getInstanceType();
+
+ public Object invoke(Method method, Object... arguments) throws Throwable;
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/BeanInstance.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ClientProxyProvider.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -17,22 +17,14 @@
package org.jboss.weld.bean.proxy;
import static org.jboss.weld.logging.messages.BeanMessage.BEAN_ID_CREATION_FAILED;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
-import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
-import java.io.Serializable;
import java.util.concurrent.ConcurrentMap;
import javax.enterprise.inject.spi.Bean;
-import org.jboss.interceptor.proxy.LifecycleMixin;
import org.jboss.weld.Container;
-import org.jboss.weld.bean.AbstractClassBean;
import org.jboss.weld.exceptions.DefinitionException;
-import org.jboss.weld.exceptions.WeldException;
import org.jboss.weld.serialization.spi.ContextualStore;
-import org.jboss.weld.util.Proxies;
-import org.jboss.weld.util.Proxies.TypeInfo;
import com.google.common.base.Function;
import com.google.common.collect.MapMaker;
@@ -91,27 +83,29 @@
*/
private static <T> T createClientProxy(Bean<T> bean, String id) throws RuntimeException
{
- try
- {
- TypeInfo typeInfo;
- if ((bean instanceof AbstractClassBean) && ((AbstractClassBean)bean).hasInterceptors())
- {
- typeInfo = TypeInfo.of(bean.getTypes()).add(Serializable.class).add(LifecycleMixin.class);
- }
- else
- {
- typeInfo = TypeInfo.of(bean.getTypes()).add(Serializable.class);
- }
- return Proxies.<T>createProxy(new ClientProxyMethodHandler(bean, id), typeInfo);
- }
- catch (InstantiationException e)
- {
- throw new WeldException(PROXY_INSTANTIATION_FAILED, e, bean);
- }
- catch (IllegalAccessException e)
- {
- throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, bean);
- }
+ ContextBeanInstance<T> beanInstance = new ContextBeanInstance<T>(bean, id);
+ return new ProxyFactory<T>(beanInstance).create(beanInstance);
+// try
+// {
+// TypeInfo typeInfo;
+// if ((bean instanceof AbstractClassBean) && ((AbstractClassBean)bean).hasInterceptors())
+// {
+// typeInfo = TypeInfo.of(bean.getTypes()).add(Serializable.class).add(LifecycleMixin.class);
+// }
+// else
+// {
+// typeInfo = TypeInfo.of(bean.getTypes()).add(Serializable.class);
+// }
+// return Proxies.<T>createProxy(new ClientProxyMethodHandler(bean, id), typeInfo);
+// }
+// catch (InstantiationException e)
+// {
+// throw new WeldException(PROXY_INSTANTIATION_FAILED, e, bean);
+// }
+// catch (IllegalAccessException e)
+// {
+// throw new WeldException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, bean);
+// }
}
/**
@@ -123,6 +117,7 @@
* @param bean The bean to get a proxy to
* @return the client proxy for the bean
*/
+ @SuppressWarnings("unchecked")
public <T> T getClientProxy(final Bean<T> bean)
{
return (T) pool.get(bean);
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ContextBeanInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ContextBeanInstance.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ContextBeanInstance.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.spi.Context;
+import javax.enterprise.inject.spi.Bean;
+
+import org.jboss.weld.Container;
+import org.jboss.weld.context.CreationalContextImpl;
+import org.jboss.weld.context.WeldCreationalContext;
+import org.jboss.weld.injection.CurrentInjectionPoint;
+import org.jboss.weld.injection.SimpleInjectionPoint;
+import org.jboss.weld.serialization.spi.ContextualStore;
+
+/**
+ * An instance locator that uses a context to lookup the instance if
+ * it exists; otherwise, a new instance will be created from the
+ * bean.
+ *
+ * @author David Allen
+ *
+ */
+public class ContextBeanInstance<T> extends AbstractBeanInstance implements Serializable
+{
+
+ private static final long serialVersionUID = -8144230657830556503L;
+ // The bean
+ private transient Bean<T> bean;
+ // The bean index in the manager
+ private final String id;
+ // The actual type of the resulting bean instance
+ private final Class<?> instanceType;
+
+ private static final ThreadLocal<WeldCreationalContext<?>> currentCreationalContext = new ThreadLocal<WeldCreationalContext<?>>();
+
+ /**
+ * Creates a new locator for instances of the given bean.
+ *
+ * @param bean The contextual bean
+ * @param id The unique identifier of this bean
+ */
+ public ContextBeanInstance(Bean<T> bean, String id)
+ {
+ this.bean = bean;
+ this.id = id;
+ this.instanceType = computeInstanceType(bean);
+ log.trace("Created context instance locator for bean " + bean + " identified as " + id);
+ }
+
+ public T getInstance()
+ {
+ if (bean == null)
+ {
+ bean = Container.instance().services().get(ContextualStore.class).<Bean<T>, T>getContextual(id);
+ }
+ Context context = Container.instance().deploymentManager().getContext(bean.getScope());
+ WeldCreationalContext<T> creationalContext;
+ WeldCreationalContext<?> previousCreationalContext = currentCreationalContext.get();
+ if (currentCreationalContext.get() == null)
+ {
+ creationalContext = new CreationalContextImpl<T>(bean);
+ }
+ else
+ {
+ creationalContext = currentCreationalContext.get().getCreationalContext(bean);
+ }
+ currentCreationalContext.set(creationalContext);
+ try
+ {
+ // Ensure that there is no injection point associated
+ Container.instance().services().get(CurrentInjectionPoint.class).push(SimpleInjectionPoint.EMPTY_INJECTION_POINT);
+ return context.get(bean, creationalContext);
+ }
+ finally
+ {
+ Container.instance().services().get(CurrentInjectionPoint.class).pop();
+ if (previousCreationalContext == null)
+ {
+ currentCreationalContext.remove();
+ }
+ else
+ {
+ currentCreationalContext.set(previousCreationalContext);
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<T> getInstanceType()
+ {
+ return (Class<T>) instanceType;
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ContextBeanInstance.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecorationHelper.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -47,8 +47,10 @@
}
};
- private Class<T> proxyClassForDecorator;
+ private final Class<T> proxyClassForDecorator;
+ private final TargetBeanInstance targetBeanInstance;
+
private T originalInstance;
private T previousDelegate;
@@ -59,9 +61,11 @@
List<Decorator<?>> decorators;
- public DecorationHelper(T originalInstance, Class<T> proxyClassForDecorator, BeanManagerImpl beanManager, List<Decorator<?>> decorators)
+ @SuppressWarnings("unchecked")
+ public DecorationHelper(TargetBeanInstance originalInstance, Class<T> proxyClassForDecorator, BeanManagerImpl beanManager, List<Decorator<?>> decorators)
{
- this.originalInstance = originalInstance;
+ this.originalInstance = (T) originalInstance.getInstance();
+ this.targetBeanInstance = originalInstance;
this.beanManager = beanManager;
this.decorators = new LinkedList<Decorator<?>>(decorators);
this.proxyClassForDecorator = proxyClassForDecorator;
@@ -92,7 +96,9 @@
try
{
T proxy = SecureReflections.newInstance(proxyClassForDecorator);
- Proxies.attachMethodHandler(proxy, createMethodHandler(injectionPoint, creationalContext, (Decorator<Object>) decorators.get(counter++)));
+ TargetBeanInstance newTargetBeanInstance = new TargetBeanInstance(targetBeanInstance);
+ newTargetBeanInstance.setInterceptorsHandler(createMethodHandler(injectionPoint, creationalContext, (Decorator<Object>) decorators.get(counter++)));
+ ProxyFactory.setBeanInstance(proxy, newTargetBeanInstance);
previousDelegate = proxy;
return proxy;
}
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,237 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtMethod;
+import javassist.CtNewConstructor;
+import javassist.CtNewMethod;
+import javassist.NotFoundException;
+
+import javax.decorator.Delegate;
+
+import org.jboss.weld.exceptions.WeldException;
+import org.jboss.weld.injection.FieldInjectionPoint;
+import org.jboss.weld.injection.ParameterInjectionPoint;
+import org.jboss.weld.injection.WeldInjectionPoint;
+
+/**
+ * This special proxy factory is mostly used for abstract decorators. When
+ * a delegate field is injected, the abstract methods directly invoke the
+ * corresponding method on the delegate. All other cases forward the calls
+ * to the {@link BeanInstance} for further processing.
+ *
+ * @author David Allen
+ */
+public class DecoratorProxyFactory<T> extends ProxyFactory<T>
+{
+ private static final String PROXY_SUFFIX = "DecoratorProxy";
+ private final WeldInjectionPoint<?, ?> delegateInjectionPoint;
+ private final CtClass delegateClass;
+ private final Field delegateField;
+
+ public DecoratorProxyFactory(Class<T> proxyType, WeldInjectionPoint<?, ?> delegateInjectionPoint)
+ {
+ super(proxyType);
+ this.delegateInjectionPoint = delegateInjectionPoint;
+ try
+ {
+ delegateClass = classPool.get(((Class<?>) delegateInjectionPoint.getBaseType()).getName());
+ }
+ catch (NotFoundException e)
+ {
+ throw new WeldException(e);
+ }
+ if (delegateInjectionPoint instanceof FieldInjectionPoint<?, ?>)
+ {
+ delegateField = ((FieldInjectionPoint<?, ?>) delegateInjectionPoint).getJavaMember();
+ }
+ else
+ {
+ delegateField = null;
+ }
+ }
+
+ @Override
+ protected void addConstructors(CtClass proxyClassType)
+ {
+ try
+ {
+ CtClass baseType = classPool.get(beanType.getName());
+ for (CtConstructor constructor : baseType.getConstructors())
+ {
+ int delegateInjectionPosition = getDelegateInjectionPosition(constructor);
+ if (delegateInjectionPosition >= 0)
+ {
+ proxyClassType.addConstructor(CtNewConstructor.make(constructor.getParameterTypes(), constructor.getExceptionTypes(), createDelegateInitializerCode(null, delegateInjectionPosition), proxyClassType));
+ }
+ else
+ {
+ proxyClassType.addConstructor(CtNewConstructor.copy(constructor, proxyClassType, null));
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ @Override
+ protected void addMethodsFromClass(CtClass proxyClassType)
+ {
+ String initializerMethod = null;
+ int delegateParameterPosition = -1;
+ if (delegateInjectionPoint instanceof ParameterInjectionPoint<?, ?>)
+ {
+ ParameterInjectionPoint<?, ?> parameterIP = (ParameterInjectionPoint<?, ?>) delegateInjectionPoint;
+ if (parameterIP.getMember() instanceof Method)
+ {
+ initializerMethod = ((Method) parameterIP.getMember()).getName();
+ delegateParameterPosition = parameterIP.getPosition();
+ }
+ }
+ try
+ {
+ for (CtMethod method : proxyClassType.getMethods())
+ {
+ if (!method.getDeclaringClass().getName().equals("java.lang.Object") || method.getName().equals("toString"))
+ {
+ log.trace("Adding method " + method.getLongName());
+ String methodBody = null;
+ if ((delegateParameterPosition >= 0) && (initializerMethod.equals(method.getName())))
+ {
+ methodBody = createDelegateInitializerCode(initializerMethod, delegateParameterPosition);
+ }
+ else if (Modifier.isAbstract(method.getModifiers()))
+ {
+ methodBody = createAbstractMethodCode(method);
+ }
+
+ if (methodBody != null)
+ {
+ proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(), method.getName(), method.getParameterTypes(), method.getExceptionTypes(), methodBody, proxyClassType));
+ }
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ @Override
+ protected String getProxyNameSuffix()
+ {
+ return PROXY_SUFFIX;
+ }
+
+ private String createAbstractMethodCode(CtMethod method) throws NotFoundException
+ {
+ CtMethod delegateMethod = null;
+ StringBuilder bodyString = new StringBuilder();
+ bodyString.append("{ ");
+ try
+ {
+ delegateMethod = delegateClass.getMethod(method.getName(), method.getSignature());
+ if (method.getReturnType() != null)
+ {
+ bodyString.append("return ($r)");
+ }
+ }
+ catch (NotFoundException e)
+ {
+ throw new WeldException(e);
+ }
+
+ if ((delegateField != null) && (!Modifier.isPrivate(delegateField.getModifiers())))
+ {
+ // Call the corresponding method directly on the delegate
+ bodyString.append(delegateField.getName());
+ bodyString.append('.');
+ bodyString.append(method.getName());
+ bodyString.append("($$); }");
+ log.trace("Delegating call directly to delegate for method " + method.getLongName());
+ }
+ else
+ {
+ // Use the associated bean instance to invoke the method
+ bodyString.append("beanInstance.invoke(");
+ if (Modifier.isPublic(delegateMethod.getModifiers()))
+ {
+ bodyString.append("beanInstance.getInstanceType().getMethod(\"");
+ log.trace("Using getMethod in proxy for method " + method.getLongName());
+ }
+ else
+ {
+ bodyString.append(method.getDeclaringClass().getName());
+ bodyString.append(".class.getDeclaredMethod(\"");
+ log.trace("Using getDeclaredMethod in proxy for method " + method.getLongName());
+ }
+ bodyString.append(method.getName());
+ bodyString.append("\", ");
+ bodyString.append(getSignatureClasses(method));
+ bodyString.append("), $args); }");
+ }
+
+ return bodyString.toString();
+ }
+
+ private String createDelegateInitializerCode(String initializerName, int delegateParameterPosition)
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append("{ super");
+ if (initializerName != null)
+ {
+ buffer.append('.');
+ buffer.append(initializerName);
+ }
+ buffer.append("($$);\n");
+ buffer.append("beanInstance = new ");
+ buffer.append(TargetBeanInstance.class.getName());
+ buffer.append("($");
+ buffer.append(delegateParameterPosition + 1);
+ buffer.append("); }");
+ return buffer.toString();
+ }
+
+ private int getDelegateInjectionPosition(CtConstructor constructor)
+ {
+ int position = -1;
+ Object[][] parameterAnnotations = constructor.getAvailableParameterAnnotations();
+ for (int i = 0; i < parameterAnnotations.length; i++)
+ {
+ for (int j = 0; j < parameterAnnotations[i].length; j++)
+ {
+ if (parameterAnnotations[i][j] instanceof Delegate)
+ {
+ position = i;
+ break;
+ }
+ }
+ }
+ return position;
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import javassist.CtClass;
+import javassist.CtConstructor;
+import javassist.CtNewConstructor;
+
+import org.jboss.weld.exceptions.WeldException;
+
+/**
+ * This factory produces proxies specific for enterprise beans, in particular
+ * session beans. It adds the interface {@link EnterpriseBeanInstance} to
+ * each proxy class.
+ *
+ * @author David Allen
+ */
+public class EnterpriseProxyFactory<T> extends ProxyFactory<T>
+{
+ private static final String PROXY_SUFFIX = "EnterpriseProxy";
+
+ /**
+ * Produces a factory for a specific bean implementation.
+ *
+ * @param proxiedBeanType the actual enterprise bean
+ */
+ public EnterpriseProxyFactory(Class<T> proxiedBeanType)
+ {
+ super(proxiedBeanType);
+ addInterface(EnterpriseBeanInstance.class);
+ }
+
+ // Not sure this is a useful approach, but non-default constructors are problematic (DRA)
+ @Override
+ protected void addConstructors(CtClass proxyClassType)
+ {
+ try
+ {
+ CtClass baseType = classPool.get(beanType.getName());
+ for (CtConstructor constructor : baseType.getConstructors())
+ {
+ proxyClassType.addConstructor(CtNewConstructor.copy(constructor, proxyClassType, null));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ @Override
+ protected String getProxyNameSuffix()
+ {
+ return PROXY_SUFFIX;
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseProxyFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseTargetBeanInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseTargetBeanInstance.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseTargetBeanInstance.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Set;
+
+import javassist.util.proxy.MethodHandler;
+
+/**
+ * @author David Allen
+ */
+public class EnterpriseTargetBeanInstance extends AbstractBeanInstance implements Serializable
+{
+ private static final long serialVersionUID = 2825052095047112162L;
+
+ private final Class<?> beanType;
+ private final MethodHandler methodHandler;
+
+ public EnterpriseTargetBeanInstance(Class<?> baseType, MethodHandler methodHandler)
+ {
+ this.beanType = baseType;
+ this.methodHandler = methodHandler;
+ }
+
+ public EnterpriseTargetBeanInstance(Set<Type> types, MethodHandler methodHandler)
+ {
+ this.beanType = computeInstanceType(types);
+ this.methodHandler = methodHandler;
+ }
+
+ public Object getInstance()
+ {
+ return null;
+ }
+
+ public Class<?> getInstanceType()
+ {
+ return beanType;
+ }
+
+ public Object invoke(Method method, Object... arguments) throws Throwable
+ {
+ // Pass the invocation directly to the method handler
+ return methodHandler.invoke(null, method, method, arguments);
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/EnterpriseTargetBeanInstance.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/Proxy.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/Proxy.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/Proxy.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+/**
+ * General interface for all proxies adding functionality that can change
+ * the behavior of the proxy during runtime.
+ *
+ * @author David Allen
+ *
+ */
+public interface Proxy
+{
+ /**
+ * Gets the proxied bean instance.
+ *
+ * @return the bean instance being proxied
+ */
+ public BeanInstance proxy_getInstance();
+
+ /**
+ * Sets the proxied instance.
+ *
+ * @param beanInstance a bean instance to proxy
+ */
+ public void proxy_setInstance(BeanInstance beanInstance);
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/Proxy.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,439 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import static org.jboss.weld.logging.Category.BEAN;
+import static org.jboss.weld.logging.LoggerFactory.loggerFactory;
+import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_BEAN_ACCESS_FAILED;
+import static org.jboss.weld.logging.messages.BeanMessage.PROXY_INSTANTIATION_FAILED;
+
+import java.io.Serializable;
+import java.lang.reflect.Modifier;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.CtField;
+import javassist.CtMethod;
+import javassist.CtNewConstructor;
+import javassist.CtNewMethod;
+import javassist.NotFoundException;
+
+import org.jboss.interceptor.proxy.LifecycleMixin;
+import org.jboss.interceptor.util.proxy.TargetInstanceProxy;
+import org.jboss.weld.bean.proxy.util.ClassloaderClassPath;
+import org.jboss.weld.exceptions.DefinitionException;
+import org.jboss.weld.exceptions.WeldException;
+import org.slf4j.cal10n.LocLogger;
+
+/**
+ * Main factory to produce proxy classes and instances for Weld beans. This
+ * implementation creates proxies which forward non-static method invocations to
+ * a {@link BeanInstance}. All proxies implement the {@link Proxy} interface.
+ *
+ * @author David Allen
+ */
+public class ProxyFactory<T>
+{
+ // The log provider
+ protected static final LocLogger log = loggerFactory().getLogger(BEAN);
+ // Default proxy class name suffix
+ private static final String PROXY_SUFFIX = "Proxy";
+
+ protected final Class<?> beanType;
+ protected final ArrayList<Class<?>> additionalInterfaces = new ArrayList<Class<?>>();
+ protected ClassLoader classLoader;
+ protected ProtectionDomain protectionDomain;
+ protected ClassPool classPool;
+
+ /**
+ * Creates a new proxy factory from any type of BeanInstance. This bean
+ * instance is only used for initialization information and is not associated
+ * with this factory once created.
+ *
+ * @param instance a bean instance that will be used with the proxy
+ */
+ public ProxyFactory(BeanInstance beanInstance)
+ {
+ this.beanType = beanInstance.getInstanceType();
+ init();
+ }
+
+ /**
+ * Creates a new proxy factory with only the type of proxy specified.
+ *
+ * @param proxiedBeanType the super-class for this proxy class
+ */
+ public ProxyFactory(Class<T> proxiedBeanType)
+ {
+ this.beanType = proxiedBeanType;
+ init();
+ }
+
+ /**
+ * Initializes the proxy factory.
+ */
+ private void init()
+ {
+ classLoader = beanType.getClassLoader();
+ protectionDomain = beanType.getProtectionDomain();
+ if (beanType.getName().startsWith("java."))
+ {
+ classLoader = this.getClass().getClassLoader();
+ protectionDomain = this.getClass().getProtectionDomain();
+ }
+ classPool = new ClassPool();
+ classPool.appendClassPath(new ClassloaderClassPath(classLoader));
+ addDefaultAdditionalInterfaces();
+ }
+
+ /**
+ * Adds an additional interface that the proxy should implement. The default
+ * implementation will be to forward invocations to the bean instance.
+ *
+ * @param newInterface an interface
+ */
+ public void addInterface(Class<?> newInterface)
+ {
+ if (!newInterface.isInterface())
+ {
+ throw new IllegalArgumentException(newInterface + " is not an interface");
+ }
+ additionalInterfaces.add(newInterface);
+ }
+
+ /**
+ * Method to create a new proxy that wraps the bean instance.
+ *
+ * @return a new proxy object
+ */
+ public T create(BeanInstance beanInstance)
+ {
+ T proxy = null;
+ Class<T> proxyClass = getProxyClass();
+ try
+ {
+ proxy = proxyClass.newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new DefinitionException(PROXY_INSTANTIATION_FAILED, e, this);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new DefinitionException(PROXY_INSTANTIATION_BEAN_ACCESS_FAILED, e, this);
+ }
+ ((Proxy) proxy).proxy_setInstance(beanInstance);
+ return proxy;
+ }
+
+ /**
+ * Produces or returns the existing proxy class.
+ *
+ * @return always the class of the proxy
+ */
+ @SuppressWarnings("unchecked")
+ public Class<T> getProxyClass()
+ {
+ String proxyClassName = beanType.getName() + "_$$_Weld" + getProxyNameSuffix();
+ if (proxyClassName.startsWith("java."))
+ {
+ proxyClassName = proxyClassName.replaceFirst("java", "org.jboss.weld");
+ }
+ Class<T> proxyClass = null;
+ log.trace("Retrieving/generating proxy class " + proxyClassName);
+ try
+ {
+ // First check to see if we already have this proxy class
+ proxyClass = (Class<T>) classLoader.loadClass(proxyClassName);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // Create the proxy class for this instance
+ try
+ {
+ proxyClass = createProxyClass(proxyClassName);
+ }
+ catch (Exception e1)
+ {
+ throw new WeldException(e1);
+ }
+ }
+ return proxyClass;
+ }
+
+ /**
+ * Convenience method to set the underlying bean instance for a proxy.
+ *
+ * @param proxy the proxy instance
+ * @param beanInstance the instance of the bean
+ */
+ public static <T> void setBeanInstance(T proxy, BeanInstance beanInstance)
+ {
+ if (proxy instanceof Proxy)
+ {
+ Proxy proxyView = (Proxy) proxy;
+ proxyView.proxy_setInstance(beanInstance);
+ }
+ }
+
+ /**
+ * Returns a suffix to append to the name of the proxy class. The name
+ * already consists of <class-name>_$$_Weld, to which the suffix is added.
+ * This allows the creation of different types of proxies for the same class.
+ *
+ * @return a name suffix
+ */
+ protected String getProxyNameSuffix()
+ {
+ return PROXY_SUFFIX;
+ }
+
+ private void addDefaultAdditionalInterfaces()
+ {
+ additionalInterfaces.add(Serializable.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ private Class<T> createProxyClass(String proxyClassName) throws Exception
+ {
+ CtClass instanceType = classPool.get(beanType.getName());
+ CtClass proxyClassType = null;
+ if (instanceType.isInterface())
+ {
+ proxyClassType = classPool.makeClass(proxyClassName);
+ proxyClassType.addInterface(instanceType);
+ }
+ else
+ {
+ proxyClassType = classPool.makeClass(proxyClassName, instanceType);
+ }
+
+ // Add interfaces which require method generation
+ for (Class<?> clazz : additionalInterfaces)
+ {
+ proxyClassType.addInterface(classPool.get(clazz.getName()));
+ }
+ addFields(proxyClassType);
+ addConstructors(proxyClassType);
+ addMethods(proxyClassType);
+
+ // Additional interfaces whose methods require special handling
+ proxyClassType.addInterface(classPool.get(Proxy.class.getName()));
+ proxyClassType.addInterface(classPool.get(LifecycleMixin.class.getName()));
+ proxyClassType.addInterface(classPool.get(TargetInstanceProxy.class.getName()));
+
+ Class<T> proxyClass = proxyClassType.toClass(classLoader, protectionDomain);
+ proxyClassType.detach();
+ log.trace("Created Proxy class of type " + proxyClass + " supporting interfaces " + Arrays.toString(proxyClass.getInterfaces()));
+ return proxyClass;
+ }
+
+ /**
+ * Adds a public default constructor to the proxy class for ease of
+ * instantiating it.
+ *
+ * @param proxyClassType the Javassist class for the proxy
+ */
+ protected void addConstructors(CtClass proxyClassType)
+ {
+ try
+ {
+ proxyClassType.addConstructor(CtNewConstructor.defaultConstructor(proxyClassType));
+ }
+ catch (CannotCompileException e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ private void addFields(CtClass proxyClassType)
+ {
+ // The field for the instance locator
+ try
+ {
+ proxyClassType.addField(new CtField(classPool.get("org.jboss.weld.bean.proxy.BeanInstance"), "beanInstance", proxyClassType));
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ private void addMethods(CtClass proxyClassType)
+ {
+ // Add all class methods for interception
+ addMethodsFromClass(proxyClassType);
+
+ // Add special proxy methods
+ addSpecialMethods(proxyClassType);
+ }
+
+ protected void addMethodsFromClass(CtClass proxyClassType)
+ {
+ try
+ {
+ for (CtMethod method : proxyClassType.getMethods())
+ {
+ if (!Modifier.isStatic(method.getModifiers()) && !method.getDeclaringClass().getName().equals("java.lang.Object") || method.getName().equals("toString"))
+ {
+ log.trace("Adding method " + method.getLongName());
+ proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(), method.getName(), method.getParameterTypes(), method.getExceptionTypes(), createInterceptorBody(method), proxyClassType));
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ /**
+ * Creates the given method on the proxy class where the implementation
+ * forwards the call directly to the bean instance.
+ *
+ * @param method any Javassist method
+ * @return a string containing the method body code to be compiled
+ * @throws NotFoundException if any of the parameter types are not found
+ */
+ protected String createInterceptorBody(CtMethod method) throws NotFoundException
+ {
+ StringBuilder bodyString = new StringBuilder();
+ bodyString.append("{ ");
+ try
+ {
+ if (method.getReturnType() != null)
+ {
+ bodyString.append("return ($r)");
+ }
+ }
+ catch (NotFoundException e)
+ {
+ // Assume this is a void method
+ }
+
+ bodyString.append("beanInstance.invoke(");
+ if (Modifier.isPublic(method.getModifiers()))
+ {
+ bodyString.append("beanInstance.getInstanceType().getMethod(\"");
+ log.trace("Using getMethod in proxy for method " + method.getLongName());
+ }
+ else
+ {
+ bodyString.append(method.getDeclaringClass().getName());
+ bodyString.append(".class.getDeclaredMethod(\"");
+ log.trace("Using getDeclaredMethod in proxy for method " + method.getLongName());
+ }
+ bodyString.append(method.getName());
+ bodyString.append("\", ");
+ bodyString.append(getSignatureClasses(method));
+ bodyString.append("), $args); }");
+
+ return bodyString.toString();
+ }
+
+ /**
+ * Produces the code for the list of argument types for the given method.
+ *
+ * @param method the method for which to produce the parameter list
+ * @return a string of comma-delimited class objects
+ * @throws NotFoundException if any of the parameter types are not found by
+ * Javassist
+ */
+ protected String getSignatureClasses(CtMethod method) throws NotFoundException
+ {
+ if (method.getParameterTypes().length > 0)
+ {
+ StringBuilder signatureBuffer = new StringBuilder();
+ signatureBuffer.append("new Class[]{");
+ boolean firstClass = true;
+ for (CtClass clazz : method.getParameterTypes())
+ {
+ if (firstClass)
+ {
+ firstClass = false;
+ }
+ else
+ {
+ signatureBuffer.append(", ");
+ }
+ signatureBuffer.append(clazz.getName());
+ signatureBuffer.append(".class");
+ }
+ signatureBuffer.append('}');
+ return signatureBuffer.toString();
+ }
+ else
+ {
+ return "null";
+ }
+ }
+
+ private void addSpecialMethods(CtClass proxyClassType)
+ {
+ try
+ {
+ // Add public getter/setter pair for the instance locator
+ proxyClassType.addMethod(CtNewMethod.make("public org.jboss.weld.bean.proxy.BeanInstance proxy_getInstance() { return beanInstance; }", proxyClassType));
+ proxyClassType.addMethod(CtNewMethod.make("public void proxy_setInstance(org.jboss.weld.bean.proxy.BeanInstance beanInstance) { this.beanInstance = beanInstance; }", proxyClassType));
+
+ // Add special methods for interceptors
+ CtClass lifecycleMixinClass = classPool.get(LifecycleMixin.class.getName());
+ for (CtMethod method : lifecycleMixinClass.getDeclaredMethods())
+ {
+ log.trace("Adding method " + method.getLongName());
+ proxyClassType.addMethod(CtNewMethod.make(method.getReturnType(), method.getName(), method.getParameterTypes(), method.getExceptionTypes(), createLifecycleBody(method), proxyClassType));
+ }
+ CtClass targetInstanceProxyClass = classPool.get(TargetInstanceProxy.class.getName());
+ CtMethod getInstanceMethod = targetInstanceProxyClass.getDeclaredMethod("getTargetInstance");
+ CtMethod getInstanceClassMethod = targetInstanceProxyClass.getDeclaredMethod("getTargetClass");
+ proxyClassType.addMethod(CtNewMethod.make(getInstanceMethod.getReturnType(), getInstanceMethod.getName(), getInstanceMethod.getParameterTypes(), getInstanceMethod.getExceptionTypes(), "{ return beanInstance.getInstance(); }", proxyClassType));
+ proxyClassType.addMethod(CtNewMethod.make(getInstanceClassMethod.getReturnType(), getInstanceClassMethod.getName(), getInstanceClassMethod.getParameterTypes(), getInstanceClassMethod.getExceptionTypes(), "{ return beanInstance.getInstanceType(); }", proxyClassType));
+ }
+ catch (Exception e)
+ {
+ throw new WeldException(e);
+ }
+ }
+
+ /**
+ * Creates the method body code for lifecycle methods which forward the calls
+ * directly to the bean instance.
+ *
+ * @param method a lifecycle method
+ * @return code for the body of the method to be compiled
+ * @throws NotFoundException if any of the parameter types are not found
+ */
+ private String createLifecycleBody(CtMethod method) throws NotFoundException
+ {
+ StringBuilder bodyString = new StringBuilder();
+ bodyString.append("{ beanInstance.invoke(");
+ bodyString.append(LifecycleMixin.class.getName());
+ bodyString.append(".class.getDeclaredMethod(\"");
+ bodyString.append(method.getName());
+ bodyString.append("\", ");
+ bodyString.append(getSignatureClasses(method));
+ bodyString.append("), $args); }");
+
+ return bodyString.toString();
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/TargetBeanInstance.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/TargetBeanInstance.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/TargetBeanInstance.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import javassist.util.proxy.MethodHandler;
+
+import javax.enterprise.inject.spi.Bean;
+
+/**
+ * A simple {@link BeanInstance} which always maintains a specific bean instance
+ * that is being proxied.
+ *
+ * @author David Allen
+ */
+public class TargetBeanInstance extends AbstractBeanInstance implements Serializable
+{
+ private static final long serialVersionUID = 1099995238604086450L;
+ private final Object instance;
+ private final Class<?> instanceType;
+ private MethodHandler interceptorsHandler;
+
+ public TargetBeanInstance(Bean<?> bean, Object instance)
+ {
+ this.instance = instance;
+ this.instanceType = computeInstanceType(bean);
+ }
+
+ public TargetBeanInstance(Object instance)
+ {
+ this.instance = instance;
+ this.instanceType = (Class<?>) instance.getClass();
+ }
+
+ /**
+ * Copy constructor
+ *
+ * @param otherBeanInstance other bean instance to copy
+ */
+ public TargetBeanInstance(TargetBeanInstance otherBeanInstance)
+ {
+ this.instance = otherBeanInstance.instance;
+ this.instanceType = otherBeanInstance.instanceType;
+ this.interceptorsHandler = otherBeanInstance.interceptorsHandler;
+ }
+
+ public Object getInstance()
+ {
+ return instance;
+ }
+
+ public Class<?> getInstanceType()
+ {
+ return instanceType;
+ }
+
+ /**
+ * @return the interceptorsHandler
+ */
+ public MethodHandler getInterceptorsHandler()
+ {
+ return interceptorsHandler;
+ }
+
+ /**
+ * @param interceptorsHandler the interceptorsHandler to set
+ */
+ public void setInterceptorsHandler(MethodHandler interceptorsHandler)
+ {
+ this.interceptorsHandler = interceptorsHandler;
+ }
+
+ @Override
+ public Object invoke(Method method, Object... arguments) throws Throwable
+ {
+ if (interceptorsHandler != null)
+ {
+ log.trace("Invoking interceptor chain for method " + method.toGenericString() + " on " + getInstance());
+ return interceptorsHandler.invoke(getInstance(), method, method, arguments);
+ }
+ else
+ {
+ log.trace("Invoking method " + method.toGenericString() + " directly on " + getInstance());
+ return super.invoke(method, arguments);
+ }
+ }
+
+}
Property changes on: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/TargetBeanInstance.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java (rev 0)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bean/proxy/util/ClassloaderClassPath.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat, Inc. and/or its affiliates, 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.util;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import javassist.ClassPath;
+import javassist.NotFoundException;
+
+/**
+ * A special classpath type used with the high-level Javassist API to lookup
+ * class bytecode through a specific classloader. This avoids the problem
+ * of finding classes in Javassist when it is used in JEE containers.
+ *
+ * @author David Allen
+ *
+ */
+public class ClassloaderClassPath implements ClassPath
+{
+ private final ClassLoader classLoader;
+
+ public ClassloaderClassPath(ClassLoader classLoader)
+ {
+ this.classLoader = classLoader;
+ }
+
+ public void close()
+ {
+ }
+
+ public URL find(String classname)
+ {
+ String resourceName = classname.replace('.', '/') + ".class";
+ return classLoader.getResource(resourceName);
+ }
+
+ public InputStream openClassfile(String classname) throws NotFoundException
+ {
+ String resourceName = classname.replace('.', '/') + ".class";
+ return classLoader.getResourceAsStream(resourceName);
+ }
+
+}
Modified: core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/bootstrap/WeldBootstrap.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -91,7 +91,6 @@
import org.jboss.weld.servlet.ServletApiAbstraction;
import org.jboss.weld.servlet.api.ServletServices;
import org.jboss.weld.transaction.spi.TransactionServices;
-import org.jboss.weld.util.JavassistCleaner;
import org.jboss.weld.util.Names;
import org.jboss.weld.util.collections.Arrays2;
import org.jboss.weld.util.serviceProvider.DefaultServiceLoaderFactory;
@@ -321,7 +320,6 @@
services.add(MetaAnnotationStore.class, new MetaAnnotationStore(services.get(ClassTransformer.class)));
services.add(ContextualStore.class, new ContextualStoreImpl());
services.add(ServiceLoaderFactory.class, new DefaultServiceLoaderFactory());
- services.add(JavassistCleaner.class, new JavassistCleaner());
services.add(InterceptionMetadataService.class, new InterceptionMetadataService());
services.add(CurrentInjectionPoint.class, new CurrentInjectionPoint());
return services;
Modified: core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/injection/ProxyClassConstructorInjectionPointWrapper.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -39,8 +39,6 @@
{
private ConstructorInjectionPoint<T> originalConstructorInjectionPoint;
- private Object injectedDelegate;
-
public ProxyClassConstructorInjectionPointWrapper(Bean<T> declaringBean, WeldConstructor<T> weldConstructor, ConstructorInjectionPoint<T> originalConstructorInjectionPoint)
{
super(declaringBean, weldConstructor);
@@ -52,31 +50,4 @@
{
return originalConstructorInjectionPoint.getWeldParameters();
}
-
- @Override
- protected Object[] getParameterValues(List<ParameterInjectionPoint<?, T>> parameters, Object specialVal, Class<? extends Annotation> specialParam, BeanManagerImpl manager, CreationalContext<?> creationalContext)
- {
- Object[] parameterValues = super.getParameterValues(parameters, specialVal, specialParam, manager, creationalContext);
- if (parameters.size() > 0)
- {
- for (ParameterInjectionPoint<?, T> parameterInjectionPoint: parameters)
- {
- if (parameterInjectionPoint.isDelegate())
- {
- this.injectedDelegate = parameterValues[parameterInjectionPoint.getPosition()];
- }
- }
- }
- return parameterValues;
- }
-
- /**
- * The delegate injected during the constructed process, if any
- *
- * @return
- */
- public Object getInjectedDelegate()
- {
- return injectedDelegate;
- }
}
Deleted: core/trunk/impl/src/main/java/org/jboss/weld/util/CleanableMethodHandler.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/CleanableMethodHandler.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/CleanableMethodHandler.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc., 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.util;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-
-import javassist.util.proxy.MethodHandler;
-
-import org.jboss.weld.Container;
-
-public class CleanableMethodHandler implements MethodHandler, Serializable
-{
-
- private static final long serialVersionUID = 2140367342468307705L;
-
- private MethodHandler delegate;
-
- public CleanableMethodHandler(MethodHandler delegate)
- {
- this.delegate = delegate;
- Container.instance().services().get(JavassistCleaner.class).add(this);
- }
-
- public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable
- {
- return delegate.invoke(self, thisMethod, proceed, args);
- }
-
- public void clean()
- {
- this.delegate = null;
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- in.defaultReadObject();
- Container.instance().services().get(JavassistCleaner.class).add(this);
- }
-
-}
Deleted: core/trunk/impl/src/main/java/org/jboss/weld/util/JavassistCleaner.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/JavassistCleaner.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/JavassistCleaner.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat, Inc., 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.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.jboss.weld.bootstrap.api.Service;
-
-public class JavassistCleaner implements Service
-{
-
- private final Collection<CleanableMethodHandler> cleanableMethodHandlers;
-
- public JavassistCleaner()
- {
- this.cleanableMethodHandlers = new ArrayList<CleanableMethodHandler>();
- }
-
- public void add(CleanableMethodHandler cleanableMethodHandler)
- {
- cleanableMethodHandlers.add(cleanableMethodHandler);
- }
-
- public void cleanup()
- {
- for (CleanableMethodHandler cleanableMethodHandler : cleanableMethodHandlers)
- {
- cleanableMethodHandler.clean();
- }
- cleanableMethodHandlers.clear();
- }
-
-}
\ No newline at end of file
Modified: core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java
===================================================================
--- core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/impl/src/main/java/org/jboss/weld/util/Proxies.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -102,6 +102,25 @@
return superclass;
}
+ public Class<?> getSuperInterface()
+ {
+ if (interfaces.isEmpty())
+ {
+ return null;
+ }
+ Iterator<Class<?>> it = interfaces.iterator();
+ Class<?> superclass = it.next();
+ while (it.hasNext())
+ {
+ Class<?> clazz = it.next();
+ if (superclass.isAssignableFrom(clazz))
+ {
+ superclass = clazz;
+ }
+ }
+ return superclass;
+ }
+
private Class<?>[] getInterfaces()
{
return interfaces.toArray(EMPTY_CLASSES);
@@ -167,78 +186,6 @@
}
/**
- * Create a proxy with a handler, registering the proxy for cleanup
- *
- * @param <T>
- * @param methodHandler
- * @param typeInfo
- * @return
- * @throws IllegalAccessException
- * @throws InstantiationException
- */
- public static <T> T createProxy(MethodHandler methodHandler, TypeInfo typeInfo) throws IllegalAccessException, InstantiationException
- {
- if (InstantiatorFactory.useInstantiators())
- {
- Class<T> proxyClass = Proxies.<T> createProxyClass(methodHandler, typeInfo);
- T instance = SecureReflections.newUnsafeInstance(proxyClass);
- setMethodHandler(proxyClass, instance, methodHandler);
- return instance;
- }
- else
- {
- return SecureReflections.newInstance(Proxies.<T> createProxyClass(methodHandler, typeInfo));
- }
- }
-
- private static <T> void setMethodHandler(Class<T> clazz, T instance, MethodHandler methodHandler)
- {
- try
- {
- Method setter = SecureReflections.getDeclaredMethod(clazz, "setHandler", MethodHandler.class);
- SecureReflections.invoke(instance, setter, methodHandler);
- }
- catch (Exception e)
- {
- throw new WeldException(METHODHANDLER_SET_FAILED, e, clazz);
- }
- }
-
- /**
- * Create a proxy class
- *
- * You will need to manually register the proxy instances for cleanup
- *
- * @param <T>
- * @param typeInfo
- * @return
- */
- public static <T> Class<T> createProxyClass(TypeInfo typeInfo)
- {
- return createProxyClass(null, typeInfo);
- }
-
- /**
- * Create a proxy class
- *
- * You will need to manually register the proxy instances for cleanup
- *
- * @param <T>
- * @param methodHandler
- * @param typeInfo
- * @return
- */
- public static <T> Class<T> createProxyClass(MethodHandler methodHandler, TypeInfo typeInfo)
- {
- ProxyFactory proxyFactory = typeInfo.createProxyFactory();
- attachMethodHandler(proxyFactory, methodHandler);
-
- @SuppressWarnings("unchecked")
- Class<T> clazz = proxyFactory.createClass();
- return clazz;
- }
-
- /**
* Indicates if a class is proxyable
*
* @param type The class to test
@@ -341,31 +288,4 @@
return null;
}
}
-
- public static ProxyFactory attachMethodHandler(ProxyFactory proxyFactory, MethodHandler methodHandler)
- {
- if (methodHandler != null)
- {
- proxyFactory.setHandler(new CleanableMethodHandler(methodHandler));
- }
- return proxyFactory;
- }
-
- public static <T> T attachMethodHandler(T instance, MethodHandler methodHandler)
- {
- if (instance instanceof ProxyObject)
- {
- if (methodHandler != null)
- {
- ((ProxyObject) instance).setHandler(new CleanableMethodHandler(methodHandler));
- }
- return instance;
- }
- else
- {
- throw new ForbiddenArgumentException(INSTANCE_NOT_A_PROXY, instance);
- }
-
- }
-
}
Modified: core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java
===================================================================
--- core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/porting-package/src/main/java/org/jboss/weld/tck/BeansImpl.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -31,7 +31,7 @@
public boolean isProxy(Object instance)
{
- return instance.getClass().getName().indexOf("_$$_javassist_") > 0;
+ return instance.getClass().getName().indexOf("_$$_Weld") > 0;
}
}
Modified: core/trunk/tests/src/main/java/org/jboss/weld/test/Utils.java
===================================================================
--- core/trunk/tests/src/main/java/org/jboss/weld/test/Utils.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/tests/src/main/java/org/jboss/weld/test/Utils.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -35,6 +35,7 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.util.TypeLiteral;
+import org.jboss.weld.bean.proxy.Proxy;
import org.jboss.weld.exceptions.UnsatisfiedResolutionException;
import org.jboss.weld.manager.BeanManagerImpl;
import org.jboss.weld.mock.el.EL;
@@ -169,4 +170,8 @@
return (T) EL.EXPRESSION_FACTORY.createValueExpression(elContext, expression, expectedType).getValue(elContext);
}
+ public static boolean isProxy(Object proxy)
+ {
+ return proxy instanceof Proxy;
+ }
}
Modified: core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/enterprise/EnterpriseBeanProxyTest.java
===================================================================
--- core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/enterprise/EnterpriseBeanProxyTest.java 2010-04-20 16:50:22 UTC (rev 6126)
+++ core/trunk/tests/src/test/java/org/jboss/weld/tests/proxy/enterprise/EnterpriseBeanProxyTest.java 2010-04-20 17:58:13 UTC (rev 6127)
@@ -22,6 +22,7 @@
import org.jboss.testharness.impl.packaging.Packaging;
import org.jboss.testharness.impl.packaging.PackagingType;
import org.jboss.weld.test.AbstractWeldTest;
+import org.jboss.weld.test.Utils;
import org.testng.annotations.Test;
@Artifact
@@ -36,7 +37,7 @@
public void testNoInterfaceView() throws Exception
{
Object mouse = getReference(MouseLocal.class);
- assert mouse instanceof ProxyObject;
+ assert Utils.isProxy(mouse);
assert mouse instanceof MouseLocal;
}
14 years, 8 months
Weld SVN: r6126 - cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular.
by weld-commits@lists.jboss.org
Author: dallen6
Date: 2010-04-20 12:50:22 -0400 (Tue, 20 Apr 2010)
New Revision: 6126
Modified:
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/CircularDependencyTest.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Food.java
cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Pig.java
Log:
CDITCK-140 Removed the PostConstruct methods and check circular deps after bean instances created
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/CircularDependencyTest.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/CircularDependencyTest.java 2010-04-20 16:11:40 UTC (rev 6125)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/CircularDependencyTest.java 2010-04-20 16:50:22 UTC (rev 6126)
@@ -31,9 +31,10 @@
@SpecAssertion(section="5", id="b")
public void testCircularInjectionOnTwoNormalBeans() throws Exception
{
- getInstanceByType(Pig.class).getName();
- assert Pig.success;
- assert Food.success;
+ Pig pig = getInstanceByType(Pig.class);
+ Food food = getInstanceByType(Food.class);
+ assert pig.getNameOfFood().equals(food.getName());
+ assert food.getNameOfPig().equals(pig.getName());
}
@Test
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Food.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Food.java 2010-04-20 16:11:40 UTC (rev 6125)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Food.java 2010-04-20 16:50:22 UTC (rev 6126)
@@ -16,7 +16,6 @@
*/
package org.jboss.jsr299.tck.tests.lookup.circular;
-import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
@@ -24,27 +23,15 @@
class Food
{
- public static boolean success;
-
@Inject Pig pig;
- public Food()
- {
- success = false;
- }
-
- @PostConstruct
- public void postConstruct()
- {
- if (pig.getName().equals("john"))
- {
- success = true;
- }
- }
-
public String getName()
{
return "food";
}
+ public String getNameOfPig()
+ {
+ return pig.getName();
+ }
}
Modified: cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Pig.java
===================================================================
--- cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Pig.java 2010-04-20 16:11:40 UTC (rev 6125)
+++ cdi-tck/trunk/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/circular/Pig.java 2010-04-20 16:50:22 UTC (rev 6126)
@@ -16,35 +16,26 @@
*/
package org.jboss.jsr299.tck.tests.lookup.circular;
-import javax.annotation.PostConstruct;
+import java.io.Serializable;
+
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
@SessionScoped
-class Pig
+class Pig implements Serializable
{
- public static boolean success;
-
+ private static final long serialVersionUID = 2445308247858178311L;
+
@Inject Food food;
- public Pig()
- {
- success = false;
- }
-
- @PostConstruct
- public void postConstruct()
- {
- if (food.getName().equals("food"))
- {
- success = true;
- }
- }
-
public String getName()
{
return "john";
}
+ public String getNameOfFood()
+ {
+ return food.getName();
+ }
}
14 years, 8 months