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