View Javadoc
1   package info.ejava.examples.ejb.interceptor.bo;
2   
3   import java.io.Serializable;
4   
5   import javax.persistence.Column;
6   import javax.persistence.Embeddable;
7   import javax.validation.constraints.NotNull;
8   import javax.validation.constraints.Pattern;
9   import javax.validation.constraints.Size;
10  
11  @SuppressWarnings("serial")
12  @Embeddable
13  public class PostalAddress implements Serializable {
14      @NotNull(groups={PreNormalizedCheck.class, PrePersistCheck.class})
15      @Size(min=2, max=30, groups={PostNormalizedCheck.class, PrePersistCheck.class})
16      @Pattern.List({
17          @Pattern(regexp="^[0-9-A-Za-z'\\ ]+$", groups={PreNormalizedCheck.class}),
18          @Pattern(regexp="^([0-9]+\\ )([A-Z][a-z0-9-]+\\ *)+$", groups=PostNormalizedCheck.class)
19      })
20      @Column(name="STREET1", length=30, nullable=false)
21      private String street1;
22      
23      @Pattern.List({
24          @Pattern(regexp="^[0-9-A-Za-z'\\ ]+$", groups={PreNormalizedCheck.class}),
25          @Pattern(regexp="^([A-Z][a-z0-9-]+\\ *)+$", groups=PostNormalizedCheck.class)
26      })
27      @Column(name="STREET2", length=30)
28      private String street2;    
29      
30      @NotNull(groups={PreNormalizedCheck.class, PrePersistCheck.class})
31      @Pattern.List({
32          @Pattern(regexp="^[A-Za-z-'\\ ]+$", groups={PreNormalizedCheck.class}),
33          @Pattern(regexp="^([A-Z][a-z-]+\\ *)+$", groups=PostNormalizedCheck.class)
34      })
35      private String city;
36      
37      @NotNull(groups=PrePersistCheck.class)
38      @Size(min=2, max=2, groups={PostNormalizedCheck.class, PrePersistCheck.class})
39      @Pattern.List({
40          @Pattern(regexp="[A-Za-z]{2}", groups=PreNormalizedCheck.class),
41          @Pattern(regexp="[A-Z][A-Z]", groups=PostNormalizedCheck.class)
42      })
43      private String state;
44      
45      @NotNull(groups={PreNormalizedCheck.class, PrePersistCheck.class})
46      @Size(min=5, max=10, groups={PostNormalizedCheck.class, PrePersistCheck.class})
47      @Pattern(regexp="^[0-9]{5}(-[0-9]{4})?$", groups=PostNormalizedCheck.class)
48      private String zip;
49  
50      public String getStreet1() { return street1; }
51      public void setStreet1(String street1) {
52          this.street1 = street1;
53      }
54      
55      public String getStreet2() { return street2; }
56      public void setStreet2(String street2) {
57          this.street2 = street2;
58      }
59      
60      public String getCity() { return city; }
61      public void setCity(String city) {
62          this.city = city;
63      }
64      
65      public String getState() { return state; }
66      public void setState(String state) {
67          this.state = state;
68      }
69      
70      public String getZip() { return zip; }
71      public void setZip(String zip) {
72          this.zip = zip;
73      }
74      
75      
76      @Override
77      public String toString() {
78          StringBuilder builder = new StringBuilder();
79          builder.append("street1=").append(street1)
80                  .append(", street2=").append(street2)
81                  .append(", city=").append(city)
82                  .append(", state=").append(state)
83                  .append(", zip=").append(zip);
84          return builder.toString();
85      }
86  }