Search in sources :

Example 1 with ItemType

use of net.sf.saxon.s9api.ItemType 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;
}
Also used : XdmNodeKind(net.sf.saxon.s9api.XdmNodeKind) SynapseXPath(org.apache.synapse.util.xpath.SynapseXPath) QName(javax.xml.namespace.QName) ItemType(net.sf.saxon.s9api.ItemType) OMElement(org.apache.axiom.om.OMElement) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) Value(org.apache.synapse.mediators.Value) List(java.util.List) ValueSerializer(org.apache.synapse.config.xml.ValueSerializer)

Aggregations

List (java.util.List)1 QName (javax.xml.namespace.QName)1 ItemType (net.sf.saxon.s9api.ItemType)1 XdmNodeKind (net.sf.saxon.s9api.XdmNodeKind)1 OMElement (org.apache.axiom.om.OMElement)1 ValueSerializer (org.apache.synapse.config.xml.ValueSerializer)1 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)1 Value (org.apache.synapse.mediators.Value)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1