Object endpoint = itEp.next();
Component c = null;
if (key.length() > 0) {
Component comp = (Component) components.get(key);
if (comp == null) {
throw new JBIException("Could not find component '" + key + "' specified for endpoint");
}
c = comp;
} else {
for (Iterator itCmp = components.values().iterator(); itCmp.hasNext();) {
Component comp = (Component) itCmp.next();
Class[] endpointClasses = (Class[]) getEndpointClassesMethod.invoke(comp, null);
if (isKnownEndpoint(endpoint, endpointClasses)) {
c = comp;
break;
}
}
if (c == null) {
c = getComponentForEndpoint(getEndpointClassesMethod, endpoint);
if (c == null) {
throw new JBIException("Unable to find a component for endpoint class: " + endpoint.getClass());
}
}
}
addEndpointMethod.invoke(c, new Object[] {endpoint });
}