as a design consideration we are planning to cache all the EJB Homes as soon as the Application server starts .
Also we want to make the code as generic as possible and not dependent on the specific classes .
So while narrowing the Object references can we do a generic narrow as shown below ?
ejbHome = (EJBHome)
Note that the object is being narrowed to EJBHome .
Later in the application when ever a jndi lookup is done the object is taken from the cache and narrowed to the specific class ...
is this ok ? does this cause any problems ? if so what ?
Thanks in advance for the help ...
You have to call PortableRemoteObject.narrow for the actual interface you intend to cast the EJBHome to later. Is you only narrow to EJBHome.class, you can't be sure that the result be be cast to your specific home interface.
You can do:
ejbHome = (EJBHome)PortableRemoteObject.narrow(objref, EJBHome.class);
Class ejbHomeInterface = ejbHome.getEJBMetaData().getHomeInterfaceClass();
EJBHome narrowEJBHome = (EJBHome)PortableRemoteObject.narrow(objref, ejbHomeInterface);
what about the different create and finder methods..they will be different for different beans...right...????
Could we use reflection?
Class c = narrowEJBHome.getClass();
Method create = c.getMethod("create");
In my case, I need some method that returns a created bean instance based only on the jndi name of the bean (or perhaps the class name of the home interface and bean class).