KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: ThrowawayControllerAdapter.java,v 1.5 2004/06/27 17:40:55 eelco12 Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/ThrowawayControllerAdapter.java,v $
4  */

5 package org.infohazard.maverick.flow;
6
7 import javax.servlet.ServletException JavaDoc;
8
9 import org.jdom.Element;
10
11 /**
12  * This adapter masquerades as a singleton controller but actually
13  * creates single-use instance controllers.
14  *
15  * created January 27, 2002
16  * @author Jeff Schnitzer
17  * @version $Revision: 1.5 $ $Date: 2004/06/27 17:40:55 $
18  */

19 public class ThrowawayControllerAdapter implements ControllerSingleton
20 {
21     /** class of controller. */
22     protected Class JavaDoc controllerClass;
23
24     /**
25      * Create the adapter.
26      * @param controllerClass the controller class
27      */

28     public ThrowawayControllerAdapter(Class JavaDoc controllerClass)
29     {
30         this.controllerClass = controllerClass;
31     }
32
33     /**
34      * Currently unused.
35      *
36      * @param controllerNode
37      * @exception ConfigException
38      */

39     public void init(Element controllerNode) throws ConfigException
40     {
41     }
42
43     /**
44      * Instantiates a single-use controller, executes it, and returns the result.
45      * @param cctx the controller context.
46      * @return String logical view name (result of command method call of controller)
47      */

48     public String JavaDoc go(ControllerContext cctx) throws ServletException JavaDoc
49     {
50         try
51         {
52             Controller instance = (Controller)this.controllerClass.newInstance();
53
54             return instance.go(cctx);
55         }
56         catch (InstantiationException JavaDoc ex)
57         {
58             throw new ServletException JavaDoc(ex);
59         }
60         catch (IllegalAccessException JavaDoc ex)
61         {
62             throw new ServletException JavaDoc(ex);
63         }
64     }
65 }
66
67
Popular Tags