3 Replies Latest reply on Jun 22, 2004 5:07 AM by sqirl

    Generate a Business Delegate and ServiceLocator

    sqirl Newbie

      Hi all,

      I´m new to XDoclet and would like to know whether there is a way to generate the Business Delegates or/and the ServiceLocator. When there´s no way, can someone please post some simple examples for these patterns?!

      greets
      sqirl

        • 1. Re: Generate a Business Delegate and ServiceLocator
          Carlos Cajina Newbie

          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
            Nicholas Whitehead Novice

            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 Newbie

              Many thanks for your help!!! The example is very usefull...

              ...sqirl.