Java Code Examples for org.springframework.core.annotation.AnnotationAttributes

The following are top voted examples for showing how to use org.springframework.core.annotation.AnnotationAttributes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Your-Microservice   File: YourMicroserviceBeanConfiguration.java   View source code 6 votes vote down vote up
/**
 * selectImports
 * <p>
 * Provides a configuration list of additional Import which should be performed to
 * implement the applicable configuration.
 *
 * @param importingClassMetadata Annotations Metadata to use to construct Imports.
 * @return String Array of Configuration Imports.
 */
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes =
            AnnotationAttributes.fromMap(
                    importingClassMetadata.getAnnotationAttributes(EnableYourMicroservice.class.getName(), false));
    String environmentType = attributes.getString("environmentType");
    LOGGER.info("Using specified EnvironmentType:[{}]", environmentType);
    /**
     *  Create our necessary Imports.
     */
    return new String[]{
            YourMicroserviceEnvironmentConfiguration.class.getName()

            // Add Security Import as Applicable ...
    };

}
 
Example 2
Project: spring-data-snowdrop   File: JpaWithSnowdropRegistrar.java   View source code 6 votes vote down vote up
private BeanDefinition buildPostProcessorDefinition(AnnotationMetadata importMetadata, AnnotationAttributes attributes) {
  SnowdropRepositoryConfigExtension extension = new SnowdropRepositoryConfigExtension();
  BeanDefinitionBuilder builder = BeanDefinitionBuilder
          .rootBeanDefinition(JpaRepositoryFactoryBeanSnowdropPostProcessor.class);

  builder.getRawBeanDefinition().setSource(importMetadata);

  builder.addPropertyValue("queryLookupStrategyKey", attributes.get(QUERY_LOOKUP_STRATEGY));

  NamedQueriesBeanDefinitionBuilder definitionBuilder = new NamedQueriesBeanDefinitionBuilder(
          extension.getDefaultNamedQueryLocation());

  String namedQueriesLocation = attributes.getString(NAMED_QUERIES_LOCATION);
  if (StringUtils.hasText(namedQueriesLocation)) {
    definitionBuilder.setLocations(namedQueriesLocation);
  }
  builder.addPropertyValue("namedQueriesLocation", definitionBuilder.build(importMetadata));

  return builder.getBeanDefinition();
}
 
Example 3
Project: lams   File: AnnotationScopeMetadataResolver.java   View source code 6 votes vote down vote up
@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);
		}
	}
	return metadata;
}
 
Example 4
Project: lams   File: AnnotationBeanNameGenerator.java   View source code 6 votes vote down vote up
/**
 * Derive a bean name from one of the annotations on the class.
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
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 " +
								"component names: '" + beanName + "' versus '" + strVal + "'");
					}
					beanName = strVal;
				}
			}
		}
	}
	return beanName;
}
 
Example 5
Project: spring-backend-boilerplate   File: EnableMenuImportSelector.java   View source code 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
	AnnotationAttributes enableMenu = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMenu.class
																											.getName(),
																									false));

	if (enableMenu != null) {
		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(DefaultMenuPlugin.class);
		AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

		MutablePropertyValues mutablePropertyValues = new MutablePropertyValues();
		mutablePropertyValues.add("extensionPointId", enableMenu.getString("extensionPointId"));
		mutablePropertyValues.add("pluginId", enableMenu.getString("pluginId"));
		mutablePropertyValues.add("menu", toMenu(enableMenu.getAnnotationArray("menu")));
		beanDefinition.setPropertyValues(mutablePropertyValues);

		registry.registerBeanDefinition("menuPlugin:" + enableMenu.getString("pluginId"), beanDefinition);
	}
}
 
Example 6
Project: spring-backend-boilerplate   File: EnableMenuImportSelector.java   View source code 6 votes vote down vote up
private Map<String,Object> toMetadata(AnnotationAttributes[] metadatas) {
	if (metadatas == null) {
		return new HashMap<>();
	}

	return Stream.of(metadatas).collect(Collectors.toMap(item -> item.getString("key"), item -> {
		Metadata.ValueType valueType = item.getEnum("type");
		switch (valueType) {
			case Boolean:
				return item.getBoolean("value");
			case Short:
			case Integer:
			case Long:
				return item.getNumber("value");
			case BigDecimal:
				return new BigDecimal(item.getString("value"));
			default:
				return item.getString("value");
		}
	}));
}
 
Example 7
Project: holon-core   File: AbstractRepeatableAnnotationRegistrar.java   View source code 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
	// Single annotation
	if (annotationMetadata.isAnnotated(repeatableAnnotation.getName())) {
		register(annotationMetadata.getAnnotationAttributes(repeatableAnnotation.getName()), registry, false);
	} else if (annotationMetadata.isAnnotated(repeatableAnnotationContainer.getName())) {
		// Multiple annotations
		Map<String, Object> attributes = annotationMetadata
				.getAnnotationAttributes(repeatableAnnotationContainer.getName());
		AnnotationAttributes[] repetitions = (AnnotationAttributes[]) attributes.get("value");
		if (repetitions != null) {
			for (AnnotationAttributes repetition : repetitions) {
				register(repetition, registry, true);
			}
		}
	}
}
 
Example 8
Project: apollo-custom   File: ApolloConfigRegistrar.java   View source code 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata
      .getAnnotationAttributes(EnableApolloConfig.class.getName()));
  String[] namespaces = attributes.getStringArray("value");
  int order = attributes.getNumber("order");
  PropertySourcesProcessor.addNamespaces(Lists.newArrayList(namespaces), order);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesPlaceholderConfigurer.class.getName(),
      PropertySourcesPlaceholderConfigurer.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, PropertySourcesProcessor.class.getName(),
      PropertySourcesProcessor.class);

  BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, ApolloAnnotationProcessor.class.getName(),
      ApolloAnnotationProcessor.class);
}
 
Example 9
Project: lodsve-framework   File: CacheImportSelector.java   View source code 6 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableCache.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableCache.class.getName(), importingClassMetadata.getClassName()));

    CacheMode cacheMode = attributes.getEnum(CACHE_MODE_ATTRIBUTE_NAME);

    if (cacheMode == CacheMode.EHCAHE) {
        return new String[]{EhcacheCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.GUAVA) {
        return new String[]{GuavaCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.REDIS) {
        return new String[]{RedisCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.MEMCACHED) {
        return new String[]{MemcachedCacheConfiguration.class.getName()};
    } else if (cacheMode == CacheMode.OSCACHE) {
        return new String[]{OscacheCacheConfiguration.class.getName()};
    }

    return new String[0];
}
 
Example 10
Project: lodsve-framework   File: SearchConfigurationSelector.java   View source code 6 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableSearch.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableSearch.class.getName(), importingClassMetadata.getClassName()));

    List<String> imports = new ArrayList<>();

    SearchType searchType = attributes.getEnum(SEARCH_TYPE_ATTRIBUTE_NAME);
    if (SearchType.SOLR.equals(searchType)) {
        imports.add(SolrConfiguration.class.getName());
    } else if (SearchType.LUCENE.equals(searchType)) {
        imports.add(LuceneConfiguration.class.getName());
    }

    return imports.toArray(new String[imports.size()]);
}
 
Example 11
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: EntityScanRegistrar.java   View source code 6 votes vote down vote up
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes
			.fromMap(metadata.getAnnotationAttributes(EntityScan.class.getName()));
	String[] basePackages = attributes.getAliasedStringArray("basePackages",
			EntityScan.class, metadata.getClassName());
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	Set<String> packagesToScan = new LinkedHashSet<String>();
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	if (packagesToScan.isEmpty()) {
		return Collections
				.singleton(ClassUtils.getPackageName(metadata.getClassName()));
	}
	return packagesToScan;
}
 
Example 12
Project: lodsve-framework   File: MongoBeanDefinitionRegistrar.java   View source code 6 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMongo.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableMongo.class.getName(), metadata.getClassName()));

    String[] domainPackage = attributes.getStringArray(DOMAIN_PACKAGES_ATTRIBUTE_NAME);
    if (ArrayUtils.isEmpty(domainPackage)) {
        domainPackage = findDefaultPackage(metadata);
    }

    String[] basePackages = attributes.getStringArray(BASE_PACKAGES_ATTRIBUTE_NAME);
    if (ArrayUtils.isEmpty(basePackages)) {
        domainPackage = findDefaultPackage(metadata);
    }

    initMongoDataSource(attributes);
    initMongoMappingContext(domainPackage);
    initMappingContextIsNewStrategyFactory();
    initMappingConverter();
    initMongoPersistentEntityIndexCreator();
    initMongoTemplate();
    initMongoRepositoryFactory();
    initMongoRepository(metadata, registry);

    BeanRegisterUtils.registerBeans(BEAN_DEFINITION_MAP, registry);
}
 
Example 13
Project: spring   File: AnnotationScopeMetadataResolver.java   View source code 6 votes vote down vote up
@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.getAliasedString("value", this.scopeAnnotationType, definition.getSource()));
			ScopedProxyMode proxyMode = attributes.getEnum("proxyMode");
			if (proxyMode == null || proxyMode == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
Example 14
Project: spring4-understanding   File: AdviceModeImportSelector.java   View source code 6 votes vote down vote up
/**
 * This implementation resolves the type of annotation from generic metadata and
 * validates that (a) the annotation is in fact present on the importing
 * {@code @Configuration} class and (b) that the given annotation has an
 * {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
 * {@link AdviceMode}.
 * <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
 * concrete implementation to choose imports in a safe and convenient fashion.
 * @throws IllegalArgumentException if expected annotation {@code A} is not present
 * on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
 * returns {@code null}
 */
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
	Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
	if (attributes == null) {
		throw new IllegalArgumentException(String.format(
			"@%s is not present on importing class '%s' as expected",
			annoType.getSimpleName(), importingClassMetadata.getClassName()));
	}

	AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	if (imports == null) {
		throw new IllegalArgumentException(String.format("Unknown AdviceMode: '%s'", adviceMode));
	}
	return imports;
}
 
Example 15
Project: spring-boot-concourse   File: EnableAutoConfigurationImportSelector.java   View source code 6 votes vote down vote up
@Override
public String[] selectImports(AnnotationMetadata metadata) {
	if (!isEnabled(metadata)) {
		return NO_IMPORTS;
	}
	try {
		AnnotationAttributes attributes = getAttributes(metadata);
		List<String> configurations = getCandidateConfigurations(metadata,
				attributes);
		configurations = removeDuplicates(configurations);
		Set<String> exclusions = getExclusions(metadata, attributes);
		configurations.removeAll(exclusions);
		configurations = sort(configurations);
		recordWithConditionEvaluationReport(configurations, exclusions);
		return configurations.toArray(new String[configurations.size()]);
	}
	catch (IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example 16
Project: spring4-understanding   File: AnnotationBeanNameGenerator.java   View source code 6 votes vote down vote up
/**
 * Derive a bean name from one of the annotations on the class.
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
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 " +
								"component names: '" + beanName + "' versus '" + strVal + "'");
					}
					beanName = strVal;
				}
			}
		}
	}
	return beanName;
}
 
Example 17
Project: spring4-understanding   File: AnnotationAttributesReadingVisitor.java   View source code 6 votes vote down vote up
@Override
public void doVisitEnd(Class<?> annotationClass) {
	super.doVisitEnd(annotationClass);
	List<AnnotationAttributes> attributes = this.attributesMap.get(this.annotationType);
	if (attributes == null) {
		this.attributesMap.add(this.annotationType, this.attributes);
	}
	else {
		attributes.add(0, this.attributes);
	}
	Set<String> metaAnnotationTypeNames = new LinkedHashSet<String>();
	Annotation[] metaAnnotations = AnnotationUtils.getAnnotations(annotationClass);
	if (!ObjectUtils.isEmpty(metaAnnotations)) {
		for (Annotation metaAnnotation : metaAnnotations) {
			if (!AnnotationUtils.isInJavaLangAnnotationPackage(metaAnnotation)) {
				recursivelyCollectMetaAnnotations(metaAnnotationTypeNames, metaAnnotation);
			}
		}
	}
	if (this.metaAnnotationMap != null) {
		this.metaAnnotationMap.put(annotationClass.getName(), metaAnnotationTypeNames);
	}
}
 
Example 18
Project: spring4-understanding   File: AnnotationMetadataTests.java   View source code 6 votes vote down vote up
private void assertMultipleAnnotationsWithIdenticalAttributeNames(AnnotationMetadata metadata) {
	AnnotationAttributes attributes1 = (AnnotationAttributes) metadata.getAnnotationAttributes(
			NamedAnnotation1.class.getName(), false);
	String name1 = attributes1.getString("name");
	assertThat("name of NamedAnnotation1", name1, is("name 1"));

	AnnotationAttributes attributes2 = (AnnotationAttributes) metadata.getAnnotationAttributes(
			NamedAnnotation2.class.getName(), false);
	String name2 = attributes2.getString("name");
	assertThat("name of NamedAnnotation2", name2, is("name 2"));

	AnnotationAttributes attributes3 = (AnnotationAttributes) metadata.getAnnotationAttributes(
			NamedAnnotation3.class.getName(), false);
	String name3 = attributes3.getString("name");
	assertThat("name of NamedAnnotation3", name3, is("name 3"));
}
 
Example 19
Project: spring-content   File: StoreUtils.java   View source code 6 votes vote down vote up
public static String[] getBasePackages(AnnotationAttributes attributes, String[] defaultPackages) {
	
	String[] value = attributes.getStringArray("value");
	String[] basePackages = attributes.getStringArray(BASE_PACKAGES);
	Class<?>[] basePackageClasses = attributes.getClassArray(BASE_PACKAGE_CLASSES);

	// Default configuration - return package of annotated class
	if (value.length == 0 && basePackages.length == 0 && basePackageClasses.length == 0) {
		return defaultPackages;
	}

	Set<String> packages = new HashSet<String>();
	packages.addAll(Arrays.asList(value));
	packages.addAll(Arrays.asList(basePackages));

	for (Class<?> typeName : basePackageClasses) {
		packages.add(ClassUtils.getPackageName(typeName));
	}

	return packages.toArray(new String[] {});
}
 
Example 20
Project: my-spring-cache-redis   File: AnnotationScopeMetadataResolver.java   View source code 6 votes vote down vote up
@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);
		}
	}
	return metadata;
}
 
Example 21
Project: my-spring-cache-redis   File: AnnotationBeanNameGenerator.java   View source code 6 votes vote down vote up
/**
 * Derive a bean name from one of the annotations on the class.
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
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 " +
								"component names: '" + beanName + "' versus '" + strVal + "'");
					}
					beanName = strVal;
				}
			}
		}
	}
	return beanName;
}
 
Example 22
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: ServletComponentScanRegistrar.java   View source code 6 votes vote down vote up
private Set<String> getPackagesToScan(AnnotationMetadata metadata) {
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(
			metadata.getAnnotationAttributes(ServletComponentScan.class.getName()));
	String[] basePackages = attributes.getStringArray("basePackages");
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	Set<String> packagesToScan = new LinkedHashSet<String>();
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	if (packagesToScan.isEmpty()) {
		return Collections
				.singleton(ClassUtils.getPackageName(metadata.getClassName()));
	}
	return packagesToScan;
}
 
Example 23
Project: cereebro   File: OnEnabledDetectorCondition.java   View source code 5 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(ConditionalOnEnabledDetector.class.getName()));
    final String name = attributes.getString("value");
    final String prefix = attributes.getString("prefix");
    RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(context.getEnvironment(),
            prefix + "." + name + ".");
    Boolean enabled = resolver.getProperty("enabled", Boolean.class, true);
    return new ConditionOutcome(enabled, ConditionMessage.forCondition(ConditionalOnEnabledDetector.class, name)
            .because(enabled ? "enabled" : "disabled"));
}
 
Example 24
Project: cereebro   File: RelationshipHintsAnnotationRelationshipDetector.java   View source code 5 votes vote down vote up
@Override
protected Set<Relationship> extractFromAnnotationAttributes(Map<String, Object> annotationAttributes) {
    Set<Relationship> result = new HashSet<>();
    AnnotationAttributes[] dependencies = (AnnotationAttributes[]) annotationAttributes.get("dependencies");
    for (AnnotationAttributes dependency : dependencies) {
        result.add(Dependency.on(component(dependency)));
    }
    AnnotationAttributes[] consumers = (AnnotationAttributes[]) annotationAttributes.get("consumers");
    for (AnnotationAttributes consumer : consumers) {
        result.add(Consumer.by(component(consumer)));
    }
    return result;
}
 
Example 25
Project: JRediClients   File: RedissonHttpSessionConfiguration.java   View source code 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableRedissonHttpSession.class.getName());
    AnnotationAttributes attrs = AnnotationAttributes.fromMap(map);
    keyPrefix = attrs.getString("keyPrefix");
    maxInactiveIntervalInSeconds = attrs.getNumber("maxInactiveIntervalInSeconds");
}
 
Example 26
Project: spring-data-generator   File: ScanningConfigurationSupport.java   View source code 5 votes vote down vote up
public ScanningConfigurationSupport(AnnotationMetadata annotationMetadata, AnnotationAttributes attributes, Environment environment){
    Assert.notNull(environment, "Environment must not be null!");
    Assert.notNull(environment, "AnnotationMetadata must not be null!");
    this.environment = environment;
    this.attributes = attributes;
    this.annotationMetadata = annotationMetadata;
    this.entityPackage = this.attributes.getStringArray("entityPackage");
    this.onlyAnnotations = this.attributes.getBoolean("onlyAnnotations");
}
 
Example 27
Project: spring-data-generator   File: AbstractTemplateProvider.java   View source code 5 votes vote down vote up
public AbstractTemplateProvider(AnnotationAttributes attributes) {
    Assert.notNull(attributes, "AnnotationAttributes must not be null!");
    this.excludeClasses = attributes.getClassArray(getExcludeClasses());
    this.postfix = attributes.getString(getPostfix());
    this.debug = attributes.getBoolean("debug");
    this.overwrite = attributes.getBoolean("overwrite");
    if (excludeClasses.length > 0 && debug) {
        SDLogger.debug(String.format("Exclude %s %s in the %s generator", excludeClasses.length, excludeClasses.length == 1 ? "entity":"entities", postfix));
    }
}
 
Example 28
Project: wamp2spring   File: WampConfiguration.java   View source code 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> attributes = AnnotationAttributes.fromMap(importMetadata
			.getAnnotationAttributes(EnableWamp.class.getName(), false));
	if (attributes != null) {
		Feature[] disableFeatures = (Feature[]) attributes.get("disable");
		if (disableFeatures != null) {
			for (Feature disableFeature : disableFeatures) {
				this.features.disable(disableFeature);
			}
		}
	}
}
 
Example 29
Project: Your-Microservice   File: YourMicroserviceBeanConfiguration.java   View source code 5 votes vote down vote up
/**
 * setImportMetadata
 *
 * @param importMetadata Annotations Metadata to validate...
 */
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableYourMicroservice.class.getName());
    this.enableYourMicroservice = AnnotationAttributes.fromMap(map);
    if (this.enableYourMicroservice == null) {
        String message =
                "@EnableYourMicroservice is not present on importing class " + importMetadata.getClassName();
        LOGGER.error(message);
        throw new IllegalArgumentException(message);
    }
}
 
Example 30
Project: azure-spring-boot   File: TestAutoConfigurationPackageRegistrar.java   View source code 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata metadata,
                                    BeanDefinitionRegistry registry) {
    final AnnotationAttributes attributes = AnnotationAttributes
            .fromMap(metadata.getAnnotationAttributes(
                    TestAutoConfigurationPackage.class.getName(), true));
    AutoConfigurationPackages.register(registry,
            ClassUtils.getPackageName(attributes.getString("value")));
}
 
Example 31
Project: spring-data-snowdrop   File: JpaWithSnowdropRegistrar.java   View source code 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata importMetadata, BeanDefinitionRegistry registry) {
  AnnotationAttributes attributes = AnnotationAttributes.fromMap(
          importMetadata.getAnnotationAttributes(JpaWithSnowdropConfiguration.class.getName(), false));
  if (attributes == null) {
    throw new IllegalArgumentException(
            "@JpaWithSnowdropConfiguration is not present on importing class " + importMetadata.getClassName());
  }
  registry.registerBeanDefinition(
          JpaRepositoryFactoryBeanSnowdropPostProcessor.class.getName(),
          buildPostProcessorDefinition(importMetadata, attributes)
  );
}
 
Example 32
Project: appstatus-spring-boot-starter   File: AbstractAppstatusImportAware.java   View source code 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata annotationMetadata) {
    Map<String, Object> map = annotationMetadata.getAnnotationAttributes(starterClass.getName());
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(map);

    initialize(attributes, new AppstatusConfigBuilder(attributes));
}
 
Example 33
Project: appstatus-spring-boot-starter   File: EnableAppStatusTestConfig.java   View source code 5 votes vote down vote up
@Override
protected void initialize(AnnotationAttributes attributes, AppstatusConfigBuilder configBuilder) {
    this.attributes = attributes;
    this.configuration = configBuilder.set("testAttribute", "testAttribute")
                                      .build();

}
 
Example 34
Project: appstatus-spring-boot-starter   File: AppStatusServiceConfig.java   View source code 5 votes vote down vote up
@Override
protected void initialize(AnnotationAttributes attributes, AppstatusConfigBuilder configBuilder) {
    this.configuration = configBuilder.set("services.log", "log")
                                      .set("services.log.format", "logFormat")
                                      .set("services.minMaxDelay", "minMaxDelay")
                                      .set("services.useThreadLocal", "useThreadLocal")
                                      .build();

    this.pointcuts = Arrays.asList(attributes.getStringArray("pointcuts"));
}
 
Example 35
Project: appstatus-spring-boot-starter   File: AppStatusBatchConfig.java   View source code 5 votes vote down vote up
@Override
protected void initialize(AnnotationAttributes attributes, AppstatusConfigBuilder builder) {
    this.configuration = builder.set("batch.logInterval", "logInterval")
                                .set("batch.zombieInterval", "zombieInterval")
                                .build();

    this.tableName = attributes.getString("tableName");
    this.daoClass = attributes.getClass("batchDaoClass");
}
 
Example 36
Project: lams   File: AbstractAsyncConfiguration.java   View source code 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableAsync = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
	Assert.notNull(this.enableAsync,
			"@EnableAsync is not present on importing class " + importMetadata.getClassName());
}
 
Example 37
Project: lams   File: JtaTransactionAnnotationParser.java   View source code 5 votes vote down vote up
@Override
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
	AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, javax.transaction.Transactional.class.getName());
	if (ann != null) {
		return parseTransactionAnnotation(ann);
	}
	else {
		return null;
	}
}
 
Example 38
Project: lams   File: SpringTransactionAnnotationParser.java   View source code 5 votes vote down vote up
@Override
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
	AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, Transactional.class.getName());
	if (ann != null) {
		return parseTransactionAnnotation(ann);
	}
	else {
		return null;
	}
}
 
Example 39
Project: lams   File: AbstractTransactionManagementConfiguration.java   View source code 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableTx = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableTransactionManagement.class.getName(), false));
	Assert.notNull(this.enableTx,
			"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
}
 
Example 40
Project: lams   File: AdviceModeImportSelector.java   View source code 5 votes vote down vote up
/**
 * This implementation resolves the type of annotation from generic metadata and
 * validates that (a) the annotation is in fact present on the importing
 * {@code @Configuration} class and (b) that the given annotation has an
 * {@linkplain #getAdviceModeAttributeName() advice mode attribute} of type
 * {@link AdviceMode}.
 * <p>The {@link #selectImports(AdviceMode)} method is then invoked, allowing the
 * concrete implementation to choose imports in a safe and convenient fashion.
 * @throws IllegalArgumentException if expected annotation {@code A} is not present
 * on the importing {@code @Configuration} class or if {@link #selectImports(AdviceMode)}
 * returns {@code null}
 */
@Override
public final String[] selectImports(AnnotationMetadata importingClassMetadata) {
	Class<?> annoType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
	Assert.notNull(attributes, String.format(
			"@%s is not present on importing class '%s' as expected",
			annoType.getSimpleName(), importingClassMetadata.getClassName()));

	AdviceMode adviceMode = attributes.getEnum(this.getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	Assert.notNull(imports, String.format("Unknown AdviceMode: '%s'", adviceMode));
	return imports;
}