// This and only this method handles @ResourceDependency and @ResourceDependencies annotations
// The source of these annotations is Class<?> inspectedClass.
// Because Class<?> and its annotations cannot change
// during request/response, it is sufficient to process Class<?> only once per view.
RequestViewContext rvc = RequestViewContext.getCurrentInstance(context);
Class<?> inspectedClass = inspected.getClass();
if (rvc.isClassAlreadyProcessed(inspectedClass))
{
return;
}
boolean classAlreadyProcessed = false;
List<ResourceDependency> dependencyList = null;
boolean isCachedList = false;
if(context.isProjectStage(ProjectStage.Production) && _classToResourceDependencyMap.containsKey(inspectedClass))
{
dependencyList = _classToResourceDependencyMap.get(inspectedClass);
if(dependencyList == null)
{
return; //class has been inspected and did not contain any resource dependency annotations
}
else if (dependencyList.isEmpty())
{
return;
}
isCachedList = true; // else annotations were found in the cache
}
if(dependencyList == null) //not in production or the class hasn't been inspected yet
{
ResourceDependency dependency = inspectedClass.getAnnotation(ResourceDependency.class);
ResourceDependencies dependencies = inspectedClass.getAnnotation(ResourceDependencies.class);
if(dependency != null || dependencies != null)
{
//resource dependencies were found using one or both annotations, create and build a new list
dependencyList = new ArrayList<ResourceDependency>();
if(dependency != null)
{
dependencyList.add(dependency);
}
if(dependencies != null)
{
dependencyList.addAll(Arrays.asList(dependencies.value()));
}
}
else
{
dependencyList = Collections.emptyList();
}
}
//resource dependencies were found through inspection or from cache, handle them
if (dependencyList != null && !dependencyList.isEmpty())
{
for (int i = 0, size = dependencyList.size(); i < size; i++)
{
ResourceDependency dependency = dependencyList.get(i);
if (!rvc.isResourceDependencyAlreadyProcessed(dependency))
{
_handleAttachedResourceDependency(context, dependency, inspectedClass);
rvc.setResourceDependencyAsProcessed(dependency);
}
}
}
//if we're in production and the list is not yet cached, store it
if(context.isProjectStage(ProjectStage.Production) && !isCachedList)
{
// Note at this point listenerForList cannot be null, but just let this
// as a sanity check.
if (dependencyList != null)
{
_classToResourceDependencyMap.put(inspectedClass, dependencyList);
}
}
if (!classAlreadyProcessed)
{
rvc.setClassProcessed(inspectedClass);
}
}