From ddfe4cb13b915dd4a41ab5c3fe23b1f96e29e9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Sun, 26 Oct 2014 13:10:38 -0200 Subject: [PATCH 1/7] Adding docs to interceptor annotations --- .../java/br/com/caelum/vraptor/Accepts.java | 11 +++++++++++ .../java/br/com/caelum/vraptor/AfterCall.java | 11 +++++++++++ .../java/br/com/caelum/vraptor/AroundCall.java | 18 ++++++++++++++++++ .../java/br/com/caelum/vraptor/BeforeCall.java | 11 +++++++++++ 4 files changed, 51 insertions(+) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java index 64fdfa475..cb277733c 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java @@ -21,6 +21,17 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Defines a method with a condition to intercept or not the current stack. The annotated method must return a + * {@code boolean} value and you can't have more than one method annotated with {@link Accepts} in the same class. + * + * + * \@Accepts + * public boolean accepts(ControllerMethod method) { + * return method.containsAnnotation(Audit.class); + * } + * + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java index 14b6324d9..6fd8bf9cf 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java @@ -21,6 +21,17 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Executes a method after the current call. The target method must have no parameters, and you can't have more than + * one method annotated with {@link AfterCall} in the same class. + * + * + * \@AfterCall + * public void intercept() { + * System.out.println("code executed after stack"); + * } + * + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/AroundCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/AroundCall.java index 9f9d9bfa6..efbf48f78 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/AroundCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/AroundCall.java @@ -21,6 +21,24 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import br.com.caelum.vraptor.core.InterceptorStack; +import br.com.caelum.vraptor.interceptor.SimpleInterceptorStack; + +/** + * Executes a method in the current call. You should use the {@code SimpleInterceptorStack#next()} to execute + * the next interceptor stack. The target method must have only one parameter with {@link SimpleInterceptorStack} or + * {@link InterceptorStack} type, and you can't have more than one method annotated with {@link AroundCall} + * in the same class. + * + * + * \@AroundCall + * public void intercept(SimpleInterceptorStack stack) { + * System.out.println("Executing before"); + * stack.next(); + * System.out.println("Executing after"); + * } + * + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java index cc424696a..181b36500 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java @@ -21,6 +21,17 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Executes a method before the current call, and you can't have more than one method annotated with {@link BeforeCall} + * in the same class. The target method must have no parameters. + * + * + * \@BeforeCall + * public void intercept() { + * System.out.println("code executed before stack"); + * } + * + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) From fb5208b242647ee7acfe66577b330d8a9bf6a4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Sun, 26 Oct 2014 13:22:34 -0200 Subject: [PATCH 2/7] Adding more docs about interceptor annotations --- .../vraptor/interceptor/AcceptsForPackages.java | 3 +++ .../vraptor/interceptor/AcceptsWithAnnotations.java | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java index df877b1b8..5c75b6c67 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java @@ -22,6 +22,9 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * A class level annotation to define that the stack will intercepted only for package or sub-packages. + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsWithAnnotations.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsWithAnnotations.java index 1255ea710..dd456bd6f 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsWithAnnotations.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsWithAnnotations.java @@ -23,6 +23,19 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * A class level annotation to define that the stack will intercepted when an annotation is present. + * + * \@AcceptsWithAnnotations(Audit.class) + * public class AuditInterceptor { + * + * \@AroundCall + * public void around(SimpleInterceptorStack stack) { + * stack.next(); + * } + * } + * + */ @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) From cdd00e8f967ad0831b147d5d012040ad19b40565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 27 Oct 2014 12:01:50 -0200 Subject: [PATCH 3/7] Adding example of use about PackagesAcceptor --- .../caelum/vraptor/interceptor/AcceptsForPackages.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java index 5c75b6c67..5823253b1 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/interceptor/AcceptsForPackages.java @@ -23,7 +23,13 @@ import java.lang.annotation.Target; /** - * A class level annotation to define that the stack will intercepted only for package or sub-packages. + * A class level annotation to define that the stack will intercepted only for packages and subpackages. In + * the example below all classes inside {@code com.myapp.controllers} will be intercepted, including subpackages. + * + * \@AcceptsForPackages("com.myapp.controllers") + * public class AuditInterceptor { + * } + * */ @Documented @Retention(RetentionPolicy.RUNTIME) From 0c682932524f7d4af8719acba09337bc53b53bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 27 Oct 2014 17:40:29 -0200 Subject: [PATCH 4/7] Clarifying text about accept restriction --- vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java index cb277733c..87dcce055 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/Accepts.java @@ -23,7 +23,7 @@ /** * Defines a method with a condition to intercept or not the current stack. The annotated method must return a - * {@code boolean} value and you can't have more than one method annotated with {@link Accepts} in the same class. + * {@code boolean} value and you can't have more than one accept strategy in the same class. * * * \@Accepts From 12effe1b76d48f182eac94fd983b6f6b00c4e27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 27 Oct 2014 17:43:59 -0200 Subject: [PATCH 5/7] Adding info about stack.next --- .../src/main/java/br/com/caelum/vraptor/AfterCall.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java index 6fd8bf9cf..80f76f3cf 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java @@ -23,7 +23,8 @@ /** * Executes a method after the current call. The target method must have no parameters, and you can't have more than - * one method annotated with {@link AfterCall} in the same class. + * one method annotated with {@link AfterCall} in the same class. The method {@code SimpleInterceptorStack#next} will + * call implicity after the execution. * * * \@AfterCall From c277c947769f6c43bfc7ea8aa3a3d1c926785774 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 27 Oct 2014 17:46:29 -0200 Subject: [PATCH 6/7] Rolling back info about next call --- .../src/main/java/br/com/caelum/vraptor/AfterCall.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java index 80f76f3cf..eb5664771 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/AfterCall.java @@ -23,8 +23,7 @@ /** * Executes a method after the current call. The target method must have no parameters, and you can't have more than - * one method annotated with {@link AfterCall} in the same class. The method {@code SimpleInterceptorStack#next} will - * call implicity after the execution. + * one method annotated with {@link AfterCall} in the same class. * * * \@AfterCall From 94f4bca9469c718ee2dba0992d942b37735b0c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Garcia?= Date: Mon, 27 Oct 2014 17:48:24 -0200 Subject: [PATCH 7/7] Adding info about next call --- .../src/main/java/br/com/caelum/vraptor/BeforeCall.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java b/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java index 181b36500..70fec66ec 100644 --- a/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java +++ b/vraptor-core/src/main/java/br/com/caelum/vraptor/BeforeCall.java @@ -23,7 +23,8 @@ /** * Executes a method before the current call, and you can't have more than one method annotated with {@link BeforeCall} - * in the same class. The target method must have no parameters. + * in the same class. The target method must have no parameters. The method + * {@code br.com.caelum.vraptor.interceptor.SimpleInterceptorStack#next} will call implicity after the execution. * * * \@BeforeCall