Java Code Examples for org.springframework.core.annotation.AnnotationAttributes#getEnum()

The following examples show how to use org.springframework.core.annotation.AnnotationAttributes#getEnum() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationScopeMetadataResolver.java    From spring-analysis-note with MIT 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 == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
Example 2
Source File: AdviceModeImportSelector.java    From spring-analysis-note with MIT 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<?> annType = GenericTypeResolver.resolveTypeArgument(getClass(), AdviceModeImportSelector.class);
	Assert.state(annType != null, "Unresolvable type argument for AdviceModeImportSelector");

	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(importingClassMetadata, annType);
	if (attributes == null) {
		throw new IllegalArgumentException(String.format(
				"@%s is not present on importing class '%s' as expected",
				annType.getSimpleName(), importingClassMetadata.getClassName()));
	}

	AdviceMode adviceMode = attributes.getEnum(getAdviceModeAttributeName());
	String[] imports = selectImports(adviceMode);
	if (imports == null) {
		throw new IllegalArgumentException("Unknown AdviceMode: " + adviceMode);
	}
	return imports;
}
 
Example 3
Source File: AnnotationScopeMetadataResolver.java    From spring4-understanding with Apache License 2.0 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 4
Source File: AdviceModeImportSelector.java    From spring4-understanding with Apache License 2.0 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 5
Source File: RedisHttpSessionConfiguration.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> attributeMap = importMetadata
			.getAnnotationAttributes(EnableRedisHttpSession.class.getName());
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
	this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
	String redisNamespaceValue = attributes.getString("redisNamespace");
	if (StringUtils.hasText(redisNamespaceValue)) {
		this.redisNamespace = this.embeddedValueResolver.resolveStringValue(redisNamespaceValue);
	}
	FlushMode flushMode = attributes.getEnum("flushMode");
	RedisFlushMode redisFlushMode = attributes.getEnum("redisFlushMode");
	if (flushMode == FlushMode.ON_SAVE && redisFlushMode != RedisFlushMode.ON_SAVE) {
		flushMode = redisFlushMode.getFlushMode();
	}
	this.flushMode = flushMode;
	this.saveMode = attributes.getEnum("saveMode");
	String cleanupCron = attributes.getString("cleanupCron");
	if (StringUtils.hasText(cleanupCron)) {
		this.cleanupCron = cleanupCron;
	}
}
 
Example 6
Source File: AnnotationScopeMetadataResolver.java    From java-technology-stack with MIT 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 == ScopedProxyMode.DEFAULT) {
				proxyMode = this.defaultProxyMode;
			}
			metadata.setScopedProxyMode(proxyMode);
		}
	}
	return metadata;
}
 
Example 7
Source File: JdbcHttpSessionConfiguration.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> attributeMap = importMetadata
			.getAnnotationAttributes(EnableJdbcHttpSession.class.getName());
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
	this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
	String tableNameValue = attributes.getString("tableName");
	if (StringUtils.hasText(tableNameValue)) {
		this.tableName = this.embeddedValueResolver.resolveStringValue(tableNameValue);
	}
	String cleanupCron = attributes.getString("cleanupCron");
	if (StringUtils.hasText(cleanupCron)) {
		this.cleanupCron = cleanupCron;
	}
	this.flushMode = attributes.getEnum("flushMode");
	this.saveMode = attributes.getEnum("saveMode");
}
 
Example 8
Source File: AnnotationScopeMetadataResolver.java    From lams with GNU General Public License v2.0 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 9
Source File: SchedulerLockConfigurationSelector.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
@Override
public String[] selectImports(@NonNull AnnotationMetadata metadata) {
    AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(EnableSchedulerLock.class.getName(), false));
    InterceptMode mode = attributes.getEnum("interceptMode");
    if (mode == PROXY_METHOD) {
        return new String[]{AutoProxyRegistrar.class.getName(), MethodProxyLockConfiguration.class.getName()};
    } else if (mode == PROXY_SCHEDULER) {
        return new String[]{AutoProxyRegistrar.class.getName(), SchedulerProxyLockConfiguration.class.getName(), RegisterDefaultTaskSchedulerPostProcessor.class.getName()};
    } else {
        throw new UnsupportedOperationException("Unknown mode " + mode);
    }

}
 
Example 10
Source File: BeanAnnotationHelper.java    From spring-analysis-note with MIT License 5 votes vote down vote up
public static boolean isScopedProxy(Method beanMethod) {
	Boolean scopedProxy = scopedProxyCache.get(beanMethod);
	if (scopedProxy == null) {
		AnnotationAttributes scope =
				AnnotatedElementUtils.findMergedAnnotationAttributes(beanMethod, Scope.class, false, false);
		scopedProxy = (scope != null && scope.getEnum("proxyMode") != ScopedProxyMode.NO);
		scopedProxyCache.put(beanMethod, scopedProxy);
	}
	return scopedProxy;
}
 
Example 11
Source File: MergedSqlConfig.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private static <E extends Enum<?>> E getEnum(AnnotationAttributes attributes, String attributeName,
		E inheritedOrDefaultValue, E defaultValue) {

	E value = attributes.getEnum(attributeName);
	if (value == inheritedOrDefaultValue) {
		value = defaultValue;
	}
	return value;
}
 
Example 12
Source File: MessageSenderEndpointBeanRegistrar.java    From synapse with Apache License 2.0 5 votes vote down vote up
@Override
protected void registerBeanDefinitions(final String channelName,
                                       final String beanName,
                                       final AnnotationAttributes annotationAttributes,
                                       final BeanDefinitionRegistry registry) {
        final Class<? extends Selector> channelSelector = annotationAttributes.getClass("selector");
        final MessageFormat messageFormat = annotationAttributes.getEnum("messageFormat");

        if (!registry.containsBeanDefinition(beanName)) {
            registry.registerBeanDefinition(
                    beanName,
                    genericBeanDefinition(DelegateMessageSenderEndpoint.class)
                            .addConstructorArgValue(channelName)
                            .addConstructorArgValue(channelSelector)
                            .addConstructorArgValue(messageFormat)
                            .setDependencyCheck(DEPENDENCY_CHECK_ALL)
                            .getBeanDefinition()
            );

            LOG.info("Registered MessageQueueSenderEndpoint {} with for channelName {}, messageFormat {}", beanName, channelName, messageFormat);
        } else {
            throw new BeanCreationException(
                    beanName,
                    format("MessageQueueReceiverEndpoint %s is already registered.", beanName)
            );
        }
}
 
Example 13
Source File: MergedSqlConfig.java    From java-technology-stack with MIT License 5 votes vote down vote up
private static <E extends Enum<?>> E getEnum(AnnotationAttributes attributes, String attributeName,
		E inheritedOrDefaultValue, E defaultValue) {

	E value = attributes.getEnum(attributeName);
	if (value == inheritedOrDefaultValue) {
		value = defaultValue;
	}
	return value;
}
 
Example 14
Source File: RedisWebSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Override
public void setImportMetadata(AnnotationMetadata importMetadata) {
	Map<String, Object> attributeMap = importMetadata
			.getAnnotationAttributes(EnableRedisWebSession.class.getName());
	AnnotationAttributes attributes = AnnotationAttributes.fromMap(attributeMap);
	this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds");
	String redisNamespaceValue = attributes.getString("redisNamespace");
	if (StringUtils.hasText(redisNamespaceValue)) {
		this.redisNamespace = this.embeddedValueResolver.resolveStringValue(redisNamespaceValue);
	}
	this.saveMode = attributes.getEnum("saveMode");
}
 
Example 15
Source File: VaultPropertySourceRegistrar.java    From spring-vault with Apache License 2.0 4 votes vote down vote up
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {

	Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null");
	Assert.notNull(registry, "BeanDefinitionRegistry must not be null");

	if (!registry.isBeanNameInUse("VaultPropertySourceRegistrar")) {
		registry.registerBeanDefinition("VaultPropertySourceRegistrar", BeanDefinitionBuilder //
				.rootBeanDefinition(VaultPropertySourceRegistrar.class) //
				.setRole(BeanDefinition.ROLE_INFRASTRUCTURE) //
				.getBeanDefinition());
	}

	Set<AnnotationAttributes> propertySources = attributesForRepeatable(annotationMetadata,
			VaultPropertySources.class.getName(), VaultPropertySource.class.getName());

	int counter = 0;

	for (AnnotationAttributes propertySource : propertySources) {

		String[] paths = propertySource.getStringArray("value");
		String ref = propertySource.getString("vaultTemplateRef");
		String propertyNamePrefix = propertySource.getString("propertyNamePrefix");
		Renewal renewal = propertySource.getEnum("renewal");
		boolean ignoreSecretNotFound = propertySource.getBoolean("ignoreSecretNotFound");

		Assert.isTrue(paths.length > 0, "At least one @VaultPropertySource(value) location is required");

		Assert.hasText(ref, "'vaultTemplateRef' in @EnableVaultPropertySource must not be empty");

		PropertyTransformer propertyTransformer = StringUtils.hasText(propertyNamePrefix)
				? PropertyTransformers.propertyNamePrefix(propertyNamePrefix) : PropertyTransformers.noop();

		for (String propertyPath : paths) {

			if (!StringUtils.hasText(propertyPath)) {
				continue;
			}

			AbstractBeanDefinition beanDefinition = createBeanDefinition(ref, renewal, propertyTransformer,
					ignoreSecretNotFound, potentiallyResolveRequiredPlaceholders(propertyPath));

			do {
				String beanName = "vaultPropertySource#" + counter;

				if (!registry.isBeanNameInUse(beanName)) {
					registry.registerBeanDefinition(beanName, beanDefinition);
					break;
				}

				counter++;
			}
			while (true);
		}
	}
}
 
Example 16
Source File: ConfigurationClassBeanDefinitionReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Read the given {@link BeanMethod}, registering bean definitions
 * with the BeanDefinitionRegistry based on its contents.
 */
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
	ConfigurationClass configClass = beanMethod.getConfigurationClass();
	MethodMetadata metadata = beanMethod.getMetadata();
	String methodName = metadata.getMethodName();

	// Do we need to mark the bean as skipped by its condition?
	if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
		configClass.skippedBeanMethods.add(methodName);
		return;
	}
	if (configClass.skippedBeanMethods.contains(methodName)) {
		return;
	}

	// Consider name and any aliases
	AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.class);
	List<String> names = new ArrayList<String>(Arrays.asList(bean.getStringArray("name")));
	String beanName = (!names.isEmpty() ? names.remove(0) : methodName);

	// Register aliases even when overridden
	for (String alias : names) {
		this.registry.registerAlias(beanName, alias);
	}

	// Has this effectively been overridden before (e.g. via XML)?
	if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
		if (beanName.equals(beanMethod.getConfigurationClass().getBeanName())) {
			throw new BeanDefinitionStoreException(beanMethod.getConfigurationClass().getResource().getDescription(),
					beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() +
					"' clashes with bean name for containing configuration class; please make those names unique!");
		}
		return;
	}

	ConfigurationClassBeanDefinition beanDef = new ConfigurationClassBeanDefinition(configClass, metadata);
	beanDef.setResource(configClass.getResource());
	beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClass.getResource()));

	if (metadata.isStatic()) {
		// static @Bean method
		beanDef.setBeanClassName(configClass.getMetadata().getClassName());
		beanDef.setFactoryMethodName(methodName);
	}
	else {
		// instance @Bean method
		beanDef.setFactoryBeanName(configClass.getBeanName());
		beanDef.setUniqueFactoryMethodName(methodName);
	}
	beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);

	AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);

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

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

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

	// Consider scoping
	ScopedProxyMode proxyMode = ScopedProxyMode.NO;
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.class);
	if (attributes != null) {
		beanDef.setScope(attributes.getString("value"));
		proxyMode = attributes.getEnum("proxyMode");
		if (proxyMode == ScopedProxyMode.DEFAULT) {
			proxyMode = ScopedProxyMode.NO;
		}
	}

	// Replace the original bean definition with the target one, if necessary
	BeanDefinition beanDefToRegister = beanDef;
	if (proxyMode != ScopedProxyMode.NO) {
		BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
				new BeanDefinitionHolder(beanDef, beanName), this.registry,
				proxyMode == ScopedProxyMode.TARGET_CLASS);
		beanDefToRegister = new ConfigurationClassBeanDefinition(
				(RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata);
	}

	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Registering bean definition for @Bean method %s.%s()",
				configClass.getMetadata().getClassName(), beanName));
	}

	this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
 
Example 17
Source File: ConfigurationClassBeanDefinitionReader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Read the given {@link BeanMethod}, registering bean definitions
 * with the BeanDefinitionRegistry based on its contents.
 */
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
	ConfigurationClass configClass = beanMethod.getConfigurationClass();
	MethodMetadata metadata = beanMethod.getMetadata();
	String methodName = metadata.getMethodName();

	// Do we need to mark the bean as skipped by its condition?
	if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
		configClass.skippedBeanMethods.add(methodName);
		return;
	}
	if (configClass.skippedBeanMethods.contains(methodName)) {
		return;
	}

	// Consider name and any aliases
	AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.class);
	List<String> names = new ArrayList<String>(Arrays.asList(bean.getStringArray("name")));
	String beanName = (names.size() > 0 ? names.remove(0) : methodName);

	// Register aliases even when overridden
	for (String alias : names) {
		this.registry.registerAlias(beanName, alias);
	}

	// Has this effectively been overridden before (e.g. via XML)?
	if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
		return;
	}

	ConfigurationClassBeanDefinition beanDef = new ConfigurationClassBeanDefinition(configClass, metadata);
	beanDef.setResource(configClass.getResource());
	beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClass.getResource()));

	if (metadata.isStatic()) {
		// static @Bean method
		beanDef.setBeanClassName(configClass.getMetadata().getClassName());
		beanDef.setFactoryMethodName(methodName);
	}
	else {
		// instance @Bean method
		beanDef.setFactoryBeanName(configClass.getBeanName());
		beanDef.setUniqueFactoryMethodName(methodName);
	}
	beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);

	AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);

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

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

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

	// Consider scoping
	ScopedProxyMode proxyMode = ScopedProxyMode.NO;
	AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.class);
	if (attributes != null) {
		beanDef.setScope(attributes.getAliasedString("value", Scope.class, configClass.getResource()));
		proxyMode = attributes.getEnum("proxyMode");
		if (proxyMode == ScopedProxyMode.DEFAULT) {
			proxyMode = ScopedProxyMode.NO;
		}
	}

	// Replace the original bean definition with the target one, if necessary
	BeanDefinition beanDefToRegister = beanDef;
	if (proxyMode != ScopedProxyMode.NO) {
		BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
				new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
		beanDefToRegister = new ConfigurationClassBeanDefinition(
				(RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata);
	}

	if (logger.isDebugEnabled()) {
		logger.debug(String.format("Registering bean definition for @Bean method %s.%s()",
				configClass.getMetadata().getClassName(), beanName));
	}

	this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
 
Example 18
Source File: MBeanExportConfiguration.java    From java-technology-stack with MIT License 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
	RegistrationPolicy registrationPolicy = enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}
 
Example 19
Source File: ComponentScanAnnotationParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
	List<TypeFilter> typeFilters = new ArrayList<>();
	FilterType filterType = filterAttributes.getEnum("type");

	for (Class<?> filterClass : filterAttributes.getClassArray("classes")) {
		switch (filterType) {
			case ANNOTATION:
				Assert.isAssignable(Annotation.class, filterClass,
						"@ComponentScan ANNOTATION type filter requires an annotation type");
				@SuppressWarnings("unchecked")
				Class<Annotation> annotationType = (Class<Annotation>) filterClass;
				typeFilters.add(new AnnotationTypeFilter(annotationType));
				break;
			case ASSIGNABLE_TYPE:
				typeFilters.add(new AssignableTypeFilter(filterClass));
				break;
			case CUSTOM:
				Assert.isAssignable(TypeFilter.class, filterClass,
						"@ComponentScan CUSTOM type filter requires a TypeFilter implementation");
				TypeFilter filter = BeanUtils.instantiateClass(filterClass, TypeFilter.class);
				ParserStrategyUtils.invokeAwareMethods(
						filter, this.environment, this.resourceLoader, this.registry);
				typeFilters.add(filter);
				break;
			default:
				throw new IllegalArgumentException("Filter type not supported with Class value: " + filterType);
		}
	}

	for (String expression : filterAttributes.getStringArray("pattern")) {
		switch (filterType) {
			case ASPECTJ:
				typeFilters.add(new AspectJTypeFilter(expression, this.resourceLoader.getClassLoader()));
				break;
			case REGEX:
				typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
				break;
			default:
				throw new IllegalArgumentException("Filter type not supported with String pattern: " + filterType);
		}
	}

	return typeFilters;
}
 
Example 20
Source File: MBeanExportConfiguration.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private void setupRegistrationPolicy(AnnotationMBeanExporter exporter, AnnotationAttributes enableMBeanExport) {
	RegistrationPolicy registrationPolicy = enableMBeanExport.getEnum("registration");
	exporter.setRegistrationPolicy(registrationPolicy);
}