use of org.apache.synapse.config.xml.ValueFactory in project wso2-synapse by wso2.
the class ScriptMediatorFactory method getIncludeKeysMap.
private Map<Value, Object> getIncludeKeysMap(OMElement elem) {
// get <include /> scripts
// map key = registry entry key, value = script source
// at this time map values are null, later loaded
// from void ScriptMediator.prepareExternalScript(MessageContext synCtx)
// TreeMap used to keep given scripts order if needed
Map<Value, Object> includeKeysMap = new LinkedHashMap<Value, Object>();
Iterator itr = elem.getChildrenWithName(INCLUDE_Q);
while (itr.hasNext()) {
OMElement includeElem = (OMElement) itr.next();
OMAttribute key = includeElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
// ValueFactory for creating dynamic or static Value
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, includeElem);
if (key == null) {
throw new SynapseException("Cannot use 'include' element without 'key'" + " attribute for a script mediator");
}
includeKeysMap.put(generatedKey, null);
}
return includeKeysMap;
}
use of org.apache.synapse.config.xml.ValueFactory in project wso2-synapse by wso2.
the class XQueryMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
XQueryMediator xQueryMediator = new XQueryMediator();
OMAttribute xqueryKey = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
OMAttribute attrTarget = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "target"));
if (xqueryKey != null) {
// KeyFactory for creating dynamic or static Key
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
if (generatedKey != null) {
// set generated key as the Key
xQueryMediator.setQueryKey(generatedKey);
} else {
handleException("The 'key' attribute is required for the XQuery mediator");
}
} else {
handleException("The 'key' attribute is required for the XQuery mediator");
}
if (attrTarget != null) {
String targetValue = attrTarget.getAttributeValue();
if (targetValue != null && !"".equals(targetValue)) {
try {
xQueryMediator.setTarget(SynapseXPathFactory.getSynapseXPath(elem, ATT_TARGET));
} catch (JaxenException e) {
handleException("Invalid XPath specified for the target attribute : " + targetValue);
}
}
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(xQueryMediator, elem);
OMElement dataSource = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "dataSource"));
if (dataSource != null) {
xQueryMediator.addAllDataSourceProperties(MediatorPropertyFactory.getMediatorProperties(dataSource));
}
Iterator it = elem.getChildrenWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "variable"));
while (it.hasNext()) {
OMElement variableOM = (OMElement) it.next();
String name = variableOM.getAttributeValue(ATT_NAME_Q);
if (name != null && !"".equals(name)) {
String type = variableOM.getAttributeValue(ATT_TYPE_Q);
if (type != null && !"".equals(type)) {
String value = variableOM.getAttributeValue(ATT_VALUE_Q);
MediatorVariable variable;
if (value != null && !"".equals(value)) {
variable = new MediatorBaseVariable(new QName(name.trim()));
variable.setValue(value.trim());
} else {
String key = variableOM.getAttributeValue(ATT_KEY_Q);
String expr = variableOM.getAttributeValue(ATT_EXPR_Q);
variable = new MediatorCustomVariable(new QName(name.trim()));
if (key != null) {
((MediatorCustomVariable) variable).setRegKey(key.trim());
}
if (expr != null && !"".equals(expr)) {
try {
SynapseXPath xpath = new SynapseXPath(expr);
OMElementUtils.addNameSpaces(xpath, variableOM, log);
((MediatorCustomVariable) variable).setExpression(xpath);
} catch (JaxenException e) {
handleException("Invalid XPath specified for" + " the expression attribute : " + expr);
}
}
}
if ("INT".equals(type.trim())) {
variable.setType(ItemType.INT);
} else if ("INTEGER".equals(type.trim())) {
variable.setType(ItemType.INTEGER);
} else if ("BOOLEAN".equals(type.trim())) {
variable.setType(ItemType.BOOLEAN);
} else if ("BYTE".equals(type.trim())) {
variable.setType(ItemType.BYTE);
} else if ("DOUBLE".equals(type.trim())) {
variable.setType(ItemType.DOUBLE);
} else if ("SHORT".equals(type.trim())) {
variable.setType(ItemType.SHORT);
} else if ("LONG".equals(type.trim())) {
variable.setType(ItemType.LONG);
} else if ("FLOAT".equals(type.trim())) {
variable.setType(ItemType.FLOAT);
} else if ("STRING".equals(type.trim())) {
variable.setType(ItemType.STRING);
} else if ("DOCUMENT".equals(type.trim())) {
variable.setNodeKind(XdmNodeKind.DOCUMENT);
} else if ("ELEMENT".equals(type.trim())) {
variable.setNodeKind(XdmNodeKind.ELEMENT);
} else {
handleException("Unsupported Type");
}
xQueryMediator.addVariable(variable);
}
}
}
return xQueryMediator;
}
use of org.apache.synapse.config.xml.ValueFactory in project wso2-synapse by wso2.
the class RecipientListEndpointFactory method createEndpoint.
@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
OMElement recipientListElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
if (recipientListElement != null) {
// create endpoint
RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
// set endpoint name
OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
// set endpoints or members
if (recipientListElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
if (recipientListElement.getChildrenWithName((MEMBER)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Endpoint> endpoints = getEndpoints(recipientListElement, recipientListEndpoint, properties);
recipientListEndpoint.setChildren(endpoints);
} else if (recipientListElement.getFirstChildWithName(MEMBER) != null) {
if (recipientListElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
String msg = "Invalid Synapse configuration. " + "recipientListElement element cannot have both member & endpoint " + "child elements";
log.error(msg);
throw new SynapseException(msg);
}
List<Member> members = getMembers(recipientListElement);
recipientListEndpoint.setMembers(members);
} else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) {
OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET);
Value dynamicEndpointSet = new ValueFactory().createValue("value", dynamicSetElement);
String maxStr = dynamicSetElement.getAttributeValue(new QName("max-cache"));
int maxCache = -1;
try {
maxCache = Integer.parseInt(maxStr);
} catch (NumberFormatException e) {
}
recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache);
if (name != null) {
recipientListEndpoint.setName(name.getAttributeValue());
}
recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet);
}
if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) {
String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements.";
log.error(msg);
throw new SynapseException(msg);
}
// process the parameters
processProperties(recipientListEndpoint, epConfig);
return recipientListEndpoint;
}
return null;
}
use of org.apache.synapse.config.xml.ValueFactory in project wso2-synapse by wso2.
the class TemplateMessageExecutor method buildParameters.
private void buildParameters(OMElement elem) {
Iterator subElements = elem.getChildElements();
while (subElements.hasNext()) {
OMElement child = (OMElement) subElements.next();
Value paramValue = new ValueFactory().createTextValue(child);
invoker.addExpressionForParamName(child.getLocalName(), paramValue);
}
}
use of org.apache.synapse.config.xml.ValueFactory in project wso2-synapse by wso2.
the class ScriptMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
ScriptMediator mediator;
ClassLoader classLoader = (ClassLoader) properties.get(SynapseConstants.SYNAPSE_LIB_LOADER);
OMAttribute keyAtt = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
OMAttribute langAtt = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "language"));
OMAttribute functionAtt = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "function"));
if (langAtt == null) {
throw new SynapseException("The 'language' attribute is required for" + " a script mediator");
// TODO: couldn't this be determined from the key in some scenarios?
}
if (keyAtt == null && functionAtt != null) {
throw new SynapseException("Cannot use 'function' attribute without 'key' " + "attribute for a script mediator");
}
Map<Value, Object> includeKeysMap = getIncludeKeysMap(elem);
if (keyAtt != null) {
// ValueFactory for creating dynamic or static Key
ValueFactory keyFac = new ValueFactory();
// create dynamic or static key based on OMElement
Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, elem);
String functionName = (functionAtt == null ? null : functionAtt.getAttributeValue());
mediator = new ScriptMediator(langAtt.getAttributeValue(), includeKeysMap, generatedKey, functionName, classLoader);
} else {
mediator = new ScriptMediator(langAtt.getAttributeValue(), elem.getText(), classLoader);
}
processAuditStatus(mediator, elem);
return mediator;
}
Aggregations