use of org.apache.neethi.builders.xml.XmlPrimtiveAssertion in project wso2-synapse by wso2.
the class ThrottleFactory method fillCallerConfiguration.
/**
* Fills the caller configuration information based on given policy
*
* @param policy Policy instance
* @param callerConfiguration Caller configuration instance
* @throws ThrottleException
*/
private static void fillCallerConfiguration(Policy policy, CallerConfiguration callerConfiguration) throws ThrottleException {
List list = policy.getPolicyComponents();
for (Iterator iterator = list.iterator(); iterator.hasNext(); ) {
Object object = iterator.next();
XmlPrimtiveAssertion primitiveAssertion = (XmlPrimtiveAssertion) object;
OMElement element = primitiveAssertion.getValue();
// Name of the policy assertion
String name = element.getLocalName();
if (name.equals(ThrottleConstants.ALLOW_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_ALLOWED);
} else if (name.equals(ThrottleConstants.DENY_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_DENIED);
} else if (name.equals(ThrottleConstants.CONTROL_PARAMETER_NAME)) {
callerConfiguration.setAccessState(ThrottleConstants.ACCESS_CONTROLLED);
OMElement controlElement = primitiveAssertion.getValue();
if (controlElement == null) {
handleException("Invalid throttle configuration - " + "Control assertion cannot be empty");
}
Policy controlPolicy = PolicyEngine.getPolicy(controlElement);
if (controlPolicy != null) {
fillControlConfiguration(controlPolicy, callerConfiguration);
} else {
handleException("Invalid throttle configuration - " + "Cannot create a policy object(Control Assertion ) " + "form given policy file ");
}
} else {
handleException("Invalid Throttle" + " Policy configuration");
}
}
}
Aggregations