KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > processmanager > ejb > ProcessManagerBean


1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Sun Microsystems, Inc. or the names of
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * This software is provided "AS IS," without a warranty of any
21 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
22 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
24 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
25 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
26 * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
27 * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
28 * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
29 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
30 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
31 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * You acknowledge that Software is not designed, licensed or intended
34 * for use in the design, construction, operation or maintenance of
35 * any nuclear facility.
36 */

37
38 package com.sun.j2ee.blueprints.processmanager.ejb;
39
40 import java.util.Collection JavaDoc;
41
42 import javax.naming.InitialContext JavaDoc;
43 import javax.naming.NamingException JavaDoc;
44 import javax.ejb.SessionBean JavaDoc;
45 import javax.ejb.SessionContext JavaDoc;
46 import javax.ejb.EJBException JavaDoc;
47 import javax.ejb.FinderException JavaDoc;
48 import javax.ejb.CreateException JavaDoc;
49 import javax.ejb.RemoveException JavaDoc;
50 import javax.ejb.DuplicateKeyException JavaDoc;
51
52 import com.sun.j2ee.blueprints.processmanager.manager.ejb.ManagerLocal;
53 import com.sun.j2ee.blueprints.processmanager.manager.ejb.ManagerLocalHome;
54
55 import com.sun.j2ee.blueprints.servicelocator.*;
56 import com.sun.j2ee.blueprints.servicelocator.ejb.*;
57
58 public class ProcessManagerBean implements SessionBean JavaDoc {
59     
60     public static final String JavaDoc MANAGER_HOME_ENV_NAME =
61         "java:comp/env/ejb/local/processmanager/Manager";
62     
63     private ManagerLocalHome mlh;
64    
65     /**
66      * Business method used for when new purchase orders are recieved
67      * and want to start the workflow process to fullfil the order
68      */

69     public void createManager(String JavaDoc orderId, String JavaDoc status,
70             String JavaDoc actyOrderStatus,
71             String JavaDoc airlineOrderStatus,
72             String JavaDoc lodgOrderStatus)
73                                        throws CreateException JavaDoc {
74   ManagerLocal manager = mlh.create(orderId, status, actyOrderStatus,
75             airlineOrderStatus, lodgOrderStatus,
76             false);
77     }
78
79     /**
80      * Business methods used to keep track of an order in the workflow process
81      */

82
83     public void updateStatus(String JavaDoc orderId, String JavaDoc status)
84   throws FinderException JavaDoc {
85   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
86   manager.setStatus(status);
87     }
88
89     public void updateOrderErrorStatus(String JavaDoc orderId, boolean error)
90   throws FinderException JavaDoc {
91   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
92   manager.setOrderError(error);
93     }
94
95     public void updateActivityOrderStatus(String JavaDoc orderId, String JavaDoc status)
96   throws FinderException JavaDoc {
97   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
98   manager.setActivityOrderStatus(status);
99     }
100
101     public void updateAirlineOrderStatus(String JavaDoc orderId, String JavaDoc status)
102   throws FinderException JavaDoc {
103   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
104   manager.setAirlineOrderStatus(status);
105     }
106     
107     public void updateLodgingOrderStatus(String JavaDoc orderId, String JavaDoc status)
108   throws FinderException JavaDoc {
109   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
110   manager.setLodgingOrderStatus(status);
111     }
112
113     public void updateStatusToCompleted(String JavaDoc orderId) throws FinderException JavaDoc{
114       //change the order status to completed if all the three suborders
115
//are completed
116

117   if ( (getActivityOrderStatus(orderId).equalsIgnoreCase(OrderStatusNames.COMPLETED)) &&
118        (getAirlineOrderStatus(orderId).equalsIgnoreCase(OrderStatusNames.COMPLETED)) &&
119        (getLodgingOrderStatus(orderId).equalsIgnoreCase(OrderStatusNames.COMPLETED))) {
120          ManagerLocal manager = mlh.findByPrimaryKey(orderId);
121          manager.setStatus("COMPLETED");
122         }
123     }
124
125
126     /**
127      * Business methods used to keep track of an order in the workflow process
128      */

129     public String JavaDoc getOrderStatus(String JavaDoc orderId) throws FinderException JavaDoc {
130   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
131   return manager.getStatus();
132     }
133
134     private String JavaDoc getActivityOrderStatus(String JavaDoc orderId)
135   throws FinderException JavaDoc {
136   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
137   return manager.getActivityOrderStatus();
138     }
139
140     private String JavaDoc getAirlineOrderStatus(String JavaDoc orderId)
141   throws FinderException JavaDoc {
142   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
143   return manager.getAirlineOrderStatus();
144     }
145
146     private String JavaDoc getLodgingOrderStatus(String JavaDoc orderId)
147   throws FinderException JavaDoc {
148   ManagerLocal manager = mlh.findByPrimaryKey(orderId);
149   return manager.getLodgingOrderStatus();
150     }
151
152
153
154     /**
155      * Business method to get all orders of given status for the admin
156      */

157     public Collection JavaDoc getOrdersByStatus (String JavaDoc status) throws FinderException JavaDoc {
158         return mlh.findOrdersByStatus(status);
159     }
160
161     public void ejbCreate() throws CreateException JavaDoc {
162   try {
163       ServiceLocator sl = new ServiceLocator();
164       mlh = (ManagerLocalHome) sl.getLocalHome(MANAGER_HOME_ENV_NAME);
165   } catch (ServiceLocatorException se) {
166       throw new EJBException JavaDoc("Got service locator exception! " +
167            se.getMessage());
168   }
169     }
170     
171     // Misc Method
172
//=============
173
//activate is empty for stateless session EJBs
174
public void ejbActivate() { }
175
176     //passivate is empty for stateless session EJBs
177
public void ejbPassivate() { }
178  
179     public void setSessionContext(SessionContext JavaDoc c) { }
180     public void ejbRemove() { }
181
182 }
183
Popular Tags