* @param metadata metadata associated with the entity
*
* @return the EntityDescriptor
*/
protected EntityDescriptor getEntityDescriptorById(String entityID, XMLObject metadata) {
EntityDescriptor descriptor = null;
log.debug("Searching for entity descriptor with an entity ID of {}", entityID);
if (indexedDescriptors.containsKey(entityID)) {
log.debug("Entity descriptor for the ID {} was found in index cache, returning", entityID);
descriptor = indexedDescriptors.get(entityID);
if (isValid(descriptor)) {
return descriptor;
} else {
indexedDescriptors.remove(descriptor);
}
}
if (metadata != null) {
if (metadata instanceof EntityDescriptor) {
log.debug("Metadata root is an entity descriptor, checking if it's the one we're looking for.");
descriptor = (EntityDescriptor) metadata;
if (!descriptor.getEntityID().equals(entityID) || !isValid(descriptor)) {
log.debug("Entity descriptor does not have the correct entity ID or is not valid, returning null");
descriptor = null;
}
} else {
log.debug("Metadata was an EntitiesDescriptor, checking if any of its descendant EntityDescriptor elements is the one we're looking for.");