/**
* @version $Rev: 422591 $ $Date: 2006-07-16 21:21:51 -0400 (Sun, 16 Jul 2006) $
*/
public class SharedLib {
public SharedLib(ClassLoader classLoader, String[] classesDirs, String[] libDirs, ServerInfo serverInfo) throws MalformedURLException {
MultiParentClassLoader multiParentClassLoader = (MultiParentClassLoader) classLoader;
Set currentUrls = new HashSet(Arrays.asList(multiParentClassLoader.getURLs()));
int size=0;
if (classesDirs != null) size += classesDirs.length;
if (libDirs != null) size += libDirs.length;
LinkedHashSet newUrls = new LinkedHashSet(size);
if (classesDirs != null) {
for (int i = 0; i < classesDirs.length; i++) {
String classesDir = classesDirs[i];
File dir = serverInfo.resolve(classesDir);
if (!dir.exists()) {
if (!dir.mkdirs()) {
throw new IllegalArgumentException("Failed to create classes dir: " + dir);
}
}
if (!dir.isDirectory()) {
throw new IllegalArgumentException("Classes dir is not a directory: " + dir);
}
URL location = dir.toURL();
if (!currentUrls.contains(location)) {
newUrls.add(location);
}
}
}
if (libDirs != null) {
for (int i = 0; i < libDirs.length; i++) {
String libDir = libDirs[i];
File dir = serverInfo.resolve(libDir);
if (!dir.exists()) {
if (!dir.mkdirs()) {
throw new IllegalArgumentException("Failed to create lib dir: " + dir);
}
}
if (!dir.isDirectory()) {
throw new IllegalArgumentException("Lib dir is not a directory: " + dir);
}
File[] files = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File file = files[j];
if (file.canRead() && (file.getName().endsWith(".jar") || file.getName().endsWith(".zip"))) {
URL location = file.toURL();
if (!currentUrls.contains(location)) {
newUrls.add(location);
}
}
}
}
}
for (Iterator iterator = newUrls.iterator(); iterator.hasNext();) {
URL url = (URL) iterator.next();
multiParentClassLoader.addURL(url);
}
}