| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.location.api.country; |
| 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 | |
@XmlRootElement(name = Country.Constants.ROOT_ELEMENT_NAME) |
| 41 | |
@XmlAccessorType(XmlAccessType.NONE) |
| 42 | |
@XmlType(name = Country.Constants.TYPE_NAME, propOrder = { |
| 43 | |
Country.Elements.CODE, |
| 44 | |
Country.Elements.ALTERNATE_CODE, |
| 45 | |
Country.Elements.NAME, |
| 46 | |
Country.Elements.RESTRICTED, |
| 47 | |
Country.Elements.ACTIVE, |
| 48 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
| 49 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
| 50 | |
}) |
| 51 | 0 | public final class Country extends AbstractDataTransferObject implements CountryContract { |
| 52 | |
private static final long serialVersionUID = -8975392777320033940L; |
| 53 | |
|
| 54 | |
@XmlElement(name = Elements.CODE, required = true) |
| 55 | |
private final String code; |
| 56 | |
|
| 57 | |
@XmlElement(name = Elements.ALTERNATE_CODE, required = false) |
| 58 | |
private final String alternateCode; |
| 59 | |
|
| 60 | |
@XmlElement(name = Elements.NAME, required = false) |
| 61 | |
private final String name; |
| 62 | |
|
| 63 | |
@XmlElement(name = Elements.RESTRICTED, required = true) |
| 64 | |
private final boolean restricted; |
| 65 | |
|
| 66 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
| 67 | |
private final boolean active; |
| 68 | |
|
| 69 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
| 70 | |
private final Long versionNumber; |
| 71 | |
|
| 72 | 0 | @SuppressWarnings("unused") |
| 73 | |
@XmlAnyElement |
| 74 | |
private final Collection<Element> _futureElements = null; |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
@SuppressWarnings("unused") |
| 80 | 0 | private Country() { |
| 81 | 0 | this.code = null; |
| 82 | 0 | this.alternateCode = null; |
| 83 | 0 | this.name = null; |
| 84 | 0 | this.restricted = false; |
| 85 | 0 | this.active = false; |
| 86 | 0 | this.versionNumber = null; |
| 87 | 0 | } |
| 88 | |
|
| 89 | 0 | private Country(Builder builder) { |
| 90 | 0 | this.code = builder.getCode(); |
| 91 | 0 | this.alternateCode = builder.getAlternateCode(); |
| 92 | 0 | this.name = builder.getName(); |
| 93 | 0 | this.restricted = builder.isRestricted(); |
| 94 | 0 | this.active = builder.isActive(); |
| 95 | 0 | this.versionNumber = builder.getVersionNumber(); |
| 96 | 0 | } |
| 97 | |
|
| 98 | |
|
| 99 | |
@Override |
| 100 | |
public String getCode() { |
| 101 | 0 | return this.code; |
| 102 | |
} |
| 103 | |
|
| 104 | |
|
| 105 | |
@Override |
| 106 | |
public String getAlternateCode() { |
| 107 | 0 | return this.alternateCode; |
| 108 | |
} |
| 109 | |
|
| 110 | |
|
| 111 | |
@Override |
| 112 | |
public String getName() { |
| 113 | 0 | return this.name; |
| 114 | |
} |
| 115 | |
|
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public boolean isActive() { |
| 119 | 0 | return this.active; |
| 120 | |
} |
| 121 | |
|
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public boolean isRestricted() { |
| 125 | 0 | return this.restricted; |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
@Override |
| 130 | |
public Long getVersionNumber() { |
| 131 | 0 | return this.versionNumber; |
| 132 | |
} |
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | 0 | public static class Builder implements CountryContract, ModelBuilder, Serializable { |
| 138 | |
private static final long serialVersionUID = -4786917485397379322L; |
| 139 | |
|
| 140 | |
private String code; |
| 141 | |
private String alternateCode; |
| 142 | |
private String name; |
| 143 | |
private boolean restricted; |
| 144 | |
private boolean active; |
| 145 | |
private Long versionNumber; |
| 146 | |
|
| 147 | |
private Builder(String code, String alternateCode, String name, |
| 148 | 0 | boolean restricted, boolean active) { |
| 149 | 0 | this.setCode(code); |
| 150 | 0 | this.setAlternateCode(alternateCode); |
| 151 | 0 | this.setName(name); |
| 152 | 0 | this.setRestricted(restricted); |
| 153 | 0 | this.setActive(active); |
| 154 | 0 | } |
| 155 | |
|
| 156 | |
public static Builder create(String code, String name) { |
| 157 | 0 | return new Builder(code, null, name, false, true); |
| 158 | |
} |
| 159 | |
|
| 160 | |
public static Builder create(String code, String alternatePostalCode, String name, |
| 161 | |
boolean restricted, boolean active) { |
| 162 | 0 | return new Builder(code, alternatePostalCode, name, restricted, active); |
| 163 | |
} |
| 164 | |
|
| 165 | |
public static Builder create(CountryContract cc) { |
| 166 | 0 | Builder builder = new Builder(cc.getCode(), cc.getAlternateCode(), |
| 167 | |
cc.getName(), cc.isRestricted(), cc.isActive()); |
| 168 | 0 | builder.setVersionNumber(cc.getVersionNumber()); |
| 169 | 0 | return builder; |
| 170 | |
} |
| 171 | |
|
| 172 | |
@Override |
| 173 | |
public Country build() { |
| 174 | 0 | return new Country(this); |
| 175 | |
} |
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
public void setCode(String code) { |
| 183 | 0 | if (StringUtils.isBlank(code)) { |
| 184 | 0 | throw new IllegalArgumentException("code cannot be blank or null"); |
| 185 | |
} |
| 186 | 0 | this.code = code; |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
@Override |
| 190 | |
public String getCode() { |
| 191 | 0 | return this.code; |
| 192 | |
} |
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
public void setAlternateCode(String alternatePostalCode) { |
| 200 | 0 | this.alternateCode = alternatePostalCode; |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
@Override |
| 204 | |
public String getAlternateCode() { |
| 205 | 0 | return this.alternateCode; |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
public void setName(String name) { |
| 214 | 0 | this.name = name; |
| 215 | 0 | } |
| 216 | |
|
| 217 | |
@Override |
| 218 | |
public String getName() { |
| 219 | 0 | return this.name; |
| 220 | |
} |
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
public void setActive(boolean active) { |
| 228 | 0 | this.active = active; |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
@Override |
| 232 | |
public boolean isActive() { |
| 233 | 0 | return this.active; |
| 234 | |
} |
| 235 | |
|
| 236 | |
|
| 237 | |
|
| 238 | |
|
| 239 | |
|
| 240 | |
|
| 241 | |
public void setVersionNumber(Long versionNumber) { |
| 242 | 0 | this.versionNumber = versionNumber; |
| 243 | 0 | } |
| 244 | |
|
| 245 | |
@Override |
| 246 | |
public Long getVersionNumber() { |
| 247 | 0 | return this.versionNumber; |
| 248 | |
} |
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
public void setRestricted(boolean restricted) { |
| 256 | 0 | this.restricted = restricted; |
| 257 | 0 | } |
| 258 | |
|
| 259 | |
@Override |
| 260 | |
public boolean isRestricted() { |
| 261 | 0 | return this.restricted; |
| 262 | |
} |
| 263 | |
} |
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | 0 | static class Elements { |
| 270 | |
final static String CODE = "code"; |
| 271 | |
final static String ALTERNATE_CODE = "alternateCode"; |
| 272 | |
final static String NAME = "name"; |
| 273 | |
final static String RESTRICTED = "restricted"; |
| 274 | |
final static String ACTIVE = "active"; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | 0 | static class Constants { |
| 281 | |
final static String ROOT_ELEMENT_NAME = "country"; |
| 282 | |
final static String TYPE_NAME = "CountryType"; |
| 283 | |
} |
| 284 | |
|
| 285 | 0 | public static class Cache { |
| 286 | |
public static final String NAME = LocationConstants.Namespaces.LOCATION_NAMESPACE_2_0 + "/" + Country.Constants.TYPE_NAME; |
| 287 | |
} |
| 288 | |
} |