ListProxy alternatePolicies =
(ListProxy) ((BeanProxy) context.getInteractionModel()).
getPropertyProxy(PolicyModel.ALTERNATE_POLICIES);
int size = alternatePolicies.size();
for (int i = size - 1; i >= 0; i--) {
PolicyReference reference = (PolicyReference)
alternatePolicies.getItemProxy(i).getModelObject();
if (reference.getExpectedPolicyType().equals(type)) {
Operation removeOp = alternatePolicies
.prepareRemoveProxyItemOperation(
alternatePolicies.getItemProxy(i));
context.executeOperation(removeOp);
}
}
// Do not add an empty policy value as this is illlegal
if (policy != null && policy.trim().length() > 0) {
PolicyReference newReference = PolicyFactory.getDefaultInstance().
createPolicyReference(policy, type);
Operation addOp =
alternatePolicies
.prepareAddModelItemOperation(newReference);
context.executeOperation(addOp);