diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java index 49eae39377..cab82c48c1 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/services/ValidationService.java @@ -489,24 +489,7 @@ public String initializeValidator(CliContext cliContext, String definitions, Tim if (sessionId != null) { System.out.println("No such cached session exists for session id " + sessionId + ", re-instantiating validator."); } - ValidationEngine validationEngine; - if (cliContext.getBaseEngine() != null && hasBaseEngineForKey(cliContext.getBaseEngine())) { - System.out.println("Building new validator engine from base engine: " + cliContext.getBaseEngine()); - validationEngine = new ValidationEngine(getBaseEngine(cliContext.getBaseEngine())); - /* As a service, it wouldn't be efficient to have a base validation engine - * for every language. So we just use the baseEngine and set the language - * manually afterward. - */ - validationEngine.setLanguage(cliContext.getLang()); - validationEngine.setLocale(cliContext.getLocale()); - } else { - System.out.println("Building new validator engine from CliContext"); - if (cliContext.getSv() == null) { - String sv = determineVersion(cliContext); - cliContext.setSv(sv); - } - validationEngine = buildValidationEngine(cliContext, definitions, tt); - } + ValidationEngine validationEngine = getValidationEngineFromCliContext(cliContext, definitions, tt); sessionId = sessionCache.cacheSession(validationEngine); System.out.println("Cached new session. Cache size = " + sessionCache.getSessionIds().size()); } else { @@ -515,6 +498,28 @@ public String initializeValidator(CliContext cliContext, String definitions, Tim return sessionId; } + private ValidationEngine getValidationEngineFromCliContext(CliContext cliContext, String definitions, TimeTracker tt) throws Exception { + ValidationEngine validationEngine; + if (cliContext.getBaseEngine() != null && hasBaseEngineForKey(cliContext.getBaseEngine())) { + System.out.println("Building new validator engine from base engine: " + cliContext.getBaseEngine()); + validationEngine = new ValidationEngine(getBaseEngine(cliContext.getBaseEngine())); + /* As a service, it wouldn't be efficient to have a base validation engine + * for every language. So we just use the baseEngine and set the language + * manually afterward. + */ + validationEngine.setLanguage(cliContext.getLang()); + validationEngine.setLocale(cliContext.getLocale()); + } else { + System.out.println("Building new validator engine from CliContext"); + if (cliContext.getSv() == null) { + String sv = determineVersion(cliContext); + cliContext.setSv(sv); + } + validationEngine = buildValidationEngine(cliContext, definitions, tt); + } + return validationEngine; + } + protected ValidationEngine.ValidationEngineBuilder getValidationEngineBuilder() { return new ValidationEngine.ValidationEngineBuilder(); }