001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 004import gov.nist.secauto.metaschema.core.datatype.adapter.UriAdapter; 005import gov.nist.secauto.metaschema.core.datatype.adapter.UriReferenceAdapter; 006import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultiline; 007import gov.nist.secauto.metaschema.core.datatype.markup.MarkupMultilineAdapter; 008import gov.nist.secauto.metaschema.core.model.IBoundObject; 009import gov.nist.secauto.metaschema.core.model.IMetaschemaData; 010import gov.nist.secauto.metaschema.core.model.JsonGroupAsBehavior; 011import gov.nist.secauto.metaschema.core.model.constraint.IConstraint; 012import gov.nist.secauto.metaschema.core.util.ObjectUtils; 013import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValue; 014import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; 015import gov.nist.secauto.metaschema.databind.model.annotations.BoundAssembly; 016import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 017import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 018import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 019import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 020import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 021import java.lang.Override; 022import java.lang.String; 023import java.net.URI; 024import java.util.LinkedList; 025import java.util.List; 026import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 027import org.apache.commons.lang3.builder.ToStringStyle; 028 029/** 030 * A reference to a resource that is either the source or the target of a mapping. 031 */ 032@MetaschemaAssembly( 033 formalName = "Mapped Resource Reference", 034 description = "A reference to a resource that is either the source or the target of a mapping.", 035 name = "mapping-resource-reference", 036 moduleClass = OscalMappingCommonModule.class 037) 038public class MappingResourceReference implements IBoundObject { 039 private final IMetaschemaData __metaschemaData; 040 041 /** 042 * "An optional namespace qualifying the resource's <code>type</code>." 043 */ 044 @BoundFlag( 045 formalName = "Resource Type Namespace", 046 description = "An optional namespace qualifying the resource's `type`.", 047 name = "ns", 048 defaultValue = "http://csrc.nist.gov/ns/oscal", 049 typeAdapter = UriAdapter.class, 050 remarks = "This value must be an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that serves as a [naming system identifier](https://pages.nist.gov/OSCAL/concepts/uri-use/#use-as-a-naming-system-identifier).\n" 051 + "\n" 052 + "When a `ns` is not provided, its value should be assumed to be `http://csrc.nist.gov/ns/oscal` and the type should be a type defined by the associated OSCAL model." 053 ) 054 private URI _ns; 055 056 /** 057 * "The semantic type of the resource." 058 */ 059 @BoundFlag( 060 formalName = "Resource Type", 061 description = "The semantic type of the resource.", 062 name = "type", 063 required = true, 064 typeAdapter = TokenAdapter.class, 065 remarks = "The `type` value must be interpreted in the context of the associated `ns` value.\n" 066 + "\n" 067 + "When a `ns` is not provided, its value should be assumed to be `http://csrc.nist.gov/ns/oscal` and this type should be set to one of the OSCAL defined values.", 068 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "catalog", description = "The mapped resource is a control catalog."), @AllowedValue(value = "profile", description = "The mapped resource is a control profile. A resolved profile is also accepted.")})) 069 ) 070 private String _type; 071 072 /** 073 * "A resolvable URL reference to the base catalog or profile that this profile is tailoring." 074 */ 075 @BoundFlag( 076 formalName = "Catalog or Profile Reference", 077 description = "A resolvable URL reference to the base catalog or profile that this profile is tailoring.", 078 name = "href", 079 required = true, 080 typeAdapter = UriReferenceAdapter.class, 081 remarks = "This value may be one of:\n" 082 + "\n" 083 + "1. an [absolute URI](https://pages.nist.gov/OSCAL/concepts/uri-use/#absolute-uri) that points to a network resolvable resource,\n" 084 + "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" 085 + "3. a bare URI fragment (i.e., \\`#uuid\\`) pointing to a `back-matter` resource 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))." 086 ) 087 private URI _href; 088 089 @BoundAssembly( 090 formalName = "Property", 091 description = "An attribute, characteristic, or quality of the containing object expressed as a namespace qualified name/value pair.", 092 useName = "prop", 093 maxOccurs = -1, 094 groupAs = @GroupAs(name = "props", inJson = JsonGroupAsBehavior.LIST) 095 ) 096 private List<Property> _props; 097 098 @BoundAssembly( 099 formalName = "Link", 100 description = "A reference to a local or remote resource, that has a specific relation to the containing object.", 101 useName = "link", 102 maxOccurs = -1, 103 groupAs = @GroupAs(name = "links", inJson = JsonGroupAsBehavior.LIST) 104 ) 105 private List<Link> _links; 106 107 @BoundField( 108 formalName = "Remarks", 109 description = "Additional commentary about the containing object.", 110 useName = "remarks", 111 typeAdapter = MarkupMultilineAdapter.class 112 ) 113 private MarkupMultiline _remarks; 114 115 public MappingResourceReference() { 116 this(null); 117 } 118 119 public MappingResourceReference(IMetaschemaData data) { 120 this.__metaschemaData = data; 121 } 122 123 @Override 124 public IMetaschemaData getMetaschemaData() { 125 return __metaschemaData; 126 } 127 128 public URI getNs() { 129 return _ns; 130 } 131 132 public void setNs(URI value) { 133 _ns = value; 134 } 135 136 public String getType() { 137 return _type; 138 } 139 140 public void setType(String value) { 141 _type = value; 142 } 143 144 public URI getHref() { 145 return _href; 146 } 147 148 public void setHref(URI value) { 149 _href = value; 150 } 151 152 public List<Property> getProps() { 153 return _props; 154 } 155 156 public void setProps(List<Property> value) { 157 _props = value; 158 } 159 160 /** 161 * Add a new {@link Property} item to the underlying collection. 162 * @param item the item to add 163 * @return {@code true} 164 */ 165 public boolean addProp(Property item) { 166 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 167 if (_props == null) { 168 _props = new LinkedList<>(); 169 } 170 return _props.add(value); 171 } 172 173 /** 174 * Remove the first matching {@link Property} item from the underlying collection. 175 * @param item the item to remove 176 * @return {@code true} if the item was removed or {@code false} otherwise 177 */ 178 public boolean removeProp(Property item) { 179 Property value = ObjectUtils.requireNonNull(item,"item cannot be null"); 180 return _props != null && _props.remove(value); 181 } 182 183 public List<Link> getLinks() { 184 return _links; 185 } 186 187 public void setLinks(List<Link> value) { 188 _links = value; 189 } 190 191 /** 192 * Add a new {@link Link} item to the underlying collection. 193 * @param item the item to add 194 * @return {@code true} 195 */ 196 public boolean addLink(Link item) { 197 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 198 if (_links == null) { 199 _links = new LinkedList<>(); 200 } 201 return _links.add(value); 202 } 203 204 /** 205 * Remove the first matching {@link Link} item from the underlying collection. 206 * @param item the item to remove 207 * @return {@code true} if the item was removed or {@code false} otherwise 208 */ 209 public boolean removeLink(Link item) { 210 Link value = ObjectUtils.requireNonNull(item,"item cannot be null"); 211 return _links != null && _links.remove(value); 212 } 213 214 public MarkupMultiline getRemarks() { 215 return _remarks; 216 } 217 218 public void setRemarks(MarkupMultiline value) { 219 _remarks = value; 220 } 221 222 @Override 223 public String toString() { 224 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 225 } 226}