001 /*
002 * Copyright 2002-2006 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005 * use this file except in compliance with the License. You may obtain a copy of
006 * the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations under
014 * the License.
015 */
016 package org.springframework.richclient.samples.simple.domain;
017
018 import java.math.BigDecimal;
019 import java.util.Date;
020 import java.util.List;
021 import java.util.ArrayList;
022
023 /**
024 * This class provides a trivial domain object for the sample application. It represents a simple Contact entry in a
025 * personal address book. It is not very useful in that it only allows a single address for an individual and it doesn't
026 * support arbitrary contact data, just predefined fields. However, since we're not going into the Address Book
027 * business, this will suffice for demonstration purposes in this sample application.
028 * <p>
029 * This class makes use of one subordinate (or nested) object in order to show how nested property paths can be used in
030 * forms. It doesn't really serve any other great design need.
031 * <p>
032 * The validation rules for this class are provided externally, by {@link SimpleValidationRulesSource}. This
033 * configuration is often required when you don't have any mechanism to extend the domain object directly, or for other
034 * design reasons, don't want to include the validation rules directly in the domain object implementation.
035 * @author Larry Streepy
036 * @see SimpleValidationRulesSource
037 */
038 public class Contact implements Comparable<Contact>
039 {
040
041 private int id;
042
043 private ContactType contactType;
044
045 private String firstName;
046
047 private String middleName;
048
049 private String lastName;
050
051 private Date dateOfBirth;
052
053 private Address address;
054
055 private String homePhone;
056
057 private String workPhone;
058
059 private String emailAddress;
060
061 private String memo;
062
063 private BigDecimal monthlyIncome;
064
065 private List<TodoItem> todoItems;
066
067 /**
068 * Default constructor.
069 */
070 public Contact() {
071 setAddress(new Address()); // Avoid null sub-object
072 todoItems = new ArrayList<TodoItem>();
073 }
074
075 /**
076 * @return the id
077 */
078 public int getId() {
079 return id;
080 }
081
082 /**
083 * @param id the id to set
084 */
085 public void setId(int id) {
086 this.id = id;
087 }
088
089 /**
090 * @return the address
091 */
092 public Address getAddress() {
093 return address;
094 }
095
096 /**
097 * @param address the address to set
098 */
099 public void setAddress(Address address) {
100 this.address = address;
101 }
102
103 /**
104 * @return the dateOfBirth
105 */
106 public Date getDateOfBirth() {
107 return dateOfBirth;
108 }
109
110 /**
111 * @param dateOfBirth the dateOfBirth to set
112 */
113 public void setDateOfBirth(Date dateOfBirth) {
114 this.dateOfBirth = dateOfBirth;
115 }
116
117 /**
118 * @return the emailAddress
119 */
120 public String getEmailAddress() {
121 return emailAddress;
122 }
123
124 /**
125 * @param emailAddress the emailAddress to set
126 */
127 public void setEmailAddress(String emailAddress) {
128 this.emailAddress = emailAddress;
129 }
130
131 /**
132 * @return the firstName
133 */
134 public String getFirstName() {
135 return firstName;
136 }
137
138 /**
139 * @param firstName the firstName to set
140 */
141 public void setFirstName(String firstName) {
142 this.firstName = firstName;
143 }
144
145 /**
146 * @return the homePhone
147 */
148 public String getHomePhone() {
149 return homePhone;
150 }
151
152 /**
153 * @param homePhone the homePhone to set
154 */
155 public void setHomePhone(String homePhone) {
156 this.homePhone = homePhone;
157 }
158
159 /**
160 * @return the lastName
161 */
162 public String getLastName() {
163 return lastName;
164 }
165
166 /**
167 * @param lastName the lastName to set
168 */
169 public void setLastName(String lastName) {
170 this.lastName = lastName;
171 }
172
173 /**
174 * @return the middleName
175 */
176 public String getMiddleName() {
177 return middleName;
178 }
179
180 /**
181 * @param middleName the middleName to set
182 */
183 public void setMiddleName(String middleName) {
184 this.middleName = middleName;
185 }
186
187 /**
188 * @return the workPhone
189 */
190 public String getWorkPhone() {
191 return workPhone;
192 }
193
194 /**
195 * @param workPhone the workPhone to set
196 */
197 public void setWorkPhone(String workPhone) {
198 this.workPhone = workPhone;
199 }
200
201 /**
202 * @return the contactType
203 */
204 public ContactType getContactType() {
205 return contactType;
206 }
207
208 /**
209 * @param contactType the contactType to set
210 */
211 public void setContactType(ContactType contactType) {
212 this.contactType = contactType;
213 }
214
215 public String getMemo()
216 {
217 return memo;
218 }
219
220 public void setMemo(String memo)
221 {
222 this.memo = memo;
223 }
224
225 public BigDecimal getMonthlyIncome()
226 {
227 return monthlyIncome;
228 }
229
230 public void setMonthlyIncome(BigDecimal monthlyIncome)
231 {
232 this.monthlyIncome = monthlyIncome;
233 }
234
235 public List<TodoItem> getTodoItems()
236 {
237 return todoItems;
238 }
239
240 public void setTodoItems(List<TodoItem> todoItems)
241 {
242 this.todoItems = todoItems;
243 }
244
245 /**
246 * Compare two objects for equality. Just test their ids.
247 * @param o object to compare
248 */
249 public boolean equals(Object o) {
250 if (o instanceof Contact) {
251 return id == ((Contact) o).id;
252 }
253 return false;
254 }
255
256 /**
257 * Hashcode.
258 */
259 public int hashCode() {
260 return id;
261 }
262
263 public int compareTo(Contact o)
264 {
265 return getId() - o.getId();
266 }
267 }