/** * Gets the named EntitiesDescriptor from the metadata. This method should not check if the provider is initialized, * if arguments are null, if metadata is valid, etc. All of this is done by the invoker of this method. * * @param name the name of the EntitiesDescriptor, never null * * @return the named EntitiesDescriptor or null if no such EntitiesDescriptor exists * * @throws MetadataProviderException thrown if there is a problem searching for the EntitiesDescriptor */ protected EntitiesDescriptor doGetEntitiesDescriptor(String name) throws MetadataProviderException { XMLObject metadata = doGetMetadata(); if (metadata == null) { log.debug("Metadata provider does not currently contain any metadata, unable to look for an EntitiesDescriptor with the name {}", name); return null; } EntitiesDescriptor descriptor = null; if (metadata instanceof EntitiesDescriptor) { descriptor = getEntitiesDescriptorByName(name, (EntitiesDescriptor) metadata); } return descriptor; }
/** * Gets the entities descriptor with the given name. * * @param name name of the entities descriptor * @param rootDescriptor the root descriptor to search in * * @return the EntitiesDescriptor with the given name */ protected EntitiesDescriptor getEntitiesDescriptorByName(String name, EntitiesDescriptor rootDescriptor) { EntitiesDescriptor descriptor = null; if (DatatypeHelper.safeEquals(name, rootDescriptor.getName()) && isValid(rootDescriptor)) { descriptor = rootDescriptor; } else { List<EntitiesDescriptor> childDescriptors = rootDescriptor.getEntitiesDescriptors(); if (childDescriptors == null || childDescriptors.isEmpty()) { return null; } for (EntitiesDescriptor childDescriptor : childDescriptors) { childDescriptor = getEntitiesDescriptorByName(name, childDescriptor); if (childDescriptor != null) { descriptor = childDescriptor; } } } return descriptor; }