Java源码示例:com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass

示例1
public static MessageType getMessageType(Method method) {
    Class<?>[] types = method.getParameterTypes();
    Class returnType = method.getReturnType();
    if (types.length < 0) {
        throw new IllegalArgumentException("invalid rpc method params");
    }

    if (types.length != 1) {
        return MessageType.POJO;
    }

    Class<?> inputType = types[0];
    if (Message.class.isAssignableFrom(inputType)
            && Message.class.isAssignableFrom(returnType)) {
        return MessageType.PROTOBUF;
    }

    ProtobufClass protobufClass = inputType.getAnnotation(ProtobufClass.class);
    if (protobufClass != null) {
        return MessageType.JPROTOBUF;
    }

    Field[] fields = inputType.getDeclaredFields();
    for (Field field : fields) {
        Protobuf protobuf = field.getAnnotation(Protobuf.class);
        if (protobuf != null) {
            return MessageType.JPROTOBUF;
        }
    }

    return MessageType.POJO;
}
 
示例2
/**
 * Fetch field infos.
 *
 * @return the list
 */
public static List<FieldInfo> fetchFieldInfos(Class cls, boolean ignoreNoAnnotation) {
    // if set ProtobufClass annotation
    Annotation annotation = cls.getAnnotation(ProtobufClass.class);

    Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
    boolean isZipZap = false;
    if (zipZap != null) {
        isZipZap = true;
    }

    boolean typeDefined = false;
    List<Field> fields = null;
    if (annotation == null) {
        fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
        if (fields.isEmpty() && ignoreNoAnnotation) {
            throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
                    + Protobuf.class.getName() + " at class " + cls.getName());
        }
    } else {
        typeDefined = true;

        fields = FieldUtils.findMatchedFields(cls, null);
    }

    List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
    return fieldInfos;
}
 
示例3
/**
 * Fetch field infos.
 *
 * @return the list
 */
protected List<FieldInfo> fetchFieldInfos() {
    // if set ProtobufClass annotation
    Annotation annotation = cls.getAnnotation(ProtobufClass.class);
    
    Annotation zipZap = cls.getAnnotation(EnableZigZap.class);
    boolean isZipZap = false;
    if (zipZap != null) {
        isZipZap = true;
    }
    
    boolean typeDefined = false;
    List<Field> fields = null;
    if (annotation == null) {
        fields = FieldUtils.findMatchedFields(cls, Protobuf.class);
        if (fields.isEmpty()) {
            throw new IllegalArgumentException("Invalid class [" + cls.getName() + "] no field use annotation @"
                    + Protobuf.class.getName() + " at class " + cls.getName());
        }
    } else {
        typeDefined = true;
        
        fields = FieldUtils.findMatchedFields(cls, null);
    }
    
    List<FieldInfo> fieldInfos = ProtobufProxyUtils.processDefaultValue(fields, typeDefined, isZipZap);
    return fieldInfos;
}