candidates.put(ns, h);
}
// Exclude directly incompatible handlers
for (URI ns : namespaces) {
for (Iterator<NamespaceHandler> it = candidates.get(ns).iterator(); it.hasNext();) {
NamespaceHandler h = it.next();
Set<Class> classes = h.getManagedClasses();
boolean compat = true;
if (classes != null) {
Set<Class> allClasses = new HashSet<Class>();
for (Class cl : classes) {
for (Class c = cl; c != null; c = c.getSuperclass()) {
allClasses.add(c);
for (Class i : c.getInterfaces()) {
allClasses.add(i);
}
}
}
for (Class cl : allClasses) {
Class clb;
try {
clb = bundle.loadClass(cl.getName());
} catch (Throwable t) {
clb = null;
}
if (clb != cl) {
compat = false;
break;
}
}
}
if (!compat) {
it.remove();
}
}
}
// TODO: do we need to check if there are incompatibilities between namespaces?
// Pick the first ones
for (URI ns : namespaces) {
Set<NamespaceHandler> h = candidates.get(ns);
if (!h.isEmpty()) {
handlers.put(ns, h.iterator().next());
}
}
return handlers;
}