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 javax.xml.namespace.QName;
19  
20  import edu.umd.cs.findbugs.annotations.NonNull;
21  
22  public interface IBoundModule
23      extends IModuleExtended<
24          IBoundModule,
25          IBoundDefinitionModelComplex,
26          IBoundDefinitionFlag,
27          IBoundDefinitionModelField<?>,
28          IBoundDefinitionModelAssembly> {
29  
30    @NonNull
31    static IBoundModule newInstance(
32        @NonNull Class<? extends IBoundModule> clazz,
33        @NonNull IBindingContext bindingContext,
34        @NonNull List<? extends IBoundModule> importedModules) {
35  
36      Constructor<? extends IBoundModule> constructor;
37      try {
38        constructor = clazz.getDeclaredConstructor(List.class, IBindingContext.class);
39      } catch (NoSuchMethodException ex) {
40        throw new IllegalArgumentException(ex);
41      }
42  
43      try {
44        return ObjectUtils.notNull(constructor.newInstance(importedModules, bindingContext));
45      } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) {
46        throw new IllegalArgumentException(ex);
47      }
48    }
49  
50    /**
51     * Get the Module binding context.
52     *
53     * @return the context
54     */
55    @NonNull
56    IBindingContext getBindingContext();
57  
58    @Override
59    default URI getLocation() { // NOPMD - intentional
60      // not known
61      return null;
62    }
63  
64    @Override
65    Collection<IBoundDefinitionModelAssembly> getAssemblyDefinitions();
66  
67    @Override
68    IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull QName name);
69  
70    @Override
71    Collection<IBoundDefinitionModelField<?>> getFieldDefinitions();
72  
73    @Override
74    IBoundDefinitionModelField<?> getFieldDefinitionByName(@NonNull QName name);
75  }