* @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 (entityID != null && indexedDescriptors.containsKey(entityID)) {
descriptor = indexedDescriptors.get(entityID);
if (isValid(descriptor)) {
log.trace("Entity descriptor for the ID {} was found in index cache, returning", entityID);
return descriptor;
} else {
indexedDescriptors.remove(descriptor);
}
}
if (metadata != null) {
if (metadata instanceof EntityDescriptor) {
log.trace("Metadata root is an entity descriptor, checking if it's the one we're looking for.");
descriptor = (EntityDescriptor) metadata;
if (!DatatypeHelper.safeEquals(descriptor.getEntityID(), entityID)) {
// skip this one, it isn't what we're looking for
descriptor = null;
} else if (!isValid(descriptor)) {
log.trace("Found entity descriptor for entity with ID {} but it is no longer valid, skipping it.",
entityID);