Search in sources :

Example 1 with TemplateMediatorFactory

use of org.apache.synapse.config.xml.TemplateMediatorFactory in project wso2-synapse by wso2.

the class SynapseConfiguration method getSequenceTemplate.

/**
 * Return the template specified with the given key
 *
 * @param key the key being referenced for the template
 * @return the template referenced by the key from local/remote registry
 */
public TemplateMediator getSequenceTemplate(String key) {
    Object o = getEntry(key);
    if (o instanceof TemplateMediator) {
        return (TemplateMediator) o;
    }
    Entry entry = null;
    if (o == null) {
        entry = new Entry(key);
        entry.setType(Entry.REMOTE_ENTRY);
    } else {
        Object object = localRegistry.get(key);
        if (object instanceof Entry) {
            entry = (Entry) object;
        }
    }
    assertEntryNull(entry, key);
    // noinspection ConstantConditions
    if (entry.getMapper() == null) {
        entry.setMapper(new XMLToTemplateMapper());
    }
    if (entry.getType() == Entry.REMOTE_ENTRY) {
        if (registry != null) {
            o = registry.getResource(entry, getProperties());
            if (o != null && o instanceof TemplateMediator) {
                localRegistry.put(key, entry);
                return (TemplateMediator) o;
            } else if (o instanceof OMNode) {
                TemplateMediator m = (TemplateMediator) new TemplateMediatorFactory().createMediator((OMElement) o, properties);
                if (m != null) {
                    entry.setValue(m);
                    return m;
                }
            }
        }
    } else {
        Object value = entry.getValue();
        if (value instanceof OMNode) {
            Object object = entry.getMapper().getObjectFromOMNode((OMNode) value, getProperties());
            if (object instanceof TemplateMediator) {
                entry.setValue(object);
                return (TemplateMediator) object;
            }
        }
    }
    // load from available libraries
    TemplateMediator templateFromLib = LibDeployerUtils.getLibArtifact(synapseLibraries, key, TemplateMediator.class);
    if (templateFromLib != null) {
        return templateFromLib;
    }
    return null;
}
Also used : OMNode(org.apache.axiom.om.OMNode) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) TemplateMediatorFactory(org.apache.synapse.config.xml.TemplateMediatorFactory) XMLToTemplateMapper(org.apache.synapse.config.xml.XMLToTemplateMapper)

Aggregations

OMNode (org.apache.axiom.om.OMNode)1 TemplateMediatorFactory (org.apache.synapse.config.xml.TemplateMediatorFactory)1 XMLToTemplateMapper (org.apache.synapse.config.xml.XMLToTemplateMapper)1 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)1