001package com.example.metaschema; 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.BoundAssembly; 014import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 015import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 016import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 017import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 018import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 019import java.lang.Override; 020import java.lang.String; 021import java.util.LinkedList; 022import java.util.List; 023import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 024import org.apache.commons.lang3.builder.ToStringStyle; 025 026@MetaschemaAssembly( 027 formalName = "Allowed Values Constraint", 028 name = "flag-allowed-values", 029 moduleClass = MetaschemaModelModule.class 030) 031public class FlagAllowedValues implements IBoundObject { 032 private final IMetaschemaData __metaschemaData; 033 034 @BoundFlag( 035 formalName = "Constraint Identifier", 036 name = "id", 037 typeAdapter = TokenAdapter.class 038 ) 039 private String _id; 040 041 @BoundFlag( 042 formalName = "Constraint Severity Level", 043 name = "level", 044 defaultValue = "ERROR", 045 typeAdapter = TokenAdapter.class, 046 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "CRITICAL", description = "A violation of the constraint represents a serious fault in the content that will prevent typical use of the content."), @AllowedValue(value = "ERROR", description = "A violation of the constraint represents a fault in the content. This may include issues around compatibility, integrity, consistency, etc."), @AllowedValue(value = "WARNING", description = "A violation of the constraint represents a potential issue with the content."), @AllowedValue(value = "INFORMATIONAL", description = "A violation of the constraint represents a point of interest."), @AllowedValue(value = "DEBUG", description = "A violation of the constraint represents a fault in the content that may warrant review by a developer when performing model or tool development.")})) 047 ) 048 private String _level; 049 050 @BoundFlag( 051 formalName = "Allow Non-Enumerated Values?", 052 name = "allow-other", 053 defaultValue = "no", 054 typeAdapter = TokenAdapter.class, 055 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "no", description = "Other value are not allowed."), @AllowedValue(value = "yes", description = "Other values are allowed.")})) 056 ) 057 private String _allowOther; 058 059 /** 060 * "Determines if the given enumerated values may be extended by other allowed value constraints." 061 */ 062 @BoundFlag( 063 formalName = "Allow Extension?", 064 description = "Determines if the given enumerated values may be extended by other allowed value constraints.", 065 name = "extensible", 066 defaultValue = "external", 067 typeAdapter = TokenAdapter.class, 068 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, values = {@AllowedValue(value = "model", description = "Can be extended by constraints within the same module."), @AllowedValue(value = "external", description = "Can be extended by external constraints."), @AllowedValue(value = "none", description = "Cannot be extended.")})) 069 ) 070 private String _extensible; 071 072 @BoundField( 073 formalName = "Formal Name", 074 description = "A formal name for the data construct, to be presented in documentation.", 075 useName = "formal-name" 076 ) 077 private String _formalName; 078 079 @BoundField( 080 formalName = "Description", 081 description = "A short description of the data construct's purpose, describing the constructs semantics.", 082 useName = "description", 083 typeAdapter = MarkupLineAdapter.class 084 ) 085 private MarkupLine _description; 086 087 @BoundAssembly( 088 formalName = "Property", 089 useName = "prop", 090 maxOccurs = -1, 091 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 092 ) 093 private List<Property> _props; 094 095 @BoundField( 096 formalName = "Allowed Value Enumeration", 097 useName = "enum", 098 minOccurs = 1, 099 maxOccurs = -1, 100 groupAs = @GroupAs(name = "enums", inJson = JsonGroupAsBehavior.LIST) 101 ) 102 private List<ConstraintValueEnum> _enums; 103 104 @BoundField( 105 formalName = "Remarks", 106 description = "Any explanatory or helpful information to be provided about the remarks parent.", 107 useName = "remarks" 108 ) 109 private Remarks _remarks; 110 111 public FlagAllowedValues() { 112 this(null); 113 } 114 115 public FlagAllowedValues(IMetaschemaData data) { 116 this.__metaschemaData = data; 117 } 118 119 @Override 120 public IMetaschemaData getMetaschemaData() { 121 return __metaschemaData; 122 } 123 124 public String getId() { 125 return _id; 126 } 127 128 public void setId(String value) { 129 _id = value; 130 } 131 132 public String getLevel() { 133 return _level; 134 } 135 136 public void setLevel(String value) { 137 _level = value; 138 } 139 140 public String getAllowOther() { 141 return _allowOther; 142 } 143 144 public void setAllowOther(String value) { 145 _allowOther = value; 146 } 147 148 public String getExtensible() { 149 return _extensible; 150 } 151 152 public void setExtensible(String value) { 153 _extensible = value; 154 } 155 156 public String getFormalName() { 157 return _formalName; 158 } 159 160 public void setFormalName(String value) { 161 _formalName = value; 162 } 163 164 public MarkupLine getDescription() { 165 return _description; 166 } 167 168 public void setDescription(MarkupLine value) { 169 _description = value; 170 } 171 172 public List<Property> getProps() { 173 return _props; 174 } 175 176 public void setProps(List<Property> value) { 177 _props = value; 178 } 179 180 /** 181 * Add a new {@link Property} item to the underlying collection. 182 * @param item the item to add 183 * @return {@code true} 184 */ 185 public boolean addProp(Property item) { 186 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 187 if (_props == null) { 188 _props = new LinkedList<>(); 189 } 190 return _props.add(value); 191 } 192 193 /** 194 * Remove the first matching {@link Property} item from the underlying collection. 195 * @param item the item to remove 196 * @return {@code true} if the item was removed or {@code false} otherwise 197 */ 198 public boolean removeProp(Property item) { 199 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 200 return _props != null && _props.remove(value); 201 } 202 203 public List<ConstraintValueEnum> getEnums() { 204 return _enums; 205 } 206 207 public void setEnums(List<ConstraintValueEnum> value) { 208 _enums = value; 209 } 210 211 /** 212 * Add a new {@link ConstraintValueEnum} item to the underlying collection. 213 * @param item the item to add 214 * @return {@code true} 215 */ 216 public boolean addEnum(ConstraintValueEnum item) { 217 ConstraintValueEnum value = ObjectUtils.requireNonNull(item,"item cannot be null"); 218 if (_enums == null) { 219 _enums = new LinkedList<>(); 220 } 221 return _enums.add(value); 222 } 223 224 /** 225 * Remove the first matching {@link ConstraintValueEnum} item from the underlying collection. 226 * @param item the item to remove 227 * @return {@code true} if the item was removed or {@code false} otherwise 228 */ 229 public boolean removeEnum(ConstraintValueEnum item) { 230 ConstraintValueEnum value = ObjectUtils.requireNonNull(item,"item cannot be null"); 231 return _enums != null && _enums.remove(value); 232 } 233 234 public Remarks getRemarks() { 235 return _remarks; 236 } 237 238 public void setRemarks(Remarks value) { 239 _remarks = value; 240 } 241 242 @Override 243 public String toString() { 244 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 245 } 246}