当前位置: 首页>>代码示例>>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;未经允许,请勿转载。