use of javax.naming.NameClassPair in project Payara by payara.
the class WebappLoader method copyDir.
/**
* Copy directory.
*/
private boolean copyDir(DirContext srcDir, File destDir) {
try {
NamingEnumeration<NameClassPair> enumeration = srcDir.list("");
while (enumeration.hasMoreElements()) {
NameClassPair ncPair = enumeration.nextElement();
String name = ncPair.getName();
Object object = srcDir.lookup(name);
File currentFile = new File(destDir, name);
if (object instanceof Resource) {
InputStream is = ((Resource) object).streamContent();
OutputStream os = new FileOutputStream(currentFile);
if (!copy(is, os))
return false;
} else if (object instanceof InputStream) {
OutputStream os = new FileOutputStream(currentFile);
if (!copy((InputStream) object, os))
return false;
} else if (object instanceof DirContext) {
if (!currentFile.isDirectory() && !currentFile.mkdir())
return false;
if (!copyDir((DirContext) object, currentFile))
return false;
}
}
} catch (NamingException | IOException e) {
return false;
}
return true;
}
use of javax.naming.NameClassPair in project geronimo-xbean by apache.
the class Lookup method list.
public void list(String name, InputStream in, PrintStream out) throws IOException {
try {
NamingEnumeration names = null;
try {
names = ctx.list(name);
} catch (NameNotFoundException e) {
out.print("lookup: ");
out.print(name);
out.println(": No such object or subcontext");
return;
} catch (Throwable e) {
out.print("lookup: error: ");
e.printStackTrace(new PrintStream(out));
return;
}
if (names == null) {
return;
}
while (names.hasMore()) {
NameClassPair entry = (NameClassPair) names.next();
out.println(entry.getName());
}
} catch (Exception e) {
e.printStackTrace(new PrintStream(out));
}
}
use of javax.naming.NameClassPair in project camel by apache.
the class JndiRegistry method findByType.
public <T> Set<T> findByType(Class<T> type) {
Set<T> answer = new LinkedHashSet<T>();
try {
NamingEnumeration<NameClassPair> list = getContext().list("");
while (list.hasMore()) {
NameClassPair pair = list.next();
Object instance = context.lookup(pair.getName());
if (type.isInstance(instance)) {
answer.add(type.cast(instance));
}
}
} catch (NamingException e) {
// ignore
}
return answer;
}
use of javax.naming.NameClassPair in project camel by apache.
the class JndiRegistry method findByTypeWithName.
public <T> Map<String, T> findByTypeWithName(Class<T> type) {
Map<String, T> answer = new LinkedHashMap<String, T>();
try {
NamingEnumeration<NameClassPair> list = getContext().list("");
while (list.hasMore()) {
NameClassPair pair = list.next();
Object instance = context.lookup(pair.getName());
if (type.isInstance(instance)) {
answer.put(pair.getName(), type.cast(instance));
}
}
} catch (NamingException e) {
// ignore
}
return answer;
}
use of javax.naming.NameClassPair in project tomcat70 by apache.
the class WebappClassLoaderBase method modified.
/**
* Have one or more classes or resources been modified so that a reload
* is appropriate?
*/
public boolean modified() {
if (log.isDebugEnabled())
log.debug("modified()");
// Checking for modified loaded resources
int length = paths.length;
// A rare race condition can occur in the updates of the two arrays
// It's totally ok if the latest class added is not checked (it will
// be checked the next time
int length2 = lastModifiedDates.length;
if (length > length2)
length = length2;
for (int i = 0; i < length; i++) {
try {
long lastModified = ((ResourceAttributes) resources.getAttributes(paths[i])).getLastModified();
if (lastModified != lastModifiedDates[i]) {
if (log.isDebugEnabled())
log.debug(" Resource '" + paths[i] + "' was modified; Date is now: " + new java.util.Date(lastModified) + " Was: " + new java.util.Date(lastModifiedDates[i]));
return (true);
}
} catch (NamingException e) {
log.error(" Resource '" + paths[i] + "' is missing");
return (true);
}
}
length = jarNames.length;
// Check if JARs have been added or removed
if (getJarPath() != null) {
try {
NamingEnumeration<Binding> enumeration = resources.listBindings(getJarPath());
int i = 0;
while (enumeration.hasMoreElements() && (i < length)) {
NameClassPair ncPair = enumeration.nextElement();
String name = ncPair.getName();
// Ignore non JARs present in the lib folder
if (!name.endsWith(".jar"))
continue;
if (!name.equals(jarNames[i])) {
// Missing JAR
log.info(" Additional JARs have been added : '" + name + "'");
return (true);
}
i++;
}
if (enumeration.hasMoreElements()) {
while (enumeration.hasMoreElements()) {
NameClassPair ncPair = enumeration.nextElement();
String name = ncPair.getName();
// Additional non-JAR files are allowed
if (name.endsWith(".jar")) {
// There was more JARs
log.info(" Additional JARs have been added");
return (true);
}
}
} else if (i < jarNames.length) {
// There was less JARs
log.info(" Additional JARs have been added");
return (true);
}
} catch (NamingException e) {
if (log.isDebugEnabled())
log.debug(" Failed tracking modifications of '" + getJarPath() + "'");
} catch (ClassCastException e) {
log.error(" Failed tracking modifications of '" + getJarPath() + "' : " + e.getMessage());
}
}
// No classes have been modified
return (false);
}
Aggregations