{
// Sort topologically the aspects, the least dependency distance
// first, and then by name within the aspects with the same distance
ClassAspect[] aspectArray = new ClassAspect[metadata.getClassAspectCount()];
Lookup predCountMap = new HashTab(metadata.getClassAspectCount());
int nStart = 0;
int nEnd = 0;
for (Iterator itr = metadata.getClassAspectIterator(); itr.hasNext();)
{
ClassAspect aspect = (ClassAspect)itr.next();
int nCount = aspect.getAspectCount();
if (nCount == 0)
{
aspectArray[nEnd++] = aspect;
}
else
{
predCountMap.put(aspect, Primitive.createInteger(nCount));
}
}
while (nStart < nEnd)
{
Arrays.sort(aspectArray, nStart, nEnd, Named.COMPARATOR);
int nNewEnd;
for (nNewEnd = nEnd; nStart < nEnd; ++nStart)
{
ClassAspect aspect = aspectArray[nStart];
for (Iterator itr = metadata.getClassAspectIterator(); itr.hasNext();)
{
ClassAspect successor = (ClassAspect)itr.next();
if (successor.hasAspect(aspect))
{
Integer predCount = (Integer)predCountMap.get(successor);
if (predCount != null)
{
int nPredCount = predCount.intValue();
if (--nPredCount == 0)
{
predCountMap.remove(successor);
aspectArray[nNewEnd++] = successor;
}
else
{
predCountMap.put(successor, Primitive.createInteger(nPredCount));
}
}
}
}
}
nEnd = nNewEnd;
}
ExceptionHolder eh = null;
if (predCountMap.size() != 0)
{
for (Iterator itr = predCountMap.iterator(); itr.hasNext();)
{
ClassAspect aspect = (ClassAspect)itr.next();
MetadataValidationException e = new MetadataValidationException("err.meta.classAspectCircularDep",
new Object[]{aspect.getName()});