📄 modelmanagerimp.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.model;
import com.jdon.model.config.ModelXmlConfig;
import com.jdon.model.cache.ModelCacheManager;
import com.jdon.controller.model.Model;
import com.jdon.util.Debug;
import com.jdon.model.mapping.*;
/**
* 本类是产生框架使用的各种Model,面向客户端调用
* 如果需要调用Model相关,调用本ModelManager
*
* 为提高性能,可在此嵌入对象池。
*
* <p>Copyright: Jdon.com Copyright (c) 2003</p>
* <p></p>
* @author banq
* @version 1.0
*/
public class ModelManagerImp implements ModelManager{
public final static String module = ModelManagerImp.class.getName();
private ModelXmlConfig modelXmlLoader;
public ModelCacheManager modelCacheManager;
public ModelManagerImp(ModelXmlConfig modelXmlLoader, ModelCacheManager modelCacheManager) {
this.modelXmlLoader = modelXmlLoader;
this.modelCacheManager = modelCacheManager;
}
/**
* 从Modelhandler池中借用一个Handler实例
* 并且初始化
*
* 借用后必须归还
*/
public ModelHandler borrowtHandlerObject(String formName) {
ModelHandler modelHandler = null;
try {
modelHandler = modelXmlLoader.borrowtHandlerObject(formName);
modelHandler.setModelMapping(modelXmlLoader.getModelMapping(formName));
} catch (Exception ex) {
Debug.logError("can't get the modelHandler for the formName " + formName,
module);
}
return modelHandler;
}
/**
* 归还从Modelhandler池中借用一个实例
*/
public void returnHandlerObject(ModelHandler modelHandler) {
if (modelHandler == null) return;
try {
modelXmlLoader.returnHandlerObject(modelHandler);
} catch (Exception ex) {
Debug.logError(" return modelHandler error" + ex, module);
}
}
/**
* 获得一个新的Model实例
*/
public Model getModelObject(String formName) {
try {
return modelXmlLoader.getModelObject(formName);
} catch (Exception ex) {
Debug.logError(ex + "", module);
}
return null;
}
/**
* 将Model实例加入缓存
* @param modelKey
* @param model
*/
public void addCache(ModelKey modelKey, Model model) {
if (modelKey.getDataKey() == null)
return;
if (modelKey.getModelClassName() != null)
modelCacheManager.setCache2(modelKey.getDataKey(),
modelKey.getModelClassName().getName(), model);
else
modelCacheManager.setCache(modelKey.getDataKey(),
modelKey.getFormName(), model);
}
/**
* 将Model实例加入缓存
*/
public void addCache(Object key, String className, Model model) {
if (key == null)
return;
modelCacheManager.setCache2(key, className, model);
}
/**
* 获取加入缓存的Model实例
*/
public Model getCache(ModelKey modelKey) {
if (modelKey.getModelClassName() != null)
return modelCacheManager.getCache2(modelKey.getDataKey(),
modelKey.getModelClassName().getName());
else
return modelCacheManager.getCache(modelKey.getDataKey(),
modelKey.getFormName());
}
/**
* 获取加入缓存的Model实例
*/
public Model getCache(Object key, String className) {
return modelCacheManager.getCache2(key, className);
}
/**
* 取出缓存中的Model实例
*/
public void removeCache(Object dataKey) throws Exception {
modelCacheManager.removeCache(dataKey);
}
public boolean isNull(String s) {
boolean isNull = false;
if (s == null)
isNull = true;
else if (s.equals(""))
isNull = true;
else if (s.equals("null"))
isNull = true;
return isNull;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -