當前位置: 首頁>>代碼示例>>Java>>正文


Java Resource.name方法代碼示例

本文整理匯總了Java中javax.annotation.Resource.name方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.name方法的具體用法?Java Resource.name怎麽用?Java Resource.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.annotation.Resource的用法示例。


在下文中一共展示了Resource.name方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getResourceName

import javax.annotation.Resource; //導入方法依賴的package包/類
private String getResourceName(InjectionPoint injectionPoint) {
    Resource resource = getResourceAnnotation(injectionPoint);
    String mappedName = resource.mappedName();
    if (!mappedName.equals("")) {
        return mappedName;
    }
    String name = resource.name();
    if (!name.equals("")) {
        return RESOURCE_LOOKUP_PREFIX + "/" + name;
    }
    String propertyName;
    if (injectionPoint.getMember() instanceof Field) {
        propertyName = injectionPoint.getMember().getName();
    } else if (injectionPoint.getMember() instanceof Method) {
        propertyName = getPropertyName((Method) injectionPoint.getMember());
        if (propertyName == null) {
            throw new IllegalArgumentException("Injection point represents a method which doesn't follow "
                    + "JavaBean conventions (unable to determine property name) " + injectionPoint);
        }
    } else {
        throw new AssertionError("Unable to inject into " + injectionPoint);
    }
    String className = injectionPoint.getMember().getDeclaringClass().getName();
    return RESOURCE_LOOKUP_PREFIX + "/" + className + "/" + propertyName;
}
 
開發者ID:weld,項目名稱:weld-junit,代碼行數:26,代碼來源:MockResourceInjectionServices.java

示例2: execPlugIn

import javax.annotation.Resource; //導入方法依賴的package包/類
public GroovyObject execPlugIn(String name, GroovyObject groovyObject,
		GroovyObject proxyObject) throws Exception {
	Field[] fields=groovyObject.getClass().getDeclaredFields();
	int size=fields.length;
	for(int i=0;i<size;i++){
		Field field=fields[i];
		Resource anno=field.getAnnotation(Resource.class);
		if(anno!=null){
			String beanId=anno.name();
			if(beanId==null || "".equals(beanId)){
				beanId=field.getName();
			}
			Object beanObj=MicroContextHolder.getContext().getBean(beanId);
			field.set(groovyObject, beanObj);
		}
	}
	return proxyObject;
}
 
開發者ID:jeffreyning,項目名稱:nh-micro,代碼行數:19,代碼來源:MicroInjectPlugin.java

示例3: getName

import javax.annotation.Resource; //導入方法依賴的package包/類
private static String getName(Resource annotation, String defaultName) {
    String name = annotation.name();
    if (name == null || name.equals("")) {
        if (defaultName != null) {
            name = defaultName;
        }
    }
    return name;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:10,代碼來源:WebAnnotationSet.java

示例4: 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);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,代碼來源:Reference.java

示例5: 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();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:CommonAnnotationBeanPostProcessor.java

示例6: getName

import javax.annotation.Resource; //導入方法依賴的package包/類
private static String getName(Resource annotation, String defaultName) {
	String name = annotation.name();
	if (name == null || name.equals("")) {
		if (defaultName != null) {
			name = defaultName;
		}
	}
	return name;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:10,代碼來源:WebAnnotationSet.java

示例7: 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);
        }
    }
}
 
開發者ID:warlock-china,項目名稱:wisp,代碼行數:51,代碼來源:UnitTestDependencyInjectionTestExecutionListener.java


注:本文中的javax.annotation.Resource.name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。