HandleDelegate handleDelegate;
try {
InitialContext ctx = new InitialContext();
handleDelegate = (HandleDelegate)
ctx.lookup("java:comp/HandleDelegate");
} catch(NamingException ne) {
// If the lookup fails, it's probably because the default
// InitialContext settings needed to access the correct
// java:comp/HandleDelegate have been overridden in this VM.
// In that case, check if the system value class override
// property file is available and if so use it.
Properties props = null;
try {
props = getJndiProperties();
} catch(Exception e) {
// Exception while attempting to access jndi property override.
// Create new NamingException that describes the error.
NamingException ne2 = new NamingException
("Error while accessing " + JNDI_PROPERTY_FILE_NAME +
" : " + e.getMessage());
ne2.initCause(e);
throw ne2;
}
if( props == null ) {
// There was no property override set.
NamingException ne3 = new NamingException
("java:comp/HandleDelegate not found. Unable to " +
" use jndi property file override since " +
JNDI_PROPERTY_FILE_NAME + " has NOT been set");
ne3.initCause(ne);
throw ne3;
}
try {
InitialContext ctx = new InitialContext(props);
handleDelegate = (HandleDelegate)
ctx.lookup("java:comp/HandleDelegate");
} catch(NamingException ne4) {
NamingException overrideEx =
new NamingException("Unable to lookup HandleDelegate " +
"with override properties = " +
props.toString());
overrideEx.initCause(ne4);
throw overrideEx;
}
}
return handleDelegate;