Package org.springframework.core.annotation

Examples of org.springframework.core.annotation.AnnotationAttributes


      if (tf.match(metadataReader, this.metadataReaderFactory)) {
        AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
        if (!metadata.isAnnotated(Profile.class.getName())) {
          return true;
        }
        AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
        return this.environment.acceptsProfiles(profile.getStringArray("value"));
      }
    }
    return false;
  }
View Full Code Here


  }

  protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
    AnnotationMetadata metadata = configClass.getMetadata();
    if (this.environment != null && metadata.isAnnotated(Profile.class.getName())) {
      AnnotationAttributes profile = MetadataUtils.attributesFor(metadata, Profile.class);
      if (!this.environment.acceptsProfiles(profile.getStringArray("value"))) {
        return;
      }
    }

    // recursively process the configuration class and its superclass hierarchy
View Full Code Here

        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);
      }
    }
View Full Code Here

    }
    beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
    beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);

    // consider role
    AnnotationAttributes role = attributesFor(metadata, Role.class);
    if (role != null) {
      beanDef.setRole(role.<Integer>getNumber("value"));
    }

    // consider name and any aliases
    AnnotationAttributes bean = attributesFor(metadata, Bean.class);
    List<String> names = new ArrayList<String>(Arrays.asList(bean.getStringArray("name")));
    String beanName = (names.size() > 0 ? names.remove(0) : beanMethod.getMetadata().getMethodName());
    for (String alias : names) {
      this.registry.registerAlias(beanName, alias);
    }

    // has this already been overridden (e.g. via XML)?
    if (this.registry.containsBeanDefinition(beanName)) {
      BeanDefinition existingBeanDef = registry.getBeanDefinition(beanName);
      // is the existing bean definition one that was created from a configuration class?
      if (!(existingBeanDef instanceof ConfigurationClassBeanDefinition)) {
        // no -> then it's an external override, probably XML
        // overriding is legal, return immediately
        if (logger.isDebugEnabled()) {
          logger.debug(String.format("Skipping loading bean definition for %s: a definition for bean " +
              "'%s' already exists. This is likely due to an override in XML.", beanMethod, beanName));
        }
        return;
      }
    }

    if (metadata.isAnnotated(Primary.class.getName())) {
      beanDef.setPrimary(true);
    }

    // is this bean to be instantiated lazily?
    if (metadata.isAnnotated(Lazy.class.getName())) {
      AnnotationAttributes lazy = attributesFor(metadata, Lazy.class);
      beanDef.setLazyInit(lazy.getBoolean("value"));
    }
    else if (configClass.getMetadata().isAnnotated(Lazy.class.getName())){
      AnnotationAttributes lazy = attributesFor(configClass.getMetadata(), Lazy.class);
      beanDef.setLazyInit(lazy.getBoolean("value"));
    }

    if (metadata.isAnnotated(DependsOn.class.getName())) {
      AnnotationAttributes dependsOn = attributesFor(metadata, DependsOn.class);
      String[] otherBeans = dependsOn.getStringArray("value");
      if (otherBeans.length > 0) {
        beanDef.setDependsOn(otherBeans);
      }
    }

    Autowire autowire = bean.getEnum("autowire");
    if (autowire.isAutowire()) {
      beanDef.setAutowireMode(autowire.value());
    }

    String initMethodName = bean.getString("initMethod");
    if (StringUtils.hasText(initMethodName)) {
      beanDef.setInitMethodName(initMethodName);
    }

    String destroyMethodName = bean.getString("destroyMethod");
    if (StringUtils.hasText(destroyMethodName)) {
      beanDef.setDestroyMethodName(destroyMethodName);
    }

    // consider scoping
    ScopedProxyMode proxyMode = ScopedProxyMode.NO;
    AnnotationAttributes scope = attributesFor(metadata, Scope.class);
    if (scope != null) {
      beanDef.setScope(scope.getString("value"));
      proxyMode = scope.getEnum("proxyMode");
      if (proxyMode == ScopedProxyMode.DEFAULT) {
        proxyMode = ScopedProxyMode.NO;
      }
    }
View Full Code Here

   * {@link org.springframework.data.simpledb.repository.support.SimpleDbRepositoryFactoryBean}. <br/>
   * The bean will be used to construct repository implementations. <br/>
   */
  @Override
  public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {
    AnnotationAttributes attributes = config.getAttributes();
        builder.addPropertyReference("simpleDbOperations", attributes.getString("simpleDbTemplateRef"));
  }
View Full Code Here

          Constructor<?>[] rawCandidates = beanClass.getDeclaredConstructors();
          List<Constructor<?>> candidates = new ArrayList<Constructor<?>>(rawCandidates.length);
          Constructor<?> requiredConstructor = null;
          Constructor<?> defaultConstructor = null;
          for (Constructor<?> candidate : rawCandidates) {
            AnnotationAttributes annotation = findAutowiredAnnotation(candidate);
            if (annotation != null) {
              if (requiredConstructor != null) {
                throw new BeanCreationException(beanName,
                    "Invalid autowire-marked constructor: " + candidate +
                    ". Found constructor with 'required' Autowired annotation already: " +
View Full Code Here

    Class<?> targetClass = clazz;

    do {
      LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<InjectionMetadata.InjectedElement>();
      for (Field field : targetClass.getDeclaredFields()) {
        AnnotationAttributes annotation = findAutowiredAnnotation(field);
        if (annotation != null) {
          if (Modifier.isStatic(field.getModifiers())) {
            if (logger.isWarnEnabled()) {
              logger.warn("Autowired annotation is not supported on static fields: " + field);
            }
            continue;
          }
          boolean required = determineRequiredStatus(annotation);
          currElements.add(new AutowiredFieldElement(field, required));
        }
      }
      for (Method method : targetClass.getDeclaredMethods()) {
        AnnotationAttributes ann = null;
        Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
        if (BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
          ann = findAutowiredAnnotation(bridgedMethod);
        }
        else if (!method.isBridge()) {
View Full Code Here

    return new InjectionMetadata(clazz, elements);
  }

  private AnnotationAttributes findAutowiredAnnotation(AccessibleObject ao) {
    for (Class<? extends Annotation> type : this.autowiredAnnotationTypes) {
      AnnotationAttributes annotation = AnnotatedElementUtils.getAnnotationAttributes(ao, type.getName());
      if (annotation != null) {
        return annotation;
      }
    }
    return null;
View Full Code Here

  public void registerBeanDefinitions(
      AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

    AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);

    AnnotationAttributes enableAJAutoProxy =
        AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
    if (enableAJAutoProxy.getBoolean("proxyTargetClass")) {
      AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
    }
  }
View Full Code Here

  @Override
  public ScopeMetadata resolveScopeMetadata(BeanDefinition definition) {
    ScopeMetadata metadata = new ScopeMetadata();
    if (definition instanceof AnnotatedBeanDefinition) {
      AnnotatedBeanDefinition annDef = (AnnotatedBeanDefinition) definition;
      AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(annDef.getMetadata(), this.scopeAnnotationType);
      if (attributes != null) {
        metadata.setScopeName(attributes.getString("value"));
        ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
        if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
          proxyMode = this.defaultProxyMode;
        }
        metadata.setScopedProxyMode(proxyMode);
      }
View Full Code Here

TOP

Related Classes of org.springframework.core.annotation.AnnotationAttributes

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.