Search in sources :

Example 46 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class MediatorFactoryFinder method getDynamicInvokeMediator.

public InvokeMediator getDynamicInvokeMediator(OMElement connectorElem, String libraryName) {
    InvokeMediator invokeMediator = new InvokeMediator();
    if (connectorElem.getLocalName() != null && libraryName != null && !libraryName.equals("")) {
        invokeMediator.setTargetTemplate(libraryName + "." + connectorElem.getLocalName());
    }
    // load configuration based references for the given connector
    OMAttribute config_key = connectorElem.getAttribute(new QName(XMLConfigConstants.CONFIG_REF));
    if (config_key != null) {
        // ValueFactory for creating dynamic or static Value
        ValueFactory keyFac = new ValueFactory();
        // create dynamic or static key based on OMElement
        Value generatedKey = keyFac.createValue(XMLConfigConstants.CONFIG_REF, connectorElem);
        // setKey
        invokeMediator.setKey(generatedKey);
    }
    buildParamteres(connectorElem, invokeMediator);
    invokeMediator.setPackageName(libraryName);
    invokeMediator.setDynamicMediator(true);
    return invokeMediator;
}
Also used : QName(javax.xml.namespace.QName) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) Value(org.apache.synapse.mediators.Value) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 47 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class MessageProcessorFactory method createMessageProcessor.

/**
 * Creates a Message processor instance from given xml configuration element
 * @param elem OMElement of that contain the Message processor configuration
 * @return  created message processor instance
 */
public static MessageProcessor createMessageProcessor(OMElement elem) {
    MessageProcessor processor = null;
    OMAttribute clssAtt = elem.getAttribute(CLASS_Q);
    if (clssAtt != null) {
        String clssName = clssAtt.getAttributeValue();
        // Make synapse configuration backward compatible
        if (MessageProcessorConstants.DEPRECATED_FORWARDING_PROCESSOR_CLASS.equals(clssName)) {
            clssName = ScheduledMessageForwardingProcessor.class.getName();
        } else if (MessageProcessorConstants.DEPRECATED_SAMPLING_PROCESSOR_CLASS.equals(clssName)) {
            clssName = SamplingProcessor.class.getName();
        }
        try {
            Class cls = Class.forName(clssName);
            processor = (MessageProcessor) cls.newInstance();
        } catch (Exception e) {
            handleException("Error while creating Message processor " + e.getMessage());
        }
    } else {
        /**
         *We throw Exception since there is not default processor
         */
        handleException("Can't create Message processor without a provider class");
    }
    OMAttribute nameAtt = elem.getAttribute(NAME_Q);
    if (nameAtt != null) {
        assert processor != null;
        processor.setName(nameAtt.getAttributeValue());
    } else {
        handleException("Can't create Message processor without a name ");
    }
    if (FORWARDING_PROCESSOR.equals(clssAtt.getAttributeValue())) {
        OMAttribute targetSequenceAtt = elem.getAttribute(TARGET_ENDPOINT_Q);
        if (targetSequenceAtt != null) {
            assert processor != null;
            processor.setTargetEndpoint(targetSequenceAtt.getAttributeValue());
        } else {
        // This validation is commented due to backward compatibility
        // handleException("Can't create Message processor without a target endpoint ");
        }
    }
    OMAttribute storeAtt = elem.getAttribute(MESSAGE_STORE_Q);
    if (storeAtt != null) {
        assert processor != null;
        processor.setMessageStoreName(storeAtt.getAttributeValue());
    } else {
        handleException("Can't create a message processor with out a message Store");
    }
    OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
    if (descriptionElem != null) {
        assert processor != null;
        processor.setDescription(descriptionElem.getText());
    }
    assert processor != null;
    processor.setParameters(getParameters(elem));
    return processor;
}
Also used : MessageProcessor(org.apache.synapse.message.processor.MessageProcessor) ScheduledMessageForwardingProcessor(org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) SynapseException(org.apache.synapse.SynapseException)

Example 48 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class TargetFactory method createTarget.

/**
 * This static method will be used to build the Target from the specified element
 *
 * @param elem - OMElement describing the xml configuration of the target
 * @param properties bag of properties with information
 * @return Target built by parsing the given element
 */
public static Target createTarget(OMElement elem, Properties properties) {
    if (!TARGET_Q.equals(elem.getQName())) {
        handleException("Element does not match with the target QName");
    }
    Target target = new Target();
    OMAttribute toAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "to"));
    if (toAttr != null && toAttr.getAttributeValue() != null) {
        target.setToAddress(toAttr.getAttributeValue());
    }
    OMAttribute soapAction = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "soapAction"));
    if (soapAction != null && soapAction.getAttributeValue() != null) {
        target.setSoapAction(soapAction.getAttributeValue());
    }
    OMAttribute sequenceAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "sequence"));
    if (sequenceAttr != null && sequenceAttr.getAttributeValue() != null) {
        target.setSequenceRef(sequenceAttr.getAttributeValue());
    }
    OMAttribute endpointAttr = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "endpoint"));
    if (endpointAttr != null && endpointAttr.getAttributeValue() != null) {
        target.setEndpointRef(endpointAttr.getAttributeValue());
    }
    OMElement sequence = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "sequence"));
    if (sequence != null) {
        SequenceMediatorFactory fac = new SequenceMediatorFactory();
        target.setSequence(fac.createAnonymousSequence(sequence, properties));
    }
    OMElement endpoint = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
    if (endpoint != null) {
        target.setEndpoint(EndpointFactory.getEndpointFromElement(endpoint, true, properties));
    }
    return target;
}
Also used : Target(org.apache.synapse.mediators.eip.Target) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 49 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class TaskManagerFactory method createTaskManager.

public static TaskManager createTaskManager(OMElement elem, Properties properties) {
    OMAttribute prov = elem.getAttribute(PROVIDER_Q);
    if (prov != null) {
        try {
            Class provider = Class.forName(prov.getAttributeValue());
            TaskManager taskManager = (TaskManager) provider.newInstance();
            taskManager.init(getProperties(elem, properties));
            taskManager.setConfigurationProperties(getProperties(elem, properties));
            return taskManager;
        } catch (ClassNotFoundException e) {
            handleException("Cannot locate task provider class : " + prov.getAttributeValue(), e);
        } catch (IllegalAccessException e) {
            handleException("Error instantiating task provider : " + prov.getAttributeValue(), e);
        } catch (InstantiationException e) {
            handleException("Error instantiating task provider : " + prov.getAttributeValue(), e);
        }
    } else {
        handleException("The task 'provider' " + "attribute is required for a taskManager definition");
    }
    return null;
}
Also used : TaskManager(org.apache.synapse.task.TaskManager) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 50 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class TemplateMediatorFactory method initParameters.

private void initParameters(OMElement templateElem, TemplateMediator templateMediator) {
    Iterator subElements = templateElem.getChildElements();
    Collection<String> paramNames = new ArrayList<String>();
    while (subElements.hasNext()) {
        OMElement child = (OMElement) subElements.next();
        if (child.getQName().equals(PARAMETER_Q)) {
            OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
            if (paramNameAttr != null) {
                paramNames.add(paramNameAttr.getAttributeValue());
            }
        // child.detach();
        }
    }
    templateMediator.setParameters(paramNames);
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMAttribute (org.apache.axiom.om.OMAttribute)187 OMElement (org.apache.axiom.om.OMElement)116 QName (javax.xml.namespace.QName)82 Iterator (java.util.Iterator)41 OMFactory (org.apache.axiom.om.OMFactory)31 OMNamespace (org.apache.axiom.om.OMNamespace)28 SynapseException (org.apache.synapse.SynapseException)28 JaxenException (org.jaxen.JaxenException)28 OMNode (org.apache.axiom.om.OMNode)13 Value (org.apache.synapse.mediators.Value)12 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)11 ArrayList (java.util.ArrayList)8 Endpoint (org.apache.synapse.endpoints.Endpoint)7 IOException (java.io.IOException)6 List (java.util.List)6 OMText (org.apache.axiom.om.OMText)6 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 StringReader (java.io.StringReader)5 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)5 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)5