001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.betwixt;
018:
019: import java.io.Serializable;
020: import java.math.BigDecimal;
021: import java.math.BigInteger;
022: import java.sql.Date;
023: import java.sql.Time;
024: import java.sql.Timestamp;
025: import java.util.ArrayList;
026: import java.util.Enumeration;
027: import java.util.Iterator;
028: import java.util.List;
029: import java.util.Map;
030:
031: import org.apache.commons.logging.Log;
032: import org.apache.commons.logging.LogFactory;
033:
034: /** <p><code>CustomerBean</code> is a sample bean for use by the test cases.</p>
035: *
036: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
037: * @author <a href="mailto:michael.davey@coderage.org">Michael Davey</a>
038: * @version $Revision: 438373 $
039: */
040: public class CustomerBean implements Serializable {
041:
042: /** Logger */
043: private static final Log log = LogFactory
044: .getLog(CustomerBean.class);
045:
046: private String id;
047: private String name;
048: private String nickName;
049: private String[] emails;
050: private int[] numbers;
051: private AddressBean address;
052: private Map projectMap;
053: private List locations = new ArrayList();
054: private Date date;
055: private Time time;
056: private Timestamp timestamp;
057: private BigDecimal bigDecimal;
058: private BigInteger bigInteger;
059:
060: public CustomerBean() {
061: }
062:
063: public String getID() {
064: return id;
065: }
066:
067: public String getNickName() {
068: return nickName;
069: }
070:
071: public String getName() {
072: return name;
073: }
074:
075: public String[] getEmails() {
076: return emails;
077: }
078:
079: public int[] getNumbers() {
080: return numbers;
081: }
082:
083: public AddressBean getAddress() {
084: return address;
085: }
086:
087: public Map getProjectMap() {
088: return projectMap;
089: }
090:
091: public Iterator getProjectNames() {
092: if (projectMap == null) {
093: return null;
094: }
095: return projectMap.keySet().iterator();
096: }
097:
098: public Enumeration getProjectURLs() {
099: 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: } else {
179: locations.set(index, location);
180: }
181: }
182:
183: public String toString() {
184: return "[" + this .getClass().getName() + ": ID=" + id
185: + ", name=" + name + ", address=" + address + "]";
186: }
187:
188: public boolean equals(Object obj) {
189: if (obj == null)
190: return false;
191: return this .hashCode() == obj.hashCode();
192: }
193:
194: public int hashCode() {
195: return toString().hashCode();
196: }
197:
198: /**
199: * Returns the date.
200: * @return Date
201: */
202: public Date getDate() {
203: return date;
204: }
205:
206: /**
207: * Returns the time.
208: * @return Time
209: */
210: public Time getTime() {
211: return time;
212: }
213:
214: /**
215: * Returns the timestamp.
216: * @return Timestamp
217: */
218: public Timestamp getTimestamp() {
219: return timestamp;
220: }
221:
222: /**
223: * Sets the date.
224: * @param date The date to set
225: */
226: public void setDate(Date date) {
227: this .date = date;
228: }
229:
230: /**
231: * Sets the time.
232: * @param time The time to set
233: */
234: public void setTime(Time time) {
235: this .time = time;
236: }
237:
238: /**
239: * Sets the timestamp.
240: * @param timestamp The timestamp to set
241: */
242: public void setTimestamp(Timestamp timestamp) {
243: this .timestamp = timestamp;
244: }
245:
246: /**
247: * Returns the bigDecimal.
248: * @return BigDecimal
249: */
250: public BigDecimal getBigDecimal() {
251: return bigDecimal;
252: }
253:
254: /**
255: * Returns the bigInteger.
256: * @return BigInteger
257: */
258: public BigInteger getBigInteger() {
259: return bigInteger;
260: }
261:
262: /**
263: * Sets the bigDecimal.
264: * @param bigDecimal The bigDecimal to set
265: */
266: public void setBigDecimal(BigDecimal bigDecimal) {
267: this .bigDecimal = bigDecimal;
268: }
269:
270: /**
271: * Sets the bigInteger.
272: * @param bigInteger The bigInteger to set
273: */
274: public void setBigInteger(BigInteger bigInteger) {
275: this .bigInteger = bigInteger;
276: }
277:
278: /**
279: * Adapter to make an {@link Iterator Iterator} instance appear to be
280: * an {@link Enumeration Enumeration} instance.
281: * Originate in commons collections
282: *
283: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
284: */
285: private static final class IteratorEnumeration implements
286: Enumeration {
287:
288: /** The iterator being decorated. */
289: private Iterator iterator;
290:
291: /**
292: * Constructs a new <code>IteratorEnumeration</code> that will not
293: * function until {@link #setIterator(Iterator) setIterator} is
294: * invoked.
295: */
296: public IteratorEnumeration() {
297: super ();
298: }
299:
300: /**
301: * Constructs a new <code>IteratorEnumeration</code> that will use
302: * the given iterator.
303: *
304: * @param iterator the iterator to use
305: */
306: public IteratorEnumeration(Iterator iterator) {
307: super ();
308: this .iterator = iterator;
309: }
310:
311: // Iterator interface
312: //-------------------------------------------------------------------------
313:
314: /**
315: * Returns true if the underlying iterator has more elements.
316: *
317: * @return true if the underlying iterator has more elements
318: */
319: public boolean hasMoreElements() {
320: return iterator.hasNext();
321: }
322:
323: /**
324: * Returns the next element from the underlying iterator.
325: *
326: * @return the next element from the underlying iterator.
327: * @throws java.util.NoSuchElementException if the underlying iterator has no
328: * more elements
329: */
330: public Object nextElement() {
331: return iterator.next();
332: }
333:
334: // Properties
335: //-------------------------------------------------------------------------
336:
337: /**
338: * Returns the underlying iterator.
339: *
340: * @return the underlying iterator
341: */
342: public Iterator getIterator() {
343: return iterator;
344: }
345:
346: /**
347: * Sets the underlying iterator.
348: *
349: * @param iterator the new underlying iterator
350: */
351: public void setIterator(Iterator iterator) {
352: this.iterator = iterator;
353: }
354:
355: }
356:
357: }
|