KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > ProjectSoapBasicBean


1 package hero.session;
2 /*
3  *
4  * ProjectSoapBasicBean.java -
5  * Copyright (C) 2003 Ecoo Team
6  * valdes@loria.fr
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */

23
24 import hero.interfaces.BnEdgeLocal;
25 import hero.interfaces.BnNodeLocal;
26 import hero.interfaces.BnProjectLocal;
27 import hero.interfaces.BnProjectLocalHome;
28 import hero.interfaces.BnRoleLocal;
29 import hero.interfaces.BnUserLocal;
30 import hero.interfaces.BnUserLocalHome;
31 import hero.util.BonitaConfig;
32 import hero.util.EventConstants;
33 import hero.util.HeroException;
34
35 import hero.interfaces.JMSServicesSessionUtil;
36 import hero.interfaces.JMSServicesSessionLocalHome;
37 import hero.interfaces.JMSServicesSessionLocal;
38
39 import java.rmi.RemoteException JavaDoc;
40 import java.util.ArrayList JavaDoc;
41 import java.util.Collection JavaDoc;
42 import java.util.Date JavaDoc;
43
44 import java.util.Iterator JavaDoc;
45
46 import javax.ejb.CreateException JavaDoc;
47 import javax.ejb.FinderException JavaDoc;
48 import javax.ejb.SessionBean JavaDoc;
49 import javax.ejb.SessionContext JavaDoc;
50 import javax.ejb.EJBException JavaDoc;
51 import javax.naming.Context JavaDoc;
52
53 import java.util.Vector JavaDoc;
54
55 import org.apache.log4j.Category;
56
57 /**
58  * Session Bean Template
59  *
60  * @ejb:bean name="ProjectSoapBasic"
61  * display-name="ProjectSoapBasic Bean"
62  * type="Stateful"
63  * transaction-type="Container"
64  * jndi-name="ejb/hero/ProjectSoapBasic"
65  *
66  * @ejb:ejb-ref ejb-name="ProjectSoapBasic"
67  * view-type="remote"
68  * ref-name="ProjectSoapBasic"
69  *
70  * @ejb:ejb-ref ejb-name="BnProject"
71  * ref-name="myhero/BnProject"
72  *
73  * @ejb:transaction type="Supports"
74  * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
75  * @jonas.bean
76  * ejb-name="ProjectSoapBasic"
77  * jndi-name="ejb/hero/ProjectSoapBasic"
78  *
79  **/

80
81 public class ProjectSoapBasicBean implements SessionBean JavaDoc, EventConstants {
82     
83     // -------------------------------------------------------------------------
84
// Static
85
// -------------------------------------------------------------------------
86
// Utility variable
87
private static final Category trace = Category.getInstance(ProjectSessionBean.class);
88     
89     // -------------------------------------------------------------------------
90
// Members
91
// -------------------------------------------------------------------------
92

93     private SessionContext JavaDoc mContext;
94     private BnProjectLocalHome pHome;
95     private BnProjectLocal mProject;
96     private JMSServicesSessionLocal jms;
97     private Collection JavaDoc subProjects = new ArrayList JavaDoc();
98     private ArrayList JavaDoc visited = new ArrayList JavaDoc();
99     private BonitaConfig bonitaConfig;
100     
101     
102     // -------------------------------------------------------------------------
103
// Basic Get Methods
104
// -------------------------------------------------------------------------
105

106     /**
107      * Get ProjectName
108      * @return String
109      *
110      * @ejb:interface-method view-type="both"
111      * @ejb:transaction type="Supports"
112      *
113      **/

114     public String JavaDoc getName() throws HeroException {
115         if (this.getProjectConfigTrace())
116             trace.info(" process name = " + this.getName() +" started by " + mContext.getCallerPrincipal().getName());
117         return mProject.getName();
118     }
119     
120     /**
121      * Get creator
122      * @return String
123      *
124      * @ejb:interface-method view-type="both"
125      * @ejb:transaction type="Supports"
126      *
127      **/

128     public String JavaDoc getCreator() throws HeroException {
129         if (this.getProjectConfigTrace())
130             trace.info(" process name = " + this.getName() +" started by " + mContext.getCallerPrincipal().getName());
131         return mProject.getCreator();
132     }
133     
134     /**
135      * Get the node executor
136      *
137      * @param name of the node
138      * @return The user executor
139      * @ejb:interface-method view-type="both"
140      * @ejb:transaction type="Supports"
141      *
142      **/

143     public String JavaDoc getNodeExecutor(String JavaDoc name) throws HeroException {
144         
145         if (this.getProjectConfigTrace())
146             trace.info("parameter: name=" + name + "process name = " + this.getName()+ " started by " + mContext.getCallerPrincipal().getName());
147         BnNodeLocal nd=mProject.getBnNode(name);
148         return nd.getExecutor();
149     }
150     
151     /**
152      * Get Node State
153      *
154      * @param name of the node
155      * @return The state of the node
156      * @ejb:interface-method view-type="both"
157      * @ejb:transaction type="Supports"
158      *
159      **/

160     public int getNodeState(String JavaDoc name) throws HeroException {
161         if (this.getProjectConfigTrace())
162             trace.info("parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
163         BnNodeLocal nd = mProject.getBnNode(name);
164         int s = nd.getState();
165         return (s);
166     }
167     
168     /**
169      * Get all users of the project
170      * @return Object[]
171      *
172      * @ejb:interface-method view-type="both"
173      * @ejb:transaction type="Supports"
174      *
175      **/

176     public Object JavaDoc[] getUsers() throws HeroException {
177         if (this.getProjectConfigTrace())
178             trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName());
179         Collection JavaDoc users = mProject.getBnUsers();
180         ArrayList JavaDoc result=new ArrayList JavaDoc();
181         for (Iterator JavaDoc i=users.iterator();i.hasNext();) {
182             result.add(((BnUserLocal)i.next()).getName());
183         }
184         return result.toArray();
185     }
186     
187     /**
188      * Return all registered users
189      * @return Object[]
190      *
191      * @ejb:interface-method view-type="both"
192      * @ejb:transaction type="Supports"
193      *
194      **/

195     public Object JavaDoc[] getAllUsers() throws HeroException {
196         if (this.getProjectConfigTrace())
197             trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName());
198         BnUserLocalHome uHome;
199         Collection JavaDoc users;
200         try {
201             uHome = (BnUserLocalHome)hero.interfaces.BnUserUtil.getLocalHome();
202         } catch (javax.naming.NamingException JavaDoc be) {
203             throw new HeroException(be.getMessage());
204         }
205         try {
206             users=uHome.findAll();
207         } catch (FinderException JavaDoc f) {
208             throw new HeroException("FinderException in findByAll users");
209         }
210         ArrayList JavaDoc result=new ArrayList JavaDoc();
211         for (Iterator JavaDoc i=users.iterator();i.hasNext();) {
212             result.add(((BnUserLocal)i.next()).getName());
213         }
214         return result.toArray();
215     }
216     
217     /**
218      * Get all role names of the project
219      * @return Object[]
220      *
221      * @ejb:interface-method view-type="both
222      * @ejb:transaction type="Supports"
223      *
224      **/

225     public Object JavaDoc[] getRolesNames() throws HeroException {
226         if (this.getProjectConfigTrace())
227             trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName());
228         Collection JavaDoc roles = mProject.getBnRoles();
229         ArrayList JavaDoc result=new ArrayList JavaDoc();
230         for (Iterator JavaDoc i=roles.iterator();i.hasNext();) {
231             result.add(((BnRoleLocal)i.next()).getName());
232         }
233         return result.toArray();
234     }
235     
236     /**
237      * Get all node names of the project
238      *
239      * @return Object[]
240      * @ejb:interface-method view-type="both"
241      * @ejb:transaction type="Supports"
242      *
243      **/

244     public Object JavaDoc[] getNodesNames() throws HeroException {
245         if (this.getProjectConfigTrace())
246             trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName());
247         
248         Vector JavaDoc names = new Vector JavaDoc();
249         Collection JavaDoc nodes = mProject.getBnNodes();
250         Iterator JavaDoc i = nodes.iterator();
251         while (i.hasNext())
252         {
253             BnNodeLocal n = (BnNodeLocal)i.next();
254             names.add(n.getName());
255         }
256         return((Collection JavaDoc)names).toArray();
257     }
258     
259     /**
260      * Get all node of the project
261      * @return Object[]
262      *
263      * @ejb:interface-method view-type="both"
264      * @ejb:transaction type="Supports"
265      *
266      **/

267     public Object JavaDoc[] getNodes() throws HeroException {
268         if (this.getProjectConfigTrace())
269             trace.info("process name = " + this.getName()+ "started by " + mContext.getCallerPrincipal().getName());
270         Vector JavaDoc nodesDetails = new Vector JavaDoc();
271         Collection JavaDoc nodes = mProject.getBnNodes();
272         
273         Iterator JavaDoc i = nodes.iterator();
274         while (i.hasNext())
275         {
276             BnNodeLocal n = (BnNodeLocal)i.next();
277             String JavaDoc[] details = new String JavaDoc[5];
278             details[0]=n.getName();
279             details[1]=hero.interfaces.Constants.Nd.nodeStateName[n.getState()];
280             details[2]=((BnRoleLocal)n.getBnRole()).getName();
281             /* modif MBL
282             if (n.getDeadline()!=null)
283                 details[3]=n.getDeadline().toString();
284             */

285              if (n.getDeadlines().size() != 0) {
286                 Collection JavaDoc co = n.getDeadlines();
287                 Iterator JavaDoc it = co.iterator();
288                 Date JavaDoc date = null;
289                 while (it.hasNext()){
290                     date = (Date JavaDoc)it.next();
291                 }
292                 details[3]=date.toString();
293              }
294             else
295                 details[3]="null";
296             details[4]=(new Boolean JavaDoc(n.getAnticipable())).toString();
297             nodesDetails.add(details);
298         }
299         return((Collection JavaDoc)nodesDetails).toArray();
300     }
301     
302     /**
303      * Get all node information
304      * @return Object[]
305      *
306      * @ejb:interface-method view-type="both"
307      * @ejb:transaction type="Supports"
308      *
309      **/

310     
311     public Object JavaDoc[] getNodeDetails(String JavaDoc node) throws HeroException {
312         if (this.getProjectConfigTrace())
313             trace.info("parameter: node=" + node + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
314         BnNodeLocal nd=mProject.getBnNode(node);
315         Vector JavaDoc detail = new Vector JavaDoc();
316         
317         detail.add(nd.getName());
318         detail.add(mProject.getName());
319         detail.add(nd.getCreator());
320         detail.add(hero.interfaces.Constants.Nd.nodeStateName[nd.getState()]);
321         detail.add(((BnRoleLocal)nd.getBnRole()).getName());
322         if (nd.getExecutor()!=null)
323             detail.add(nd.getExecutor());
324         else
325             detail.add("null");
326         /*
327         if (nd.getDeadline()!=null)
328             detail.add(nd.getDeadline().toString());
329         */

330         if (nd.getDeadlines().size() != 0) {
331             Collection JavaDoc co = nd.getDeadlines();
332             Iterator JavaDoc it = co.iterator();
333             Date JavaDoc date = null;
334             while (it.hasNext()){
335                 date = (Date JavaDoc)it.next();
336             }
337             detail.add(date.toString());
338          }
339         
340         else detail.add("null");
341         
342         detail.add(new Boolean JavaDoc((nd.getAnticipable())).toString());
343         
344         if (nd.getDescription()!=null)
345             detail.add(nd.getDescription());
346         else detail.add("null");
347         
348         return(detail.toArray());
349     }
350     
351     /**
352      * Get user roles in project
353      * @return Object[]
354      *
355      * @param userName The name of the user
356      *
357      * @ejb:interface-method view-type="both"
358      * @ejb:transaction type="Supports"
359      *
360      **/

361     public Object JavaDoc[] getUserRolesInProjectNames(String JavaDoc userName) throws HeroException {
362         if (this.getProjectConfigTrace())
363             trace.info("parameter: userName=" + userName + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
364         BnUserLocalHome uHome;
365         BnUserLocal user;
366         ArrayList JavaDoc result=new ArrayList JavaDoc();
367         try {
368             uHome = (BnUserLocalHome)hero.interfaces.BnUserUtil.getLocalHome();
369         } catch (javax.naming.NamingException JavaDoc be) {
370             throw new HeroException(be.getMessage());
371         }
372         try {
373             user=uHome.findByName(userName);
374         } catch (FinderException JavaDoc f) {
375             throw new HeroException("FinderException");
376         }
377         Collection JavaDoc userRoles = user.getBnRoles();
378         Collection JavaDoc projectRoles=mProject.getBnRoles();
379         for(Iterator JavaDoc i=userRoles.iterator();i.hasNext();){
380             BnRoleLocal ur=(BnRoleLocal)i.next();
381             for(Iterator JavaDoc j=projectRoles.iterator();j.hasNext();){
382                 BnRoleLocal up=(BnRoleLocal)j.next();
383                 if(ur.getId()==up.getId())
384                     result.add(ur.getName());
385             }
386         }
387         return result.toArray();
388     }
389     
390     /**
391      * get all in edges of the node
392      * @return Object[]
393      *
394      * @param name the name ot the node
395      *
396      * @ejb:interface-method view-type="both"
397      * @ejb:transaction type="Supports"
398      *
399      **/

400     public Object JavaDoc[] getNodeInEdges(String JavaDoc name) throws HeroException {
401         if (this.getProjectConfigTrace())
402             trace.info("parameter: name=" + name + "process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
403         Vector JavaDoc in=new Vector JavaDoc();
404         BnNodeLocal nd=mProject.getBnNode(name);
405         
406         Collection JavaDoc edgesIn=nd.getInBnEdges();
407         Iterator JavaDoc i = edgesIn.iterator();
408         while (i.hasNext()){
409             BnEdgeLocal e = (BnEdgeLocal)i.next();
410             String JavaDoc[] details = new String JavaDoc[4];
411             details[0]=e.getName();
412             details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()];
413             BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode();
414             details[2]=nIn.getName();
415             BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode();
416             details[3]=nOut.getName();
417             in.add(details);
418         }
419         
420         return(in.toArray());
421     }
422     
423     /**
424      * Get all BnEdge of the project
425      * @return Object[]
426      *
427      * @ejb:interface-method view-type="both"
428      * @ejb:transaction type="Supports"
429      *
430      **/

431     public Object JavaDoc[] getEdges() throws HeroException {
432         if (this.getProjectConfigTrace())
433             trace.info("process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
434         Vector JavaDoc edgesDetails = new Vector JavaDoc();
435         Collection JavaDoc edges = mProject.getBnEdges();
436         Iterator JavaDoc i = edges.iterator();
437         while (i.hasNext())
438         {
439             BnEdgeLocal e = (BnEdgeLocal)i.next();
440             String JavaDoc[] details = new String JavaDoc[4];
441             details[0]=e.getName();
442             details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()];
443             BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode();
444             details[2]=nIn.getName();
445             BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode();
446             details[3]=nOut.getName();
447             edgesDetails.add(details);
448         }
449         return(edgesDetails.toArray());
450     }
451     
452     /**
453      * get all out edges of the node
454      * @return Object[]
455      *
456      * @param name the name ot the node
457      *
458      * @ejb:interface-method view-type="both"
459      * @ejb:transaction type="Supports"
460      *
461      **/

462     public Object JavaDoc[] getNodeOutEdges(String JavaDoc name) throws HeroException {
463         if (this.getProjectConfigTrace())
464             trace.info("parameter: name=" + name+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
465         
466         Vector JavaDoc out=new Vector JavaDoc();
467         BnNodeLocal nd=mProject.getBnNode(name);
468         
469         Collection JavaDoc edgesOut=nd.getOutBnEdges();
470         Iterator JavaDoc i = edgesOut.iterator();
471         while (i.hasNext()){
472             BnEdgeLocal e = (BnEdgeLocal)i.next();
473             String JavaDoc[] details = new String JavaDoc[4];
474             details[0]=e.getName();
475             details[1]=hero.interfaces.Constants.Ed.edgeStateName[e.getState()];
476             BnNodeLocal nIn = (BnNodeLocal)e.getInBnNode();
477             details[2]=nIn.getName();
478             BnNodeLocal nOut = (BnNodeLocal)e.getOutBnNode();
479             details[3]=nOut.getName();
480             out.add(details);
481         }
482         
483         return(out.toArray());
484     }
485     
486     /**
487      * Get the type of the node
488      *
489      * @param name of the node
490      * @return The type of the node
491      * @ejb:interface-method view-type="both"
492      * @ejb:transaction type="Supports"
493      *
494      **/

495     public int getNodeType(String JavaDoc name) throws HeroException {
496         if (this.getProjectConfigTrace())
497             trace.info("parameter: name=" + name+"process name = " + this.getName()+" started by " + mContext.getCallerPrincipal().getName());
498         BnNodeLocal nd = mProject.getBnNode(name);
499         return (nd.getType());
500     }
501     
502     // -------------------------------------------------------------------------
503
// ejbCreate and initProject business methods
504
// -------------------------------------------------------------------------
505

506     /**
507      * Init the Project Session Bean. You have to call this method after "create" call. After that
508      * all methods of ProjectSession API are available.
509      *
510      * @param projectName project name
511      * @ejb:interface-method view-type="both"
512      * @ejb:transaction type="Required"
513      * @throws HeroException
514      **/

515     public void initProject(String JavaDoc projectName) throws HeroException {
516         Context JavaDoc lContext;
517         if (this.getProjectConfigTrace())
518             trace.info("parameter: projectName=" + projectName+" started by " + mContext.getCallerPrincipal().getName());
519         try {
520             pHome = hero.interfaces.BnProjectUtil.getLocalHome();
521             this.mProject = pHome.findByName(projectName);
522         } catch (javax.naming.NamingException JavaDoc ne) {
523             throw new HeroException(ne.getMessage());
524         } catch (javax.ejb.FinderException JavaDoc fe) {
525             throw new HeroException(fe.getMessage());
526         }
527     }
528     
529     private boolean getProjectConfigTrace() throws HeroException{
530         if (this.getName()!=null)
531             return (bonitaConfig.getProcessTrace(this.getName()));
532         else
533             return true;
534     }
535     
536     
537     /**
538      * Creates the Project Session Bean. This method is the first one to invoke in order to
539      * use ProjectSession API. If the user is not authorized this method throws an exception.
540      *
541      * @throws CreateException
542      *
543      * @ejb:create-method view-type="both"
544      **/

545     public void ejbCreate() throws CreateException JavaDoc {
546     }
547     
548     /**
549      * Internal Enterprise Java Beans method.
550      **/

551     public void ejbPostCreate(String JavaDoc oldProject, String JavaDoc newProject)
552     throws CreateException JavaDoc, RemoteException JavaDoc {
553     }
554     
555     /**
556      * Internal Enterprise Java Beans method.
557      **/

558     public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
559         mContext = context;
560         try{
561             JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
562             this.jms=home.create();
563             this.bonitaConfig = new BonitaConfig();
564         }catch(Exception JavaDoc e){throw new EJBException JavaDoc(e.getMessage());}
565     }
566     
567     /**
568      * Internal Enterprise Java Beans method.
569      **/

570     
571     public void ejbRemove() {
572     }
573     
574     /**
575      * Internal Enterprise Java Beans method.
576      **/

577     
578     public void ejbActivate() {
579     }
580     
581     /**
582      * Internal Enterprise Java Beans method.
583      **/

584     
585     public void ejbPassivate() {
586     }
587 }
588
Popular Tags