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 static Logfile theLog;
22 theLog = Logfile.getInstance("/tmp/smod.dispatch");
26 * privater Konstruktor, um versehentliche Instantiierung zu verhindern
28 private ServletModuleDispatch () {
32 * Die Dispatch-Routine ruft das von dem Hauptservlet kommende ServletModule
33 * mit dem per HttpServletRequest angegebenen Paramter <code>do</code> auf.
34 * Ist kein Parameter angegeben, so wird versucht, in die <code>defaultAction</code>
35 * des ServletModules zu springen.
37 * @param req Http-Request, das vom Dispatcher an die Methode des
38 * ServletModules durchgereicht wird
39 * @param res Http-Response, die vom Dispatcher an die Methode des
40 * ServletModules durchgereicht wird
41 * @param sMod ServletModule, an das dispatched wird.
42 * @param mod Name des Modules als String (für Logfile)
45 public static void dispatch(ServletModule sMod, HttpServletRequest req,
46 HttpServletResponse res) throws ServletModuleException
48 //sMod.predeliver(req,res);
50 String doParam = req.getParameter("do");
51 //theLog.printInfo("SerletModuleDispatch: " + sMod.toString() + " with method " + doParam);
52 if (doParam == null) {
53 if (sMod.defaultAction() != null) doParam = sMod.defaultAction();
54 else throw new ServletModuleException("Parameter do nicht angegeben!");
57 Class[] params= { HttpServletRequest.class, HttpServletResponse.class};
60 Method method = sMod.getClass().getMethod(doParam,params);
62 method.invoke(sMod,new Object[] {req,res} );
65 else theLog.printDebugInfo("method lookup unsuccesful");
67 catch ( NoSuchMethodException e) { throw new ServletModuleException("no such method!" + e.toString());}
68 catch ( SecurityException e) { throw new ServletModuleException("method not allowed!" + e.toString());}
69 catch ( InvocationTargetException e) {throw new ServletModuleException("target method exception!" + e.getTargetException().toString());}
70 catch ( IllegalAccessException e) { throw new ServletModuleException("illegal method not allowed!" + e.toString());}
71 // catch ( Exception e ) { throw new ServletModuleException(e.toString()); }
73 throw new ServletModuleException("delivery failed! -- ");