Author: echatellier Date: 2010-04-09 12:13:09 +0200 (Fri, 09 Apr 2010) New Revision: 2839 Log: Jndi properties are based on application config options. Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-04-09 08:56:49 UTC (rev 2838) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-04-09 10:13:09 UTC (rev 2839) @@ -30,13 +30,13 @@ import org.apache.openejb.assembler.classic.AppInfo; import org.apache.openejb.assembler.classic.Assembler; import org.apache.openejb.loader.SystemInstance; +import org.chorem.lima.LimaMain; import org.chorem.lima.business.AccountService; import org.chorem.lima.business.EntryBookService; import org.chorem.lima.business.FinancialPeriodService; import org.chorem.lima.business.FiscalPeriodService; import org.chorem.lima.business.RecordService; import org.chorem.lima.business.TransactionService; -import org.chorem.lima.business.ejb.EntryBookServiceImpl; /** * Is class is a service factory based on embedded openejb container. @@ -53,6 +53,24 @@ * Mais il vaudrait mieux essayer en distant pour verifier si * la factorisation est similaire. * + * Attention, en mode distant, les jar "javaee-api" et "openejbclient" + * doivent etre les mêmes (avec une snapshot ca fesait une NPE) + * + * + * <h3>Lookup EJB methods</h3> + * + * <ul> + * <li>first way is : + * <pre>FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo");</pre></li> + * <li>second way is (spec compliant) + * <pre>Object obj = ctx.lookup("my/bean/Foo"); + * FooHome ejbHome = (FooHome) + * PortableRemoteObject.narrow(obj, FooHome.class);</pre><li> + * + * <h3>TODO</h3> + * + * <p>All services are hardcoded in local mode for now</p> + * * @author chatellier * @version $Revision$ * @@ -64,27 +82,35 @@ /** Log. */ private static Log log = LogFactory.getLog(LimaServiceFactory.class); + /** Single instance. */ protected static LimaServiceFactory instance; + /** JNDI context used to look for EJB. */ protected InitialContext ctx; /** * Init openejb jndi context. */ protected LimaServiceFactory() { - - // embedded server - // TODO put this in configuration - Properties properties = new Properties(); - properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory"); + // TODO EC-20100407 maybe put all options in LimaConfig and allow user to configure it (remove getFlatOptions use) + Properties props = LimaMain.config.getFlatOptions(); + + // Context.INITIAL_CONTEXT_FACTORY is a mandatory option + // containsKey() does'nt work :( + if (!props.containsKey(Context.INITIAL_CONTEXT_FACTORY)) { + throw new RuntimeException("Application configuration is missing mandatory property " + + Context.INITIAL_CONTEXT_FACTORY); + } + try { - ctx = new InitialContext(properties); + ctx = new InitialContext(props); } catch (NamingException eee) { if (log.isErrorEnabled()) { log.error("Can't initialize initial context", eee); } } + } /** @@ -108,15 +134,8 @@ */ public AccountService getAccountService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "AccountServiceImplLocal"; AccountService ejbHome = null; try { @@ -130,49 +149,14 @@ } /** - * Get Journal service. - * - * @return account service proxy - */ - public EntryBookServiceImpl getJournalService() { - - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration - String lookupName = "JournalServiceImplLocal"; - EntryBookServiceImpl ejbHome = null; - try { - ejbHome = (EntryBookServiceImpl)ctx.lookup(lookupName); - } catch (NamingException eee) { - if (log.isErrorEnabled()) { - log.error("Can't lookup for service : " + lookupName, eee); - } - } - return ejbHome; - } - - /** * Get FiscalPeriod service. * * @return fiscalPeriod service proxy */ public FiscalPeriodService getFiscalPeriodService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "FiscalPeriodServiceImplLocal"; FiscalPeriodService ejbHome = null; try { @@ -188,19 +172,12 @@ /** * Get FinancialPeriod service. * - * @return fiscalPeriod service proxy + * @return Financial Period service proxy */ public FinancialPeriodService getFinancialPeriodService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "FinancialPeriodServiceImplLocal"; FinancialPeriodService ejbHome = null; try { @@ -220,15 +197,8 @@ */ public TransactionService getTransactionService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "TransactionServiceImplLocal"; TransactionService ejbHome = null; try { @@ -248,15 +218,8 @@ */ public EntryBookService getEntryBookService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "EntryBookServiceImplLocal"; EntryBookService ejbHome = null; try { @@ -276,15 +239,8 @@ */ public RecordService getRecordService() { - // first way is - // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); - - // second way is (spec compliant) - // Object obj = ctx.lookup("my/bean/Foo"); - // FooHome ejbHome = (FooHome) - // PortableRemoteObject.narrow(obj, FooHome.class); - - // TODO put lookup name in configuration + // TODO EC-20100410 put lookup name in configuration + // name should be fully configurable due to custom implementation used String lookupName = "RecordServiceImplLocal"; RecordService ejbHome = null; try { @@ -306,6 +262,8 @@ * @throws Exception when trying to destroy a non existent application */ public void destroy() throws Exception { + + // destroy code (only in embedded mode) Assembler assembler = SystemInstance.get().getComponent(Assembler.class); for (AppInfo appInfo : assembler.getDeployedApplications()) { assembler.destroyApplication(appInfo.jarPath);
participants (1)
-
echatellier@users.chorem.org