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