if (!ROUTER_Q.equals(elem.getQName())) {
handleException("Unable to create the Router mediator. " +
"Unexpected element as the Router mediator configuration");
}
RouterMediator m = new RouterMediator();
OMAttribute continueAfterAttr = elem.getAttribute(ATT_CONTINUE_AFTER);
if (continueAfterAttr != null && continueAfterAttr.getAttributeValue() != null) {
m.setContinueAfter(Boolean.parseBoolean(continueAfterAttr.getAttributeValue()));
}
for (Iterator itr = elem.getChildrenWithName(ROUTE_Q); itr.hasNext();) {
OMElement routeElement = (OMElement) itr.next();
OMAttribute expressionAttr = routeElement.getAttribute(ATT_EXPRN);
OMAttribute matchAttr = routeElement.getAttribute(ATT_MATCH);
OMAttribute breakRouterAttr = routeElement.getAttribute(ATT_BREAK_ROUTER);
OMElement targetElem = routeElement.getFirstChildWithName(TARGET_Q);
Route route = new Route();
if (expressionAttr != null && expressionAttr.getAttributeValue() != null) {
try {
route.setExpression(
SynapseXPathFactory.getSynapseXPath(routeElement, ATT_EXPRN));
} catch (JaxenException e) {
handleException("Couldn't build the xpath from the expression : "
+ expressionAttr.getAttributeValue(), e);
}
} else {
handleException("Route without an expression attribute has been found, " +
"but it is required to have an expression for all routes");
}
if (matchAttr != null && matchAttr.getAttributeValue() != null) {
route.setMatch(Pattern.compile(matchAttr.getAttributeValue()));
}
if (breakRouterAttr != null && breakRouterAttr.getAttributeValue() != null) {
route.setBreakRouter(Boolean.parseBoolean(breakRouterAttr.getAttributeValue()));
}
if (targetElem != null) {
route.setTarget(TargetFactory.createTarget(targetElem, properties));
} else {
handleException("Route has to have a target for it, " +
"missing the taregt of the route");
}
m.addRoute(route);
}
return m;
}