1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind;
7
8 import gov.nist.secauto.metaschema.core.model.IModule;
9 import gov.nist.secauto.metaschema.databind.codegen.IModuleBindingGenerator;
10 import gov.nist.secauto.metaschema.databind.model.IBoundModule;
11
12 import edu.umd.cs.findbugs.annotations.NonNull;
13
14 public class SimpleModuleLoaderStrategy
15 extends AbstractModuleLoaderStrategy {
16 @NonNull
17 private static final IModuleBindingGenerator COMPILATION_DISABLED_GENERATOR = module -> {
18 throw new UnsupportedOperationException(
19 "Dynamic compilation of Metaschema modules is not enabled by default." +
20 " Configure a different IModuleBindingGenerator with the IModuleLoaderStrategy" +
21 " used with the IBindignContext.");
22 };
23
24 @NonNull
25 private final IModuleBindingGenerator generator;
26
27 public SimpleModuleLoaderStrategy() {
28 this(COMPILATION_DISABLED_GENERATOR);
29 }
30
31 public SimpleModuleLoaderStrategy(@NonNull IModuleBindingGenerator generator) {
32 this.generator = generator;
33 }
34
35 @Override
36 protected Class<? extends IBoundModule> handleUnboundModule(IModule module) {
37 return generator.generate(module);
38 }
39 }