Search in sources :

Example 1 with XMLToTemplateMapper

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

the class SynapseConfiguration method getEndpointTemplate.

public Template getEndpointTemplate(String key) {
    Object o = getEntry(key);
    if (o instanceof Template) {
        return (Template) 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 Template) {
                localRegistry.put(key, entry);
                return (Template) o;
            } else if (o instanceof OMNode) {
                Template m = new TemplateFactory().createEndpointTemplate((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 Template) {
                entry.setValue(object);
                return (Template) object;
            }
        }
    }
    // load from available libraries
    Template templateFromLib = LibDeployerUtils.getLibArtifact(synapseLibraries, key, Template.class);
    if (templateFromLib != null) {
        return templateFromLib;
    }
    return null;
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) XMLToTemplateMapper(org.apache.synapse.config.xml.XMLToTemplateMapper) TemplateFactory(org.apache.synapse.config.xml.endpoints.TemplateFactory) Template(org.apache.synapse.endpoints.Template)

Example 2 with XMLToTemplateMapper

use of org.apache.synapse.config.xml.XMLToTemplateMapper 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)2 XMLToTemplateMapper (org.apache.synapse.config.xml.XMLToTemplateMapper)2 OMElement (org.apache.axiom.om.OMElement)1 TemplateMediatorFactory (org.apache.synapse.config.xml.TemplateMediatorFactory)1 TemplateFactory (org.apache.synapse.config.xml.endpoints.TemplateFactory)1 Template (org.apache.synapse.endpoints.Template)1 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)1