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 javax.xml.namespace.QName; 019 020import edu.umd.cs.findbugs.annotations.NonNull; 021 022public interface IBoundModule 023 extends IModuleExtended< 024 IBoundModule, 025 IBoundDefinitionModelComplex, 026 IBoundDefinitionFlag, 027 IBoundDefinitionModelField<?>, 028 IBoundDefinitionModelAssembly> { 029 030 @NonNull 031 static IBoundModule newInstance( 032 @NonNull Class<? extends IBoundModule> clazz, 033 @NonNull IBindingContext bindingContext, 034 @NonNull List<? extends IBoundModule> importedModules) { 035 036 Constructor<? extends IBoundModule> constructor; 037 try { 038 constructor = clazz.getDeclaredConstructor(List.class, IBindingContext.class); 039 } catch (NoSuchMethodException ex) { 040 throw new IllegalArgumentException(ex); 041 } 042 043 try { 044 return ObjectUtils.notNull(constructor.newInstance(importedModules, bindingContext)); 045 } catch (InstantiationException | IllegalAccessException | InvocationTargetException ex) { 046 throw new IllegalArgumentException(ex); 047 } 048 } 049 050 /** 051 * Get the Module binding context. 052 * 053 * @return the context 054 */ 055 @NonNull 056 IBindingContext getBindingContext(); 057 058 @Override 059 default URI getLocation() { // NOPMD - intentional 060 // not known 061 return null; 062 } 063 064 @Override 065 Collection<IBoundDefinitionModelAssembly> getAssemblyDefinitions(); 066 067 @Override 068 IBoundDefinitionModelAssembly getAssemblyDefinitionByName(@NonNull QName name); 069 070 @Override 071 Collection<IBoundDefinitionModelField<?>> getFieldDefinitions(); 072 073 @Override 074 IBoundDefinitionModelField<?> getFieldDefinitionByName(@NonNull QName name); 075}