本文整理匯總了Java中javax.annotation.Resource.type方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.type方法的具體用法?Java Resource.type怎麽用?Java Resource.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.annotation.Resource
的用法示例。
在下文中一共展示了Resource.type方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getType
import javax.annotation.Resource; //導入方法依賴的package包/類
private static String getType(Resource annotation, Class<?> defaultType) {
Class<?> type = annotation.type();
if (type == null || type.equals(Object.class)) {
if (defaultType != null) {
type = defaultType;
}
}
return Introspection.convertPrimitiveType(type).getCanonicalName();
}
示例2: createFor
import javax.annotation.Resource; //導入方法依賴的package包/類
public static Reference createFor(Resource resource, Field field) {
final Class<?> type;
if (!Object.class.equals(resource.type())) {
type = resource.type();
} else {
type = field.getType();
}
final String name;
if (resource.name().length() > 0) {
name = resource.name();
} else {
name = field.getDeclaringClass().getName() + "/" + field.getName();
}
return new Reference(type, name, field);
}
示例3: ResourceElement
import javax.annotation.Resource; //導入方法依賴的package包/類
public ResourceElement(Member member, PropertyDescriptor pd) {
super(member, pd);
AnnotatedElement ae = (AnnotatedElement) member;
Resource resource = ae.getAnnotation(Resource.class);
String resourceName = resource.name();
Class<?> resourceType = resource.type();
this.isDefaultName = !StringUtils.hasLength(resourceName);
if (this.isDefaultName) {
resourceName = this.member.getName();
if (this.member instanceof Method && resourceName.startsWith("set") && resourceName.length() > 3) {
resourceName = Introspector.decapitalize(resourceName.substring(3));
}
}
else if (beanFactory instanceof ConfigurableBeanFactory){
resourceName = ((ConfigurableBeanFactory) beanFactory).resolveEmbeddedValue(resourceName);
}
if (resourceType != null && !Object.class.equals(resourceType)) {
checkResourceType(resourceType);
}
else {
// No resource type specified... check field/method.
resourceType = getResourceType();
}
this.name = resourceName;
this.lookupType = resourceType;
this.mappedName = resource.mappedName();
}
示例4: isInjectionPoint
import javax.annotation.Resource; //導入方法依賴的package包/類
private static boolean isInjectionPoint(Resource resource, Class fieldType, String errorMessage, Class resourceType ) {
Class t = resource.type();
if (t.equals(Object.class)) {
return fieldType.equals(resourceType);
} else if (t.equals(resourceType)) {
if (fieldType.isAssignableFrom(resourceType)) {
return true;
} else {
// type compatibility error
throw new WebServiceException(errorMessage);
}
}
return false;
}
示例5: getType
import javax.annotation.Resource; //導入方法依賴的package包/類
private static String getType(Resource annotation, Class<?> defaultType) {
Class<?> type = annotation.type();
if (type == null || type.equals(Object.class)) {
if (defaultType != null) {
type = defaultType;
}
}
return Introspection.convertPrimitiveType(type).getCanonicalName();
}
示例6: afterTestMethod
import javax.annotation.Resource; //導入方法依賴的package包/類
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
super.afterTestMethod(testContext);
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) testContext.getApplicationContext()
.getAutowireCapableBeanFactory();
/**
* 方法結束後記錄被測試對象的bean名稱
*/
Object bean = testContext.getTestInstance();
List<Field> fields = getDeclaredFields(bean);
for (Field field : fields) {
InjectMocks injectMocks = field.getAnnotation(InjectMocks.class);
if (injectMocks == null) {
continue;
}
Object testedBean = null;
String testedBeanName = null;
/**
* 被測試的對象如果通過spring自動注入,則記錄
* 兩種注入方式 Autowired
* Resource
*/
if (field.getAnnotation(Autowired.class) != null) {
Qualifier qualifier = field.getAnnotation(Qualifier.class);
testedBean = qualifier == null ? beanFactory.getBean(field.getType())
: beanFactory.getBean(qualifier.value());
testedBeanName = qualifier == null ? beanFactory.getBeanNamesForType(field.getType())[0]
: qualifier.value();
} else if (field.getAnnotation(Resource.class) != null) {
Resource resource = field.getAnnotation(Resource.class);
Class<?> type = resource.type();
String name = resource.name();
if (StringUtils.isNotEmpty(name)) {
testedBean = beanFactory.getBean(name);
testedBeanName = name;
} else {
testedBean = (type != Object.class) ? beanFactory.getBean(type)
: beanFactory.getBean(field.getType());
testedBeanName = (type != Object.class) ? beanFactory.getBeanNamesForType(type)[0]
: beanFactory.getBeanNamesForType(field.getType())[0];
}
}
if (testedBean != null) {
testedObjects.put(testedBeanName, testedBean);
}
}
}