View Javadoc

1   /**
2    * Generated by Mod4j BusinessDomain DSL by BeanClassImplBase in JavaBean.xpt at: Mon Oct 20
3    * 22:16:43 CEST 2008
4    */
5   package org.company.thesandbox.domain;
6   
7   import java.util.Collections;
8   import java.util.Set;
9   import java.util.HashSet;
10  import org.mod4j.runtime.validation.MinValueValidator;
11  import org.mod4j.runtime.validation.MaxValueValidator;
12  import org.mod4j.runtime.validation.MinLengthValidator;
13  import org.mod4j.runtime.validation.MaxLengthValidator;
14  import org.mod4j.runtime.validation.RegExpValidator;
15  
16  import org.company.thesandbox.domain.businessrules.AnotherRule;
17  import org.company.thesandbox.domain.businessrules.OneEarDiscount;
18  
19  /**
20   * A Customer represents a Person who orders from the RecordShop.
21   * 
22   * @author Generated by Mod4j BusinessDomain DSL
23   */
24  
25  @SuppressWarnings("serial")
26  public abstract class CustomerImplBase extends Person implements java.io.Serializable {
27  
28      /**
29       * customerNr:
30       */
31      private int customerNr;
32  
33      /**
34       * username:
35       */
36      private String username;
37  
38      public static final Integer USERNAME_MINLENGTH = 3;
39  
40      public static final Integer USERNAME_MAXLENGTH = 10;
41  
42      /**
43       * emailAddress:
44       */
45      private String emailAddress;
46  
47      public static final String EMAILADDRESS_REGEXP = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}$";
48  
49      /**
50       * blackListed:
51       */
52      private Boolean blackListed = false;
53  
54      /**
55       * discountPercentage:
56       */
57      private int discountPercentage = 0;
58  
59      public static final int DISCOUNTPERCENTAGE_MINVALUE = 0;
60  
61      public static final int DISCOUNTPERCENTAGE_MAXVALUE = 100;
62  
63      /**
64       * orders: One 2 Many Bidirectional: The customer has a number of orders
65       */
66      private Set<Order> orders = new HashSet<Order>();
67  
68      /**
69       * @return orders (Set<Order>)
70       */
71      public Set<Order> getOrders() {
72          return Collections.unmodifiableSet(this.orders);
73      }
74  
75      /**
76       * Implements adding single element to a collection
77       */
78      public void addToOrders(Order element) {
79          if (element == null) {
80              return;
81          }
82          if (this.orders.contains(element)) {
83              return;
84          }
85          this.orders.add(element);
86  
87          if (element.getCustomer() != null) {
88              element.getCustomer().z_internalRemoveFromorders(element);
89          }
90          element.z_internalAddTocustomer((Customer) ((Customer) this));
91          validation.validate();
92  
93      }
94  
95      /**
96       * Implements removal of a single element from feature
97       * 
98       * @param element
99       */
100     public void removeFromOrders(Order element) {
101         if (element == null) {
102             return;
103         }
104         this.orders.remove(element);
105         element.z_internalRemoveFromcustomer((Customer) ((Customer) this));
106 
107         validation.validate();
108     }
109 
110     /**
111      * This operation should NOT be used by clients. It implements the correct addition of an
112      * element in an association.
113      * 
114      * @param element
115      */
116     public void z_internalAddToorders(Order element) {
117         this.orders.add(element);
118     }
119 
120     /**
121      * This operation should NOT be used by clients. It implements the correct removal of an element
122      * in an association.
123      * 
124      * @param element
125      */
126     public void z_internalRemoveFromorders(Order element) {
127         this.orders.remove(element);
128     }
129 
130     /**
131      * Default no-argument constructor for CustomerImplBase
132      */
133     protected CustomerImplBase() {
134         super();
135     }
136 
137     /**
138      * Minimal constructor for CustomerImplBase
139      * 
140      * @param firstName
141      *            (string) First name of the person.
142      * @param lastName
143      *            (string) Last name of the person.
144      * @param customerNr
145      *            (integer)
146      */
147     public CustomerImplBase(String firstName, String lastName, int customerNr) {
148         super(firstName, lastName);
149 
150         this.customerNr = customerNr;
151 
152         validation.addValidator(new MinLengthValidator(Customer.class, "username",
153                 USERNAME_MINLENGTH));
154 
155         validation.addValidator(new MaxLengthValidator(Customer.class, "username",
156                 USERNAME_MAXLENGTH));
157 
158         validation.addValidator(new RegExpValidator(Customer.class, "emailAddress",
159                 EMAILADDRESS_REGEXP));
160 
161         validation.addValidator(new MinValueValidator(Customer.class, "discountPercentage",
162                 DISCOUNTPERCENTAGE_MINVALUE));
163 
164         validation.addValidator(new MaxValueValidator(Customer.class, "discountPercentage",
165                 DISCOUNTPERCENTAGE_MAXVALUE));
166 
167         validation.addValidator(new OneEarDiscount());
168         validation.addValidator(new AnotherRule());
169 
170         validation.validate();
171     }
172 
173     /**
174      * 
175      * @return customerNr (int)
176      */
177     public int getCustomerNr() {
178         return this.customerNr;
179     }
180 
181     /**
182      * 
183      * @return username (String)
184      */
185     public String getUsername() {
186         return this.username;
187     }
188 
189     /**
190      * 
191      * @return emailAddress (String)
192      */
193     public String getEmailAddress() {
194         return this.emailAddress;
195     }
196 
197     /**
198      * 
199      * @return blackListed (Boolean)
200      */
201     public Boolean isBlackListed() {
202         return this.blackListed;
203     }
204 
205     /**
206      * 
207      * @return discountPercentage (int)
208      */
209     public int getDiscountPercentage() {
210         return this.discountPercentage;
211     }
212 
213     /**
214      * @param customerNr
215      *            (int)
216      */
217     public void setCustomerNr(final int customerNr) {
218         this.customerNr = customerNr;
219         validation.validate();
220     }
221 
222     /**
223      * @param username
224      *            (String)
225      */
226     public void setUsername(final String username) {
227         this.username = username;
228         validation.validate();
229     }
230 
231     /**
232      * @param emailAddress
233      *            (String)
234      */
235     public void setEmailAddress(final String emailAddress) {
236         this.emailAddress = emailAddress;
237         validation.validate();
238     }
239 
240     /**
241      * @param blackListed
242      *            (Boolean)
243      */
244     public void setBlackListed(final Boolean blackListed) {
245         this.blackListed = blackListed;
246         validation.validate();
247     }
248 
249     /**
250      * @param discountPercentage
251      *            (int)
252      */
253     public void setDiscountPercentage(final int discountPercentage) {
254         this.discountPercentage = discountPercentage;
255         validation.validate();
256     }
257 
258     /**
259      * Activate/deactivate validation for this business class. When set to active the validation
260      * will immediately be executed.
261      * 
262      * @param value
263      *            (boolean)
264      */
265     public void activateValidation(boolean value) {
266 
267         this.validation.setActive(value);
268         if (value) {
269             validation.validate();
270         }
271     }
272 
273 }