123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- ##############################################################################
- # HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems.
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- ##############################################################################
- -->
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
- <xsl:template match="esxdl">
- <xsl:variable name="servicename"><xsl:value-of select="EsdlService/@name"/></xsl:variable>
- <xsl:variable name="servicebase"><xsl:value-of select="$servicename"/>ServiceBase</xsl:variable>
- #include "<xsl:value-of select="$servicename"/>ServiceBase.hpp"
- #include "jliball.hpp"
- #include "jlog.hpp"
- #include "jptree.hpp"
- <xsl:apply-templates select="EsdlService"/>
- </xsl:template>
- <xsl:template name="outputCppPrimitive">
- <xsl:param name="typename"/>
- <xsl:choose>
- <xsl:when test="$typename='bool'"><xsl:value-of select="'Boolean'"/></xsl:when>
- <xsl:when test="$typename='boolean'"><xsl:value-of select="'Boolean'"/></xsl:when>
- <xsl:when test="$typename='decimal'"><xsl:value-of select="'Double'"/></xsl:when>
- <xsl:when test="$typename='float'"><xsl:value-of select="'Float'"/></xsl:when>
- <xsl:when test="$typename='double'"><xsl:value-of select="'Double'"/></xsl:when>
- <xsl:when test="$typename='integer'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='int64'"><xsl:value-of select="'Integer64'"/></xsl:when>
- <xsl:when test="$typename='uint64'"><xsl:value-of select="'Integer64'"/></xsl:when>
- <xsl:when test="$typename='long'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='int'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='short'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='nonPositiveInteger'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='negativeInteger'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='nonNegativeInteger'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='unsigned'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='unsignedLong'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='unsignedInt'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='unsignedShort'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='unsignedByte'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='positiveInteger'"><xsl:value-of select="'Integer'"/></xsl:when>
- <xsl:when test="$typename='base64Binary'"><xsl:value-of select="'PString'"/></xsl:when>
- <xsl:when test="$typename='string'"><xsl:value-of select="'PString'"/></xsl:when>
- <xsl:when test="$typename='xsdString'"><xsl:value-of select="'PString'"/></xsl:when>
- <xsl:when test="$typename='normalizedString'"><xsl:value-of select="'PString'"/></xsl:when>
- <xsl:when test="$typename='binary'"><xsl:value-of select="'PString'"/></xsl:when>
- <xsl:otherwise><xsl:value-of select="$typename"/></xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="EsdlService">
- <xsl:variable name="servicename" select="@name"/>
- <xsl:variable name="servicebase"><xsl:value-of select="$servicename"/>ServiceBase</xsl:variable>
- <xsl:for-each select="EsdlMethod">
- <xsl:text>extern "C" int on</xsl:text><xsl:value-of select="../@name"/><xsl:value-of select="@name"/>(const char* CtxStr, const char* ReqStr, StringBuffer& RespStr)
- {
- Owned<<xsl:value-of select="$servicebase"/>> service = create<xsl:value-of select="$servicename"/>ServiceObj();
- return service-><xsl:value-of select="@name"/><xsl:text>(CtxStr, ReqStr, RespStr);
- }
- </xsl:text>
- </xsl:for-each>
- <xsl:text>
- class </xsl:text><xsl:value-of select="$servicename"/>UnSerializer : public CInterface, implements IInterface
- {
- public:
- IMPLEMENT_IINTERFACE;
- <xsl:value-of select="$servicename"/>UnSerializer()
- {
- }
- int unserialize(EsdlContext* obj, IPropertyTree* ptree)
- {
- if (!obj || !ptree)
- return 0;
- if (ptree->hasProp("username"))
- obj->username.setown(new PString(ptree->queryProp("username")));
- if (ptree->hasProp("clientMajorVersion"))
- obj->clientMajorVersion.setown(new Integer(ptree->getPropInt("clientMajorVersion")));
- if (ptree->hasProp("clientMinorVersion"))
- obj->clientMinorVersion.setown(new Integer(ptree->getPropInt("clientMinorVersion")));
- }<xsl:text>
- </xsl:text>
- <xsl:for-each select="/esxdl/EsdlRequest|/esxdl/EsdlResponse|/esxdl/EsdlStruct">
- <xsl:call-template name="generateUnserializeForStruct"/>
- </xsl:for-each>
- <xsl:for-each select="/esxdl/EsdlRequest|/esxdl/EsdlResponse|/esxdl/EsdlStruct">
- <xsl:call-template name="generateSerializeForStruct"/>
- </xsl:for-each>
- <xsl:text>
- };
- </xsl:text>
- <xsl:for-each select="EsdlMethod">
- <xsl:text>int </xsl:text><xsl:value-of select="$servicebase"/>::<xsl:value-of select="@name"/><xsl:text>(const char* CtxStr, const char* ReqStr, StringBuffer& RespStr)
- {</xsl:text>
- Owned<<xsl:value-of select="$servicename"/>UnSerializer> UnSe = new <xsl:value-of select="$servicename"/>UnSerializer();
- Owned<EsdlContext> ctx = new EsdlContext();
- if (CtxStr && *CtxStr)
- {
- Owned<IPropertyTree> ptree = createPTreeFromXMLString(CtxStr);
- UnSe->unserialize(ctx.get(), ptree.get());
- }
- Owned<<xsl:value-of select="$servicebase"/>> service = create<xsl:value-of select="$servicename"/>ServiceObj();
- Owned<<xsl:value-of select="@request_type"/>> req = new <xsl:value-of select="@request_type"/>();
- Owned<IPropertyTree> ptree;
- ptree.setown(createPTreeFromXMLString(ReqStr));
- UnSe->unserialize(req.get(), ptree.get());
- Owned<<xsl:value-of select="@response_type"/>> resp = service-><xsl:value-of select="@name"/>(ctx.get(), req.get());
- RespStr = "<Response><Results><Result><Dataset name=\"<xsl:value-of select="@response_type"/>\"><Row>";
- UnSe->serialize(resp.get(), RespStr);
- RespStr.append("</Row></Dataset></Result></Results></Response>");
- return 0;
- }<xsl:text>
- </xsl:text>
- </xsl:for-each>
- </xsl:template>
- <xsl:template name="generateUnserializeForStruct">
- int unserialize(<xsl:value-of select="@name"/>* obj, IPropertyTree* ptree)
- {
- if (!obj || !ptree)
- return 0;
- IPropertyTree* subtree = nullptr;<xsl:text>
- </xsl:text>
- <xsl:for-each select="*">
- <xsl:variable name="fieldclass" select="name(.)"/>
- <xsl:variable name="fieldname" select="@name"/>
- <xsl:variable name="fieldvar" select="concat('m_', $fieldname)"/>
- <xsl:choose>
- <xsl:when test="$fieldclass='EsdlElement'">
- <xsl:choose>
- <xsl:when test="@complex_type">
- subtree = ptree->queryPropTree("<xsl:value-of select="$fieldname"/>");
- if (subtree != nullptr)
- {
- obj-><xsl:value-of select="$fieldvar"/>.setown(new <xsl:value-of select="@complex_type"/>());
- unserialize(obj-><xsl:value-of select="$fieldvar"/>.get(), subtree);
- }<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="primitive">
- <xsl:call-template name="outputCppPrimitive">
- <xsl:with-param name="typename">
- <xsl:value-of select="@type"/>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$primitive='PString'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new PString(ptree->queryProp("<xsl:value-of select="$fieldname"/>")));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Integer'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new Integer(ptree->getPropInt("<xsl:value-of select="$fieldname"/>")));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Integer64'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new Integer64(ptree->getPropInt64("<xsl:value-of select="$fieldname"/>")));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Boolean'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new Boolean(ptree->getPropBool("<xsl:value-of select="$fieldname"/>")));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Float'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new Float(atof(ptree->queryProp("<xsl:value-of select="$fieldname"/>"))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Double'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/>.setown(new Double(atof(ptree->queryProp("<xsl:value-of select="$fieldname"/>"))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:when test="$fieldclass='EsdlArray'">
- subtree = ptree->queryPropTree("<xsl:value-of select="$fieldname"/>");
- if (subtree != nullptr)
- {
- Owned<IPropertyTreeIterator> itr = subtree->getElements("<xsl:value-of select="@item_tag"/>");
- ForEach (*itr)
- {
- IPropertyTree* onetree = &itr->query();<xsl:text>
- </xsl:text>
- <xsl:variable name="primitive">
- <xsl:call-template name="outputCppPrimitive">
- <xsl:with-param name="typename">
- <xsl:value-of select="@type"/>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$primitive=@type">
- Owned<<xsl:value-of select="@type"/>> oneobj(new <xsl:value-of select="@type"/>());
- unserialize(oneobj.get(), onetree);
- obj-><xsl:value-of select="$fieldvar"/>.append(*oneobj.getClear());<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='PString'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new PString(onetree->queryProp("."))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Integer'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new Integer(onetree->getPropInt("."))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Integer64'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new Integer64(onetree->getPropInt64("."))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Boolean'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new Boolean(onetree->getPropBool("."))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Float'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new Float(atof(onetree->queryProp(".")))));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$primitive='Double'">
- obj-><xsl:value-of select="$fieldvar"/>.append(*(new Double(atof(onetree->queryProp(".")))));<xsl:text>
- </xsl:text>
- </xsl:when>
- </xsl:choose>
- }<xsl:text>
- </xsl:text>
- }<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$fieldclass='EsdlEnum'">
- if (ptree->hasProp("<xsl:value-of select="$fieldname"/>"))
- obj-><xsl:value-of select="$fieldvar"/> = EnumHandler<xsl:value-of select="@enum_type"/>::fromString(ptree->queryProp("<xsl:value-of select="$fieldname"/>"));<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- return 0;
- }
- </xsl:template>
- <xsl:template name="generateSerializeForStruct">
- int serialize(<xsl:value-of select="@name"/>* obj, StringBuffer& buf)
- {
- if (!obj)
- return 0;<xsl:text>
- </xsl:text>
- <xsl:for-each select="*">
- <xsl:variable name="fieldclass" select="name(.)"/>
- <xsl:variable name="fieldname" select="@name"/>
- <xsl:variable name="fieldvar" select="concat('m_', $fieldname)"/>
- <xsl:choose>
- <xsl:when test="$fieldclass='EsdlElement'">
- if (obj-><xsl:value-of select="$fieldvar"/>)
- {
- buf.append("<<xsl:value-of select="$fieldname"/>>");<xsl:text>
- </xsl:text>
- <xsl:choose>
- <xsl:when test="@complex_type">
- <xsl:text> </xsl:text>serialize(obj-><xsl:value-of select="$fieldvar"/>, buf);<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="primitive">
- <xsl:call-template name="outputCppPrimitive">
- <xsl:with-param name="typename">
- <xsl:value-of select="@type"/>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:text> </xsl:text>buf.append(obj-><xsl:value-of select="$fieldvar"/>->str());<xsl:text>
- </xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- <xsl:text> </xsl:text>buf.append("</<xsl:value-of select="$fieldname"/>>");<xsl:text>
- }
- </xsl:text>
- </xsl:when>
- <xsl:when test="$fieldclass='EsdlArray'">
- if (obj-><xsl:value-of select="$fieldvar"/>.length() > 0)
- {
- buf.append("<<xsl:value-of select="$fieldname"/>>");
- ForEachItemIn(i, obj-><xsl:value-of select="$fieldvar"/>)
- {<xsl:text>
- </xsl:text>
- <xsl:variable name="primitive">
- <xsl:call-template name="outputCppPrimitive">
- <xsl:with-param name="typename">
- <xsl:value-of select="@type"/>
- </xsl:with-param>
- </xsl:call-template>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="$primitive=@type">
- <xsl:text> </xsl:text><xsl:value-of select="@type"/>& oneitem = obj-><xsl:value-of select="$fieldvar"/>.item(i);
- buf.append("<<xsl:value-of select="@item_tag"/>>");
- serialize(&oneitem, buf);
- buf.append("</<xsl:value-of select="@item_tag"/>>");<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- <xsl:text> </xsl:text><xsl:value-of select="$primitive"/>& oneitem = obj-><xsl:value-of select="$fieldvar"/>.item(i);
- buf.append("<<xsl:value-of select="@item_tag"/>>").append(oneitem.str()).append("</<xsl:value-of select="@item_tag"/>>");<xsl:text>
- </xsl:text>
- </xsl:otherwise>
- </xsl:choose>
- }
- buf.append("</<xsl:value-of select="$fieldname"/>>");
- }<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:when test="$fieldclass='EsdlEnum'">
- if (obj-><xsl:value-of select="$fieldvar"/> != <xsl:value-of select="@enum_type"/>::UNSET)
- buf.append("<<xsl:value-of select="$fieldname"/>>").append(EnumHandler<xsl:value-of select="@enum_type"/>::toString(obj-><xsl:value-of select="$fieldvar"/>)).append("</<xsl:value-of select="$fieldname"/>>");<xsl:text>
- </xsl:text>
- </xsl:when>
- <xsl:otherwise>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:for-each>
- return 0;
- }<xsl:text>
- </xsl:text>
- </xsl:template>
- </xsl:stylesheet>
|