[jboss-cvs] JBossAS SVN: r63585 - in projects/aop/trunk/aop/src: test/org/jboss/test/aop and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jun 20 12:22:32 EDT 2007
Author: kabir.khan at jboss.com
Date: 2007-06-20 12:22:32 -0400 (Wed, 20 Jun 2007)
New Revision: 63585
Added:
projects/aop/trunk/aop/src/main/org/jboss/aop/AdviceType.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/BeforeAfterThrowingAnnotatedTestCase.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/POJO.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestAspect.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestException.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
projects/aop/trunk/aop/src/main/org/jboss/aop/Bind.java
projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
Log:
[JBAOP-386] Extend @Bind annotation to allow b/a/t/f bindings
Added: projects/aop/trunk/aop/src/main/org/jboss/aop/AdviceType.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AdviceType.java (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AdviceType.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -0,0 +1,31 @@
+/*
+* 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.aop;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public enum AdviceType {
+ AROUND, BEFORE, AFTER, THROWING, FINALLY;
+}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2007-06-20 15:04:19 UTC (rev 63584)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectAnnotationLoader.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -465,7 +465,18 @@
cflowExpression = new PointcutExpressionParser(new StringReader(cflow)).CFlowExpression();
}
- AdviceFactory factory = new AdviceFactory(def, minfo.getName());
+
+ org.jboss.aop.advice.AdviceType internalAdviceType = getInternalAdviceType(binding.type());
+ AdviceFactory factory = null;
+ if (internalAdviceType == org.jboss.aop.advice.AdviceType.AROUND)
+ {
+ factory = new AdviceFactory(def, minfo.getName());
+ }
+ else
+ {
+ factory = new AdviceFactory(def, minfo.getName(), internalAdviceType);
+ }
+
manager.addInterceptorFactory(factory.getName(), factory);
InterceptorFactory[] fact = {factory};
String name = getAspectMethodBindingName(cf, minfo);
@@ -475,6 +486,31 @@
}
}
+ private org.jboss.aop.advice.AdviceType getInternalAdviceType(AdviceType adviceType)
+ {
+ if (adviceType == AdviceType.AROUND)
+ {
+ return org.jboss.aop.advice.AdviceType.AROUND;
+ }
+ else if (adviceType == AdviceType.BEFORE)
+ {
+ return org.jboss.aop.advice.AdviceType.BEFORE;
+ }
+ else if (adviceType == AdviceType.AFTER)
+ {
+ return org.jboss.aop.advice.AdviceType.AFTER;
+ }
+ else if (adviceType == AdviceType.THROWING)
+ {
+ return org.jboss.aop.advice.AdviceType.THROWING;
+ }
+ else if (adviceType == AdviceType.FINALLY)
+ {
+ return org.jboss.aop.advice.AdviceType.FINALLY;
+ }
+
+ throw new RuntimeException("Bad type " + adviceType);
+ }
private void undeployAspectMethodBindings(ClassFile cf)
throws Exception
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Bind.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Bind.java 2007-06-20 15:04:19 UTC (rev 63584)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Bind.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -35,6 +35,8 @@
@Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME)
public @interface Bind
{
+ AdviceType type() default AdviceType.AROUND;
+
String pointcut();
String cflow() default "";
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-06-20 15:04:19 UTC (rev 63584)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/JoinPointInfo.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -96,7 +96,7 @@
public boolean hasAdvices()
{
- return (interceptors != null && interceptors.length > 0) /*|| (factories != null && factories.length > 0)*/;
+ return (interceptors != null && interceptors.length > 0);
}
public boolean equalChains(JoinPointInfo other)
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/BeforeAfterThrowingAnnotatedTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/BeforeAfterThrowingAnnotatedTestCase.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/BeforeAfterThrowingAnnotatedTestCase.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -0,0 +1,80 @@
+/*
+* 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.beforeafterthrowingannotated;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.aop.AOPTestWithSetup;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeforeAfterThrowingAnnotatedTestCase extends AOPTestWithSetup
+{
+ public BeforeAfterThrowingAnnotatedTestCase(String arg0)
+ {
+ super(arg0);
+ }
+
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("BeforeAfterThrowingAnnotatedTestCase");
+ suite.addTestSuite(BeforeAfterThrowingAnnotatedTestCase.class);
+ return suite;
+ }
+
+ public void testAspects()
+ {
+ POJO pojo = new POJO();
+ assertEquals(0, TestAspect.interceptions.size());
+
+ pojo.method();
+ assertEquals(3, TestAspect.interceptions.size());
+ assertEquals("BEFORE", TestAspect.interceptions.get(0));
+ assertEquals("AFTER", TestAspect.interceptions.get(1));
+ assertEquals("FINALLY", TestAspect.interceptions.get(2));
+
+ TestAspect.interceptions.clear();
+ try
+ {
+ pojo.method(true);
+ fail("expected exception");
+ }
+ catch(TestException expected)
+ {
+ }
+ assertEquals(3, TestAspect.interceptions.size());
+ assertEquals("BEFORE", TestAspect.interceptions.get(0));
+ assertEquals("THROWING", TestAspect.interceptions.get(1));
+ assertEquals("FINALLY", TestAspect.interceptions.get(2));
+ }
+
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/POJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/POJO.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/POJO.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -0,0 +1,43 @@
+/*
+* 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.beforeafterthrowingannotated;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO
+{
+ public void method()
+ {
+
+ }
+
+ public void method(boolean error)
+ {
+ if (error)
+ {
+ throw new TestException();
+ }
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestAspect.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestAspect.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestAspect.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -0,0 +1,66 @@
+/*
+* 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.beforeafterthrowingannotated;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.aop.AdviceType;
+import org.jboss.aop.Aspect;
+import org.jboss.aop.Bind;
+import org.jboss.aop.advice.annotation.Thrown;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+ at Aspect
+public class TestAspect
+{
+ public static List<String> interceptions = new ArrayList<String>();
+
+
+ @Bind(type=AdviceType.BEFORE, pointcut="execution(* org.jboss.test.aop.beforeafterthrowingannotated.POJO->method(..))")
+ public void before()
+ {
+ interceptions.add("BEFORE");
+ }
+
+ @Bind(type=AdviceType.AFTER, pointcut="execution(* org.jboss.test.aop.beforeafterthrowingannotated.POJO->method(..))")
+ public void after()
+ {
+ interceptions.add("AFTER");
+ }
+
+ @Bind(type=AdviceType.THROWING, pointcut="execution(* org.jboss.test.aop.beforeafterthrowingannotated.POJO->method(..))")
+ public void throwing(@Thrown Throwable t)
+ {
+ interceptions.add("THROWING");
+ }
+
+ @Bind(type=AdviceType.FINALLY, pointcut="execution(* org.jboss.test.aop.beforeafterthrowingannotated.POJO->method(..))")
+ public void finaly()
+ {
+ interceptions.add("FINALLY");
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestException.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestException.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/beforeafterthrowingannotated/TestException.java 2007-06-20 16:22:32 UTC (rev 63585)
@@ -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.beforeafterthrowingannotated;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestException extends RuntimeException
+{
+
+}
More information about the jboss-cvs-commits
mailing list