View Javadoc

1   /*
2    * $Id: CreditCardTO.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.samples.voipservice.to;
12  
13  import org.mule.samples.voipservice.LocaleMessage;
14  
15  import java.io.Serializable;
16  import java.util.ArrayList;
17  import java.util.List;
18  
19  /**
20   * @author Binildas Christudas
21   */
22  public class CreditCardTO implements Serializable, Cloneable
23  {
24      /**
25       * Serial version
26       */
27      private static final long serialVersionUID = 7743847846905485620L;
28  
29      private String cardNumber;
30      private String validTill;
31      private String cardType;
32  
33      public static final String VISA = "Visa";
34      public static final String MASTER_CARD = "Master Card";
35      public static final String AMEX = "Amex";
36  
37      private static final List CREDIT_CARDS;
38  
39      static
40      {
41          CREDIT_CARDS = new ArrayList();
42  
43          CREDIT_CARDS.add(new CreditCardTO("1111-2222-3333-4444", "01-JAN-2006", VISA));
44          CREDIT_CARDS.add(new CreditCardTO("2222-3333-4444-5555", "01-FEB-2006", MASTER_CARD));
45          CREDIT_CARDS.add(new CreditCardTO("3333-4444-5555-6666", "01-MAR-2006", VISA));
46          CREDIT_CARDS.add(new CreditCardTO("4444-5555-6666-7777", "01-APR-2006", VISA));
47          CREDIT_CARDS.add(new CreditCardTO("5555-6666-7777-8888", "01-JAN-2007", MASTER_CARD));
48          CREDIT_CARDS.add(new CreditCardTO("6666-7777-8888-9999", "01-FEB-2007", MASTER_CARD));
49          CREDIT_CARDS.add(new CreditCardTO("7777-8888-9999-1111", "01-MAR-2007", VISA));
50          CREDIT_CARDS.add(new CreditCardTO("8888-9999-1111-2222", "01-APR-2007", MASTER_CARD));
51          CREDIT_CARDS.add(new CreditCardTO("9999-1111-2222-3333", "01-JAN-2008", VISA));
52          CREDIT_CARDS.add(new CreditCardTO("9999-1111-2222-4444", "01-FEB-2008", VISA));
53      }
54  
55      public CreditCardTO()
56      {
57          super();
58      }
59  
60      public CreditCardTO(String cardNumber, String validTill, String cardType)
61      {
62          this.cardNumber = cardNumber;
63          this.validTill = validTill;
64          this.cardType = cardType;
65      }
66  
67      public void setCardNumber(String cardNumber)
68      {
69          this.cardNumber = cardNumber;
70      }
71  
72      public String getCardNumber()
73      {
74          return cardNumber;
75      }
76  
77      public void setValidTill(String validTill)
78      {
79          this.validTill = validTill;
80      }
81  
82      public String getValidTill()
83      {
84          return validTill;
85      }
86  
87      public void setCardType(String cardType)
88      {
89          this.cardType = cardType;
90      }
91  
92      public String getCardType()
93      {
94          return cardType;
95      }
96  
97      public Object clone()
98      {
99          Object clone = null;
100         try
101         {
102             clone = super.clone();
103         }
104         catch (CloneNotSupportedException cloneNotSupportedException)
105         {
106             // too bad
107         }
108         return clone;
109     }
110 
111     public String toString()
112     {
113         StringBuffer stringBuffer = new StringBuffer();
114         if (this.cardNumber != null)
115         {
116             stringBuffer.append(LocaleMessage.getCardNumberCaption(cardNumber));
117         }
118         if (this.validTill != null)
119         {
120             stringBuffer.append(LocaleMessage.getValidTillCaption(validTill));
121         }
122         if (this.cardType != null)
123         {
124             stringBuffer.append(LocaleMessage.getCardTypeCaption(cardType));
125         }
126         return stringBuffer.toString();
127     }
128 
129     public static CreditCardTO getRandomCreditCard()
130     {
131 
132         int index = new Double(Math.random() * 10).intValue();
133         return (CreditCardTO)((CreditCardTO)CREDIT_CARDS.get(index)).clone();
134     }
135 
136 }