📄 commanddispatcher.java
字号:
package com.doone.wskfmgr.common.command;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Instances turn a request into a command, which may then be executed.
*
* @pattern Command (role=commandDispatcher)
*
* @generatedBy CodePro at 07-1-30 H9:22
*
* @author wushaol
*
* @version $Revision$
*/
public class CommandDispatcher {
/**
* The name of the servlet parameter specifying the command or action.
*/
private static final String ACTION_PARAMETER_NAME = "action";
/**
* The servlet request.
*/
private HttpServletRequest request;
/**
* The servlet response.
*/
private HttpServletResponse response;
/**
* The properties associated with the request.
*/
private java.util.Properties properties;
/**
* Create a new instance of the dispatcher containing the parameters from
* the servlet request.
*
* @param request the servlet request
* @param response the servlet response
*/
public CommandDispatcher(
HttpServletRequest request,
HttpServletResponse response) {
this.request = request;
this.response = response;
this.properties = extractProperties(request);
}
/**
* Get the servlet request properties.
*
* @return the properties for the servlet request
*/
public Properties getProperties() {
return properties;
}
/**
* Get the servlet request.
*
* @return the servlet request
*/
public HttpServletRequest getRequest() {
return request;
}
/**
* Get the servlet response.
*
* @return the servlet response
*/
public HttpServletResponse getResponse() {
return response;
}
/**
* Get the command specified by the servlet request.
*
* @return the command specified by the servlet request
*/
public CommandInterface getCommand() {
String param = getProperties().getProperty(ACTION_PARAMETER_NAME);
if (param == null) {
return null;
}
return CommandFactory.getCommand(param);
}
/**
* @see RegistCommandInterface.executeCommand()
*/
public String executeCommand() throws Exception {
CommandInterface command = getCommand();
if (command == null)
return null;
return command.execute(this);
}
/**
* Translates servlet request properties to java properties.
*
* @param the servlet request object
*
* @return the servlet request properties
*/
private Properties extractProperties(HttpServletRequest servletrequest) {
properties = new Properties();
Enumeration enumeration = servletrequest.getParameterNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = servletrequest.getParameterValues(name)[0];
properties.put(name, value);
}
return properties;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -