Package org.springframework.core.annotation

Examples of org.springframework.core.annotation.AnnotationAttributes


    if (original == null) {
      return null;
    }

    AnnotationAttributes result = new AnnotationAttributes(original.size());
    for (Map.Entry<String, Object> entry : original.entrySet()) {
      try {
        Object value = entry.getValue();
        if (value instanceof AnnotationAttributes) {
          value = convertClassValues(classLoader, (AnnotationAttributes) value, classValuesAsString);
        }
        else if (value instanceof AnnotationAttributes[]) {
          AnnotationAttributes[] values = (AnnotationAttributes[]) value;
          for (int i = 0; i < values.length; i++) {
            values[i] = convertClassValues(classLoader, values[i], classValuesAsString);
          }
        }
        else if (value instanceof Type) {
          value = (classValuesAsString ? ((Type) value).getClassName()
              : classLoader.loadClass(((Type) value).getClassName()));
        }
        else if (value instanceof Type[]) {
          Type[] array = (Type[]) value;
          Object[] convArray = (classValuesAsString ? new String[array.length] : new Class<?>[array.length]);
          for (int i = 0; i < array.length; i++) {
            convArray[i] = (classValuesAsString ? array[i].getClassName()
                : classLoader.loadClass(array[i].getClassName()));
          }
          value = convArray;
        }
        else if (classValuesAsString) {
          if (value instanceof Class) {
            value = ((Class<?>) value).getName();
          }
          else if (value instanceof Class[]) {
            Class<?>[] clazzArray = (Class[]) value;
            String[] newValue = new String[clazzArray.length];
            for (int i = 0; i < clazzArray.length; i++) {
              newValue[i] = clazzArray[i].getName();
            }
            value = newValue;
          }
        }
        result.put(entry.getKey(), value);
      }
      catch (Exception ex) {
        // Class not found - can't resolve class reference in annotation
        // attribute.
      }
View Full Code Here


    // To start with, we populate the results with a copy of all attribute
    // values from the target annotation. A copy is necessary so that we do
    // not inadvertently mutate the state of the metadata passed to this
    // method.
    AnnotationAttributes results = new AnnotationAttributes(attributesList.get(0));

    Set<String> overridableAttributeNames = new HashSet<String>(results.keySet());
    overridableAttributeNames.remove(AnnotationUtils.VALUE);

    // Since the map is a LinkedMultiValueMap, we depend on the ordering of
    // elements in the map and reverse the order of the keys in order to traverse
    // "down" the annotation hierarchy.
    List<String> annotationTypes = new ArrayList<String>(attributesMap.keySet());
    Collections.reverse(annotationTypes);

    // No need to revisit the target annotation type:
    annotationTypes.remove(annotationType);

    for (String currentAnnotationType : annotationTypes) {
      List<AnnotationAttributes> currentAttributesList = attributesMap.get(currentAnnotationType);
      if (currentAttributesList != null && !currentAttributesList.isEmpty()) {
        Set<String> metaAnns = metaAnnotationMap.get(currentAnnotationType);
        if (metaAnns != null && metaAnns.contains(annotationType)) {
          AnnotationAttributes currentAttributes = currentAttributesList.get(0);
          for (String overridableAttributeName : overridableAttributeNames) {
            Object value = currentAttributes.get(overridableAttributeName);
            if (value != null) {
              // Store the value, potentially overriding a value from an
              // attribute of the same name found higher in the annotation
              // hierarchy.
              results.put(overridableAttributeName, value);
View Full Code Here

    return getAnnotationAttributes(annotationType, false);
  }

  @Override
  public AnnotationAttributes getAnnotationAttributes(String annotationType, boolean classValuesAsString) {
    AnnotationAttributes raw = AnnotationReadingVisitorUtils.getMergedAnnotationAttributes(
        this.attributesMap, this.metaAnnotationMap, annotationType);
    return AnnotationReadingVisitorUtils.convertClassValues(this.classLoader, raw, classValuesAsString);
  }
View Full Code Here

    ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
    AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
    assertThat("import metadata was not injected", importMetadata, notNullValue());
    assertThat(importMetadata.getClassName(), is(ImportingConfig.class.getName()));
    AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
    Class<?>[] importedClasses = importAttribs.getClassArray("value");
    assertThat(importedClasses[0].getName(), is(ImportedConfig.class.getName()));
  }
View Full Code Here

    ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
    AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
    assertThat("import metadata was not injected", importMetadata, notNullValue());
    assertThat(importMetadata.getClassName(), is(IndirectlyImportingConfig.class.getName()));
    AnnotationAttributes enableAttribs = AnnotationConfigUtils.attributesFor(importMetadata, EnableImportedConfig.class);
    String foo = enableAttribs.getString("foo");
    assertThat(foo, is("xyz"));
  }
View Full Code Here

  static class MetaConditionalFilter implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
      AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(MetaConditional.class.getName()));
      assertThat(attributes.getString("value"), equalTo("test"));
      return true;
    }
View Full Code Here

   * {@link Timed @Timed} annotation on the supplied
   * {@link FrameworkMethod test method}.
   * @return the timeout, or {@code 0} if none was specified.
   */
  protected long getSpringTimeout(FrameworkMethod frameworkMethod) {
    AnnotationAttributes annAttrs = AnnotatedElementUtils.getAnnotationAttributes(frameworkMethod.getMethod(),
      Timed.class.getName());
    if (annAttrs == null) {
      return 0;
    }
    else {
      long millis = annAttrs.<Long> getNumber("millis").longValue();
      return millis > 0 ? millis : 0;
    }
  }
View Full Code Here

  private ProxyConfig proxyConfig;

  @Override
  public void setImportMetadata(AnnotationMetadata importMetadata) {
    final AnnotationAttributes enableMetrics = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(EnableMetrics.class.getName(), false));
    Assert.notNull(enableMetrics, "@" + EnableMetrics.class.getSimpleName() + " is not present on importing class " + importMetadata.getClassName());

    this.proxyConfig = new ProxyConfig();
    this.proxyConfig.setExposeProxy(enableMetrics.getBoolean("exposeProxy"));
    this.proxyConfig.setProxyTargetClass(enableMetrics.getBoolean("proxyTargetClass"));
  }
View Full Code Here

   * 'true' as is done in the main test above.
   */
  @Test
  public void standardAnnotationMetadata_nestedAnnotationsAsMap_false() throws Exception {
    AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class);
    AnnotationAttributes specialAttrs = (AnnotationAttributes) metadata.getAnnotationAttributes(SpecialAttr.class.getName());
    Annotation[] nestedAnnoArray = (Annotation[]) specialAttrs.get("nestedAnnoArray");
    assertThat(nestedAnnoArray[0], instanceOf(NestedAnno.class));
  }
View Full Code Here

    AnnotationMetadata metadata = metadataReader.getAnnotationMetadata();
    assertMetaAnnotationOverrides(metadata);
  }

  private void assertMetaAnnotationOverrides(AnnotationMetadata metadata) {
    AnnotationAttributes attributes = (AnnotationAttributes) metadata.getAnnotationAttributes(
      TestComponentScan.class.getName(), false);
    String[] basePackages = attributes.getStringArray("basePackages");
    assertThat("length of basePackages[]", basePackages.length, is(1));
    assertThat("basePackages[0]", basePackages[0], is("org.example.componentscan"));
    String[] value = attributes.getStringArray("value");
    assertThat("length of value[]", value.length, is(0));
    Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
    assertThat("length of basePackageClasses[]", basePackageClasses.length, is(0));
  }
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.