@Override
public <T extends ErlangService> T getService(final Class<T> type) {
try {
final Class<? extends ErlangService> clazz = implementations.get(type);
if (clazz == null) {
throw new InjectionException(
"ErlangService implementation not found for " + type.getName());
}
final Constructor<?> constructor = clazz.getConstructors()[0];
final Class<?>[] parameterTypes = constructor.getParameterTypes();
final Object[] initargs = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
final Class<?> paramType = parameterTypes[i];
initargs[i] = injectParameter(paramType);
}
return (T) constructor.newInstance(initargs);
} catch (final Exception e) {
throw new InjectionException("Could not instantiate service "
+ type.getName(), e);
}
}