001// Generated from: ../../../../../../../../oscal/src/metaschema/oscal_mapping-common_metaschema.xml 002// Do not edit - changes will be lost when regenerated. 003package dev.metaschema.oscal.lib.model; 004 005import dev.metaschema.core.datatype.adapter.TokenAdapter; 006import dev.metaschema.core.model.IBoundObject; 007import dev.metaschema.core.model.IMetaschemaData; 008import dev.metaschema.core.model.JsonGroupAsBehavior; 009import dev.metaschema.core.model.constraint.IConstraint; 010import dev.metaschema.core.util.ObjectUtils; 011import dev.metaschema.databind.model.annotations.AllowedValue; 012import dev.metaschema.databind.model.annotations.AllowedValues; 013import dev.metaschema.databind.model.annotations.BoundAssembly; 014import dev.metaschema.databind.model.annotations.BoundField; 015import dev.metaschema.databind.model.annotations.BoundFlag; 016import dev.metaschema.databind.model.annotations.GroupAs; 017import dev.metaschema.databind.model.annotations.MetaschemaAssembly; 018import dev.metaschema.databind.model.annotations.ValueConstraints; 019import edu.umd.cs.findbugs.annotations.NonNull; 020import edu.umd.cs.findbugs.annotations.Nullable; 021import java.util.LinkedList; 022import java.util.List; 023import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 024import org.apache.commons.lang3.builder.ToStringStyle; 025 026/** 027 * Select a control or controls from an imported control set. 028 */ 029@MetaschemaAssembly( 030 formalName = "Select Control", 031 description = "Select a control or controls from an imported control set.", 032 name = "select-control-by-id", 033 moduleClass = OscalMappingCommonModule.class, 034 remarks = "If `with-child-controls` is \"yes\" on the call to a control, no sibling `call`elements need to be used to call any controls appearing within it. Since generally, this is how control enhancements are represented (as controls within controls), this provides a way to include controls with all their dependent controls (enhancements) without having to call them individually." 035) 036public class SelectControlById implements IBoundObject { 037 private final IMetaschemaData __metaschemaData; 038 039 /** 040 * When a control is included, whether its child (dependent) controls are also included. 041 */ 042 @BoundFlag( 043 formalName = "Include Contained Controls with Control", 044 description = "When a control is included, whether its child (dependent) controls are also included.", 045 name = "with-child-controls", 046 typeAdapter = TokenAdapter.class, 047 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "yes", description = "Include child controls with an included control."), @AllowedValue(value = "no", description = "When importing a control, only include child controls that are also explicitly called.")})) 048 ) 049 private String _withChildControls; 050 051 /** 052 * Selecting a control by its ID given as a literal. 053 */ 054 @BoundField( 055 formalName = "Match Controls by Identifier", 056 description = "Selecting a control by its ID given as a literal.", 057 useName = "with-id", 058 maxOccurs = -1, 059 groupAs = @GroupAs(name = "with-ids", inJson = JsonGroupAsBehavior.LIST), 060 typeAdapter = TokenAdapter.class 061 ) 062 private List<String> _withIds; 063 064 /** 065 * Selecting a set of controls by matching their IDs with a wildcard pattern. 066 */ 067 @BoundAssembly( 068 formalName = "Match Controls by Pattern", 069 description = "Selecting a set of controls by matching their IDs with a wildcard pattern.", 070 useName = "matching", 071 maxOccurs = -1, 072 groupAs = @GroupAs(name = "matching", inJson = JsonGroupAsBehavior.LIST) 073 ) 074 private List<MappedControlMatching> _matching; 075 076 /** 077 * Constructs a new {@code dev.metaschema.oscal.lib.model.SelectControlById} instance with no metadata. 078 */ 079 public SelectControlById() { 080 this(null); 081 } 082 083 /** 084 * Constructs a new {@code dev.metaschema.oscal.lib.model.SelectControlById} instance with the specified metadata. 085 * 086 * @param data 087 * the metaschema data, or {@code null} if none 088 */ 089 public SelectControlById(IMetaschemaData data) { 090 this.__metaschemaData = data; 091 } 092 093 @Override 094 public IMetaschemaData getMetaschemaData() { 095 return __metaschemaData; 096 } 097 098 /** 099 * Get the "{@literal Include Contained Controls with Control}". 100 * 101 * <p> 102 * When a control is included, whether its child (dependent) controls are also included. 103 * 104 * @return the with-child-controls value, or {@code null} if not set 105 */ 106 @Nullable 107 public String getWithChildControls() { 108 return _withChildControls; 109 } 110 111 /** 112 * Set the "{@literal Include Contained Controls with Control}". 113 * 114 * <p> 115 * When a control is included, whether its child (dependent) controls are also included. 116 * 117 * @param value 118 * the with-child-controls value to set, or {@code null} to clear 119 */ 120 public void setWithChildControls(@Nullable String value) { 121 _withChildControls = value; 122 } 123 124 /** 125 * Get the "{@literal Match Controls by Identifier}". 126 * 127 * <p> 128 * Selecting a control by its ID given as a literal. 129 * 130 * @return the with-id value 131 */ 132 @NonNull 133 public List<String> getWithIds() { 134 if (_withIds == null) { 135 _withIds = new LinkedList<>(); 136 } 137 return ObjectUtils.notNull(_withIds); 138 } 139 140 /** 141 * Set the "{@literal Match Controls by Identifier}". 142 * 143 * <p> 144 * Selecting a control by its ID given as a literal. 145 * 146 * @param value 147 * the with-id value to set 148 */ 149 public void setWithIds(@NonNull List<String> value) { 150 _withIds = value; 151 } 152 153 /** 154 * Add a new {@link String} item to the underlying collection. 155 * @param item the item to add 156 * @return {@code true} 157 */ 158 public boolean addWithId(String item) { 159 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 160 if (_withIds == null) { 161 _withIds = new LinkedList<>(); 162 } 163 return _withIds.add(value); 164 } 165 166 /** 167 * Remove the first matching {@link String} item from the underlying collection. 168 * @param item the item to remove 169 * @return {@code true} if the item was removed or {@code false} otherwise 170 */ 171 public boolean removeWithId(String item) { 172 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 173 return _withIds != null && _withIds.remove(value); 174 } 175 176 /** 177 * Get the "{@literal Match Controls by Pattern}". 178 * 179 * <p> 180 * Selecting a set of controls by matching their IDs with a wildcard pattern. 181 * 182 * @return the matching value 183 */ 184 @NonNull 185 public List<MappedControlMatching> getMatching() { 186 if (_matching == null) { 187 _matching = new LinkedList<>(); 188 } 189 return ObjectUtils.notNull(_matching); 190 } 191 192 /** 193 * Set the "{@literal Match Controls by Pattern}". 194 * 195 * <p> 196 * Selecting a set of controls by matching their IDs with a wildcard pattern. 197 * 198 * @param value 199 * the matching value to set 200 */ 201 public void setMatching(@NonNull List<MappedControlMatching> value) { 202 _matching = value; 203 } 204 205 /** 206 * Add a new {@link MappedControlMatching} item to the underlying collection. 207 * @param item the item to add 208 * @return {@code true} 209 */ 210 public boolean addMatching(MappedControlMatching item) { 211 MappedControlMatching value = ObjectUtils.requireNonNull(item,"item cannot be null"); 212 if (_matching == null) { 213 _matching = new LinkedList<>(); 214 } 215 return _matching.add(value); 216 } 217 218 /** 219 * Remove the first matching {@link MappedControlMatching} item from the underlying collection. 220 * @param item the item to remove 221 * @return {@code true} if the item was removed or {@code false} otherwise 222 */ 223 public boolean removeMatching(MappedControlMatching item) { 224 MappedControlMatching value = ObjectUtils.requireNonNull(item,"item cannot be null"); 225 return _matching != null && _matching.remove(value); 226 } 227 228 @Override 229 public String toString() { 230 return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString()); 231 } 232}