/** * Load the Service implementation with the specified key. This method should never return null. * * @param <T> the type of the Service * @param type the type of the Service to load * @param key the key that identifies the desired implementation * @return the matching Service implementation * @throws NoSuchElementException if no service could be loaded with the given key. */ public static <T extends Service> T load( Class<T> type, String key ) { T service = loadSilently( type, key ); if ( service == null ) { throw new NoSuchElementException( String.format( "Could not find any implementation of %s with a key=\"%s\"", type.getName(), key ) ); } return service; }
@Nullable private static RecordFormats loadRecordFormat( String recordFormat ) { if ( StringUtils.isNotEmpty( recordFormat ) ) { if ( Standard.LATEST_NAME.equals( recordFormat ) ) { return Standard.LATEST_RECORD_FORMATS; } for ( RecordFormats knownFormat : KNOWN_FORMATS ) { if ( recordFormat.equals( knownFormat.name() ) ) { return knownFormat; } } RecordFormats.Factory formatFactory = Service.loadSilently( RecordFormats.Factory.class, recordFormat ); if ( formatFactory != null ) { return formatFactory.newInstance(); } } return null; }
/** * Load the Service implementation with the specified key. This method should never return null. * * @param <T> the type of the Service * @param type the type of the Service to load * @param key the key that identifies the desired implementation * @return the matching Service implementation * @throws NoSuchElementException if no service could be loaded with the given key. */ public static <T extends Service> T load( Class<T> type, String key ) { T service = loadSilently( type, key ); if ( service == null ) { throw new NoSuchElementException( String.format( "Could not find any implementation of %s with a key=\"%s\"", type.getName(), key ) ); } return service; }
@Nullable private static RecordFormats loadRecordFormat( String recordFormat ) { if ( StringUtils.isNotEmpty( recordFormat ) ) { if ( Standard.LATEST_NAME.equals( recordFormat ) ) { return Standard.LATEST_RECORD_FORMATS; } for ( RecordFormats knownFormat : KNOWN_FORMATS ) { if ( recordFormat.equals( knownFormat.name() ) ) { return knownFormat; } } RecordFormats.Factory formatFactory = Service.loadSilently( RecordFormats.Factory.class, recordFormat ); if ( formatFactory != null ) { return formatFactory.newInstance(); } } return null; }