Examples of MetaDataReader


Examples of org.springframework.core.type.classreading.MetadataReader

              ClassUtils.convertClassNameToResourcePath(pkg) + ENTITY_CLASS_RESOURCE_PATTERN;
          Resource[] resources = this.resourcePatternResolver.getResources(pattern);
          MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
          for (Resource resource : resources) {
            if (resource.isReadable()) {
              MetadataReader reader = readerFactory.getMetadataReader(resource);
              String className = reader.getClassMetadata().getClassName();
              if (matchesFilter(reader, readerFactory)) {
                scannedUnit.addManagedClassName(className);
              }
            }
          }
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

    }
    else {
      String className = beanDef.getBeanClassName();
      if (className != null) {
        try {
          MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(className);
          metadata = metadataReader.getAnnotationMetadata();
        }
        catch (IOException ex) {
          if (logger.isDebugEnabled()) {
            logger.debug("Could not find class file for introspecting factory methods: " + className, ex);
          }
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

   * @param className the name of the class to parse
   * @param beanName may be null, but if populated represents the bean id
   * (assumes that this configuration class was configured via XML)
   */
  public void parse(String className, String beanName) throws IOException {
    MetadataReader reader = this.metadataReaderFactory.getMetadataReader(className);
    processConfigurationClass(new ConfigurationClass(reader, beanName));
  }
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

  protected AnnotationMetadata doProcessConfigurationClass(
      ConfigurationClass configClass, AnnotationMetadata metadata) throws IOException {

    // recursively process any member (nested) classes first
    for (String memberClassName : metadata.getMemberClassNames()) {
      MetadataReader reader = this.metadataReaderFactory.getMetadataReader(memberClassName);
      AnnotationMetadata memberClassMetadata = reader.getAnnotationMetadata();
      if (ConfigurationClassUtils.isConfigurationCandidate(memberClassMetadata)) {
        processConfigurationClass(new ConfigurationClass(reader, true));
      }
    }

    // process any @PropertySource annotations
    AnnotationAttributes propertySource =
        attributesFor(metadata, org.springframework.context.annotation.PropertySource.class);
    if (propertySource != null) {
      String name = propertySource.getString("name");
      String[] locations = propertySource.getStringArray("value");
      int nLocations = locations.length;
      if (nLocations == 0) {
        throw new IllegalArgumentException("At least one @PropertySource(value) location is required");
      }
      for (int i = 0; i < nLocations; i++) {
        locations[i] = this.environment.resolveRequiredPlaceholders(locations[i]);
      }
      ClassLoader classLoader = this.resourceLoader.getClassLoader();
      if (!StringUtils.hasText(name)) {
        for (String location : locations) {
          this.propertySources.push(new ResourcePropertySource(location, classLoader));
        }
      }
      else {
        if (nLocations == 1) {
          this.propertySources.push(new ResourcePropertySource(name, locations[0], classLoader));
        }
        else {
          CompositePropertySource ps = new CompositePropertySource(name);
          for (String location : locations) {
            ps.addPropertySource(new ResourcePropertySource(location, classLoader));
          }
          this.propertySources.push(ps);
        }
      }
    }

    // process any @ComponentScan annotions
    AnnotationAttributes componentScan = attributesFor(metadata, ComponentScan.class);
    if (componentScan != null) {
      // the config class is annotated with @ComponentScan -> perform the scan immediately
      Set<BeanDefinitionHolder> scannedBeanDefinitions =
          this.componentScanParser.parse(componentScan, metadata.getClassName());

      // check the set of scanned definitions for any further config classes and parse recursively if necessary
      for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
        if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
          this.parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
        }
      }
    }

    // process any @Import annotations
    Set<String> imports = getImports(metadata.getClassName(), null, new HashSet<String>());
    if (imports != null && !imports.isEmpty()) {
      processImport(configClass, imports.toArray(new String[imports.size()]), true);
    }

    // process any @ImportResource annotations
    if (metadata.isAnnotated(ImportResource.class.getName())) {
      AnnotationAttributes importResource = attributesFor(metadata, ImportResource.class);
      String[] resources = importResource.getStringArray("value");
      Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
      for (String resource : resources) {
        configClass.addImportedResource(resource, readerClass);
      }
    }

    // process individual @Bean methods
    Set<MethodMetadata> beanMethods = metadata.getAnnotatedMethods(Bean.class.getName());
    for (MethodMetadata methodMetadata : beanMethods) {
      configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass));
    }

    // process superclass, if any
    if (metadata.hasSuperClass()) {
      String superclass = metadata.getSuperClassName();
      if (this.knownSuperclasses.add(superclass)) {
        // superclass found, return its annotation metadata and recurse
        if (metadata instanceof StandardAnnotationMetadata) {
          Class<?> clazz = ((StandardAnnotationMetadata) metadata).getIntrospectedClass();
          return new StandardAnnotationMetadata(clazz.getSuperclass(), true);
        }
        else if (superclass.startsWith("java")) {
          // never load core JDK classes via ASM, in particular not java.lang.Object!
          try {
            return new StandardAnnotationMetadata(
                this.resourceLoader.getClassLoader().loadClass(superclass), true);
          }
          catch (ClassNotFoundException ex) {
            throw new IllegalStateException(ex);
          }
        }
        else {
          MetadataReader reader = this.metadataReaderFactory.getMetadataReader(superclass);
          return reader.getAnnotationMetadata();
        }
      }
    }

    // no superclass, processing is complete
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

    }
    else {
      this.importStack.push(configClass);
      AnnotationMetadata importingClassMetadata = configClass.getMetadata();
      for (String candidate : classesToImport) {
        MetadataReader reader = this.metadataReaderFactory.getMetadataReader(candidate);
        if (new AssignableTypeFilter(ImportSelector.class).match(reader, this.metadataReaderFactory)) {
          // the candidate class is an ImportSelector -> delegate to it to determine imports
          try {
            ImportSelector selector = BeanUtils.instantiateClass(
                this.resourceLoader.getClassLoader().loadClass(candidate), ImportSelector.class);
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

        if (traceEnabled) {
          logger.trace("Scanning " + resource);
        }
        if (resource.isReadable()) {
          try {
            MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
            if (isCandidateComponent(metadataReader)) {
              ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
              sbd.setResource(resource);
              sbd.setSource(resource);
              if (isCandidateComponent(sbd)) {
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

      String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
          ClassUtils.convertClassNameToResourcePath(basePackage) + "/" + this.resourcePattern;
      Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);
      for (int i = 0; i < resources.length; i++) {
        Resource resource = resources[i];
        MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
        if (isCandidateComponent(metadataReader)) {
          ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
          sbd.setSource(resource);
          if (isCandidateComponent(sbd)) {
            candidates.add(sbd);
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

        Resource resource = resources[i];
        if (traceEnabled) {
          logger.trace("Scanning " + resource);
        }
        if (resource.isReadable()) {
          MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
          if (isCandidateComponent(metadataReader)) {
            ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
            sbd.setResource(resource);
            sbd.setSource(resource);
            if (isCandidateComponent(sbd)) {
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

              ClassUtils.convertClassNameToResourcePath(pkg) + RESOURCE_PATTERN;
          Resource[] resources = this.resourcePatternResolver.getResources(pattern);
          MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
          for (Resource resource : resources) {
            if (resource.isReadable()) {
              MetadataReader reader = readerFactory.getMetadataReader(resource);
              String className = reader.getClassMetadata().getClassName();
              if (matchesFilter(reader, readerFactory)) {
                config.addAnnotatedClass(this.resourcePatternResolver.getClassLoader().loadClass(className));
              }
            }
          }
View Full Code Here

Examples of org.springframework.core.type.classreading.MetadataReader

    doTestAnnotationInfo(annInfo);
  }

  public void testAsmAnnotationMetadata() throws IOException {
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(AnnotatedComponent.class.getName());
    doTestAnnotationInfo(metadataReader.getAnnotationMetadata());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.