001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: InvoiceBean.java 5061 2004-07-02 16:04:32Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.relation.cascade;
027:
028: import java.rmi.RemoteException;
029: import javax.ejb.CreateException;
030: import javax.ejb.EntityContext;
031: import javax.ejb.EntityBean;
032: import javax.ejb.RemoveException;
033:
034: import org.objectweb.jonas.common.Log;
035: import org.objectweb.util.monolog.api.BasicLevel;
036: import org.objectweb.util.monolog.api.Logger;
037:
038: /**
039: * Implementation for bean Invoice
040: * @author Ph Durieux
041: */
042: public abstract class InvoiceBean implements EntityBean {
043:
044: static protected Logger logger = null;
045: protected EntityContext ejbContext = null;
046:
047: public Integer ejbCreate(String number) throws CreateException {
048: logger.log(BasicLevel.DEBUG, "");
049: setNumber(number);
050: return null;
051: }
052:
053: public void ejbPostCreate(String number) {
054: logger.log(BasicLevel.DEBUG, "");
055: }
056:
057: // persistent fields
058: public abstract Integer getId();
059:
060: public abstract void setId(Integer id);
061:
062: public abstract String getNumber();
063:
064: public abstract void setNumber(String number);
065:
066: // persistent relationships
067: public abstract CarL getCar();
068:
069: public abstract void setCar(CarL car);
070:
071: public void setEntityContext(EntityContext ec) {
072: if (logger == null)
073: logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
074: logger.log(BasicLevel.DEBUG, "");
075: ejbContext = ec;
076: }
077:
078: public void unsetEntityContext() {
079: logger.log(BasicLevel.DEBUG, "");
080: ejbContext = null;
081: }
082:
083: public void ejbLoad() {
084: logger.log(BasicLevel.DEBUG, "");
085: }
086:
087: public void ejbStore() {
088: logger.log(BasicLevel.DEBUG, "");
089: }
090:
091: public void ejbActivate() {
092: logger.log(BasicLevel.DEBUG, "");
093: }
094:
095: public void ejbPassivate() {
096: logger.log(BasicLevel.DEBUG, "");
097: }
098:
099: /**
100: * this instance is being removed.
101: * we must be able to access bean fields here, including the CMRs
102: */
103: public void ejbRemove() throws javax.ejb.RemoveException {
104: logger.log(BasicLevel.DEBUG, "number=" + getNumber());
105: CarL mycar = getCar();
106: if (mycar == null) {
107: logger.log(BasicLevel.ERROR, "CMR field is null");
108: throw new RemoveException(
109: "Cannot access CMR field inside Invoice.ejbRemove");
110: }
111: String carnumber = mycar.getNumber();
112: if (!getNumber().startsWith(carnumber)) {
113: throw new RemoveException(
114: "Bad car number while removing Invoice:"
115: + carnumber);
116: }
117: CustomerL cust = mycar.getCustomer();
118: if (cust == null) {
119: logger.log(BasicLevel.ERROR,
120: "Cannot get customer from invoice");
121: throw new RemoveException(
122: "Cannot get customer from invoice");
123: }
124: }
125: }
|