1 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 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 public abstract AddressLocal getAddress(); 72 public abstract void setAddress(AddressLocal address); 73 74 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 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 |