1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  package org.apache.commons.betwixt;
17  
18  import java.io.Serializable;
19  import java.math.BigDecimal;
20  import java.math.BigInteger;
21  import java.sql.Date;
22  import java.sql.Time;
23  import java.sql.Timestamp;
24  import java.util.ArrayList;
25  import java.util.Enumeration;
26  import java.util.Iterator;
27  import java.util.List;
28  import java.util.Map;
29  
30  import org.apache.commons.collections.iterators.IteratorEnumeration;
31  import org.apache.commons.logging.Log;
32  import org.apache.commons.logging.LogFactory;
33  
34  /*** <p><code>CustomerBean</code> is a sample bean for use by the test cases.</p>
35    *
36    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
37    * @author <a href="mailto:michael.davey@coderage.org">Michael Davey</a>
38    * @version $Revision: 1.10 $
39    */
40  public class CustomerBean implements Serializable {
41  
42      /*** Logger */
43      private static final Log log = LogFactory.getLog( CustomerBean.class );
44      
45      private String id;
46      private String name;
47      private String nickName;
48      private String[] emails;
49      private int[] numbers;
50      private AddressBean address;
51      private Map projectMap;
52      private List locations = new ArrayList();
53  	private Date date;
54  	private Time time;
55  	private Timestamp timestamp;
56  	private BigDecimal bigDecimal;
57  	private BigInteger bigInteger;
58  	    
59      public CustomerBean() {
60      }
61  
62      public String getID() {
63          return id;
64      }
65      
66      public String getNickName() {
67         return nickName;
68      }
69  
70      
71      public String getName() {
72          return name;
73      }
74      
75      public String[] getEmails() {
76          return emails;
77      }
78  
79      public int[] getNumbers() {
80          return numbers;
81      }
82  
83      public AddressBean getAddress() {
84          return address;
85      }
86  
87      public Map getProjectMap() {
88          return projectMap;
89      }
90      
91      public Iterator getProjectNames() {
92          if ( projectMap == null ) {
93              return null;
94          }
95          return projectMap.keySet().iterator();
96      }
97      
98      public Enumeration getProjectURLs() {
99          if ( projectMap == null ) {
100             return null;
101         }
102         return new IteratorEnumeration( projectMap.values().iterator() );
103     }
104     
105     public List getLocations() {
106         return locations;
107     }
108     
109     /*** An indexed property */
110     public String getLocation(int index) {
111         return (String) locations.get(index);
112     }
113     
114     public void setID(String id) {
115         this.id = id;
116     }
117     
118     public void setName(String name) {
119         this.name = name;
120     }
121  
122     public void setNickName(String nickName) {
123         this.nickName = nickName;
124     }    
125     
126     public void setEmails(String[] emails) {
127         this.emails = emails;
128     }
129     
130     public void addEmail(String email) {
131         int newLength = (emails == null) ? 1 : emails.length+1;
132         String[] newArray = new String[newLength];
133         for (int i=0; i< newLength-1; i++) {
134             newArray[i] = emails[i];
135         }
136         newArray[newLength-1] = email;
137         emails = newArray;
138     }    
139     
140     public void setNumbers(int[] numbers) {
141         this.numbers = numbers;
142     }
143 
144     public void addNumber(int number) {
145         if ( log.isDebugEnabled() ) {
146             log.debug( "Adding number: " + number );
147         }
148         
149         int newLength = (numbers == null) ? 1 : numbers.length+1;
150         int[] newArray = new int[newLength];
151         for (int i=0; i< newLength-1; i++) {
152             newArray[i] = numbers[i];
153         }
154         newArray[newLength-1] = number;
155         numbers = newArray;
156     }
157     
158     public void setAddress(AddressBean address) {
159         this.address = address;
160         
161         if ( log.isDebugEnabled() ) {
162             log.debug( "Setting the address to be: " + address );
163         }
164     }
165 
166     public void setProjectMap(Map projectMap) {
167         this.projectMap = projectMap;
168     }
169     
170     public void addLocation(String location) {
171         locations.add(location);
172     }
173     
174     /*** An indexed property */
175     public void setLocation(int index, String location) {
176         if ( index == locations.size() ) {
177             locations.add( location );
178         }
179         else {
180             locations.set(index, location);
181         }
182     }
183 
184     public String toString() {
185         return "[" + this.getClass().getName() + ": ID=" + id + ", name=" + name
186                 + ", address=" + address + "]";
187     }
188     
189     public boolean equals( Object obj ) {
190         if ( obj == null ) return false;
191         return this.hashCode() == obj.hashCode();
192     }
193     
194     public int hashCode() {
195         return toString().hashCode();
196     }
197 	/***
198 	 * Returns the date.
199 	 * @return Date
200 	 */
201 	public Date getDate() {
202 		return date;
203 	}
204 
205 	/***
206 	 * Returns the time.
207 	 * @return Time
208 	 */
209 	public Time getTime() {
210 		return time;
211 	}
212 
213 	/***
214 	 * Returns the timestamp.
215 	 * @return Timestamp
216 	 */
217 	public Timestamp getTimestamp() {
218 		return timestamp;
219 	}
220 
221 	/***
222 	 * Sets the date.
223 	 * @param date The date to set
224 	 */
225 	public void setDate(Date date) {
226 		this.date = date;
227 	}
228 
229 	/***
230 	 * Sets the time.
231 	 * @param time The time to set
232 	 */
233 	public void setTime(Time time) {
234 		this.time = time;
235 	}
236 
237 	/***
238 	 * Sets the timestamp.
239 	 * @param timestamp The timestamp to set
240 	 */
241 	public void setTimestamp(Timestamp timestamp) {
242 		this.timestamp = timestamp;
243 	}
244 
245 	/***
246 	 * Returns the bigDecimal.
247 	 * @return BigDecimal
248 	 */
249 	public BigDecimal getBigDecimal() {
250 		return bigDecimal;
251 	}
252 
253 	/***
254 	 * Returns the bigInteger.
255 	 * @return BigInteger
256 	 */
257 	public BigInteger getBigInteger() {
258 		return bigInteger;
259 	}
260 
261 	/***
262 	 * Sets the bigDecimal.
263 	 * @param bigDecimal The bigDecimal to set
264 	 */
265 	public void setBigDecimal(BigDecimal bigDecimal) {
266 		this.bigDecimal = bigDecimal;
267 	}
268 
269 	/***
270 	 * Sets the bigInteger.
271 	 * @param bigInteger The bigInteger to set
272 	 */
273 	public void setBigInteger(BigInteger bigInteger) {
274 		this.bigInteger = bigInteger;
275 	}
276 
277 }