- Revision
- 477
- Author
- mauro
- Date
- 2007-12-14 12:31:18 -0600 (Fri, 14 Dec 2007)
Log Message
WAFFLE-48: Refactored annotations.
Modified Paths
- trunk/examples/mydvds-example/src/main/java/org/codehaus/waffle/example/mydvds/action/DvdsController.java
- trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/UploadController.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/ActionMethod.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/DefaultActionMethod.java
- trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java
- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/intercept/SecurityMethodInterceptorTest.java
- trunk/waffle-distribution/src/site/content/action-methods.html
Added Paths
Diff
Modified: trunk/examples/mydvds-example/src/main/java/org/codehaus/waffle/example/mydvds/action/DvdsController.java (476 => 477)
--- trunk/examples/mydvds-example/src/main/java/org/codehaus/waffle/example/mydvds/action/DvdsController.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/examples/mydvds-example/src/main/java/org/codehaus/waffle/example/mydvds/action/DvdsController.java 2007-12-14 18:31:18 UTC (rev 477) @@ -1,10 +1,10 @@ package org.codehaus.waffle.example.mydvds.action; -import org.codehaus.waffle.example.mydvds.persistence.PersistenceManager; +import org.codehaus.waffle.action.annotation.ActionMethod; import org.codehaus.waffle.example.mydvds.model.Dvd; import org.codehaus.waffle.example.mydvds.model.Passport; import org.codehaus.waffle.example.mydvds.model.User; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; +import org.codehaus.waffle.example.mydvds.persistence.PersistenceManager; public class DvdsController { @@ -19,7 +19,7 @@ } // just to be intercepted - @DefaultActionMethod + @ActionMethod(asDefault=true) public void index() { }
Modified: trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/UploadController.java (476 => 477)
--- trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/UploadController.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/examples/simple-example/src/main/java/org/codehaus/waffle/example/simple/UploadController.java 2007-12-14 18:31:18 UTC (rev 477) @@ -4,7 +4,8 @@ import java.util.List; import org.apache.commons.fileupload.FileItem; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; +import org.codehaus.waffle.action.annotation.ActionMethod; +import org.codehaus.waffle.action.annotation.PRG; import org.codehaus.waffle.io.FileUploader; public class UploadController { @@ -17,9 +18,9 @@ this.uploader = uploader; } - @DefaultActionMethod(prg=false) + @ActionMethod(asDefault=true) + @PRG(use=false) // PRG needs to be disabled to allow request-scope content to be accessible in referring view public void upload(){ - // PRG needs to be disabled to allow request-scope content to be accessible in referring view files = uploader.getFileItems(); errors = uploader.getErrors(); }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java (476 => 477)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/AbstractMethodDefinitionFinder.java 2007-12-14 18:31:18 UTC (rev 477) @@ -10,18 +10,6 @@ *****************************************************************************/ package org.codehaus.waffle.action; -import org.codehaus.waffle.WaffleException; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; -import org.codehaus.waffle.bind.ValueConverterFinder; -import org.codehaus.waffle.context.ContextContainer; -import org.codehaus.waffle.context.RequestLevelContainer; -import org.codehaus.waffle.i18n.MessagesContext; -import org.codehaus.waffle.monitor.ActionMonitor; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.MessageFormat; @@ -32,6 +20,19 @@ import java.util.List; import java.util.Map; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.codehaus.waffle.WaffleException; +import org.codehaus.waffle.action.annotation.ActionMethod; +import org.codehaus.waffle.bind.ValueConverterFinder; +import org.codehaus.waffle.context.ContextContainer; +import org.codehaus.waffle.context.RequestLevelContainer; +import org.codehaus.waffle.i18n.MessagesContext; +import org.codehaus.waffle.monitor.ActionMonitor; + /** * Abstract base implementation for all method definition finders * @@ -96,7 +97,7 @@ } for (Method method : controllerType.getMethods()) { - if (method.isAnnotationPresent(DefaultActionMethod.class)) { + if (isDefaultActionMethod(method)) { defaultMethodCache.put(controllerType, method); // add to cache MethodDefinition methodDefinition = buildDefaultMethodDefinition(method, request); actionMonitor.defaultActionMethodFound(methodDefinition); @@ -107,6 +108,14 @@ throw new NoDefaultActionMethodException(controllerType.getName()); } + private boolean isDefaultActionMethod(Method method) { + ActionMethod actionMethod = method.getAnnotation(ActionMethod.class); + if ( actionMethod != null ){ + return actionMethod.asDefault(); + } + return false; + } + private MethodDefinition findPragmaticActionMethod(Object controller, String methodName, HttpServletRequest request, @@ -157,7 +166,10 @@ private MethodDefinition buildDefaultMethodDefinition(Method method, HttpServletRequest request) { MethodDefinition methodDefinition = new MethodDefinition(method); - DefaultActionMethod defaultActionMethod = method.getAnnotation(DefaultActionMethod.class); + if ( !isDefaultActionMethod(method) ){ + throw new NoDefaultActionMethodException("Method "+method+" is not annotated with @ActionMethod(asDefault=true)."); + } + ActionMethod defaultActionMethod = method.getAnnotation(ActionMethod.class); List<String> arguments = new ArrayList<String>(defaultActionMethod.parameters().length); for (String value : defaultActionMethod.parameters()) {
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/ActionMethod.java (476 => 477)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/ActionMethod.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/ActionMethod.java 2007-12-14 18:31:18 UTC (rev 477) @@ -15,9 +15,15 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Annotation to control action method properties. + * + * @author Mauro Talevi + * @author Michael Ward + */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface ActionMethod { String[] parameters() default {}; - boolean prg() default true; + boolean asDefault() default false; }
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/DefaultActionMethod.java (476 => 477)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/DefaultActionMethod.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/DefaultActionMethod.java 2007-12-14 18:31:18 UTC (rev 477) @@ -15,9 +15,11 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +/** + * @deprecated Use @ActionMethod(asDefault=true) + */ @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface DefaultActionMethod { String[] parameters() default {}; - boolean prg() default true; }
Added: trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/PRG.java (0 => 477)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/PRG.java (rev 0) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/action/annotation/PRG.java 2007-12-14 18:31:18 UTC (rev 477) @@ -0,0 +1,29 @@ +/***************************************************************************** + * Copyright (C) 2005,2006 Michael Ward * + * All rights reserved. * + * ------------------------------------------------------------------------- * + * The software in this package is published under the terms of the BSD * + * style license a copy of which has been included with this distribution in * + * the LICENSE.txt file. * + * * + * Original code by: Michael Ward * + *****************************************************************************/ +package org.codehaus.waffle.action.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotation to control the use of the PRG (Post/Redirect/Get) paradigm. + * See http://en.wikipedia.org/wiki/Post/Redirect/Get + * + * @author Mauro Talevi + * @author Michael Ward + */ [EMAIL PROTECTED](ElementType.METHOD) [EMAIL PROTECTED](RetentionPolicy.RUNTIME) +public @interface PRG { + boolean use() default true; +}
Modified: trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java (476 => 477)
--- trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/main/java/org/codehaus/waffle/servlet/WaffleServlet.java 2007-12-14 18:31:18 UTC (rev 477) @@ -27,8 +27,7 @@ import org.codehaus.waffle.action.ActionMethodResponse; import org.codehaus.waffle.action.ActionMethodResponseHandler; import org.codehaus.waffle.action.MethodDefinition; -import org.codehaus.waffle.action.annotation.ActionMethod; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; +import org.codehaus.waffle.action.annotation.PRG; import org.codehaus.waffle.bind.DataBinder; import org.codehaus.waffle.bind.RequestAttributeBinder; import org.codehaus.waffle.context.ContextContainer; @@ -208,23 +207,18 @@ } /** - * Determine if PRG paradigm is used from the "prg" attribute of the action method annotations + * Determine if PRG paradigm is used from the @PRG annotation of the action method * * @param methodDefinition the MethodDefinition - * @return A boolean flag, defaults to <code>true</code> + * @return A boolean flag, defaults to <code>true</code> if no annotation found */ private boolean usePRG(MethodDefinition methodDefinition) { Method method = methodDefinition.getMethod(); - // first check ActionMethod annotation - ActionMethod actionMethod = method.getAnnotation(ActionMethod.class); - if ( actionMethod != null ){ - return actionMethod.prg(); + // look for PRG annotation + PRG prg = method.getAnnotation(PRG.class); + if ( prg != null ){ + return prg.use(); } - // then check DefaultActionMethod annotation - DefaultActionMethod defaultActionMethod = method.getAnnotation(DefaultActionMethod.class); - if ( defaultActionMethod != null ){ - return defaultActionMethod.prg(); - } // else default to true return true; }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java (476 => 477)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/AnnotatedMethodDefinitionFinderTest.java 2007-12-14 18:31:18 UTC (rev 477) @@ -17,7 +17,7 @@ import ognl.TypeConverter; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; +import org.codehaus.waffle.action.annotation.ActionMethod; import org.codehaus.waffle.bind.ognl.OgnlValueConverter; import org.codehaus.waffle.bind.ognl.OgnlValueConverterFinder; import org.codehaus.waffle.context.ContextContainer; @@ -699,7 +699,7 @@ public class ControllerWithDefaultActionMethod { - @DefaultActionMethod(parameters = { "helloworld" }) + @ActionMethod(asDefault=true, parameters = { "helloworld" }) public void foobar(String value) { } @@ -707,7 +707,7 @@ public class ControllerWithDefaultActionMethodNoValue { - @DefaultActionMethod + @ActionMethod(asDefault=true) public void foobar() { }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java (476 => 477)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/ParanamerMethodDefinitionFinderTest.java 2007-12-14 18:31:18 UTC (rev 477) @@ -17,7 +17,7 @@ import ognl.TypeConverter; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; +import org.codehaus.waffle.action.annotation.ActionMethod; import org.codehaus.waffle.bind.ognl.OgnlValueConverter; import org.codehaus.waffle.bind.ognl.OgnlValueConverterFinder; import org.codehaus.waffle.monitor.ActionMonitor; @@ -660,7 +660,7 @@ public class ControllerWithDefaultActionMethod { - @DefaultActionMethod(parameters = { "helloworld" }) + @ActionMethod(asDefault=true, parameters = { "helloworld" }) public void foobar(String value) { } @@ -668,7 +668,7 @@ public class ControllerWithDefaultActionMethodNoValue { - @DefaultActionMethod + @ActionMethod(asDefault=true) public void foobar() { }
Modified: trunk/waffle-core/src/test/java/org/codehaus/waffle/action/intercept/SecurityMethodInterceptorTest.java (476 => 477)
--- trunk/waffle-core/src/test/java/org/codehaus/waffle/action/intercept/SecurityMethodInterceptorTest.java 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-core/src/test/java/org/codehaus/waffle/action/intercept/SecurityMethodInterceptorTest.java 2007-12-14 18:31:18 UTC (rev 477) @@ -7,7 +7,6 @@ import org.codehaus.waffle.action.ActionMethodInvocationException; import org.codehaus.waffle.action.annotation.ActionMethod; -import org.codehaus.waffle.action.annotation.DefaultActionMethod; import org.codehaus.waffle.controller.ControllerDefinition; import org.jmock.Expectations; import org.jmock.Mockery; @@ -88,7 +87,7 @@ public class MyController { - @DefaultActionMethod + @ActionMethod(asDefault=true) public void methodWithDefaultActionMethod() { }
Modified: trunk/waffle-distribution/src/site/content/action-methods.html (476 => 477)
--- trunk/waffle-distribution/src/site/content/action-methods.html 2007-12-14 15:03:28 UTC (rev 476) +++ trunk/waffle-distribution/src/site/content/action-methods.html 2007-12-14 18:31:18 UTC (rev 477) @@ -222,7 +222,7 @@ been triggered. For that Waffle provides the <b>DefaultActionMethod</b> annotation. In the example below we have a <i>CheckoutController</i> that will calculate the shipping cost by default when no other ActionMethod has been triggered. The method that has been annotated with - <b>@DefaultActionMethod(parameters = <a name=""theCart", "customerAddress"">"theCart", + <b>@ActionMethod(asDefault=true, parameters = <a name=""theCart", "customerAddress"">"theCart", "customerAddress"</a>)</b>. These two values, <b>theCart</b> and <b>customerAddress</b>, will be used to resolve that methods arguments. </p> @@ -236,7 +236,7 @@ this.shippingCalculator = shippingCalculator; } - @DefaultActionMethod(parameters = {"theCart", "customerAddress"}) + @ActionMethod(asDefault=true, parameters = {"theCart", "customerAddress"}) public void calculate(Cart cart, Address address) { shippingCost = shippingCalculator.calculate(cart, address); }
To unsubscribe from this list please visit:
