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

templates.thrift.client.perstruct.exception.decorator.class.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/header.include.vm")
#parse("${include}/generic.include.vm")
#parse("thrift/include/client.struct.decorator.include.vm")
#if(!$sourceinfo.exception)
#set($codewriter.saveCurrentFile = false)
#stop
#end
#set ( $baseClass = $sourceinfo.baseClass)
#set ( $className ="${baseClass.simpleName}" )
#set ( $fields         = $TOOL.sortByName($sourceinfo.getFieldDescriptors()) )
#set ( $pkg = ${sourceinfo.decoratorPackage})
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
package $pkg;
#outputImports()
import com.gitee.l0km.xthrift.base.exception.BaseServiceException;

import java.io.PrintStream;
import java.io.PrintWriter;
import com.facebook.swift.codec.ThriftStruct;
#if(!${fields.empty})
import com.facebook.swift.codec.ThriftField;
import com.facebook.swift.codec.ThriftField.Requiredness;
#end
#if ($sourceinfo.needTransformer)
import com.gitee.l0km.xthrift.thrift.TypeTransformer;
#end
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * decorator pattern 装饰者模式代理{@link #typeName(${baseClass})}
* 代理对象必须有默认构造方法,String参数构造方法可选,必须是普通类型,不可以有@ThriftStruct注释
* 转发所有{@link #typeName(${baseClass})}get/set方法到{@link ${esc.hash}delegate()}指定的实例,
* $GENERAED_BY
* @author guyadong * */ @ThriftStruct public final class ${className} extends BaseServiceException implements ThriftDecorator<#typeName(${baseClass})> { private static final long serialVersionUID = 1L; private final #typeName(${baseClass}) delegate; public ${className}(){ this(new #typeName(${baseClass})()); } #if($sourceinfo.hasStringConstructor()) public ${className}(String message){ this(new #typeName(${baseClass})(message)); } #end public ${className}(#typeName(${baseClass}) delegate) { super(checkNotNull(delegate,"delegate is null").getMessage(),delegate.getCause()); // 检查被装饰类是否有@ThriftStruct注释 if(delegate.getClass().isAnnotationPresent(ThriftStruct.class)){ throw new IllegalArgumentException( String.format("NOT ALLOW %s have @ThriftStruct annotation",delegate.getClass().getName())); } this.delegate = delegate; } /** * @return 返回被装饰的{@link #typeName(${baseClass})}实例 */ @Override public #typeName(${baseClass}) delegate() { return delegate; } @Override public void printStackTrace() { delegate().printStackTrace(); } @Override public void printStackTrace(PrintStream s) { delegate().printStackTrace(s); } @Override public void printStackTrace(PrintWriter s) { delegate().printStackTrace(s); } @Override public StackTraceElement[] getStackTrace() { return delegate().getStackTrace(); } @Override public Throwable initCause(Throwable cause) { return delegate().initCause(cause); } @Override public int hashCode() { return delegate().hashCode(); } @Override public boolean equals(Object obj) { return delegate().equals(obj); } @Override public String toString() { return delegate().toString(); } #set($fieldCount = 4 ) #foreach ($field in $fields) #set($fieldCount = $fieldCount + 1 ) #set($propertyType = $field.propertyType) #if($propertyType.primitive) #set ($requireness = 'Requiredness.REQUIRED' ) #else #set ($requireness = 'Requiredness.OPTIONAL' ) #end @ThriftField(value = $fieldCount,requiredness=$requireness) #set ($readMethod = $field.readMethod) public $sourceinfo.toClientThriftType($readMethod.genericReturnType) ${readMethod.name}(){ return #returnValue($readMethod.genericReturnType,"delegate().${readMethod.name}()"); } @ThriftField #set ($writeMethod = $field.writeMethod) public void ${writeMethod.name}($sourceinfo.toClientThriftType($readMethod.genericReturnType) value){ delegate().${writeMethod.name}(#setValue($readMethod.genericReturnType,'value')); } #end##foreach }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy