public Mediator createMediator(OMElement elem) {
ThrottleMediator throttleMediator = new ThrottleMediator();
OMElement policy = elem.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "policy"));
if (policy != null) {
OMAttribute key = policy.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
if (key != null) {
String keyValue = key.getAttributeValue();
if (keyValue != null && !"".equals(keyValue)) {
throttleMediator.setPolicyKey(keyValue);
} else {
handleException("key attribute should have a value ");
}
} else {
OMElement inLine = policy.getFirstElement();
if (inLine != null) {
throttleMediator.setInLinePolicy(inLine);
}
}
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processTraceState(throttleMediator,elem);
String id = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "id"));
if (id != null && !"".equals(id)) {
throttleMediator.setId(id.trim());
} else {
handleException("Idy attribute must have defined ");
}
SequenceMediatorFactory mediatorFactory = new SequenceMediatorFactory();
OMAttribute onReject = elem.getAttribute(
new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.ONREJECT));
if (onReject != null) {
String onRejectValue = onReject.getAttributeValue();
if (onRejectValue != null) {
throttleMediator.setOnRejectSeqKey(onRejectValue.trim());
}
} else {
OMElement onRejectMediatorElement = elem.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ONREJECT));
if (onRejectMediatorElement != null) {
throttleMediator.setOnRejectMediator(mediatorFactory.createAnonymousSequence(
onRejectMediatorElement));
}
}
OMAttribute onAccept = elem.getAttribute(
new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.ONACCEPT));
if (onAccept != null) {
String onAcceptValue = onAccept.getAttributeValue();
if (onAcceptValue != null) {
throttleMediator.setOnAcceptSeqKey(onAcceptValue);
}
} else {
OMElement onAcceptMediatorElement = elem.getFirstChildWithName(
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ONACCEPT));
if (onAcceptMediatorElement != null) {
throttleMediator.setOnAcceptMediator(mediatorFactory.createAnonymousSequence(
onAcceptMediatorElement));
}
}
return throttleMediator;
}
|