001package net.gdface.annotation; 002 003import java.lang.annotation.ElementType; 004import java.lang.annotation.Retention; 005import java.lang.annotation.RetentionPolicy; 006import java.lang.annotation.Target; 007 008/** 009 * 服务定义<br> 010 * {@link #bridgeType()},{@link #targetType()},{@link #genericTypes()}用来定义成多态端口的方式<br> 011 * 例如:{@link #portPrefix()}为"db_",{@link #bridgeType()}定义为{@link String},{@link #targetType()}定义为byte[], 012 * {@link #genericTypes()}定义为{"URL","Base64"}<br> 013 * 那么对于一个方法{@code public int addImage(byte[] img)}生成的的服务端口为:<br> 014 * {@code public int db_addImage(byte[] img)}<br> 015 * {@code public int db_addImageByURL(String img)}<br> 016 * {@code public int db_addImageByBase64(String img)}<br> 017 * 018 * @author guyadong 019 * 020 */ 021@Target({ ElementType.TYPE }) 022@Retention(RetentionPolicy.RUNTIME) 023public @interface Service { 024 /** 025 * 端口(方法)名前缀,防止多个接口实现之间的方法名冲突 026 * 027 * @return 028 */ 029 String portPrefix() default ""; 030 031 /** 032 * 方法中需要生成多个端口的的桥接类型 033 * 034 * @return 035 */ 036 Class<?> bridgeType() default Object.class; 037 038 /** 039 * 目标参数类型<br> 040 * 具有该类型的方法参数 {@link #bridgeType()}和 {@link #genericTypes()}才有效 041 * 042 * @return 043 */ 044 Class<?> targetType() default Object.class; 045 046 /** 047 * 可以将{@link #bridgeType()}转成 {@link #targetType()}的数据类型列表<br> 048 * 会根据这个名字生成 "ByXXX"后缀的方法,例如:定义为{"URL","Base64"}<br> 049 * 不允许有重复的值 050 * 051 * @return 052 */ 053 String[] genericTypes() default {}; 054 055 /** 056 * {@link #genericTypes()}中每个类型名对应的类<br> 057 * 不允许有重复的值,不允许为{@code null} 058 * 059 * @return 060 */ 061 Class<?>[]genericTypeClasses() default {}; 062}