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