1 18 19 package cowsultants.itracker.ejb.beans.session; 20 21 import java.util.*; 22 import javax.ejb.*; 23 import javax.jms.*; 24 import javax.naming.*; 25 import javax.rmi.*; 26 27 import cowsultants.itracker.ejb.beans.entity.*; 28 import cowsultants.itracker.ejb.client.interfaces.*; 29 import cowsultants.itracker.ejb.client.models.*; 30 import cowsultants.itracker.ejb.client.util.*; 31 32 public class ReportHandlerBean implements SessionBean { 33 SessionContext context = null; 34 35 InitialContext ic = null; 36 IDGeneratorHome idHome = null; 37 ReportLocalHome rHome = null; 38 39 public ReportModel getReport(Integer id) { 40 try { 41 ReportLocal report = rHome.findByPrimaryKey(id); 42 return report.getModel(); 43 } catch(FinderException fe) { 44 } 45 return null; 46 } 47 48 public byte[] getReportFile(Integer reportId) { 49 byte[] data = new byte[0]; 50 51 try { 52 ReportLocal report = rHome.findByPrimaryKey(reportId); 53 data = report.getFileData(); 54 if(data == null) { 55 data = new byte[0]; 56 } 57 } catch(FinderException fe) { 58 } 59 return data; 60 } 61 62 public ReportModel[] getAllReports() { 63 int i = 0; 64 ReportModel[] reportArray = new ReportModel[0]; 65 66 try { 67 Collection reports = rHome.findAll(); 68 reportArray = new ReportModel[reports.size()]; 69 for(Iterator iterator = reports.iterator(); iterator.hasNext(); i++) { 70 reportArray[i] = ((ReportLocal) iterator.next()).getModel(); 71 } 72 } catch(FinderException fe) { 73 } 74 return reportArray; 75 } 76 77 public int getNumberReports() { 78 try { 79 Collection reports = rHome.findAll(); 80 return reports.size(); 81 } catch(FinderException fe) { 82 } 83 return 0; 84 } 85 86 public ReportModel createReport(ReportModel model) { 87 try { 88 IDGenerator idGen = idHome.create(); 89 ReportLocal report = rHome.create(idGen.getId(ReportLocal.ID_NAME)); 90 report.setModel(model); 91 return report.getModel(); 92 } catch(CreateException ce) { 93 Logger.logDebug("Could not create report.", ce); 94 } 95 return null; 96 } 97 98 public ReportModel updateReport(ReportModel model) { 99 try { 100 ReportLocal report = rHome.findByPrimaryKey(model.getId()); 101 report.setModel(model); 102 return report.getModel(); 103 } catch(FinderException fe) { 104 } 105 return null; 106 } 107 108 public boolean removeReport(Integer reportId) { 109 try { 110 rHome.remove(reportId); 111 return true; 112 } catch(RemoveException re) { 113 } 114 return false; 115 } 116 117 public void ejbCreate() { 118 try { 119 ic = new InitialContext(); 120 Object idRef = ic.lookup("java:comp/env/" + IDGenerator.JNDI_NAME); 121 idHome = (IDGeneratorHome) PortableRemoteObject.narrow(idRef, IDGeneratorHome.class); 122 123 rHome = (ReportLocalHome) ic.lookup("java:comp/env/" + ReportLocal.JNDI_NAME); 124 } catch(NamingException ne) { 125 Logger.logError("Exception while looking up home interfaces.", ne); 126 } 127 } 128 129 public void setSessionContext(SessionContext value) { 130 context = value; 131 } 132 133 public void ejbActivate() {} 134 public void ejbPassivate() {} 135 public void ejbRemove() {} 136 } 137 | Popular Tags |