try {
if (exprAttr != null) {
xpath = SynapseXPathFactory.getSynapseXPath(propElem, ATT_EXPRN);
}
} catch (JaxenException e) {
throw new MediatorException("Error in building the expression as an SynapseXPath" + e);
}
// if there is a value attribute there is no action (action is implied as read value)
if (valueAttr != null) {
String value = valueAttr.getAttributeValue();
// all other three attributes can not co-exists
if (exprAttr != null && ctxNameAttr != null) {
throw new MediatorException("Command properties can not contain all three 'value', " +
"'expression' and 'context-name' attributes. Only one or " +
"combination of two can be there.");
} else {
addStaticSetterProperty(name, value);
if (exprAttr != null) {
// action ==> ReadValueAndUpdateMesssage
addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
// action ==> ReadValueAndUpdateContext
addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
} // else the action ==> ReadValue
}
} else if (propElem.getFirstElement() != null) {
// all other two attributes can not co-exists
if (exprAttr != null && ctxNameAttr != null) {
throw new MediatorException("Command properties can not contain all the " +
"'expression' and 'context-name' attributes with a child. Only one " +
"attribute of those can co-exists with a child");
} else {
addStaticSetterProperty(name, propElem.getFirstElement());
if (exprAttr != null) {
// action ==> ReadValueAndUpdateMesssage
addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
// action ==> ReadValueAndUpdateContext
addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
} // else the action ==> ReadValue
}
} else {
// if both context-name and expression is there
if (exprAttr != null && ctxNameAttr != null) {
if (actionAttr != null && actionAttr.getAttributeValue() != null) {
String action = actionAttr.getAttributeValue();
if (RM_ACTION.equals(action) || UC_ACTION.equals(action)) {
// action ==> ReadMessageAndUpdateContext
addMessageSetterProperty(name, xpath);
addContextGetterProperty(name, ctxNameAttr.getAttributeValue());
} else if (RC_ACTION.equals(action) || UM_ACTION.equals(action)) {
// action ==> ReadContextAndUpdateMessage
addContextSetterProperty(name, ctxNameAttr.getAttributeValue());
addMessageGetterProperty(name, xpath);
} else {
throw new MediatorException("Invalid action for " +
"the command property with the name " + name);
}
} else {
throw new MediatorException("Action attribute " +
"is required for the command property with name " + name);
}
} else {
// only one of expression or context-name is present
if (actionAttr != null && actionAttr.getAttributeValue() != null) {
String action = actionAttr.getAttributeValue();
if (exprAttr != null) {
if (RM_ACTION.equals(action)) {
// action ==> ReadMessage
addMessageSetterProperty(name, xpath);
} else if (UM_ACTION.equals(action)) {
// action ==> UpdateMessage
addMessageGetterProperty(name, xpath);
} else if (RAUM_ACTION.equals(action)) {
// action ==> ReadAndUpdateMessage
addMessageSetterProperty(name, xpath);
addMessageGetterProperty(name, xpath);
} else {
throw new MediatorException("Invalid action for " +
"the command property with the name " + name);
}
} else if (ctxNameAttr != null) {
String ctxName = ctxNameAttr.getAttributeValue();
if (RC_ACTION.equals(action)) {
// action ==> ReadContext
addContextSetterProperty(name, ctxName);
} else if (UC_ACTION.equals(action)) {
// action ==> UpdateContext
addContextGetterProperty(name, ctxName);
} else if (RAUC_ACTION.equals(action)) {
// action ==> ReadAndUpdateContext
addContextSetterProperty(name, ctxName);
addContextGetterProperty(name, ctxName);
} else {
throw new MediatorException("Invalid action for " +
"the command property with the name " + name);
}
} else {
throw new MediatorException("Unrecognized command property with the name " + name);
}
} else {
// action ==> ReadAndUpdateMessage/Context
if (exprAttr != null) {
addMessageSetterProperty(name, xpath);
addMessageGetterProperty(name, xpath);
} else if (ctxNameAttr != null) {
String ctxName = ctxNameAttr.getAttributeValue();
addContextSetterProperty(name, ctxName);
addContextGetterProperty(name, ctxName);
} else {
throw new MediatorException("Unrecognized command property with the name " + name);
}
}
}
}
}