7 import java.lang.reflect.*;
8 import javax.servlet.http.*;
9 import mir.servlet.ServletModuleException;
14 * Dispatcher, der in einer ServletModule-Klasse, die Methode, die per Http-Post oder Get
15 * Parameter "do" angegeben wurde, ausruft.
17 public final class ServletModuleDispatch {
19 private static Logfile theLog;
20 private static final Class[] SIGNATURE =
21 { HttpServletRequest.class, HttpServletResponse.class };
25 theLog = Logfile.getInstance("/tmp/smod.dispatch");
29 * privater Konstruktor, um versehentliche Instantiierung zu verhindern
31 private ServletModuleDispatch () {
35 * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule
36 * mit dem per HttpServletRequest angegebenen Paramter <code>do</code> auf.
37 * Ist kein Parameter angegeben, so wird versucht, in die <code>defaultAction</code>
38 * des ServletModules zu springen.
40 * @param req Http-Request, das vom Dispatcher an die Methode des
41 * ServletModules durchgereicht wird
42 * @param res Http-Response, die vom Dispatcher an die Methode des
43 * ServletModules durchgereicht wird
44 * @param sMod ServletModule, an das dispatched wird.
45 * @param mod Name des Modules als String (für Logfile)
48 public static void dispatch(ServletModule sMod, HttpServletRequest req,
49 HttpServletResponse res) throws ServletModuleException, ServletModuleUserException
51 //sMod.predeliver(req,res);
53 String doParam = req.getParameter("do");
54 theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam);
55 if (doParam == null) {
56 if (sMod.defaultAction() != null) doParam = sMod.defaultAction();
57 else throw new ServletModuleException("no parameter do supplied!");
61 Method method = sMod.getClass().getMethod(doParam,SIGNATURE);
63 method.invoke(sMod,new Object[] {req,res} );
66 else theLog.printDebugInfo("method lookup unsuccesful");
68 catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());}
69 catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());}
70 catch ( InvocationTargetException e) {
71 if (e.getTargetException().getClass().getName().equals("mir.servlet.ServletModuleUserException")) {
72 throw new ServletModuleUserException(((ServletModuleUserException)e.getTargetException()).getMsg());
75 throw new ServletModuleException(e.getTargetException().toString());
78 catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());}
80 //hopefully we don't get here ...
81 throw new ServletModuleException("delivery failed! -- ");