本文整理汇总了Java中org.springframework.core.annotation.AnnotationAttributes.getEnum方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationAttributes.getEnum方法的具体用法?Java AnnotationAttributes.getEnum怎么用?Java AnnotationAttributes.getEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.annotation.AnnotationAttributes
的用法示例。
在下文中一共展示了AnnotationAttributes.getEnum方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolveScopeMetadata
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@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;
}
示例2: selectImports
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@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];
}
示例3: selectImports
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@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()]);
}
示例4: selectImports
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
* 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;
}
示例5: resolveScopeMetadata
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@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;
}
示例6: selectImports
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
* 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;
}
示例7: registerBeanDefinitions
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@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());
}
示例8: getEnum
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
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;
}
示例9: selectImports
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
Class<?> annoType = EnableOAuth2.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()));
}
List<String> configurationClasses = new ArrayList<>();
if (attributes.getEnum("mode") == OperationMode.COMBINED) {
configurationClasses.add(ResourceServerConfiguration.class.getName());
configurationClasses.add(AuthorizationServerConfiguration.class.getName());
OAuth2Configuration.authenticationProviderBean = attributes.getString("authenticationProviderBean");
}
if (attributes.getEnum("mode") == OperationMode.RESOURCES) {
configurationClasses.add(ResourceServerConfiguration.class.getName());
String authenticationUrl = attributes.getString("authenticationUrl");
Assert.hasText(authenticationUrl, "Standalone resource servers need to have an authentication endpoint configured, property authenticationUrl");
AuthenticationProviderConfiguration.authenticationUrl = authenticationUrl;
OAuth2Configuration.authenticationProviderBean = "httpAuthenticationProvider";
configurationClasses.add(AuthenticationProviderConfiguration.class.getName());
}
if (attributes.getEnum("mode") == OperationMode.AUTHORIZATIONS) {
configurationClasses.add(AuthorizationServerConfiguration.class.getName());
OAuth2Configuration.authenticationProviderBean = attributes.getString("authenticationProviderBean");
}
configurationClasses.add(OAuth2Configuration.class.getName());
return configurationClasses.toArray(new String[configurationClasses.size()]);
}
示例10: typeFiltersFor
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"An error occured while processing a @ComponentScan ANNOTATION type filter: ");
@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,
"An error occured while processing a @ComponentScan CUSTOM type filter: ");
typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
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;
}
示例11: typeFiltersFor
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getClassArray("value")) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"An error occured when processing a @ComponentScan "
+ "ANNOTATION type filter: ");
@SuppressWarnings("unchecked")
Class<Annotation> annoClass = (Class<Annotation>) filterClass;
typeFilters.add(new AnnotationTypeFilter(annoClass));
break;
case ASSIGNABLE_TYPE:
typeFilters.add(new AssignableTypeFilter(filterClass));
break;
case CUSTOM:
Assert.isAssignable(TypeFilter.class, filterClass,
"An error occured when processing a @ComponentScan "
+ "CUSTOM type filter: ");
typeFilters
.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
break;
default:
throw new IllegalArgumentException("Unknown filter type " + filterType);
}
}
for (String expression : getPatterns(filterAttributes)) {
String rawName = filterType.toString();
if ("REGEX".equals(rawName)) {
typeFilters.add(new RegexPatternTypeFilter(Pattern.compile(expression)));
} else if ("ASPECTJ".equals(rawName)) {
typeFilters.add(new AspectJTypeFilter(expression, this.resourceLoader
.getClassLoader()));
} else {
throw new IllegalArgumentException("Unknown filter type " + filterType);
}
}
return typeFilters;
}
示例12: typeFiltersFor
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getAliasedClassArray("classes", ComponentScan.Filter.class, null)) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"An error occured while processing a @ComponentScan ANNOTATION type filter: ");
@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,
"An error occured while processing a @ComponentScan CUSTOM type filter: ");
typeFilters.add(BeanUtils.instantiateClass(filterClass, TypeFilter.class));
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;
}
示例13: registerBeanDefinitions
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
@Override
public void registerBeanDefinitions(AnnotationMetadata annotationMetadata,
BeanDefinitionRegistry registry) {
Assert.notNull(annotationMetadata, "AnnotationMetadata must not be null!");
Assert.notNull(registry, "BeanDefinitionRegistry must not be null!");
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");
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, propertyPath);
registry.registerBeanDefinition("vaultPropertySource#" + counter,
beanDefinition);
counter++;
}
}
}
示例14: typeFiltersFor
import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
private List<TypeFilter> typeFiltersFor(AnnotationAttributes filterAttributes) {
List<TypeFilter> typeFilters = new ArrayList<TypeFilter>();
FilterType filterType = filterAttributes.getEnum("type");
for (Class<?> filterClass : filterAttributes.getAliasedClassArray("classes", ComponentScan.Filter.class, null)) {
switch (filterType) {
case ANNOTATION:
Assert.isAssignable(Annotation.class, filterClass,
"An error occured while processing a @ComponentScan ANNOTATION type filter: ");
@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,
"An error occured while processing a @ComponentScan CUSTOM type filter: ");
TypeFilter filter = BeanUtils.instantiateClass(filterClass, TypeFilter.class);
invokeAwareMethods(filter);
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;
}