ExitCodeGenerators Class — spring-boot Architecture
Architecture documentation for the ExitCodeGenerators class in ExitCodeGenerators.java from the spring-boot codebase.
Entity Profile
Source Code
core/spring-boot/src/main/java/org/springframework/boot/ExitCodeGenerators.java lines 40–131
class ExitCodeGenerators implements Iterable<ExitCodeGenerator> {
private final List<ExitCodeGenerator> generators = new ArrayList<>();
void addAll(Throwable exception, ExitCodeExceptionMapper... mappers) {
Assert.notNull(exception, "'exception' must not be null");
Assert.notNull(mappers, "'mappers' must not be null");
addAll(exception, Arrays.asList(mappers));
}
void addAll(Throwable exception, Iterable<? extends ExitCodeExceptionMapper> mappers) {
Assert.notNull(exception, "'exception' must not be null");
Assert.notNull(mappers, "'mappers' must not be null");
for (ExitCodeExceptionMapper mapper : mappers) {
add(exception, mapper);
}
}
void add(Throwable exception, ExitCodeExceptionMapper mapper) {
Assert.notNull(exception, "'exception' must not be null");
Assert.notNull(mapper, "'mapper' must not be null");
add(new MappedExitCodeGenerator(exception, mapper));
}
void addAll(ExitCodeGenerator... generators) {
Assert.notNull(generators, "'generators' must not be null");
addAll(Arrays.asList(generators));
}
void addAll(Iterable<? extends ExitCodeGenerator> generators) {
Assert.notNull(generators, "'generators' must not be null");
for (ExitCodeGenerator generator : generators) {
add(generator);
}
}
void add(ExitCodeGenerator generator) {
Assert.notNull(generator, "'generator' must not be null");
this.generators.add(generator);
AnnotationAwareOrderComparator.sort(this.generators);
}
@Override
public Iterator<ExitCodeGenerator> iterator() {
return this.generators.iterator();
}
/**
* Get the final exit code that should be returned. The final exit code is the first
* non-zero exit code that is {@link ExitCodeGenerator#getExitCode generated}.
* @return the final exit code.
*/
int getExitCode() {
int exitCode = 0;
for (ExitCodeGenerator generator : this.generators) {
try {
int value = generator.getExitCode();
if (value != 0) {
exitCode = value;
break;
}
}
catch (Exception ex) {
exitCode = 1;
ex.printStackTrace();
}
}
return exitCode;
}
/**
* Adapts an {@link ExitCodeExceptionMapper} to an {@link ExitCodeGenerator}.
*/
private static class MappedExitCodeGenerator implements ExitCodeGenerator {
private final Throwable exception;
private final ExitCodeExceptionMapper mapper;
MappedExitCodeGenerator(Throwable exception, ExitCodeExceptionMapper mapper) {
this.exception = exception;
this.mapper = mapper;
}
@Override
public int getExitCode() {
return this.mapper.getExitCode(this.exception);
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free