A.13 ProvidenceDoctorBean ClassCode Example A.16 shows the source code for the ProvidenceDoctorBean class described in Chapter 9. Code Example A.16 ProvidenceDoctorBean Class Source Codepackage com.star.plan; import javax.ejb.*; import javax.naming.*; import java.util.*; import com.wombat.plan.*; import com.wombat.AbstractEntityBean; import com.star.plan.providence.*; public class ProvidenceDoctorBean extends AbstractEntityBean { private DoctorInfo doctorInfo; private ProvidenceWebPort providence; /******************************************************************/ /* business methods */ /******************************************************************/ public String getFirstName() { return getDoctorInfo().getFirstName(); } public String getLastName() { return getDoctorInfo().getLastName(); } public String getSpecialty() { return getDoctorInfo().getSpecialty(); } public String[] getHospitals() { return getDoctorInfo().getHospitals(); } public int getPracticeSince() { return getDoctorInfo().getPracticeSince(); } /******************************************************************/ /* create, find methods */ /******************************************************************/ public DoctorPkey ejbCreate(String firstName, String lastName, String specialty, String[] hospitals, int practiceSince) throws CreateException { throw new CreateException( "Create not supported for Providence Health plan"); } public void ejbPostCreate(String firstName, String lastName, String specialty, String[] hospitals, int practiceSince) throws CreateException {} public DoctorPkey ejbFindByPrimaryKey(DoctorPkey pkey) throws FinderException { try { DoctorInfo doctorQuery = new DoctorInfo(); doctorQuery.setFirstName(pkey.firstName); doctorQuery.setLastName(pkey.lastName); doctorInfo = providence.getDoctorInfo(null, doctorQuery)[0]; } catch ( Exception ex ) { throw new ObjectNotFoundException(); } return pkey; } /******************************************************************/ /* miscellaneous methods */ /******************************************************************/ public void setEntityContext(EntityContext ctx) { super.setEntityContext(ctx); try { InitialContext ic = new InitialContext(); ProvidenceWebService service = (ProvidenceWebService)ic.lookup( "java:comp/env/service/ProvidenceWebService"); providence = service.getProvidenceWebSvcPort(); } catch ( Exception ex ) { throw new EJBException(ex); } } public void ejbRemove() { doctorInfo = null; } public void ejbPassivate() { doctorInfo = null; } private DoctorInfo getDoctorInfo() { if ( doctorInfo == null ) { DoctorPkey pkey = (DoctorPkey)entityContext.getPrimaryKey(); try { DoctorInfo doctorQuery = new DoctorInfo(); doctorQuery.setFirstName(pkey.firstName); doctorQuery.setLastName(pkey.lastName); doctorInfo = providence.getDoctorInfo(null, doctorQuery)[0]; } catch ( Exception ex ) { throw new EJBException(ex); } } return doctorInfo; } } |