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

📄 initplugin.java

📁 Java/J2EE框架Jdon-Framework系统的Sample
💻 JAVA
字号:
/**
 * Copyright 2005 Jdon.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */

package com.jdon.strutsutil;

import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.PlugIn;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.config.PlugInConfig;

import javax.servlet.ServletException;
import com.jdon.util.Debug;
import java.util.*;


import javax.servlet.ServletContext;
import com.jdon.controller.KeyConstants;

import com.jdon.controller.ContainerSetupScript;
import java.io.InputStream;
import com.jdon.util.FileLocator;


/**
 * Struts应用框架初始化
 *
 *
 * 需要在struts_config.xml中加入:
 *   <plug-in className="com.jdon.strutsutil.InitPlugIn"/>
 *
 * 设置本初始化,可使用对象池等技术配置
 *
 * <p>Copyright: Jdon.com Copyright (c) 2003</p>
 * <p></p>
 * @author banq
 * @version 1.0
 */

public class InitPlugIn implements PlugIn, KeyConstants{
  public final static String module = InitPlugIn.class.getName();

  private final static String CONFIG_NAME = "modelmapping-config";
  private ContainerSetupScript css = new ContainerSetupScript();
  private FileLocator fileLocator = new FileLocator();

  private ActionServlet servlet = null;
  private ModuleConfig config = null;


  public void init(ActionServlet servlet, ModuleConfig config) throws
      ServletException {
    // Remember our associated configuration and servlet
    this.config = config;
    this.servlet = servlet;

    ServletContext sc = servlet.getServletContext();

    Collection listConfigs = getConfigs(sc);
    css.prepare(listConfigs, sc);

  }

  private List getConfigs(ServletContext sc) throws ServletException {
    String config_file = "";
    List configList = new ArrayList();
    PlugInConfig[] plugInConfigs = config.findPlugInConfigs();
    int length = plugInConfigs.length;
    for (int i = 0; i < length; i++) {
      Set entries = plugInConfigs[i].getProperties().entrySet();
      Iterator iter = entries.iterator();
      while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        if (CONFIG_NAME.equals(entry.getKey())) { //可能有多个配置
          config_file = (String) entry.getValue();
          Debug.logInfo(" look up a config: " + config_file,
                        module);
          if (checkExsit(config_file)){
            Debug.logInfo(" got the config: " + config_file,
                        module);
            configList.add(config_file);
          }
          else
            Debug.logError(" cannot locate the config: " + config_file ,
                          module);

        }
      }
    }
    return configList;
  }

  public boolean checkExsit(String config_file){
    boolean ret = false;
    InputStream xmlFile = null;
    try{
      xmlFile = fileLocator.getConfPathXmlStream(config_file);
      if (xmlFile != null)
        ret = true;
    }catch(Exception ex){

    }
    return ret;
  }

  public void destroy() {
    css.destroyed(servlet.getServletContext());
    config = null;
    servlet = null;
  }

}

⌨️ 快捷键说明

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