private static final QName ON_FAIL_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "on-fail");
private static final QName SCHEMA_Q = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "schema");
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
ValidateMediator validateMediator = new ValidateMediator();
// process schema element definitions and create DynamicProperties
List<String> schemaKeys = new ArrayList<String>();
Iterator schemas = elem.getChildrenWithName(SCHEMA_Q);
while (schemas.hasNext()) {
Object o = schemas.next();
if (o instanceof OMElement) {
OMElement omElem = (OMElement) o;
OMAttribute keyAtt = omElem.getAttribute(ATT_KEY);
if (keyAtt != null) {
schemaKeys.add(keyAtt.getAttributeValue());
} else {
handleException("A 'schema' definition must contain a local property 'key'");
}
} else {
handleException("Invalid 'schema' declaration for validate mediator");
}
}
if (schemaKeys.size() == 0) {
handleException("No schema specified for the validate mediator");
} else {
validateMediator.setSchemaKeys(schemaKeys);
}
// process source XPath attribute if present
OMAttribute attSource = elem.getAttribute(ATT_SOURCE);
if (attSource != null) {
try {
validateMediator.setSource(SynapseXPathFactory.getSynapseXPath(elem, ATT_SOURCE));
} catch (JaxenException e) {
handleException("Invalid XPath expression specified for attribute 'source'", e);
}
}
// process on-fail
OMElement onFail = null;
Iterator iterator = elem.getChildrenWithName(ON_FAIL_Q);
if (iterator.hasNext()) {
onFail = (OMElement)iterator.next();
}
if (onFail != null && onFail.getChildElements().hasNext()) {
addChildren(onFail, validateMediator, properties);
} else {
handleException("A non-empty <on-fail> child element is required for " +
"the <validate> mediator");
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(validateMediator,elem);
// set the features
for (Map.Entry<String,String> entry : collectNameValuePairs(elem, FEATURE_Q).entrySet()) {
String value = entry.getValue();
boolean isFeatureEnabled;
if ("true".equals(value)) {
isFeatureEnabled = true;
} else if ("false".equals(value)) {
isFeatureEnabled = false;
} else {
handleException("The feature must have value true or false");
break;
}
try {
validateMediator.addFeature(entry.getKey(), isFeatureEnabled);
} catch (SAXException e) {
handleException("Error setting validation feature : " + entry.getKey()
+ " to : " + value, e);
}
}