templates.service.webservice.class.vm Maven / Gradle / Ivy
#parse("${include}/generic.include.vm")
#set ( $className ="FaceDbService")
##将$sourceinfo改名
#set ( $sourceinfolist =$TOOL.sortBy($sourceinfo,"interfaceClass.simpleName"))
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
#set ( $imports = $sourceinfolist.get(0).importedList )
#if($sourceinfolist.size()>1)
#foreach( $sourceinfo in $sourceinfolist)
#if($velocityCount>1)$imports.putAll($sourceinfo.importedList)#end
#if($sourceinfo.serviceInfo.portPrefix=='db_')#set($db_interfaceClass=$sourceinfo.interfaceClass)#end
#end
#end
#set ( $BaseBean =$CLASS.forName("net.gdface.db.dbmanager.oracle.BaseBean"))
#set ( $ServiceRuntime =$CLASS.forName("com.gitee.l0km.com4j.base.exception.ServiceRuntime"))
###addIntoImports($ServiceRuntime)
$TOOL.addImportedClasses($imports,$ServiceRuntime)
#set ( $IOException =$CLASS.forName("java.io.IOException"))
#addIntoImports($IOException)
#if($sourceinfolist.size()>1)
#foreach( $sourceinfo in $sourceinfolist)
#if($velocityCount>1)$sourceinfo.importedList.putAll($imports)#end
#end
#end
#macro(callMethod)
$varName.${method.name}(#join($method.parameters '#if($genericParamName.contains($e.name)&&$genericType=="URL")new URL($e.name)#else$e.name#end' ','));
#end
##生成注释
#macro (comment $method)
/**
* 参见{@link $method.getDocSignature($imports)}
#foreach( $parameter in $method.parameters) * @param $parameter.name
#end
* @return #typeName($method.genericReturnType)
#foreach( $exception in $method.exceptionTypes) * @throws $exception.simpleName
#end
* @see $method.getDocSignature($imports)
*/
#end
package $pkg;
##删除FaceDbSDK引用
#if($db_interfaceClass)#set($tmp=$sourceinfolist[0].importedList.remove($db_interfaceClass.simpleName))#end
#outputImports1($sourceinfolist[0].importedClassNames)
import com.gitee.l0km.com4j.base.FaceUtilitsX;
/**
* 实现#foreach( $sourceinfo in $sourceinfolist )#if ( $velocityCount > 1 ),#end {@link $sourceinfo.interfaceClass.name}#end核心接口的webservice代理
* 所有服务器端接口方法(port)抛出的{@link RuntimeException}异常都被封装为{@link ServiceRuntime}异常发送到客户端
* $GENERAED_BY
* @author guyadong
*
*/
public class ${className} {
##定义变量
#foreach( $sourceinfo in $sourceinfolist)
#if($sourceinfo.serviceInfo.portPrefix=='db_')#set ($db=$TOOL.toVarName($sourceinfo.interfaceClass))#set($instanceType=$sourceinfo.refClass)#set($dbclass = ${sourceinfo.refClass.simpleName})#end
#if($sourceinfo.serviceInfo.portPrefix=='sdk_')#set ($sdk=$TOOL.toVarName($sourceinfo.interfaceClass))#set($instanceType=$sourceinfo.interfaceClass)#end
private static final #typeName($instanceType) $TOOL.toVarName($sourceinfo.interfaceClass);
#end
static{
//静态初始化
if (!FaceUtilitsX.isBuilding()){
try{
// 从 config中获取类名
String implClassName = net.gdface.facedbsdk.Configuration.getFaceDbSDKLocalImplClass();
// 加载 ${dbclass} 实现类
System.out.printf("load class %s\n", implClassName);
Class> clazz = Class.forName(implClassName);
// 判断是否子类
if (${dbclass}.class.equals(clazz)||!${dbclass}.class.isAssignableFrom(clazz)) {
throw new ExceptionInInitializerError(String.format(
"invalid class %s,the class must derive from %s", implClassName,
${dbclass}.class.getName()));
}
// 从配置文件中读取参数设置debug标记
${dbclass}.setDebug(net.gdface.facedbsdk.Configuration.getDebug());
$db = ${dbclass}.getInstance();
$sdk= ${db}.getFaceAPI();
} catch (ClassNotFoundException e) {
throw new ExceptionInInitializerError(e);
}
}else{
#foreach( $sourceinfo in $sourceinfolist)
$TOOL.toVarName($sourceinfo.interfaceClass)=null;
#end
}
}
#foreach( $sourceinfo in $sourceinfolist)
## $methods要重新赋值
#set ( $methods = $sourceinfo.methodsNeedGenerated )
#set ( $varName = $TOOL.toVarName($sourceinfo.interfaceClass))
#set ( $serviceinfo = $sourceinfo.serviceInfo )
#set ( $portPrefix = $serviceinfo.portPrefix)
#set ( $bridgeType = $serviceinfo.bridgeType)
#set ( $targetType = $serviceinfo.targetType)
#set ( $defaultGenericTypes= $serviceinfo.genericTypeMap.keySet())
#foreach ($method in $TOOL.sortBySignature($methods))
#if($sourceinfo.getServicePort($method))
#set ( $port =$sourceinfo.getServicePort($method))
#set ( $suffix =$port.suffix())
#set ( $genericParamName =$TOOL.toSet($port.genericParam()))
#set ( $genericTypes =$TOOL.toSet($port.genericTypes()))
#else
#set ( $suffix ="")
#set ( $genericParamName =[])
#end
#set ( $methodName =$portPrefix+$method.name+$suffix)
#######
#comment($method)
#set($exps = $TOOL.sortBy($TOOL.toSet($method.genericExceptionTypes),"simpleName"))
#set($tmp=$exps.add($ServiceRuntime))
public final #typeParametersDefine()#typeName($method.genericReturnType) $methodName (#join($method.parameters '#typeName($e.type) $e.name' ',')) #fillThrows($exps){
try{
## #RETURN() $varName.${method.name}(#join($method.parameters '$e.name' ','));
#if($TOOL.isVoid($method.returnType))
#callMethod()
#else
#RETURN() #callMethod()
#end
}#foreach($exp in $TOOL.sortThrowable($method.genericExceptionTypes))catch(${exp.simpleName} e){
// 对于${exp.simpleName}的子类,封装成${exp.simpleName}抛出
throw e.getClass()==${exp.simpleName}.class?e:new ${exp.simpleName}(e);
}#end
catch (RuntimeException e) {
throw new #typeName($ServiceRuntime)(e);
}
}
#if($serviceinfo.annotationDefined&&!$genericParamName.isEmpty())
#if($genericTypes.isEmpty())#set ( $genericTypes =$defaultGenericTypes)#end
#foreach( $genericType in $genericTypes)
#comment($method)
#set($exps = $TOOL.sortBy($TOOL.toSet($method.genericExceptionTypes),"simpleName"))
#set($tmp=$exps.add($ServiceRuntime))
public final #typeParametersDefine()#typeName($method.genericReturnType) ${methodName}By$genericType (#join($method.parameters '#if($genericParamName.contains($e.name))#typeName($bridgeType)#else#pamameterType($e)#end $e.name' ',')) #fillThrows($exps){
try{
#if($TOOL.isVoid($method.returnType))
#callMethod()
#else
#RETURN() #callMethod()
#end
}#foreach($exp in $TOOL.sortThrowable($method.genericExceptionTypes))catch(${exp.simpleName} e){
// 对于${exp.simpleName}的子类,封装成${exp.simpleName}抛出
throw e.getClass()==${exp.simpleName}.class?e:new ${exp.simpleName}(e);
}#end
catch (RuntimeException e){
throw new #typeName($ServiceRuntime)(e);
}#join($sourceinfo.getThrowsByMatchedGenericMethod($method,$serviceinfo.getType($genericType))
'catch(#typeName($e) e){
throw new #typeName($ServiceRuntime)(e);
}
' '')
}
#end
#end
#end
#end
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy