{
final List rval = new ArrayList();
for (Iterator iter = loaderConfigs.iterator(); iter.hasNext();)
{
final ClasspathConfig lConfig = (ClasspathConfig) iter.next();
if (lConfig.getFactories() != null)
{
log.debug("using cached " + lConfig.getFactories());
for (StringTokenizer tokens = new StringTokenizer(lConfig.getFactories(), ","); tokens.hasMoreTokens();)
{
rval.add(tokens.nextToken());
}
}
else if (lConfig.isNoFactories())
{
log.debug("previously scanned " + lConfig.getJar());
}
else
{
Runnable r = new Runnable()
{
public void run()
{
final List localFactories = new ArrayList();
boolean foundFactory = false;
StringBuffer factoriesAsString = null;
try
{
log.debug("searching " + lConfig.getJar());
ClassLoader l = createClassLoader(loaderConfigs, baseLoader);
JarFile jarFile = new JarFile(lConfig.getJar());
ProgressMonitor monitor = null;
int entryNumber = 0;
if (HermesBrowser.getBrowser() != null)
{
monitor = new ProgressMonitor(HermesBrowser.getBrowser(), "Looking for factories in " + lConfig.getJar(), "Scanning...", 0, jarFile
.size());
monitor.setMillisToDecideToPopup(0);
monitor.setMillisToPopup(0);
monitor.setProgress(0);
}
for (Enumeration iter = jarFile.entries(); iter.hasMoreElements();)
{
ZipEntry entry = (ZipEntry) iter.nextElement();
entryNumber++;
if (monitor != null)
{
monitor.setProgress(entryNumber);
monitor.setNote("Checking entry " + entryNumber + " of " + jarFile.size());
}
if (entry.getName().endsWith(".class"))
{
String s = entry.getName().substring(0, entry.getName().indexOf(".class"));
s = s.replaceAll("/", ".");
try
{
if (s.startsWith("hermes.browser") || s.startsWith("hermes.impl") || s.startsWith("javax.jms"))
{
// NOP
}
else
{
Class clazz = l.loadClass(s);
if (!clazz.isInterface())
{
if (implementsOrExtends(clazz, ConnectionFactory.class))
{
foundFactory = true;
localFactories.add(s);
if (factoriesAsString == null)
{
factoriesAsString = new StringBuffer();
factoriesAsString.append(clazz.getName());
}
else
{
factoriesAsString.append(",").append(clazz.getName());
}
log.debug("found " + clazz.getName());
}
}
/**
* TODO: remove Class clazz = l.loadClass(s);
* Class[] interfaces = clazz.getInterfaces();
* for (int i = 0; i < interfaces.length; i++) {
* if
* (interfaces[i].equals(TopicConnectionFactory.class) ||
* interfaces[i].equals(QueueConnectionFactory.class) ||
* interfaces[i].equals(ConnectionFactory.class)) {
* foundFactory = true; localFactories.add(s);
* if (factoriesAsString == null) {
* factoriesAsString = new
* StringBuffer(clazz.getName()); } else {
* factoriesAsString.append(",").append(clazz.getName()); }
* log.debug("found " + clazz.getName()); } }
*/
}
}
catch (Throwable t)
{
// NOP
}
}
}
}
catch (IOException e)
{
log.error("unable to access jar/zip " + lConfig.getJar() + ": " + e.getMessage(), e);
}
if (!foundFactory)
{
lConfig.setNoFactories(true);
}
else
{
lConfig.setFactories(factoriesAsString.toString());
rval.addAll(localFactories);
}
}
};