KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > beans > session > ReportHandlerBean


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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