3 Replies Latest reply on Sep 12, 2002 6:16 AM by Tung Dang

    How to extend EJBLocalHome interface?

    Dries De Moor Newbie

      I wonder if it is possible to extend the EJBLocalHome interface?

      Mayby I should explain why I want to do this?
      I have several LocalEntity beans which are accessed by a SessionFacade Bean.
      The current state I'm in is that I have a create method in the session facade for each Entitybean. The create methods in the SessionFacade look more or less the same. It is actually just a copy past operation and change the LocalHome and LocalObject interfaces.
      The data representing an entity bean is assembled in ValueObjects. Each value object extends a DefaultValueObject.

      What I want to do is create an interface BasicEJBLocalHome which extends EJBLocalHome. In the BasicEJBLocalHome, I define a create method which takes a valueobject and returns BasicLocalObject interface (this interface extends the EJBLocalObject interface. this was the question in my previous post.)
      All the LocalHome interfaces of the EJB's extend the BasicEJBLocalHome interface.

      If this is possible, I only have to create one create method in the SessionFacade taking a DefaultValueObject and a jndiName of the bean.
      Lookup the bean and cast it to BasicEJBLocalHome and call the create method on it. This should then call the create method of the corresponding beanclass. So my Session facade will look much smaller and it will be much easier to maintain the code.

      I tried this. I used sun's reference implementation to test this but the verifier in the deploytool fails. It claims the Beanclasses doesn't contain and ejbCreate method. Although there is one with the same signature as defined in the BasicEJBLocalHome.

      Can somebody tell me if what I wrote is possible? If it is possible, am I doing something wrong. And if it is not possible, is there an onther solution to the problem I described?

      I hope the describtion is clear enough.


      Thanks a lot for your time.

        • 1. Re: How to extend EJBLocalHome interface?
          Tung Dang Novice

          My project has a similar situation to yours, and of course you can extend the EJBLocalHome interface, and it is very easy.

          public interface MyBasicEJBLocalHome extends the EJBLocalHome {
          public MyBasicEJBLocalObject create(...) throws ...;
          // some methods more.
          }

          public interface MyFirstEJBLocalHome extends MyBasicEJBLocalHome {
          }

          public interface MySecondEJBLocalHome extends MyBasicEJBLocalHome {
          }

          ... and so on.

          I could successfully deploy my project with JBoss 3.0.1 and it works fine.

          Hope it helps.

          • 2. Re: How to extend EJBLocalHome interface?
            Dries De Moor Newbie

            Hello,

            I know this is possible. What I actually wanted to know is the following. You define a create method in the most generic LocalHome interface. Then you define several EntityBeans which have their own Home interface which extends the generic LocalHome interface.
            You lookup an entitybeans homeinterface you cast it to the generic home interface and you call the create method.
            e.g.
            EntityBean is BeanA

            BasicLocalHome basicLocalHome = (BasicLocalHome)context.lookUp();
            basicLocalHome.create();


            Will the EJB container call the create method of the bean you've looked up? If not, how can I solve the problem I descirbed in the first post?


            Thanks,

            Dries


            • 3. Re: How to extend EJBLocalHome interface?
              Tung Dang Novice

              Of course, it will because in this case you have a BasicLocalHome and its create method will be invoked.

              Regards.