⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionhelper.java

📁 JAVA Servlet2.3外文书籍源码
💻 JAVA
字号:
package forum;

import java.util.HashMap;

/**
 * A helper class from which to look up and retrieve an instance
 * of an Action class to process a specific request.
 *
 * @author    Simon Brown
 */
public class ActionHelper {

  /** the collection of actions that we know about */
  private static HashMap actions = new HashMap();

  /**
   * Called on class loadup to populate the actions collection.
   */
  static {
    actions.put("ViewTopic", "forum.ViewTopicAction");
    actions.put("Login", "forum.LoginAction");
    actions.put("Logout", "forum.LogoutAction");
    actions.put("NewResponse", "forum.NewResponseAction");
    actions.put("ProcessNewResponse", "forum.ProcessNewResponseAction");
    actions.put("DeleteResponse", "forum.DeleteResponseAction");
  }

  /**
   * Given the name/type of request, this method returns tha Action
   * instance appropriate to process the request.
   *
   * @param name    the name (type) of the request
   * @return  an instance of Action (could be null if no mapping has been defined)
   */
  public static Action getAction(String name) {

    System.out.println("ActionHelper : Getting Action for " + name);

    Action action = null;

    try {
      // instantiate the appropriate class to handle the request
      Class c = Class.forName((String)actions.get(name));
      action = (Action)c.newInstance();
    } catch (Exception e) {
      e.printStackTrace();
    }

    System.out.println("ActionHelper : Found " + action.getClass().getName());

    return action;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -