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.customer.account.ejb;
039:
040: import javax.ejb.EntityContext;
041: import javax.ejb.RemoveException;
042: import javax.ejb.CreateException;
043: import javax.naming.NamingException;
044: import javax.naming.InitialContext;
045:
046: import com.sun.j2ee.blueprints.contactinfo.ejb.ContactInfoLocal;
047: import com.sun.j2ee.blueprints.contactinfo.ejb.ContactInfoLocalHome;
048: import com.sun.j2ee.blueprints.creditcard.ejb.CreditCardLocal;
049: import com.sun.j2ee.blueprints.creditcard.ejb.CreditCardLocalHome;
050:
051: public abstract class AccountEJB implements javax.ejb.EntityBean {
052:
053: private EntityContext context = null;
054:
055: // getters and setters for CMP fields
056: //====================================
057: public abstract String getStatus();
058:
059: public abstract void setStatus(String status);
060:
061: // CMR fields
062: //============
063: public abstract ContactInfoLocal getContactInfo();
064:
065: public abstract void setContactInfo(ContactInfoLocal contactInfo);
066:
067: public abstract CreditCardLocal getCreditCard();
068:
069: public abstract void setCreditCard(CreditCardLocal creditCard);
070:
071: // EJB create method
072: //===================
073: public Object ejbCreate(String status,
074: ContactInfoLocal contactInfo, CreditCardLocal creditCard)
075: throws CreateException {
076: setStatus(status);
077: return null;
078: }
079:
080: public Object ejbCreate(String status) throws CreateException {
081: setStatus(status);
082: return null;
083: }
084:
085: public void ejbPostCreate(String status) throws CreateException {
086: setStatus(status);
087: try {
088: InitialContext ic = new InitialContext();
089: ContactInfoLocalHome cih = (ContactInfoLocalHome) ic
090: .lookup("java:comp/env/ejb/ContactInfo");
091: ContactInfoLocal contactInfo = cih.create();
092: setContactInfo(contactInfo);
093: CreditCardLocalHome cch = (CreditCardLocalHome) ic
094: .lookup("java:comp/env/ejb/CreditCard");
095: CreditCardLocal creditCard = cch.create();
096: setCreditCard(creditCard);
097: } catch (javax.naming.NamingException ne) {
098: throw new CreateException(
099: "ContactInfoEJB error: naming exception looking up contact info or credit card");
100: }
101:
102: }
103:
104: public void ejbPostCreate(String status,
105: ContactInfoLocal contactInfo, CreditCardLocal creditCard)
106: throws CreateException {
107: setContactInfo(contactInfo);
108: setCreditCard(creditCard);
109: }
110:
111: // Misc Method
112: //=============
113: public void setEntityContext(EntityContext c) {
114: context = c;
115: }
116:
117: public void unsetEntityContext() {
118: context = null;
119: }
120:
121: public void ejbRemove() throws RemoveException {
122: }
123:
124: public void ejbActivate() {
125: }
126:
127: public void ejbPassivate() {
128: }
129:
130: public void ejbStore() {
131: }
132:
133: public void ejbLoad() {
134: }
135: }
|