initplugin.java
来自「一个非常好的FRAMWRK!是一个外国组织做的!不!」· Java 代码 · 共 125 行
JAVA
125 行
/**
* Copyright 2003-2005 the original author or authors.
* 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 java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
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 com.jdon.container.config.app.AppConfigureCollection;
import com.jdon.container.startup.ContainerSetupScript;
import com.jdon.util.Debug;
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{
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);
AppConfigureCollection appConfigureFiles = new AppConfigureCollection(listConfigs);
css.prepare(appConfigureFiles, 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 + =
减小字号Ctrl + -
显示快捷键?