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


Java AnnotationUtils.getAnnotation方法代码示例

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


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

示例1: tstGetServicePropertySetters

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * Disabled since it doesn't work as we can't proxy final classes.
 */
public void tstGetServicePropertySetters() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setStringType", new Class<?>[] { String.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);

	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	Class<?>[] intfs = (Class[]) getPrivateProperty(pfb, "serviceTypes");
	assertEquals(intfs[0], String.class);

	setter = AnnotatedBean.class.getMethod("setIntType", new Class<?>[] { Integer.TYPE });
	ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);

	pfb = new OsgiServiceProxyFactoryBean();
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	intfs = (Class[]) getPrivateProperty(pfb, "serviceTypes");
	assertEquals(intfs[0], Integer.TYPE);

}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:OsgiServiceAnnotationTest.java

示例2: testProperMultiCardinality

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testProperMultiCardinality() throws Exception {
	OsgiServiceCollectionProxyFactoryBean pfb = new OsgiServiceCollectionProxyFactoryBean();

	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality0_N",
		new Class<?>[] { List.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertFalse(pfb.getAvailability() == Availability.MANDATORY);

	setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality1_N",
		new Class<?>[] { SortedSet.class });
	ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	pfb = new OsgiServiceCollectionProxyFactoryBean();
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertTrue(pfb.getAvailability() == Availability.MANDATORY);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:OsgiServiceAnnotationTest.java

示例3: testGetServicePropertyClassloader

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyClassloader() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderClient",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertEquals(pfb.getImportContextClassLoader(), ImportContextClassLoaderEnum.CLIENT);

	pfb = new OsgiServiceProxyFactoryBean();
	setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderUmanaged",
		new Class<?>[] { AnnotatedBean.class });
	ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);

	assertEquals(pfb.getImportContextClassLoader(), ImportContextClassLoaderEnum.UNMANAGED);

	pfb = new OsgiServiceProxyFactoryBean();
	setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithClassLoaderServiceProvider",
		new Class<?>[] { AnnotatedBean.class });
	ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertEquals(pfb.getImportContextClassLoader(), ImportContextClassLoaderEnum.SERVICE_PROVIDER);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:24,代码来源:OsgiServiceAnnotationTest.java

示例4: processFields

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
private void processFields(Object bean, Field[] declaredFields) {
  for (Field field : declaredFields) {
    ApolloConfig annotation = AnnotationUtils.getAnnotation(field, ApolloConfig.class);
    if (annotation == null) {
      continue;
    }

    Preconditions.checkArgument(Config.class.isAssignableFrom(field.getType()),
        "Invalid type: %s for field: %s, should be Config", field.getType(), field);

    String namespace = annotation.value();
    Config config = ConfigService.getConfig(namespace);

    ReflectionUtils.makeAccessible(field);
    ReflectionUtils.setField(field, bean, config);
  }
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:18,代码来源:ApolloAnnotationProcessor.java

示例5: testGetServicePropertyCardinality

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyCardinality() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality1_1",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertTrue(pfb.getAvailability() == Availability.MANDATORY);

	setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithCardinality0_1",
		new Class<?>[] { AnnotatedBean.class });
	ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	pfb = new OsgiServiceProxyFactoryBean();
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	assertFalse(pfb.getAvailability() == Availability.MANDATORY);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:16,代码来源:OsgiServiceAnnotationTest.java

示例6: testErrorMultiCardinality

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testErrorMultiCardinality() throws Exception {
	OsgiServiceCollectionProxyFactoryBean pfb = new OsgiServiceCollectionProxyFactoryBean();

	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanErrorTypeWithCardinality1_N",
		new Class<?>[] { SortedSet.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	pfb = new OsgiServiceCollectionProxyFactoryBean();
	try {
		processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
		fail("IllegalArgumentException should have been thrown");
	}
	catch (Exception e) {
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:15,代码来源:OsgiServiceAnnotationTest.java

示例7: testGetServicePropertyBeanName

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyBeanName() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithBeanName",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	String beanName = (String) getPrivateProperty(pfb, "serviceBeanName");
	;
	assertEquals(beanName, "myBean");
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:11,代码来源:OsgiServiceAnnotationTest.java

示例8: testGetServicePropertyFilter

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyFilter() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithFilter",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	String filter = (String) getPrivateProperty(pfb, "filter");
	;
	assertEquals(filter, "(wooey=fooo)");
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:11,代码来源:OsgiServiceAnnotationTest.java

示例9: testGetServicePropertyServiceClass

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyServiceClass() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeWithServiceType",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	Class<?>[] intfs = (Class[]) getPrivateProperty(pfb, "interfaces");
	assertEquals(intfs[0], Object.class);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:10,代码来源:OsgiServiceAnnotationTest.java

示例10: testGetServicePropertyComplex

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
public void testGetServicePropertyComplex() throws Exception {
	OsgiServiceProxyFactoryBean pfb = new OsgiServiceProxyFactoryBean();
	Method setter = AnnotatedBean.class.getMethod("setAnnotatedBeanTypeComplex",
		new Class<?>[] { AnnotatedBean.class });
	ServiceReference ref = AnnotationUtils.getAnnotation(setter, ServiceReference.class);
	processor.getServiceProperty(pfb, ref, setter.getParameterTypes()[0], null);
	Class<?>[] intfs = (Class[]) getPrivateProperty(pfb, "interfaces");
	String filter = (String) getPrivateProperty(pfb, "filter");
	String beanName = (String) getPrivateProperty(pfb, "serviceBeanName");
	assertEquals(intfs[0], AnnotatedBean.class);
	assertFalse(pfb.getAvailability() == Availability.MANDATORY);
	assertEquals(ImportContextClassLoaderEnum.SERVICE_PROVIDER, pfb.getImportContextClassLoader());
	assertEquals(filter, "(id=fooey)");
	assertEquals(beanName, "myBean");
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:16,代码来源:OsgiServiceAnnotationTest.java

示例11: hasServiceProperty

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
protected ServiceReference hasServiceProperty(PropertyDescriptor propertyDescriptor) {
	Method setter = propertyDescriptor.getWriteMethod();
	return setter != null ? AnnotationUtils.getAnnotation(setter, ServiceReference.class) : null;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:5,代码来源:ServiceReferenceInjectionBeanPostProcessor.java

示例12: checkQualifier

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * Match the given qualifier annotation against the candidate bean definition.
 */
protected boolean checkQualifier(
		BeanDefinitionHolder bdHolder, Annotation annotation, TypeConverter typeConverter) {

	Class<? extends Annotation> type = annotation.annotationType();
	RootBeanDefinition bd = (RootBeanDefinition) bdHolder.getBeanDefinition();

	AutowireCandidateQualifier qualifier = bd.getQualifier(type.getName());
	if (qualifier == null) {
		qualifier = bd.getQualifier(ClassUtils.getShortName(type));
	}
	if (qualifier == null) {
		// First, check annotation on factory method, if applicable
		Annotation targetAnnotation = getFactoryMethodAnnotation(bd, type);
		if (targetAnnotation == null) {
			RootBeanDefinition dbd = getResolvedDecoratedDefinition(bd);
			if (dbd != null) {
				targetAnnotation = getFactoryMethodAnnotation(dbd, type);
			}
		}
		if (targetAnnotation == null) {
			// Look for matching annotation on the target class
			if (getBeanFactory() != null) {
				Class<?> beanType = getBeanFactory().getType(bdHolder.getBeanName());
				if (beanType != null) {
					targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(beanType), type);
				}
			}
			if (targetAnnotation == null && bd.hasBeanClass()) {
				targetAnnotation = AnnotationUtils.getAnnotation(ClassUtils.getUserClass(bd.getBeanClass()), type);
			}
		}
		if (targetAnnotation != null && targetAnnotation.equals(annotation)) {
			return true;
		}
	}

	Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation);
	if (attributes.isEmpty() && qualifier == null) {
		// If no attributes, the qualifier must be present
		return false;
	}
	for (Map.Entry<String, Object> entry : attributes.entrySet()) {
		String attributeName = entry.getKey();
		Object expectedValue = entry.getValue();
		Object actualValue = null;
		// Check qualifier first
		if (qualifier != null) {
			actualValue = qualifier.getAttribute(attributeName);
		}
		if (actualValue == null) {
			// Fall back on bean definition attribute
			actualValue = bd.getAttribute(attributeName);
		}
		if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) &&
				expectedValue instanceof String && bdHolder.matchesName((String) expectedValue)) {
			// Fall back on bean name (or alias) match
			continue;
		}
		if (actualValue == null && qualifier != null) {
			// Fall back on default, but only if the qualifier is present
			actualValue = AnnotationUtils.getDefaultValue(annotation, attributeName);
		}
		if (actualValue != null) {
			actualValue = typeConverter.convertIfNecessary(actualValue, expectedValue.getClass());
		}
		if (!expectedValue.equals(actualValue)) {
			return false;
		}
	}
	return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:75,代码来源:QualifierAnnotationAutowireCandidateResolver.java

示例13: getFactoryMethodAnnotation

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class<? extends Annotation> type) {
	Method resolvedFactoryMethod = bd.getResolvedFactoryMethod();
	return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:5,代码来源:QualifierAnnotationAutowireCandidateResolver.java

示例14: isDeleted

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * Returns true if the method has been marked as deleted.
 * @param method the method
 * @return true - if is is marked as deleted.
 */
public static boolean isDeleted(Method method)
{
    WebApiDeleted deleted = AnnotationUtils.getAnnotation(method, WebApiDeleted.class);
    return (deleted!=null);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:11,代码来源:ResourceInspector.java

示例15: isNoAuth

import org.springframework.core.annotation.AnnotationUtils; //导入方法依赖的package包/类
/**
 * Returns true if the method has been marked as no auth required.
 * @param method the method
 * @return true - if is is marked as no auth required.
 */
public static boolean isNoAuth(Method method)
{
    WebApiNoAuth noAuth = AnnotationUtils.getAnnotation(method, WebApiNoAuth.class);
    return (noAuth!=null);
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:11,代码来源:ResourceInspector.java


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