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