1 package test.ejb;2 3 import test.interfaces.AccountHome;4 import test.interfaces.AddressLocalHome;5 import test.interfaces.ApplicationException;6 import test.interfaces.Customer;7 import test.interfaces.CustomerData;8 import test.interfaces.CustomerLightValue;9 import test.interfaces.CustomerNormalValue;10 import test.interfaces.CustomerPK;11 12 import javax.ejb.CreateException ;13 import javax.ejb.EJBException ;14 import javax.ejb.EntityContext ;15 import javax.naming.InitialContext ;16 import java.util.Collection ;17 18 /**19 * This is a customer bean. It is an example of how to use the XDoclet tags.20 *21 * @ejb.bean22 * cmp-version="1.x"23 * jndi-name="${ejb.prefix}/bank/Customer"24 * name="Customer"25 * type="CMP"26 * use-soft-locking="true"27 * view-type="remote"28 * @ejb.ejb-ref29 * ejb-name="Account"30 * ref-name="ejb/bank/Account"31 * @ejb.security-role-ref32 * role-link="Administrator"33 * role-name="admin"34 * @ejb.permission35 * role-name="Teller"36 * @ejb.transaction37 * type="Required"38 * @ejb.data-object39 * use-super-equals="true"40 * @ejb.value-object41 * match="light"42 * name="CustomerLight"43 * @ejb.value-object44 * match="normal"45 * name="CustomerNormal"46 * @ejb.value-object47 * match="*"48 * @jboss.ejb-ref-jndi49 * jndi-name="ejb/bank/Account"50 * ref-name="bank/Account"51 * @ejb.persistence table-name="customer"52 * @jboss.create-table "true"53 * @jboss.remove-table "true"54 * @jboss.tuned-updates "true"55 * @jboss.read-only "true"56 * @jboss.time-out "100"57 * @weblogic.transaction-isolation TRANSACTION_SERIALIZABLE58 *59 * @jonas.bean ejb-name="Customer"60 * jndi-name="CustomerHome"61 * @jonas.ejb-ref ejb-ref-name="ejb/bank/Account"62 * jndi-name="Account"63 * @jonas.jdbc-mapping64 * jndi-name="jdbc_1"65 * jdbc-table-name="customer"66 *67 * @todo This too should not appear in CMP class68 */69 70 public abstract class CustomerBean71 extends PersonBean {72 private EntityContext ctx;73 74 /**75 * Overriden from Person.76 *77 * @todo This todo should not appear in interfaces78 * @ejb.interface-method79 * @weblogic.transaction-isolation TRANSACTION_READ_COMMITTED80 */81 public void talkTo() {82 }83 84 /**85 * Overloaded works too.86 *87 * @ejb.interface-method88 */89 public void talkTo(String somebody) {90 }91 92 /**93 * Credit limit94 *95 * @ejb.persistent-field96 * @ejb.persistence97 * column-name="credit"98 * @ejb.value-object99 * match="normal"100 * @ejb.value-object101 * match="light"102 */103 public abstract float getCredit();104 105 /**106 * Array107 *108 * @ejb.persistent-field109 * @ejb.persistence110 * column-name="array"111 * @ejb.value-object112 * match="normal"113 * @ejb.value-object114 * match="light"115 */116 public abstract String [][] getArray();117 118 /**119 * Array120 *121 * @ejb.persistent-field122 * @ejb.persistence123 * column-name="image"124 * @ejb.value-object125 * match="normal"126 * @ejb.value-object127 * match="light"128 */129 public abstract byte[] getImage();130 131 /**132 * Tax Code133 *134 * @ejb.persistent-field135 * @ejb.persistence136 * column-name="tax"137 * @ejb.value-object138 * match="normal"139 */140 public abstract float getTax();141 142 /**143 * Credit limit144 *145 */146 public abstract void setCredit(float credit);147 148 /**149 * Accounts of this customer150 *151 * @ejb.interface-method152 * @ejb.transaction153 * type="Supports"154 * @ejb.value-object155 * aggregate="test.interfaces.AccountValue"156 * aggregate-name="AccountView"157 * match="normal"158 * members="test.interfaces.AccountLocal"159 * members-name="Account"160 * relation="external"161 * type="java.util.Collection"162 */163 public java.util.Collection getAccounts() {164 // Some code here under that will flame the guy who break multiple method tags165 CustomerNormalValue normal = new CustomerNormalValue();166 normal.getCredit();167 CustomerLightValue light = new CustomerLightValue();168 light.getCredit();169 try {170 AccountHome home = (AccountHome) new InitialContext ().lookup("java:comp/env/ejb/bank/Account");171 return home.findByOwner((Customer) ctx.getEJBObject());172 }173 catch (Exception e) {174 throw new EJBException (e);175 }176 }177 178 /**179 * Just to show that generated methods can be exported to remote/local interafce180 *181 * @ejb.interface-method182 */183 public abstract void addAccount(test.interfaces.AccountValue added)184 throws javax.ejb.FinderException ;185 186 /**187 * Generated bulk accessor. Not remote, but could be.188 *189 */190 public void setData(CustomerData data) {191 try {192 super.setData(data);193 setCredit(data.getCredit());194 }195 catch (Exception e) {196 throw new javax.ejb.EJBException (e);197 }198 }199 200 /**201 * @ejb.interface-method202 * view-type="remote"203 */204 public abstract void setCustomerNormalValue(CustomerNormalValue value)205 throws ApplicationException;206 207 /**208 * @ejb.interface-method209 * view-type="remote"210 */211 public abstract CustomerNormalValue getCustomerNormalValue();212 213 /**214 * This method to show how validation errors can be reported to the user. This is Business Logic validation error.215 *216 */217 protected void validate(CustomerNormalValue value)218 throws ApplicationException {219 /* This exception should better be done in the client itself because220 it requires no ejb connection. Anyway this is an "example" on how221 business validation can be done */222 if (value.getTax() < 0)223 throw new ApplicationException("A Customer can not have a negative Tax");224 }225 226 /**227 * Generated bulk accessor. This is set as remote to allow clients to get all data in one call.228 *229 * @ejb.interface-method230 * view-type="remote"231 * @ejb.transaction232 * type="Supports"233 */234 public CustomerData getData() {235 return null;236 }237 238 /**239 * @ejb:interface-method240 * @ejb:permission role-name="Administrator"241 * @ejb:transaction type="Supports"242 * @ejb:value-object match="*" compose="test.interfaces.AddressValue" compose-name="AddressValue"243 */244 // public abstract test.interfaces.AddressLocal getAddress();245 246 /**247 * @ejb:interface-method248 */249 // public abstract void setAddress(test.interfaces.AddressLocal addr);250 251 /**252 * Accounts of this customer253 *254 * @ejb.interface-method255 * @ejb.transaction256 * type="Supports"257 * @ejb.value-object258 * compose="test.interfaces.AddressValue"259 * compose-name="ShippingAddressValue"260 * match="normal"261 * members="test.interfaces.AddressLocal"262 * members-name="ShippingAddress"263 * relation="external"264 * type="java.util.Collection"265 */266 public java.util.Collection getShippingAddresses() {267 try {268 AddressLocalHome home = (AddressLocalHome) new InitialContext ().lookup("java:comp/env/ejb/bank/Address");269 return home.findByOwner((Customer) ctx.getEJBObject());270 }271 catch (Exception e) {272 throw new EJBException (e);273 }274 }275 276 /**277 * Create customer.278 *279 * @ejb.create-method280 * @ejb.permission281 * role-name="Administrator"282 */283 public java.lang.Object ejbCreate(CustomerNormalValue data)284 throws CreateException {285 try {286 setId(data.getId());287 // data.getAddressValue().setId(data.getId());288 // AddressUtil.getLocalHome().create(data.getAddressValue());289 return null;290 }291 catch (Exception e) {292 throw new EJBException (e);293 }294 }295 296 // Let's test the ejbPC auto add feature297 // public void ejbPostCreate(CustomerNormalValue data)298 // throws CreateException {}299 300 /**301 * Create customer.302 *303 */304 public void ejbPostCreate(CustomerData data)305 throws CreateException {306 }307 308 // EntityBean implementation -------------------------------------309 /**310 * Remove311 *312 * @ejb:transaction type="Mandatory"313 */314 // public void ejbRemove() throws RemoveException {315 // getAddress().remove();316 // }317 318 /**319 * To see if abstract works320 *321 */322 public abstract void ejbLoad();323 324 /**325 * Custom Finders326 *327 */328 public java.util.Collection ejbFindCustomFinderInSuper() {329 return null;330 }331 332 /**333 * @ejb:home-method334 */335 public void ejbHomeCopyToArchive(CustomerPK pk) {336 // does nothing with CMP, BMP will override337 }338 339 }340