001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind;
007
008import gov.nist.secauto.metaschema.core.model.IModule;
009import gov.nist.secauto.metaschema.core.model.MetaschemaException;
010import gov.nist.secauto.metaschema.databind.codegen.IModuleBindingGenerator;
011import gov.nist.secauto.metaschema.databind.model.IBoundModule;
012
013import edu.umd.cs.findbugs.annotations.NonNull;
014
015public class SimpleModuleLoaderStrategy
016    extends AbstractModuleLoaderStrategy {
017  @NonNull
018  private static final IModuleBindingGenerator COMPILATION_DISABLED_GENERATOR = module -> {
019    throw new UnsupportedOperationException(
020        "Dynamic compilation of Metaschema modules is not enabled by default." +
021            " Configure a different IModuleBindingGenerator with the IModuleLoaderStrategy" +
022            " used with the IBindignContext.");
023  };
024
025  @NonNull
026  private final IModuleBindingGenerator generator;
027
028  public SimpleModuleLoaderStrategy() {
029    this(COMPILATION_DISABLED_GENERATOR);
030  }
031
032  public SimpleModuleLoaderStrategy(@NonNull IModuleBindingGenerator generator) {
033    this.generator = generator;
034  }
035
036  @Override
037  protected Class<? extends IBoundModule> handleUnboundModule(IModule module) throws MetaschemaException {
038    return generator.generate(module);
039  }
040}