Search in sources :

Example 1 with NamingEntry

use of org.apache.naming.NamingEntry 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 NamingEntry

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

the class WebDirContext method list.

/**
 * Enumerates the names bound in the named context, along with the class
 * names of 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 names and class names of the bindings in
 * this context. Each element of the enumeration is of type NameClassPair.
 * @exception NamingException if a naming exception is encountered
 */
@Override
public NamingEnumeration<NameClassPair> list(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> jfList = list(jfeEntry);
        if (namingEntries != null) {
            namingEntries.addAll(jfList);
        } else {
            namingEntries = jfList;
        }
    }
    if (file == null && jfeEntries.size() == 0) {
        throw new NamingException(MessageFormat.format(rb.getString(LogFacade.RESOURCES_NOT_FOUND), name));
    }
    return new NamingContextEnumeration(namingEntries.iterator());
}
Also used : NamingContextEnumeration(org.apache.naming.NamingContextEnumeration) NamingException(javax.naming.NamingException) NamingEntry(org.apache.naming.NamingEntry) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with NamingEntry

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

the class WebDirContext method list.

protected List<NamingEntry> list(JarFileEntry jfeEntry) {
    List<NamingEntry> entries = new ArrayList<NamingEntry>();
    JarFile jarFile = jfeEntry.jarFile;
    JarEntry jarEntry = jfeEntry.jarEntry;
    if (!jarEntry.isDirectory()) {
        return entries;
    }
    String prefix = jarEntry.getName();
    int prefixLength = prefix.length();
    Enumeration<JarEntry> e = jarFile.entries();
    while (e.hasMoreElements()) {
        JarEntry je = e.nextElement();
        String name = je.getName();
        if (name.length() > prefixLength && name.startsWith(prefix)) {
            int endIndex = name.indexOf('/', prefixLength);
            if (endIndex != -1 && endIndex != name.length() - 1) {
                // more levels
                continue;
            }
            String subName = ((endIndex != -1) ? name.substring(prefixLength, endIndex) : name.substring(prefixLength));
            Object object = null;
            if (je.isDirectory()) {
                WebDirContext tempContext = new WebDirContext(env);
                tempContext.docBase = name;
                tempContext.setAllowLinking(getAllowLinking());
                tempContext.setCaseSensitive(isCaseSensitive());
                tempContext.setJarFileResourcesProvider(jarFileResourcesProvider);
                tempContext.setJarResourceBase(name);
                object = tempContext;
            } else {
                object = new JarResource(jarFile, je);
            }
            entries.add(new NamingEntry(subName, object, NamingEntry.ENTRY));
        }
    }
    return entries;
}
Also used : NamingEntry(org.apache.naming.NamingEntry) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 4 with NamingEntry

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

the class FileDirContext method list.

/**
 * List the resources which are members of a collection.
 *
 * @param file Collection
 * @return ArrayList containg NamingEntry objects
 */
protected ArrayList<NamingEntry> list(File file) {
    ArrayList<NamingEntry> entries = new ArrayList<NamingEntry>();
    if (!file.isDirectory())
        return entries;
    String[] names = file.list();
    if (names == null) {
        /* Some IO error occurred such as bad file permissions,
             * lack of file descriptors.
             * Prevent a NPE with Arrays.sort(names) */
        logger.log(Level.WARNING, LogFacade.FILE_RESOURCES_LISTING_NULL, file.getAbsolutePath());
        return entries;
    }
    // Sort alphabetically
    Arrays.sort(names);
    NamingEntry entry = null;
    for (int i = 0; i < names.length; i++) {
        // START S1AS8PE 4965170
        String keyName = file.getPath() + '/' + names[i];
        File currentFile = validate(file, names[i], keyName, listFileCache, true);
        // END S1AS8PE 4965170
        Object object = null;
        if (currentFile != null && currentFile.isDirectory()) {
            FileDirContext tempContext = new FileDirContext(env);
            tempContext.setDocBase(file.getPath());
            tempContext.setAllowLinking(getAllowLinking());
            tempContext.setCaseSensitive(isCaseSensitive());
            object = tempContext;
        } else {
            object = new FileResource(currentFile);
        }
        entry = new NamingEntry(names[i], object, NamingEntry.ENTRY);
        entries.add(entry);
    }
    return entries;
}
Also used : NamingEntry(org.apache.naming.NamingEntry) File(java.io.File)

Example 5 with NamingEntry

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

the class WARDirContext method list.

/**
 * List children as objects.
 */
protected ArrayList<NamingEntry> list(Entry entry) {
    ArrayList<NamingEntry> entries = new ArrayList<NamingEntry>();
    Entry[] children = entry.getChildren();
    Arrays.sort(children);
    NamingEntry namingEntry = null;
    for (int i = 0; i < children.length; i++) {
        ZipEntry current = children[i].getEntry();
        Object object = null;
        if (current.isDirectory()) {
            object = new WARDirContext(base, children[i]);
        } else {
            object = new WARResource(current);
        }
        namingEntry = new NamingEntry(children[i].getName(), object, NamingEntry.ENTRY);
        entries.add(namingEntry);
    }
    return entries;
}
Also used : ZipEntry(java.util.zip.ZipEntry) NamingEntry(org.apache.naming.NamingEntry) ZipEntry(java.util.zip.ZipEntry) NamingEntry(org.apache.naming.NamingEntry)

Aggregations

NamingEntry (org.apache.naming.NamingEntry)11 File (java.io.File)5 ArrayList (java.util.ArrayList)3 JarFile (java.util.jar.JarFile)3 ZipEntry (java.util.zip.ZipEntry)3 NameNotFoundException (javax.naming.NameNotFoundException)2 NamingException (javax.naming.NamingException)2 DirContext (javax.naming.directory.DirContext)2 NamingContextBindingsEnumeration (org.apache.naming.NamingContextBindingsEnumeration)2 NamingContextEnumeration (org.apache.naming.NamingContextEnumeration)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 JarEntry (java.util.jar.JarEntry)1 CompositeName (javax.naming.CompositeName)1 Name (javax.naming.Name)1