1 27 28 package checker; 29 import java.util.*; 30 import javax.ejb.*; 31 import javax.naming.*; 32 33 34 public class CheckerBean implements SessionBean, CheckerRemoteBusiness { 35 String customerName; 36 37 public CheckerBean() { 38 } 39 40 public void ejbCreate(String person) { 41 customerName = person; 42 } 43 44 public double applyDiscount(double amount) { 45 try { 46 double discount; 47 48 Context initial = new InitialContext(); 49 Context environment = (Context) initial.lookup("java:comp/env"); 50 51 Double discountLevel = 52 (Double ) environment.lookup("Discount Level"); 53 Double discountPercent = 54 (Double ) environment.lookup("Discount Percent"); 55 56 if (amount >= discountLevel.doubleValue()) { 57 discount = discountPercent.doubleValue(); 58 } else { 59 discount = 0.00; 60 } 61 62 return amount * (1.00 - discount); 63 } catch (NamingException ex) { 64 throw new EJBException("NamingException: " + ex.getMessage()); 65 } 66 } 67 68 public void ejbRemove() { 69 } 70 71 public void ejbActivate() { 72 } 73 74 public void ejbPassivate() { 75 } 76 77 public void setSessionContext(SessionContext sc) { 78 } 79 } | Popular Tags |