> Let me explain, what I'm trying to achieve:
>
> I want some of my stateless session (computation) beans
> implement a predefined interface, for instance
>
> public interface ComputationBean
> {
>    public String compute(String xml)
> throws ComputationException;
> }
>
> I need that, because these beans could be deployed
> at run time, and the client (web-application) needs to
> perform the same common task on all of them. I don't
> own those beans, they are supposed to be written by
> user/customers.
>
> It's not a problem, right? Remote interfaces just need
> to be extended from ComputationBean and been classes should
> implement ComputationBean as well.

The above only works if ComputationException extends RemoteException (or
else compute is not a valid remote method). Also, bean classes *may*
implement ComputationBean, but it's not a requirement.

> Ok, but how the client can call the bean compute method,
> or actually, how can I obtain its Home Interface and
> create the bean?
>
> Suppose I know a JNDI name for any bean, and I can look
> up the bean up by name:
>
> Object homeRef = jndiContext.lookup(beanNameString);
>
> but, how can I cast (narrow) homeRef to the specific
> bean home interface? I don't know the name and it's
> not in the client CLASSPATH as well. Can I define some
> generic Home and Remote Interfaces and force users
> inherit their home/remote interfaces from them?
> I think it won't work, though.

It's a tricky one. Use reflection would be my recommendation (I know I
know..sucks, but that's life).

> public interface ComputationBeanHome extends EJBHome
> {
>    public ComputationBean create();
> }
>
> public UserBeanHome extends ComputationBeanHome
> {
> }

Nah, doesn't work. Create needs to return the exact type of the component,
i.e. UserBeanHome.

> Is this possible somehow? I'm thinking about some other
> possible solutions, but really don't know which is
> right or even will work.
>
> Perhaps, I should process userbeen.jar at the deployment
> time and by parsing ejb-jar.xml get real Remote and Home
> interfaces, then load them dynamically on the client, use
> reflection to find a "create()" method and so on.

All you have to do is do reflection on the home found in JNDI for the
"create" method. You don't need to actually know what interface it uses.

/Rickard




--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to