001: /*
002: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. U.S.
003: * Government Rights - Commercial software. Government users are subject
004: * to the Sun Microsystems, Inc. standard license agreement and
005: * applicable provisions of the FAR and its supplements. Use is subject
006: * to license terms.
007: *
008: * This distribution may include materials developed by third parties.
009: * Sun, Sun Microsystems, the Sun logo, Java and J2EE are trademarks
010: * or registered trademarks of Sun Microsystems, Inc. in the U.S. and
011: * other countries.
012: *
013: * Copyright (c) 2005 Sun Microsystems, Inc. Tous droits reserves.
014: *
015: * Droits du gouvernement americain, utilisateurs gouvernementaux - logiciel
016: * commercial. Les utilisateurs gouvernementaux sont soumis au contrat de
017: * licence standard de Sun Microsystems, Inc., ainsi qu'aux dispositions
018: * en vigueur de la FAR (Federal Acquisition Regulations) et des
019: * supplements a celles-ci. Distribue par des licences qui en
020: * restreignent l'utilisation.
021: *
022: * Cette distribution peut comprendre des composants developpes par des
023: * tierces parties. Sun, Sun Microsystems, le logo Sun, Java et J2EE
024: * sont des marques de fabrique ou des marques deposees de Sun
025: * Microsystems, Inc. aux Etats-Unis et dans d'autres pays.
026: */
027:
028: package dataregistry;
029:
030: import java.math.BigDecimal;
031: import java.sql.Timestamp;
032: import java.util.Collection;
033: import java.util.Date;
034: import java.util.Iterator;
035: import javax.ejb.EJBException;
036:
037: /**
038: * This is the bean class for the OrdersBean enterprise bean.
039: */
040: public abstract class OrderBean implements javax.ejb.EntityBean,
041: dataregistry.OrderLocalBusiness {
042: private javax.ejb.EntityContext context;
043:
044: // <editor-fold defaultstate="collapsed" desc="EJB infrastructure methods. Click on the + sign on the left to edit the code.">
045: // TODO Consider creating Transfer Object to encapsulate data
046: // TODO Review finder methods
047: /**
048: * @see javax.ejb.EntityBean#setEntityContext(javax.ejb.EntityContext)
049: */
050: public void setEntityContext(javax.ejb.EntityContext aContext) {
051: context = aContext;
052: }
053:
054: /**
055: * @see javax.ejb.EntityBean#ejbActivate()
056: */
057: public void ejbActivate() {
058:
059: }
060:
061: /**
062: * @see javax.ejb.EntityBean#ejbPassivate()
063: */
064: public void ejbPassivate() {
065:
066: }
067:
068: /**
069: * @see javax.ejb.EntityBean#ejbRemove()
070: */
071: public void ejbRemove() {
072:
073: }
074:
075: /**
076: * @see javax.ejb.EntityBean#unsetEntityContext()
077: */
078: public void unsetEntityContext() {
079: context = null;
080: }
081:
082: /**
083: * @see javax.ejb.EntityBean#ejbLoad()
084: */
085: public void ejbLoad() {
086:
087: }
088:
089: /**
090: * @see javax.ejb.EntityBean#ejbStore()
091: */
092: public void ejbStore() {
093:
094: }
095:
096: // </editor-fold>
097:
098: public abstract java.lang.Integer getOrderId();
099:
100: public abstract void setOrderId(java.lang.Integer orderId);
101:
102: public abstract java.lang.String getStatus();
103:
104: public abstract void setStatus(java.lang.String status);
105:
106: public abstract java.sql.Timestamp getLastUpdate();
107:
108: public abstract void setLastUpdate(java.sql.Timestamp lastUpdate);
109:
110: public abstract java.math.BigDecimal getDiscount();
111:
112: public abstract void setDiscount(java.math.BigDecimal discount);
113:
114: public abstract java.lang.String getShipmentInfo();
115:
116: public abstract void setShipmentInfo(java.lang.String shipmentInfo);
117:
118: public abstract java.util.Collection getLineitemBean();
119:
120: public abstract void setLineitemBean(
121: java.util.Collection lineitemBean);
122:
123: public java.lang.Integer ejbCreate(java.lang.Integer orderId,
124: java.lang.String status, java.sql.Timestamp lastUpdate,
125: java.math.BigDecimal discount, java.lang.String shipmentInfo)
126: throws javax.ejb.CreateException {
127: if (orderId == null) {
128: throw new javax.ejb.CreateException(
129: "The field \"orderId\" must not be null");
130: }
131: if (status == null) {
132: throw new javax.ejb.CreateException(
133: "The field \"status\" must not be null");
134: }
135: if (lastUpdate == null) {
136: throw new javax.ejb.CreateException(
137: "The field \"lastUpdate\" must not be null");
138: }
139: if (discount == null) {
140: throw new javax.ejb.CreateException(
141: "The field \"discount\" must not be null");
142: }
143:
144: // TODO add additional validation code, throw CreateException if data is not valid
145: setOrderId(orderId);
146: setStatus(status);
147: setLastUpdate(lastUpdate);
148: setDiscount(discount);
149: setShipmentInfo(shipmentInfo);
150:
151: return null;
152: }
153:
154: public void ejbPostCreate(java.lang.Integer orderId,
155: java.lang.String status, java.sql.Timestamp lastUpdate,
156: java.math.BigDecimal discount, java.lang.String shipmentInfo) {
157: // TODO populate relationships here if appropriate
158:
159: }
160:
161: public java.lang.Integer ejbCreate(java.lang.Integer orderId,
162: java.lang.String status, java.math.BigDecimal discount,
163: java.lang.String shipmentInfo)
164: throws javax.ejb.CreateException {
165: //TODO implement ejbCreate
166: setOrderId(orderId);
167: setStatus(status);
168: setLastUpdate(new Timestamp(new Date().getTime()));
169: setDiscount(discount);
170: setShipmentInfo(shipmentInfo);
171:
172: return null;
173: }
174:
175: public void ejbPostCreate(java.lang.Integer orderId,
176: java.lang.String status, java.math.BigDecimal doscount,
177: java.lang.String shipmentInfo)
178: throws javax.ejb.CreateException {
179: //TODO implement ejbPostCreate
180: }
181:
182: public double calculateAmmount() {
183: //TODO implement calculateAmmount
184: double ammount = 0;
185: Collection items = getLineitemBean();
186:
187: for (Iterator it = items.iterator(); it.hasNext();) {
188: LineItemLocal item = (LineItemLocal) it.next();
189: VendorPartLocal part = item.getVendorPartNumber();
190: ammount += (part.getPrice().doubleValue() * item
191: .getQuantity().doubleValue());
192: }
193:
194: return (ammount * (100 - getDiscount().intValue())) / 100;
195:
196: }
197:
198: public void ejbHomeAdjustDiscount(int adjustment) {
199: //TODO implement ejbHomeHomeAdjustDiscount
200: try {
201: Collection orders = ejbSelectAll();
202:
203: for (Iterator it = orders.iterator(); it.hasNext();) {
204: OrderLocal order = (OrderLocal) it.next();
205: int newDiscount = order.getDiscount().intValue()
206: + adjustment;
207: order.setDiscount((newDiscount > 0) ? new BigDecimal(
208: newDiscount) : new BigDecimal(0));
209: }
210: } catch (Exception ex) {
211: throw new EJBException(ex.getMessage());
212: }
213:
214: }
215:
216: public abstract java.util.Collection ejbSelectAll()
217: throws javax.ejb.FinderException;
218:
219: public int getNexId() {
220: return getLineitemBean().size() + 1;
221: }
222: }
|