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 (Iterator itr = mediator.
getStaticSetterProperties().keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
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)) {
AXIOMXPath xpath = mediator.getMessageGetterProperties().get(propName);
prop.addAttribute(fac.createOMAttribute("expression", nullNS, xpath.toString()));
serializeNamespaces(prop, xpath);
}
pojoCommand.addChild(prop);
}
for (Iterator itr = mediator.
getMessageSetterProperties().keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
AXIOMXPath exprn = mediator.getMessageSetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
prop.addAttribute(fac.createOMAttribute("expression", nullNS, exprn.toString()));
serializeNamespaces(prop, exprn);
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 (Iterator itr = mediator.
getContextSetterProperties().keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
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)) {
AXIOMXPath exprn = mediator.getMessageGetterProperties().get(propName);
prop.addAttribute(fac.createOMAttribute("expression", nullNS, exprn.toString()));
serializeNamespaces(prop, exprn);
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
} else {
prop.addAttribute(fac.createOMAttribute("action", nullNS, "ReadContext"));
}
pojoCommand.addChild(prop);
}
for (Iterator itr = mediator.
getContextGetterProperties().keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
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 (Iterator itr = mediator.
getMessageGetterProperties().keySet().iterator(); itr.hasNext(); ) {
String propName = (String) itr.next();
if (!isSerialized(propName, mediator)) {
AXIOMXPath exprn = mediator.getMessageGetterProperties().get(propName);
OMElement prop = fac.createOMElement(PROP_Q);
prop.addAttribute(fac.createOMAttribute("name", nullNS, propName));
prop.addAttribute(fac.createOMAttribute("expression", nullNS,
exprn.toString()));
serializeNamespaces(prop, exprn);