Package org.springframework.beans.factory.config

Examples of org.springframework.beans.factory.config.SingletonBeanRegistry


    if (configCandidates.isEmpty()) {
      return;
    }

    // Detect any custom bean name generation strategy supplied through the enclosing application context
    SingletonBeanRegistry singletonRegistry = null;
    if (registry instanceof SingletonBeanRegistry) {
      singletonRegistry = (SingletonBeanRegistry) registry;
      if (!this.localBeanNameGeneratorSet && singletonRegistry.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) {
        BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR);
        this.componentScanBeanNameGenerator = generator;
        this.importBeanNameGenerator = generator;
      }
    }

    // Parse each @Configuration class
    ConfigurationClassParser parser = new ConfigurationClassParser(
        this.metadataReaderFactory, this.problemReporter, this.environment,
        this.resourceLoader, this.componentScanBeanNameGenerator, registry);
    for (BeanDefinitionHolder holder : configCandidates) {
      BeanDefinition bd = holder.getBeanDefinition();
      try {
        if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
          parser.parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
        }
        else {
          parser.parse(bd.getBeanClassName(), holder.getBeanName());
        }
      }
      catch (IOException ex) {
        throw new BeanDefinitionStoreException("Failed to load bean class: " + bd.getBeanClassName(), ex);
      }
    }
    parser.validate();

    // Handle any @PropertySource annotations
    Stack<PropertySource<?>> parsedPropertySources = parser.getPropertySources();
    if (!parsedPropertySources.isEmpty()) {
      if (!(this.environment instanceof ConfigurableEnvironment)) {
        logger.warn("Ignoring @PropertySource annotations. " +
            "Reason: Environment must implement ConfigurableEnvironment");
      }
      else {
        MutablePropertySources envPropertySources = ((ConfigurableEnvironment)this.environment).getPropertySources();
        while (!parsedPropertySources.isEmpty()) {
          envPropertySources.addLast(parsedPropertySources.pop());
        }
      }
    }

    // Read the model and create bean definitions based on its content
    if (this.reader == null) {
      this.reader = new ConfigurationClassBeanDefinitionReader(
          registry, this.sourceExtractor, this.problemReporter, this.metadataReaderFactory,
          this.resourceLoader, this.environment, this.importBeanNameGenerator);
    }
    this.reader.loadBeanDefinitions(parser.getConfigurationClasses());

    // Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
    if (singletonRegistry != null) {
      if (!singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
        singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
      }
    }

    if (this.metadataReaderFactory instanceof CachingMetadataReaderFactory) {
      ((CachingMetadataReaderFactory) this.metadataReaderFactory).clearCache();
View Full Code Here


    if (configCandidates.isEmpty()) {
      return;
    }

    // Detect any custom bean name generation strategy supplied through the enclosing application context
    SingletonBeanRegistry singletonRegistry = null;
    if (registry instanceof SingletonBeanRegistry) {
      singletonRegistry = (SingletonBeanRegistry) registry;
      if (!this.localBeanNameGeneratorSet && singletonRegistry.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) {
        BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR);
        this.componentScanBeanNameGenerator = generator;
        this.importBeanNameGenerator = generator;
      }
    }

    // Parse each @Configuration class
    ConfigurationClassParser parser = new ConfigurationClassParser(
        this.metadataReaderFactory, this.problemReporter, this.environment,
        this.resourceLoader, this.componentScanBeanNameGenerator, registry);

    Set<ConfigurationClass> alreadyParsed = new HashSet<ConfigurationClass>(configCandidates.size());
    do {
      parser.parse(configCandidates);
      parser.validate();

      Set<ConfigurationClass> configClasses = new LinkedHashSet<ConfigurationClass>(parser.getConfigurationClasses());
      configClasses.removeAll(alreadyParsed);

      // Read the model and create bean definitions based on its content
      if (this.reader == null) {
        this.reader = new ConfigurationClassBeanDefinitionReader(registry, this.sourceExtractor,
            this.problemReporter, this.metadataReaderFactory, this.resourceLoader, this.environment,
            this.importBeanNameGenerator, parser.getImportRegistry());
      }
      this.reader.loadBeanDefinitions(configClasses);
      alreadyParsed.addAll(configClasses);

      configCandidates.clear();
      if (registry.getBeanDefinitionCount() > candidateNames.length) {
        String[] newCandidateNames = registry.getBeanDefinitionNames();
        Set<String> oldCandidateNames = new HashSet<String>(Arrays.asList(candidateNames));
        Set<String> alreadyParsedClasses = new HashSet<String>();
        for (ConfigurationClass configurationClass : alreadyParsed) {
          alreadyParsedClasses.add(configurationClass.getMetadata().getClassName());
        }
        for (String candidateName : newCandidateNames) {
          if (!oldCandidateNames.contains(candidateName)) {
            BeanDefinition beanDef = registry.getBeanDefinition(candidateName);
            if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory)
                && !alreadyParsedClasses.contains(beanDef.getBeanClassName())) {
              configCandidates.add(new BeanDefinitionHolder(beanDef, candidateName));
            }
          }
        }
        candidateNames = newCandidateNames;
      }
    }
    while (!configCandidates.isEmpty());

    // Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
    if (singletonRegistry != null) {
      if (!singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
        singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
      }
    }

    if (this.metadataReaderFactory instanceof CachingMetadataReaderFactory) {
      ((CachingMetadataReaderFactory) this.metadataReaderFactory).clearCache();
View Full Code Here

TOP

Related Classes of org.springframework.beans.factory.config.SingletonBeanRegistry

Copyright © 2018 www.massapicom. 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.