001: /*
002: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * for use in the design, construction, operation or maintenance of
035: * any nuclear facility.
036: */
037:
038: package com.sun.j2ee.blueprints.creditcard.ejb;
039:
040: import javax.ejb.EntityContext;
041: import javax.ejb.RemoveException;
042: import javax.ejb.CreateException;
043:
044: public abstract class CreditCardEJB implements javax.ejb.EntityBean {
045:
046: private EntityContext context = null;
047:
048: // getters and setters for CMP fields
049: //====================================
050: public abstract String getCardNumber();
051:
052: public abstract void setCardNumber(String cardNumber);
053:
054: public abstract String getCardType();
055:
056: public abstract void setCardType(String cardType);
057:
058: public abstract String getExpiryDate();
059:
060: public abstract void setExpiryDate(String expiryDate);
061:
062: // EJB create method
063: //===================
064: public Object ejbCreate(String cardNumber, String cardType,
065: String expiryDate) throws CreateException {
066: setCardNumber(cardNumber);
067: setCardType(cardType);
068: setExpiryDate(expiryDate);
069: return null;
070: }
071:
072: public void ejbPostCreate(String cardNumber, String cardType,
073: String expiryDate) throws CreateException {
074: }
075:
076: public Object ejbCreate(CreditCard creditCard)
077: throws CreateException {
078: setCardNumber(creditCard.getCardNumber());
079: setCardType(creditCard.getCardType());
080: setExpiryDate(creditCard.getExpiryDate());
081: return null;
082: }
083:
084: public void ejbPostCreate(CreditCard creditCard)
085: throws CreateException {
086: }
087:
088: public Object ejbCreate() throws CreateException {
089: return null;
090: }
091:
092: public void ejbPostCreate() throws CreateException {
093: }
094:
095: public String getExpiryMonth() {
096: String dateString = getExpiryDate();
097: if (dateString != null) {
098: // get the slash and return the text before it
099: int slashStart = dateString.indexOf("/");
100: if (slashStart != -1)
101: return dateString.substring(0, slashStart);
102: }
103: return "01";
104: }
105:
106: public String getExpiryYear() {
107: String dateString = getExpiryDate();
108: if (dateString != null) {
109: // get the slash and return the text after it
110: int slashStart = dateString.indexOf("/");
111: if (slashStart != -1)
112: return dateString.substring(slashStart + 1, dateString
113: .length());
114:
115: }
116: return "2010";
117: }
118:
119: public CreditCard getData() {
120: CreditCard creditCard = new CreditCard();
121: creditCard.setCardNumber(getCardNumber());
122: creditCard.setCardType(getCardType());
123: creditCard.setExpiryDate(getExpiryDate());
124: return creditCard;
125: }
126:
127: // Misc Method
128: //=============
129: public void setEntityContext(EntityContext c) {
130: context = c;
131: }
132:
133: public void unsetEntityContext() {
134: context = null;
135: }
136:
137: public void ejbRemove() throws RemoveException {
138: }
139:
140: public void ejbActivate() {
141: }
142:
143: public void ejbPassivate() {
144: }
145:
146: public void ejbStore() {
147: }
148:
149: public void ejbLoad() {
150: }
151: }
|