001/* 002 * SPDX-FileCopyrightText: none 003 * SPDX-License-Identifier: CC0-1.0 004 */ 005 006package gov.nist.secauto.metaschema.databind.model; 007 008import gov.nist.secauto.metaschema.core.model.IModuleExtended; 009import gov.nist.secauto.metaschema.core.util.ObjectUtils; 010import gov.nist.secauto.metaschema.databind.IBindingContext; 011 012import java.lang.reflect.Constructor; 013import java.lang.reflect.InvocationTargetException; 014import java.net.URI; 015import java.util.Collection; 016import java.util.List; 017 018import edu.umd.cs.findbugs.annotations.NonNull; 019 020public interface IBoundModule 021 extends IModuleExtended< 022 IBoundModule, 023 IBoundDefinitionModelComplex, 024 IBoundDefinitionFlag, 025 IBoundDefinitionModelField<?>, 026 IBoundDefinitionModelAssembly> { 027 028 @NonNull 029 static IBoundModule newInstance( 030 @NonNull Class<? extends IBoundModule> clazz, 031 @NonNull IBindingContext bindingContext, 032 @NonNull List<? extends IBoundModule> importedModules) { 033 034 Constructor<? extends IBoundModule> constructor; 035 try { 036 constructor = clazz.getDeclaredConstructor(List.class, IBindingContext.class); 037 } catch (NoSuchMethodException ex) { 038 throw new IllegalArgumentException(ex); 039 } 040 041 try { 042 return ObjectUtils.notNull(constructor.newInstance(importedModules, bindingContext)); 043 } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { 044 throw new IllegalArgumentException(ex); 045 } 046 } 047 048 /** 049 * Get the Module binding context. 050 * 051 * @return the context 052 */ 053 @NonNull 054 IBindingContext getBindingContext(); 055 056 @Override 057 default URI getLocation() { // NOPMD - intentional 058 // not known 059 return null; 060 } 061 062 @Override 063 Collection<IBoundDefinitionModelAssembly> getAssemblyDefinitions(); 064 065 @Override 066 IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull Integer name); 067 068 @Override 069 Collection<IBoundDefinitionModelField<?>> getFieldDefinitions(); 070 071 @Override 072 IBoundDefinitionModelField<?> getFieldDefinitionByName(@NonNull Integer name); 073}