请教:com.jdon.propsutil的getProperty()函数是做什么用的?

oldbird 04-07-09

private static String className = "com.jdon.controller.WebServiceFactory";
protected static ServiceFactory factory = null;

public static ServiceFactory getInstance() {
if (factory == null) {
synchronized (initLock) {
if (factory == null) {
try {
//Load the class and create an instance.
String confClassName = propsUtil.getProperty("serviceFactory.class");
if ((confClassName != null) && !confClassName.equals("")){
Debug.logVerbose( "confClassName is loaded:" + confClassName, module);
className = confClassName;
}

Class c = Class.forName(className);
factory = (ServiceFactory) c.newInstance();

} catch (Exception e) {
Debug.logError(" get factory instance error:" + e, module);
return null;
}
}
}
}
return factory;
}

这段代码调用了propsUtil的getproperty()方法,请问这个方法是什么意思,应该怎么实现呢?谢谢

banq
2004-07-11 20:47

用来获得配置文件中className值.

private static String className = "com.jdon.controller.WebServiceFactory";

已经给className配置了缺省的值:com.jdon.controller.WebServiceFactory,有可能我们需要改变这个值,那么在配置文件中配置一下:

className = MyWebServiceFactory

这样通过propsUtil.getProperty可以获得,propsUtil.getProperty具体语法和用法可参考Jive中的getProperty("JiveHome")用法,是一致的。