Having worked with JNDI and CORBA's naming service (or IOR string object narrowing) in the past, and having experienced the cumbersome nature of simply resolving an object:
- In CORBA's naming service you either have to register your component at startup (preferably using an LDAP based service) and know the compound name for later retrieval. Or use the IOR string by narrowing it into an object. At a previous installation we hade a servlet that served the IOR string based on the name from a request parameter. This is not at all clean; it introduced a troublesome dependency with an unreliable web-based service.
- JNDI I hate also because you still need to encode (albeit you can configure it on your component's descriptor file) it inside your code and perform the lookup with that string name. This code is pretty substantial and cumbersome if you have to use a fair amount of resource objects.
What I would like to have as part of the J2EE specification is the ability to have bean style properties of a resource/component/etc I am writing and configuring this on my descriptor file as simple properties. The JNDI name of the said resource/component/etc will be used on the property value. The Object type translation should performed automatically by the configuration framework.
Consider:
public class MySessionBean implement SessionBean {
private UserTableEntity mUserTableEntity;
// The rest of the code goes below
//...
public void setUserTableEntity
(UserTableEntity pUserTableEntity) {
mUserTableEntity = pUserTableEntity;
}
public UserTableEntity getUserTableEntity() {
return mUserTableEntity;
}
}
On the descriptor you then link the entity onto this session bean using the entity's JNDI name as the value. Instead of finding this value from the context (which you currently do and proceed to resolve it and cast it to its class type, hmmm...), all this work will be done for you whenever the object is started/activated or loaded.
This can be easily done on all type of components (servlet, ejb, message beans, etc) that are configurable in a J2EE environment.