Examples of AnnotationAttributes


Examples of org.springframework.core.annotation.AnnotationAttributes

    }
    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

Examples of org.springframework.core.annotation.AnnotationAttributes

   * {@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

Examples of org.springframework.core.annotation.AnnotationAttributes

          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

Examples of org.springframework.core.annotation.AnnotationAttributes

    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

Examples of org.springframework.core.annotation.AnnotationAttributes

    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

Examples of org.springframework.core.annotation.AnnotationAttributes

  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

Examples of org.springframework.core.annotation.AnnotationAttributes

  @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

Examples of org.springframework.core.annotation.AnnotationAttributes

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

    // Consider name and any aliases
    AnnotationAttributes bean = AnnotationConfigUtils.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 effectively been overridden before (e.g. via XML)?
    if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
      return;
    }

    AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);

    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 = AnnotationConfigUtils.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

Examples of org.springframework.core.annotation.AnnotationAttributes

            "]. Reason: Environment must implement ConfigurableEnvironment");
      }
    }

    // Process any @ComponentScan annotations
    AnnotationAttributes componentScan = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ComponentScan.class);
    if (componentScan != null && !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
      // The config class is annotated with @ComponentScan -> perform the scan immediately
      Set<BeanDefinitionHolder> scannedBeanDefinitions =
          this.componentScanParser.parse(componentScan, sourceClass.getMetadata().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)) {
          parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
        }
      }
    }

    // Process any @Import annotations
    processImports(configClass, sourceClass, getImports(sourceClass), true, false);

    // Process any @ImportResource annotations
    if (sourceClass.getMetadata().isAnnotated(ImportResource.class.getName())) {
      AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClass.getMetadata(), ImportResource.class);
      String[] resources = importResource.getStringArray("value");
      Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader");
      for (String resource : resources) {
        String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
        configClass.addImportedResource(resolvedResource, readerClass);
      }
    }
View Full Code Here

Examples of org.springframework.core.annotation.AnnotationAttributes

  protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
    AnnotationMetadata amd = annotatedDef.getMetadata();
    Set<String> types = amd.getAnnotationTypes();
    String beanName = null;
    for (String type : types) {
      AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(amd, type);
      if (isStereotypeWithNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
        Object value = attributes.get("value");
        if (value instanceof String) {
          String strVal = (String) value;
          if (StringUtils.hasLength(strVal)) {
            if (beanName != null && !strVal.equals(beanName)) {
              throw new IllegalStateException("Stereotype annotations suggest inconsistent " +
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.