当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationAttributes.get方法代码示例

本文整理汇总了Java中org.springframework.core.annotation.AnnotationAttributes.get方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationAttributes.get方法的具体用法?Java AnnotationAttributes.get怎么用?Java AnnotationAttributes.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.annotation.AnnotationAttributes的用法示例。


在下文中一共展示了AnnotationAttributes.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: determineBeanNameFromAnnotation

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:AnnotationBeanNameGenerator.java

示例2: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * 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));
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:48,代码来源:AutoProxyRegistrar.java

示例3: registerBeanDefinitions

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * 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 && AdviceMode.class == mode.getClass() &&
				Boolean.class == proxyTargetClass.getClass()) {
			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));
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:48,代码来源:AutoProxyRegistrar.java

示例4: standardAnnotationMetadata_nestedAnnotationsAsMap_false

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * In order to preserve backward-compatibility, {@link StandardAnnotationMetadata}
 * defaults to return nested annotations and annotation arrays as actual
 * Annotation instances. It is recommended for compatibility with ASM-based
 * AnnotationMetadata implementations to set the 'nestedAnnotationsAsMap' flag to
 * 'true' as is done in the main test above.
 */
@Test
public void standardAnnotationMetadata_nestedAnnotationsAsMap_false() throws Exception {
	AnnotationMetadata metadata = new StandardAnnotationMetadata(AnnotatedComponent.class);
	AnnotationAttributes specialAttrs = (AnnotationAttributes) metadata.getAnnotationAttributes(SpecialAttr.class.getName());
	Annotation[] nestedAnnoArray = (Annotation[]) specialAttrs.get("nestedAnnoArray");
	assertThat(nestedAnnoArray[0], instanceOf(NestedAnno.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:AnnotationMetadataTests.java

示例5: extractInitParameters

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
protected final Map<String, String> extractInitParameters(Map<String, Object> attributes) {
    Map<String, String> initParameters = new HashMap<String, String>();
    for (AnnotationAttributes initParam : (AnnotationAttributes[]) attributes.get("initParams")) {
        String name = (String) initParam.get("name");
        String value = (String) initParam.get("value");
        initParameters.put(name, value);
    }
    return initParameters;
}
 
开发者ID:PebbleTemplates,项目名称:pebble-spring-boot-starter,代码行数:10,代码来源:ServletComponentHandler.java

示例6: extractInitParameters

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
protected final Map<String, String> extractInitParameters(
		Map<String, Object> attributes) {
	Map<String, String> initParameters = new HashMap<String, String>();
	for (AnnotationAttributes initParam : (AnnotationAttributes[]) attributes
			.get("initParams")) {
		String name = (String) initParam.get("name");
		String value = (String) initParam.get("value");
		initParameters.put(name, value);
	}
	return initParameters;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:ServletComponentHandler.java

示例7: extractValue

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Extract the value attribute from the given annotation.
 * @since 4.3
 */
protected Object extractValue(AnnotationAttributes attr) {
	Object value = attr.get(AnnotationUtils.VALUE);
	if (value == null) {
		throw new IllegalStateException("Value annotation must have a value attribute");
	}
	return value;
}
 
开发者ID:txazo,项目名称:spring,代码行数:12,代码来源:QualifierAnnotationAutowireCandidateResolver.java

示例8: getMergedAnnotationAttributes

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Retrieve the merged attributes of the annotation of the given type,
 * if any, from the supplied {@code attributesMap}.
 * <p>Annotation attribute values appearing <em>lower</em> in the annotation
 * hierarchy (i.e., closer to the declaring class) will override those
 * defined <em>higher</em> in the annotation hierarchy.
 * @param attributesMap the map of annotation attribute lists, keyed by
 * annotation type name
 * @param metaAnnotationMap the map of meta annotation relationships,
 * keyed by annotation type name
 * @param annotationName the fully qualified class name of the annotation
 * type to look for
 * @return the merged annotation attributes, or {@code null} if no
 * matching annotation is present in the {@code attributesMap}
 * @since 4.0.3
 */
public static AnnotationAttributes getMergedAnnotationAttributes(
		LinkedMultiValueMap<String, AnnotationAttributes> attributesMap,
		Map<String, Set<String>> metaAnnotationMap, String annotationName) {

	// Get the unmerged list of attributes for the target annotation.
	List<AnnotationAttributes> attributesList = attributesMap.get(annotationName);
	if (attributesList == null || attributesList.isEmpty()) {
		return null;
	}

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

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

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

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

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

	return results;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:66,代码来源:AnnotationReadingVisitorUtils.java

示例9: getMergedAnnotationAttributes

import org.springframework.core.annotation.AnnotationAttributes; //导入方法依赖的package包/类
/**
 * Retrieve the merged attributes of the annotation of the given type,
 * if any, from the supplied {@code attributesMap}.
 * <p>Annotation attribute values appearing <em>lower</em> in the annotation
 * hierarchy (i.e., closer to the declaring class) will override those
 * defined <em>higher</em> in the annotation hierarchy.
 * @param attributesMap the map of annotation attribute lists, keyed by
 * annotation type name
 * @param metaAnnotationMap the map of meta annotation relationships,
 * keyed by annotation type name
 * @param annotationName the fully qualified class name of the annotation
 * type to look for
 * @return the merged annotation attributes, or {@code null} if no
 * matching annotation is present in the {@code attributesMap}
 * @since 4.0.3
 */
public static AnnotationAttributes getMergedAnnotationAttributes(
		LinkedMultiValueMap<String, AnnotationAttributes> attributesMap,
		Map<String, Set<String>> metaAnnotationMap, String annotationName) {

	// Get the unmerged list of attributes for the target annotation.
	List<AnnotationAttributes> attributesList = attributesMap.get(annotationName);
	if (attributesList == null || attributesList.isEmpty()) {
		return null;
	}

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

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

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

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

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

	return results;
}
 
开发者ID:txazo,项目名称:spring,代码行数:65,代码来源:AnnotationReadingVisitorUtils.java


注:本文中的org.springframework.core.annotation.AnnotationAttributes.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。