001package gov.nist.secauto.oscal.lib.model;
002
003import gov.nist.secauto.metaschema.binding.model.annotations.AssemblyConstraints;
004import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
005import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
006import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
007import gov.nist.secauto.metaschema.binding.model.annotations.Index;
008import gov.nist.secauto.metaschema.binding.model.annotations.IsUnique;
009import gov.nist.secauto.metaschema.binding.model.annotations.KeyField;
010import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
011import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
012import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
013import gov.nist.secauto.metaschema.model.common.datatype.adapter.UuidAdapter;
014import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
015import java.lang.Override;
016import java.lang.String;
017import java.util.LinkedList;
018import java.util.List;
019import java.util.UUID;
020import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
021import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
022
023/**
024 * A collection of component descriptions, which may optionally be grouped by capability.
025 */
026@MetaschemaAssembly(
027    formalName = "Component Definition",
028    description = "A collection of component descriptions, which may optionally be grouped by capability.",
029    name = "component-definition",
030    metaschema = OscalComponentDefinitionMetaschema.class,
031    rootName = "component-definition"
032)
033@AssemblyConstraints(
034    index = @Index(level = IConstraint.Level.ERROR, target = "component", name = "index-system-component-uuid", keyFields = @KeyField(target = "@uuid"), remarks = "Since multiple `component` entries can be provided, each component must have a unique `uuid`."),
035    isUnique = @IsUnique(id = "unique-component-definition-capability", level = IConstraint.Level.ERROR, target = "capability", keyFields = @KeyField(target = "@uuid"), remarks = "A given `component` must not be referenced more than once within the same `capability`.")
036)
037public class ComponentDefinition {
038  @BoundFlag(
039      formalName = "Component Definition Universally Unique Identifier",
040      description = "Provides a globally unique means to identify a given component definition instance.",
041      useName = "uuid",
042      required = true,
043      typeAdapter = UuidAdapter.class
044  )
045  private UUID _uuid;
046
047  @BoundAssembly(
048      formalName = "Document Metadata",
049      description = "Provides information about the containing document, and defines concepts that are shared across the document.",
050      useName = "metadata",
051      minOccurs = 1
052  )
053  private Metadata _metadata;
054
055  @BoundAssembly(
056      formalName = "Import Component Definition",
057      description = "Loads a component definition from another resource.",
058      useName = "import-component-definition",
059      maxOccurs = -1
060  )
061  @GroupAs(
062      name = "import-component-definitions",
063      inJson = JsonGroupAsBehavior.LIST
064  )
065  private List<ImportComponentDefinition> _importComponentDefinitions;
066
067  @BoundAssembly(
068      formalName = "Component",
069      description = "A defined component that can be part of an implemented system.",
070      useName = "component",
071      maxOccurs = -1
072  )
073  @GroupAs(
074      name = "components",
075      inJson = JsonGroupAsBehavior.LIST
076  )
077  private List<DefinedComponent> _components;
078
079  @BoundAssembly(
080      formalName = "Capability",
081      description = "A grouping of other components and/or capabilities.",
082      useName = "capability",
083      maxOccurs = -1
084  )
085  @GroupAs(
086      name = "capabilities",
087      inJson = JsonGroupAsBehavior.LIST
088  )
089  private List<Capability> _capabilities;
090
091  @BoundAssembly(
092      formalName = "Back matter",
093      description = "A collection of resources that may be referenced from within the OSCAL document instance.",
094      useName = "back-matter"
095  )
096  private BackMatter _backMatter;
097
098  public ComponentDefinition() {
099  }
100
101  public UUID getUuid() {
102    return _uuid;
103  }
104
105  public void setUuid(UUID value) {
106    _uuid = value;
107  }
108
109  public Metadata getMetadata() {
110    return _metadata;
111  }
112
113  public void setMetadata(Metadata value) {
114    _metadata = value;
115  }
116
117  public List<ImportComponentDefinition> getImportComponentDefinitions() {
118    return _importComponentDefinitions;
119  }
120
121  public void setImportComponentDefinitions(List<ImportComponentDefinition> value) {
122    _importComponentDefinitions = value;
123  }
124
125  /**
126   * Add a new {@link ImportComponentDefinition} item to the underlying collection.
127   * @param item the item to add
128   * @return {@code true}
129   */
130  public boolean addImportComponentDefinition(ImportComponentDefinition item) {
131    ImportComponentDefinition value = ObjectUtils.requireNonNull(item,"item cannot be null");
132    if (_importComponentDefinitions == null) {
133      _importComponentDefinitions = new LinkedList<>();
134    }
135    return _importComponentDefinitions.add(value);
136  }
137
138  /**
139   * Remove the first matching {@link ImportComponentDefinition} item from the underlying collection.
140   * @param item the item to remove
141   * @return {@code true} if the item was removed or {@code false} otherwise
142   */
143  public boolean removeImportComponentDefinition(ImportComponentDefinition item) {
144    ImportComponentDefinition value = ObjectUtils.requireNonNull(item,"item cannot be null");
145    return _importComponentDefinitions == null ? false : _importComponentDefinitions.remove(value);
146  }
147
148  public List<DefinedComponent> getComponents() {
149    return _components;
150  }
151
152  public void setComponents(List<DefinedComponent> value) {
153    _components = value;
154  }
155
156  /**
157   * Add a new {@link DefinedComponent} item to the underlying collection.
158   * @param item the item to add
159   * @return {@code true}
160   */
161  public boolean addComponent(DefinedComponent item) {
162    DefinedComponent value = ObjectUtils.requireNonNull(item,"item cannot be null");
163    if (_components == null) {
164      _components = new LinkedList<>();
165    }
166    return _components.add(value);
167  }
168
169  /**
170   * Remove the first matching {@link DefinedComponent} item from the underlying collection.
171   * @param item the item to remove
172   * @return {@code true} if the item was removed or {@code false} otherwise
173   */
174  public boolean removeComponent(DefinedComponent item) {
175    DefinedComponent value = ObjectUtils.requireNonNull(item,"item cannot be null");
176    return _components == null ? false : _components.remove(value);
177  }
178
179  public List<Capability> getCapabilities() {
180    return _capabilities;
181  }
182
183  public void setCapabilities(List<Capability> value) {
184    _capabilities = value;
185  }
186
187  /**
188   * Add a new {@link Capability} item to the underlying collection.
189   * @param item the item to add
190   * @return {@code true}
191   */
192  public boolean addCapability(Capability item) {
193    Capability value = ObjectUtils.requireNonNull(item,"item cannot be null");
194    if (_capabilities == null) {
195      _capabilities = new LinkedList<>();
196    }
197    return _capabilities.add(value);
198  }
199
200  /**
201   * Remove the first matching {@link Capability} item from the underlying collection.
202   * @param item the item to remove
203   * @return {@code true} if the item was removed or {@code false} otherwise
204   */
205  public boolean removeCapability(Capability item) {
206    Capability value = ObjectUtils.requireNonNull(item,"item cannot be null");
207    return _capabilities == null ? false : _capabilities.remove(value);
208  }
209
210  public BackMatter getBackMatter() {
211    return _backMatter;
212  }
213
214  public void setBackMatter(BackMatter value) {
215    _backMatter = value;
216  }
217
218  @Override
219  public String toString() {
220    return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
221  }
222}