* @return the desired source
*/
@SuppressWarnings("unchecked")
protected static <U> AbstractDataSource<U> getSource(final IKey key, boolean readImmediately) {
AbstractDataSource<U> result = null;
final IDataSourceProducer producer = DataSourceProducerProvider.getProducer(key.getSourceProduction());
try {
if (producer == null) {
throw new KeyCompatibilityException(key, producer);
} else if (producer instanceof AbstractRefreshingManager<?>) {
result = (AbstractDataSource<U>) ((AbstractRefreshingManager<?>) producer).createDataSource(key, false,
readImmediately);
} else {
result = (AbstractDataSource<U>) producer.createDataSource(key);
}
} catch (final Exception e) {
Logger.getLogger(Mediator.LOGGER_ACCESS).log(Level.SEVERE,
"Failed to create source for key: " + (key == null ? null : key.getInformationKey()), e);
}