in src/main/java/org/apache/neethi/AbstractPolicyOperator.java [91:163]
private static PolicyComponent normalizeOperator(Policy policy,
PolicyOperator operator,
PolicyRegistry reg,
boolean deep) {
short type = operator.getType();
if (operator.isEmpty()) {
ExactlyOne exactlyOne = new ExactlyOne();
if (Constants.TYPE_EXACTLYONE != type) {
exactlyOne.addPolicyComponent(new All());
}
return exactlyOne;
}
List<PolicyComponent> childComponentsList = new ArrayList<PolicyComponent>();
for (PolicyComponent policyComponent : operator.getPolicyComponents()) {
if (policyComponent.getType() == Constants.TYPE_ASSERTION) {
if (deep) {
policyComponent = ((Assertion) policyComponent).normalize();
}
if (policyComponent.getType() == Constants.TYPE_POLICY) {
childComponentsList.add(((Policy) policyComponent).getFirstPolicyComponent());
} else {
ExactlyOne exactlyOne = new ExactlyOne();
All all = new All();
all.addPolicyComponent(policyComponent);
exactlyOne.addPolicyComponent(all);
childComponentsList.add(exactlyOne);
}
} else if (policyComponent.getType() == Constants.TYPE_POLICY_REF) {
String uri = ((PolicyReference) policyComponent).getURI();
policyComponent = reg == null ? null : reg.lookup(uri);
if (policyComponent == null && uri.charAt(0) == '#') {
String id = uri.substring(1);
policyComponent = reg == null ? null : reg.lookup(id);
if (policyComponent == null) {
for (PolicyComponent p : policy.getPolicyComponents()) {
if (p instanceof Policy && id.equals(((Policy)p).getId())) {
policyComponent = p;
}
}
}
}
if (policyComponent == null) {
throw new RuntimeException(uri + " can't be resolved");
}
All all = new All();
all.addPolicyComponents(((Policy) policyComponent).getPolicyComponents());
childComponentsList.add(AbstractPolicyOperator.normalizeOperator(policy, all, reg, deep));
} else if (policyComponent.getType() == Constants.TYPE_POLICY) {
All all = new All();
all.addPolicyComponents(((Policy) policyComponent).getPolicyComponents());
childComponentsList.add(AbstractPolicyOperator.normalizeOperator(policy, all, reg, deep));
} else {
childComponentsList.add(AbstractPolicyOperator
.normalizeOperator(policy,
(PolicyOperator)policyComponent, reg, deep));
}
}
return computeResultantComponent(childComponentsList, type);
}