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