1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind.model;
7   
8   import gov.nist.secauto.metaschema.core.model.IModuleExtended;
9   import gov.nist.secauto.metaschema.core.util.ObjectUtils;
10  import gov.nist.secauto.metaschema.databind.IBindingContext;
11  
12  import java.lang.reflect.Constructor;
13  import java.lang.reflect.InvocationTargetException;
14  import java.net.URI;
15  import java.util.Collection;
16  import java.util.List;
17  
18  import edu.umd.cs.findbugs.annotations.NonNull;
19  
20  public interface IBoundModule
21      extends IModuleExtended<
22          IBoundModule,
23          IBoundDefinitionModelComplex,
24          IBoundDefinitionFlag,
25          IBoundDefinitionModelField<?>,
26          IBoundDefinitionModelAssembly> {
27  
28    @NonNull
29    static IBoundModule newInstance(
30        @NonNull Class<? extends IBoundModule> clazz,
31        @NonNull IBindingContext bindingContext,
32        @NonNull List<? extends IBoundModule> importedModules) {
33  
34      Constructor<? extends IBoundModule> constructor;
35      try {
36        constructor = clazz.getDeclaredConstructor(List.class, IBindingContext.class);
37      } catch (NoSuchMethodException ex) {
38        throw new IllegalArgumentException(ex);
39      }
40  
41      try {
42        return ObjectUtils.notNull(constructor.newInstance(importedModules, bindingContext));
43      } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
44        throw new IllegalArgumentException(ex);
45      }
46    }
47  
48    /**
49     * Get the Module binding context.
50     *
51     * @return the context
52     */
53    @NonNull
54    IBindingContext getBindingContext();
55  
56    @Override
57    default URI getLocation() { // NOPMD - intentional
58      // not known
59      return null;
60    }
61  
62    @Override
63    Collection<IBoundDefinitionModelAssembly> getAssemblyDefinitions();
64  
65    @Override
66    IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull Integer name);
67  
68    @Override
69    Collection<IBoundDefinitionModelField<?>> getFieldDefinitions();
70  
71    @Override
72    IBoundDefinitionModelField<?> getFieldDefinitionByName(@NonNull Integer name);
73  }