This content has been marked as final.
Show 3 replies
-
1. Re: Generate a Business Delegate and ServiceLocator
ccajina Jun 16, 2004 5:10 PM (in response to sqirl)Try the EJB Design Patterns book (free download @ TheServerSide) and/or Professional Struts Applications source code (also avaliable online from Wiley or Apress, don't remember) You'll have to code most of it, but it will give more control and understanding of how things work.
Good Luck! -
2. Re: Generate a Business Delegate and ServiceLocator
nickman Jun 16, 2004 5:20 PM (in response to sqirl)We have a ServiceDelegate which returns a proxy as follows:
public static Object getServiceDelegate(String jndiName) throws NamingException { ServiceDelegate sd = new ServiceDelegate(jndiName); return Proxy.newProxyInstance(sd.getLocal().getClass().getClassLoader(), sd.getLocal().getClass().getInterfaces(), sd); }
The private constructor looks like this:private ServiceDelegate(String jndiName) throws NamingException { local = EJBLocalFactory.getInstance().getLocal(jndiName); }
Then the EJBLocalFactory does this:private ThreadLocal locals = null; . . public EJBLocalObject getLocal(String jndiName) throws NamingException { Map localsMap = (Map) locals.get(); if(localsMap==null) { localsMap = new HashMap(); locals.set(localsMap); } EJBLocalObject local = (EJBLocalObject) localsMap.get(jndiName); if (local == null) { EJBLocalHome home = (EJBLocalHome) homes.get(jndiName); if (home == null) { home = (EJBLocalHome) ctx.lookup(jndiName); homes.put(jndiName, home); } try { Method method = home.getClass().getMethod("create", noArgs); local = (EJBLocalObject) method.invoke(home, noObjs); localsMap.put(jndiName, local); locals.set(localsMap); } catch (Exception ex) { throw new NamingException( "Exception Reflecting create() Method On Home Object From " + jndiName + ":" + ex); } } return local; }
Fairly generic from every perspective, and it seems to work ok too.
//Nicholas -
3. Re: Generate a Business Delegate and ServiceLocator
sqirl Jun 22, 2004 5:07 AM (in response to sqirl)Many thanks for your help!!! The example is very usefull...
...sqirl.