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