KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > AdminSessionBean


1 package hero.session;
2
3 /**
4  *
5  * Bonita
6  * Copyright (C) 1999 Bull S.A.
7  * Bull 68 route de versailles 78434 Louveciennes Cedex France
8  * Further information: bonita@objectweb.org
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along wit this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  *
26 --------------------------------------------------------------------------
27  * $Id: AdminSessionBean.java,v 1.7 2005/03/23 09:06:43 mvaldes Exp $
28  *
29 --------------------------------------------------------------------------
30  */

31 import hero.interfaces.BnProjectLocal;
32 import hero.interfaces.BnProjectLocalHome;
33 import hero.interfaces.BnNodeLocalHome;
34 import hero.interfaces.BnNodeLocal;
35 import hero.interfaces.Constants;
36 import hero.util.EventConstants;
37 import hero.util.HeroException;
38
39 import java.util.ArrayList JavaDoc;
40 import java.util.Collection JavaDoc;
41 import java.util.Iterator JavaDoc;
42
43 import javax.ejb.CreateException JavaDoc;
44 import javax.ejb.SessionBean JavaDoc;
45 import javax.ejb.SessionContext JavaDoc;
46
47 import org.apache.log4j.Logger;
48
49
50 /**
51 *
52 * The Admin Session Bean, is an stateful session bean that provides the admin API to get information about
53 * projects and activities in which the user is admin.<br><br>
54 * <strong>The following lines shows a sample code to use this API in your application:<br><br></strong>
55 * <br>
56 * First of all you have to import the Admin Session files:<br>
57 * <br>
58 * import hero.interfaces.AdminSessionLocalHome;<br>
59 * import hero.interfaces.AdminSessionLocal;<br>
60 * import hero.interfaces.AdminSessionHome;<br>
61 * import hero.interfaces.AdminSession;<br>
62 * import hero.interfaces.AdminSessionUtil;<br>
63 * <br>
64 * Now, it is time to create the Admin Session instance:<br>
65 * <br>
66 * Like this if you want to use local interfaces:<br><br>
67 * AdminSessionLocalHome adminh = (AdminSessionLocalHome)hero.interfaces.AdminSessionUtil.getLocalHome();<br>
68 * AdminSessionLocal adminsession = adminh.create();<br>
69 * <br>
70 * or like this if you use remote interfaces:<br>
71 * <br>
72 * AdminSessionHome adminh = (AdminSessionHome)hero.interfaces.AdminSessionUtil.getHome();<br>
73 * AdminSession adminsession = adminh.create();<br>
74 * <br>
75 * <br>
76 * Now you can call all Admin Sessions methods...
77 *
78  *
79  * @ejb:bean name="AdminSession"
80  * display-name="AdminSession Bean"
81  * type="Stateless"
82  * transaction-type="Container"
83  * jndi-name="ejb/hero/AdminSession"
84  * local-jndi-name="ejb/hero/AdminSession_L"
85  *
86  * @ejb:ejb-ref ejb-name="BnProject"
87  * ref-name="myhero/BnProject"
88  * @ejb:transaction type="Supports"
89  * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
90  * @jonas.bean
91  * ejb-name="AdminSession"
92  * jndi-name="ejb/hero/AdminSession"
93  *
94  *
95  **/

96
97 public class AdminSessionBean implements SessionBean JavaDoc, EventConstants {
98
99
100    // -------------------------------------------------------------------------
101
// Static
102
// -------------------------------------------------------------------------
103
// Utility variable
104
private static final Logger trace = Logger.getLogger(AdminSessionBean.class);
105    
106    // -------------------------------------------------------------------------
107
// Members
108
// -------------------------------------------------------------------------
109

110    private SessionContext JavaDoc mContext;
111   
112    // -------------------------------------------------------------------------
113
// Methods
114
// -------------------------------------------------------------------------
115

116    /**
117     * Get admin workflow models (admin is the role of the model administrator)
118     *
119     * @ejb:interface-method view-type="both"
120     * @ejb:transaction type="Supports"
121     *
122    **/

123        public Collection JavaDoc getModels() throws HeroException {
124        trace.info("start by " + mContext.getCallerPrincipal().getName());
125         Collection JavaDoc result = new ArrayList JavaDoc();
126         BnProjectLocalHome projhome;
127         try {
128             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
129             Collection JavaDoc models =projhome.findByAdmin(mContext.getCallerPrincipal().getName(), Constants.ADMIN, Constants.Pj.MODEL);
130             Iterator JavaDoc mdls = models.iterator();
131             while (mdls.hasNext())
132             {
133                 BnProjectLocal pj = (BnProjectLocal)mdls.next();
134                 result.add(pj.getBnProjectLightValue());
135             }
136             return result;
137         } catch (javax.naming.NamingException JavaDoc ne) {
138             trace.error(ne.getMessage());
139             throw new HeroException(ne.getMessage());
140         } catch (javax.ejb.FinderException JavaDoc fe) {
141             trace.error(fe.getMessage());
142             throw new HeroException(fe.getMessage());
143         }
144        }
145        
146    /**
147     * Get instances list for models in which this user is admin (admin is the role of the model administrator)
148     *
149     * @ejb:interface-method view-type="both"
150     * @ejb:transaction type="Supports"
151     *
152    **/

153        public Collection JavaDoc getInstances() throws HeroException {
154        trace.info("start by " + mContext.getCallerPrincipal().getName());
155         BnProjectLocalHome projhome;
156         Collection JavaDoc result = new ArrayList JavaDoc();
157         try {
158             projhome = hero.interfaces.BnProjectUtil.getLocalHome();
159             Collection JavaDoc instances =projhome.findByAdmin(mContext.getCallerPrincipal().getName(), Constants.ADMIN, Constants.Pj.INSTANCE);
160             Iterator JavaDoc inst = instances.iterator();
161             while (inst.hasNext())
162             {
163                 BnProjectLocal pj = (BnProjectLocal)inst.next();
164                 result.add(pj.getBnProjectLightValue());
165             }
166             return result;
167         } catch (javax.naming.NamingException JavaDoc ne) {
168             trace.error(ne.getMessage());
169             throw new HeroException(ne.getMessage());
170         } catch (javax.ejb.FinderException JavaDoc fe) {
171             trace.error(fe.getMessage());
172             throw new HeroException(fe.getMessage());
173         }
174        }
175        
176    /**
177     * Get activities for instances/cooperatives projects in which this user is admin (admin is the role of the model administrator)
178     *
179     * @ejb:interface-method view-type="both"
180     * @ejb:transaction type="Supports"
181     *
182    **/

183        public Collection JavaDoc getActivities() throws HeroException {
184        trace.info("start by " + mContext.getCallerPrincipal().getName());
185         BnNodeLocalHome nodehome;
186         Collection JavaDoc result = new ArrayList JavaDoc();
187         try {
188             nodehome = hero.interfaces.BnNodeUtil.getLocalHome();
189             Collection JavaDoc activities = nodehome.findAdminActivities(mContext.getCallerPrincipal().getName(), Constants.ADMIN, Constants.Pj.INSTANCE, Constants.Pj.COOPERATIVE);
190             Iterator JavaDoc act = activities.iterator();
191             while (act.hasNext())
192             {
193                 BnNodeLocal nd = (BnNodeLocal)act.next();
194                 result.add(nd.getBnNodeValue());
195             }
196             return result;
197         } catch (javax.naming.NamingException JavaDoc ne) {
198             trace.error(ne.getMessage());
199             throw new HeroException(ne.getMessage());
200         } catch (javax.ejb.FinderException JavaDoc fe) {
201             trace.error(fe.getMessage());
202             throw new HeroException(fe.getMessage());
203         }
204       }
205        
206    /**
207    * Create the AdminSession Bean
208    *
209    * @throws CreateException
210    *
211    * @ejb.permission unchecked="yes"
212    * @ejb:create-method view-type="both"
213    **/

214
215     public void ejbCreate() throws CreateException JavaDoc {
216     trace.debug("ejbCreate");
217     }
218     
219     public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
220     mContext = context;
221     }
222     
223     public void ejbRemove() {
224     }
225     
226     public void ejbActivate() {
227     }
228     
229     public void ejbPassivate() {
230     }
231     
232 }
233
Popular Tags