use of org.elasticsearch.common.inject.internal.Errors in project elasticsearch by elastic.
the class InjectorImpl method getProviderOrThrow.
<T> Provider<T> getProviderOrThrow(final Key<T> key, Errors errors) throws ErrorsException {
final InternalFactory<? extends T> factory = getInternalFactory(key, errors);
// ES: optimize for a common case of read only instance getting from the parent...
if (factory instanceof InternalFactory.Instance) {
return new Provider<T>() {
@Override
public T get() {
try {
return (T) ((InternalFactory.Instance) factory).get(null, null, null);
} catch (ErrorsException e) {
// ignore
}
// should never happen...
assert false;
return null;
}
};
}
final Dependency<T> dependency = Dependency.get(key);
return new Provider<T>() {
@Override
public T get() {
final Errors errors = new Errors(dependency);
try {
T t = callInContext(new ContextualCallable<T>() {
@Override
public T call(InternalContext context) throws ErrorsException {
context.setDependency(dependency);
try {
return factory.get(errors, context, dependency);
} finally {
context.setDependency(null);
}
}
});
errors.throwIfNewErrors(0);
return t;
} catch (ErrorsException e) {
throw new ProvisionException(errors.merge(e.getErrors()).getMessages());
}
}
@Override
public String toString() {
return factory.toString();
}
};
}
use of org.elasticsearch.common.inject.internal.Errors in project elasticsearch by elastic.
the class MembersInjectorImpl method injectMembers.
@Override
public void injectMembers(T instance) {
Errors errors = new Errors(typeLiteral);
try {
injectAndNotify(instance, errors);
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
errors.throwProvisionExceptionIfErrorsExist();
}
use of org.elasticsearch.common.inject.internal.Errors in project elasticsearch by elastic.
the class MembersInjectorStore method getInjectors.
/**
* Returns the injectors for the specified injection points.
*/
List<SingleMemberInjector> getInjectors(Set<InjectionPoint> injectionPoints, Errors errors) {
List<SingleMemberInjector> injectors = new ArrayList<>();
for (InjectionPoint injectionPoint : injectionPoints) {
try {
Errors errorsForMember = injectionPoint.isOptional() ? new Errors(injectionPoint) : errors.withSource(injectionPoint);
SingleMemberInjector injector = injectionPoint.getMember() instanceof Field ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember) : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
injectors.add(injector);
} catch (ErrorsException ignoredForNow) {
// ignored for now
}
}
return Collections.unmodifiableList(injectors);
}
use of org.elasticsearch.common.inject.internal.Errors in project elasticsearch by elastic.
the class ProviderToInternalFactoryAdapter method get.
@Override
public T get() {
final Errors errors = new Errors();
try {
T t = injector.callInContext(new ContextualCallable<T>() {
@Override
public T call(InternalContext context) throws ErrorsException {
Dependency dependency = context.getDependency();
return internalFactory.get(errors, context, dependency);
}
});
errors.throwIfNewErrors(0);
return t;
} catch (ErrorsException e) {
throw new ProvisionException(errors.merge(e.getErrors()).getMessages());
}
}
use of org.elasticsearch.common.inject.internal.Errors in project elasticsearch by elastic.
the class InjectionPoint method forMember.
private List<Dependency<?>> forMember(Member member, TypeLiteral<?> type, Annotation[][] parameterAnnotations) {
Errors errors = new Errors(member);
Iterator<Annotation[]> annotationsIterator = Arrays.asList(parameterAnnotations).iterator();
List<Dependency<?>> dependencies = new ArrayList<>();
int index = 0;
for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
try {
Annotation[] paramAnnotations = annotationsIterator.next();
Key<?> key = Annotations.getKey(parameterType, member, paramAnnotations, errors);
dependencies.add(newDependency(key, Nullability.allowsNull(paramAnnotations), index));
index++;
} catch (ErrorsException e) {
errors.merge(e.getErrors());
}
}
errors.throwConfigurationExceptionIfErrorsExist();
return Collections.unmodifiableList(dependencies);
}
Aggregations