[jboss-cvs] JBossAS SVN: r79725 - projects/aop/trunk/aop/docs/examples/after-throwing.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Oct 20 01:40:29 EDT 2008
Author: flavia.rainone at jboss.com
Date: 2008-10-20 01:40:29 -0400 (Mon, 20 Oct 2008)
New Revision: 79725
Added:
projects/aop/trunk/aop/docs/examples/after-throwing/POJOException.java
Modified:
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/jboss-aop.xml
Log:
[JBAOP-388] Updated after-throwing tutorial exemple, to illustrate (code) and document (html file) that @Thrown-annotated
parameters can have types different from Throwable now.
Modified: projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java 2008-10-20 05:34:36 UTC (rev 79724)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/Aspect.java 2008-10-20 05:40:29 UTC (rev 79725)
@@ -33,17 +33,17 @@
System.out.println(">>> afterThrowing: " + thrown);
}
- public void afterThrowingJoinPoint(@JoinPoint MethodExecution methodExecution, @Thrown Throwable thrown)
+ public void afterThrowingJoinPoint(@JoinPoint MethodExecution methodExecution, @Thrown POJOException thrown)
{
System.out.println(">>> afterThrowingJoinPoint: " + thrown);
}
- public void afterThrowingArg(@Thrown Throwable thrown, @Arg String argument)
+ public void afterThrowingArg(@Thrown RuntimeException thrown, @Arg String argument)
{
System.out.println(">>> afterThrowingArg: " + thrown);
}
- public void afterThrowingJoinPointArg(@Thrown Throwable thrown, @JoinPoint MethodExecution methodExecution, @Arg String argument)
+ public void afterThrowingJoinPointArg(@Thrown NullPointerException thrown, @JoinPoint MethodExecution methodExecution, @Arg String argument)
{
System.out.println(">>> afterThrowingJoinPointArg: " + thrown);
}
Modified: projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java 2008-10-20 05:34:36 UTC (rev 79724)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/Driver.java 2008-10-20 05:40:29 UTC (rev 79725)
@@ -26,17 +26,39 @@
{
POJO pojo = new POJO();
- System.out.println("\nCalling POJO->throwExceptionMethod()");
+ System.out.println("\nCalling POJO->throwPOJOExceptionMethod()");
System.out.println("====================================");
try
{
- pojo.throwExceptionMethod("argument");
+ pojo.throwPOJOExceptionMethod("argument");
}
catch (Exception exception)
{
- System.out.println("Caching Exception " + exception);
+ System.out.println("Catching Exception " + exception);
}
+ System.out.println("\nCalling POJO->throwRuntimeExceptionMethod()");
+ System.out.println("====================================");
+ try
+ {
+ pojo.throwRuntimeExceptionMethod("argument");
+ }
+ catch (Exception exception)
+ {
+ System.out.println("Catching Exception " + exception);
+ }
+
+ System.out.println("\nCalling POJO->throwNullPointerExceptionMethod()");
+ System.out.println("====================================");
+ try
+ {
+ pojo.throwNullPointerExceptionMethod("argument");
+ }
+ catch (Exception exception)
+ {
+ System.out.println("Catching Exception " + exception);
+ }
+
System.out.println("\nCalling POJO->throwNothingMethod()");
System.out.println("==================================");
pojo.throwNothingMethod();
Modified: projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java 2008-10-20 05:34:36 UTC (rev 79724)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/POJO.java 2008-10-20 05:40:29 UTC (rev 79725)
@@ -22,12 +22,25 @@
public class POJO
{
- public void throwExceptionMethod(String arg) throws Exception
+ public void throwPOJOExceptionMethod(String arg) throws POJOException
{
- System.out.println("RUNNING POJO->throwsExceptionMethod(\"" + arg + "\")");
- throw new Exception("POJO Exception");
+ System.out.println("RUNNING POJO->throwsPOJOExceptionMethod(\"" + arg + "\")");
+ throw new POJOException();
}
+ public void throwRuntimeExceptionMethod(String arg) throws POJOException
+ {
+ System.out.println("RUNNING POJO->throwsRuntimeExceptionMethod(\"" + arg + "\")");
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
+ public void throwNullPointerExceptionMethod(String arg) throws POJOException
+ {
+ System.out.println("RUNNING POJO->throwsNullPointerExceptionMethod(\"" + arg + "\")");
+ String nullText = null;
+ System.out.println(nullText.toString());
+ }
+
public void throwNothingMethod()
{
System.out.println("RUNNING POJO->throwNothingMethod()");
Added: projects/aop/trunk/aop/docs/examples/after-throwing/POJOException.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/POJOException.java (rev 0)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/POJOException.java 2008-10-20 05:40:29 UTC (rev 79725)
@@ -0,0 +1,26 @@
+/*
+ * 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 POJOException extends Exception
+{
+
+}
\ No newline at end of file
Modified: projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html 2008-10-20 05:34:36 UTC (rev 79724)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/after-throwing.html 2008-10-20 05:40:29 UTC (rev 79725)
@@ -21,10 +21,15 @@
So, an after-throwing advice should be of the form:
</p><p>
<pre>
-public void <any-method-name>(@<Annotation> <any type> arg0, @<Annotation> <any type> arg1, ... @Thrown Throwable argi, ... @<Annotation> <any type> argN) throws <Exception1>,<Exception2>,...,<ExceptionN>
+public void <any-method-name>(@<Annotation> <any type> arg0, @<Annotation> <any type> arg1, ... @Thrown <Throwable-Type> argi, ... @<Annotation> <any type> argN) throws <Exception1>,<Exception2>,...,<ExceptionN>
</pre>
</p><p>
-Where 0 <= i <= N.
+Where 0 <= i <= N and <tt>Throwable-Type</tt> can be one of the following:
+<ul>
+<li><code>java.lang.Throwable</code></li>
+<li><code>any runtime exception</code></li>
+<li>an exception declared to be thrown by the joinpoint you are intercepting</li>
+</ul>
</p><p>
<h4>Binding After Throwing Advices</h4>
@@ -47,36 +52,40 @@
<h4>Examples</h4>
</p><p>
-You can find examples of after-throwing advices in the <tt>Aspect.java</tt> file.
+You can find examples of after-throwing advice 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.
+Is the simplest you can write, since the <tt>@Thrown</tt>-annotated 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:
+The following advice signature is valid to intercept a method execution throwing a
+<code>POJOException</code> exception:
<pre>
-public void afterThrowingJoinPoint(@JoinPoint MethodExecution methodExecution, @Thrown Throwable thrown)
+public void afterThrowingJoinPoint(@JoinPoint MethodExecution methodExecution, @Thrown POJOException 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:
+If the method being intercepted receives an <tt>String</tt> argument, and you want to intercept that method
+throwing RuntimeExceptions, these after-throwing signatures are also valid:
</p><p>
<pre>
-public void afterThrowingArg(@Thrown Throwable thrown, @Arg String argument)
-public void afterThrowingJoinPointArg(@Thrown Throwable thrown, @JoinPoint MethodExecution methodExecution, @Arg String argument)
+public void afterThrowingArg(@Thrown RuntimeException thrown, @Arg String argument)
+public void afterThrowingJoinPointArg(@Thrown NullPointerException thrown, @JoinPoint MethodExecution methodExecution, @Arg String argument)
</pre>
</p><p>
+Note that the first one receives a <tt>RuntimeException</tt> as <tt>@Thrown</tt>-annotated parameter. Thus, this advice is going to be invoked
+only when the intercepted method throws a <tt>RuntimeException</tt>. The second advice is more specific regarding this parameter, and will
+be invoked only when the intercepted method throws a <tt>NullPointerException</tt>.
</p><p>
+</p><p>
<h4>Run the example</h4>
</p><p>
@@ -88,18 +97,32 @@
<p>It will javac the files and then run the AOPC precompiler to manipulate the bytecode, then finally run the example. The output should be similar to this:</p>
<pre>
_run.aopc:
- [java] Calling POJO->throwExceptionMethod()
+ [java]
+ [java] Calling POJO->throwPOJOExceptionMethod()
[java] ====================================
- [java] RUNNING POJO->throwsExceptionMethod("argument")
- [java] >>> afterThrowing: java.lang.Exception: POJO Exception
- [java] >>> afterThrowingJoinPoint: java.lang.Exception: POJO Exception
- [java] >>> afterThrowingArg: java.lang.Exception: POJO Exception
- [java] >>> afterThrowingJoinPointArg: java.lang.Exception: POJO Exception
- [java] Caching Exception java.lang.Exception: POJO Exception
-
- [java] Calling POJO->throwNothingMethod()
+ [java] RUNNING POJO->throwsPOJOExceptionMethod("argument")
+ [java] >>> afterThrowing: POJOException
+ [java] >>> afterThrowingJoinPoint: POJOException
+ [java] Catching Exception POJOException
+ [java]
+ [java] Calling POJO->throwRuntimeExceptionMethod()
+ [java] ====================================
+ [java] RUNNING POJO->throwsRuntimeExceptionMethod("argument")
+ [java] >>> afterThrowing: java.lang.ArrayIndexOutOfBoundsException
+ [java] >>> afterThrowingArg: java.lang.ArrayIndexOutOfBoundsException
+ [java] Catching Exception java.lang.ArrayIndexOutOfBoundsException
+ [java]
+ [java] Calling POJO->throwNullPointerExceptionMethod()
+ [java] ====================================
+ [java] RUNNING POJO->throwsNullPointerExceptionMethod("argument")
+ [java] >>> afterThrowing: java.lang.NullPointerException
+ [java] >>> afterThrowingArg: java.lang.NullPointerException
+ [java] >>> afterThrowingJoinPointArg: java.lang.NullPointerException
+ [java] Catching Exception java.lang.NullPointerException
+ [java]
+ [java] Calling POJO->throwNothingMethod()
[java] ==================================
- [java] RUNNING POJO->throwNothingMethod()
+ [java] RUNNING POJO->throwNothingMethod()
[java] No Exception this time
</pre>
</p>
Modified: projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml 2008-10-20 05:34:36 UTC (rev 79724)
+++ projects/aop/trunk/aop/docs/examples/after-throwing/jboss-aop.xml 2008-10-20 05:40:29 UTC (rev 79725)
@@ -5,6 +5,9 @@
<bind pointcut="execution(* POJO->*(..))">
<throwing name="afterThrowing" aspect="Aspect"/>
+ </bind>
+
+ <bind pointcut="execution(* POJO->*(..) throws POJOException)">
<throwing name="afterThrowingJoinPoint" aspect="Aspect"/>
</bind>
More information about the jboss-cvs-commits
mailing list