Interface/Bean inheritance

Discussions

EJB design: Interface/Bean inheritance

  1. Interface/Bean inheritance (1 messages)

    Hi this is a brief description of our development team current problem any advise would be greatly appreciated.

    The problem is that we want the same bean to show two different RemoteInterface depending on who is calling it. One of the interface should be common among all our Session beans in the system while the other should be specific for each bean.

    There should exist the possiblity to lookup the beans implementing the Common interface like this.

    Common lookupCommon(String jndiName){
    CommonHome home =context.lookup(jndiName);
    return home.create();
    }


    In other words we would like something like this

    interface Common extends EJBObject{
    void common() throws RemoteException;
    }

    interface Specific extends Common{
    void specific();
    }


    class SpecificEJB{
    Specific ejbCreate(){}
    void common(){}
    void specific(){}
    }


    interface CommonHome() extends EJBHome{
    Common create();
    }

    interface SpecificHome() extends CommonHome{
    Specific create();
    }

    Deploy with
    Home SpecificHome
    Remote Specific
    EJBClass SpecificEJB

    The problem with this is the home interfaces. If we specify the home's like above we get a java compiler error as a method in the subinterface is not allowed to return a more narrow class than the super interface....


    If we try to deploy the bean using the classes

    Home CommonHome
    Remote Specific
    EJBClass SpecificEJB
     
    we get an error from the bean verifier as the create method in the home interface must return the Remote interface.


    We can deploy using
    Home CommonHome
    Remote Common
    EJBClass SpecificEJB

    But then it lose the point as we will never be able to call the specific methods of the Bean as they are not defined in the RemoteInterface....



    Is there anyway around this? Can a bean really only implement one interface?

    Regards
    /David


  2. Interface/Bean inheritance[ Go to top ]

    To answer your question, yes.. Bean can implement many interface.... But, the home interface has to return either Remote Interface or the Collection, Enumeration depending on what it returns.. The create methods always return remote interface.. Is there way around it? Yes. You should have a "Common" interface which other interface extends.

    public interface Common extends EJBObject {}

    public interface Specific extends Common {}

    public interface SpecificHome extends EJBHome {
      public SpecificHome create() throws CreateException, RemoteException;
    }

    (Common) lookup("Specific");

    both of them are specific to their Bean, but what it returned can be cast to Common.

    Se Hee