beanobjectentityconfig.java
来自「mysql集群」· Java 代码 · 共 130 行
JAVA
130 行
/*
* This program is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.meidusa.amoeba.config;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.meidusa.amoeba.bean.PureJavaReflectionProvider;
import com.meidusa.amoeba.util.Initialisable;
import com.meidusa.amoeba.util.InitialisationException;
import com.meidusa.amoeba.util.ObjectUtil;
import com.meidusa.amoeba.util.StringUtil;
/**
* Bean 的基本配置信息
*
* @author <a href=mailto:piratebase@sina.com>Struct chen</a>
* @version $Id: BeanObjectEntityConfig.java 3594 2006-11-23 07:39:25Z struct $
*/
public class BeanObjectEntityConfig extends ConfigEntity implements Cloneable{
private static Logger logger = Logger.getLogger(BeanObjectEntityConfig.class);
private static final long serialVersionUID = 1L;
private String name;
private String className;
private Map<String,Object> params = new HashMap<String,Object>();
private static PureJavaReflectionProvider reflectionProvider = new PureJavaReflectionProvider();
public String getClassName() {
return className;
}
public void setClassName(String beanObject) {
this.className = beanObject;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String,Object> getParams() {
return params;
}
public void setParams(Map<String,Object> params) {
this.params = params;
}
/**
* 用于clone,子类可覆盖此方法
* @return
*/
protected BeanObjectEntityConfig newObject(){
Object object = null;
try {
object = this.getClass().newInstance();
} catch (InstantiationException e) {
logger.error("Instantiation class :"+ this.getClass()+" Exception",e);
} catch (IllegalAccessException e) {
logger.error("IllegalAccess class :"+ this.getClass()+" Exception",e);
}
return (BeanObjectEntityConfig)object;
}
public Object createBeanObject(boolean initEarly) throws ConfigurationException{
try {
Object object= reflectionProvider.newInstance(Class.forName(className));
ParameterMapping.mappingObject(object, getParams());
if(initEarly){
if(object instanceof Initialisable){
((Initialisable)object).init();
}
}
return object;
} catch (ClassNotFoundException e) {
logger.error("instanceo object error:",e);
throw new ConfigurationException(e);
}catch (InitialisationException e){
logger.error("instanceo object error:",e);
throw new ConfigurationException(e);
}
}
public Object clone(){
BeanObjectEntityConfig entityConfig = newObject();
if(entityConfig == null) {
return null;
}
entityConfig.className = this.className;
entityConfig.name = this.name;
Map<String,Object> params = new HashMap<String,Object>();
params.putAll(this.params);
return entityConfig;
}
public int hashCode(){
int hashcode = 37;
hashcode += (this.name == null?0:name.hashCode());
hashcode += (this.className == null?0:className.hashCode());
hashcode += (this.params == null?0:params.hashCode());
return hashcode;
}
public boolean equals(Object object){
if(object instanceof BeanObjectEntityConfig){
BeanObjectEntityConfig entity = (BeanObjectEntityConfig)object;
boolean isEquals = StringUtil.equals(this.name,entity.name);
isEquals = isEquals && StringUtil.equals(this.className,entity.getClassName());
isEquals = isEquals && (ObjectUtil.equals(this.params,entity.params));
return isEquals;
}
return false;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?