Search in sources :

Example 1 with NamingContextBindingsEnumeration

use of org.apache.naming.NamingContextBindingsEnumeration in project Payara by payara.

the class WebDirContext method listBindings.

/**
 * Enumerates the names bound in the named context, along with the
 * objects bound to them. The contents of any subcontexts are not
 * included.
 * <p>
 * If a binding is added to or removed from this context, its effect on
 * an enumeration previously returned is undefined.
 *
 * @param name the name of the context to list
 * @return an enumeration of the bindings in this context.
 * Each element of the enumeration is of type Binding.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
    List<NamingEntry> namingEntries = null;
    File file = file(name, true);
    if (file != null) {
        namingEntries = list(file);
    }
    List<JarFileEntry> jfeEntries = lookupAllFromJars(name);
    for (JarFileEntry jfeEntry : jfeEntries) {
        List<NamingEntry> jfeList = list(jfeEntry);
        if (namingEntries != null) {
            namingEntries.addAll(jfeList);
        } else {
            namingEntries = jfeList;
        }
    }
    if (file == null && jfeEntries.size() == 0) {
        throw new NamingException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
    }
    return new NamingContextBindingsEnumeration(namingEntries.iterator(), this);
}
Also used : NamingContextBindingsEnumeration(org.apache.naming.NamingContextBindingsEnumeration) NamingException(javax.naming.NamingException) NamingEntry(org.apache.naming.NamingEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 2 with NamingContextBindingsEnumeration

use of org.apache.naming.NamingContextBindingsEnumeration in project tomcat70 by apache.

the class BaseDirContext method listBindings.

/**
 * Enumerates the names bound in the named context, along with the
 * objects bound to them.
 *
 * @param name the name of the context to list
 * @return an enumeration of the bindings in this context.
 * Each element of the enumeration is of type Binding.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public final NamingEnumeration<Binding> listBindings(String name) throws NamingException {
    if (!aliases.isEmpty()) {
        AliasResult result = findAlias(name);
        if (result.dirContext != null) {
            return result.dirContext.listBindings(result.aliasName);
        }
    }
    // Next do a standard lookup
    List<NamingEntry> bindings = doListBindings(name);
    // Check the alternate locations
    List<NamingEntry> altBindings = null;
    String resourceName = "/META-INF/resources" + name;
    for (DirContext altDirContext : altDirContexts) {
        if (altDirContext instanceof BaseDirContext) {
            altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
        }
        if (altBindings != null) {
            if (bindings == null) {
                bindings = altBindings;
            } else {
                bindings.addAll(altBindings);
            }
        }
    }
    if (bindings != null) {
        return new NamingContextBindingsEnumeration(bindings.iterator(), this);
    }
    // Really not found
    throw new NameNotFoundException(sm.getString("resources.notFound", name));
}
Also used : NamingContextBindingsEnumeration(org.apache.naming.NamingContextBindingsEnumeration) NameNotFoundException(javax.naming.NameNotFoundException) NamingEntry(org.apache.naming.NamingEntry) DirContext(javax.naming.directory.DirContext)

Aggregations

NamingContextBindingsEnumeration (org.apache.naming.NamingContextBindingsEnumeration)2 NamingEntry (org.apache.naming.NamingEntry)2 File (java.io.File)1 JarFile (java.util.jar.JarFile)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 DirContext (javax.naming.directory.DirContext)1