private static final QName SEQUENCE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "RMSequence");
public Mediator createMediator(OMElement elem) {
RMSequenceMediator sequenceMediator = new RMSequenceMediator();
OMAttribute correlation =
elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "correlation"));
OMAttribute lastMessage =
elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "last-message"));
OMAttribute single = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "single"));
OMAttribute version = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "version"));
if (single == null && correlation == null) {
String msg = "The 'single' attribute value of true or a 'correlation' attribute is " +
"required for the configuration of a RMSequence mediator";
log.error(msg);
throw new SynapseException(msg);
}
if (correlation != null) {
if (correlation.getAttributeValue() != null &&
correlation.getAttributeValue().trim().length() == 0) {
String msg = "Invalid attribute value specified for correlation";
log.error(msg);
throw new SynapseException(msg);
} else {
try {
sequenceMediator.setCorrelation(new AXIOMXPath(correlation.getAttributeValue()));
} catch (JaxenException e) {
String msg = "Invalid XPath expression for attribute correlation : "
+ correlation.getAttributeValue();
log.error(msg);
throw new SynapseException(msg);
}
}
OMElementUtils.addNameSpaces(sequenceMediator.getCorrelation(), elem, log);
}
if (single != null) {
sequenceMediator.setSingle(Boolean.valueOf(single.getAttributeValue()));
}
if (sequenceMediator.isSingle() && sequenceMediator.getCorrelation() != null) {
String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
+ "single attribute value of true and a correlation attribute specified.";
log.error(msg);
throw new SynapseException(msg);
} else if (!sequenceMediator.isSingle() && sequenceMediator.getCorrelation() == null) {
String msg = "Invalid RMSequence mediator. A RMSequence must have a "
+ "single attribute value of true or a correlation attribute specified.";
log.error(msg);
throw new SynapseException(msg);
}
if (lastMessage != null) {
if (lastMessage.getAttributeValue() != null &&
lastMessage.getAttributeValue().trim().length() == 0) {
String msg = "Invalid attribute value specified for last-message";
log.error(msg);
throw new SynapseException(msg);
} else {
try {
sequenceMediator.setLastMessage(new AXIOMXPath(lastMessage.getAttributeValue()));
} catch (JaxenException e) {
String msg = "Invalid XPath expression for attribute last-message : "
+ lastMessage.getAttributeValue();
log.error(msg);
throw new SynapseException(msg);
}
}
OMElementUtils.addNameSpaces(sequenceMediator.getLastMessage(), elem, log);
}
if (sequenceMediator.isSingle() && sequenceMediator.getLastMessage() != null) {
String msg = "Invalid RMSequence mediator. A RMSequence can't have both a "
+ "single attribute value of true and a last-message attribute specified.";
log.error(msg);
throw new SynapseException(msg);
}
if (version != null) {
if (!Constants.SEQUENCE_VERSION_1_0.equals(version.getAttributeValue()) &&
!Constants.SEQUENCE_VERSION_1_1.equals(version.getAttributeValue())) {
String msg = "Only '" + Constants.SEQUENCE_VERSION_1_0 + "' or '" +
Constants.SEQUENCE_VERSION_1_1
+ "' values are allowed for attribute version for a RMSequence mediator"
+ ", Unsupported version " + version.getAttributeValue();
log.error(msg);
throw new SynapseException(msg);
}
sequenceMediator.setVersion(version.getAttributeValue());
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
initMediator(sequenceMediator, elem);