本文整理了Java中org.jvnet.hk2.annotations.Inject.name()
方法的一些代码示例,展示了Inject.name()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Inject.name()
方法的具体详情如下:
包路径:org.jvnet.hk2.annotations.Inject
类名称:Inject
方法名:name
暂无
代码示例来源:origin: com.sun.enterprise/auto-depends
String getTargetName(AnnotatedElement target, Inject inject) {
Named named = target.getAnnotation(Named.class);
String name = inject.name();
if (named!=null && !inject.name().isEmpty()) {
throw new RuntimeException("Field or method [" + target.toString() + "] is annotated with both a @Named" +
" annotation as well as a @Inject.name() value, please choose");
}
if (named!=null) {
name = named.value();
}
return name;
}
}
代码示例来源:origin: org.glassfish.hk2/auto-depends
static String injection_failed_msg(Object t, Annotation inject, Throwable cause) {
String name = (Inject.class.isInstance(inject)) ? Inject.class.cast(inject).name() : null;
name = (null == name || name.isEmpty()) ? null : name;
String msg;
if (Field.class.isInstance(t)) {
Field target = Field.class.cast(t);
msg = "injection failed on " + target.getDeclaringClass().getName() + "." +
target.getName() + " with " + target.getGenericType() + (null == name ? "" : " and name '" + name + "'");
} else {
msg = "injection failed on " + t + (null == name ? "" : " with name '" + name + "'");
}
return msg;
}
代码示例来源:origin: com.sun.enterprise/auto-depends
static String injection_failed_msg(AnnotatedElement t, Annotation inject, Throwable cause) {
String name = (Inject.class.isInstance(inject)) ? Inject.class.cast(inject).name() : null;
name = (null == name || name.isEmpty()) ? null : name;
String msg;
if (Field.class.isInstance(t)) {
Field target = Field.class.cast(t);
msg = "injection failed on " + target.getDeclaringClass().getName() + "." +
target.getName() + " with " + target.getGenericType() + (null == name ? "" : " and name '" + name + "'");
} else {
msg = "injection failed on " + t + (null == name ? "" : " with name '" + name + "'");
}
return msg;
}
代码示例来源:origin: org.glassfish.hk2/auto-depends
void populateContractLocator(ContractLocatorImpl<?> contractLocator, AnnotatedElement target, Inject inject) {
Named named = target.getAnnotation(Named.class);
String name = inject.name();
if (named!=null && !inject.name().isEmpty()) {
throw new RuntimeException("Field or method [" + target.toString() + "] is annotated with both a @Named" +
" annotation as well as a @Inject.name() value, please choose");
}
if (named!=null) {
name = named.value();
}
contractLocator.named(name);
// now we need to obtain all qualifiers on the injection target so we narrow the search.
Annotation[] targetAnnotations = target.getAnnotations();
// if there is only one annotation, it's @Inject, we can ignore qualifiers narrowing
if (name.isEmpty() && targetAnnotations.length > 1) {
for (Annotation annotation : target.getAnnotations()) {
for (Annotation annotationAnnotation : annotation.annotationType().getAnnotations()) {
if (annotationAnnotation.annotationType()==Qualifier.class) {
contractLocator.annotatedWith(annotation.annotationType());
}
}
}
}
}
}
代码示例来源:origin: com.sun.enterprise/config
Class<V> type)
throws ComponentException {
String name = annotated.getAnnotation(Inject.class).name();
name = (null == name || name.isEmpty()) ? null : name;
代码示例来源:origin: org.glassfish.hk2/config
Class<V> type)
throws ComponentException {
String name = annotated.getAnnotation(Inject.class).name();
name = (null == name || name.isEmpty()) ? null : name;
代码示例来源:origin: com.sun.enterprise/auto-depends
protected <V> V getHolderInjectValue(final Habitat habitat,
final Object component,
final Inhabitant<?> onBehalfOf,
final AnnotatedElement target,
final Type genericType,
final Class<V> type,
final Inject inject) throws ComponentException {
final Type t = Types.getTypeArgument(((java.lang.reflect.Field) target).getGenericType(), 0);
final Class<?> finalType = Types.erasure(t);
if (habitat.isContract(finalType)) {
final Inhabitant<?> i = manage(onBehalfOf, habitat.getInhabitant(finalType, inject.name()));
return type.cast(i);
}
try {
if (finalType.cast(component) != null) {
return type.cast(onBehalfOf);
}
} catch (ClassCastException e) {
// ignore
}
V result = type.cast(getInhabitantByType(onBehalfOf, habitat, finalType));
// TODO: validate() here too
return result;
}
内容来源于网络,如有侵权,请联系作者删除!