1515 */
1616package io .serverlessworkflow .impl ;
1717
18+ import static io .serverlessworkflow .impl .WorkflowUtils .loadFirst ;
1819import static io .serverlessworkflow .impl .WorkflowUtils .safeClose ;
1920
2021import io .serverlessworkflow .api .types .SchemaInline ;
@@ -305,8 +306,7 @@ public Builder withDefaultCatalogURI(URI defaultCatalogURI) {
305306 public WorkflowApplication build () {
306307 if (modelFactory == null ) {
307308 modelFactory =
308- ServiceLoader .load (WorkflowModelFactory .class )
309- .findFirst ()
309+ loadFirst (WorkflowModelFactory .class )
310310 .orElseThrow (
311311 () ->
312312 new IllegalStateException (
@@ -318,21 +318,17 @@ public WorkflowApplication build() {
318318 ServiceLoader .load (ExpressionFactory .class ).forEach (exprFactories ::add );
319319 if (schemaValidatorFactory == null ) {
320320 schemaValidatorFactory =
321- ServiceLoader .load (SchemaValidatorFactory .class )
322- .findFirst ()
321+ loadFirst (SchemaValidatorFactory .class )
323322 .orElseGet (() -> EmptySchemaValidatorHolder .instance );
324323 }
325324 if (taskFactory == null ) {
326325 taskFactory =
327- ServiceLoader .load (TaskExecutorFactory .class )
328- .findFirst ()
329- .orElseGet (() -> DefaultTaskExecutorFactory .get ());
326+ loadFirst (TaskExecutorFactory .class ).orElseGet (() -> DefaultTaskExecutorFactory .get ());
330327 }
331328 ServiceLoader .load (EventPublisher .class ).forEach (e -> eventPublishers .add (e ));
332329 if (eventConsumer == null ) {
333330 eventConsumer =
334- ServiceLoader .load (EventConsumer .class )
335- .findFirst ()
331+ loadFirst (EventConsumer .class )
336332 .orElseGet (
337333 () -> {
338334 InMemoryEvents inMemory = new InMemoryEvents (executorFactory );
@@ -353,18 +349,14 @@ public WorkflowApplication build() {
353349
354350 if (configManager == null ) {
355351 configManager =
356- ServiceLoader .load (ConfigManager .class )
357- .findFirst ()
358- .orElseGet (() -> new SystemPropertyConfigManager ());
352+ loadFirst (ConfigManager .class ).orElseGet (() -> new SystemPropertyConfigManager ());
359353 }
360354 if (secretManager == null ) {
361355 secretManager =
362- ServiceLoader .load (SecretManager .class )
363- .findFirst ()
364- .orElseGet (() -> new ConfigSecretManager (configManager ));
356+ loadFirst (SecretManager .class ).orElseGet (() -> new ConfigSecretManager (configManager ));
365357 }
366- templateResolver = ServiceLoader . load (URITemplateResolver .class ). findFirst ( );
367- functionReader = ServiceLoader . load (FunctionReader .class ). findFirst ( );
358+ templateResolver = loadFirst (URITemplateResolver .class );
359+ functionReader = loadFirst (FunctionReader .class );
368360 if (defaultCatalogURI == null ) {
369361 defaultCatalogURI = URI .create ("https://github.com/serverlessworkflow/catalog" );
370362 }
0 commit comments