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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations