package services;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class BusinessService {
private final static String DEFUL_IMP = "HibernateFactory ";
private static Log log = LogFactory.getLog(BusinessService.class);
private static JliveBBS service = null;
public static JliveBBS instance() {
if (service == null) {
// load service implement class from config file
String classStr = null;
if (classStr == null || classStr.length() < 1) {
if (log.isDebugEnabled())
log.debug( "load implement Factory for defullclass: "
+ DEFUL_IMP);
classStr = DEFUL_IMP;
}
try {
Class serviceImp = Class.forName(classStr);
service = (JliveBBS) serviceImp.newInstance();
} catch (ClassNotFoundException e) {
log.info( "don 't instantiate Factory class: " + classStr);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return service;
}
}
********************************************************
这个是测试的类:
package HibernateTestGroup;
import java.util.*;
import forms.Boards;
import forms.Groups;
import forms.Users;
import DAO.*;
import services.BusinessService;
public class TestGroup {
public static GroupManager mng = BusinessService.instance()
.getGroupManager();
public void addgroup(){
Groups group=new Groups();
group.setGroupname( " 华灯初上 ");
group.setDesc( "物尽繁华尽先孤独 ");
group.setCreatedate(new Date());
try{
mng.addGroup(group);
}catch(Exception e){
e.printStackTrace();
}
}
public void loadallgroup() {
List list = mng.loadAllGroups(new Users());
System.out.println( "- ");
for (Iterator iter = list.iterator(); iter.hasNext();) {
Groups group = (Groups) iter.next();
System.out.print(group.getGroupname());
List boards = (List) group.getBoards();
for (Iterator iterator = boards.iterator(); iterator.hasNext();) {
Boards board = (Boards) iterator.next();
System.out.println( " + " + board.getBoardname());
}
System.out.println( "- ");
}
}
public static void main(String args[]){
TestGroup test=new TestGroup();
test.addgroup();