1 Reply Latest reply on Feb 21, 2002 2:47 AM by J. Wolfgang Kaltz

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

    Nikolaj G. Newbie

      Hi there,

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

      BeanConn mrbean = new BeanConn("MrBean");

      , instead of:

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

      Howto? Thanks


        • 1. Re: Howto make an "easy to use" bean connector class?
          J. Wolfgang Kaltz Novice

          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.