本文整理汇总了Java中com.nick.scalpel.annotation.opt.RetrieveBean类的典型用法代码示例。如果您正苦于以下问题:Java RetrieveBean类的具体用法?Java RetrieveBean怎么用?Java RetrieveBean使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RetrieveBean类属于com.nick.scalpel.annotation.opt包,在下文中一共展示了RetrieveBean类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: autoWire
import com.nick.scalpel.annotation.opt.RetrieveBean; //导入依赖的package包/类
private void autoWire(Object object, Field field) {
makeAccessible(field);
Object fieldObject = getField(field, object);
if (fieldObject != null) return;
RetrieveBean retrieveBean = field.getAnnotation(RetrieveBean.class);
boolean singleton = retrieveBean.singleton();
int id = retrieveBean.id();
if (id > 0) {
Object bean = getBeanById(id);
setField(field, object, Preconditions.checkNotNull(bean, "No such bean with id:" + id));
return;
}
Class clz = field.getType();
if (!singleton) {
setField(field, object, createBeanAndCache(clz));
} else {
Object existingBean = findBeanByClass(clz, id);
if (existingBean != null) {
logD("Using existing bean:" + existingBean + ", for:" + field);
setField(field, object, existingBean);
} else {
setField(field, object, createBeanAndCache(clz));
}
}
}
示例2: annotationClass
import com.nick.scalpel.annotation.opt.RetrieveBean; //导入依赖的package包/类
@Override
public Class<? extends Annotation> annotationClass() {
return RetrieveBean.class;
}