| | |
| | | package com.java110.doc.registrar; |
| | | |
| | | import com.java110.doc.annotation.Java110ApiDoc; |
| | | import com.java110.doc.annotation.Java110CmdDoc; |
| | | import com.java110.doc.annotation.Java110CmdDocDiscovery; |
| | | import com.java110.doc.entity.CmdDocDto; |
| | | import org.springframework.beans.factory.BeanClassLoaderAware; |
| | | import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; |
| | | import org.springframework.beans.factory.config.BeanDefinition; |
| | |
| | | * api 文档 注入类 |
| | | * Created by wuxw on 2018/7/2. |
| | | */ |
| | | public class Java110CmdDocDiscoveryRegistrar implements ImportBeanDefinitionRegistrar,ResourceLoaderAware, BeanClassLoaderAware { |
| | | public class Java110CmdDocDiscoveryRegistrar implements ImportBeanDefinitionRegistrar, ResourceLoaderAware, BeanClassLoaderAware { |
| | | |
| | | private ResourceLoader resourceLoader; |
| | | |
| | | private ClassLoader classLoader; |
| | | |
| | | public Java110CmdDocDiscoveryRegistrar(){ |
| | | public Java110CmdDocDiscoveryRegistrar() { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { |
| | | try { |
| | | registerListener(importingClassMetadata,registry); |
| | | registerListener(importingClassMetadata, registry); |
| | | } catch (NoSuchMethodException e) { |
| | | e.printStackTrace(); |
| | | } catch (InvocationTargetException e) { |
| | |
| | | |
| | | /** |
| | | * 注册侦听 |
| | | * |
| | | * @param metadata |
| | | * @param registry |
| | | */ |
| | |
| | | Map<String, Object> attrs = metadata |
| | | .getAnnotationAttributes(Java110CmdDocDiscovery.class.getName()); |
| | | |
| | | Object cmdPublishClassObj = attrs.get("cmdPublishClass"); |
| | | Object cmdPublishClassObj = attrs.get("cmdDocClass"); |
| | | |
| | | //Assert.notNull(cmdPublishClassObj,"Java110CmdDiscovery 没有配置 cmdPublishClass 属性"); |
| | | |
| | | Class<?> cmdPublishClass = (Class<?>) cmdPublishClassObj; |
| | | |
| | | AnnotationTypeFilter annotationTypeFilter = new AnnotationTypeFilter( |
| | | Java110ApiDoc.class); |
| | | Java110CmdDoc.class); |
| | | |
| | | scanner.addIncludeFilter(annotationTypeFilter); |
| | | basePackages = getBasePackages(metadata); |
| | |
| | | AnnotatedBeanDefinition beanDefinition = (AnnotatedBeanDefinition) candidateComponent; |
| | | AnnotationMetadata annotationMetadata = beanDefinition.getMetadata(); |
| | | |
| | | |
| | | Map<String, Object> attributes = annotationMetadata |
| | | .getAnnotationAttributes( |
| | | Java110CmdDoc.class.getCanonicalName()); |
| | | |
| | | String beanName = getListenerName(attributes,beanDefinition); |
| | | String serviceCode = attributes.get("serviceCode").toString(); |
| | | String beanName = getListenerName(attributes, beanDefinition); |
| | | CmdDocDto cmdDocDto = new CmdDocDto(); |
| | | cmdDocDto.setCmdClass(candidateComponent.getClass()); |
| | | cmdDocDto.setDescription(attributes.get("description").toString()); |
| | | cmdDocDto.setAuthor(attributes.get("author").toString()); |
| | | cmdDocDto.setResource(attributes.get("resource").toString()); |
| | | cmdDocDto.setTitle(attributes.get("title").toString()); |
| | | cmdDocDto.setUrl(attributes.get("url").toString()); |
| | | cmdDocDto.setVersion(attributes.get("version").toString()); |
| | | cmdDocDto.setHttpMethod(attributes.get("httpMethod").toString()); |
| | | cmdDocDto.setServiceCode(attributes.get("serviceCode").toString()); |
| | | |
| | | |
| | | /*BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(beanDefinition, beanName); |
| | | BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, registry);*/ |
| | | // Method method = cmdPublishClass.getMethod("addListener", CmdListenerDto.class); |
| | | // method.invoke(null,new CmdListenerDto(beanName,serviceCode)); |
| | | Method method = cmdPublishClass.getMethod("addCmdDoc", CmdDocDto.class); |
| | | method.invoke(null, cmdDocDto); |
| | | } |
| | | } |
| | | } |
| | |
| | | beanDefinition.getMetadata().getClassName(), |
| | | Java110CmdDocDiscoveryRegistrar.this.classLoader); |
| | | return !target.isAnnotation(); |
| | | } |
| | | catch (Exception ex) { |
| | | } catch (Exception ex) { |
| | | this.logger.error( |
| | | "Could not load target class: " |
| | | + beanDefinition.getMetadata().getClassName(), |
| | |
| | | |
| | | /** |
| | | * 获取名称 |
| | | * |
| | | * @param listeners |
| | | * @param beanDefinition |
| | | * @return |
| | | */ |
| | | private String getListenerName(Map<String, Object> listeners,AnnotatedBeanDefinition beanDefinition) { |
| | | private String getListenerName(Map<String, Object> listeners, AnnotatedBeanDefinition beanDefinition) { |
| | | if (listeners == null) { |
| | | String shortClassName = ClassUtils.getShortName(beanDefinition.getBeanClassName()); |
| | | return Introspector.decapitalize(shortClassName); |