1 25 26 package org.objectweb.jonas.jtests.beans.relation.cascade; 27 28 import java.rmi.RemoteException ; 29 import java.util.Collection ; 30 import java.util.Vector ; 31 import javax.ejb.CreateException ; 32 import javax.ejb.EJBException ; 33 import javax.ejb.EntityBean ; 34 import javax.ejb.EntityContext ; 35 import javax.ejb.RemoveException ; 36 import javax.naming.InitialContext ; 37 import javax.naming.NamingException ; 38 39 import org.objectweb.jonas.common.Log; 40 import org.objectweb.util.monolog.api.BasicLevel; 41 import org.objectweb.util.monolog.api.Logger; 42 43 47 public abstract class CarBean implements EntityBean { 48 49 static protected Logger logger = null; 50 protected EntityContext ejbContext = null; 51 protected InsuranceHL insuranceHL = null; 52 protected InvoiceHL invoiceHL = null; 53 54 public Object ejbCreate(String number, byte type, String name) throws CreateException { 55 logger.log(BasicLevel.DEBUG, ""); 56 setNumber(number); 57 setType(type); 58 setName(name); 59 return null; 60 } 61 62 public void ejbPostCreate(String number, byte type, String name) throws CreateException { 63 logger.log(BasicLevel.DEBUG, ""); 64 InsuranceL ins = insuranceHL.create("000" + number); 65 setInsurance(ins); 66 } 67 68 public abstract Integer getId(); 70 public abstract void setId(Integer id); 71 public abstract String getNumber(); 72 public abstract void setNumber(String number); 73 public abstract byte getType(); 74 public abstract void setType(byte type); 75 public abstract String getName(); 76 public abstract void setName(String name); 77 78 public abstract InsuranceL getInsurance(); 80 public abstract void setInsurance(InsuranceL i); 81 public abstract CustomerL getCustomer(); 82 public abstract void setCustomer(CustomerL c); 83 public abstract java.util.Collection getInvoices(); 84 public abstract void setInvoices(java.util.Collection invoices); 85 86 87 public void addInvoice(String number) throws NamingException , CreateException { 88 logger.log(BasicLevel.DEBUG, ""); 89 InvoiceL invoice = invoiceHL.create(number); 90 Collection invoices = getInvoices(); 91 invoices.add(invoice); 92 } 93 94 public void setEntityContext(EntityContext ec) { 95 if (logger == null) 96 logger = Log.getLogger(Log.JONAS_TESTS_PREFIX); 97 logger.log(BasicLevel.DEBUG, ""); 98 ejbContext = ec; 99 try { 100 InitialContext cntx = new InitialContext (); 101 insuranceHL = (InsuranceHL) cntx.lookup("java:comp/env/ejb/InsuranceHomeLocal"); 102 invoiceHL = (InvoiceHL) cntx.lookup("java:comp/env/ejb/InvoiceHomeLocal"); 103 } catch (Exception e) { 104 throw new javax.ejb.EJBException (e); 105 } 106 } 107 108 public void unsetEntityContext() { 109 logger.log(BasicLevel.DEBUG, ""); 110 ejbContext = null; 111 } 112 113 public void ejbLoad() { 114 logger.log(BasicLevel.DEBUG, ""); 115 checkCustomerAccess(); 116 } 117 118 public void ejbStore() { 119 logger.log(BasicLevel.DEBUG, ""); 120 checkCustomerAccess(); 121 } 122 123 public void ejbActivate() { 124 logger.log(BasicLevel.DEBUG, ""); 125 } 129 130 public void ejbPassivate() { 131 logger.log(BasicLevel.DEBUG, ""); 132 } 136 137 141 public void ejbRemove() throws javax.ejb.RemoveException { 142 logger.log(BasicLevel.DEBUG, ""); 143 InsuranceL myins = getInsurance(); 144 if (myins == null) { 145 logger.log(BasicLevel.ERROR, "CMR field Insurance is null"); 146 throw new RemoveException ("Cannot access CMR field Insurance inside ejbRemove"); 147 } 148 String insnumber = myins.getNumber(); 149 String expect = "000" + getNumber(); 150 if (! expect.equals(insnumber)) { 151 throw new RemoveException ("Bad insurance number:" + insnumber); 152 } 153 checkCustomerAccess(); 154 } 155 156 protected void checkCustomerAccess() { 157 logger.log(BasicLevel.DEBUG, ""); 158 CustomerL mycust = getCustomer(); 159 if (mycust == null) { 160 logger.log(BasicLevel.ERROR, "CMR field Customer is null"); 161 throw new EJBException ("CMR field Customer is null"); 162 } 163 Name n = mycust.getName(); 164 if (n == null || n.getLastName().length() == 0) { 165 logger.log(BasicLevel.ERROR, "Cannot get customer name"); 166 throw new EJBException ("Cannot get customer name"); 167 } 168 } 169 } 170 | Popular Tags |