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

org.onetwo.common.apiclient.simple.GenericApiClentRegistrar Maven / Gradle / Ivy

package org.onetwo.common.apiclient.simple;

import java.lang.annotation.Annotation;

import org.onetwo.common.apiclient.ApiClientMethod;
import org.onetwo.common.apiclient.ApiClientResponseHandler;
import org.onetwo.common.apiclient.RestExecutorFactory;
import org.onetwo.common.apiclient.impl.AbstractApiClentRegistrar;
import org.onetwo.common.apiclient.impl.DefaultApiClientFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

import net.jodah.typetools.TypeResolver;

/**
 * @author wayshall
 * 
*/ public class GenericApiClentRegistrar extends AbstractApiClentRegistrar { @SuppressWarnings("unchecked") public static > Class[] resolveRawArguments(Class subType) { Class[] paramClasses = (Class[])TypeResolver.resolveRawArguments(GenericApiClentRegistrar.class, subType); return paramClasses; } private ApiClientResponseHandler responseHandler; protected GenericApiClentRegistrar() { Class[] paramClasses = (Class[])resolveRawArguments(getClass()); // this.importingAnnotationClass = paramClasses[0]; // this.componentAnnotationClass = paramClasses[1]; setImportingAnnotationClass(paramClasses[0]); setComponentAnnotationClass(paramClasses[1]); } public GenericApiClentRegistrar(Class importingAnnotationClass, Class componentAnnotationClass) { super(importingAnnotationClass, componentAnnotationClass); } @Override protected BeanDefinitionBuilder createApiClientFactoryBeanBuilder(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes) { String className = annotationMetadata.getClassName(); BeanDefinitionBuilder definition = BeanDefinitionBuilder.genericBeanDefinition(DefaultApiClientFactoryBean.class); definition.addPropertyValue("url", resolveUrl(attributes, annotationMetadata)); definition.addPropertyValue("path", resolvePath(attributes)); definition.addPropertyValue("interfaceClass", className); definition.addPropertyValue("responseHandler", responseHandler); definition.addPropertyReference("restExecutor", RestExecutorFactory.REST_EXECUTOR_FACTORY_BEAN_NAME); // definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE); return definition; } final public void setResponseHandler(ApiClientResponseHandler responseHandler) { this.responseHandler = responseHandler; } }