KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > ce > auction > model > CreditCard


1 package org.hibernate.ce.auction.model;
2
3 import javax.persistence.*;
4
5 /**
6  * This billing strategy can handle various credit cards.
7  * <p>
8  * The type of credit card is handled with a typesafe
9  * enumeration, <tt>CreditCardType</tt>.
10  *
11  * @see CreditCardType
12  * @author Christian Bauer <christian@hibernate.org>
13  */

14 @Entity(access = AccessType.FIELD)
15 @Table(name = "CREDIT_CARD")
16 @Inheritance(strategy = InheritanceType.JOINED)
17 @JoinColumn(name = "CREDIT_CARD_ID")
18 public class CreditCard extends BillingDetails {
19
20     //TODO: Test if this really works
21
@org.hibernate.annotations.Type(type = "creditcard_type")
22     @Column(name = "CC_TYPE", nullable = false)
23     private CreditCardType type;
24
25     @Column(name = "CC_NUMBER", nullable = false, updatable = false)
26     private String JavaDoc number;
27
28     @Column(name = "EXP_MONTH", nullable = false, updatable = false)
29     private String JavaDoc expMonth;
30
31     @Column(name = "EXP_YEAR", nullable = false, updatable = false)
32     private String JavaDoc expYear;
33
34     /**
35      * No-arg constructor for JavaBean tools.
36      */

37     CreditCard() { super(); }
38
39     /**
40      * Full constructor.
41      *
42      * @param ownerName
43      * @param user
44      * @param type
45      * @param expMonth
46      * @param expYear
47      */

48     public CreditCard(String JavaDoc ownerName, User user, String JavaDoc number, CreditCardType type,
49                       String JavaDoc expMonth, String JavaDoc expYear) {
50         super(ownerName, user);
51         this.type = type;
52         this.number = number;
53         this.expMonth = expMonth;
54         this.expYear = expYear;
55     }
56
57     // ********************** Accessor Methods ********************** //
58

59     public CreditCardType getType() { return type; }
60
61     public String JavaDoc getNumber() { return number; }
62
63     public String JavaDoc getExpMonth() { return expMonth; }
64
65     public String JavaDoc getExpYear() { return expYear; }
66
67     // ********************** Common Methods ********************** //
68

69     public String JavaDoc toString() {
70         return "CreditCard ('" + getId() + "'), " +
71                 "Type: '" + getType() + "'";
72     }
73
74     // ********************** Business Methods ********************** //
75

76     public boolean isValid() {
77         // Use the type to validate the CreditCard details.
78
return getType().isValid(this);
79     }
80
81 }
82
Popular Tags