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);
}
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());
}
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;
}
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;
}
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;
}
Aggregations