1 37 38 package com.sun.j2ee.blueprints.opc.workflowmanager; 39 40 import java.util.*; 41 42 import javax.jms.*; 43 import javax.ejb.*; 44 import javax.naming.*; 45 import javax.ejb.Timer ; 46 47 import com.sun.j2ee.blueprints.opc.workflowmanager.handlers.*; 48 import com.sun.j2ee.blueprints.processmanager.ejb.*; 49 import com.sun.j2ee.blueprints.processmanager.manager.ejb.*; 50 import com.sun.j2ee.blueprints.servicelocator.*; 51 import com.sun.j2ee.blueprints.servicelocator.ejb.*; 52 import com.sun.j2ee.blueprints.opc.JNDINames; 53 54 58 public class WorkFlowManagerBean implements MessageDrivenBean, MessageListener, TimedObject { 59 60 private MessageDrivenContext context; 61 private POHandler poHandler; 62 private InvoiceHandler invHandler; 63 private ProcessManagerLocal pm; 64 65 public void setMessageDrivenContext(MessageDrivenContext context) { 66 this.context=context; 67 } 68 69 public void ejbCreate() { 70 try{ 71 poHandler = new POHandler(); 72 invHandler = new InvoiceHandler(); 73 ServiceLocator sl = new ServiceLocator(); 74 ProcessManagerLocalHome pmlh = (ProcessManagerLocalHome) 75 sl.getLocalHome(JNDINames.PM_EJB); 76 pm = pmlh.create(); 77 } catch (HandlerException he){ 78 throw new EJBException(he.getMessage()); 79 } catch (ServiceLocatorException se) { 80 throw new EJBException(se.getMessage()); 81 } catch (Exception exe) { 82 throw new EJBException(exe.getMessage()); 83 } 84 } 85 86 public void onMessage(Message message) { 87 try{ 88 92 String docType = message.getStringProperty(JNDINames.DOC_TYPE); 93 if(docType.equals(JNDINames.PO_DOCUMENT)) { 94 poHandler.handle(message); 95 } else if(docType.equals(JNDINames.INVOICE_DOCUMENT)) { 96 invHandler.handle(message); 97 createStatusUpdateTimer(); 98 } 99 } catch (HandlerException he){ 100 throw new EJBException(he); 101 } catch (JMSException exe) { 102 throw new EJBException(exe); 103 } 104 } 105 106 private void createStatusUpdateTimer() { 107 try{ 108 109 TimerService timerService = context.getTimerService(); 110 111 if ((timerService.getTimers()).isEmpty()) { 113 Context ic = new InitialContext(); 114 115 int expiration = (((Integer ) ic.lookup(JNDINames.TIMER_EXPIRATION)).intValue()) * 60000; 117 int interval = (((Integer ) ic.lookup(JNDINames.TIMER_INTERVAL)).intValue()) * 60000; 118 Timer timer = timerService.createTimer(expiration, interval, "OPC order update timer"); 119 } 120 } catch (Exception exe) { 121 throw new EJBException(exe); 122 } 123 } 124 125 public void ejbTimeout(Timer timer) { 126 try{ 127 128 Collection ordersList = pm.getOrdersByStatus(OrderStatusNames.SUBMITTED); 130 Iterator iter = ordersList.iterator(); 131 while (iter.hasNext()) { 132 ManagerLocal mgr = (ManagerLocal) iter.next(); 133 String orderID = mgr.getOrderId(); 134 135 pm.updateStatusToCompleted(orderID); 137 138 if(pm.getOrderStatus(orderID).equals(OrderStatusNames.COMPLETED)){ 140 invHandler.sendOrderCompletedMail(orderID); 141 } 142 } 143 } catch (Exception exe) { 144 throw new EJBException(exe); 145 } 146 } 147 148 public void ejbRemove() {} 149 } 150 151 | Popular Tags |