1    /*
2     * Copyright 2010 :torweg free software group
3     * 
4     * This program is free software: you can redistribute it and/or modify
5     * it under the terms of the GNU General Public License as published by
6     * the Free Software Foundation, either version 3 of the License, or
7     * (at your option) any later version.
8     * 
9     * This program is distributed in the hope that it will be useful,
10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    * GNU General Public License for more details.
13    * 
14    * You should have received a copy of the GNU General Public License
15    * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16    *
17    */
18   package org.torweg.pulse.component.shop.checkout;
19   
20   import javax.persistence.Column;
21   import javax.persistence.Entity;
22   import javax.xml.bind.annotation.XmlAccessType;
23   import javax.xml.bind.annotation.XmlAccessorType;
24   import javax.xml.bind.annotation.XmlElement;
25   import javax.xml.bind.annotation.XmlRootElement;
26   
27   import org.torweg.pulse.util.entity.AbstractBasicEntity;
28   
29   /**
30    * The {@code Address}.
31    * 
32    * @author Christian Schatt
33    * @version $Revision: 1979 $
34    */
35   @Entity(name = "checkout_Address")
36   @XmlRootElement(name = "address")
37   @XmlAccessorType(XmlAccessType.NONE)
38   public class Address extends AbstractBasicEntity {
39   
40       /**
41        * The {@code serialVersionUID}.
42        */
43       private static final long serialVersionUID = -8269668143815450812L;
44   
45       /**
46        * The salutation.
47        */
48       @Column(updatable = false)
49       @XmlElement(name = "salutation")
50       private String salutation;
51   
52       /**
53        * The first name.
54        */
55       @Column(updatable = false)
56       @XmlElement(name = "first-name")
57       private String firstName;
58   
59       /**
60        * The last name.
61        */
62       @Column(updatable = false)
63       @XmlElement(name = "last-name")
64       private String lastName;
65   
66       /**
67        * The additional name info.
68        */
69       @Column(updatable = false)
70       @XmlElement(name = "additional-name-info")
71       private String additionalNameInfo;
72   
73       /**
74        * The institution.
75        */
76       @Column(updatable = false)
77       @XmlElement(name = "institution")
78       private String institution;
79   
80       /**
81        * The street.
82        */
83       @Column(updatable = false)
84       @XmlElement(name = "street")
85       private String street;
86   
87       /**
88        * The additional street info.
89        */
90       @Column(updatable = false)
91       @XmlElement(name = "additional-street-info")
92       private String additionalStreetInfo;
93   
94       /**
95        * The postal code.
96        */
97       @Column(updatable = false)
98       @XmlElement(name = "postal-code")
99       private String postalCode;
100  
101      /**
102       * The city.
103       */
104      @Column(updatable = false)
105      @XmlElement(name = "city")
106      private String city;
107  
108      /**
109       * The region.
110       */
111      @Column(updatable = false)
112      @XmlElement(name = "region")
113      private String region;
114  
115      /**
116       * The country.
117       */
118      @Column(updatable = false)
119      @XmlElement(name = "country")
120      private String country;
121  
122      /**
123       * The no-argument constructor used by JAXB and JPA.
124       */
125      @Deprecated
126      protected Address() {
127          super();
128      }
129  
130      /**
131       * The copy constructor.
132       * 
133       * @param a
134       *            the {@code Address} to be copied.
135       * @throws IllegalArgumentException
136       *             if the given {@code Address} is {@code null}.
137       */
138      public Address(final Address a) {
139          super();
140  
141          if (a == null) {
142              throw new IllegalArgumentException("The given Address is null.");
143          }
144  
145          this.salutation = a.getSalutation();
146          this.firstName = a.getFirstName();
147          this.lastName = a.getLastName();
148          this.additionalNameInfo = a.getAdditionalNameInfo();
149          this.institution = a.getInstitution();
150          this.street = a.getStreet();
151          this.additionalStreetInfo = a.getAdditionalStreetInfo();
152          this.postalCode = a.getPostalCode();
153          this.city = a.getCity();
154          this.region = a.getRegion();
155          this.country = a.getCountry();
156      }
157  
158      /**
159       * The constructor used by the {@code AddressBuilder}.
160       * 
161       * @param builder
162       *            the {@code AddressBuilder}.
163       */
164      private Address(final AddressBuilder builder) {
165          super();
166  
167          this.salutation = builder.getSalutation();
168          this.firstName = builder.getFirstName();
169          this.lastName = builder.getLastName();
170          this.additionalNameInfo = builder.getAdditionalNameInfo();
171          this.institution = builder.getInstitution();
172          this.street = builder.getStreet();
173          this.additionalStreetInfo = builder.getAdditionalStreetInfo();
174          this.postalCode = builder.getPostalCode();
175          this.city = builder.getCity();
176          this.region = builder.getRegion();
177          this.country = builder.getCountry();
178      }
179  
180      /**
181       * Returns the salutation.
182       * 
183       * @return the salutation.
184       */
185      public final String getSalutation() {
186          return this.salutation;
187      }
188  
189      /**
190       * Returns the first name.
191       * 
192       * @return the first name.
193       */
194      public final String getFirstName() {
195          return this.firstName;
196      }
197  
198      /**
199       * Returns the last name.
200       * 
201       * @return the last name.
202       */
203      public final String getLastName() {
204          return this.lastName;
205      }
206  
207      /**
208       * Returns the additional name info.
209       * 
210       * @return the additional name info.
211       */
212      public final String getAdditionalNameInfo() {
213          return this.additionalNameInfo;
214      }
215  
216      /**
217       * Returns the institution.
218       * 
219       * @return the institution.
220       */
221      public final String getInstitution() {
222          return this.institution;
223      }
224  
225      /**
226       * Returns the street.
227       * 
228       * @return the street.
229       */
230      public final String getStreet() {
231          return this.street;
232      }
233  
234      /**
235       * Returns the additional street info.
236       * 
237       * @return the additional street info.
238       */
239      public final String getAdditionalStreetInfo() {
240          return this.additionalStreetInfo;
241      }
242  
243      /**
244       * Returns the postal code.
245       * 
246       * @return the postal code.
247       */
248      public final String getPostalCode() {
249          return this.postalCode;
250      }
251  
252      /**
253       * Returns the city.
254       * 
255       * @return the city.
256       */
257      public final String getCity() {
258          return this.city;
259      }
260  
261      /**
262       * Returns the region.
263       * 
264       * @return the region.
265       */
266      public final String getRegion() {
267          return this.region;
268      }
269  
270      /**
271       * Returns the country.
272       * 
273       * @return the country.
274       */
275      public final String getCountry() {
276          return this.country;
277      }
278  
279      /**
280       * The {@code AddressBuilder}.
281       * 
282       * @author Christian Schatt
283       * @version $Revision: 1979 $
284       */
285      public static class AddressBuilder {
286  
287          /**
288           * The salutation.
289           */
290          private String salutation;
291  
292          /**
293           * The first name.
294           */
295          private String firstName;
296  
297          /**
298           * The last name.
299           */
300          private String lastName;
301  
302          /**
303           * The additional name info.
304           */
305          private String additionalNameInfo;
306  
307          /**
308           * The institution.
309           */
310          private String institution;
311  
312          /**
313           * The street.
314           */
315          private String street;
316  
317          /**
318           * The additional street info.
319           */
320          private String additionalStreetInfo;
321  
322          /**
323           * The postal code.
324           */
325          private String postalCode;
326  
327          /**
328           * The city.
329           */
330          private String city;
331  
332          /**
333           * The region.
334           */
335          private String region;
336  
337          /**
338           * The country.
339           */
340          private String country;
341  
342          /**
343           * The no-argument constructor.
344           */
345          public AddressBuilder() {
346              super();
347          }
348  
349          /**
350           * Returns the salutation.
351           * 
352           * @return the salutation.
353           */
354          public final String getSalutation() {
355              return this.salutation;
356          }
357  
358          /**
359           * Sets the salutation.
360           * 
361           * @param s
362           *            the salutation to set.
363           * @return {@code this}.
364           */
365          public final AddressBuilder setSalutation(final String s) {
366              this.salutation = s;
367              return this;
368          }
369  
370          /**
371           * Returns the first name.
372           * 
373           * @return the first name.
374           */
375          public final String getFirstName() {
376              return this.firstName;
377          }
378  
379          /**
380           * Sets the first name.
381           * 
382           * @param fn
383           *            the first name to set.
384           * @return {@code this}.
385           */
386          public final AddressBuilder setFirstName(final String fn) {
387              this.firstName = fn;
388              return this;
389          }
390  
391          /**
392           * Returns the last name.
393           * 
394           * @return the last name.
395           */
396          public final String getLastName() {
397              return this.lastName;
398          }
399  
400          /**
401           * Sets the last name.
402           * 
403           * @param ln
404           *            the last name to set.
405           * @return {@code this}.
406           */
407          public final AddressBuilder setLastName(final String ln) {
408              this.lastName = ln;
409              return this;
410          }
411  
412          /**
413           * Returns the additional name info.
414           * 
415           * @return the additional name info.
416           */
417          public final String getAdditionalNameInfo() {
418              return this.additionalNameInfo;
419          }
420  
421          /**
422           * Sets the additional name info.
423           * 
424           * @param ani
425           *            the additional name info to set.
426           * @return {@code this}.
427           */
428          public final AddressBuilder setAdditionalNameInfo(final String ani) {
429              this.additionalNameInfo = ani;
430              return this;
431          }
432  
433          /**
434           * Returns the institution.
435           * 
436           * @return the institution.
437           */
438          public final String getInstitution() {
439              return this.institution;
440          }
441  
442          /**
443           * Sets the institution.
444           * 
445           * @param i
446           *            the institution to set.
447           * @return {@code this}.
448           */
449          public final AddressBuilder setInstitution(final String i) {
450              this.institution = i;
451              return this;
452          }
453  
454          /**
455           * Returns the street.
456           * 
457           * @return the street.
458           */
459          public final String getStreet() {
460              return this.street;
461          }
462  
463          /**
464           * Sets the street.
465           * 
466           * @param s
467           *            the street to set.
468           * @return {@code this}.
469           */
470          public final AddressBuilder setStreet(final String s) {
471              this.street = s;
472              return this;
473          }
474  
475          /**
476           * Returns the additional street info.
477           * 
478           * @return the additional street info.
479           */
480          public final String getAdditionalStreetInfo() {
481              return this.additionalStreetInfo;
482          }
483  
484          /**
485           * Sets the additional street info.
486           * 
487           * @param asi
488           *            the additional street info to set.
489           * @return {@code this}.
490           */
491          public final AddressBuilder setAdditionalStreetInfo(final String asi) {
492              this.additionalStreetInfo = asi;
493              return this;
494          }
495  
496          /**
497           * Returns the postal code.
498           * 
499           * @return the postal code.
500           */
501          public final String getPostalCode() {
502              return this.postalCode;
503          }
504  
505          /**
506           * Sets the postal code.
507           * 
508           * @param pc
509           *            the postal code to set.
510           * @return {@code this}.
511           */
512          public final AddressBuilder setPostalCode(final String pc) {
513              this.postalCode = pc;
514              return this;
515          }
516  
517          /**
518           * Returns the city.
519           * 
520           * @return the city.
521           */
522          public final String getCity() {
523              return this.city;
524          }
525  
526          /**
527           * Sets the city.
528           * 
529           * @param c
530           *            the city to set.
531           * @return {@code this}.
532           */
533          public final AddressBuilder setCity(final String c) {
534              this.city = c;
535              return this;
536          }
537  
538          /**
539           * Returns the region.
540           * 
541           * @return the region.
542           */
543          public final String getRegion() {
544              return this.region;
545          }
546  
547          /**
548           * Sets the region.
549           * 
550           * @param r
551           *            the region to set.
552           * @return {@code this}.
553           */
554          public final AddressBuilder setRegion(final String r) {
555              this.region = r;
556              return this;
557          }
558  
559          /**
560           * Returns the country.
561           * 
562           * @return the country.
563           */
564          public final String getCountry() {
565              return this.country;
566          }
567  
568          /**
569           * Sets the country.
570           * 
571           * @param c
572           *            the country to set.
573           * @return {@code this}.
574           */
575          public final AddressBuilder setCountry(final String c) {
576              this.country = c;
577              return this;
578          }
579  
580          /**
581           * Builds a new {@code Address}.
582           * 
583           * @return the new {@code Address}.
584           */
585          public final Address build() {
586              return new Address(this); // NOPMD
587          }
588  
589      }
590  
591  }
592