Search in sources :

Example 1 with AnnotatedCommandMediator

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;
}
Also used : SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) SynapseException(org.apache.synapse.SynapseException) JaxenException(org.jaxen.JaxenException) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) AnnotatedCommandMediator(org.apache.synapse.mediators.ext.AnnotatedCommandMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

Iterator (java.util.Iterator)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 OMElement (org.apache.axiom.om.OMElement)1 SynapseException (org.apache.synapse.SynapseException)1 AnnotatedCommandMediator (org.apache.synapse.mediators.ext.AnnotatedCommandMediator)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1 JaxenException (org.jaxen.JaxenException)1