try {
@SuppressWarnings("unchecked")
T t = (T) factoryMethod.invoke(factory, (Object[])null);
return t;
} catch (Exception ex) {
throw new JuRuntimeException("Couldn't invoke method " + factoryMethod, ex);
}
}
@Override
public String toString() {
return factoryMethod.toString();
}
});
}
}
}
} else {
if (clazz.isAssignableFrom(simulatable.getClass())) {
@SuppressWarnings("unchecked")
final T type = (T)simulatable;
this.addType(clazz
, implementations
, type.getClass().getAnnotation(DynamicCdiTag.class)
, new TypeCreator<T>() {
@Override
public T createType() {
return type;
}
@Override
public String toString() {
return type.getClass().getName();
}
});
}
}
}
if (implementations.containsKey(tagName)) {
logger.debug("Returning intance by tag match: {}", implementations.get(tagName));
return implementations.get(tagName).createType();
} else if (implementations.containsKey(defaultTagName)) {
logger.debug("Returning default instance: {}", implementations.get(defaultTagName));
return implementations.get(defaultTagName).createType();
} else {
throw new JuRuntimeException(String.format("No dynamic implementation found for %s and tagName=%s or defaultTagName=%s",
clazz.getName(), tagName, defaultTagName));
}
}