Search in sources :

Example 1 with TemplateFactory

use of org.apache.synapse.config.xml.endpoints.TemplateFactory 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 TemplateFactory

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

the class SynapseXMLConfigurationFactory method defineEndpointTemplate.

public static Template defineEndpointTemplate(SynapseConfiguration config, OMElement elem, Properties properties) {
    TemplateFactory templateFactory = new TemplateFactory();
    String name = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    try {
        Template template = templateFactory.createEndpointTemplate(elem, properties);
        if (template != null) {
            config.addEndpointTemplate(template.getName(), template);
        }
        return template;
    } catch (Exception e) {
        String msg = "Endpoint Template: " + name + "configuration cannot be built";
        handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_TEMPLATES, msg, e);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) TemplateFactory(org.apache.synapse.config.xml.endpoints.TemplateFactory) SynapseException(org.apache.synapse.SynapseException) Template(org.apache.synapse.endpoints.Template)

Example 3 with TemplateFactory

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

the class XMLToTemplateMapper method getObjectFromOMNode.

public Object getObjectFromOMNode(OMNode om, Properties properties) {
    if (!(om instanceof OMElement)) {
        throw new SynapseException("Configuration is not in proper format.");
    }
    OMElement elem = (OMElement) om;
    OMElement element = elem.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
    if (element != null) {
        return MediatorFactoryFinder.getInstance().getMediator(elem, properties);
    }
    element = elem.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
    if (element != null) {
        TemplateFactory templateFactory = new TemplateFactory();
        return templateFactory.createEndpointTemplate(elem, properties);
    }
    return null;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) TemplateFactory(org.apache.synapse.config.xml.endpoints.TemplateFactory)

Aggregations

TemplateFactory (org.apache.synapse.config.xml.endpoints.TemplateFactory)3 QName (javax.xml.namespace.QName)2 OMElement (org.apache.axiom.om.OMElement)2 SynapseException (org.apache.synapse.SynapseException)2 Template (org.apache.synapse.endpoints.Template)2 OMNode (org.apache.axiom.om.OMNode)1 XMLToTemplateMapper (org.apache.synapse.config.xml.XMLToTemplateMapper)1