//Fill data into the ThrottlePolicy object by going through existing policy
if (throttlePolicy != null) {
for (Object inThrottle : throttlePolicy.getPolicyComponents()) {
//top level elements can be an 'All' or MaximumConcurrentAccess
if (inThrottle instanceof Policy) {
InternalData data = new InternalData();
for (Object inSecondLevelPolicy : ((Policy) inThrottle).getAssertions()) {
//In this level it can be ID or 'ExactlyOne'
if (inSecondLevelPolicy instanceof XmlPrimtiveAssertion) {
OMElement range = ((XmlPrimtiveAssertion) inSecondLevelPolicy).getValue();
data.setRange(range.getText());
if (range.getAttributeValue(ThrottleConstants
.THROTTLE_TYPE_ATTRIBUTE_QNAME).equals(
ThrottleComponentConstants.DOMIN_ATT_VALUE)) {
data.setRangeType(ThrottleComponentConstants.DOMIN_ATT_VALUE);
}
} else if (inSecondLevelPolicy instanceof Policy) {
for (Object inThirdLevelPolicy :
((Policy) inSecondLevelPolicy).getPolicyComponents()) {
if (inThirdLevelPolicy instanceof XmlPrimtiveAssertion) {
OMElement accessLevel = ((XmlPrimtiveAssertion)
inThirdLevelPolicy).getValue();
if (accessLevel.getLocalName()
.equals(ThrottleConstants.ALLOW_PARAMETER_NAME)) {
data.setAccessLevel(ThrottleConstants.ACCESS_ALLOWED);
} else if (accessLevel.getLocalName()
.equals(ThrottleConstants.DENY_PARAMETER_NAME)) {
data.setAccessLevel(ThrottleConstants.ACCESS_DENIED);
} else {
data.setAccessLevel(ThrottleConstants.ACCESS_CONTROLLED);
OMElement policy = accessLevel
.getFirstChildWithName(Constants.Q_ELEM_POLICY);
Policy fourthLevelPolicy = PolicyEngine.getPolicy(policy);
for (Object inFourthLevelPolicy :
fourthLevelPolicy.getPolicyComponents()) {
OMElement temp = ((XmlPrimtiveAssertion)
inFourthLevelPolicy).getValue();
String localname = temp.getLocalName();
//there can be three params here
if (localname.equals(ThrottleConstants
.MAXIMUM_COUNT_PARAMETER_NAME)) {
data.setMaxRequestCount(validateAndToInt(temp.getText()));
} else if (localname.equals(ThrottleConstants
.UNIT_TIME_PARAMETER_NAME)) {
data.setUnitTime(validateAndToInt(temp.getText()));
} else if (localname.equals(ThrottleConstants
.PROHIBIT_TIME_PERIOD_PARAMETER_NAME)) {
data.setProhibitTimePeriod(validateAndToInt(temp.getText()));
}
}
}
}
}