001package org.schemastore.json.sarif.x210;
002
003import gov.nist.secauto.metaschema.core.datatype.adapter.StringAdapter;
004import gov.nist.secauto.metaschema.core.model.IBoundObject;
005import gov.nist.secauto.metaschema.core.model.IMetaschemaData;
006import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior;
007import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
008import gov.nist.secauto.metaschema.core.util.ObjectUtils;
009import gov.nist.secauto.metaschema.databind.model.annotations.BoundField;
010import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag;
011import gov.nist.secauto.metaschema.databind.model.annotations.Expect;
012import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs;
013import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly;
014import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints;
015import java.lang.Override;
016import java.lang.String;
017import java.util.LinkedList;
018import java.util.List;
019import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
020import org.apache.commons.lang3.builder.ToStringStyle;
021
022/**
023 * Encapsulates a message intended to be read by the end user.
024 */
025@MetaschemaAssembly(
026    formalName = "Message",
027    description = "Encapsulates a message intended to be read by the end user.",
028    name = "message",
029    moduleClass = SarifModule.class,
030    valueConstraints = @ValueConstraints(expect = @Expect(level = IConstraint.Level.ERROR, test = "exists(@id|text)", message = "At least one id or text must be provided."))
031)
032public class Message implements IBoundObject {
033  private final IMetaschemaData __metaschemaData;
034
035  /**
036   * "The id of the message."
037   */
038  @BoundFlag(
039      formalName = "Message Identifier",
040      description = "The id of the message.",
041      name = "id",
042      required = true,
043      typeAdapter = StringAdapter.class
044  )
045  private String _id;
046
047  @BoundField(
048      formalName = "Text",
049      description = "A plain text message string.",
050      useName = "text"
051  )
052  private String _text;
053
054  @BoundField(
055      formalName = "Markdown",
056      description = "A Markdown message string.",
057      useName = "markdown"
058  )
059  private String _markdown;
060
061  @BoundField(
062      formalName = "Argument",
063      description = "A sequence of strings to substitute into the message string.",
064      useName = "argument",
065      maxOccurs = -1,
066      groupAs = @GroupAs(name = "arguments", inJson = JsonGroupAsBehavior.LIST)
067  )
068  private List<String> _arguments;
069
070  public Message() {
071    this(null);
072  }
073
074  public Message(IMetaschemaData data) {
075    this.__metaschemaData = data;
076  }
077
078  @Override
079  public IMetaschemaData getMetaschemaData() {
080    return __metaschemaData;
081  }
082
083  public String getId() {
084    return _id;
085  }
086
087  public void setId(String value) {
088    _id = value;
089  }
090
091  public String getText() {
092    return _text;
093  }
094
095  public void setText(String value) {
096    _text = value;
097  }
098
099  public String getMarkdown() {
100    return _markdown;
101  }
102
103  public void setMarkdown(String value) {
104    _markdown = value;
105  }
106
107  public List<String> getArguments() {
108    return _arguments;
109  }
110
111  public void setArguments(List<String> value) {
112    _arguments = value;
113  }
114
115  /**
116   * Add a new {@link String} item to the underlying collection.
117   * @param item the item to add
118   * @return {@code true}
119   */
120  public boolean addArgument(String item) {
121    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
122    if (_arguments == null) {
123      _arguments = new LinkedList<>();
124    }
125    return _arguments.add(value);
126  }
127
128  /**
129   * Remove the first matching {@link String} item from the underlying collection.
130   * @param item the item to remove
131   * @return {@code true} if the item was removed or {@code false} otherwise
132   */
133  public boolean removeArgument(String item) {
134    String value = ObjectUtils.requireNonNull(item,"item cannot be null");
135    return _arguments != null && _arguments.remove(value);
136  }
137
138  @Override
139  public String toString() {
140    return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString();
141  }
142}