[jboss-cvs] JBossAS SVN: r62181 - in projects/aop/trunk/aop/docs/examples: after-throwing and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 9 01:19:08 EDT 2007
Author: flavia.rainone at jboss.com
Date: 2007-04-09 01:19:08 -0400 (Mon, 09 Apr 2007)
New Revision: 62181
Added:
projects/aop/trunk/aop/docs/examples/after-throwing/
projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java
projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java
projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java
projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html
projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.wiki
projects/aop/trunk/aop/docs/examples/after-throwing/build.xml
projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml
Log:
[JBAOP-44] After-throwing example.
Added: projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.
+*/
+
+import org.jboss.aop.advice.annotation.Arg;
+import org.jboss.aop.advice.annotation.JoinPoint;
+import org.jboss.aop.advice.annotation.Thrown;
+
+import org.jboss.aop.joinpoint.IMethodInfo;
+
+public class Aspect
+{
+ public void afterThrowing(@Thrown Throwable thrown)
+ {
+ System.out.println(">>> afterThrowing: " + thrown);
+ }
+
+ public void afterThrowingInfo(@JoinPoint IMethodInfo methodInfo, @Thrown Throwable thrown)
+ {
+ System.out.println(">>> afterThrowingInfo: " + thrown);
+ }
+
+ public void afterThrowingArg(@Thrown Throwable thrown, @Arg String argument)
+ {
+ System.out.println(">>> afterThrowingArg: " + thrown);
+ }
+
+ public void afterThrowingInfoArg(@Thrown Throwable thrown, @JoinPoint IMethodInfo methodInfo, @Arg String argument)
+ {
+ System.out.println(">>> afterThrowingInfoArg: " + thrown);
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+
+public class Driver
+{
+ public static void main(String[] args) throws Exception
+ {
+ POJO pojo = new POJO();
+
+ System.out.println("\nCalling POJO->throwExceptionMethod()");
+ System.out.println("====================================");
+ try
+ {
+ pojo.throwExceptionMethod("argument");
+ }
+ catch (Exception exception)
+ {
+ System.out.println("Caching Exception " + exception);
+ }
+
+ System.out.println("\nCalling POJO->throwNothingMethod()");
+ System.out.println("==================================");
+ pojo.throwNothingMethod();
+ System.out.println("No Exception this time");
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+
+public class POJO
+{
+ public void throwExceptionMethod(String arg) throws Exception
+ {
+ System.out.println("RUNNING POJO->throwsExceptionMethod(\"" + arg + "\")");
+ throw new Exception("POJO Exception");
+ }
+
+ public void throwNothingMethod()
+ {
+ System.out.println("RUNNING POJO->throwNothingMethod()");
+ }
+}
\ No newline at end of file
Added: projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,105 @@
+<html>
+<body>
+<p>
+<h2>After Throwing Advices</h2>
+
+</p><p>
+<h4>Overview</h4>
+
+Besides before, after and around advices, you can also write after-throwing advices.
+These advices intercept joinpoints throwing an exception. In this example, we will see
+how to write that type of advices.
+</p><p>
+<h4>Writing After Throwing Advices</h4>
+
+</p><p>
+</p><p>
+After-throwing advices are written using the annotated parameter signature.
+The only difference is that these advices feature an additional annotated parameter:
+<tt>@Thrown</tt>. This mandatory parameter will hold the thrown exception.
+So, an after-throwing advice should be of the form:
+</p><p>
+<pre>
+public void <any-method-name>(@Thrown Throwable arg0, @<Annotation> <any type> arg1, @<Annotation> <any type> arg1, ... , @<Annotation> <any type> argN) throws <Exception1>,<Exception2>,...,<ExceptionN>
+</pre>
+</p><p>
+<h4>Binding After Throwing Advices</h4>
+
+</p><p>
+To bind an after throwing advice to a pointcut, simply insert the <tt><throwing></tt> tag
+in a binding xml declaration, as in the following example:
+</p><p>
+<pre>
+<bind pointcut="execution(* POJO->*(..))">
+ <throwing name="afterThrowing" aspect="Aspect"/>
+</bind>
+</pre>
+</p><p>
+Differently from other advice types, after-throwing advices aren't called everytime
+an intercepted joinpoint gets executed. On the contrary, after-throwing advices are
+invoked only when the joinpoint throws an exception. So, in the binding example
+above, this means that <tt>afterThrowing</tt> will be invoked only after a <tt>POJO</tt> method
+throws an exception, instead of being invoked after all <tt>POJO</tt> methods' executions.
+</p><p>
+<h4>Examples</h4>
+
+</p><p>
+You can find examples of after-throwing advices in the <tt>Aspect.java</tt> file.
+</p><p>
+The following advice signature:
+<pre>
+public void afterThrowing(@Thrown Throwable thrown)
+</pre>
+</p><p>
+Is the simplest you can write, since the <tt>@Thrown Throwable</tt> parameter is mandatory.
+</p><p>
+But you can also include any other
+<a href="../annotated-parameters/annotated-parameters.html">annotated parameter</a> (except
+<tt>@Return</tt>, which is exclusive of after advices).
+</p><p>
+The following advice signature is valid to intercept a method execution throwing an
+exception:
+<pre>
+public void afterThrowingInfo(@JoinPoint IMethodInfo methodInfo, @Thrown Throwable thrown)
+</pre>
+</p><p>
+Notice that you can declare the annotated parameters in any order you wish.
+</p><p>
+If the method being intercepted receives an <tt>String</tt> argument, these after throwing
+signatures are also valid:
+</p><p>
+<pre>
+public void afterThrowingArg(@Thrown Throwable thrown, @Arg String argument)
+public void afterThrowingInfoArg(@Thrown Throwable thrown, @JoinPoint IMethodInfo methodInfo, @Arg String argument)
+</pre>
+</p><p>
+</p><p>
+<h4>Run the example</h4>
+
+</p><p>
+<b>THIS EXAMPLE REQUIRES JDK 1.5!!</b> To compile and run:
+<pre>
+ $ ant
+</pre>
+It will javac the files and then run the AOPC precompiler to manipulate the bytecode,
+then finally run the example. The output should read as follows:
+<pre>
+run:
+
+ [java] Calling POJO->throwExceptionMethod()
+ [java] ====================================
+ [java] RUNNING POJO->throwsExceptionMethod("argument")
+ [java] >>> afterThrowing: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingInfo: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingArg: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingInfoArg: java.lang.Exception: POJO Exception
+ [java] Caching Exception java.lang.Exception: POJO Exception
+
+ [java] Calling POJO->throwNothingMethod()
+ [java] ==================================
+ [java] RUNNING POJO->throwNothingMethod()
+ [java] No Exception this time
+</pre>
+</p>
+</body>
+</html>
Added: projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.wiki
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.wiki (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.wiki 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,93 @@
+!!!After Throwing Advices
+
+!Overview
+Besides before, after and around advices, you can also write after-throwing advices.
+These advices intercept joinpoints throwing an exception. In this example, we will see
+how to write that type of advices.
+
+!Writing After Throwing Advices
+
+
+After-throwing advices are written using the annotated parameter signature.
+The only difference is that these advices feature an additional annotated parameter:
+{{@Thrown}}. This mandatory parameter will hold the thrown exception.
+So, an after-throwing advice should be of the form:
+
+{{{
+public void <any-method-name>(@Thrown Throwable arg0, @<Annotation> <any type> arg1, @<Annotation> <any type> arg1, ... , @<Annotation> <any type> argN) throws <Exception1>,<Exception2>,...,<ExceptionN>
+}}}
+
+!Binding After Throwing Advices
+
+To bind an after throwing advice to a pointcut, simply insert the {{<throwing>}} tag
+in a binding xml declaration, as in the following example:
+
+{{{
+<bind pointcut="execution(* POJO->*(..))">
+ <throwing name="afterThrowing" aspect="Aspect"/>
+</bind>
+}}}
+
+Differently from other advice types, after-throwing advices aren't called everytime
+an intercepted joinpoint gets executed. On the contrary, after-throwing advices are
+invoked only when the joinpoint throws an exception. So, in the binding example
+above, this means that {{afterThrowing}} will be invoked only after a {{POJO}} method
+throws an exception, instead of being invoked after all {{POJO}} methods' executions.
+
+!Examples
+
+You can find examples of after-throwing advices in the {{Aspect.java}} file.
+
+The following advice signature:
+{{{
+public void afterThrowing(@Thrown Throwable thrown)
+}}}
+
+Is the simplest you can write, since the {{@Thrown Throwable}} parameter is mandatory.
+
+But you can also include any other
+[annotated parameter|../annotated-parameters/annotated-parameters.html] (except
+{{@Return}}, which is exclusive of after advices).
+
+The following advice signature is valid to intercept a method execution throwing an
+exception:
+{{{
+public void afterThrowingInfo(@JoinPoint IMethodInfo methodInfo, @Thrown Throwable thrown)
+}}}
+
+Notice that you can declare the annotated parameters in any order you wish.
+
+If the method being intercepted receives an {{String}} argument, these after throwing
+signatures are also valid:
+
+{{{
+public void afterThrowingArg(@Thrown Throwable thrown, @Arg String argument)
+public void afterThrowingInfoArg(@Thrown Throwable thrown, @JoinPoint IMethodInfo methodInfo, @Arg String argument)
+}}}
+
+
+!Run the example
+
+__THIS EXAMPLE REQUIRES JDK 1.5!!__ To compile and run:
+{{{
+ $ ant
+}}}
+It will javac the files and then run the AOPC precompiler to manipulate the bytecode,
+then finally run the example. The output should read as follows:
+{{{
+run:
+
+ [java] Calling POJO->throwExceptionMethod()
+ [java] ====================================
+ [java] RUNNING POJO->throwsExceptionMethod("argument")
+ [java] >>> afterThrowing: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingInfo: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingArg: java.lang.Exception: POJO Exception
+ [java] >>> afterThrowingInfoArg: java.lang.Exception: POJO Exception
+ [java] Caching Exception java.lang.Exception: POJO Exception
+
+ [java] Calling POJO->throwNothingMethod()
+ [java] ==================================
+ [java] RUNNING POJO->throwNothingMethod()
+ [java] No Exception this time
+}}}
Added: projects/aop/trunk/aop/docs/examples/after-throwing/build.xml
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/build.xml (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/build.xml 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project default="run" name="JBoss/AOP">
+ <target name="prepare">
+ <property name="jboss.aop.root" value="../../../.."/>
+ <property name="jboss.aop.lib" value="${jboss.aop.root}/lib"/>
+ <property name="jboss.aop.lib50" value="${jboss.aop.root}/lib-50"/>
+
+ <path id="jboss.aop.classpath">
+ <fileset dir="${jboss.aop.lib}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="jboss.aop.classpath50">
+ <fileset dir="${jboss.aop.lib50}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="classpath">
+ <path refid="jboss.aop.classpath"/>
+ <pathelement path="."/>
+ </path>
+
+ <property name="aop50jar" value="${jboss.aop.lib50}/jboss-aop-jdk50.jar"/>
+
+ <path id="classpath50">
+ <path refid="jboss.aop.classpath50"/>
+ <pathelement path="."/>
+ </path>
+
+ <taskdef name="aopc" classname="org.jboss.aop.ant.AopC" classpathref="jboss.aop.classpath"/>
+ </target>
+
+
+ <target name="compile" depends="prepare">
+ <javac srcdir="."
+ destdir="."
+ debug="on"
+ deprecation="on"
+ optimize="off"
+ includes="**">
+ <classpath refid="classpath50"/>
+ </javac>
+ <aopc compilerclasspathref="classpath50" classpathref="classpath50" verbose="true">
+ <sysproperty key="jboss.aop.path" value="jboss-aop.xml"/>
+ <sysproperty key="jboss.aop.verbose" value="true"/>
+ <classpath path="."/>
+ <src path="."/>
+ <aoppath path="jboss-aop.xml"/>
+ </aopc>
+ </target>
+
+ <target name="run" depends="compile">
+ <java fork="yes" failOnError="true" className="Driver">
+ <sysproperty key="jboss.aop.path" value="jboss-aop.xml"/>
+ <classpath refid="classpath"/>
+ </java>
+ </target>
+
+ <target name="compile50standalone" depends="prepare">
+ <javac srcdir="."
+ destdir="."
+ debug="on"
+ deprecation="on"
+ optimize="off"
+ includes="**">
+ <classpath refid="classpath50"/>
+ </javac>
+ </target>
+
+ <target name="run.50.instrumented" depends="compile50standalone">
+ <java fork="yes" failOnError="true" className="Driver">
+ <sysproperty key="jboss.aop.path" value="jboss-aop.xml"/>
+ <sysproperty key="jboss.aop.instrumentor" value="org.jboss.aop.instrument.GeneratedAdvisorInstrumentor"/>
+ <jvmarg value="-javaagent:${aop50jar}"/>
+ <classpath refid="classpath50"/>
+ </java>
+ </target>
+
+</project>
Added: projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml 2007-04-09 05:19:08 UTC (rev 62181)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<aop>
+
+ <aspect class="Aspect" scope="PER_VM"/>
+
+ <bind pointcut="execution(* POJO->*(..))">
+ <throwing name="afterThrowing" aspect="Aspect"/>
+ <throwing name="afterThrowingInfo" aspect="Aspect"/>
+ <throwing name="afterThrowingArg" aspect="Aspect"/>
+ <throwing name="afterThrowingInfoArg" aspect="Aspect"/>
+ </bind>
+
+</aop>
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list