001// Generated from: ../../../../../../../../oscal/src/metaschema/oscal_metadata_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.StringAdapter;
006import dev.metaschema.core.datatype.adapter.TokenAdapter;
007import dev.metaschema.core.datatype.adapter.UriAdapter;
008import dev.metaschema.core.datatype.adapter.UriReferenceAdapter;
009import dev.metaschema.core.datatype.markup.MarkupLine;
010import dev.metaschema.core.datatype.markup.MarkupLineAdapter;
011import dev.metaschema.core.model.IBoundObject;
012import dev.metaschema.core.model.IMetaschemaData;
013import dev.metaschema.core.model.constraint.IConstraint;
014import dev.metaschema.core.util.ObjectUtils;
015import dev.metaschema.databind.model.annotations.AllowedValue;
016import dev.metaschema.databind.model.annotations.AllowedValues;
017import dev.metaschema.databind.model.annotations.BoundField;
018import dev.metaschema.databind.model.annotations.BoundFlag;
019import dev.metaschema.databind.model.annotations.Expect;
020import dev.metaschema.databind.model.annotations.IndexHasKey;
021import dev.metaschema.databind.model.annotations.KeyField;
022import dev.metaschema.databind.model.annotations.Matches;
023import dev.metaschema.databind.model.annotations.MetaschemaAssembly;
024import dev.metaschema.databind.model.annotations.ValueConstraints;
025import dev.metaschema.oscal.lib.model.metadata.AbstractLink;
026import edu.umd.cs.findbugs.annotations.NonNull;
027import edu.umd.cs.findbugs.annotations.Nullable;
028import java.net.URI;
029import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
030import org.apache.commons.lang3.builder.ToStringStyle;
031
032/**
033 * A reference to a local or remote resource, that has a specific relation to the containing object.
034 */
035@MetaschemaAssembly(
036    formalName = "Link",
037    description = "A reference to a local or remote resource, that has a specific relation to the containing object.",
038    name = "link",
039    moduleClass = OscalMetadataModule.class,
040    remarks = "To provide a cryptographic hash for a remote target resource, a local reference to a back matter `resource` is needed. The resource allows one or more hash values to be provided using the `rlink/hash` object.\n"
041            + "\n"
042            + "The OSCAL `link` is a roughly based on the HTML [link element](https://www.w3.org/TR/html401/struct/links.html#edef-LINK).",
043    valueConstraints = @ValueConstraints(indexHasKey = @IndexHasKey(id = "oscal-metadata-link-reference-index-back-matter-resource", level = IConstraint.Level.ERROR, target = ".[@rel=('reference') and starts-with(@href,'#')]", indexName = "index-back-matter-resource", keyFields = @KeyField(target = "@href", pattern = "#(.*)")), matches = {@Matches(id = "oscal-metadata-link-reference-href-datatype-uri-reference", level = IConstraint.Level.ERROR, target = ".[@rel=('reference') and starts-with(@href,'#')]/@href", typeAdapter = UriReferenceAdapter.class), @Matches(id = "oscal-metadata-link-reference-href-datatype-uri", level = IConstraint.Level.ERROR, target = ".[@rel=('reference') and not(starts-with(@href,'#'))]/@href", typeAdapter = UriAdapter.class), @Matches(id = "oscal-metadata-link-resource-fragment-datatype", level = IConstraint.Level.ERROR, target = "@resource-fragment", pattern = "(?:[0-9a-zA-Z-._~/?!$&'()*+,;=:@]|%[0-9A-F][0-9A-F])+", remarks = "This pattern is based on the fragment Augmented Backus-Naur form (ABNF) syntax provided in \\[RFC3986 section 3.5\\](https://www.rfc-editor.org/rfc/rfc3986#section-3.5). Uppercase alpha hex digits are required, which is the preferred normalized form defined in RFC3986.")}, expect = @Expect(id = "oscal-metadata-link-uri-reference-no-media-type", description = "A local reference SHOULD NOT have a media-type.", level = IConstraint.Level.ERROR, target = ".[starts-with(@href,'#')]", test = "not(exists(@media-type))", remarks = "Since both `link` and `back-matter/resource` both allow specification of a `media-type`, the `media-type` on `link` may conflict with the any `media-type` entries on a resource's `rlink` or `base64` objects. This constraint prevents this from occurring."))
044)
045public class Link extends AbstractLink implements IBoundObject {
046  private final IMetaschemaData __metaschemaData;
047
048  /**
049   * A resolvable URL reference to a resource.
050   */
051  @BoundFlag(
052      formalName = "Hypertext Reference",
053      description = "A resolvable URL reference to a resource.",
054      name = "href",
055      required = true,
056      typeAdapter = UriReferenceAdapter.class,
057      remarks = "This value may be one of:\n"
058              + "\n"
059              + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n"
060              + "2. a [relative reference](https://pages.nist.gov/OSCAL/concepts/uri-use/#relative-reference) pointing to a network resolvable resource whose base URI is the URI of the containing document, or\n"
061              + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to an OSCAL object by the objects identifier (e.g., id, uuid) in this or an imported document (see [linking to another OSCAL object](https://pages.nist.gov/OSCAL/concepts/uri-use/#linking-to-another-oscal-object)). The specific object type will differ based on the link relationship type."
062  )
063  private URI _href;
064
065  /**
066   * Describes the type of relationship provided by the link's hypertext reference. This can be an indicator of the link's purpose.
067   */
068  @BoundFlag(
069      formalName = "Link Relation Type",
070      description = "Describes the type of relationship provided by the link's hypertext reference. This can be an indicator of the link's purpose.",
071      name = "rel",
072      typeAdapter = TokenAdapter.class,
073      valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(id = "oscal-metadata-link-rel-values", level = IConstraint.Level.ERROR, allowOthers = true, values = @AllowedValue(value = "reference", description = "A generalized reference to a network resource (relative or absolute) or to a `back-matter` resource by UUID expressed as a bare URI fragment.")))
074  )
075  private String _rel;
076
077  /**
078   * A label that indicates the nature of a resource, as a data serialization or format.
079   */
080  @BoundFlag(
081      formalName = "Link Media Type",
082      description = "A label that indicates the nature of a resource, as a data serialization or format.",
083      name = "media-type",
084      typeAdapter = StringAdapter.class,
085      remarks = "The `media-type` provides a hint about the content model of the referenced resource. A valid entry from the [IANA Media Types registry](https://www.iana.org/assignments/media-types/media-types.xhtml) SHOULD be used."
086  )
087  private String _mediaType;
088
089  /**
090   * In case where the <code>href</code> points to a <code>back-matter/resource</code>, this value will indicate the URI <a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.5">fragment</a> to append to any <code>rlink</code> associated with the resource. This value MUST be <a href="https://www.rfc-editor.org/rfc/rfc3986#section-2.1">URI encoded</a>.
091   */
092  @BoundFlag(
093      formalName = "Resource Fragment",
094      description = "In case where the `href` points to a `back-matter/resource`, this value will indicate the URI [fragment](https://www.rfc-editor.org/rfc/rfc3986#section-3.5) to append to any `rlink` associated with the resource. This value MUST be [URI encoded](https://www.rfc-editor.org/rfc/rfc3986#section-2.1).",
095      name = "resource-fragment",
096      typeAdapter = StringAdapter.class
097  )
098  private String _resourceFragment;
099
100  /**
101   * A textual label to associate with the link, which may be used for presentation in a tool.
102   */
103  @BoundField(
104      formalName = "Link Text",
105      description = "A textual label to associate with the link, which may be used for presentation in a tool.",
106      useName = "text",
107      typeAdapter = MarkupLineAdapter.class
108  )
109  private MarkupLine _text;
110
111  /**
112   * Constructs a new {@code dev.metaschema.oscal.lib.model.Link} instance with no metadata.
113   */
114  public Link() {
115    this(null);
116  }
117
118  /**
119   * Constructs a new {@code dev.metaschema.oscal.lib.model.Link} instance with the specified metadata.
120   *
121   * @param data
122   *           the metaschema data, or {@code null} if none
123   */
124  public Link(IMetaschemaData data) {
125    this.__metaschemaData = data;
126  }
127
128  @Override
129  public IMetaschemaData getMetaschemaData() {
130    return __metaschemaData;
131  }
132
133  /**
134   * Get the "{@literal Hypertext Reference}".
135   *
136   * <p>
137   * A resolvable URL reference to a resource.
138   *
139   * @return the href value
140   */
141  @NonNull
142  public URI getHref() {
143    return _href;
144  }
145
146  /**
147   * Set the "{@literal Hypertext Reference}".
148   *
149   * <p>
150   * A resolvable URL reference to a resource.
151   *
152   * @param value
153   *           the href value to set
154   */
155  public void setHref(@NonNull URI value) {
156    _href = value;
157  }
158
159  /**
160   * Get the "{@literal Link Relation Type}".
161   *
162   * <p>
163   * Describes the type of relationship provided by the link's hypertext reference. This can be an indicator of the link's purpose.
164   *
165   * @return the rel value, or {@code null} if not set
166   */
167  @Nullable
168  public String getRel() {
169    return _rel;
170  }
171
172  /**
173   * Set the "{@literal Link Relation Type}".
174   *
175   * <p>
176   * Describes the type of relationship provided by the link's hypertext reference. This can be an indicator of the link's purpose.
177   *
178   * @param value
179   *           the rel value to set, or {@code null} to clear
180   */
181  public void setRel(@Nullable String value) {
182    _rel = value;
183  }
184
185  /**
186   * Get the "{@literal Link Media Type}".
187   *
188   * <p>
189   * A label that indicates the nature of a resource, as a data serialization or format.
190   *
191   * @return the media-type value, or {@code null} if not set
192   */
193  @Nullable
194  public String getMediaType() {
195    return _mediaType;
196  }
197
198  /**
199   * Set the "{@literal Link Media Type}".
200   *
201   * <p>
202   * A label that indicates the nature of a resource, as a data serialization or format.
203   *
204   * @param value
205   *           the media-type value to set, or {@code null} to clear
206   */
207  public void setMediaType(@Nullable String value) {
208    _mediaType = value;
209  }
210
211  /**
212   * Get the "{@literal Resource Fragment}".
213   *
214   * <p>
215   * In case where the <code>href</code> points to a <code>back-matter/resource</code>, this value will indicate the URI <a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.5">fragment</a> to append to any <code>rlink</code> associated with the resource. This value MUST be <a href="https://www.rfc-editor.org/rfc/rfc3986#section-2.1">URI encoded</a>.
216   *
217   * @return the resource-fragment value, or {@code null} if not set
218   */
219  @Nullable
220  public String getResourceFragment() {
221    return _resourceFragment;
222  }
223
224  /**
225   * Set the "{@literal Resource Fragment}".
226   *
227   * <p>
228   * In case where the <code>href</code> points to a <code>back-matter/resource</code>, this value will indicate the URI <a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.5">fragment</a> to append to any <code>rlink</code> associated with the resource. This value MUST be <a href="https://www.rfc-editor.org/rfc/rfc3986#section-2.1">URI encoded</a>.
229   *
230   * @param value
231   *           the resource-fragment value to set, or {@code null} to clear
232   */
233  public void setResourceFragment(@Nullable String value) {
234    _resourceFragment = value;
235  }
236
237  /**
238   * Get the "{@literal Link Text}".
239   *
240   * <p>
241   * A textual label to associate with the link, which may be used for presentation in a tool.
242   *
243   * @return the text value, or {@code null} if not set
244   */
245  @Nullable
246  public MarkupLine getText() {
247    return _text;
248  }
249
250  /**
251   * Set the "{@literal Link Text}".
252   *
253   * <p>
254   * A textual label to associate with the link, which may be used for presentation in a tool.
255   *
256   * @param value
257   *           the text value to set, or {@code null} to clear
258   */
259  public void setText(@Nullable MarkupLine value) {
260    _text = value;
261  }
262
263  @Override
264  public String toString() {
265    return ObjectUtils.notNull(new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString());
266  }
267}