Introduce ResultHandlerService

- Replace main use of ResultHandler with ResultHandlerService which is
  a framework type of impl for handlers found from conversion service.
  This handles types better and easier to handle with bean cycles, etc.
- Removed IterableResultHandler to think about these use cases later
  when further refactoring is done.
- TypeHierarchyResultHandler is removed and better functionality now
  via ResultHandlerService.
- Relates #336
This commit is contained in:
Janne Valkealahti
2021-12-21 17:49:06 +00:00
parent c5081acee8
commit d883e0e660
12 changed files with 531 additions and 160 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.shell.boot;
import java.util.Collection;
import java.util.Set;
import javax.validation.Validation;
import javax.validation.Validator;
@@ -33,8 +34,9 @@ import org.springframework.core.convert.converter.ConverterFactory;
import org.springframework.core.convert.converter.GenericConverter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.shell.ResultHandler;
import org.springframework.shell.ResultHandlerService;
import org.springframework.shell.Shell;
import org.springframework.shell.result.IterableResultHandler;
import org.springframework.shell.result.GenericResultHandlerService;
import org.springframework.shell.result.ResultHandlerConfig;
/**
@@ -71,8 +73,16 @@ public class SpringShellAutoConfiguration {
}
@Bean
public Shell shell(@Qualifier("main") ResultHandler resultHandler, @Qualifier("iterableResultHandler") IterableResultHandler iterableResultHandler) {
iterableResultHandler.setDelegate(resultHandler);
return new Shell(resultHandler);
public ResultHandlerService resultHandlerService(Set<ResultHandler<?>> resultHandlers) {
GenericResultHandlerService service = new GenericResultHandlerService();
for (ResultHandler<?> resultHandler : resultHandlers) {
service.addResultHandler(resultHandler);
}
return service;
}
@Bean
public Shell shell(ResultHandlerService resultHandlerService) {
return new Shell(resultHandlerService);
}
}