1 13 package info.magnolia.cms.servlets; 14 15 import java.lang.reflect.InvocationTargetException ; 16 import java.lang.reflect.Method ; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import javax.servlet.http.HttpServletResponse ; 20 21 import org.apache.log4j.Logger; 22 23 24 29 public abstract class MVCServletHandlerImpl implements MVCServletHandler { 30 31 protected static final String VIEW_ERROR = "error"; 33 36 private static Logger log = Logger.getLogger(MVCServletHandlerImpl.class); 37 38 protected HttpServletRequest request; 39 40 protected HttpServletResponse response; 41 42 private String name; 43 44 protected MVCServletHandlerImpl(String name, HttpServletRequest request, HttpServletResponse response) { 45 super(); 46 this.name = name; 47 this.request = request; 48 this.response = response; 49 } 50 51 54 public String getName() { 55 return name; 56 } 57 58 63 public String execute(String command) { 64 String view = VIEW_ERROR; 65 Method method; 66 67 try { 68 method = this.getClass().getMethod(command, new Class []{}); 69 view = (String ) method.invoke(this, new Object []{}); 71 } 72 catch (InvocationTargetException e) { 73 log.error("can't call command: " + command, e.getTargetException()); } 75 catch (Exception e) { 76 log.error("can't call command: " + command, e); } 78 79 return view; 80 } 81 82 } 83 | Popular Tags |