if ((index < 0) || (index > constraints.accessConstraints().size()))
{
throw new IndexOutOfBoundsException("Unable to add to list at index: " + index);
}
// verify constraint
SecurityConstraintImpl constraint = validateConstraintForAdd((SecurityConstraintImpl)element);
// add to underlying ordered list
constraints.accessConstraints().add(index, constraint);
// set apply order in added element
if (index > 0)
{
constraint.setApplyOrder(((SecurityConstraintImpl)constraints.accessConstraints().get(index-1)).getApplyOrder() + 1);
}
else
{
constraint.setApplyOrder(0);
}
// maintain apply order in subsequent elements
for (int i = index, limit = constraints.accessConstraints().size() - 1; (i < limit); i++)
{
SecurityConstraintImpl nextConstraint = (SecurityConstraintImpl)constraints.accessConstraints().get(i + 1);
if (nextConstraint.getApplyOrder() <= constraint.getApplyOrder())
{
// adjust apply order for next element
nextConstraint.setApplyOrder(constraint.getApplyOrder() + 1);
constraint = nextConstraint;
}
else
{
// apply order maintained for remaining list elements