All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.includes.webclient.gsoap.factory.body.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/generic.include.vm")
#if( $source_type == "cpp" )
\#include "${factoryClassName}.h"
\#include "assert_macros.h"
\#include "regex_utils.h"
\#include 
#else
#pragma once
\#include "${className}.h"
\#include "stdsoap2.h"
#end
#parse("${include}/webclient.gsoap.factory.${sourceinfo.interfaceClass.simpleName}.import.vm")
#init_qualifier($source_type $factoryClassName)

$gsoapHelper.namespaceBegin($sourceinfo.baseClass)
#if( $source_type != "cpp" )
${BASEINDENT}    // 创建$gsoapHelper.toCppFullName(${sourceinfo.interfaceClass}) 接口实例的工厂类(单实例) 
${BASEINDENT}    // $GENERAED_BY
${BASEINDENT}    class $factoryClassName {
${BASEINDENT}    private:
${BASEINDENT}        // webservice服务器目标地址模板 
${BASEINDENT}        const std::string ENDPOINT_TEMPLATE = "http://#host#:#port#/axis2/services/$sourceinfo.serviceName";
${BASEINDENT}        const std::string HOST = "#host#";
${BASEINDENT}        const std::string PORT = "#port#";
${BASEINDENT}        // 缺省构造函数 
${BASEINDENT}        $factoryClassName()=default;             
#end
${BASEINDENT}        // 根据host和port构造webservice服务器目标地址 
${BASEINDENT}        // port 小于0时使用默认值8080
${BASEINDENT}        // 如果参数无效则抛出std::invalid_argument异常 
${BASEINDENT}        std::string $!{METHOD_PREFIX}makeEndpoint(const std::string& host, int port#defaultParamValue(-1))const#if( $source_type == "h" );
#else{
${BASEINDENT}            std::string _host,_port;
${BASEINDENT}            if (!net::gdface::utils::isHost(host)) {
${BASEINDENT}                throw_if(!net::gdface::utils::isHostWithPort(host, _host, _port));
${BASEINDENT}            } else {
${BASEINDENT}                _host = host;
${BASEINDENT}                if (port < 0)
${BASEINDENT}                    port = 8080;
${BASEINDENT}                std::ostringstream stream;
${BASEINDENT}                stream << port;
${BASEINDENT}                _port = stream.str();
${BASEINDENT}            }
${BASEINDENT}            auto endpoint = ENDPOINT_TEMPLATE;
${BASEINDENT}            endpoint.replace(endpoint.find(HOST), HOST.size(), _host);
${BASEINDENT}            endpoint.replace(endpoint.find(PORT), PORT.size(), _port);
${BASEINDENT}            return endpoint;
${BASEINDENT}        }
#end
${BASEINDENT}    $!{PUBLIC}
${BASEINDENT}        // 获取 $factoryClassName 实例
${BASEINDENT}        $!{STATIC}const $factoryClassName& $!{METHOD_PREFIX}getInstance() noexcept#if( $source_type == "h" );
#else{
${BASEINDENT}            static $factoryClassName instance;
${BASEINDENT}            return instance;
${BASEINDENT}        }
#end
${BASEINDENT}        // 创建${sourceinfo.interfaceClass.simpleName}实例对象 
${BASEINDENT}        // endpoint webservice服务器目标地址(url),为空或不符合url格式时抛出异常 
${BASEINDENT}        // paramSoap soap参数对象,可通过此参数调整soap调用的工作参数,如soap.send_timeout,soap.recv_timeout,
${BASEINDENT}        // 关于soap的参数设置参见gsoap的官方文档:http://www.genivia.com/doc/soapdoc2.html
${BASEINDENT}        std::shared_ptr<${sourceinfo.interfaceClass.simpleName}> $!{METHOD_PREFIX}makeGSoapInstanceByURL(const std::string& endpoint, const soap& paramSoap#defaultParamValue("soap()"))const#if( $source_type == "h" );
#else {
${BASEINDENT}            throw_if_msg(!net::gdface::utils::isURL(endpoint),std::string("the endpoint:INVALID URL string:").append(endpoint))
${BASEINDENT}            return std::make_shared<${className}>(endpoint,paramSoap);
${BASEINDENT}        }
#end
${BASEINDENT}        // 创建${sourceinfo.interfaceClass.simpleName}实例对象 
${BASEINDENT}        // 可以根据自己的习惯将主机名和端口号合并为一个字符串用host参数传递,也可以将主机名和端口号分别用host和port参数传递 
${BASEINDENT}        // 如果参数无效则抛出std::invalid_argument异常 
${BASEINDENT}        // host 服务器主机地址(主机名[:端口])
${BASEINDENT}        // port 服务器端口(默认值:8080)
${BASEINDENT}        // paramSoap soap参数对象,可通过此参数调整soap调用的工作参数,如soap.send_timeout,soap.recv_timeout,
${BASEINDENT}        // 关于soap的参数设置参见gsoap的官方文档:http://www.genivia.com/doc/soapdoc2.html
${BASEINDENT}        std::shared_ptr<${sourceinfo.interfaceClass.simpleName}> $!{METHOD_PREFIX}makeGSoapInstance(const std::string& host, int port#defaultParamValue(-1), const soap& paramSoap#defaultParamValue("soap()"))const#if( $source_type == "h" );
#else{
${BASEINDENT}            return makeGSoapInstanceByURL(makeEndpoint(host,port),paramSoap);
${BASEINDENT}        }
#end
#parse("${include}/webclient.gsoap.factory.${sourceinfo.interfaceClass.simpleName}.body.vm")
#if( $source_type != "cpp" )
${BASEINDENT}    };
#end
 $gsoapHelper.namespaceEnd()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy