Wednesday, December 17, 2008

a good lookup snippet

    @SuppressWarnings("unchecked")
public T lookup(Class clazz, final String pJndiName) {
T cs = null;
String jndiName = (pJndiName == null)
? jndiPrefix + clazz.getSimpleName() + "Bean/remote"
: pJndiName;

LOG.debug("Looking for "+jndiName);
try {
Object o = context.lookup(jndiName);
if (o == null) {
System.err.println("unable to find " + jndiName);
} else {
System.out.println("retrieved instance of "
+ o.getClass().getName());
}
cs = (T) PortableRemoteObject.narrow(o, clazz);

} catch (NamingException e) {
e.printStackTrace();
}
return cs;
}

No comments: