protected static void addChildren(OMElement el, ListMediator m, Properties properties) { Iterator it = el.getChildElements(); while (it.hasNext()) { OMElement child = (OMElement) it.next(); if (!DESCRIPTION_Q.equals(child.getQName())) { // neglect the description tag Mediator med = MediatorFactoryFinder.getInstance().getMediator(child, properties); if (med != null) { m.addChild(med); } else { String msg = "Unknown mediator : " + child.getLocalName(); log.error(msg); throw new SynapseException(msg); } } } } }
public static void main(String[] args) throws Exception{ String connectorStr = "<sfdc.getContact xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "\t\t <parameter name=\"param1\" value=\"val1\"/>\n" + "\t\t <parameter name=\"param2\" value=\"val2\"/>\n" + "\t</sfdc.getContact>"; OMElement inConnectorElem = AXIOMUtil.stringToOM(connectorStr); String libName = "synapse.lang.eip"; InvokeMediator invokeMediator = MediatorFactoryFinder.getInstance().getDynamicInvokeMediator(inConnectorElem, libName); invokeMediator.getTargetTemplate(); }
/** * Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators * (i.e. Sequence Mediator) loaded dynamically from a Registry * @param om node from which the object is expected * @return Object buit from the om node */ public Object getObjectFromOMNode(OMNode om, Properties properties) { if (om instanceof OMElement) { return getMediator((OMElement) om, properties); } else { handleException("Invalid mediator configuration XML : " + om); } return null; }
public static Mediator defineSequence(SynapseConfiguration config, OMElement ele, Properties properties) { Mediator mediator = null; String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")); if (name != null) { try { MediatorFactoryFinder.getInstance().setSynapseImportMap(config.getSynapseImports()); mediator = MediatorFactoryFinder.getInstance().getMediator(ele, properties); if (mediator != null) { config.addSequence(name, mediator); // mandatory sequence is treated as a special sequence because it will be fetched for // each and every message and keeps a direct reference to that from the configuration // this also limits the ability of the mandatory sequence to be dynamic if (SynapseConstants.MANDATORY_SEQUENCE_KEY.equals(name)) { config.setMandatorySequence(mediator); } } } catch (Exception e) { String msg = "Sequence configuration: " + name + " cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_SEQUENCES, msg, e); } return mediator; } else { String msg = "Invalid sequence definition without a name"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_SEQUENCES, msg); } return null; }
MediatorFactoryFinder.getInstance().setSynapseLibraryMap(getSynapseConfiguration().getSynapseLibraries()); Mediator m = MediatorFactoryFinder.getInstance().getMediator( artifactConfig, properties); if (m instanceof SequenceMediator) {
entry.setMapper(MediatorFactoryFinder.getInstance()); return (Mediator) o; } else if (o instanceof OMNode) { Mediator m = (Mediator) MediatorFactoryFinder.getInstance(). getObjectFromOMNode((OMNode) o, properties); if (m != null) { entry.setValue(m);
QName tagQName = factory.getTagQName(); Class<? extends MediatorFactory> clazz = factory.getClass(); MediatorFactoryFinder.getInstance().getFactoryMap().put(tagQName, clazz); log.info("Registered mediator factory " + clazz.getName() + " for " + tagQName);
entry.setMapper(MediatorFactoryFinder.getInstance()); } else if (key.getType().equals(ENDPOINT)) { entry.setMapper(XMLToEndpointMapper.getInstance());
private static void loadMediatorFactories() { for (Class c : mediatorFactories) { try { MediatorFactory fac = (MediatorFactory) c.newInstance(); factoryMap.put(fac.getTagQName(), c); } catch (Exception e) { throw new SynapseException("Error instantiating " + c.getName(), e); } } // now iterate through the available pluggable mediator factories registerExtensions(); initialized = true; }
public static synchronized MediatorFactoryFinder getInstance() { if (!initialized) { loadMediatorFactories(); } return instance; }
for (Map.Entry<String, Library> entry : synapseLibraryMap.entrySet()) { if (entry.getValue().getLibArtifactDetails().containsKey(localName)) { return getDynamicInvokeMediator(element, entry.getValue().getPackage()); for (Map.Entry<String, SynapseImport> entry : synapseImportMap.entrySet()) { if (localName.startsWith(entry.getValue().getLibName())) { return getDynamicInvokeMediator(element, entry.getValue().getLibPackage());
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; }
entry.setMapper(MediatorFactoryFinder.getInstance()); return (Mediator) o; } else if (o instanceof OMNode) { Mediator m = (Mediator) MediatorFactoryFinder.getInstance(). getObjectFromOMNode((OMNode) o, properties); if (m != null) { entry.setValue(m);
QName tagQName = factory.getTagQName(); Class<? extends MediatorFactory> clazz = factory.getClass(); MediatorFactoryFinder.getInstance().getFactoryMap().put(tagQName, clazz); log.info("Registered mediator factory " + clazz.getName() + " for " + tagQName);
/** * Return the format of the payload factory specified by the given key * @param key * @return OMElement */ public OMElement getFormat(String key) { Object o = localRegistry.get(key); if (o != null && o instanceof OMElement) { return (OMElement) o; } Entry entry = new Entry(key); entry.setType(Entry.REMOTE_ENTRY); assertEntryNull(entry, key); //noinspection ConstantConditions if (entry.getMapper() == null) { entry.setMapper(MediatorFactoryFinder.getInstance()); } if (registry != null) { o = registry.getFormat(entry); if (o instanceof OMElement) { localRegistry.put(key, o); return (OMElement) o; } } return null; }
private static void loadMediatorFactories() { for (Class c : mediatorFactories) { try { MediatorFactory fac = (MediatorFactory) c.newInstance(); factoryMap.put(fac.getTagQName(), c); } catch (Exception e) { throw new SynapseException("Error instantiating " + c.getName(), e); } } // now iterate through the available pluggable mediator factories registerExtensions(); initialized = true; }
public static synchronized MediatorFactoryFinder getInstance() { if (!initialized) { loadMediatorFactories(); } return instance; }
public static Mediator defineMediatorTemplate(SynapseConfiguration config, OMElement ele, Properties properties) { Mediator mediator = null; String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name")); if (name != null) { try { mediator = MediatorFactoryFinder.getInstance().getMediator(ele, properties); if (mediator != null) { config.addSequenceTemplate(name, (TemplateMediator) mediator) ; } } catch (Exception e) { String msg = "Template configuration: " + name + " cannot be built"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_TEMPLATES, msg, e); } return mediator; } else { String msg = "Invalid mediation template definition without a name"; handleConfigurationError(SynapseConstants.FAIL_SAFE_MODE_TEMPLATES, msg); } return null; }
entry.setMapper(MediatorFactoryFinder.getInstance()); return (Mediator) o; } else if (o instanceof OMNode) { Mediator m = (Mediator) MediatorFactoryFinder.getInstance(). getObjectFromOMNode((OMNode) o, properties); if (m != null) { entry.setValue(m);
/** * Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators * (i.e. Sequence Mediator) loaded dynamically from a Registry * @param om node from which the object is expected * @return Object buit from the om node */ public Object getObjectFromOMNode(OMNode om, Properties properties) { if (om instanceof OMElement) { return getMediator((OMElement) om, properties); } else { handleException("Invalid mediator configuration XML : " + om); } return null; }