Author: echatellier Date: 2010-04-02 19:02:21 +0200 (Fri, 02 Apr 2010) New Revision: 2827 Log: La factory des services supporte maintenant tous les services 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-02 17:01:48 UTC (rev 2826) +++ trunk/lima-swing/src/main/java/org/chorem/lima/service/LimaServiceFactory.java 2010-04-02 17:02:21 UTC (rev 2827) @@ -1,5 +1,5 @@ -/* *##% - * Copyright (C) 2010 Code Lutin, Chatellier Eric +/* *##% Lima Swing + * Copyright (C) 2008 - 2010 CodeLutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ + * ##%*/ package org.chorem.lima.service; @@ -31,8 +31,12 @@ import org.apache.openejb.assembler.classic.Assembler; import org.apache.openejb.loader.SystemInstance; import org.chorem.lima.business.AccountService; -import org.chorem.lima.business.ejb.JournalServiceImpl; -import org.chorem.lima.business.ejb.PeriodServiceImpl; +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. @@ -42,6 +46,13 @@ * <li>http://openejb.apache.org/embedding-openejb.html</li> * </ul> * + * Elle est pour l'instant statique en attendant mieux. + * + * Toutes les méthodes utilisent, <ServiceName>ImplLocal comme nom local + * (convention openejb) c'est donc plus factorisable que le code actuel. + * Mais il vaudrait mieux essayer en distant pour verifier si + * la factorisation est similaire. + * * @author chatellier * @version $Revision$ * @@ -60,10 +71,11 @@ /** * Init openejb jndi context. */ - public LimaServiceFactory() { - Properties properties = new Properties(); + protected LimaServiceFactory() { // embedded server + // TODO put this in configuration + Properties properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.openejb.client.LocalInitialContextFactory"); try { @@ -105,10 +117,10 @@ // PortableRemoteObject.narrow(obj, FooHome.class); // TODO put lookup name in configuration - String lookupName = AccountService.class.getName().replace('.', '/'); + String lookupName = "AccountServiceImplLocal"; AccountService ejbHome = null; try { - ejbHome = (AccountService)ctx.lookup("AccountServiceImplLocal"); + ejbHome = (AccountService)ctx.lookup(lookupName); } catch (NamingException eee) { if (log.isErrorEnabled()) { log.error("Can't lookup for service : " + lookupName, eee); @@ -122,7 +134,7 @@ * * @return account service proxy */ - public JournalServiceImpl getJournalService() { + public EntryBookServiceImpl getJournalService() { // first way is // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); @@ -133,10 +145,10 @@ // PortableRemoteObject.narrow(obj, FooHome.class); // TODO put lookup name in configuration - String lookupName = JournalServiceImpl.class.getName().replace('.', '/'); - JournalServiceImpl ejbHome = null; + String lookupName = "JournalServiceImplLocal"; + EntryBookServiceImpl ejbHome = null; try { - ejbHome = (JournalServiceImpl)ctx.lookup("JournalServiceImplLocal"); + ejbHome = (EntryBookServiceImpl)ctx.lookup(lookupName); } catch (NamingException eee) { if (log.isErrorEnabled()) { log.error("Can't lookup for service : " + lookupName, eee); @@ -146,11 +158,11 @@ } /** - * Get Journal service. + * Get FiscalPeriod service. * - * @return account service proxy + * @return fiscalPeriod service proxy */ - public PeriodServiceImpl getPeriodService() { + public FiscalPeriodService getFiscalPeriodService() { // first way is // FooHome ejbHome = (FooHome)new InitialContext().lookup("java:openejb/ejb/my/bean/Foo"); @@ -161,10 +173,10 @@ // PortableRemoteObject.narrow(obj, FooHome.class); // TODO put lookup name in configuration - String lookupName = PeriodServiceImpl.class.getName().replace('.', '/'); - PeriodServiceImpl ejbHome = null; + String lookupName = "FiscalPeriodServiceImplLocal"; + FiscalPeriodService ejbHome = null; try { - ejbHome = (PeriodServiceImpl)ctx.lookup("PeriodServiceImplLocal"); + ejbHome = (FiscalPeriodService)ctx.lookup(lookupName); } catch (NamingException eee) { if (log.isErrorEnabled()) { log.error("Can't lookup for service : " + lookupName, eee); @@ -174,6 +186,118 @@ } /** + * Get FinancialPeriod service. + * + * @return fiscalPeriod 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 + String lookupName = "FinancialPeriodServiceImplLocal"; + FinancialPeriodService ejbHome = null; + try { + ejbHome = (FinancialPeriodService)ctx.lookup(lookupName); + } catch (NamingException eee) { + if (log.isErrorEnabled()) { + log.error("Can't lookup for service : " + lookupName, eee); + } + } + return ejbHome; + } + + /** + * Get transaction service. + * + * @return transaction service proxy + */ + 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 + String lookupName = "TransactionServiceImplLocal"; + TransactionService ejbHome = null; + try { + ejbHome = (TransactionService)ctx.lookup(lookupName); + } catch (NamingException eee) { + if (log.isErrorEnabled()) { + log.error("Can't lookup for service : " + lookupName, eee); + } + } + return ejbHome; + } + + /** + * Get transaction service. + * + * @return transaction service proxy + */ + 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 + String lookupName = "EntryBookServiceImplLocal"; + EntryBookService ejbHome = null; + try { + ejbHome = (EntryBookService)ctx.lookup(lookupName); + } catch (NamingException eee) { + if (log.isErrorEnabled()) { + log.error("Can't lookup for service : " + lookupName, eee); + } + } + return ejbHome; + } + + /** + * Get record service. + * + * @return record service proxy + */ + 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 + String lookupName = "RecordServiceImplLocal"; + RecordService ejbHome = null; + try { + ejbHome = (RecordService)ctx.lookup(lookupName); + } catch (NamingException eee) { + if (log.isErrorEnabled()) { + log.error("Can't lookup for service : " + lookupName, eee); + } + } + return ejbHome; + } + + /** * Destroy openejb jndi context. * * Code taken from openEJB faq :
participants (1)
-
echatellier@users.chorem.org