use of org.apache.synapse.mediators.Value in project wso2-synapse by wso2.
the class InvokeMediatorFactory method buildParameters.
private void buildParameters(OMElement elem) {
Iterator subElements = elem.getChildElements();
while (subElements.hasNext()) {
OMElement child = (OMElement) subElements.next();
if (child.getQName().equals(WITH_PARAM_Q)) {
OMAttribute paramNameAttr = child.getAttribute(ATT_NAME);
Value paramValue = new ValueFactory().createValue("value", child);
if (paramNameAttr != null) {
// set parameter value
invoker.addExpressionForParamName(paramNameAttr.getAttributeValue(), paramValue);
}
}
}
}
use of org.apache.synapse.mediators.Value 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.mediators.Value in project wso2-synapse by wso2.
the class ScriptMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof ScriptMediator)) {
handleException("Unsupported mediator passed in for serialization : " + m.getType());
}
ScriptMediator scriptMediator = (ScriptMediator) m;
OMElement script = fac.createOMElement("script", synNS);
String language = scriptMediator.getLanguage();
Value key = scriptMediator.getKey();
String function = scriptMediator.getFunction();
ValueSerializer keySerializer = new ValueSerializer();
if (key != null) {
script.addAttribute(fac.createOMAttribute("language", nullNS, language));
// Serialize Value using ValueSerializer
keySerializer.serializeValue(key, XMLConfigConstants.KEY, script);
if (!function.equals("mediate")) {
script.addAttribute(fac.createOMAttribute("function", nullNS, function));
}
} else {
script.addAttribute(fac.createOMAttribute("language", nullNS, language));
OMTextImpl textData = (OMTextImpl) fac.createOMText(scriptMediator.getScriptSrc().trim());
textData.setType(XMLStreamConstants.CDATA);
script.addChild(textData);
}
Map<Value, Object> includeMap = scriptMediator.getIncludeMap();
for (Value includeKey : includeMap.keySet()) {
if (includeKey != null) {
OMElement includeKeyElement = fac.createOMElement("include", synNS);
// Serialize Value using ValueSerializer
keySerializer.serializeValue(includeKey, XMLConfigConstants.KEY, includeKeyElement);
script.addChild(includeKeyElement);
}
}
saveTracingState(script, scriptMediator);
return script;
}
use of org.apache.synapse.mediators.Value 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.mediators.Value in project wso2-synapse by wso2.
the class XQueryMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof XQueryMediator)) {
handleException("Invalid Mediator has passed to serializer");
}
XQueryMediator queryMediator = (XQueryMediator) m;
OMElement xquery = fac.createOMElement("xquery", synNS);
Value key = queryMediator.getQueryKey();
if (key != null) {
// Serialize Key using KeySerializer
ValueSerializer keySerializer = new ValueSerializer();
keySerializer.serializeValue(key, XMLConfigConstants.KEY, xquery);
}
saveTracingState(xquery, queryMediator);
SynapseXPath targetXPath = queryMediator.getTarget();
if (targetXPath != null && !SourceXPathSupport.DEFAULT_XPATH.equals(targetXPath.toString())) {
SynapseXPathSerializer.serializeXPath(targetXPath, xquery, "target");
}
List<MediatorProperty> pros = queryMediator.getProcessorProperties();
if (pros != null && !pros.isEmpty()) {
OMElement dataSource = fac.createOMElement("dataSource", synNS);
serializeProperties(dataSource, pros);
xquery.addChild(dataSource);
}
List list = queryMediator.getVariables();
if (list != null && !list.isEmpty()) {
for (Object o : list) {
if (o instanceof MediatorBaseVariable) {
MediatorBaseVariable variable = (MediatorBaseVariable) o;
QName name = variable.getName();
Object value = variable.getValue();
if (name != null && value != null) {
OMElement baseElement = fac.createOMElement("variable", synNS);
baseElement.addAttribute(fac.createOMAttribute("name", nullNS, name.getLocalPart()));
baseElement.addAttribute(fac.createOMAttribute("value", nullNS, (String) value));
String type = null;
ItemType variableType = variable.getType();
XdmNodeKind nodeKind = variable.getNodeKind();
if (ItemType.INT == variableType) {
type = "INT";
} else if (ItemType.INTEGER == variableType) {
type = "INTEGER";
} else if (ItemType.BOOLEAN == variableType) {
type = "BOOLEAN";
} else if (ItemType.BYTE == variableType) {
type = "BYTE";
} else if (ItemType.DOUBLE == variableType) {
type = "DOUBLE";
} else if (ItemType.SHORT == variableType) {
type = "SHORT";
} else if (ItemType.LONG == variableType) {
type = "LONG";
} else if (ItemType.FLOAT == variableType) {
type = "FLOAT";
} else if (ItemType.STRING == variableType) {
type = "STRING";
} else if (XdmNodeKind.DOCUMENT == nodeKind) {
type = "DOCUMENT";
} else if (XdmNodeKind.ELEMENT == nodeKind) {
type = "ELEMENT";
} else {
handleException("Unknown Type " + variableType);
}
if (type != null) {
baseElement.addAttribute(fac.createOMAttribute("type", nullNS, type));
}
xquery.addChild(baseElement);
}
} else if (o instanceof MediatorCustomVariable) {
MediatorCustomVariable variable = (MediatorCustomVariable) o;
QName name = variable.getName();
if (name != null) {
OMElement customElement = fac.createOMElement("variable", synNS);
customElement.addAttribute(fac.createOMAttribute("name", nullNS, name.getLocalPart()));
String regkey = variable.getRegKey();
if (regkey != null) {
customElement.addAttribute(fac.createOMAttribute("key", nullNS, regkey));
}
SynapseXPath expression = variable.getExpression();
if (expression != null && !SourceXPathSupport.DEFAULT_XPATH.equals(expression.toString())) {
SynapseXPathSerializer.serializeXPath(expression, customElement, "expression");
}
String type = null;
ItemType variableType = variable.getType();
XdmNodeKind nodeKind = variable.getNodeKind();
if (XdmNodeKind.DOCUMENT == nodeKind) {
type = "DOCUMENT";
} else if (XdmNodeKind.ELEMENT == nodeKind) {
type = "ELEMENT";
} else if (ItemType.INT == variableType) {
type = "INT";
} else if (ItemType.INTEGER == variableType) {
type = "INTEGER";
} else if (ItemType.BOOLEAN == variableType) {
type = "BOOLEAN";
} else if (ItemType.BYTE == variableType) {
type = "BYTE";
} else if (ItemType.DOUBLE == variableType) {
type = "DOUBLE";
} else if (ItemType.SHORT == variableType) {
type = "SHORT";
} else if (ItemType.LONG == variableType) {
type = "LONG";
} else if (ItemType.FLOAT == variableType) {
type = "FLOAT";
} else if (ItemType.STRING == variableType) {
type = "STRING";
} else {
handleException("Unknown Type " + variableType);
}
if (type != null) {
customElement.addAttribute(fac.createOMAttribute("type", nullNS, type));
}
xquery.addChild(customElement);
}
}
}
}
return xquery;
}
Aggregations