use of org.apache.synapse.mediators.ext.POJOCommandMediator in project wso2-synapse by wso2.
the class POJOCommandMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof POJOCommandMediator)) {
handleException("Unsupported mediator passed in for serialization : " + m.getType());
}
POJOCommandMediator mediator = (POJOCommandMediator) m;
OMElement pojoCommand = fac.createOMElement("pojoCommand", synNS);
saveTracingState(pojoCommand, mediator);
if (mediator.getCommand() != null && mediator.getCommand().getClass().getName() != null) {
pojoCommand.addAttribute(fac.createOMAttribute("name", nullNS, mediator.getCommand().getName()));
} else {
handleException("Invalid POJO Command mediator. The command class name is required");
}
for (String propName : mediator.getStaticSetterProperties().keySet()) {
Object value = mediator.getStaticSetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
if (value instanceof String) {
prop.addAttribute(fac.createOMAttribute("value", nullNS, (String) value));
} else if (value instanceof OMElement) {
prop.addChild((OMElement) value);
} else {
handleException("Unable to serialize the command " + "mediator property with the naem " + propName + " : Unknown type");
}
if (mediator.getContextGetterProperties().containsKey(propName)) {
prop.addAttribute(fac.createOMAttribute("context-name", nullNS, mediator.getContextGetterProperties().get(propName)));
} else if (mediator.getMessageGetterProperties().containsKey(propName)) {
SynapseXPathSerializer.serializeXPath(mediator.getMessageGetterProperties().get(propName), prop, "expression");
}
pojoCommand.addChild(prop);
}
for (String propName : mediator.getMessageSetterProperties().keySet()) {
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
SynapseXPathSerializer.serializeXPath(mediator.getMessageSetterProperties().get(propName), prop, "expression");
if (mediator.getMessageGetterProperties().containsKey(propName)) {
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadAndUpdateMessage"));
} else if (mediator.getContextGetterProperties().containsKey(propName)) {
prop.addAttribute(fac.createOMAttribute("context-name", nullNS, mediator.getContextGetterProperties().get(propName)));
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadMessage"));
} else {
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadMessage"));
}
pojoCommand.addChild(prop);
}
for (String propName : mediator.getContextSetterProperties().keySet()) {
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
prop.addAttribute(fac.createOMAttribute("context-name", nullNS, mediator.getContextSetterProperties().get(propName)));
if (mediator.getContextGetterProperties().containsKey(propName)) {
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadAndUpdateContext"));
} else if (mediator.getMessageGetterProperties().containsKey(propName)) {
SynapseXPathSerializer.serializeXPath(mediator.getMessageGetterProperties().get(propName), prop, "expression");
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
} else {
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
}
pojoCommand.addChild(prop);
}
for (String propName : mediator.getContextGetterProperties().keySet()) {
if (!isSerialized(propName, mediator)) {
String value = mediator.getContextGetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
prop.addAttribute(fac.createOMAttribute("context-name", nullNS, value));
prop.addAttribute(fac.createOMAttribute("action", nullNS, "UpdateContext"));
pojoCommand.addChild(prop);
}
}
for (String propName : mediator.getMessageGetterProperties().keySet()) {
if (!isSerialized(propName, mediator)) {
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
SynapseXPathSerializer.serializeXPath(mediator.getMessageGetterProperties().get(propName), prop, "expression");
prop.addAttribute(fac.createOMAttribute("action", nullNS, "UpdateMessage"));
pojoCommand.addChild(prop);
}
}
return pojoCommand;
}
use of org.apache.synapse.mediators.ext.POJOCommandMediator in project wso2-synapse by wso2.
the class POJOCommandMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
POJOCommandMediator pojoMediator = new POJOCommandMediator();
processAuditStatus(pojoMediator, elem);
// Class name of the Command object should be present
OMAttribute name = elem.getAttribute(ATT_NAME);
if (name == null) {
String msg = "The name of the actual POJO command implementation class" + " is a required attribute";
log.error(msg);
throw new SynapseException(msg);
}
// load the class for the command object
try {
pojoMediator.setCommand(getClass().getClassLoader().loadClass(name.getAttributeValue()));
} catch (ClassNotFoundException e) {
handleException("Unable to load the class specified as the command " + name.getAttributeValue(), e);
}
// at the mediation time
for (Iterator it = elem.getChildElements(); it.hasNext(); ) {
OMElement child = (OMElement) it.next();
if ("property".equals(child.getLocalName())) {
OMAttribute nameAttr = child.getAttribute(ATT_NAME);
if (nameAttr != null && nameAttr.getAttributeValue() != null && !"".equals(nameAttr.getAttributeValue())) {
handlePropertyAction(nameAttr.getAttributeValue(), child, pojoMediator);
} else {
handleException("A POJO command mediator " + "property must specify the name attribute");
}
}
}
return pojoMediator;
}
Aggregations