[jboss-cvs] JBossAS SVN: r58006 - in branches/Branch_AOP_1_5/aop: . src/main/org/jboss/aop src/main/org/jboss/aop/advice src/resources/test/construction src/test/org/jboss/test/aop/construction
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 2 07:00:05 EST 2006
Author: kabir.khan at jboss.com
Date: 2006-11-02 06:59:50 -0500 (Thu, 02 Nov 2006)
New Revision: 58006
Added:
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java
Modified:
branches/Branch_AOP_1_5/aop/build.xml
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java
branches/Branch_AOP_1_5/aop/src/resources/test/construction/jboss-aop.xml
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java
Log:
[JBAOP-303] Per instance construction advices should be possible
Modified: branches/Branch_AOP_1_5/aop/build.xml
===================================================================
--- branches/Branch_AOP_1_5/aop/build.xml 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/build.xml 2006-11-02 11:59:50 UTC (rev 58006)
@@ -67,7 +67,7 @@
<!-- Module name(s) & version -->
<property name="module.name" value="aop"/>
<property name="module.Name" value="JBoss AOP"/>
- <property name="module.version" value="1.5.2.GA"/>
+ <property name="module.version" value="snapshot-Branch_AOP_1_5"/>
<!-- ========= -->
<!-- Libraries -->
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2006-11-02 11:59:50 UTC (rev 58006)
@@ -35,6 +35,7 @@
import org.jboss.aop.advice.AspectDefinition;
import org.jboss.aop.advice.AspectFactory;
import org.jboss.aop.advice.AspectFactoryDelegator;
+import org.jboss.aop.advice.AspectFactoryWithClassLoader;
import org.jboss.aop.advice.DynamicCFlowDefinition;
import org.jboss.aop.advice.GenericAspectFactory;
import org.jboss.aop.advice.Interceptor;
@@ -77,12 +78,27 @@
//TODO: We need something to undeploy everything...
protected AspectManager manager;
+ private ClassLoader cl;
public AspectAnnotationLoader(AspectManager manager)
{
this.manager = manager;
}
+ public void setClassLoader(ClassLoader cl)
+ {
+ this.cl = cl;
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ if (cl == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ return cl;
+ }
+
public void deployInputStreamIterator(Iterator it) throws Exception
{
while (it.hasNext())
@@ -197,10 +213,12 @@
if (isFactory)
{
factory = new AspectFactoryDelegator(cf.getName(), null);
+ ((AspectFactoryWithClassLoader)factory).setClassLoader(cl);
}
else
{
factory = new GenericAspectFactory(cf.getName(), null);
+ ((AspectFactoryWithClassLoader)factory).setClassLoader(cl);
}
AspectDefinition def = new AspectDefinition(cf.getName(), scope, factory);
manager.addAspectDefinition(def);
@@ -256,10 +274,12 @@
if (isFactory)
{
aspectFactory = new AspectFactoryDelegator(cf.getName(), null);
+ ((AspectFactoryWithClassLoader)aspectFactory).setClassLoader(cl);
}
else
{
aspectFactory = new GenericAspectFactory(cf.getName(), null);
+ ((AspectFactoryWithClassLoader)aspectFactory).setClassLoader(cl);
}
AspectDefinition def = new AspectDefinition(cf.getName(), scope, aspectFactory);
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/advice/AbstractAdvice.java 2006-11-02 11:59:50 UTC (rev 58006)
@@ -22,6 +22,7 @@
package org.jboss.aop.advice;
import org.jboss.aop.instrument.Untransformable;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
import org.jboss.aop.joinpoint.ConstructorCalledByConstructorInvocation;
import org.jboss.aop.joinpoint.ConstructorCalledByMethodInvocation;
import org.jboss.aop.joinpoint.ConstructorInvocation;
@@ -46,6 +47,7 @@
private static final Class[] INVOCATION_SIGNATURE = {Invocation.class};
private static final Class[] METHOD_SIGNATURE = {MethodInvocation.class};
private static final Class[] CONSTRUCTOR_SIGNATURE = {ConstructorInvocation.class};
+ private static final Class[] CONSTRUCTION_SIGNATURE = {ConstructionInvocation.class};
private static final Class[] FIELD_SIGNATURE = {FieldInvocation.class};
private static final Class[] FIELD_READ_SIGNATURE = {FieldReadInvocation.class};
private static final Class[] FIELD_WRITE_SIGNATURE = {FieldWriteInvocation.class};
@@ -56,6 +58,7 @@
protected Method invocationAdvice;
protected Method methodAdvice;
protected Method constructorAdvice;
+ protected Method constructionAdvice;
protected Method fieldAdvice;
protected Method fieldReadAdvice;
protected Method fieldWriteAdvice;
@@ -75,6 +78,7 @@
{
methodAdvice = findByMethodInvocation(adviceName, aspectClass);
constructorAdvice = findByConstructorInvocation(adviceName, aspectClass);
+ constructionAdvice = findByConstructionInvocation(adviceName, aspectClass);
fieldAdvice = findByFieldInvocation(adviceName, aspectClass);
if (fieldAdvice == null)
{
@@ -166,6 +170,19 @@
return null;
}
+ protected static Method findByConstructionInvocation(String adviceName, Class clazz)
+ {
+ try
+ {
+ return clazz.getMethod(adviceName, CONSTRUCTION_SIGNATURE);
+ }
+ catch (NoSuchMethodException e)
+ {
+ // complete
+ }
+ return null;
+ }
+
protected static Method findByMethodCalledByMethodInvocation(String adviceName, Class clazz)
{
try
@@ -257,6 +274,14 @@
}
return constructorAdvice;
}
+ if (invocation instanceof ConstructionInvocation)
+ {
+ if (constructorAdvice == null)
+ {
+ throw new IllegalStateException("Unable to resolve ConstructionInvocation advice " + getName());
+ }
+ return constructorAdvice;
+ }
if (invocation instanceof MethodCalledByMethodInvocation)
{
if (methodCalledByMethodAdvice == null)
Modified: branches/Branch_AOP_1_5/aop/src/resources/test/construction/jboss-aop.xml
===================================================================
--- branches/Branch_AOP_1_5/aop/src/resources/test/construction/jboss-aop.xml 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/resources/test/construction/jboss-aop.xml 2006-11-02 11:59:50 UTC (rev 58006)
@@ -4,6 +4,7 @@
<aop>
<aspect class="org.jboss.test.aop.construction.Aspect"/>
+ <aspect class="org.jboss.test.aop.construction.PerInstanceAspect"/>
<bind pointcut="construction(org.jboss.test.aop.construction.SuperPOJO->new(..))">
<advice aspect="org.jboss.test.aop.construction.Aspect" name="construction"/>
@@ -14,4 +15,10 @@
<advice aspect="org.jboss.test.aop.construction.Aspect" name="construction2"/>
</bind>
+
+ <bind pointcut="construction(org.jboss.test.aop.construction.PerInstancePOJO->new(..))">
+ <advice aspect="org.jboss.test.aop.construction.PerInstanceAspect" name="construction"/>
+ <advice aspect="org.jboss.test.aop.construction.PerInstanceAspect" name="invocation"/>
+ </bind>
+
</aop>
Modified: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/ConstructionTester.java 2006-11-02 11:59:50 UTC (rev 58006)
@@ -63,5 +63,14 @@
POJO pojo = new POJO();
DefaultPOJO d = new DefaultPOJO();
}
+
+ public void testPerInstance()
+ {
+ PerInstanceAspect.construction = false;
+ PerInstanceAspect.invocation = false;
+ PerInstancePOJO pojo = new PerInstancePOJO();
+ assertTrue(PerInstanceAspect.construction);
+ assertTrue(PerInstanceAspect.invocation);
+ }
}
Added: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstanceAspect.java 2006-11-02 11:59:50 UTC (rev 58006)
@@ -0,0 +1,47 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.construction;
+
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstanceAspect
+{
+ static boolean construction;
+ static boolean invocation;
+ public Object construction(ConstructionInvocation inv) throws Throwable
+ {
+ construction = true;
+ return inv.invokeNext();
+ }
+
+ public Object invocation(Invocation inv) throws Throwable
+ {
+ invocation = true;
+ return inv.invokeNext();
+ }
+}
Added: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java 2006-11-02 11:50:34 UTC (rev 58005)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/construction/PerInstancePOJO.java 2006-11-02 11:59:50 UTC (rev 58006)
@@ -0,0 +1,32 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.construction;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class PerInstancePOJO
+{
+
+}
More information about the jboss-cvs-commits
mailing list