| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.location.api.county; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.core.api.CoreConstants; |
| 20 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
| 21 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
| 22 | |
import org.kuali.rice.location.api.LocationConstants; |
| 23 | |
import org.w3c.dom.Element; |
| 24 | |
|
| 25 | |
import javax.xml.bind.annotation.XmlAccessType; |
| 26 | |
import javax.xml.bind.annotation.XmlAccessorType; |
| 27 | |
import javax.xml.bind.annotation.XmlAnyElement; |
| 28 | |
import javax.xml.bind.annotation.XmlElement; |
| 29 | |
import javax.xml.bind.annotation.XmlRootElement; |
| 30 | |
import javax.xml.bind.annotation.XmlType; |
| 31 | |
import java.io.Serializable; |
| 32 | |
import java.util.Collection; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
@XmlRootElement(name = County.Constants.ROOT_ELEMENT_NAME) |
| 43 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 44 | |
@XmlType(name = County.Constants.TYPE_NAME, propOrder = { |
| 45 | |
County.Elements.CODE, |
| 46 | |
County.Elements.NAME, |
| 47 | |
County.Elements.COUNTRY_CODE, |
| 48 | |
County.Elements.STATE_CODE, |
| 49 | |
County.Elements.ACTIVE, |
| 50 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 51 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 52 | |
}) |
| 53 | 3 | public final class County extends AbstractDataTransferObject implements CountyContract { |
| 54 | |
|
| 55 | |
private static final long serialVersionUID = 6097498602725305353L; |
| 56 | |
|
| 57 | |
@XmlElement(name = Elements.CODE, required = true) |
| 58 | |
private final String code; |
| 59 | |
|
| 60 | |
@XmlElement(name = Elements.NAME, required = true) |
| 61 | |
private final String name; |
| 62 | |
|
| 63 | |
@XmlElement(name = Elements.COUNTRY_CODE, required = true) |
| 64 | |
private final String countryCode; |
| 65 | |
|
| 66 | |
@XmlElement(name = Elements.STATE_CODE, required = true) |
| 67 | |
private final String stateCode; |
| 68 | |
|
| 69 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
| 70 | |
private final boolean active; |
| 71 | |
|
| 72 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 73 | |
private final Long versionNumber; |
| 74 | |
|
| 75 | 5 | @SuppressWarnings("unused") |
| 76 | |
@XmlAnyElement |
| 77 | |
private final Collection<Element> _futureElements = null; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
@SuppressWarnings("unused") |
| 83 | 2 | private County() { |
| 84 | 2 | this.code = null; |
| 85 | 2 | this.name = null; |
| 86 | 2 | this.countryCode = null; |
| 87 | 2 | this.stateCode = null; |
| 88 | 2 | this.active = false; |
| 89 | 2 | this.versionNumber = null; |
| 90 | 2 | } |
| 91 | |
|
| 92 | 3 | private County(Builder builder) { |
| 93 | 3 | code = builder.getCode(); |
| 94 | 3 | name = builder.getName(); |
| 95 | 3 | countryCode = builder.getCountryCode(); |
| 96 | 3 | stateCode = builder.getStateCode(); |
| 97 | 3 | active = builder.isActive(); |
| 98 | 3 | versionNumber = builder.getVersionNumber(); |
| 99 | 3 | } |
| 100 | |
|
| 101 | |
|
| 102 | |
@Override |
| 103 | |
public String getCode() { |
| 104 | 0 | return code; |
| 105 | |
} |
| 106 | |
|
| 107 | |
|
| 108 | |
@Override |
| 109 | |
public String getName() { |
| 110 | 0 | return name; |
| 111 | |
} |
| 112 | |
|
| 113 | |
|
| 114 | |
@Override |
| 115 | |
public String getCountryCode() { |
| 116 | 0 | return countryCode; |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
@Override |
| 121 | |
public String getStateCode() { |
| 122 | 0 | return stateCode; |
| 123 | |
} |
| 124 | |
|
| 125 | |
|
| 126 | |
@Override |
| 127 | |
public boolean isActive() { |
| 128 | 0 | return active; |
| 129 | |
} |
| 130 | |
|
| 131 | |
|
| 132 | |
@Override |
| 133 | |
public Long getVersionNumber() { |
| 134 | 0 | return versionNumber; |
| 135 | |
} |
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | 3 | public static class Builder implements CountyContract, ModelBuilder, Serializable { |
| 141 | |
|
| 142 | |
private static final long serialVersionUID = 7077484401017765844L; |
| 143 | |
|
| 144 | |
private String code; |
| 145 | |
private String name; |
| 146 | |
private String countryCode; |
| 147 | |
private String stateCode; |
| 148 | |
private boolean active; |
| 149 | |
private Long versionNumber; |
| 150 | |
|
| 151 | 17 | private Builder(String code, String name, String countryCode, String stateCode) { |
| 152 | 17 | setCode(code); |
| 153 | 13 | setName(name); |
| 154 | 10 | setCountryCode(countryCode); |
| 155 | 7 | setStateCode(stateCode); |
| 156 | 4 | setVersionNumber(versionNumber); |
| 157 | 4 | } |
| 158 | |
|
| 159 | |
|
| 160 | |
|
| 161 | |
|
| 162 | |
public static Builder create(String code, String name, String countryCode, String stateCode) { |
| 163 | 15 | final Builder builder = new Builder(code, name, countryCode, stateCode); |
| 164 | 2 | builder.setActive(true); |
| 165 | 2 | return builder; |
| 166 | |
} |
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
public static Builder create(CountyContract contract) { |
| 172 | 2 | final Builder builder = new Builder(contract.getCode(), contract.getName(), contract.getCountryCode(), contract.getStateCode()); |
| 173 | 2 | builder.setActive(contract.isActive()); |
| 174 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
| 175 | 2 | return builder; |
| 176 | |
} |
| 177 | |
|
| 178 | |
@Override |
| 179 | |
public String getCode() { |
| 180 | 4 | return code; |
| 181 | |
} |
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
|
| 187 | |
|
| 188 | |
public void setCode(String code) { |
| 189 | 17 | if (StringUtils.isBlank(code)) { |
| 190 | 4 | throw new IllegalArgumentException("code is blank"); |
| 191 | |
} |
| 192 | |
|
| 193 | 13 | this.code = code; |
| 194 | 13 | } |
| 195 | |
|
| 196 | |
@Override |
| 197 | |
public String getName() { |
| 198 | 4 | return name; |
| 199 | |
} |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
|
| 206 | |
public void setName(String name) { |
| 207 | 13 | if (StringUtils.isBlank(name)) { |
| 208 | 3 | throw new IllegalArgumentException("name is blank"); |
| 209 | |
} |
| 210 | |
|
| 211 | 10 | this.name = name; |
| 212 | 10 | } |
| 213 | |
|
| 214 | |
@Override |
| 215 | |
public String getCountryCode() { |
| 216 | 4 | return countryCode; |
| 217 | |
} |
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
public void setCountryCode(String countryCode) { |
| 226 | 10 | if (StringUtils.isBlank(countryCode)) { |
| 227 | 3 | throw new IllegalArgumentException("countryCode is blank"); |
| 228 | |
} |
| 229 | |
|
| 230 | 7 | this.countryCode = countryCode; |
| 231 | 7 | } |
| 232 | |
|
| 233 | |
@Override |
| 234 | |
public String getStateCode() { |
| 235 | 4 | return stateCode; |
| 236 | |
} |
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
public void setStateCode(String stateCode) { |
| 245 | 7 | if (StringUtils.isBlank(stateCode)) { |
| 246 | 3 | throw new IllegalArgumentException("stateCode is blank"); |
| 247 | |
} |
| 248 | |
|
| 249 | 4 | this.stateCode = stateCode; |
| 250 | 4 | } |
| 251 | |
|
| 252 | |
@Override |
| 253 | |
public boolean isActive() { |
| 254 | 4 | return active; |
| 255 | |
} |
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
public void setActive(boolean active) { |
| 262 | 4 | this.active = active; |
| 263 | 4 | } |
| 264 | |
|
| 265 | |
@Override |
| 266 | |
public Long getVersionNumber() { |
| 267 | 4 | return versionNumber; |
| 268 | |
} |
| 269 | |
|
| 270 | |
public void setVersionNumber(Long versionNumber) { |
| 271 | 6 | this.versionNumber = versionNumber; |
| 272 | 6 | } |
| 273 | |
|
| 274 | |
@Override |
| 275 | |
public County build() { |
| 276 | 3 | return new County(this); |
| 277 | |
} |
| 278 | |
} |
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | 0 | static class Constants { |
| 284 | |
final static String ROOT_ELEMENT_NAME = "county"; |
| 285 | |
final static String TYPE_NAME = "CountyType"; |
| 286 | |
} |
| 287 | |
|
| 288 | |
|
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | 0 | static class Elements { |
| 293 | |
final static String CODE = "code"; |
| 294 | |
final static String NAME = "name"; |
| 295 | |
final static String COUNTRY_CODE = "countryCode"; |
| 296 | |
final static String STATE_CODE = "stateCode"; |
| 297 | |
final static String ACTIVE = "active"; |
| 298 | |
} |
| 299 | |
|
| 300 | 0 | public static class Cache { |
| 301 | |
public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + County.Constants.TYPE_NAME; |
| 302 | |
} |
| 303 | |
} |