try {
f.set(instance, context.get(f.getType()));
} catch (IllegalAccessException e) {
throw (Error) new IllegalAccessError(e.getMessage()).initCause(e);
} catch (InterruptedException e) {
throw new ProvisionException("Failed to set a context parameter", e);
} catch (IOException e) {
throw new ProvisionException("Failed to set a context parameter", e);
}
}
}
class MethodInjector<T> extends ParameterInjector<T> {
final Method m;
MethodInjector(Method m) {
this.m = m;
m.setAccessible(true);
}
@Override
public void injectMembers(T instance) {
try {
Class<?>[] types = m.getParameterTypes();
Object[] args = new Object[types.length];
for (int i = 0; i < args.length; i++) {
args[i] = context.get(types[i]);
}
m.invoke(instance, args);
} catch (IllegalAccessException e) {
throw (Error) new IllegalAccessError(e.getMessage()).initCause(e);
} catch (InvocationTargetException e) {
throw new ProvisionException("Failed to set a context parameter", e);
} catch (InterruptedException e) {
throw new ProvisionException("Failed to set a context parameter", e);
} catch (IOException e) {
throw new ProvisionException("Failed to set a context parameter", e);
}
}
}
});
}