KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > contactinfo > ejb > ContactInfoEJB


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.contactinfo.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 import com.sun.j2ee.blueprints.address.ejb.AddressLocal;
46 import com.sun.j2ee.blueprints.address.ejb.AddressLocalHome;
47 import com.sun.j2ee.blueprints.address.ejb.Address;
48 import com.sun.j2ee.blueprints.servicelocator.ejb.ServiceLocator;
49 import com.sun.j2ee.blueprints.servicelocator.ServiceLocatorException;
50
51
52 public abstract class ContactInfoEJB implements javax.ejb.EntityBean {
53
54   private EntityContext context = null;
55
56   // getters and setters for CMP fields
57
//====================================
58
public abstract String getFamilyName();
59   public abstract void setFamilyName(String familyName);
60
61   public abstract String getGivenName();
62   public abstract void setGivenName(String givenName);
63
64   public abstract String getTelephone();
65   public abstract void setTelephone(String telephone);
66
67   public abstract String getEmail();
68   public abstract void setEmail(String email);
69
70   // CMR fields
71
public abstract AddressLocal getAddress();
72   public abstract void setAddress(AddressLocal address);
73
74   // EJB create methods
75
//===================
76
public Object ejbCreate () throws CreateException {
77     return null;
78   }
79
80   public void ejbPostCreate () throws CreateException {
81     try {
82       ServiceLocator serviceLocator = new ServiceLocator();
83       AddressLocalHome adh = (AddressLocalHome)
84           serviceLocator.getLocalHome(JNDINames.ADDR_EJB);
85       AddressLocal address = adh.create();
86       setAddress(address);
87     } catch (ServiceLocatorException ne) {
88       throw new CreateException("ContactInfoEJB error: ServiceLocator exception looking up address");
89     }
90   }
91
92   public Object ejbCreate(String givenName, String familyName,
93                           String telephone, String email, AddressLocal address)
94                           throws CreateException {
95     setGivenName(givenName);
96     setFamilyName(familyName);
97     setTelephone(telephone);
98     setEmail(email);
99     return null;
100   }
101
102   public void ejbPostCreate(String givenName, String familyName,
103                             String telephone, String email,
104                             AddressLocal address) throws CreateException {
105     setAddress(address);
106   }
107
108   public Object ejbCreate(ContactInfo contactInfo) throws CreateException {
109     setGivenName(contactInfo.getGivenName());
110     setFamilyName(contactInfo.getFamilyName());
111     setTelephone(contactInfo.getPhone());
112     setEmail(contactInfo.getEmail());
113     return null;
114   }
115
116   public void ejbPostCreate(ContactInfo contactInfo) throws CreateException {
117     try {
118       ServiceLocator serviceLocator = new ServiceLocator();
119       AddressLocalHome adh = (AddressLocalHome)
120           serviceLocator.getLocalHome(JNDINames.ADDR_EJB);
121       AddressLocal address = adh.create(contactInfo.getAddress());
122       setAddress(address);
123     } catch (ServiceLocatorException ne) {
124       throw new CreateException("ContactInfoEJB error: ServiceLocator exception looking up address");
125     }
126   }
127
128   public ContactInfo getData() {
129     ContactInfo contactInfo = new ContactInfo();
130     contactInfo.setGivenName(getGivenName());
131     contactInfo.setFamilyName(getFamilyName());
132     contactInfo.setPhone(getTelephone());
133     contactInfo.setEmail(getEmail());
134     contactInfo.setAddress(getAddress().getData());
135     return contactInfo;
136   }
137
138   // Misc Method
139
//=============
140
public void setEntityContext(EntityContext c) {
141     context = c;
142   }
143   public void unsetEntityContext() {
144     context = null;
145   }
146   public void ejbRemove() throws RemoveException {
147   }
148   public void ejbActivate() {
149   }
150   public void ejbPassivate() {
151   }
152   public void ejbStore() {
153   }
154   public void ejbLoad() {
155   }
156 }
157
Popular Tags