Search in sources :

Example 6 with XmlPrimtiveAssertion

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");
        }
    }
}
Also used : Policy(org.apache.neethi.Policy) Iterator(java.util.Iterator) List(java.util.List) OMElement(org.apache.axiom.om.OMElement) XmlPrimtiveAssertion(org.apache.neethi.builders.xml.XmlPrimtiveAssertion)

Aggregations

Iterator (java.util.Iterator)6 List (java.util.List)6 XmlPrimtiveAssertion (org.apache.neethi.builders.xml.XmlPrimtiveAssertion)6 Policy (org.apache.neethi.Policy)5 OMElement (org.apache.axiom.om.OMElement)4 QName (javax.xml.namespace.QName)2 ArrayList (java.util.ArrayList)1 All (org.apache.neethi.All)1 ExactlyOne (org.apache.neethi.ExactlyOne)1