KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > creditcard > ejb > CreditCardEJB


1 /*
2  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * - Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * - Redistribution in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of
17  * contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any
21  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
25  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26  * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
27  * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
28  * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
29  * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
30  * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
31  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32  *
33  * You acknowledge that Software is not designed, licensed or intended
34  * for use in the design, construction, operation or maintenance of
35  * any nuclear facility.
36  */

37
38 package com.sun.j2ee.blueprints.creditcard.ejb;
39
40 import javax.ejb.EntityContext;
41 import javax.ejb.RemoveException;
42 import javax.ejb.CreateException;
43
44 public abstract class CreditCardEJB implements javax.ejb.EntityBean {
45
46   private EntityContext context = null;
47
48   // getters and setters for CMP fields
49
//====================================
50
public abstract String getCardNumber();
51   public abstract void setCardNumber(String cardNumber);
52
53   public abstract String getCardType();
54   public abstract void setCardType(String cardType);
55
56   public abstract String getExpiryDate();
57   public abstract void setExpiryDate(String expiryDate);
58
59
60   // EJB create method
61
//===================
62
public Object ejbCreate(String cardNumber, String cardType,
63                           String expiryDate) throws CreateException {
64                             setCardNumber(cardNumber);
65                             setCardType(cardType);
66                             setExpiryDate(expiryDate);
67                             return null;
68   }
69
70   public void ejbPostCreate(String cardNumber, String cardType,
71                             String expiryDate) throws CreateException { }
72
73   public Object ejbCreate(CreditCard creditCard) throws CreateException {
74     setCardNumber(creditCard.getCardNumber());
75     setCardType(creditCard.getCardType());
76     setExpiryDate(creditCard.getExpiryDate());
77     return null;
78   }
79
80   public void ejbPostCreate(CreditCard creditCard) throws CreateException { }
81
82   public Object ejbCreate() throws CreateException {
83     return null;
84   }
85
86   public void ejbPostCreate() throws CreateException { }
87
88   public String getExpiryMonth() {
89     String dateString = getExpiryDate();
90     if (dateString != null) {
91       // get the slash and return the text before it
92
int slashStart = dateString.indexOf("/");
93       if (slashStart != -1) return dateString.substring(0,slashStart);
94     }
95     return "01";
96   }
97
98   public String getExpiryYear() {
99     String dateString = getExpiryDate();
100     if (dateString != null) {
101       // get the slash and return the text after it
102
int slashStart = dateString.indexOf("/");
103       if (slashStart != -1) return dateString.substring(slashStart +1, dateString.length());
104
105     }
106     return "2010";
107   }
108
109   public CreditCard getData() {
110     CreditCard creditCard = new CreditCard();
111     creditCard.setCardNumber(getCardNumber());
112     creditCard.setCardType(getCardType());
113     creditCard.setExpiryDate(getExpiryDate());
114     return creditCard;
115   }
116
117   // Misc Method
118
//=============
119
public void setEntityContext(EntityContext c) {
120     context = c;
121   }
122   public void unsetEntityContext() {
123     context = null;
124   }
125   public void ejbRemove() throws RemoveException { }
126   public void ejbActivate() { }
127   public void ejbPassivate() { }
128   public void ejbStore() { }
129   public void ejbLoad() { }
130 }
131
Popular Tags