protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
FilterMediator filter = new FilterMediator();
OMAttribute attXpath = elem.getAttribute(ATT_XPATH);
OMAttribute attSource = elem.getAttribute(ATT_SOURCE);
OMAttribute attRegex = elem.getAttribute(ATT_REGEX);
if (attXpath != null) {
if (attXpath.getAttributeValue() != null &&
attXpath.getAttributeValue().trim().length() == 0) {
handleException("Invalid attribute value specified for xpath");
} else {
try {
filter.setXpath(SynapseXPathFactory.getSynapseXPath(elem, ATT_XPATH));
} catch (JaxenException e) {
handleException("Invalid XPath expression for attribute xpath : "
+ attXpath.getAttributeValue(), e);
}
}
} else if (attSource != null && attRegex != null) {
if ((attSource.getAttributeValue() != null &&
attSource.getAttributeValue().trim().length() == 0) || (attRegex.getAttributeValue()
!= null && attRegex.getAttributeValue().trim().length() == 0) ){
handleException("Invalid attribute values for source and/or regex specified");
} else {
try {
filter.setSource(SynapseXPathFactory.getSynapseXPath(elem, ATT_SOURCE));
} catch (JaxenException e) {
handleException("Invalid XPath expression for attribute source : "
+ attSource.getAttributeValue(), e);
}
try {
filter.setRegex(Pattern.compile(attRegex.getAttributeValue()));
} catch (PatternSyntaxException pse) {
handleException("Invalid Regular Expression for attribute regex : "
+ attRegex.getAttributeValue(), pse);
}
}
} else {
handleException("An xpath or (source, regex) attributes are required for a filter");
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(filter,elem);
OMElement thenElem = elem.getFirstChildWithName(THEN_Q);
if (thenElem != null) {
filter.setThenElementPresent(true);
OMAttribute sequenceAttr = thenElem.getAttribute(ATT_SEQUENCE);
if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
filter.setThenKey(sequenceAttr.getAttributeValue());
} else {
addChildren(thenElem, filter, properties);
}
OMElement elseElem = elem.getFirstChildWithName(ELSE_Q);
if (elseElem != null) {
sequenceAttr = elseElem.getAttribute(ATT_SEQUENCE);
if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
filter.setElseKey(sequenceAttr.getAttributeValue());
} else {
AnonymousListMediator listMediator = AnonymousListMediatorFactory
.createAnonymousListMediator(elseElem, properties);