Search in sources :

Example 1 with ValueSerializer

use of org.apache.synapse.config.xml.ValueSerializer 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;
}
Also used : Value(org.apache.synapse.mediators.Value) OMTextImpl(org.apache.axiom.om.impl.llom.OMTextImpl) OMElement(org.apache.axiom.om.OMElement) ValueSerializer(org.apache.synapse.config.xml.ValueSerializer)

Example 2 with ValueSerializer

use of org.apache.synapse.config.xml.ValueSerializer 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)

Example 3 with ValueSerializer

use of org.apache.synapse.config.xml.ValueSerializer in project wso2-synapse by wso2.

the class RecipientListEndpointSerializer method serializeEndpoint.

@Override
protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof RecipientListEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) endpoint;
    // serialize the parameters
    serializeProperties(recipientListEndpoint, endpointElement);
    serializeCommonAttributes(endpoint, endpointElement);
    OMElement recipientListElement = fac.createOMElement("recipientlist", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(recipientListElement);
    // element
    if (recipientListEndpoint.getChildren() != null) {
        for (Endpoint childEndpoint : recipientListEndpoint.getChildren()) {
            recipientListElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
        }
    } else if (recipientListEndpoint.getMembers() != null) {
        for (Member member : recipientListEndpoint.getMembers()) {
            OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
            memberEle.addAttribute(fac.createOMAttribute("hostName", null, member.getHostName()));
            memberEle.addAttribute(fac.createOMAttribute("httpPort", null, String.valueOf(member.getHttpPort())));
            memberEle.addAttribute(fac.createOMAttribute("httpsPort", null, String.valueOf(member.getHttpsPort())));
            recipientListElement.addChild(memberEle);
        }
    } else {
        OMElement dynamicEpEle = fac.createOMElement("endpoints", SynapseConstants.SYNAPSE_OMNAMESPACE, recipientListElement);
        new ValueSerializer().serializeValue(recipientListEndpoint.getDynamicEnpointSet(), "value", dynamicEpEle);
        dynamicEpEle.addAttribute(fac.createOMAttribute("max-cache", null, String.valueOf(recipientListEndpoint.getCurrentPoolSize())));
        recipientListElement.addChild(dynamicEpEle);
    }
    return endpointElement;
}
Also used : RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) OMElement(org.apache.axiom.om.OMElement) Member(org.apache.axis2.clustering.Member) ValueSerializer(org.apache.synapse.config.xml.ValueSerializer)

Aggregations

OMElement (org.apache.axiom.om.OMElement)3 ValueSerializer (org.apache.synapse.config.xml.ValueSerializer)3 Value (org.apache.synapse.mediators.Value)2 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 OMTextImpl (org.apache.axiom.om.impl.llom.OMTextImpl)1 Member (org.apache.axis2.clustering.Member)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 RecipientListEndpoint (org.apache.synapse.endpoints.RecipientListEndpoint)1 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)1 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)1