KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > customer > account > ejb > AccountEJB


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.customer.account.ejb;
39
40 import javax.ejb.EntityContext;
41 import javax.ejb.RemoveException;
42 import javax.ejb.CreateException;
43 import javax.naming.NamingException;
44 import javax.naming.InitialContext;
45
46 import com.sun.j2ee.blueprints.contactinfo.ejb.ContactInfoLocal;
47 import com.sun.j2ee.blueprints.contactinfo.ejb.ContactInfoLocalHome;
48 import com.sun.j2ee.blueprints.creditcard.ejb.CreditCardLocal;
49 import com.sun.j2ee.blueprints.creditcard.ejb.CreditCardLocalHome;
50
51 public abstract class AccountEJB implements javax.ejb.EntityBean {
52
53     private EntityContext context = null;
54
55     // getters and setters for CMP fields
56
//====================================
57
public abstract String getStatus();
58     public abstract void setStatus(String status);
59
60     // CMR fields
61
//============
62
public abstract ContactInfoLocal getContactInfo();
63     public abstract void setContactInfo(ContactInfoLocal contactInfo);
64
65     public abstract CreditCardLocal getCreditCard();
66     public abstract void setCreditCard(CreditCardLocal creditCard);
67
68     // EJB create method
69
//===================
70
public Object ejbCreate(String status, ContactInfoLocal contactInfo, CreditCardLocal creditCard) throws CreateException {
71         setStatus(status);
72         return null;
73     }
74
75     public Object ejbCreate(String status) throws CreateException {
76         setStatus(status);
77         return null;
78     }
79
80     public void ejbPostCreate(String status) throws CreateException {
81         setStatus(status);
82         try {
83             InitialContext ic = new InitialContext();
84             ContactInfoLocalHome cih = (ContactInfoLocalHome) ic.lookup("java:comp/env/ejb/ContactInfo");
85             ContactInfoLocal contactInfo = cih.create();
86             setContactInfo(contactInfo);
87             CreditCardLocalHome cch = (CreditCardLocalHome) ic.lookup("java:comp/env/ejb/CreditCard");
88             CreditCardLocal creditCard = cch.create();
89             setCreditCard(creditCard);
90         } catch (javax.naming.NamingException ne) {
91             throw new CreateException("ContactInfoEJB error: naming exception looking up contact info or credit card");
92         }
93
94     }
95
96     public void ejbPostCreate(String status, ContactInfoLocal contactInfo, CreditCardLocal creditCard) throws CreateException {
97         setContactInfo(contactInfo);
98         setCreditCard(creditCard);
99     }
100
101
102     // Misc Method
103
//=============
104
public void setEntityContext(EntityContext c) {
105         context = c;
106     }
107     public void unsetEntityContext() {
108         context = null;
109     }
110     public void ejbRemove() throws RemoveException { }
111     public void ejbActivate() { }
112     public void ejbPassivate() { }
113     public void ejbStore() { }
114     public void ejbLoad() { }
115 }
116
Popular Tags