use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.
the class MediatorFactoryFinder method getMediator.
/**
* This method returns a Processor given an OMElement. This will be used
* recursively by the elements which contain processor elements themselves
* (e.g. rules)
*
* @param element XML representation of a mediator
* @param properties bag of properties to pass in any information to the factory
* @return Processor
*/
public Mediator getMediator(OMElement element, Properties properties) {
String localName = element.getLocalName();
QName qName;
if (element.getNamespace() != null) {
qName = new QName(element.getNamespace().getNamespaceURI(), localName);
} else {
qName = new QName(localName);
}
if (log.isDebugEnabled()) {
log.debug("getMediator(" + qName + ")");
}
Class cls = factoryMap.get(qName);
if (cls == null && localName.indexOf('.') > -1) {
String newLocalName = localName.substring(0, localName.indexOf('.'));
qName = new QName(element.getNamespace().getNamespaceURI(), newLocalName);
if (log.isDebugEnabled()) {
log.debug("getMediator.2(" + qName + ")");
}
cls = factoryMap.get(qName);
}
if (cls == null) {
if (synapseLibraryMap != null && !synapseLibraryMap.isEmpty()) {
for (Map.Entry<String, Library> entry : synapseLibraryMap.entrySet()) {
if (entry.getValue().getLibArtifactDetails().containsKey(localName)) {
return getDynamicInvokeMediator(element, entry.getValue().getPackage());
}
}
}
if (!synapseImportMap.isEmpty()) {
for (Map.Entry<String, SynapseImport> entry : synapseImportMap.entrySet()) {
if (localName.startsWith(entry.getValue().getLibName())) {
return getDynamicInvokeMediator(element, entry.getValue().getLibPackage());
}
}
}
String msg = "Unknown mediator referenced by configuration element : " + qName;
log.error(msg);
throw new SynapseException(msg);
}
try {
MediatorFactory mf = (MediatorFactory) cls.newInstance();
return mf.createMediator(element, properties);
} catch (InstantiationException e) {
String msg = "Error initializing mediator factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
} catch (IllegalAccessException e) {
String msg = "Error initializing mediator factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
}
}
use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.
the class SynapseImportSerializer method serializeImport.
/**
* This method will implements the serialization of SynapseImport object to its configuration
*
* @param s the type SynapseImport which is subjected to the serialization
* @return OMElement serialized in to xml from the given parameters
*/
public static OMElement serializeImport(SynapseImport s) {
if (!(s instanceof SynapseImport)) {
handleException("Unsupported Synapse Import passed in for serialization");
}
SynapseImport synapseImport = (SynapseImport) s;
OMElement importElem = fac.createOMElement("import", synNS);
if (synapseImport.getLibName() != null) {
importElem.addAttribute(fac.createOMAttribute("name", nullNS, s.getLibName()));
} else {
handleException("Invalid Synapse Import. Target Library name is required");
}
if (synapseImport.getLibPackage() != null) {
importElem.addAttribute(fac.createOMAttribute("package", nullNS, s.getLibPackage()));
} else {
handleException("Invalid Synapse Import. Target Library package is required");
}
if (synapseImport.isStatus()) {
importElem.addAttribute(fac.createOMAttribute("status", nullNS, "enabled"));
} else {
importElem.addAttribute(fac.createOMAttribute("status", nullNS, "disabled"));
}
return importElem;
}
use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.
the class SynapseImportFactory method createImport.
@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseImport createImport(OMElement elem, Properties properties) {
OMAttribute pkgAtt = elem.getAttribute(PACKAGE_Q);
SynapseImport synapseImport = new SynapseImport();
OMAttribute nameAtt = elem.getAttribute(NAME_Q);
if (nameAtt != null) {
synapseImport.setLibName(nameAtt.getAttributeValue());
} else {
handleException("Synapse Import Target Library name is not specified");
}
if (pkgAtt != null) {
synapseImport.setLibPackage(pkgAtt.getAttributeValue());
} else {
handleException("Synapse Import Target Library package is not specified");
}
OMAttribute status = elem.getAttribute(STATUS_Q);
if (status != null && status.getAttributeValue().equals("enabled")) {
synapseImport.setStatus(true);
} else {
synapseImport.setStatus(false);
}
log.info("Successfully created Synapse Import: " + nameAtt.getAttributeValue());
return synapseImport;
}
use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.
the class SynapseImportSerializerTest method testSerializeImportDisabled.
/**
* Test SerializeImport with valid synapseImport, status disabled.
*/
@Test
public void testSerializeImportDisabled() {
SynapseImport synapseImport = new SynapseImport();
synapseImport.setLibName("testLibName");
synapseImport.setLibPackage("testVersion");
OMElement element = SynapseImportSerializer.serializeImport(synapseImport);
Assert.assertEquals("asserting OMElement name", "import", element.getLocalName());
OMAttribute temp = element.getAttribute(new QName("name"));
Assert.assertEquals("asserting name attribute", "testLibName", temp.getAttributeValue());
temp = element.getAttribute(new QName("package"));
Assert.assertEquals("asserting package attribute", "testVersion", temp.getAttributeValue());
temp = element.getAttribute(new QName("status"));
Assert.assertEquals("asserting status attribute", "disabled", temp.getAttributeValue());
}
use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.
the class SynapseImportSerializerTest method testSerializeImportNoLibPackage.
/**
* Test serializeImport with incomplete synapseImport.
*/
@Test
public void testSerializeImportNoLibPackage() {
SynapseImport synapseImport = new SynapseImport();
synapseImport.setLibName("testLibName");
thrown.expect(SynapseException.class);
thrown.expectMessage("Invalid Synapse Import. Target Library package is required");
SynapseImportSerializer.serializeImport(synapseImport);
}
Aggregations