KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > flow > ControllerWithParams


1 /*
2  * $Id: ControllerWithParams.java,v 1.3 2004/06/27 17:41:31 eelco12 Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/ControllerWithParams.java,v $
4  */

5
6 package org.infohazard.maverick.flow;
7
8 import java.util.Map JavaDoc;
9 import javax.servlet.ServletException JavaDoc;
10
11 /**
12  * This is a Decorator pattern, adding params defined for a controller.
13  */

14 public class ControllerWithParams implements Controller
15 {
16     /**
17      * the decorated controller.
18      */

19     protected Controller decorated;
20     /**
21      * the controller parameters.
22      */

23     protected Map JavaDoc params;
24     
25     /**
26      * Create a decorator for the given controller with the given parameters.
27      * @param decorate the controller to decorate
28      * @param params the parameters
29      */

30     public ControllerWithParams(Controller decorate, Map JavaDoc params)
31     {
32         if (params == null)
33             throw new IllegalArgumentException JavaDoc("Don't use this decorator without params");
34             
35         this.decorated = decorate;
36         this.params = params;
37     }
38
39     /**
40      * Puts all controller parameters and then defers execution to the command
41      * method of the controller.
42      * @see org.infohazard.maverick.flow.Controller#go(org.infohazard.maverick.flow.ControllerContext)
43      */

44     public String JavaDoc go(ControllerContext cctx) throws ServletException JavaDoc
45     {
46         ((MaverickContext)cctx).putAllControllerParams(this.params);
47         
48         return this.decorated.go(cctx);
49     }
50     /**
51      * Get decorated.
52      * @return Controller Returns the decorated.
53      */

54     public Controller getDecorated()
55     {
56         return decorated;
57     }
58 }
59
Popular Tags