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.contactinfo.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: import com.sun.j2ee.blueprints.address.ejb.AddressLocal;
046: import com.sun.j2ee.blueprints.address.ejb.AddressLocalHome;
047: import com.sun.j2ee.blueprints.address.ejb.Address;
048: import com.sun.j2ee.blueprints.servicelocator.ejb.ServiceLocator;
049: import com.sun.j2ee.blueprints.servicelocator.ServiceLocatorException;
050:
051: public abstract class ContactInfoEJB implements javax.ejb.EntityBean {
052:
053: private EntityContext context = null;
054:
055: // getters and setters for CMP fields
056: //====================================
057: public abstract String getFamilyName();
058:
059: public abstract void setFamilyName(String familyName);
060:
061: public abstract String getGivenName();
062:
063: public abstract void setGivenName(String givenName);
064:
065: public abstract String getTelephone();
066:
067: public abstract void setTelephone(String telephone);
068:
069: public abstract String getEmail();
070:
071: public abstract void setEmail(String email);
072:
073: // CMR fields
074: public abstract AddressLocal getAddress();
075:
076: public abstract void setAddress(AddressLocal address);
077:
078: // EJB create methods
079: //===================
080: public Object ejbCreate() throws CreateException {
081: return null;
082: }
083:
084: public void ejbPostCreate() throws CreateException {
085: try {
086: ServiceLocator serviceLocator = new ServiceLocator();
087: AddressLocalHome adh = (AddressLocalHome) serviceLocator
088: .getLocalHome(JNDINames.ADDR_EJB);
089: AddressLocal address = adh.create();
090: setAddress(address);
091: } catch (ServiceLocatorException ne) {
092: throw new CreateException(
093: "ContactInfoEJB error: ServiceLocator exception looking up address");
094: }
095: }
096:
097: public Object ejbCreate(String givenName, String familyName,
098: String telephone, String email, AddressLocal address)
099: throws CreateException {
100: setGivenName(givenName);
101: setFamilyName(familyName);
102: setTelephone(telephone);
103: setEmail(email);
104: return null;
105: }
106:
107: public void ejbPostCreate(String givenName, String familyName,
108: String telephone, String email, AddressLocal address)
109: throws CreateException {
110: setAddress(address);
111: }
112:
113: public Object ejbCreate(ContactInfo contactInfo)
114: throws CreateException {
115: setGivenName(contactInfo.getGivenName());
116: setFamilyName(contactInfo.getFamilyName());
117: setTelephone(contactInfo.getPhone());
118: setEmail(contactInfo.getEmail());
119: return null;
120: }
121:
122: public void ejbPostCreate(ContactInfo contactInfo)
123: throws CreateException {
124: try {
125: ServiceLocator serviceLocator = new ServiceLocator();
126: AddressLocalHome adh = (AddressLocalHome) serviceLocator
127: .getLocalHome(JNDINames.ADDR_EJB);
128: AddressLocal address = adh.create(contactInfo.getAddress());
129: setAddress(address);
130: } catch (ServiceLocatorException ne) {
131: throw new CreateException(
132: "ContactInfoEJB error: ServiceLocator exception looking up address");
133: }
134: }
135:
136: public ContactInfo getData() {
137: ContactInfo contactInfo = new ContactInfo();
138: contactInfo.setGivenName(getGivenName());
139: contactInfo.setFamilyName(getFamilyName());
140: contactInfo.setPhone(getTelephone());
141: contactInfo.setEmail(getEmail());
142: contactInfo.setAddress(getAddress().getData());
143: return contactInfo;
144: }
145:
146: // Misc Method
147: //=============
148: public void setEntityContext(EntityContext c) {
149: context = c;
150: }
151:
152: public void unsetEntityContext() {
153: context = null;
154: }
155:
156: public void ejbRemove() throws RemoveException {
157: }
158:
159: public void ejbActivate() {
160: }
161:
162: public void ejbPassivate() {
163: }
164:
165: public void ejbStore() {
166: }
167:
168: public void ejbLoad() {
169: }
170: }
|