1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
public class GlobalMgr {
private ApplicationContext ac;
public final ApplicationContext getAc() {
return ac;
}
public final ServiceDAO getServiceDAO () {
return (ServiceDAO) GlobalMgr.getInstance().getAc().getBean("serviceDAO");
}
...
/**
* Récupére l'instance unique de la class Singleton. Remarque : le
* constructeur est rendu inaccessible
*/
public static synchronized GlobalMgr getInstance() {
if (null == instance) {
instance = new GlobalMgr();
}
return instance;
}
/**
* Constructeur redéfini comme �tant privé pour interdire son appel et
* forcer � passer par la méthode getInstance()
*/
private GlobalMgr() {
String [] acFiles = {
"arc/db/config/application-context-arcdb.xml",
"org/j2ee/migrate/config/constant-config.xml",
"omnis/db/config/application-context-omnisdb.xml",
"org/j2ee/migrate/config/application-context-omnistoarc-config.xml" };
ac = new ClassPathXmlApplicationContext(acFiles);
}
/** L'instance statique */
private static GlobalMgr instance;
} |
Partager