📄 modelxmlconfig.java
字号:
/**
* 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.model.config;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import com.jdon.container.config.app.AppConfigureCollection;
import com.jdon.container.pico.Startable;
import com.jdon.model.handler.HandlerClassFactory;
import com.jdon.model.mapping.ModelMapping;
import com.jdon.util.Debug;
/**
* 根据modelmapping.xml生产相应的实例
* 下面两个方法预先需要执行:
* loadMapping(); //获取xml
* createModelClass();//预先创建一些class
*
* ModelFactory是有状态的类。
*
* @author banq
*/
public final class ModelXmlConfig implements Startable {
public final static String module = ModelXmlConfig.class.getName();
private HandlerClassFactory handlerClassFactory;
private Map configLoadedList = new HashMap();
//formName 与ModelMapping对应关系
private Map mps = new HashMap();
//Model class 池
private Map modelClasses = new HashMap();
//Hanlder class池
private Map handlerClasses = new HashMap();
public ModelXmlConfig(AppConfigureCollection appConfigureFiles,
HandlerClassFactory handlerClassFactory) {
this.handlerClassFactory = handlerClassFactory;
Iterator iter = appConfigureFiles.getConfigList().iterator();
while (iter.hasNext()) {
String configFile = (String) iter.next();
if (!configLoadedList.containsKey(configFile)) {
ConfigureReader configureReader = new ConfigureReader(configFile);
Debug.logVerbose("init configFile = " + configFile, module);
configLoadedList.put(configFile, configureReader);
}
}
}
/**
* 将所有的ConfigureLoader包含的内容合并在一起。
* 本方法相当于start()
* 参考 {@link #detroy()} method
*
*/
public void start() {
try {
Iterator iter = configLoadedList.keySet().iterator();
while (iter.hasNext()) {
String configFile = (String) iter.next();
Debug.logVerbose(" start configFile = " + configFile, module);
ConfigureReader configureLoader = (ConfigureReader)configLoadedList.get(configFile);
Map xmlMaps = configureLoader.load();
mps.putAll(xmlMaps);
Iterator mpsIter = xmlMaps.keySet().iterator();
while(mpsIter.hasNext()){
String formName = (String)mpsIter.next();
Debug.logVerbose(" start formName = " + formName , module);
ModelMapping mp = (ModelMapping)xmlMaps.get(formName);
modelClasses.put(formName, handlerClassFactory.createModel(mp));
handlerClasses.put(formName, handlerClassFactory.createHandler(mp));
}
}
configLoadedList.clear();
} catch (Exception ex) {
Debug.logError(" !!!!!!!framework started error: " + ex, module);
}
}
/**
* 清除内存
*/
public void stop() {
mps.clear();
configLoadedList.clear();
modelClasses.clear();
handlerClasses.clear();
}
public ModelMapping getModelMapping(String formName) {
return (ModelMapping) mps.get(formName);
}
/**
* @return Returns the handlerClasses.
*/
public Map getHandlerClasses() {
return handlerClasses;
}
/**
* @return Returns the modelClasses.
*/
public Map getModelClasses() {
return modelClasses;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -