if (manager.getParent() != null)
{
Iterator<DeploymentAspect> it = manager.getParent().getDeploymentAspects().iterator();
while (it.hasNext())
{
DeploymentAspect aspect = it.next();
parentProvidedConditions.addAll(aspect.getProvidesAsSet());
}
}
sortedAspects = new ArrayList<DeploymentAspect>();
List<DeploymentAspect> allAspects = new ArrayList<DeploymentAspect>(unsortedAspects);
// Add aspects with no requirements first
Iterator<DeploymentAspect> itAll = allAspects.iterator();
while (itAll.hasNext())
{
DeploymentAspect aspect = itAll.next();
if (aspect.getRequires() == null || parentProvidedConditions.containsAll(aspect.getRequiresAsSet()))
{
sortedAspects.add(aspect);
itAll.remove();
}
}
// Add aspects that have requirements that already added aspects provide
itAll = allAspects.iterator();
while (itAll.hasNext())
{
DeploymentAspect aspect = itAll.next();
int index = getAspectIndex(sortedAspects, aspect);
if (index != -1)
{
sortedAspects.add(index, aspect);
itAll.remove();
itAll = allAspects.iterator(); // Hm,...
}
}
// Add LAST_DEPLOYMENT_ASPECT
itAll = allAspects.iterator();
while (itAll.hasNext())
{
DeploymentAspect aspect = itAll.next();
if (DeploymentAspect.LAST_DEPLOYMENT_ASPECT.equals(aspect.getRequires()))
{
sortedAspects.add(aspect);
itAll.remove();
}
}