001package gov.nist.secauto.oscal.lib.model; 002 003import gov.nist.secauto.metaschema.core.datatype.adapter.TokenAdapter; 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.AllowedValue; 010import gov.nist.secauto.metaschema.databind.model.annotations.AllowedValues; 011import gov.nist.secauto.metaschema.databind.model.annotations.BoundField; 012import gov.nist.secauto.metaschema.databind.model.annotations.BoundFlag; 013import gov.nist.secauto.metaschema.databind.model.annotations.GroupAs; 014import gov.nist.secauto.metaschema.databind.model.annotations.Matches; 015import gov.nist.secauto.metaschema.databind.model.annotations.MetaschemaAssembly; 016import gov.nist.secauto.metaschema.databind.model.annotations.ValueConstraints; 017import java.lang.Override; 018import java.lang.String; 019import java.util.LinkedList; 020import java.util.List; 021import org.apache.commons.lang3.builder.ReflectionToStringBuilder; 022import org.apache.commons.lang3.builder.ToStringStyle; 023 024/** 025 * A postal address for the location. 026 */ 027@MetaschemaAssembly( 028 formalName = "Address", 029 description = "A postal address for the location.", 030 name = "address", 031 moduleClass = OscalMetadataModule.class 032) 033public class Address implements IBoundObject { 034 private final IMetaschemaData __metaschemaData; 035 036 /** 037 * "Indicates the type of address." 038 */ 039 @BoundFlag( 040 formalName = "Address Type", 041 description = "Indicates the type of address.", 042 name = "type", 043 typeAdapter = TokenAdapter.class, 044 valueConstraints = @ValueConstraints(allowedValues = @AllowedValues(level = IConstraint.Level.ERROR, allowOthers = true, values = {@AllowedValue(value = "home", description = "A home address."), @AllowedValue(value = "work", description = "A work address.")})) 045 ) 046 private String _type; 047 048 @BoundField( 049 formalName = "Address line", 050 description = "A single line of an address.", 051 useName = "addr-line", 052 maxOccurs = -1, 053 groupAs = @GroupAs(name = "addr-lines", inJson = JsonGroupAsBehavior.LIST) 054 ) 055 private List<String> _addrLines; 056 057 @BoundField( 058 formalName = "City", 059 description = "City, town or geographical region for the mailing address.", 060 useName = "city" 061 ) 062 private String _city; 063 064 @BoundField( 065 formalName = "State", 066 description = "State, province or analogous geographical region for a mailing address.", 067 useName = "state" 068 ) 069 private String _state; 070 071 @BoundField( 072 formalName = "Postal Code", 073 description = "Postal or ZIP code for mailing address.", 074 useName = "postal-code" 075 ) 076 private String _postalCode; 077 078 @BoundField( 079 formalName = "Country Code", 080 description = "The ISO 3166-1 alpha-2 country code for the mailing address.", 081 useName = "country", 082 valueConstraints = @ValueConstraints(matches = @Matches(level = IConstraint.Level.ERROR, pattern = "[A-Z]{2}")) 083 ) 084 private String _country; 085 086 public Address() { 087 this(null); 088 } 089 090 public Address(IMetaschemaData data) { 091 this.__metaschemaData = data; 092 } 093 094 @Override 095 public IMetaschemaData getMetaschemaData() { 096 return __metaschemaData; 097 } 098 099 public String getType() { 100 return _type; 101 } 102 103 public void setType(String value) { 104 _type = value; 105 } 106 107 public List<String> getAddrLines() { 108 return _addrLines; 109 } 110 111 public void setAddrLines(List<String> value) { 112 _addrLines = value; 113 } 114 115 /** 116 * Add a new {@link String} item to the underlying collection. 117 * @param item the item to add 118 * @return {@code true} 119 */ 120 public boolean addAddrLine(String item) { 121 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 122 if (_addrLines == null) { 123 _addrLines = new LinkedList<>(); 124 } 125 return _addrLines.add(value); 126 } 127 128 /** 129 * Remove the first matching {@link String} item from the underlying collection. 130 * @param item the item to remove 131 * @return {@code true} if the item was removed or {@code false} otherwise 132 */ 133 public boolean removeAddrLine(String item) { 134 String value = ObjectUtils.requireNonNull(item,"item cannot be null"); 135 return _addrLines != null && _addrLines.remove(value); 136 } 137 138 public String getCity() { 139 return _city; 140 } 141 142 public void setCity(String value) { 143 _city = value; 144 } 145 146 public String getState() { 147 return _state; 148 } 149 150 public void setState(String value) { 151 _state = value; 152 } 153 154 public String getPostalCode() { 155 return _postalCode; 156 } 157 158 public void setPostalCode(String value) { 159 _postalCode = value; 160 } 161 162 public String getCountry() { 163 return _country; 164 } 165 166 public void setCountry(String value) { 167 _country = value; 168 } 169 170 @Override 171 public String toString() { 172 return new ReflectionToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).toString(); 173 } 174}