use of org.apache.synapse.mediators.ext.AnnotatedCommandMediator in project wso2-synapse by wso2.
the class AnnotatedCommandMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
AnnotatedCommandMediator pojoMediator = new AnnotatedCommandMediator();
processAuditStatus(pojoMediator, elem);
// Class name of the Command object should be present
OMAttribute name = elem.getAttribute(ATT_NAME);
if (name == null) {
String msg = "The name of the actual POJO command implementation class" + " is a required attribute";
log.error(msg);
throw new SynapseException(msg);
}
// load the class for the command object
try {
pojoMediator.setCommand(getClass().getClassLoader().loadClass(name.getAttributeValue()));
} catch (ClassNotFoundException e) {
handleException("Unable to load the class specified as the command " + name.getAttributeValue(), e);
}
// at the mediation time
for (Iterator it = elem.getChildElements(); it.hasNext(); ) {
OMElement child = (OMElement) it.next();
if ("property".equals(child.getLocalName())) {
String propName = child.getAttribute(ATT_NAME).getAttributeValue();
if (propName == null) {
handleException("A POJO command mediator property must specify the name attribute");
} else {
if (child.getAttribute(ATT_EXPRN) != null) {
SynapseXPath xpath;
try {
xpath = SynapseXPathFactory.getSynapseXPath(child, ATT_EXPRN);
pojoMediator.addMessageSetterProperty(propName, xpath);
} catch (JaxenException e) {
handleException("Error instantiating XPath expression : " + child.getAttribute(ATT_EXPRN), e);
}
} else {
if (child.getAttribute(ATT_VALUE) != null) {
pojoMediator.addStaticSetterProperty(propName, child.getAttribute(ATT_VALUE).getAttributeValue());
} else {
handleException("A POJO mediator property must specify either " + "name and expression attributes, or name and value attributes");
}
}
}
}
}
return pojoMediator;
}
Aggregations