Mike Argyriou
Mike Argyriou

Reputation: 1310

locate ejb implementation class (not interface)

I want to browse my server's jndi registry (e.g. jboss) and locate for each ejb its implementation class. Assume for example that I have the local bean

@Stateless(name="fooService")
public class FooServiceBean implements FooService () { ... }

and the interface

@Local
public interface FooService { ... }

and I retrieve it from jndi with:

Context ctx = new InitialContext();
Object obj = ctx.lookup("fooService");

The question now..how can I know that obj is instance of FooServiceBean?

Update 25 Sep 2013: So far I haven't found that this is possible and actually it makes sense. JNDI hosts only interfaces.

Upvotes: 0

Views: 888

Answers (2)

Lefteris Laskaridis
Lefteris Laskaridis

Reputation: 2322

This doesn't answer your question but:

Your client shouldn't really know by which mechanism is the interface implemented. This would be a bad design as it would couple you client to the implementation instead of an interface. Your bean implementation class is managed by the application server run-time. Clients shouldn't be aware of its existence.

Upvotes: 1

Brett Kail
Brett Kail

Reputation: 33936

That sounds like the wrong approach. Why does your client need/want to know? The point of separate interface from implementation is to insulate clients from implementation changes. If you really need to know, you could add an isFooServiceBean() method that returns true from FooServiceBean but returns false from all other implementations, but it sounds like something is mis-designed.

Upvotes: 0

Related Questions