A.10 InsurancePlanAdminBean Class

A.10 InsurancePlanAdminBean Class

Code Example A.13 shows the source code for the InsurancePlanAdminBean class described in Chapter 9.

Code Example A.13 InsurancePlanAdminBean Class Source Code
 package com.star.admin; import javax.ejb.*; import javax.naming.InitialContext; import java.util.Collection; import com.wombat.plan.*; public class InsurancePlanAdminBean implements SessionBean {     private SessionContext sessionContext;     private PlanHome planHome;     private DoctorHome doctorHome;     public InsurancePlanAdminBean(){}     public void createInsurancePlan(String planId, String planName,        int planType, double coverageFactor, double ageFactor,                 double smokerCost)     {     try {         Plan newPlan = planHome.create(planId, planName, planType,                       coverageFactor, ageFactor, smokerCost);     } catch ( CreateException ex ) {         throw new EJBException(ex);     }     }     public PlanInfo getPlanInfo(String planId)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         PlanInfo planInfo = new PlanInfo();         planInfo.planId = plan.getPlanId();         planInfo.planName = plan.getPlanName();         planInfo.planType = plan.getPlanType();         planInfo.coverageFactor = plan.getCoverageFactor();         planInfo.ageFactor = plan.getAgeFactor();         planInfo.smokerCost = plan.getSmokerCost();         return planInfo;     } catch ( Exception ex ) {         throw new EJBException(ex);     }      }     public void addDoctors(String planId, DoctorInfo[] doctors)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         for ( int i=0; i<doctors.length; i++ ) {         // Find or create a Doctor bean.         DoctorPkey pkey = new DoctorPkey(doctors[i].firstName,                         doctors[i].lastName);         Doctor doctor;         try {             doctor = doctorHome.findByPrimaryKey(pkey);         } catch ( FinderException fe ) {             doctor = doctorHome.create(doctors[i].firstName,                           doctors[i].lastName,                           doctors[i].specialty,                           doctors[i].hospitals,                           doctors[i].practiceSince);         }         plan.addDoctor(doctor);         }     } catch ( Exception ex ) {         throw new EJBException(ex);     }      }     public void removeDoctors(String planId, DoctorInfo[] doctors)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         for ( int i=0; i<doctors.length; i++ ) {         // Find a Doctor bean.         DoctorPkey pkey = new DoctorPkey(doctors[i].firstName,                         doctors[i].lastName);         Doctor doctor;         try {             doctor = doctorHome.findByPrimaryKey(pkey);         } catch ( FinderException ex ) {             throw new EJBException(ex);         }         plan.removeDoctor(doctor);         }     } catch ( Exception ex ) {         throw new EJBException(ex);     }      }     public DoctorInfo[] getAllDoctors(String planId)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         Collection doctors = plan.getAllDoctors();         return (DoctorInfo[])doctors.toArray(                   new Doctor[doctors.size()]);     } catch ( Exception ex ) {         throw new EJBException(ex);     }      }     public void setSmokerCost(String planId, double cost)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         plan.setSmokerCost(cost);     } catch ( Exception ex ) {         throw new EJBException(ex);     }      }     public void setCoverageFactor(String planId, double s)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         plan.setCoverageFactor(s);     } catch ( Exception ex ) {         throw new EJBException(ex);     }     }     public void setAgeFactor(String planId, double s)     {     try {         Plan plan = planHome.findByPrimaryKey(planId);         plan.setAgeFactor(s);     } catch ( Exception ex ) {         throw new EJBException(ex);     }     }     /* Life-cycle methods */     public void setSessionContext(SessionContext sessionContext) {         this.sessionContext = sessionContext;     try {         // Look up local home object for PlanEJB using JNDI.         InitialContext initialContext = new InitialContext();         planHome = (PlanHome)initialContext.lookup(                       "java:comp/env/ejb/PlanEJB");         doctorHome = (DoctorHome)initialContext.lookup(                      "java:comp/env/ejb/DoctorEJB");     } catch ( Exception ex ) {         throw new EJBException(ex);     }     }     public void ejbCreate() {}     public void ejbRemove() {}     public void ejbActivate() {}     public void ejbPassivate() {} } 


Applying Enterprise Javabeans
Applying Enterprise JavaBeans(TM): Component-Based Development for the J2EE(TM) Platform
ISBN: 0201702673
EAN: 2147483647
Year: 2003
Pages: 110

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net