Skip to main content

how to work with multiple business interfaces

2 replies [Last post]
dogeared
Offline
Joined: 2006-01-06

The spec indicates that a bean can implement multiple interfaces. The spec also has annotations to support this as in:

public interface IState {
    public String getState();
}

public interface ICountry {
    public String getCountry();
}

@Stateless
@Remote({IState.class,ICountry.class})
public class LocationInformation implements IState,ICountry {
    public String getState() {
        ...
    }

    public String getCountry() {
        ...
    }
}

The specification is vague on how to interact with a bean defined this way.

From a standalone client, how is the lookup done? Deploying this to Glassfish does not automatically put anything into the JNDI namespace the way it does when you are working with a single remote business interface. If you were interacting with it from within the container, say from another bean, how could you inject a reference to this bean?

Logically, it seems like you would have to lookup and work with each interface.

I am curious to know how this should be done in from the perspective of the spec and how (or if) it can be done with Glassfish.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dogeared
Offline
Joined: 2006-01-06

It seems just by observation that JBoss does not yet support the feature from the specification of having multiple business interfaces. At least not in an automated way.

However, it looks like Glassfish does. Using the example from the original post, I was able to see that Glassfish exposes the business interfaces in the usual EJB 3.0 way, BUT prefixed with a pound sign (#). It looks like this:

#examples.interfaces.IState
#examples.interfaces.ICountry

I don't believe that this automatic binding is part of the specification, but it works - at least with Glassfish. In a client, if I do the following lookup:

IState is = (IState)ic.lookup("#"+IState.class.getName());
ICountry ic = (ICountry)ic.lookup("#"+ICountry.class.getName());

I can then call the methods defined in the interfaces and get the response back from the bean deployed in the application server.

vbkraemer
Offline
Joined: 2003-09-03

You may want to consider creating a Java EE 5 application client. GlassFish makes this really easy to deploy and run.. See: http://blogs.sun.com/roller/page/vkraemer?entry=application_client_ejb_3_0

By using an app client (in the ACC) you can take advantage of injection. Then, you can worry about your business code, instead of trying to find out what your server has done with the JNDI name.

I would be worried that the lookup code that you wrote may not be portable, too.

vbk