1 Reply Latest reply on Feb 21, 2002 2:47 AM by jwkaltz

    Howto make an "easy to use" bean connector class?

    nikolaj

      Hi there,

      I want to make an easy bean connector class that I can use dynamically, like:

      BeanConn mrbean = new BeanConn("MrBean");
      bc.doTheStuff();

      , instead of:

      InitialContext ctx = new InitialContext();
      MrBeanLocalHome home = (MrBeanLocalHome) ctx.lookup("java:comp/env/ejb/MrBean");
      MrBeanLocal mrbean = home.create();
      mrbean.doTheStuff();

      Howto? Thanks

      /nikolaj

        • 1. Re: Howto make an "easy to use" bean connector class?
          jwkaltz

          If you use a ServiceLocator, than you've already hidden most of the complexity.
          See (for example) java.sun.com for the ServiceLocator pattern.

          You can of course encapsulate as much or as little as you want, but my personal preference is to encapsulate the lookups in a ServiceLocator (thereby allowing to cache the home interfaces, as the lookups are quite expensive), so in the end you have something like
          MrBeanLocalHome home = (MrBeanLocalHome) ServiceLocator.getResource("MrBean");
          MrBeanLocal mrbean = home.create();

          I wouldn't hide the create() part because you're not gaining much but you're losing in code transparency.