首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

BoneCP源码——从Manual configuration谈起

2013-03-16 
BoneCP源码——从Manual configuration说起BoneCP官网上有其配置的使用文档,看最基本的Manual configuration

BoneCP源码——从Manual configuration说起

BoneCP官网上有其配置的使用文档,看最基本的Manual configuration:

?

if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(int.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {try{method.invoke(this, Integer.parseInt(val));} catch (NumberFormatException e){// do nothing, use the default value}}} else if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(long.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {try{method.invoke(this, Long.parseLong(val));} catch (NumberFormatException e){// do nothing, use the default value}}} else if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(String.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {method.invoke(this, val);}} if (method.getParameterTypes().length == 1 && method.getParameterTypes()[0].equals(boolean.class)){String val = props.getProperty(tmp);if (val == null){val = props.getProperty("bonecp."+tmp); // hibernate provider style}if (val != null) {method.invoke(this, Boolean.parseBoolean(val));}}

个人认为这段代码写得不够优雅,至少相同部分可以提取出来,从设计的角度说这里也最好采用工厂方式便于多种实现。

?

热点排行