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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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;
}
 
Example 41
Project: lams   File: AspectJAutoProxyRegistrar.java   Source Code and License 5 votes vote down vote up
/**
 * Register, escalate, and configure the AspectJ auto proxy creator based on the value
 * of the @{@link EnableAspectJAutoProxy#proxyTargetClass()} attribute on the importing
 * {@code @Configuration} class.
 */
@Override
public void registerBeanDefinitions(
		AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

	AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);

	AnnotationAttributes enableAJAutoProxy =
			AnnotationConfigUtils.attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
	if (enableAJAutoProxy.getBoolean("proxyTargetClass")) {
		AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
	}
}
 
Example 42
Project: lams   File: AnnotationConfigUtils.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
		String containerClassName, String annotationClassName) {

	Set<AnnotationAttributes> result = new LinkedHashSet<AnnotationAttributes>();
	addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));

	Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName, false);
	if (container != null && container.containsKey("value")) {
		for (Map<String, Object> containedAttributes : (Map<String, Object>[]) container.get("value")) {
			addAttributesIfNotNull(result, containedAttributes);
		}
	}
	return Collections.unmodifiableSet(result);
}
 
Example 43
Project: lams   File: AutoProxyRegistrar.java   Source Code and License 5 votes vote down vote up
/**
 * Register, escalate, and configure the standard auto proxy creator (APC) against the
 * given registry. Works by finding the nearest annotation declared on the importing
 * {@code @Configuration} class that has both {@code mode} and {@code proxyTargetClass}
 * attributes. If {@code mode} is set to {@code PROXY}, the APC is registered; if
 * {@code proxyTargetClass} is set to {@code true}, then the APC is forced to use
 * subclass (CGLIB) proxying.
 * <p>Several {@code @Enable*} annotations expose both {@code mode} and
 * {@code proxyTargetClass} attributes. It is important to note that most of these
 * capabilities end up sharing a {@linkplain AopConfigUtils#AUTO_PROXY_CREATOR_BEAN_NAME
 * single APC}. For this reason, this implementation doesn't "care" exactly which
 * annotation it finds -- as long as it exposes the right {@code mode} and
 * {@code proxyTargetClass} attributes, the APC can be registered and configured all
 * the same.
 */
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
	boolean candidateFound = false;
	Set<String> annoTypes = importingClassMetadata.getAnnotationTypes();
	for (String annoType : annoTypes) {
		AnnotationAttributes candidate = AnnotationConfigUtils.attributesFor(importingClassMetadata, annoType);
		Object mode = candidate.get("mode");
		Object proxyTargetClass = candidate.get("proxyTargetClass");
		if (mode != null && proxyTargetClass != null && mode.getClass().equals(AdviceMode.class) &&
				proxyTargetClass.getClass().equals(Boolean.class)) {
			candidateFound = true;
			if (mode == AdviceMode.PROXY) {
				AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry);
				if ((Boolean) proxyTargetClass) {
					AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
					return;
				}
			}
		}
	}
	if (!candidateFound) {
		String name = getClass().getSimpleName();
		logger.warn(String.format("%s was imported but no annotations were found " +
				"having both 'mode' and 'proxyTargetClass' attributes of type " +
				"AdviceMode and boolean respectively. This means that auto proxy " +
				"creator registration and configuration may not have occured as " +
				"intended, and components may not be proxied as expected. Check to " +
				"ensure that %s has been @Import'ed on the same class where these " +
				"annotations are declared; otherwise remove the import of %s " +
				"altogether.", name, name, name));
	}
}
 
Example 44
Project: lams   File: MBeanExportConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> map = importMetadata.getAnnotationAttributes(EnableMBeanExport.class.getName());
	this.attributes = AnnotationAttributes.fromMap(map);
	Assert.notNull(this.attributes,
			"@EnableMBeanExport is not present on importing class " + importMetadata.getClassName());
}
 
Example 45
Project: lams   File: AutowiredAnnotationBeanPostProcessor.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 46
Project: lams   File: AbstractCachingConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	this.enableCaching = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
	Assert.notNull(this.enableCaching,
			"@EnableCaching is not present on importing class " +
			importMetadata.getClassName());
}
 
Example 47
Project: spring-backend-boilerplate   File: EnableMenuImportSelector.java   Source Code and License 5 votes vote down vote up
private MenuExtensionPoint toExtensionPoint(AnnotationAttributes[] extensionPoints) {
	if (extensionPoints == null) {
		return null;
	}

	return Stream.of(extensionPoints).findFirst().map(item -> {
		MenuExtensionPoint result = new MenuExtensionPoint();
		result.setId(item.getString("id"));
		result.setDescription(item.getString("description"));
		return result;
	}).orElse(null);
}
 
Example 48
Project: holon-datastore-jpa   File: JpaEntityScanPackages.java   Source Code and License 5 votes vote down vote up
@Override
protected void register(Map<String, Object> attributes, BeanDefinitionRegistry registry,
		boolean fromRepeatableAnnotationContainer) {
	AnnotationAttributes annotationAttributes = AnnotationAttributes.fromMap(attributes);
	registerPackageNames(annotationAttributes.getString("value"), registry,
			getPackagesToScan(annotationAttributes));
}
 
Example 49
Project: holon-datastore-jpa   File: JpaEntityScanPackages.java   Source Code and License 5 votes vote down vote up
private static Set<String> getPackagesToScan(AnnotationAttributes attributes) {
	String[] basePackages = attributes.getStringArray("basePackages");
	Class<?>[] basePackageClasses = attributes.getClassArray("basePackageClasses");
	Set<String> packagesToScan = new LinkedHashSet<>();
	packagesToScan.addAll(Arrays.asList(basePackages));
	for (Class<?> basePackageClass : basePackageClasses) {
		packagesToScan.add(ClassUtils.getPackageName(basePackageClass));
	}
	return packagesToScan;
}
 
Example 50
Project: spring-session-data-mongodb   File: MongoHttpSessionConfiguration.java   Source Code and License 5 votes vote down vote up
public void setImportMetadata(AnnotationMetadata importMetadata) {

		AnnotationAttributes attributes = AnnotationAttributes.fromMap(
			importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName()));

		this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");

		String collectionNameValue = attributes.getString("collectionName");
		if (StringUtils.hasText(collectionNameValue)) {
			this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue);
		}
	}
 
Example 51
Project: spring-session-data-mongodb   File: ReactiveMongoWebSessionConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {

	AnnotationAttributes attributes = AnnotationAttributes.fromMap(
		importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName()));

	this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");

	String collectionNameValue = attributes.getString("collectionName");
	if (StringUtils.hasText(collectionNameValue)) {
		this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue);
	}

}
 
Example 52
Project: jetcache   File: JetCacheProxyConfiguration.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
    this.enableMethodCache = AnnotationAttributes.fromMap(
            importMetadata.getAnnotationAttributes(EnableMethodCache.class.getName(), false));
    if (this.enableMethodCache == null) {
        throw new IllegalArgumentException(
                "@EnableMethodCache is not present on importing class " + importMetadata.getClassName());
    }
}
 
Example 53
Project: spring-seed   File: SpringSeedRestApiMvcConfigration.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(EnableSpringSeedRestApiMvc.class.getName()));
	this.disableCors =  attributes.getBoolean("disableCors");
	this.parseAuthorizationHeader = attributes.getBoolean("parseAuthorizationHeader");
	AnnotationAttributes jwt = attributes.getAnnotation("enableJwtConfig");
	this.jwtValue = jwt.getBoolean("value");
	this.jwtSecretPropertyName = jwt.getString("secretPropertyName");
	this.expiration = jwt.getNumber("expiration").longValue();

	this.enableSwagger2 = attributes.getBoolean("enableSwagger2");
}
 
Example 54
Project: spring-seed   File: SpringSeedJpa.java   Source Code and License 5 votes vote down vote up
@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		AnnotationAttributes attributes = AnnotationAttributes.fromMap(importingClassMetadata.getAnnotationAttributes(EnableSpringSeedJpa.class.getName()));
		String propertyPrefix = attributes.getString("propertyPrefix");
		String beanNamePrefix =  attributes.getString("beanNamePrefix");
		Class<?>[] entityPackages = attributes.getClassArray("baseEntityClasses");

/*
		//There are two ways to register bean dynamically in Spring.
 		DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)this.beanFactory;

		DataSource dataSource = JpaBuilderUtil.newDataSource(environment, prefix);
		beanFactory.registerSingleton(prefix + DataSource.class.getSimpleName(), dataSource);

		EntityManagerFactory entityManagerFactory = JpaBuilderUtil.newEntityManagerFactory(dataSource, entityPackages);
		beanFactory.registerSingleton(prefix + "entityManager", entityManagerFactory);

		PlatformTransactionManager platformTransactionManager = JpaBuilderUtil.newPlatformTransactionManager(entityManagerFactory);
		beanFactory.registerSingleton(prefix + "transactionManager", platformTransactionManager);
*/

		BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(Dbcp2DataSourceFactoryBean.class)
			.addPropertyValue("prefix", propertyPrefix)
			.addPropertyValue("environment", this.environment)
			.setDestroyMethodName("close");
		String dataSourceName = beanNamePrefix.isEmpty()? "dataSource": beanNamePrefix + "DataSource";
		registry.registerBeanDefinition(dataSourceName, builder.getBeanDefinition());

		BeanDefinitionBuilder builderEntity = BeanDefinitionBuilder.genericBeanDefinition(EntityManagerFactoryFactoryBean.class)
			.addPropertyReference("dataSource", dataSourceName)
			.addPropertyValue("entityPackages", entityPackages);
		String entityManagerFactoryName = beanNamePrefix.isEmpty()? "entityManagerFactory": beanNamePrefix + "EntityManagerFactory";
		registry.registerBeanDefinition(entityManagerFactoryName, builderEntity.getBeanDefinition());

		BeanDefinitionBuilder builderTrans = BeanDefinitionBuilder.genericBeanDefinition(JpaTransactionManagerFactoryBean.class)
			.addPropertyReference("entityManagerFactory",entityManagerFactoryName);
		String transactionManagerName = beanNamePrefix.isEmpty()? "transactionManager": beanNamePrefix + "TransactionManager";
		registry.registerBeanDefinition(transactionManagerName, builderTrans.getBeanDefinition());
	}
 
Example 55
Project: spring-seed   File: SpringSeedRedis.java   Source Code and License 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(importMetadata.getAnnotationAttributes(EnableSpringSeedRedis.class.getName()));
	this.defaultExpiration =  attributes.getNumber("defaultExpiration").longValue();
	this.propertyPrefix = attributes.getString("propertyPrefix");
	AnnotationAttributes[] annotationAttributes = attributes.getAnnotationArray("cacheExpirations");
	for(AnnotationAttributes a: annotationAttributes){
		expiresMap.put(a.getString("value"), a.getNumber("expiration").longValue());
	}
	this.clearBeforeStart = attributes.getBoolean("clearBeforeStart");
}
 
Example 56
Project: play-java-spring-data-jpa   File: GuiceModuleRegistrar.java   Source Code and License 5 votes vote down vote up
private Set<Pattern> parsePatterns(AnnotationMetadata annotation, String attributeName) {
	Set<Pattern> result = new HashSet<Pattern>();
	AnnotationAttributes attributes = new AnnotationAttributes(
			annotation.getAnnotationAttributes(GuiceModule.class.getName()));
	String[] filters = attributes.getStringArray(attributeName);

	for (String filter : filters) {
		result.add(Pattern.compile(filter));
	}

	return result;
}
 
Example 57
Project: play-java-spring-data-jpa   File: GuiceModuleRegistrar.java   Source Code and License 5 votes vote down vote up
private Set<String> parseNames(AnnotationMetadata annotation, String attributeName) {
	Set<String> result = new HashSet<String>();
	AnnotationAttributes attributes = new AnnotationAttributes(
			annotation.getAnnotationAttributes(GuiceModule.class.getName()));
	String[] filters = attributes.getStringArray(attributeName);

	for (String filter : filters) {
		result.add(filter);
	}

	return result;
}
 
Example 58
Project: play-java-spring-data-jpa   File: GuiceModuleRegistrar.java   Source Code and License 5 votes vote down vote up
private Set<TypeFilter> parseFilters(AnnotationMetadata annotation,
		String attributeName) {

	Set<TypeFilter> result = new HashSet<TypeFilter>();
	AnnotationAttributes attributes = new AnnotationAttributes(
			annotation.getAnnotationAttributes(GuiceModule.class.getName()));
	AnnotationAttributes[] filters = attributes.getAnnotationArray(attributeName);

	for (AnnotationAttributes filter : filters) {
		result.addAll(typeFiltersFor(filter));
	}

	return result;
}
 
Example 59
Project: lodsve-framework   File: DfsBeanDefinitionRegistrar.java   Source Code and License 5 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(EnableDfs.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableDfs.class.getName(), annotationMetadata.getClassName()));

    DfsType type = attributes.getEnum(VALUE_ATTRIBUTE_NAME);
    Class<? extends DfsService> clazz = type != null ? type.getImplClazz() : null;

    if (clazz == null) {
        return;
    }

    BeanDefinitionBuilder fsServiceBean = BeanDefinitionBuilder.genericBeanDefinition(clazz);
    beanDefinitionRegistry.registerBeanDefinition("fsService", fsServiceBean.getBeanDefinition());
}
 
Example 60
Project: lodsve-framework   File: MyBatisConfigurationBuilder.java   Source Code and License 5 votes vote down vote up
private MyBatisConfigurationBuilder(AnnotationMetadata metadata) {
    this.metadata = metadata;

    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableMyBatis.class.getName(), false));
    Assert.notNull(attributes, String.format("@%s is not present on importing class '%s' as expected", EnableMyBatis.class.getName(), metadata.getClassName()));
    this.attributes = attributes;
    this.useFlyway = attributes.getBoolean(Constant.USE_FLYWAY_ATTRIBUTE_NAME);
    this.migration = attributes.getString(Constant.MIGRATION_ATTRIBUTE_NAME);
}