1 /* 2 * SPDX-FileCopyrightText: none 3 * SPDX-License-Identifier: CC0-1.0 4 */ 5 6 package gov.nist.secauto.metaschema.core.model; 7 8 import java.util.Collection; 9 import java.util.function.Predicate; 10 11 import edu.umd.cs.findbugs.annotations.NonNull; 12 import edu.umd.cs.findbugs.annotations.Nullable; 13 14 /** 15 * Represents a Metaschema definition for a complex object that may contain 16 * flags. 17 */ 18 public interface IModelDefinition extends IDefinition, IContainer { 19 /** 20 * Tests if the provided definition represents complex data. The data is complex 21 * if one of the following is true: 22 * <ul> 23 * <li>The instance is a {@link IAssemblyDefinition}.</li> 24 * <li>The instance is a {@link IFieldDefinition} that has flags.</li> 25 * </ul> 26 * 27 * This method can be used as a {@link Predicate}. 28 * 29 * @param definition 30 * the definition to test 31 * @return {@code true} if the data is complex, or {@code false} otherwise 32 */ 33 static boolean complexObjectFilter(IModelDefinition definition) { 34 boolean retval = true; 35 if (definition instanceof IFieldDefinition) { 36 IFieldDefinition field = (IFieldDefinition) definition; 37 retval = !field.getFlagInstances().isEmpty(); 38 } 39 return retval; 40 } 41 42 @Override 43 default boolean hasChildren() { 44 return !getFlagInstances().isEmpty(); 45 } 46 47 /** 48 * Retrieves a flag instance, by the flag's effective name-based qualified name 49 * index. 50 * 51 * @param index 52 * the flag's name-based qualified name index 53 * @return the matching flag instance, or {@code null} if there is no flag 54 * matching the specified name 55 */ 56 @Nullable 57 IFlagInstance getFlagInstanceByName(@NonNull Integer index); 58 59 /** 60 * Retrieves the flag instances for all flags defined on the containing 61 * definition. 62 * 63 * @return the flags 64 */ 65 @NonNull 66 Collection<? extends IFlagInstance> getFlagInstances(); 67 68 /** 69 * Retrieves the flag instance to use as as the property name for the containing 70 * object in JSON who's value will be the object containing the flag. 71 * 72 * @return the flag instance if a JSON key is configured, or {@code null} 73 * otherwise 74 */ 75 // TODO: remove once moved to the instance side 76 @Nullable 77 IFlagInstance getJsonKey(); 78 }