private static final QName ANNOTATED_COMMAND_Q =
new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "annotatedCommand");
public Mediator createMediator(OMElement elem) {
AnnotatedCommandMediator pojoMediator = new AnnotatedCommandMediator();
// 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);
}
// setting the properties to the command. these properties will be instantiated
// 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) {
AXIOMXPath xpath = null;
try {
xpath = new AXIOMXPath(
child.getAttribute(ATT_EXPRN).getAttributeValue());
OMElementUtils.addNameSpaces(xpath, child, log);
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");
}