--- java/org/apache/naming/resources/BaseDirContext.java (revision 1613338) +++ java/org/apache/naming/resources/BaseDirContext.java (working copy) @@ -425,12 +425,12 @@ if (path != null) return path; - + + String resourceName = "/META-INF/resources" + name; // Check the alternate locations for (DirContext altDirContext : altDirContexts) { if (altDirContext instanceof BaseDirContext){ - path = ((BaseDirContext) altDirContext).getRealPath( - "/META-INF/resources" + name); + path = ((BaseDirContext) altDirContext).getRealPath(resourceName); if (path != null) return path; } @@ -470,6 +470,17 @@ @Override public final Object lookup(String name) throws NamingException { // First check for aliases + Object obj = doLookupWithoutNFE(name); + if (obj != null) { + return obj; + } + + // Really not found + throw new NameNotFoundException( + sm.getString("resources.notFound", name)); + } + + protected Object doLookupWithoutNFE(String name) throws NamingException { if (!aliases.isEmpty()) { AliasResult result = findAlias(name); if (result.dirContext != null) { @@ -484,19 +495,25 @@ return obj; // Check the alternate locations + String resourceName = "/META-INF/resources" + name; for (DirContext altDirContext : altDirContexts) { - try { - obj = altDirContext.lookup("/META-INF/resources" + name); - if (obj != null) - return obj; - } catch ( NamingException ex) { - // ignore + if (altDirContext instanceof BaseDirContext) { + obj = ((BaseDirContext)altDirContext).doLookupWithoutNFE(resourceName); + } + else { + try { + obj = altDirContext.lookup(resourceName); + } catch ( NamingException ex) { + // ignore + } + } + if (obj != null) { + return obj; } } - // Really not found - throw new NameNotFoundException( - sm.getString("resources.notFound", name)); + //Return null instead + return null; } /** @@ -689,10 +706,10 @@ // Check the alternate locations List altBindings = null; + String resourceName = "/META-INF/resources" + name; for (DirContext altDirContext : altDirContexts) { if (altDirContext instanceof BaseDirContext) { - altBindings = ((BaseDirContext) altDirContext).doListBindings( - "/META-INF/resources" + name); + altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName); } if (altBindings != null) { if (bindings == null) { @@ -758,10 +775,10 @@ // Check the alternate locations List altBindings = null; + String resourceName = "/META-INF/resources" + name; for (DirContext altDirContext : altDirContexts) { if (altDirContext instanceof BaseDirContext) { - altBindings = ((BaseDirContext) altDirContext).doListBindings( - "/META-INF/resources" + name); + altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName); } if (altBindings != null) { if (bindings == null) { @@ -791,7 +808,7 @@ * This method is idempotent. It succeeds even if the terminal atomic * name is not bound in the target context, but throws * NameNotFoundException if any of the intermediate contexts do not exist. - * + * * In a federated naming system, a context from one naming system may be * bound to a name in another. One can subsequently look up and perform * operations on the foreign context using a composite name. However, an @@ -1138,12 +1155,12 @@ if (attrs != null) return attrs; - + + String resourceName = "/META-INF/resources" + name; // Check the alternate locations for (DirContext altDirContext : altDirContexts) { if (altDirContext instanceof BaseDirContext) - attrs = ((BaseDirContext) altDirContext).doGetAttributes( - "/META-INF/resources" + name, attrIds); + attrs = ((BaseDirContext) altDirContext).doGetAttributes(resourceName, attrIds); else { try { attrs = altDirContext.getAttributes(name, attrIds);