Index: NamingContext.java =================================================================== RCS file: /cvsroot/jboss/jnp/src/main/org/jnp/interfaces/NamingContext.java,v retrieving revision 1.36 diff -u -r1.36 NamingContext.java --- NamingContext.java 20 Nov 2004 03:31:58 -0000 1.36 +++ NamingContext.java 17 Dec 2004 04:32:32 -0000 @@ -92,6 +92,8 @@ public static final String JNP_DISCOVERY_TIMEOUT = "jnp.discoveryTimeout"; /** */ public static final String JNP_PARSED_NAME = "jnp.parsedName"; + /** A flag to enable passing of relative names to NamingManager */ + public static final String JNP_USE_RELATIVE_NAME = "jnp.useRelativeName"; /** The default discovery multicast information */ public final static String DEFAULT_DISCOVERY_GROUP_ADDRESS = "230.0.0.4"; @@ -428,6 +430,9 @@ Name parsedName = (Name) refEnv.get(JNP_PARSED_NAME); if( parsedName != null ) name = parsedName; + + obj = getStateToBind ( obj, name, refEnv ); + try { String className; @@ -478,6 +483,8 @@ if( parsedName != null ) name = parsedName; + obj = getStateToBind ( obj, name, refEnv ); + try { String className; @@ -563,7 +570,8 @@ if (res instanceof MarshalledValuePair) { MarshalledValuePair mvp = (MarshalledValuePair) res; - return mvp.get(); + + return getObjectInstanceWrapFailure (mvp.get(), name, refEnv); } else if(res instanceof MarshalledObject) { @@ -584,44 +592,25 @@ else if (res instanceof ResolveResult) { // Dereference partial result - try + Object resolveRes = ((ResolveResult)res).getResolvedObj (); + Object context, instanceId; + + if (resolveRes instanceof LinkRef) { - Object resolveRes = ((ResolveResult)res).getResolvedObj (); - if (resolveRes instanceof LinkRef) - { - String ref = ((LinkRef)resolveRes).getLinkName (); - Context ctx; - try - { - ctx = (Context) resolveLink(resolveRes, null); - return ctx.lookup (((ResolveResult)res).getRemainingName ()); - } catch (ClassCastException e) - { - throw new NotContextException (ref + " is not a context"); - } - } else - { - try - { - Context ctx = (Context)NamingManager.getObjectInstance (resolveRes, - getAbsoluteName (name), - this, - refEnv); - return ctx.lookup (((ResolveResult)res).getRemainingName ()); - } catch (ClassCastException e) - { - throw new NotContextException (); - } - } - } catch (NamingException e) + context = resolveLink(resolveRes, null); + instanceId = ((LinkRef)resolveRes).getLinkName (); + } else { - throw e; - } catch (Exception e) + context = getObjectInstanceWrapFailure (resolveRes, name, refEnv); + instanceId = context; + } + + if ((context instanceof Context) == false) { - NamingException ex = new NamingException ("Could not dereference object"); - ex.setRootCause (e); - throw ex; + throw new NotContextException (instanceId + " is not a context"); } + + return ((Context) context).lookup (((ResolveResult)res).getRemainingName ()); } else if (res instanceof LinkRef) { @@ -631,23 +620,10 @@ else if (res instanceof Reference) { // Dereference object - try - { - res = NamingManager.getObjectInstance (res, - getAbsoluteName (name), - this, - refEnv); - if( res instanceof LinkRef ) - res = resolveLink(res, refEnv); - } catch (NamingException e) - { - throw e; - } catch (Exception e) - { - NamingException ex = new NamingException ("Could not dereference object"); - ex.setRootCause (e); - throw ex; - } + res = getObjectInstanceWrapFailure (res, name, refEnv); + + if( res instanceof LinkRef ) + res = resolveLink(res, refEnv); } return res; @@ -959,7 +935,7 @@ Name n = getAbsoluteName (name); link = naming.lookup (n); if (!(link instanceof LinkRef) && link instanceof Reference) - link = NamingManager.getObjectInstance (link, n, this, null); + link = getObjectInstance (link, name, null); } catch(IOException e) { @@ -978,7 +954,7 @@ } return link; } - + protected Object resolveLink(Object res, Hashtable refEnv) throws NamingException { @@ -1005,6 +981,47 @@ // Private ------------------------------------------------------- + private boolean useAbsoluteName (Hashtable env) + { + if( env == null ) + return true; + String useRelativeName = (String) env.get( JNP_USE_RELATIVE_NAME ); + return Boolean.valueOf( useRelativeName ) == Boolean.FALSE; + } + + private Object getStateToBind (Object obj, Name name, Hashtable env) + throws NamingException + { + if( useAbsoluteName( env ) ) + name = getAbsoluteName (name); + return NamingManager.getStateToBind (obj, name, this, env); + } + + private Object getObjectInstance (Object obj, Name name, Hashtable env) + throws Exception + { + if( useAbsoluteName (env) ) + name = getAbsoluteName (name); + return NamingManager.getObjectInstance (obj, name, this, env); + } + + private Object getObjectInstanceWrapFailure (Object obj, Name name, Hashtable env) + throws NamingException + { + try + { + return getObjectInstance (obj, name, env); + } catch (NamingException e) + { + throw e; + } catch (Exception e) + { + NamingException ex = new NamingException ("Could not dereference object"); + ex.setRootCause (e); + throw ex; + } + } + /** This methods sends a broadcast message on the network and asks and * HA-JNDI server to sent it the HA-JNDI stub */