View Javadoc

1   /*
2    * $Id: CreditCardTO.java 7963 2007-08-21 08:53:15Z 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  public class CreditCardTO implements Serializable, Cloneable
20  {
21      /**
22       * Serial version
23       */
24      private static final long serialVersionUID = 7743847846905485620L;
25  
26      private String cardNumber;
27      private String validTill;
28      private String cardType;
29  
30      public static final String VISA = "Visa";
31      public static final String MASTER_CARD = "Master Card";
32      public static final String AMEX = "Amex";
33  
34      private static final List CREDIT_CARDS;
35  
36      static
37      {
38          CREDIT_CARDS = new ArrayList();
39  
40          CREDIT_CARDS.add(new CreditCardTO("1111-2222-3333-4444", "01-JAN-2006", VISA));
41          CREDIT_CARDS.add(new CreditCardTO("2222-3333-4444-5555", "01-FEB-2006", MASTER_CARD));
42          CREDIT_CARDS.add(new CreditCardTO("3333-4444-5555-6666", "01-MAR-2006", VISA));
43          CREDIT_CARDS.add(new CreditCardTO("4444-5555-6666-7777", "01-APR-2006", VISA));
44          CREDIT_CARDS.add(new CreditCardTO("5555-6666-7777-8888", "01-JAN-2007", MASTER_CARD));
45          CREDIT_CARDS.add(new CreditCardTO("6666-7777-8888-9999", "01-FEB-2007", MASTER_CARD));
46          CREDIT_CARDS.add(new CreditCardTO("7777-8888-9999-1111", "01-MAR-2007", VISA));
47          CREDIT_CARDS.add(new CreditCardTO("8888-9999-1111-2222", "01-APR-2007", MASTER_CARD));
48          CREDIT_CARDS.add(new CreditCardTO("9999-1111-2222-3333", "01-JAN-2008", VISA));
49          CREDIT_CARDS.add(new CreditCardTO("9999-1111-2222-4444", "01-FEB-2008", VISA));
50      }
51  
52      public CreditCardTO()
53      {
54          super();
55      }
56  
57      public CreditCardTO(String cardNumber, String validTill, String cardType)
58      {
59          this.cardNumber = cardNumber;
60          this.validTill = validTill;
61          this.cardType = cardType;
62      }
63  
64      public void setCardNumber(String cardNumber)
65      {
66          this.cardNumber = cardNumber;
67      }
68  
69      public String getCardNumber()
70      {
71          return cardNumber;
72      }
73  
74      public void setValidTill(String validTill)
75      {
76          this.validTill = validTill;
77      }
78  
79      public String getValidTill()
80      {
81          return validTill;
82      }
83  
84      public void setCardType(String cardType)
85      {
86          this.cardType = cardType;
87      }
88  
89      public String getCardType()
90      {
91          return cardType;
92      }
93  
94      public Object clone()
95      {
96          Object clone = null;
97          try
98          {
99              clone = super.clone();
100         }
101         catch (CloneNotSupportedException cloneNotSupportedException)
102         {
103             // too bad
104         }
105         return clone;
106     }
107 
108     public String toString()
109     {
110         StringBuffer stringBuffer = new StringBuffer();
111         if (this.cardNumber != null)
112         {
113             stringBuffer.append(LocaleMessage.getCardNumberCaption(cardNumber));
114         }
115         if (this.validTill != null)
116         {
117             stringBuffer.append(LocaleMessage.getValidTillCaption(validTill));
118         }
119         if (this.cardType != null)
120         {
121             stringBuffer.append(LocaleMessage.getCardTypeCaption(cardType));
122         }
123         return stringBuffer.toString();
124     }
125 
126     public static CreditCardTO getRandomCreditCard()
127     {
128 
129         int index = new Double(Math.random() * 10).intValue();
130         return (CreditCardTO)((CreditCardTO)CREDIT_CARDS.get(index)).clone();
131     }
132 
133 }