options = newOptions;
log.trace("Looking for resource: name={}", resourceName);
R resource = null;
ResourceNotFoundException chainingException = null;
if (visitedMappings == null) {
visitedMappings = createLinkedList();
}
if (findBestMatch()) {
// findBestMatch() ���1. �ҵ�alias����û���ҵ����յ�resource mapping
if (lastMatchedPattern instanceof ResourceAlias) {
if (parent != null) {
log.trace("Resource \"{}\" not found. Trying to find it in super ResourceLoadingService",
resourceName);
try {
resource = loadParentResource(resourceName, options);
} catch (ResourceNotFoundException e) {
// alias���ı�resourceName���ʱ����쳣��Ϊcaused by�쳣
chainingException = e;
}
}
} else {
// findBestMatch() ���2, 3. �ҵ�resource mapping
ResourceLoaderMapping mapping = (ResourceLoaderMapping) lastMatchedPattern;
resource = loadMappedResource(mapping, options);
if (resource == null) {
// ����resourceName���ı䣬���쳣��Ϊcaused by�쳣
if (!isEquals(resourceName, originalResourceName)) {
logResourceNotFound(resourceName);
chainingException = new ResourceNotFoundException(String.format(
"Could not find resource \"%s\"", resourceName));
}
}
}
}
// findBestMatch() ���4. ʲôҲû�ҵ�
else {
if (parent != null) {
log.trace("Resource \"{}\" not found. " + "Trying to find it in super ResourceLoadingService",
resourceName);
// ֱ���׳��쳣����Ϊ��parent��resourceName��δ�ı䣬û��Ҫ�����ظ����쳣��Ϣ
resource = loadParentResource(resourceName, options);
}
}
if (resource == null) {
logResourceNotFound(originalResourceName);
throw new ResourceNotFoundException(String.format("Could not find resource \"%s\"", originalResourceName),
chainingException);
}
log.debug("Found resource \"{}\": {}", originalResourceName, resource);