View Javadoc
1   package gov.nist.secauto.oscal.lib.model;
2   
3   import gov.nist.secauto.metaschema.binding.model.annotations.BoundAssembly;
4   import gov.nist.secauto.metaschema.binding.model.annotations.BoundField;
5   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFieldValue;
6   import gov.nist.secauto.metaschema.binding.model.annotations.BoundFlag;
7   import gov.nist.secauto.metaschema.binding.model.annotations.Expect;
8   import gov.nist.secauto.metaschema.binding.model.annotations.GroupAs;
9   import gov.nist.secauto.metaschema.binding.model.annotations.MetaschemaAssembly;
10  import gov.nist.secauto.metaschema.binding.model.annotations.ValueConstraints;
11  import gov.nist.secauto.metaschema.model.common.JsonGroupAsBehavior;
12  import gov.nist.secauto.metaschema.model.common.constraint.IConstraint;
13  import gov.nist.secauto.metaschema.model.common.datatype.adapter.StringAdapter;
14  import gov.nist.secauto.metaschema.model.common.datatype.adapter.UuidAdapter;
15  import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLine;
16  import gov.nist.secauto.metaschema.model.common.datatype.markup.MarkupLineAdapter;
17  import gov.nist.secauto.metaschema.model.common.util.ObjectUtils;
18  import java.lang.Override;
19  import java.lang.String;
20  import java.util.LinkedList;
21  import java.util.List;
22  import java.util.UUID;
23  import org.apache.commons.lang3.builder.MultilineRecursiveToStringStyle;
24  import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
25  
26  /**
27   * Information about the protocol used to provide a service.
28   */
29  @MetaschemaAssembly(
30      formalName = "Service Protocol Information",
31      description = "Information about the protocol used to provide a service.",
32      name = "protocol",
33      metaschema = OscalImplementationCommonMetaschema.class
34  )
35  @ValueConstraints(
36      expect = @Expect(level = IConstraint.Level.WARNING, test = "@uuid", message = "It is a best practice to provide a UUID.")
37  )
38  public class Protocol {
39    @BoundFlag(
40        formalName = "Service Protocol Information Universally Unique Identifier",
41        description = "A [machine-oriented](https://pages.nist.gov/OSCAL/concepts/identifier-use/#machine-oriented), [globally unique](https://pages.nist.gov/OSCAL/concepts/identifier-use/#globally-unique) identifier with [cross-instance](https://pages.nist.gov/OSCAL/concepts/identifier-use/#cross-instance) scope that can be used to reference this service protocol information elsewhere in [this or other OSCAL instances](https://pages.nist.gov/OSCAL/concepts/identifier-use/#scope). The locally defined *UUID* of the `service protocol` can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned [per-subject](https://pages.nist.gov/OSCAL/concepts/identifier-use/#consistency), which means it should be consistently used to identify the same subject across revisions of the document.",
42        useName = "uuid",
43        typeAdapter = UuidAdapter.class
44    )
45    private UUID _uuid;
46  
47    @BoundFlag(
48        formalName = "Protocol Name",
49        description = "The common name of the protocol, which should be the appropriate \"service name\" from the [IANA Service Name and Transport Protocol Port Number Registry](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).",
50        useName = "name",
51        required = true,
52        typeAdapter = StringAdapter.class,
53        remarks = "The short name of the protocol (e.g., https)."
54    )
55    private String _name;
56  
57    /**
58     * "A human readable name for the protocol (e.g., Transport Layer Security)."
59     */
60    @BoundField(
61        formalName = "Protocol Title",
62        description = "A human readable name for the protocol (e.g., Transport Layer Security).",
63        useName = "title"
64    )
65    @BoundFieldValue(
66        typeAdapter = MarkupLineAdapter.class
67    )
68    private MarkupLine _title;
69  
70    @BoundAssembly(
71        formalName = "Port Range",
72        description = "Where applicable this is the IPv4 port range on which the service operates.",
73        useName = "port-range",
74        maxOccurs = -1
75    )
76    @GroupAs(
77        name = "port-ranges",
78        inJson = JsonGroupAsBehavior.LIST
79    )
80    private List<PortRange> _portRanges;
81  
82    public Protocol() {
83    }
84  
85    public UUID getUuid() {
86      return _uuid;
87    }
88  
89    public void setUuid(UUID value) {
90      _uuid = value;
91    }
92  
93    public String getName() {
94      return _name;
95    }
96  
97    public void setName(String value) {
98      _name = value;
99    }
100 
101   public MarkupLine getTitle() {
102     return _title;
103   }
104 
105   public void setTitle(MarkupLine value) {
106     _title = value;
107   }
108 
109   public List<PortRange> getPortRanges() {
110     return _portRanges;
111   }
112 
113   public void setPortRanges(List<PortRange> value) {
114     _portRanges = value;
115   }
116 
117   /**
118    * Add a new {@link PortRange} item to the underlying collection.
119    * @param item the item to add
120    * @return {@code true}
121    */
122   public boolean addPortRange(PortRange item) {
123     PortRange value = ObjectUtils.requireNonNull(item,"item cannot be null");
124     if (_portRanges == null) {
125       _portRanges = new LinkedList<>();
126     }
127     return _portRanges.add(value);
128   }
129 
130   /**
131    * Remove the first matching {@link PortRange} item from the underlying collection.
132    * @param item the item to remove
133    * @return {@code true} if the item was removed or {@code false} otherwise
134    */
135   public boolean removePortRange(PortRange item) {
136     PortRange value = ObjectUtils.requireNonNull(item,"item cannot be null");
137     return _portRanges == null ? false : _portRanges.remove(value);
138   }
139 
140   @Override
141   public String toString() {
142     return new ReflectionToStringBuilder(this, MultilineRecursiveToStringStyle.MULTI_LINE_STYLE).toString();
143   }
144 }