001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValue; 004import gov.nist.secauto.metaschema.binding.model.annotations.AllowedValues; 005import gov.nist.secauto.metaschema.binding.model.annotations.BoundField; 006import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue; 007import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag; 008import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs; 009import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly; 010import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints; 011import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior; 012import gov.nist.secauto.metaschema.model.common.constraint.IConstraint; 013import gov.nist.secauto.metaschema.model.common.datatype.adapter.TokenAdapter; 014import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine; 015import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLineAdapter; 016import gov.nist.secauto.metaschema.model.common.util.ObjectUtils; 017import java.lang.Override; 018import java.lang.String; 019import java.util.LinkedList; 020import java.util.List; 021import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle; 022import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 023 024/** 025 * Presenting a choice among alternatives. 026 */ 027@MetaschemaAssembly( 028 formalName = "Selection", 029 description = "Presenting a choice among alternatives.", 030 name = "parameter-selection", 031 metaschema = OscalControlCommonMetaschema.class, 032 remarks = "A set of parameter value choices, that may be picked from to set the parameter value." 033) 034public class ParameterSelection { 035 @BoundFlag( 036 formalName = "Parameter Cardinality", 037 description = "Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted.", 038 useName = "how-many", 039 typeAdapter = TokenAdapter.class 040 ) 041 @ValueConstraints( 042 allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "one", description = "Only one value is permitted."), @AllowedValue(value = "one-or-more", description = "One or more values are permitted.")}) 043 ) 044 private String _howMany; 045 046 /** 047 * "A value selection among several such options." 048 */ 049 @BoundField( 050 formalName = "Choice", 051 description = "A value selection among several such options.", 052 useName = "choice", 053 maxOccurs = -1 054 ) 055 @BoundFieldValue( 056 typeAdapter = MarkupLineAdapter.class 057 ) 058 @GroupAs( 059 name = "choice", 060 inJson = JsonGroupAsBehavior.LIST 061 ) 062 private List<MarkupLine> _choice; 063 064 public ParameterSelection() { 065 } 066 067 public String getHowMany() { 068 return _howMany; 069 } 070 071 public void setHowMany(String value) { 072 _howMany = value; 073 } 074 075 public List<MarkupLine> getChoice() { 076 return _choice; 077 } 078 079 public void setChoice(List<MarkupLine> value) { 080 _choice = value; 081 } 082 083 /** 084 * Add a new {@link MarkupLine} item to the underlying collection. 085 * @param item the item to add 086 * @return {@code true} 087 */ 088 public boolean addChoice(MarkupLine item) { 089 MarkupLine value = ObjectUtils.requireNonNull(item,"item cannot be null"); 090 if (_choice == null) { 091 _choice = new LinkedList<>(); 092 } 093 return _choice.add(value); 094 } 095 096 /** 097 * Remove the first matching {@link MarkupLine} item from the underlying collection. 098 * @param item the item to remove 099 * @return {@code true} if the item was removed or {@code false} otherwise 100 */ 101 public boolean removeChoice(MarkupLine item) { 102 MarkupLine value = ObjectUtils.requireNonNull(item,"item cannot be null"); 103 return _choice == null ? false : _choice.remove(value); 104 } 105 106 @Override 107 public String toString() { 108 return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString(); 109 } 110}