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