use of org.apache.synapse.mediators.filters.router.ConditionalRouterMediator in project wso2-synapse by wso2.
the class ConditionalRouterMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
ConditionalRouterMediator conditionalRouterMediator = new ConditionalRouterMediator();
processAuditStatus(conditionalRouterMediator, elem);
if (elem.getAttribute(CONTINUE_AFTER_ATTR) != null) {
if (JavaUtils.isTrueExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
conditionalRouterMediator.setContinueAfter(true);
} else if (JavaUtils.isFalseExplicitly(elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim())) {
conditionalRouterMediator.setContinueAfter(false);
} else {
handleException("continueAfter attribute value of the conditionalRouter must " + "be either 'true' or 'false', the value found is : " + elem.getAttributeValue(CONTINUE_AFTER_ATTR).trim());
}
}
Iterator itr = elem.getChildrenWithName(ROUTE_Q);
while (itr.hasNext()) {
OMElement routeElem = (OMElement) itr.next();
ConditionalRoute conditionalRoute = new ConditionalRoute();
if (routeElem.getAttribute(BREAK_ROUTE_ATTR) != null) {
if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
conditionalRoute.setBreakRoute(true);
} else if (JavaUtils.isFalseExplicitly(routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim())) {
conditionalRoute.setBreakRoute(false);
} else {
handleException("breakRoute attribute value of the conditionalRoute element must " + "be either 'true' or 'false', the value found is : " + routeElem.getAttributeValue(BREAK_ROUTE_ATTR).trim());
}
}
OMElement conditionElem = routeElem.getFirstChildWithName(CONDITION_Q);
if (conditionElem == null) {
handleException("Couldn't find the condition of the conditional router");
return null;
}
try {
Evaluator evaluator = EvaluatorFactoryFinder.getInstance().getEvaluator(conditionElem.getFirstElement());
conditionalRoute.setEvaluator(evaluator);
} catch (EvaluatorException ee) {
handleException("Couldn't build the condition of the conditional router", ee);
}
OMElement targetElem = routeElem.getFirstChildWithName(TARGET_Q);
Target target = TargetFactory.createTarget(targetElem, properties);
if (JavaUtils.isTrueExplicitly(routeElem.getAttributeValue(ASYNCHRONOUS_ATTR))) {
target.setAsynchronous(true);
} else {
target.setAsynchronous(false);
}
conditionalRoute.setTarget(target);
conditionalRouterMediator.addRoute(conditionalRoute);
}
return conditionalRouterMediator;
}
use of org.apache.synapse.mediators.filters.router.ConditionalRouterMediator in project wso2-synapse by wso2.
the class ConditionalRouterMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
OMElement conditionalRouterElem = fac.createOMElement("conditionalRouter", synNS);
saveTracingState(conditionalRouterElem, m);
ConditionalRouterMediator conditionalRouterMediator = (ConditionalRouterMediator) m;
if (conditionalRouterMediator.isContinueAfterExplicitlySet()) {
conditionalRouterElem.addAttribute("continueAfter", Boolean.toString(conditionalRouterMediator.isContinueAfter()), nullNS);
}
for (ConditionalRoute conditionalRoute : conditionalRouterMediator.getConditionalRoutes()) {
OMElement routeElem = fac.createOMElement("conditionalRoute", synNS);
if (conditionalRoute.isBreakRouteExplicitlySet()) {
routeElem.addAttribute("breakRoute", Boolean.toString(conditionalRoute.isBreakRoute()), nullNS);
}
if (conditionalRoute.getEvaluator() != null) {
EvaluatorSerializer evaluatorSerializer = EvaluatorSerializerFinder.getInstance().getSerializer(conditionalRoute.getEvaluator().getName());
if (evaluatorSerializer != null) {
OMElement conditionElement = fac.createOMElement("condition", synNS);
try {
evaluatorSerializer.serialize(conditionElement, conditionalRoute.getEvaluator());
} catch (EvaluatorException e) {
handleException("Cannot serialize the Evaluator", e);
}
routeElem.addChild(conditionElement);
}
}
if (conditionalRoute.getTarget() != null) {
routeElem.addChild(TargetSerializer.serializeTarget(conditionalRoute.getTarget()));
} else {
handleException("ConditionalRoute in a conditional router has to have a target");
}
if (conditionalRoute.getTarget().isAsynchronous()) {
routeElem.addAttribute(fac.createOMAttribute("asynchronous", nullNS, "true"));
}
conditionalRouterElem.addChild(routeElem);
}
return conditionalRouterElem;
}
Aggregations