KickJava   Java API By Example, From Geeks To Geeks.

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


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 SchedulerHandlerBean implements SessionBean {
33     SessionContext context = null;
34
35     InitialContext ic = null;
36     IDGeneratorHome idHome = null;
37     ScheduledTaskLocalHome stHome = null;
38
39     public ScheduledTaskModel getTask(Integer JavaDoc id) {
40         try {
41             ScheduledTaskLocal task = stHome.findByPrimaryKey(id);
42             return task.getModel();
43         } catch(FinderException fe) {
44         }
45         return null;
46     }
47
48     public ScheduledTaskModel[] getAllTasks() {
49         int i = 0;
50         ScheduledTaskModel[] taskArray = new ScheduledTaskModel[0];
51
52         try {
53             Collection tasks = stHome.findAll();
54             taskArray = new ScheduledTaskModel[tasks.size()];
55             for(Iterator iterator = tasks.iterator(); iterator.hasNext(); i++) {
56                 taskArray[i] = ((ScheduledTaskLocal) iterator.next()).getModel();
57             }
58         } catch(FinderException fe) {
59         }
60         return taskArray;
61     }
62
63     public ScheduledTaskModel createTask(ScheduledTaskModel model) {
64         try {
65             IDGenerator idGen = idHome.create();
66             ScheduledTaskLocal task = stHome.create(idGen.getId(ScheduledTaskLocal.ID_NAME));
67             task.setModel(model);
68             return task.getModel();
69         } catch(CreateException ce) {
70             Logger.logDebug("Could not create task.", ce);
71         }
72         return null;
73     }
74
75     public ScheduledTaskModel updateTask(ScheduledTaskModel model) {
76         try {
77             ScheduledTaskLocal task = stHome.findByPrimaryKey(model.getId());
78             task.setModel(model);
79             return task.getModel();
80         } catch(FinderException fe) {
81         }
82         return null;
83     }
84
85     public boolean removeTask(Integer JavaDoc taskId) {
86         try {
87             stHome.remove(taskId);
88             return true;
89         } catch(RemoveException re) {
90         }
91         return false;
92     }
93
94     public void ejbCreate() {
95         try {
96             ic = new InitialContext();
97             Object JavaDoc idRef = ic.lookup("java:comp/env/" + IDGenerator.JNDI_NAME);
98             idHome = (IDGeneratorHome) PortableRemoteObject.narrow(idRef, IDGeneratorHome.class);
99
100             stHome = (ScheduledTaskLocalHome) ic.lookup("java:comp/env/" + ScheduledTaskLocal.JNDI_NAME);
101         } catch(NamingException ne) {
102             Logger.logError("Exception while looking up home interfaces.", ne);
103         }
104     }
105
106     public void setSessionContext(SessionContext value) {
107         context = value;
108     }
109
110     public void ejbActivate() {}
111     public void ejbPassivate() {}
112     public void ejbRemove() {}
113 }
114   
Popular Tags