KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > servlets > MVCServletHandlerImpl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.servlets;
14
15 import java.lang.reflect.InvocationTargetException JavaDoc;
16 import java.lang.reflect.Method JavaDoc;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20
21 import org.apache.log4j.Logger;
22
23
24 /**
25  * Default implementation of a MVCHandler. Calls the command through reflection.
26  * @author Philipp Bracher
27  * @version $Id: AdminInterfaceServlet.java 661 2005-05-03 14:10:45Z philipp $
28  */

29 public abstract class MVCServletHandlerImpl implements MVCServletHandler {
30
31     protected static final String JavaDoc VIEW_ERROR = "error"; //$NON-NLS-1$
32

33     /**
34      * Logger.
35      */

36     private static Logger log = Logger.getLogger(MVCServletHandlerImpl.class);
37
38     protected HttpServletRequest JavaDoc request;
39
40     protected HttpServletResponse JavaDoc response;
41
42     private String JavaDoc name;
43
44     protected MVCServletHandlerImpl(String JavaDoc name, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
45         super();
46         this.name = name;
47         this.request = request;
48         this.response = response;
49     }
50
51     /**
52      * @see info.magnolia.cms.servlets.MVCServletHandler#getName()
53      */

54     public String JavaDoc getName() {
55         return name;
56     }
57
58     /**
59      * Call the method through reflection
60      * @param command
61      * @return the name of the view to show (used in renderHtml)
62      */

63     public String JavaDoc execute(String JavaDoc command) {
64         String JavaDoc view = VIEW_ERROR;
65         Method JavaDoc method;
66
67         try {
68             method = this.getClass().getMethod(command, new Class JavaDoc[]{});
69             // method.setAccessible(true);
70
view = (String JavaDoc) method.invoke(this, new Object JavaDoc[]{});
71         }
72         catch (InvocationTargetException JavaDoc e) {
73             log.error("can't call command: " + command, e.getTargetException()); //$NON-NLS-1$
74
}
75         catch (Exception JavaDoc e) {
76             log.error("can't call command: " + command, e); //$NON-NLS-1$
77
}
78
79         return view;
80     }
81
82 }
83
Popular Tags