KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > ProjectSessionBean


1 package hero.session;
2 /*
3 * 02/01/2002 - 15:24:07
4 *
5 * ProjectSessionEJB.java -
6 * Copyright (C) 2002 Ecoo Team
7 * valdes@loria.fr
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.entity.EdgeState;
25 import hero.entity.NodeState;
26 import hero.interfaces.BnAgentEdgeLocal;
27 import hero.interfaces.BnAgentEdgeLocalHome;
28 import hero.interfaces.BnAgentEdgeValue;
29 import hero.interfaces.BnAgentLocal;
30 import hero.interfaces.BnAgentLocalHome;
31 import hero.interfaces.BnAgentValue;
32 import hero.interfaces.BnEdgeLocal;
33 import hero.interfaces.BnEdgeLocalHome;
34 import hero.interfaces.BnEdgeUtil;
35 import hero.interfaces.BnEdgeValue;
36 import hero.interfaces.BnNodeHookLocal;
37 import hero.interfaces.BnNodeHookLocalHome;
38 import hero.interfaces.BnNodeHookUtil;
39 import hero.interfaces.BnNodeInterHookLocal;
40 import hero.interfaces.BnNodeInterHookValue;
41 import hero.interfaces.BnNodeInterHookLocalHome;
42 import hero.interfaces.BnNodeInterHookUtil;
43 import hero.interfaces.BnNodeLightValue;
44 import hero.interfaces.BnNodeLocal;
45 import hero.interfaces.BnNodeLocalHome;
46 import hero.interfaces.BnNodePropertyLocal;
47 import hero.interfaces.BnNodePropertyValue;
48 import hero.interfaces.BnNodePropertyLocalHome;
49 import hero.interfaces.BnNodePropertyUtil;
50 import hero.interfaces.BnNodeUtil;
51 import hero.interfaces.BnNodeValue;
52 import hero.interfaces.BnIterationLocal;
53 import hero.interfaces.BnIterationLocalHome;
54 import hero.interfaces.BnIterationUtil;
55 import hero.interfaces.BnIterationLightValue;
56 import hero.interfaces.BnProjectHookLocal;
57 import hero.interfaces.BnProjectHookLocalHome;
58 import hero.interfaces.BnProjectHookUtil;
59 import hero.interfaces.BnProjectInterHookLocal;
60 import hero.interfaces.BnProjectInterHookLocalHome;
61 import hero.interfaces.BnProjectInterHookUtil;
62 import hero.interfaces.BnProjectLocal;
63 import hero.interfaces.BnProjectLocalHome;
64 import hero.interfaces.BnProjectPropertyLocal;
65 import hero.interfaces.BnProjectPropertyLocalHome;
66 import hero.interfaces.BnProjectPropertyUtil;
67 import hero.interfaces.BnProjectPropertyValue;
68 import hero.interfaces.BnProjectValue;
69 import hero.interfaces.BnProjectConfigLocalHome;
70 import hero.interfaces.BnRoleLocal;
71 import hero.interfaces.BnRoleLocalHome;
72 import hero.interfaces.BnRoleUtil;
73 import hero.interfaces.BnRoleValue;
74 import hero.interfaces.BnUserLightValue;
75 import hero.interfaces.BnUserLocal;
76 import hero.interfaces.BnUserLocalHome;
77 import hero.interfaces.BnUserUtil;
78 import hero.interfaces.EngineLocal;
79 import hero.interfaces.EngineLocalHome;
80 import hero.interfaces.InvalidValueException;
81 import hero.interfaces.Constants;
82 import hero.interfaces.ProjectSessionLocal;
83
84 import hero.interfaces.UserServiceLocal;
85 import hero.interfaces.UserServiceLocalHome;
86
87 import hero.util.BonitaConfig;
88 import hero.util.BonitaDeadline;
89 import hero.util.BonitaProjectLocator;
90 import hero.util.BonitaServiceException;
91 import hero.util.DeleteEdgeException;
92 import hero.util.EventConstants;
93 import hero.util.HeroException;
94 import hero.util.AdminException;
95 import hero.util.HiddenException;
96 import hero.util.AccessException;
97 import hero.util.NodeExecutingException;
98 import hero.util.StrutsEdgeValue;
99 import hero.util.StrutsNodeValue;
100 import hero.util.values.BonitaEdgeValue;
101 import hero.util.values.BonitaIterationValue;
102 import hero.util.values.BonitaNodeValue;
103 import hero.util.values.BonitaProjectValue;
104 import hero.util.values.BonitaPropertyValue;
105 import hero.util.values.BonitaRoleValue;
106 import hero.util.values.BonitaUserValue;
107 import hero.interfaces.JMSServicesSessionUtil;
108 import hero.interfaces.JMSServicesSessionLocalHome;
109 import hero.interfaces.JMSServicesSessionLocal;
110
111 import hero.interfaces.BnRoleMapperLocal;
112 import hero.interfaces.BnRoleMapperLocalHome;
113 import hero.interfaces.BnRoleMapperUtil;
114
115 import hero.interfaces.BnNodePerformerAssignLocal;
116 import hero.interfaces.BnNodePerformerAssignLocalHome;
117 import hero.interfaces.BnNodePerformerAssignUtil;
118 import hero.interfaces.BnNodePerformerAssignValue;
119
120 import java.rmi.RemoteException JavaDoc;
121 import java.util.ArrayList JavaDoc;
122
123 import java.util.Collection JavaDoc;
124 import java.util.Date JavaDoc;
125 import java.util.Iterator JavaDoc;
126 import java.util.Map JavaDoc;
127
128 import javax.ejb.CreateException JavaDoc;
129 import javax.ejb.FinderException JavaDoc;
130 import javax.ejb.RemoveException JavaDoc;
131 import javax.ejb.SessionBean JavaDoc;
132 import javax.ejb.SessionContext JavaDoc;
133 import javax.ejb.EJBException JavaDoc;
134 import javax.naming.Context JavaDoc;
135
136 import org.apache.log4j.Logger;
137 import org.apache.log4j.Level;
138
139 /**
140  *
141  * Project Session Bean is an stateful session bean that provides the interface for workflow process
142  * definition. By means of this API we can create workflow processes, project activities, transitions between activities ,
143  * users and roles, properties, hooks, external agents...<br><br>
144  *
145  * A Bonita Workflow process is composed by the activities (nodes) and the connections between these
146  * activities (edges). For each project, the administrator/s set the list of responsibles to execute these
147  * activites (users and roles). In the same way, the Project Session Bean API offers a great number of
148  * functionalities for working with activities behaviors (hooks) and workflow relevant data (properties).<br><br>
149  *
150  * This API can be used on different contexts depending on the needs of your application, so you can instantiate
151  * an existing project in order to perform set, get, update and remove operations, you can create a new workflow
152  * project (by instantiating a project that does not exists), you can clone an existing project or creates a
153  * new workflow instante of a project.
154  *
155  * <strong>The following lines shows a sample code to use this API in your application:<br><br></strong>
156  * <br>
157  * First of all you have to import the Project Session files:<br>
158  * <br>
159  * import hero.interfaces.ProjectSessionLocalHome;<br>
160  * import hero.interfaces.ProjectSessionLocal;<br>
161  * import hero.interfaces.ProjectSessionHome;<br>
162  * import hero.interfaces.ProjectSession;<br>
163  * import hero.interfaces.ProjectSessionUtil;<br>
164  * <br>
165  * Now, it is time to create the Project Session instance:<br>
166  * <br>
167  * Like this if you want to use local interfaces:<br><br>
168  * ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome();<br>
169  * ProjectSessionLocal projectsession = projecth.create();<br>
170  * <br>
171  * or like this if you use remote interfaces:<br>
172  * <br>
173  * ProjectSessionHome userh = (ProjectSessionHome)hero.interfaces.ProjectSessionUtil.getHome();<br>
174  * ProjectSession projectsession = projecth.create();<br>
175  * <br>
176  * <br>
177  * - If you want to use Project Session API for a specific project, you have to init this project.<br><br>
178  * Depending of the workflow process type you want, use:<br><br>
179  *
180  * projectsession.initProject("yourProject"); // for cooperative projects<br>
181  * <br>or<br>
182  * projectsession.initModel("yourProject"); // for workflow models<br>
183  * <br>
184  * - In order to clone an existing project, you have to call the initProject method:<br><br>
185  * projectsession.initProject("Project","CloneProject");<br><br>
186  *
187  * - If you want to instantiate a project, you have to do the following:<br><br>
188  * projectsession.instantiateProject("Project");<br><br>
189  *
190  * Now you can use Project Session methods...
191  *
192  *
193  * @ejb:bean name="ProjectSession"
194  * display-name="ProjectSession Bean"
195  * type="Stateful"
196  * transaction-type="Container"
197  * jndi-name="ejb/hero/ProjectSession"
198  * local-jndi-name="ejb/hero/ProjectSession_L"
199  * reentrant="true"
200  *
201  * @ejb:ejb-ref ejb-name="ProjectSession"
202  * view-type="remote"
203  * ref-name="ProjectSession"
204  *
205  * @ejb:ejb-ref ejb-name="BnProject"
206  * ref-name="myhero/BnProject"
207  * @ejb:transaction type="Supports"
208  *
209  * @ejb.permission role-name="BONITAUSER,user,SuperAdmin"
210  * @jonas.bean
211  * ejb-name="ProjectSession"
212  * jndi-name="ejb/hero/ProjectSession"
213  *
214  *
215  * @copyright INRIA
216  * @author Miguel Valdes
217  *
218  **/

219
220 public class ProjectSessionBean implements SessionBean JavaDoc, EventConstants{
221
222     // -------------------------------------------------------------------------
223
// Static
224
// -------------------------------------------------------------------------
225
// Utility variable
226
private static final Logger trace = Logger.getLogger(ProjectSessionBean.class);
227     private static final Logger thelog = Logger.getLogger("log");
228
229     // -------------------------------------------------------------------------
230
// Members
231
// -------------------------------------------------------------------------
232

233     private SessionContext JavaDoc mContext;
234     
235     private BnProjectLocalHome pHome;
236     private BnProjectLocal mProject=null;
237     private Collection JavaDoc subProjects = new ArrayList JavaDoc();
238     private JMSServicesSessionLocal jms = null;
239     private ArrayList JavaDoc visited = new ArrayList JavaDoc();
240     private String JavaDoc caller=null;
241     private BonitaConfig bonitaConfig;
242     
243     // -------------------------------------------------------------------------
244
// Methods
245
// -------------------------------------------------------------------------
246

247     // -------------------------------------------------------------------------
248
// Add business methods
249
// -------------------------------------------------------------------------
250

251     /**
252      * Add a user to this project (This user must exist at bonita database)
253      *
254      * @param userName The name of the user to associate to the project
255      *
256      * @ejb:interface-method view-type="both"
257      * @ejb:transaction type="Required"
258      * @throws HeroException
259      *
260      **/

261     public void addUser(String JavaDoc userName) throws HeroException {
262         if (this.getProjectConfigTrace())
263             trace.info(" Parameter: name=" + userName + " process name = "+this.getName()+ " started by " + this.getCaller());
264         UserServiceLocalHome ushome;
265         UserServiceLocal ul;
266         if (!isAdminOfProject(this.getCaller()))
267         {
268             if (this.getProjectConfigTrace())
269                 trace.error("Only the Admin of the project is allowed to do this operation... ");
270             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
271         }
272         BnUserLocalHome uHome;
273         BnRoleLocalHome rHome;
274         BnRoleLocal mRole;
275         BnUserLocal mUser;
276         try {
277             ushome = hero.interfaces.UserServiceUtil.getLocalHome();
278             uHome = hero.interfaces.BnUserUtil.getLocalHome();
279             rHome = hero.interfaces.BnRoleUtil.getLocalHome();
280         } catch (javax.naming.NamingException JavaDoc be) {
281             if (this.getProjectConfigTrace())
282                 trace.error(be.getMessage());
283             throw new HeroException(be.getMessage());
284         }
285         try {
286             ul = ushome.create();
287             mUser = ul.findUser(userName);
288         } catch (Exception JavaDoc fe) {
289             if (this.getProjectConfigTrace())
290                 trace.error("User does not exist " + fe.getMessage());
291             throw new HeroException("User does not exist");
292         }
293         Collection JavaDoc cUsers = mProject.getBnUsers();
294         if (!cUsers.contains(mUser))
295         {
296             cUsers.add(mUser);
297             if (!userName.equals(Constants.ADMIN))
298                 this.addRole(userName, "BnUser BnRole");
299             this.setUserRole(userName, userName);
300             jms.sendProjectEvent(ADDUSERPROJECT,this.getName(),userName);
301         }
302     }
303     
304     /**
305      * Add a node to the project. This method creates a node with the corresponding
306      * node type and assign to it the hero.interfaces.Constants.InitialRole role.<br><br>
307      *
308      * Possible node types are:<br>
309      * <br>
310      * hero.interfaces.Constants.Nd.AND_JOIN_NODE // Manual and join node <br>
311      * hero.interfaces.Constants.Nd.OR_JOIN_NODE // Manual or join node <br>
312      * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE // Automatic and join node <br>
313      * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE // Automatic or join node <br>
314      *
315      * @param name The name of the node to add to the project
316      * @param nodeType The type of the node to add to the project
317      *
318      * @ejb:interface-method view-type="both"
319      * @ejb:transaction type="Required"
320      * @throws HeroException
321      *
322      **/

323     
324     public void addNode(String JavaDoc name, int nodeType) throws HeroException {
325         if (this.getProjectConfigTrace())
326             trace.info("parameter: name= " + name + " nodeType= " + name + " process name = "+this.getName()+ " started by " + this.getCaller());
327         BnNodeLocalHome nHome;
328         BnNodeLocal mNode;
329         if (!isAdminOfProject(this.getCaller()))
330         {
331             if (this.getProjectConfigTrace())
332                 trace.error("Only the Admin of the project is allowed to do this operation... ");
333             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
334         }
335
336         try {
337             nHome = hero.interfaces.BnNodeUtil.getLocalHome();
338         } catch (javax.naming.NamingException JavaDoc be) {
339             if (this.getProjectConfigTrace())
340                 trace.error(be.getMessage());
341             throw new HeroException(be.getMessage());
342         }
343         
344         try {
345             BnNodeLocal nf = nHome.findByName(name, mProject.getId());
346             throw new HeroException("Node "+ name+ " already exist in project "+ mProject.getName());
347         } catch (javax.ejb.FinderException JavaDoc nn) {
348             if (this.getProjectConfigTrace())
349                 if (this.getProjectConfigTrace())
350                     trace.error(nn.getMessage());
351             try {
352                 if (name.equals(""))
353                     throw new HeroException("Node name can not be empty...");
354                 BnNodeLocal nd = nHome.create(name, nodeType);
355                 // Models are not executable
356
if (mProject.getType().equals(Constants.Pj.MODEL))
357                     nd.setState(Constants.Nd.INITIAL);
358                 BnNodeValue ndata = nd.getBnNodeValue();
359                 ndata.setCreationDate(new java.util.Date JavaDoc());
360                 nd.setBnNodeValue(ndata);
361                 
362                 Collection JavaDoc cNodes = mProject.getBnNodes();
363                 cNodes.add(nd);
364                 //nd.setBnProject(mProject);
365

366                 String JavaDoc creator = this.getCaller();
367                 nd.setCreator(creator);
368                 nd.setExecutor(creator); // Only for JOnAS consistency
369
BnRoleLocalHome rHome = BnRoleUtil.getLocalHome();
370                 BnRoleLocal role = rHome.findByName(hero.interfaces.Constants.INITIALROLE,mProject.getId());
371                 nd.setBnRole(role);
372                             
373                 if (nodeType == Constants.Nd.SUB_PROCESS_NODE)
374                 {
375                     try {
376                             BnProjectLocal pl = pHome.findByName(name);
377                             pl.setParent(mProject.getName());
378                     } catch (javax.ejb.FinderException JavaDoc pe) {
379                         if (this.getProjectConfigTrace())
380                             trace.error("Project "+ name+ " does not exist " + pe.getMessage());
381                         throw new HeroException("Project "+ name+ " does not exist");}
382                 }
383                 
384                 // Tell the world
385
jms.sendNodeEvent(ADDNODE,this.getName(),name,nodeType,ndata.getState(),this.getCaller());
386             } catch (InvalidValueException ie) {
387                 if (this.getProjectConfigTrace())
388                     trace.error(ie.getMessage());
389                 throw new HeroException(ie.getMessage());
390             } catch (CreateException JavaDoc ce) {
391                 if (this.getProjectConfigTrace())
392                     trace.error(ce.getMessage());
393                 throw new HeroException(ce.getMessage());
394             } catch (FinderException JavaDoc fe) {fe.printStackTrace();
395                 if (this.getProjectConfigTrace())
396                     trace.error(fe.getMessage());
397                 throw new HeroException(fe.getMessage());
398             } catch (javax.naming.NamingException JavaDoc ne) {
399                 if (this.getProjectConfigTrace())
400                     trace.error(ne.getMessage());
401                 throw new HeroException(ne.getMessage());
402             }
403         }
404     }
405     
406     /**
407      * Add a subProcess node to the project. This method creates the subProject from an existing
408      * project and creates the node associated to it. The type of created node is
409      * hero.interfaces.Constants.Nd.SUB_PROCESS_NODE
410      *
411      * @param name The name of the node to add to the project
412      * @param projectName the name of the subProcess
413      *
414      * @ejb:interface-method view-type="both"
415      * @ejb:transaction type="Required"
416      * @throws HeroException
417      *
418      **/

419     
420     public void addNodeSubProcess(String JavaDoc name, String JavaDoc projectName) throws HeroException {
421         if (this.getProjectConfigTrace())
422             trace.info("parameters : name=" + name + "project=" + projectName + " process name = " + this.getName()+ " started by " + this.getCaller());
423         if (!isAdminOfProject(this.getCaller()))
424         {
425             if (this.getProjectConfigTrace())
426                 trace.error("Only the Admin of the project is allowed to do this operation... ");
427             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
428         }
429         try{
430             String JavaDoc aP = mProject.getName();
431             this.initProject(projectName,name);
432             Collection JavaDoc nodes = mProject.getBnNodes();
433             Iterator JavaDoc nds = nodes.iterator();
434             while (nds.hasNext()) // first activity will be initial
435
{
436                 BnNodeLocal subNode = (BnNodeLocal)nds.next();
437                 if (subNode.getState()==Constants.Nd.READY)
438                     this.setNodeState(subNode,Constants.Nd.INITIAL);
439             }
440             if (mProject.getType().equals(Constants.Pj.MODEL))
441                 this.initModel(aP);
442             else
443                 this.initProject(aP);
444             this.addNode(name,Constants.Nd.SUB_PROCESS_NODE);
445             subProjects.clear();
446         }catch (Exception JavaDoc ans){
447             if (this.getProjectConfigTrace())
448                 trace.error("Error in addNodeSubProcess " + ans.getMessage());
449             throw new HeroException("Error in addNodeSubProcess");
450         }
451     }
452     
453     /**
454      * Add an Agent to the Project
455      *
456      * @param name The name of the Agent to add to the project
457      *
458      * @ejb:interface-method view-type="both"
459      * @ejb:transaction type="Required"
460      * @throws HeroException
461      *
462      **/

463     public void addAgent(String JavaDoc name) throws HeroException {
464         if (this.getProjectConfigTrace())
465             trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
466         BnAgentLocalHome nHome;
467         BnAgentLocal mAgent;
468         if (!isAdminOfProject(this.getCaller()))
469         {
470             if (this.getProjectConfigTrace())
471                 trace.error("Only the Admin of the project is allowed to do this operation... ");
472             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
473         }
474         try {
475             nHome = hero.interfaces.BnAgentUtil.getLocalHome();
476         } catch (javax.naming.NamingException JavaDoc be) {
477             if (this.getProjectConfigTrace())
478                 trace.error(be.getMessage());
479             throw new HeroException(be.getMessage());
480         }
481         
482         try {
483             BnAgentLocal nf = nHome.findByName(name, mProject.getId());
484             throw new HeroException("BnAgent "+ name+ " already exist in project "+ mProject.getName());
485         } catch (javax.ejb.FinderException JavaDoc nn) {
486             if (this.getProjectConfigTrace())
487                 trace.error(nn.getMessage());
488             
489             try {
490                 BnAgentLocal ag = nHome.create(name);
491                 BnAgentValue adata = ag.getBnAgentValue();
492                 adata.setCreationDate(new java.util.Date JavaDoc());
493                 ag.setBnAgentValue(adata);
494                 Collection JavaDoc cAgents = mProject.getBnAgents();
495                 cAgents.add(ag);
496                 String JavaDoc creator = this.getCaller();
497                 BnUserLocalHome uHome = hero.interfaces.BnUserUtil.getLocalHome();
498                 BnUserLocal user = uHome.findByName(creator);
499                 ag.setCreator(user);
500                 
501                 // Tell the world
502
// jms.sendNodeEvent(ADDNODE,this.getName(),name,nodeType,ndata.getState(),this.getCaller());
503
} catch (InvalidValueException ie) {
504                 if (this.getProjectConfigTrace())
505                     trace.error(ie.getMessage());
506                 throw new HeroException(ie.getMessage());
507             } catch (CreateException JavaDoc ce) {
508                 if (this.getProjectConfigTrace())
509                     trace.error(ce.getMessage());
510                 throw new HeroException(ce.getMessage());
511             } catch (FinderException JavaDoc fe) {
512                 if (this.getProjectConfigTrace())
513                     trace.error(fe.getMessage());
514                 throw new HeroException(fe.getMessage());
515             } catch (javax.naming.NamingException JavaDoc ne) {
516                 if (this.getProjectConfigTrace())
517                     trace.error(ne.getMessage());
518                 throw new HeroException(ne.getMessage());
519             }
520         }
521     }
522     
523     /**
524      * Add an edge to the project. Creates a transition between two nodes by specifying
525      * the name of this edge. <strong> No more implemented </strong>
526      *
527      * @param name the name ot the edge
528      *
529      * @ejb:interface-method view-type="both"
530      * @ejb:transaction type="Required"
531      * @throws HeroException
532      *
533      **/

534     public void addEdge(String JavaDoc name, String JavaDoc in, String JavaDoc out)
535     throws HeroException {
536         if (this.getProjectConfigTrace())
537             trace.error("parameters: name=" + name + " in=" + in + " out=" + out + " process name = " + this.getName()+ " started by " + this.getCaller());
538         throw new HeroException("no more implemented");
539     }
540     
541     /**
542      * Add an edge between two nodes of the project [in] ---- [out]. This operation refresh
543      * the out node state. If new edge forms a cycle an exception is throwed.
544      *
545      * @param in the name of the in Node
546      * @param out the name of the out Node
547      *
548      * @ejb:interface-method view-type="both"
549      * @ejb:transaction type="Required"
550      *
551      * @throws HeroException
552      *
553      **/

554     public String JavaDoc addEdge(String JavaDoc in, String JavaDoc out) throws HeroException {
555         if (this.getProjectConfigTrace())
556             trace.info("parameters: in=" + in + " out:" + out + " process name = " + this.getName()+ " started by " + this.getCaller());
557         BnEdgeLocalHome eHome;
558         BnNodeLocalHome nHome;
559         BnNodeLocal mInNode;
560         BnNodeLocal mOutNode;
561         BnEdgeLocal mEdge;
562         if (!isAdminOfProject(this.getCaller()))
563         {
564             if (this.getProjectConfigTrace())
565                 trace.error("Only the Admin of the project is allowed to do this operation... ");
566             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
567         }
568         try {
569             nHome = hero.interfaces.BnNodeUtil.getLocalHome();
570         } catch (javax.naming.NamingException JavaDoc be) {
571             if (this.getProjectConfigTrace())
572                 trace.error(be.getMessage());
573             throw new HeroException(be.getMessage());
574         }
575         try {
576             mInNode = nHome.findByName(in, mProject.getId());
577         } catch (FinderException JavaDoc fe) {
578             if (this.getProjectConfigTrace())
579                 trace.error("In Node does not exist " + fe.getMessage());
580             throw new HeroException("In Node does not exist");
581         }
582         try {
583             mOutNode = nHome.findByName(out, mProject.getId());
584         } catch (FinderException JavaDoc fe) {
585             if (this.getProjectConfigTrace())
586                 trace.error("Out Node does not exist " + fe.getMessage());
587             throw new HeroException("Out Node does not exist");
588         }
589         try {
590             eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
591         } catch (javax.naming.NamingException JavaDoc be) {
592             if (this.getProjectConfigTrace())
593                 trace.error(be.getMessage());
594             throw new HeroException(be.getMessage());
595         }
596         visited.clear();
597         if (!checkStructuralConstraints(in, out))
598             throw new hero.util.EdgeCycleException("This edge add a cycle");
599         
600         if (checkDynamics(out)) { // check state of Nodes
601
if (checkDuplicateEdge(in, out)) {
602                 try {
603                     mEdge = eHome.create();
604                     mEdge.setBnProject(mProject);
605                     mEdge.setInBnNode(mInNode);
606                     mEdge.setOutBnNode(mOutNode);
607                     
608                     jms.sendEdgeEvent(ADDEDGE,this.getName(),mEdge.getName(),mInNode.getName(),mOutNode.getName(),this.getCaller());
609                     
610                 } catch (InvalidValueException ie) {
611                     if (this.getProjectConfigTrace())
612                         trace.error(ie.getMessage());
613                     throw new HeroException(ie.getMessage());
614                 } catch (CreateException JavaDoc ce) {
615                     if (this.getProjectConfigTrace())
616                         trace.error(ce.getMessage());
617                     throw new HeroException(ce.getMessage());
618                 }
619             } else {
620                 throw new hero.util.DuplicatedEdgeException("Cannot add edge. BnEdge between nodes already exist");
621             }
622         } else {
623             throw new hero.util.NodeStartedException("Cannot add edge. " + out + " is already started");
624         }
625         /*visited.clear();
626          if (!checkStructuralConstraints(in, out))
627          throw new hero.util.EdgeCycleException("This edge add a cycle");*/

628         
629         // update the current graph state
630
int edgeState = hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][mInNode.getState()];
631         this.setEdgeState(mEdge, edgeState);
632         /*if (mOutNode.getState()==Constants.Nd.READY)
633             this.setNodeState(mOutNode, Constants.Nd.INITIAL);*/

634
635         int newOperation = mOutNode.getActivation().state(mOutNode);
636         int newState = mOutNode.getTransition().computeState(mOutNode, newOperation);
637         if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
638             throw new HeroException("AddEdge generated a bad Node transition");
639         }
640         this.setNodeState(mOutNode, newState);
641         // jms.sendNodeEvent(READYINITIAL,this.getName(),nOut.getName(),nOut.getType(),INITIAL,context.getCallerPrincipal().getName());
642
return mEdge.getName();
643     }
644     
645     /**
646      * Add an AgentEdge to the Project [in] ---- [out]
647      *
648      * @param in the name of the in Agent
649      * @param out the name of the out Node
650      *
651      * @ejb:interface-method view-type="both"
652      * @ejb:transaction type="Required"
653      *
654      * @throws HeroException
655      *
656      **/

657     public String JavaDoc addAgentEdge(String JavaDoc in, String JavaDoc out) throws HeroException {
658         if (this.getProjectConfigTrace())
659             trace.info("parameters: in=" + in + " out:" + out + " process name = " + this.getName()+ " started by " + this.getCaller());
660         BnAgentEdgeLocalHome eHome;
661         BnNodeLocalHome nHome;
662         BnAgentLocalHome aHome;
663         BnAgentLocal mInAgent;
664         BnNodeLocal mOutNode;
665         BnAgentEdgeLocal mEdge;
666         if (!isAdminOfProject(this.getCaller()))
667         {
668             if (this.getProjectConfigTrace())
669                 trace.error("Only the Admin of the project is allowed to do this operation... ");
670             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
671         }
672         try {
673             aHome = hero.interfaces.BnAgentUtil.getLocalHome();
674         } catch (javax.naming.NamingException JavaDoc be) {
675             if (this.getProjectConfigTrace())
676                 trace.error(be.getMessage());
677             throw new HeroException(be.getMessage());
678         }
679         try {
680             mInAgent = aHome.findByName(in, mProject.getId());
681         } catch (FinderException JavaDoc fe) {
682             if (this.getProjectConfigTrace())
683                 trace.error("In Agent does not exist " + fe.getMessage());
684             throw new HeroException("In Agent does not exist");
685         }
686         try {
687             nHome = hero.interfaces.BnNodeUtil.getLocalHome();
688         } catch (javax.naming.NamingException JavaDoc be) {
689             if (this.getProjectConfigTrace())
690                 trace.error(be.getMessage());
691             throw new HeroException(be.getMessage());
692         }
693         try {
694             mOutNode = nHome.findByName(out, mProject.getId());
695         } catch (FinderException JavaDoc fe) {
696             if (this.getProjectConfigTrace())
697                 trace.error("Out Node does not exist " + fe.getMessage());
698             throw new HeroException("Out Node does not exist");
699         }
700         try {
701             eHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome();
702         } catch (javax.naming.NamingException JavaDoc be) {
703             if (this.getProjectConfigTrace())
704                 trace.error(be.getMessage());
705             throw new HeroException(be.getMessage());
706         }
707         if (checkDynamics(out)) { // check state of Nodes
708
if (checkDuplicateAgentEdge(in, out)) {
709                 try {
710                     mEdge = eHome.create();
711                     mEdge.setBnProject(mProject);
712                     mEdge.setInBnAgent(mInAgent);
713                     mEdge.setOutBnNode(mOutNode);
714                     
715                     //jms.sendEdgeEvent(ADDEDGE,this.getName(),mEdge.getName(),mInNode.getName(),mOutNode.getName(),this.getCaller());
716

717                 } catch (InvalidValueException ie) {
718                     if (this.getProjectConfigTrace())
719                         trace.error(ie.getMessage());
720                     throw new HeroException(ie.getMessage());
721                 } catch (CreateException JavaDoc ce) {
722                     if (this.getProjectConfigTrace())
723                         trace.error(ce.getMessage());
724                     throw new HeroException(ce.getMessage());
725                 }
726             } else {
727                 throw new hero.util.DuplicatedEdgeException("Cannot add agentEdge. AgentEdge between nodes already exist");
728             }
729         } else {
730             throw new hero.util.NodeStartedException(
731                     "Cannot add agentEdge. " + out + " is already started");
732         }
733         
734         // update the current graph state
735
this.setAgentEdgeState(mEdge, hero.interfaces.Constants.Ed.INITIAL);
736         
737         int newOperation = mOutNode.getActivation().state(mOutNode);
738         int newState = mOutNode.getTransition().computeState(mOutNode, newOperation);
739         if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
740             throw new HeroException("AddEdge generated a bad Node transition");
741         }
742         this.setNodeState(mOutNode, newState);
743         // jms.sendNodeEvent(READYINITIAL,this.getName(),nOut.getName(),nOut.getType(),INITIAL,context.getCallerPrincipal().getName());
744
return mEdge.getName();
745     }
746     
747     /**
748      * Add a role to the project. Creates a role within this project. The role is specific of this project
749      *
750      * @param name the name of the role
751      * @param description the description of the role
752      *
753      * @ejb:interface-method view-type="both"
754      * @ejb:transaction type="Required"
755      *
756      * @throws HeroException
757      *
758      **/

759     public void addRole(String JavaDoc roleName, String JavaDoc description)
760     throws HeroException {
761         BnRoleLocalHome roleh;
762         if (this.getProjectConfigTrace())
763             trace.info("parameters: roleName=" + roleName + " description=" + description + " process name = " + this.getName()+ " started by " + this.getCaller());
764         if (!isAdminOfProject(this.getCaller()))
765         {
766             if (this.getProjectConfigTrace())
767                 trace.error("Only the Admin of the project is allowed to do this operation... ");
768             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
769         }
770         try {
771             roleh = BnRoleUtil.getLocalHome();
772         } catch (javax.naming.NamingException JavaDoc ne) {
773             if (this.getProjectConfigTrace())
774                 trace.error(ne.getMessage());
775             throw new HeroException(ne.getMessage());
776         }
777         
778         try {
779             BnRoleLocal nf = roleh.findByName(roleName, mProject.getId());
780             throw new HeroException("BnRole "+ roleName+ " already exist in project "+ mProject.getName());
781         } catch (javax.ejb.FinderException JavaDoc nn) {
782             if (this.getProjectConfigTrace())
783                 trace.error(nn.getMessage());
784             
785             BnRoleValue rv = new BnRoleValue();
786             rv.setName(roleName);
787             rv.setDescription(description);
788             try {
789                 BnRoleLocal rl = roleh.create(rv);
790                 mProject.getBnRoles().add(rl);
791                 //rl.setBnProject(mProject);
792
jms.sendRoleEvent(ADDROLE,this.getName(),roleName);
793             } catch (javax.ejb.CreateException JavaDoc ce) {
794                 if (this.getProjectConfigTrace())
795                     trace.error(ce.getMessage());
796                 throw new HeroException(ce.getMessage());
797             }
798         }
799     }
800     
801     /**
802      * Add a new iteration between two nodes. This methods sets an iteration which is stopped when
803      * the lastNode property "iterate" is false.
804      *
805      * @param from the name of the first node
806      * @param to the name of the last node
807      *
808      * @ejb:interface-method view-type="both"
809      * @ejb:transaction type="Required"
810      *
811      * @throws HeroException
812      *
813      **/

814     public void addIteration(String JavaDoc from, String JavaDoc to, String JavaDoc condition) throws HeroException {
815         if (this.getProjectConfigTrace())
816             trace.info("parameters: from=" + from + " to=" + to + " condition=" + condition + " process name = " + this.getName()+ " started by " + this.getCaller());
817         BnIterationLocalHome iteh;
818         if (!isAdminOfProject(this.getCaller()))
819         {
820             if (this.getProjectConfigTrace())
821                 trace.error("Only the Admin of the project is allowed to do this operation... ");
822             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
823         }
824         if (!this.checkStructuralConstraints(from,to))
825         {
826             try {
827                 iteh = BnIterationUtil.getLocalHome();
828             } catch (javax.naming.NamingException JavaDoc ne) {
829                 if (this.getProjectConfigTrace())
830                     trace.error(ne.getMessage());
831                 throw new HeroException(ne.getMessage());
832             }
833             
834             try {
835                 BnIterationLocal it = iteh.findByFromTo(from, to, mProject.getId());
836                 throw new HeroException("Iteration already exist between: "+ from +" and "+to+" nodes, in project "+ mProject.getName());
837             } catch (javax.ejb.FinderException JavaDoc nn) {
838                 
839                 BnIterationLightValue iv = new BnIterationLightValue();
840                 iv.setFromNode(from);
841                 iv.setToNode(to);
842                 iv.setCondition(condition);
843                 try {
844                     BnIterationLocal il = iteh.create(iv);
845                     mProject.getBnIterations().add(il);
846                     jms.sendIterationEvent(ADDITERATION,this.getName(), from, to);
847                 } catch (Exception JavaDoc ce) {
848                     if (this.getProjectConfigTrace())
849                         trace.error(ce.getMessage());
850                     throw new HeroException(ce.getMessage());
851                 }
852             }
853         }
854         else
855             throw new HeroException("This iteration is not possible...");
856     }
857     
858     /**
859      * Delete an iteration between two nodes.
860      *
861      * @param from the name of the first node
862      * @param to the name of the last node
863      *
864      * @ejb:interface-method view-type="both"
865      * @ejb:transaction type="Required"
866      *
867      * @throws HeroException
868      *
869      **/

870     public void deleteIteration(String JavaDoc from, String JavaDoc to) throws HeroException {
871         if (this.getProjectConfigTrace())
872             trace.info("parameters: from=" + from + " to=" + to +" process name = " + this.getName()+ " started by " + this.getCaller());
873         BnIterationLocalHome iteh;
874         if (!isAdminOfProject(this.getCaller()))
875         {
876             if (this.getProjectConfigTrace())
877                 trace.error("Only the Admin of the project is allowed to do this operation... ");
878             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
879         }
880         try {
881             iteh = BnIterationUtil.getLocalHome();
882         } catch (javax.naming.NamingException JavaDoc ne) {
883             if (this.getProjectConfigTrace())
884                 trace.error(ne.getMessage());
885             throw new HeroException(ne.getMessage());
886         }
887         try {
888             BnIterationLocal it = iteh.findByFromTo(from, to, mProject.getId());
889             it.remove();
890         } catch (javax.ejb.FinderException JavaDoc nn) {
891             if (this.getProjectConfigTrace())
892                 trace.error("Iteration does not exist: "+ from +" and "+to+" nodes, in project "+ mProject.getName());
893             throw new HeroException("Iteration does not exist: "+ from +" and "+to+" nodes, in project "+ mProject.getName());
894         } catch (javax.ejb.RemoveException JavaDoc rn) {
895             if (this.getProjectConfigTrace())
896                 trace.error("Error when deleting activity iteration: "+ from +" and "+to+" nodes, in project "+ mProject.getName());
897             throw new HeroException("Error when deleting activity iteration: "+ from +" and "+to+" nodes, in project "+ mProject.getName());
898         }
899     }
900     
901     /**
902      * Add hook to project. Add an existing hook file to the project. This hook type uses a
903      * Java or TCL file loaded at run time. The hookName represents the class java or tcl file to be loaded by the system at run time.
904      * These classes must be in the application server classpath to be correctly executed.
905      * Put your hooks classes in $BONITA_HOME\src\resources\hooks and then redeploy bonita.ear (ant task).
906      *
907      * @param hookName the name of the hook
908      * @param eventName the event
909      * @param hookType the type
910      * @ejb:interface-method view-type="both"
911      * @ejb:transaction type="Required"
912      * @throws HeroException
913      *
914      **/

915     public void addHook(String JavaDoc hookName, String JavaDoc eventName, int hookType)
916     throws HeroException {
917         if (this.getProjectConfigTrace())
918             trace.info("parameters: hookName=" + hookName + " eventName=" + eventName + " process name = " + this.getName()+ " started by " + this.getCaller());
919         BnProjectHookLocalHome pHome;
920         BnProjectHookLocal ppLocal;
921         if (!isAdminOfProject(this.getCaller()))
922         {
923             if (this.getProjectConfigTrace())
924                 trace.error("Only the Admin of the project is allowed to do this operation... ");
925             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
926         }
927         try {
928             pHome = BnProjectHookUtil.getLocalHome();
929         } catch (javax.naming.NamingException JavaDoc ne) {
930             if (this.getProjectConfigTrace())
931                 trace.error(ne.getMessage());
932             throw new HeroException(ne.getMessage());
933         }
934         
935         try {
936             BnProjectHookLocal pf = pHome.findByName(mProject.getId(), hookName);
937             throw new HeroException("BnProject hook "+ hookName + " already exist in project "+ mProject.getName());
938         } catch (javax.ejb.FinderException JavaDoc pn) {
939             if (this.getProjectConfigTrace())
940                 trace.error(pn.getMessage());
941             try {
942                 BnProjectHookLocal h = pHome.create(hookName, eventName, hookType);
943                 h.setBnProject(mProject);
944             } catch (CreateException JavaDoc fe) {
945                 if (this.getProjectConfigTrace())
946                     trace.error(fe.getMessage());
947                 throw new HeroException(fe.getMessage());
948             } catch (InvalidValueException ie) {
949                 if (this.getProjectConfigTrace())
950                     trace.error(ie.getMessage());
951                 throw new HeroException(ie.getMessage());
952             }
953         }
954     }
955     
956     /**
957      * Add hook to a node. Add an existing hook file to the node. This type of hook use a
958      * Java or TCL file loaded at run time. The hookName represents the class java or tcl file to be loaded by the system at run time.
959      * These classes must be in the application server classpath to be correctly executed.
960      * Put your hooks classes in $BONITA_HOME\src\resources\hooks and then redeploy bonita.ear (ant task).
961      *
962      * @param nodeName the name of the node
963      * @param hookName the name of the hook
964      * @param eventName the name of the event
965      * @param hookType the type of the hook
966      * @ejb:interface-method view-type="both"
967      * @ejb:transaction type="Required"
968      * @throws HeroException
969      *
970      **/

971     public void addNodeHook(String JavaDoc nodeName,String JavaDoc hookName,String JavaDoc eventName,int hookType) throws HeroException {
972         if (this.getProjectConfigTrace())
973             trace.info("parameters: node="+ nodeName+ " hookName="+ hookName+ " eventName=" + eventName + " process name = " + this.getName()+ " started by " + this.getCaller());
974         BnNodeHookLocalHome pHome;
975         BnNodeHookLocal ppLocal;
976         if (!isAdminOfProject(this.getCaller()))
977         {
978             if (this.getProjectConfigTrace())
979                 trace.error("Only the Admin of the project is allowed to do this operation... ");
980             throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
981         }
982         BnNodeLocal nd = mProject.getBnNode(nodeName);
983         try {
984             pHome = BnNodeHookUtil.getLocalHome();
985         } catch (javax.naming.NamingException JavaDoc ne) {
986             if (this.getProjectConfigTrace())
987                 trace.error(ne.getMessage());
988             throw new HeroException(ne.getMessage());
989         }
990         
991         try {
992             BnNodeHookLocal nf = pHome.findByName(nd.getId(), hookName);
993             throw new HeroException("BnNode hook "+ hookName+ " already exist in node "+ nodeName);
994         } catch (javax.ejb.FinderException JavaDoc nn) {
995             if (this.getProjectConfigTrace())
996                 trace.error(nn.getMessage());
997             try {
998                 BnNodeHookLocal h = pHome.create(hookName, eventName, hookType);
999                 h.setBnNode(nd);
1000            } catch (CreateException JavaDoc fe) {
1001                if (this.getProjectConfigTrace())
1002                    trace.error(fe.getMessage());
1003                throw new HeroException(fe.getMessage());
1004            } catch (InvalidValueException ie) {
1005                if (this.getProjectConfigTrace())
1006                    trace.error(ie.getMessage());
1007                throw new HeroException(ie.getMessage());
1008            }
1009        }
1010    }
1011    
1012    /**
1013     * Add/Update an existing mapper to the role. This type of mapper use a
1014     * Java file loaded at run time.
1015     *
1016     * @param roleName the name of the role
1017     * @param mapperName the name of the mapper
1018     * @param mapperType the type of the mapper
1019     * @ejb:interface-method view-type="both"
1020     * @ejb:transaction type="Required"
1021     * @throws HeroException
1022     *
1023     **/

1024    public void addRoleMapper(String JavaDoc roleName,String JavaDoc mapperName,int mapperType) throws HeroException {
1025        // logs trace
1026
if (this.getProjectConfigTrace())
1027            trace.info("parameters: roleName="+ roleName+ " mapperName="+ mapperName+ " mapperType="+ mapperType+ " process name = " + this.getName()+ " started by " + this.getCaller());
1028        
1029        BnRoleMapperLocalHome mapperh;
1030        BnRoleLocalHome roleh;
1031        BnRoleMapperLocal ppLocal = null;
1032        BnRoleLocal role = null;
1033        if (!isAdminOfProject(this.getCaller()))
1034        {
1035            if (this.getProjectConfigTrace())
1036                trace.error("Only the Admin of the project is allowed to do this operation... ");
1037            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1038        }
1039        try {
1040            mapperh = BnRoleMapperUtil.getLocalHome();
1041            roleh = BnRoleUtil.getLocalHome();
1042        } catch (javax.naming.NamingException JavaDoc ne) {
1043            if (this.getProjectConfigTrace())
1044                trace.error(ne.getMessage());
1045            throw new HeroException(ne.getMessage());
1046        }
1047        // Get objet role local with findByName from BnRoleBean
1048
try {
1049            role = roleh.findByName(roleName, mProject.getId());
1050        } catch (FinderException JavaDoc pfe) {
1051            if (this.getProjectConfigTrace())
1052                trace.error(pfe.getMessage());
1053            throw new HeroException("The bnRole does not exist for role : " + roleName);
1054        }
1055        // if the role has not already a mapper put one. Otherwise update it.
1056
ppLocal = role.getBnRoleMapper();
1057        if (ppLocal != null){
1058            ppLocal.setName(mapperName);
1059            ppLocal.setType(mapperType);
1060        }
1061        else {
1062            try {
1063                ppLocal = mapperh.create(mapperName, mapperType);
1064                ppLocal.setBnRole(role);
1065            } catch (CreateException JavaDoc fe) {
1066                if (this.getProjectConfigTrace())
1067                    trace.error(fe.getMessage());
1068                throw new HeroException(fe.getMessage());
1069            } catch (InvalidValueException ie) {
1070                if (this.getProjectConfigTrace())
1071                    trace.error(ie.getMessage());
1072                throw new HeroException(ie.getMessage());
1073            }
1074        }
1075    }
1076    
1077    /**
1078     * Add/Update an existing performerAssign to the node. This type of performerAssign use a
1079     * Java file loaded at run time.
1080     *
1081     * @param nodeName the name of the node
1082     * @param performerAssignName the name of the performerAssign
1083     * @param performerAssignType the type of the performerAssign
1084     * @ejb:interface-method view-type="both"
1085     * @ejb:transaction type="Required"
1086     * @throws HeroException
1087     *
1088     **/

1089    public void addNodePerformerAssign(String JavaDoc nodeName,String JavaDoc performerAssignName,int performerAssignType, String JavaDoc propertyName) throws HeroException {
1090        // logs trace
1091
if (this.getProjectConfigTrace())
1092            trace.debug("addNodePerformerAssign: node = "+ nodeName+ " performerAssignName = "+ performerAssignName);
1093        
1094        BnNodePerformerAssignLocalHome performerAssignh;
1095        BnNodeLocalHome nodeh;
1096        BnNodePerformerAssignLocal ppLocal = null;
1097        BnNodeLocal node = null;
1098        if (!isAdminOfProject(this.getCaller()))
1099        {
1100            if (this.getProjectConfigTrace())
1101                trace.error("Only the Admin of the project is allowed to do this operation... ");
1102            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1103        }
1104        try {
1105            performerAssignh = BnNodePerformerAssignUtil.getLocalHome();
1106            nodeh = BnNodeUtil.getLocalHome();
1107        } catch (javax.naming.NamingException JavaDoc ne) {
1108            throw new HeroException(ne.getMessage());
1109        }
1110        // Get objet node local with findByName from BnNodeBean
1111
try {
1112            node = nodeh.findByName(nodeName, mProject.getId());
1113        } catch (FinderException JavaDoc pfe) {
1114            throw new HeroException("The bnNode does not exist for node : " + nodeName);
1115        }
1116        // if the node has not already a performerAssign put one. Otherwise update it.
1117
ppLocal = node.getBnNodePerformerAssign();
1118        if (ppLocal != null){
1119            ppLocal.setName(performerAssignName);
1120            ppLocal.setType(performerAssignType);
1121            ppLocal.setPropertyName(propertyName);
1122        }
1123        else {
1124            try {
1125                ppLocal = performerAssignh.create(performerAssignName, performerAssignType, propertyName);
1126                ppLocal.setBnNode(node);
1127            } catch (CreateException JavaDoc fe) {
1128                throw new HeroException(fe.getMessage());
1129            } catch (InvalidValueException ie) {
1130                throw new HeroException(ie.getMessage());
1131            }
1132        }
1133    }
1134    
1135    /**
1136     * Add interhook to a node. Set a new hook to this node by setting the eventName, hookType and
1137     * script values.<br><br>
1138     *
1139     * The possible values of the argumets are:<br><br>
1140     * <strong>eventName:<br></strong>
1141     * hero.interfaces.Constants.Nd.BEFORESTART<br>
1142     * hero.interfaces.Constants.Nd.AFTERSTART<br>
1143     * hero.interfaces.Constants.Nd.BEFORETERMINATE<br>
1144     * hero.interfaces.Constants.Nd.AFTERTERMINATE<br>
1145     * hero.interfaces.Constants.Nd.ONCANCEL<br>
1146     * hero.interfaces.Constants.Nd.ANTICIPATE<br><br>
1147     *
1148     * <strong>hookType:<br></strong>
1149     *
1150     * hero.hook.Hook.BSINTERACTIVE<br><br>
1151     *
1152     * <strong>script:<br></strong>
1153     * The beanshell source code associated to this hook.<br><br>
1154     *
1155     * <strong>The following sample code illustrates how to use this method:<br><br></strong>
1156     *
1157     * ...<br>
1158     * String script = "import hero.interfaces.*;\n"<br>
1159     * + "import hero.interfaces.BnNodeLocal;\n"<br>
1160     * + "beforeStart (Object b,Object n) {\n\n\n"<br>
1161     * + "System.out.println(\"Hook Test\");\n"<br>
1162     * + "}";<br>
1163     * <strong>yourProjectSessionInstance</strong>.addNodeInterHook("NodeName","Hook_Name",Constants.Nd.BEFORESTART,hero.hook.Hook.BSINTERACTIVE,script);
1164     *
1165     * @param nodeName the name of the node
1166     * @param hookName the name of the hook
1167     * @param eventName the name of the event
1168     * @param hookType the type of the hook
1169     * @param script the value of the script
1170     * @ejb:interface-method view-type="both"
1171     * @ejb:transaction type="Required"
1172     * @throws HeroException
1173     *
1174     **/

1175    public void addNodeInterHook(String JavaDoc nodeName,String JavaDoc hookName,String JavaDoc eventName,int hookType,String JavaDoc value)
1176    throws HeroException {
1177        if (this.getProjectConfigTrace())
1178            trace.info("parameters: node="+ nodeName+ " hookName="+ hookName+ " eventName="+ eventName+ " value="+ value + " process name = " + this.getName()+ " started by " + this.getCaller());
1179        BnNodeInterHookLocalHome pHome;
1180        BnNodeInterHookLocal ppLocal;
1181        if (!isAdminOfProject(this.getCaller()))
1182        {
1183            if (this.getProjectConfigTrace())
1184                trace.error("Only the Admin of the project is allowed to do this operation... ");
1185            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1186        }
1187    
1188        BnNodeLocal nd = mProject.getBnNode(nodeName);
1189        try {
1190            pHome = BnNodeInterHookUtil.getLocalHome();
1191        } catch (javax.naming.NamingException JavaDoc ne) {
1192            if (this.getProjectConfigTrace())
1193                trace.error(ne.getMessage());
1194            throw new HeroException(ne.getMessage());
1195        }
1196        
1197        try {
1198            BnNodeInterHookLocal nf = pHome.findByName(nd.getId(), hookName);
1199            throw new HeroException("Interactive node hook "+ hookName+ " already exist in node "+ nodeName);
1200        } catch (javax.ejb.FinderException JavaDoc nn) {
1201            if (this.getProjectConfigTrace())
1202                trace.error(nn.getMessage());
1203            try {
1204                BnNodeInterHookLocal h = pHome.create(hookName, eventName, hookType, value);
1205                h.setBnNode(nd);
1206            } catch (CreateException JavaDoc fe) {
1207                if (this.getProjectConfigTrace())
1208                    trace.error(fe.getMessage());
1209                throw new HeroException(fe.getMessage());
1210            } catch (InvalidValueException ie) {
1211                if (this.getProjectConfigTrace())
1212                    trace.error(ie.getMessage());
1213                throw new HeroException(ie.getMessage());
1214            }
1215        }
1216    }
1217    
1218    /**
1219     * Add interhook to the project. Creates new hook associated to all project activites.
1220     * See the {@link #addNodeInterHook(String,String,String,int,String) addNodeInterHook} method in order
1221     * to identify arguments values.
1222     *
1223     * @param hookName the name of the hook
1224     * @param eventName the name of the event
1225     * @param hookType the type of the hook
1226     * @param script the value of the script
1227     * @ejb:interface-method view-type="both"
1228     * @ejb:transaction type="Required"
1229     * @throws HeroException
1230     *
1231     **/

1232    public void addInterHook(String JavaDoc hookName,String JavaDoc eventName,int hookType,String JavaDoc value)
1233    throws HeroException {
1234        if (this.getProjectConfigTrace())
1235            trace.info("parameters: hookName="+ hookName+ " eventName="+ eventName+ " value="+ value + " process name = " + this.getName()+ " started by " + this.getCaller());
1236        BnProjectInterHookLocalHome pHome;
1237        BnProjectInterHookLocal ppLocal;
1238        if (!isAdminOfProject(this.getCaller()))
1239        {
1240            if (this.getProjectConfigTrace())
1241                trace.error("Only the Admin of the project is allowed to do this operation... ");
1242            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1243        }
1244        try {
1245            pHome = BnProjectInterHookUtil.getLocalHome();
1246        } catch (javax.naming.NamingException JavaDoc ne) {
1247            if (this.getProjectConfigTrace())
1248                trace.error(ne.getMessage());
1249            throw new HeroException(ne.getMessage());
1250        }
1251        
1252        try {
1253            BnProjectInterHookLocal nf = pHome.findByName(mProject.getId(), hookName);
1254            throw new HeroException("Interactive hook "+ hookName+ " already exist in project "+ mProject.getName());
1255        } catch (javax.ejb.FinderException JavaDoc nn) {
1256            if (this.getProjectConfigTrace())
1257                trace.error(nn.getMessage());
1258            try {
1259                BnProjectInterHookLocal h = pHome.create(hookName, eventName, hookType, value);
1260                h.setBnProject(mProject);
1261            } catch (CreateException JavaDoc fe) {
1262                if (this.getProjectConfigTrace())
1263                    trace.error(fe.getMessage());
1264                throw new HeroException(fe.getMessage());
1265            } catch (InvalidValueException ie) {
1266                if (this.getProjectConfigTrace())
1267                    trace.error(ie.getMessage());
1268                throw new HeroException(ie.getMessage());
1269            }
1270        }
1271    }
1272    
1273    /**
1274     * Active a workflow process (model/cooperative)
1275     *
1276     * @param name the name of the workflow process
1277     *
1278     * @ejb:interface-method view-type="both"
1279     * @ejb:transaction type="Required"
1280     * @throws HeroException
1281     *
1282     **/

1283    public void activeProcess() throws HeroException {
1284        if (!isAdminOfProject(this.getCaller()))
1285        {
1286            if (this.getProjectConfigTrace())
1287                trace.error("Only the Admin of the project is allowed to do this operation... ");
1288            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1289        }
1290        if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
1291        {
1292            mProject.setStatus(Constants.Pj.ACTIVE);
1293            try {
1294                //serviceLocator.initCache(mProject.getName());
1295
mProject.setModel(BonitaProjectLocator.generateProjectValue(mProject.getName()));
1296            } catch (BonitaServiceException e) {e.printStackTrace();
1297              throw new HeroException(e.getMessage());
1298            }
1299        }
1300        else
1301            throw new HeroException("This project is already ACTIVE...");
1302    }
1303    
1304    /**
1305     * Hide a workflow process (model/cooperative)
1306     *
1307     * @param name the name of the workflow process
1308     *
1309     * @ejb:interface-method view-type="both"
1310     * @ejb:transaction type="Required"
1311     * @throws HeroException
1312     *
1313     **/

1314    public void hideProcess() throws HeroException {
1315        if (!isAdminOfProject(this.getCaller()))
1316        {
1317            if (this.getProjectConfigTrace())
1318                trace.error("Only the Admin of the project is allowed to do this operation... ");
1319            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1320        }
1321        if (mProject.getStatus().equals(Constants.Pj.ACTIVE))
1322        {
1323            mProject.setStatus(Constants.Pj.HIDDEN);
1324            try {
1325                //serviceLocator.initCache(mProject.getName());
1326
mProject.setModel(BonitaProjectLocator.generateProjectValue(mProject.getName()));
1327            } catch (BonitaServiceException e) {e.printStackTrace();
1328              throw new HeroException(e.getMessage());
1329            }
1330        }
1331        else
1332            throw new HeroException("This projects is already HIDDEN...");
1333    }
1334    
1335    // -------------------------------------------------------------------------
1336
// Delete business methods
1337
// -------------------------------------------------------------------------
1338

1339    /**
1340     * Delete a node from the project. If this node is in executing state, the
1341     * method throws an execption
1342     *
1343     * @param name the name of the edge
1344     *
1345     * @ejb:interface-method view-type="both"
1346     * @ejb:transaction type="Required"
1347     * @throws HeroException
1348     *
1349     **/

1350    public void deleteNode(String JavaDoc name) throws HeroException {
1351        // check deletion conditions
1352
if (this.getProjectConfigTrace())
1353            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
1354        if (!isAdminOfProject(this.getCaller()))
1355        {
1356            if (this.getProjectConfigTrace())
1357                trace.error("Only the Admin of the project is allowed to do this operation... ");
1358            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1359        }
1360        BnNodeLocal nd = mProject.getBnNode(name);
1361        if (nd.isExecuting()) {
1362            throw new NodeExecutingException("Cannot delete node. It is executing");
1363        }
1364        /* if (nd.isTerminated()) {
1365         throw new NodeTerminatedException("Cannot delete node. It is terminated");
1366         }
1367         if (nd.isCancelled()) {
1368         throw new NodeCancelledException("Cannot delete node. It is cancelled");
1369         }*/

1370        if (this.getNodeType(name)==Constants.Nd.SUB_PROCESS_NODE)
1371        {
1372            try {
1373                BnProjectLocal plocal = pHome.findByName(name);
1374                Collection JavaDoc nodes = plocal.getBnNodes();
1375                Iterator JavaDoc nds = nodes.iterator();
1376                while (nds.hasNext()) // Verifies if the project has any subProcesses
1377
{
1378                    BnNodeLocal nod = (BnNodeLocal)nds.next();
1379                    if (nod.getType()==Constants.Nd.SUB_PROCESS_NODE)
1380                        throw new HeroException("Error in delete project: You have to delete subProcesses first !!");
1381                }
1382                plocal.remove();
1383                jms.sendProjectEvent(DELETEPROJECT, name);
1384            } catch (RemoveException JavaDoc pre) {
1385                if (this.getProjectConfigTrace())
1386                    trace.error("Cannot remove project " + pre.getMessage());
1387                throw new HeroException("Cannot remove project " + pre.getMessage());
1388            } catch (FinderException JavaDoc pfe) {
1389                if (this.getProjectConfigTrace())
1390                    trace.error("Cannot find project " + pfe.getMessage());
1391                throw new HeroException("Cannot find project " + pfe.getMessage());
1392            }
1393        }
1394        
1395        Collection JavaDoc edgesIn = nd.getInBnEdges();
1396        Object JavaDoc[] edai = edgesIn.toArray();
1397        for (int i = 0; i < edai.length; i++) {
1398            edgeDeletion((BnEdgeLocal) edai[i]);
1399        }
1400        Collection JavaDoc edgesOut = nd.getOutBnEdges();
1401        Object JavaDoc[] edao = edgesOut.toArray();
1402        for (int i = 0; i < edao.length; i++) {
1403            edgeDeletion((BnEdgeLocal) edao[i]);
1404        }
1405        try {
1406            int state = nd.getState();
1407            int type = nd.getType();
1408            nd.remove();
1409            jms.sendNodeEvent(DELETENODE,this.getName(),name,type,state,this.getCaller());
1410        } catch (RemoveException JavaDoc re) {
1411            if (this.getProjectConfigTrace())
1412                trace.error("Cannot remove node " + re.getMessage());
1413            throw new HeroException("Cannot remove node " + re.getMessage());
1414        }
1415    }
1416    
1417    /**
1418     * Delete an edge to the project. If out node of this edge is in executing, terminated or cancelled state, the
1419     * method throws an execption.
1420     *
1421     * @param name the name ot the edge
1422     *
1423     * @ejb:interface-method view-type="both"
1424     * @ejb:transaction type="Required"
1425     * @throws HeroException
1426     *
1427     **/

1428    public void deleteEdge(String JavaDoc name) throws HeroException {
1429        // check deletion conditions
1430
if (this.getProjectConfigTrace())
1431            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
1432        BnEdgeLocalHome eh;
1433        BnEdgeLocal ed;
1434        if (!isAdminOfProject(this.getCaller()))
1435        {
1436            if (this.getProjectConfigTrace())
1437                trace.error("Only the Admin of the project is allowed to do this operation... ");
1438            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1439        }
1440        try {
1441            eh = BnEdgeUtil.getLocalHome();
1442        } catch (javax.naming.NamingException JavaDoc ne) {
1443            if (this.getProjectConfigTrace())
1444                trace.error(ne.getMessage());
1445            throw new HeroException(ne.getMessage());
1446        }
1447        try {
1448            ed = eh.findByName(name, mProject.getId());
1449        } catch (FinderException JavaDoc fe) {
1450            if (this.getProjectConfigTrace())
1451                trace.error("edge does not exists " + fe.getMessage());
1452            throw new HeroException("edge does not exists " + name);
1453        }
1454        String JavaDoc nodeIn = ed.getInBnNode().getName();
1455        String JavaDoc nodeOut = ed.getOutBnNode().getName();
1456        edgeDeletion(ed);
1457        jms.sendEdgeEvent(DELETEEDGE,this.getName(),name,nodeIn,nodeOut,this.getCaller());
1458    }
1459    
1460    /** Actually deletes an edge and restore the state of the outgoing node
1461     * <strong>Not a business method</strong>
1462     **/

1463    
1464    public void edgeDeletion(BnEdgeLocal ed) throws HeroException {
1465        BnNodeLocal nd = ed.getOutBnNode();
1466        if (this.getProjectConfigTrace())
1467            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
1468        if (!isAdminOfProject(this.getCaller()))
1469        {
1470            if (this.getProjectConfigTrace())
1471                trace.error("Only the Admin of the project is allowed to do this operation... ");
1472            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1473        }
1474        if (nd.isExecuting()) {
1475            throw new DeleteEdgeException("Cannot delete edge. Out node executing");
1476        }
1477        /* if (nd.isTerminated()) {
1478         throw new DeleteEdgeException("Cannot delete edge. Out node terminated");
1479         }
1480         if (nd.isCancelled()) {
1481         throw new DeleteEdgeException("Cannot delete edge. Out node cancelled");
1482         }*/

1483        try {
1484            ed.remove();
1485            int newOperation = nd.getActivation().state(nd);
1486            int newState = nd.getTransition().computeState(nd, newOperation);
1487            if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
1488                throw new HeroException("AddEdge generated a bad BnNode transition");
1489            }
1490            if (!mProject.getType().equals(Constants.Pj.MODEL))
1491                this.setNodeState(nd, newState);
1492        } catch (RemoveException JavaDoc e) {
1493            if (this.getProjectConfigTrace())
1494                trace.error("deleteNode failed " + e.getMessage());
1495            throw new HeroException("deleteNode failed " + e.getMessage());
1496        }
1497    }
1498    
1499    
1500    /**
1501     * Detete a hook. Delete a Java or aTCL hook of this project. </strong>
1502     *
1503     * @param hookName the name of the hook
1504     * @ejb:interface-method view-type="both"
1505     * @ejb:transaction type="Required"
1506     * @throws HeroException
1507     *
1508     **/

1509    public void deleteHook(String JavaDoc hookName) throws HeroException {
1510        if (this.getProjectConfigTrace())
1511            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
1512        BnProjectHookLocalHome pHome;
1513        BnProjectHookLocal ppLocal;
1514        if (!isAdminOfProject(this.getCaller()))
1515        {
1516            if (this.getProjectConfigTrace())
1517                trace.error("Only the Admin of the project is allowed to do this operation... ");
1518            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1519        }
1520        try {
1521            pHome = BnProjectHookUtil.getLocalHome();
1522        } catch (javax.naming.NamingException JavaDoc ne) {
1523            if (this.getProjectConfigTrace())
1524                trace.error(ne.getMessage());
1525            throw new HeroException(ne.getMessage());
1526        }
1527        
1528        try {
1529            BnProjectHookLocal ph = pHome.findByName(mProject.getId(), hookName);
1530            ph.remove();
1531        } catch (FinderException JavaDoc fe) {
1532            if (this.getProjectConfigTrace())
1533                trace.error(fe.getMessage());
1534            throw new HeroException(fe.getMessage());
1535        } catch (RemoveException JavaDoc rm) {
1536            if (this.getProjectConfigTrace())
1537                trace.error(rm.getMessage());
1538            throw new HeroException(rm.getMessage());
1539        }
1540    }
1541    
1542    /**
1543     * Delete a node hook. Delete a Java or a TCL hook of this node. </strong>
1544     *
1545     * @param nodeName the name of the node
1546     * @param hookName the name
1547     * @ejb:interface-method view-type="both"
1548     * @ejb:transaction type="Required"
1549     * @throws HeroException
1550     *
1551     **/

1552    public void deleteNodeHook(String JavaDoc nodeName, String JavaDoc hookName)
1553    throws HeroException {
1554        if (this.getProjectConfigTrace())
1555            trace.info("parameters: nodename=" + nodeName + "Hookname=" + hookName + " process name = " + this.getName()+ " started by " + this.getCaller());
1556        BnNodeHookLocalHome pHome;
1557        BnNodeHookLocal ppLocal;
1558        BnNodeLocal nd = mProject.getBnNode(nodeName);
1559        if (!isAdminOfProject(this.getCaller()))
1560        {
1561            if (this.getProjectConfigTrace())
1562                trace.error("Only the Admin of the project is allowed to do this operation... ");
1563            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1564        }
1565        try {
1566            pHome = BnNodeHookUtil.getLocalHome();
1567        } catch (javax.naming.NamingException JavaDoc ne) {
1568            if (this.getProjectConfigTrace())
1569                trace.error(ne.getMessage());
1570            throw new HeroException(ne.getMessage());
1571        }
1572        try {
1573            BnNodeHookLocal nh = pHome.findByName(nd.getId(), hookName);
1574            nh.remove();
1575        } catch (FinderException JavaDoc fe) {
1576            if (this.getProjectConfigTrace())
1577                trace.error(fe.getMessage());
1578            throw new HeroException(fe.getMessage());
1579        } catch (RemoveException JavaDoc rm) {
1580            if (this.getProjectConfigTrace())
1581                trace.error(rm.getMessage());
1582            throw new HeroException(rm.getMessage());
1583        }
1584    }
1585    
1586    /**
1587     * Delete a node interHook.
1588     *
1589     * @param nodeName the name of the node
1590     * @param hookName the name of the interHook
1591     * @ejb:interface-method view-type="both"
1592     * @ejb:transaction type="Required"
1593     * @throws HeroException
1594     *
1595     **/

1596    public void deleteNodeInterHook(String JavaDoc nodeName, String JavaDoc interHookName)
1597    throws HeroException {
1598        if (this.getProjectConfigTrace())
1599            trace.info("parameters: nodename=" + nodeName + "InerhookName=" + interHookName + " process name = " + this.getName()+ " started by " + this.getCaller());
1600        BnNodeInterHookLocalHome pHome;
1601        BnNodeInterHookLocal ppLocal;
1602        BnNodeLocal nd = mProject.getBnNode(nodeName);
1603        if (!isAdminOfProject(this.getCaller()))
1604        {
1605            if (this.getProjectConfigTrace())
1606                trace.error("Only the Admin of the project is allowed to do this operation... ");
1607            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1608        }
1609        try {
1610            pHome = BnNodeInterHookUtil.getLocalHome();
1611        } catch (javax.naming.NamingException JavaDoc ne) {
1612            if (this.getProjectConfigTrace())
1613                trace.error(ne.getMessage());
1614            throw new HeroException(ne.getMessage());
1615        }
1616        try {
1617            BnNodeInterHookLocal nh =
1618                pHome.findByName(nd.getId(), interHookName);
1619            nh.remove();
1620        } catch (FinderException JavaDoc fe) {
1621            if (this.getProjectConfigTrace())
1622                trace.error(fe.getMessage());
1623            throw new HeroException(fe.getMessage());
1624        } catch (RemoveException JavaDoc rm) {
1625            if (this.getProjectConfigTrace())
1626                trace.error(rm.getMessage());
1627            throw new HeroException(rm.getMessage());
1628        }
1629    }
1630    
1631    /**
1632     * Detete a interHook of this project. This method deletes this hook from all projects nodes.
1633     *
1634     * @param hookName the name of the hook
1635     * @ejb:interface-method view-type="both"
1636     * @ejb:transaction type="Required"
1637     * @throws HeroException
1638     *
1639     **/

1640    public void deleteInterHook(String JavaDoc interHookName) throws HeroException {
1641        BnProjectInterHookLocalHome pHome;
1642        BnProjectInterHookLocal ppLocal;
1643        if (this.getProjectConfigTrace())
1644            trace.info("parameter: interhookName=" + interHookName + " process name = " + this.getName()+ " started by " + this.getCaller());
1645        if (!isAdminOfProject(this.getCaller()))
1646        {
1647            if (this.getProjectConfigTrace())
1648                trace.error("Only the Admin of the project is allowed to do this operation... ");
1649            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1650        }
1651        try {
1652            pHome = BnProjectInterHookUtil.getLocalHome();
1653        } catch (javax.naming.NamingException JavaDoc ne) {
1654            if (this.getProjectConfigTrace())
1655                trace.error(ne.getMessage());
1656            throw new HeroException(ne.getMessage());
1657        }
1658        
1659        try {
1660            BnProjectInterHookLocal ph =
1661                pHome.findByName(mProject.getId(), interHookName);
1662            ph.remove();
1663        } catch (FinderException JavaDoc fe) {
1664            if (this.getProjectConfigTrace())
1665                trace.error(fe.getMessage());
1666            throw new HeroException(fe.getMessage());
1667        } catch (RemoveException JavaDoc rm) {
1668            if (this.getProjectConfigTrace())
1669                trace.error(rm.getMessage());
1670            throw new HeroException(rm.getMessage());
1671        }
1672    }
1673    
1674    /**
1675     * Delete a role mapper.
1676     *
1677     * @param roleName the name of the node
1678     * @param roleName name
1679     * @ejb:interface-method view-type="both"
1680     * @ejb:transaction type="Required"
1681     * @throws HeroException
1682     *
1683     **/

1684    public void deleteRoleMapper(String JavaDoc roleName) throws HeroException {
1685        if (this.getProjectConfigTrace())
1686            trace.info("parameter: roleName=" + roleName + " process name = " + this.getName()+ " started by " + this.getCaller());
1687        BnRoleLocalHome pHome;
1688        BnRoleMapperLocal mapperL;
1689        BnRoleLocal roleL;
1690        if (!isAdminOfProject(this.getCaller()))
1691        {
1692            if (this.getProjectConfigTrace())
1693                trace.error("Only the Admin of the project is allowed to do this operation... ");
1694            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1695        }
1696        try {
1697            pHome = BnRoleUtil.getLocalHome();
1698        } catch (javax.naming.NamingException JavaDoc ne) {
1699            if (this.getProjectConfigTrace())
1700                trace.error(ne.getMessage());
1701            throw new HeroException(ne.getMessage());
1702        }
1703        
1704        try {
1705            roleL = pHome.findByName(roleName, mProject.getId());
1706            mapperL = roleL.getBnRoleMapper();
1707        } catch (FinderException JavaDoc fe) {
1708            if (this.getProjectConfigTrace())
1709                trace.error(fe.getMessage());
1710            throw new HeroException(fe.getMessage());
1711        }
1712        
1713        try {
1714            mapperL.remove();
1715        } catch (RemoveException JavaDoc rm) {
1716            if (this.getProjectConfigTrace())
1717                trace.error(rm.getMessage());
1718            throw new HeroException(rm.getMessage());
1719        }
1720    }
1721    
1722    /**
1723     * Delete a property of the project. Deletes the project property associated to this key.
1724     *
1725     * @param key the key of the property
1726     * @ejb:interface-method view-type="both"
1727     * @ejb:transaction type="Required"
1728     * @throws HeroException
1729     *
1730     **/

1731    public void deleteProperty(String JavaDoc key) throws HeroException {
1732        if (this.getProjectConfigTrace())
1733            trace.info("parameter: key=" + key + " process name = " + this.getName()+ " started by " + this.getCaller());
1734        
1735        BnProjectPropertyLocalHome pHome;
1736        BnProjectPropertyLocal ppLocal;
1737        if (!isAdminOfProject(this.getCaller()))
1738        {
1739            if (this.getProjectConfigTrace())
1740                trace.error("Only the Admin of the project is allowed to do this operation... ");
1741            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1742        }
1743        try {
1744            pHome = BnProjectPropertyUtil.getLocalHome();
1745        } catch (javax.naming.NamingException JavaDoc ne) {
1746            if (this.getProjectConfigTrace())
1747                trace.error(ne.getMessage());
1748            throw new HeroException(ne.getMessage());
1749        }
1750        Collection JavaDoc c = null;
1751        try {
1752            c = pHome.findByTheKey(mProject.getId(), key);
1753        } catch (FinderException JavaDoc fe) {
1754            if (this.getProjectConfigTrace())
1755                trace.error(fe.getMessage());
1756            throw new HeroException(fe.getMessage());
1757        }
1758        
1759        if (!c.isEmpty()) {
1760            try {
1761                ppLocal = (BnProjectPropertyLocal) (c.toArray())[0];
1762                ppLocal.remove();
1763            } catch (RemoveException JavaDoc rm) {
1764                if (this.getProjectConfigTrace())
1765                    trace.error(rm.getMessage());
1766                throw new HeroException(rm.getMessage());
1767            }
1768            
1769        } else {
1770            throw new HeroException("Property not found :" + key);
1771        }
1772    }
1773    
1774    /**
1775     * Delete a property of a node. Deletes the node property associated to this key
1776     *
1777     * @param nodeName the name of the node
1778     * @param key the key of the property
1779     * @ejb:interface-method view-type="both"
1780     * @ejb:transaction type="Required"
1781     * @throws HeroException
1782     *
1783     **/

1784    public void deleteNodeProperty(String JavaDoc nodeName, String JavaDoc key)
1785    throws HeroException {
1786        if (this.getProjectConfigTrace())
1787            trace.info("parameters: node=" + nodeName + " key=" + key + " process name = " + this.getName()+ " started by " + this.getCaller());
1788        
1789        BnNodePropertyLocalHome pHome;
1790        BnNodePropertyLocal propertyLocal = null;
1791        if (!isAdminOfProject(this.getCaller()))
1792        {
1793            if (this.getProjectConfigTrace())
1794                trace.error("Only the Admin of the project is allowed to do this operation... ");
1795            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1796        }
1797        BnNodeLocal nd = mProject.getBnNode(nodeName);
1798        
1799        try {
1800            pHome = BnNodePropertyUtil.getLocalHome();
1801        } catch (javax.naming.NamingException JavaDoc ne) {
1802            if (this.getProjectConfigTrace())
1803                trace.error(ne.getMessage());
1804            throw new HeroException(ne.getMessage());
1805        }
1806        Collection JavaDoc c = null;
1807        try {
1808            c = pHome.findByTheKey(nd.getId(), key);
1809        } catch (FinderException JavaDoc fe) {
1810            if (this.getProjectConfigTrace())
1811                trace.error(fe.getMessage());
1812            throw new HeroException(fe.getMessage());
1813        }
1814        
1815        if (!c.isEmpty()) {
1816            try {
1817                propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
1818                propertyLocal.remove();
1819            } catch (RemoveException JavaDoc rm) {
1820                if (this.getProjectConfigTrace())
1821                    trace.error(rm.getMessage());
1822                throw new HeroException(rm.getMessage());
1823            }
1824            
1825        } else {
1826            throw new HeroException("Property not found :" + key);
1827        }
1828    }
1829    
1830    // -------------------------------------------------------------------------
1831
// Set business methods
1832
// -------------------------------------------------------------------------
1833

1834    /**
1835     * Set a trace level of the actual project.
1836     *
1837     * @param level the trace level
1838     *
1839     * @ejb:interface-method view-type="local"
1840     * @ejb:transaction type="Required"
1841     * @throws HeroException
1842     *
1843     **/

1844    public void setTraceLevel(String JavaDoc level) throws HeroException {
1845        if (this.getProjectConfigTrace())
1846            trace.info("parameters: level=" + level + " process name = " + this.getName()+ " started by " + this.getCaller());
1847        if (!isAdminOfProject(this.getCaller()))
1848        {
1849            if (this.getProjectConfigTrace())
1850                trace.error("Only the Admin of the project is allowed to do this operation... ");
1851            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1852        }
1853        if (level.equals(Constants.INFO))
1854            trace.setLevel(Level.INFO);
1855        else if (level.equals(Constants.DEBUG))
1856            trace.setLevel(Level.DEBUG);
1857        else if (level.equals(Constants.ERROR))
1858            trace.setLevel(Level.ERROR);
1859    }
1860    
1861    /**
1862     * Set a log level of the actual project.
1863     *
1864     * @param level the log level
1865     *
1866     * @ejb:interface-method view-type="local"
1867     * @ejb:transaction type="Required"
1868     * @throws HeroException
1869     *
1870     **/

1871    public void setLogLevel(String JavaDoc level) throws HeroException {
1872        if (this.getProjectConfigTrace())
1873            trace.info("parameters: level=" + level + " process name = " + this.getName()+ " started by " + this.getCaller());
1874        if (!isAdminOfProject(this.getCaller()))
1875        {
1876            if (this.getProjectConfigTrace())
1877                trace.error("Only the Admin of the project is allowed to do this operation... ");
1878            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1879        }
1880        if (level.equals(Constants.INFO))
1881            thelog.setLevel(Level.INFO);
1882        else if (level.equals(Constants.DEBUG))
1883            thelog.setLevel(Level.DEBUG);
1884        else if (level.equals(Constants.ERROR))
1885            thelog.setLevel(Level.ERROR);
1886    }
1887    
1888    
1889    /**
1890     * Set a role to this user. This role is assigned to the user in the context of
1891     * the actual project.
1892     *
1893     * @param userName the name of the user
1894     * @param roleName the name of the role
1895     *
1896     * @ejb:interface-method view-type="both"
1897     * @ejb:transaction type="Required"
1898     * @throws HeroException
1899     *
1900     **/

1901    public void setUserRole(String JavaDoc userName, String JavaDoc roleName)
1902    throws HeroException {
1903        if (this.getProjectConfigTrace())
1904            trace.info("parameters: user=" + userName + " role=" + roleName + " process name = " + this.getName()+ " started by " + this.getCaller());
1905        BnRoleLocalHome roleh;
1906        BnUserLocalHome userh;
1907        UserServiceLocalHome ushome;
1908        UserServiceLocal ul;
1909        if (!isAdminOfProject(this.getCaller()))
1910        {
1911            if (this.getProjectConfigTrace())
1912                trace.error("Only the Admin of the project is allowed to do this operation... ");
1913            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1914        }
1915        try {
1916            roleh = BnRoleUtil.getLocalHome();
1917            userh = BnUserUtil.getLocalHome();
1918            ushome= hero.interfaces.UserServiceUtil.getLocalHome();
1919        } catch (javax.naming.NamingException JavaDoc ne) {
1920            if (this.getProjectConfigTrace())
1921                trace.error(ne.getMessage());
1922            throw new HeroException(ne.getMessage());
1923        }
1924        try {
1925            ul = ushome.create();
1926            BnUserLocal user = ul.findUser(userName);
1927            
1928            BnRoleLocal role = roleh.findByName(roleName, mProject.getId());
1929            user.getBnRoles().add(role);
1930            jms.sendUserRoleEvent(SETUSERROLE,this.getName(),userName,roleName);
1931        } catch (Exception JavaDoc fe) {
1932            if (this.getProjectConfigTrace())
1933                trace.error(fe.getMessage());
1934            throw new HeroException(fe.getMessage());
1935        }
1936    }
1937    
1938    /**
1939     * Sets the role of an activity. Changes the role of this activity
1940     *
1941     * @param name the name of the activity
1942     * @param role the name of the role
1943     *
1944     * @ejb:interface-method view-type="both"
1945     * @ejb:transaction type="Required"
1946     * @throws HeroException
1947     *
1948     **/

1949    public void setNodeRole(String JavaDoc name, String JavaDoc role) throws HeroException {
1950        if (this.getProjectConfigTrace())
1951            trace.info("parameters: name=" + name + " role=" + role + " process name = " + this.getName()+ " started by " + this.getCaller());
1952        BnRoleLocalHome rh;
1953        BnNodeLocalHome nh;
1954        BnNodeLocal nl;
1955        BnRoleLocal rl;
1956        if (!isAdminOfProject(this.getCaller()))
1957        {
1958            if (this.getProjectConfigTrace())
1959                trace.error("Only the Admin of the project is allowed to do this operation... ");
1960            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
1961        }
1962        try {
1963            rh = BnRoleUtil.getLocalHome();
1964            nh = BnNodeUtil.getLocalHome();
1965        } catch (javax.naming.NamingException JavaDoc ne) {
1966            if (this.getProjectConfigTrace())
1967                trace.error(ne.getMessage());
1968            throw new HeroException(ne.getMessage());
1969        }
1970        try {
1971            nl = nh.findByName(name, mProject.getId());
1972        } catch (FinderException JavaDoc fe) {
1973            if (this.getProjectConfigTrace())
1974                trace.error("BnNode does not exists " + fe.getMessage());
1975            throw new HeroException("BnNode does not exists " + name);
1976        }
1977        try {
1978            rl = rh.findByName(role, mProject.getId());
1979        } catch (FinderException JavaDoc fe) {
1980            if (this.getProjectConfigTrace())
1981                trace.error("BnRole does not exists " + fe.getMessage());
1982            throw new HeroException("BnRole does not exists " + role);
1983        }
1984        nl.setBnRole(rl);
1985        jms.sendProjectEvent(CHANGEROLE, this.getName());
1986    }
1987    
1988    /**
1989     * Set edit node changes. Only for GraphEditor client
1990     *
1991     * @param name of the node
1992     * @param role of the node
1993     * @param description of the node
1994     * @param deadline of the node
1995     * @ejb:interface-method view-type="both"
1996     * @ejb:transaction type="Required"
1997     *
1998     **/

1999    public void setEditNode(String JavaDoc node, String JavaDoc role, String JavaDoc description, long deadline) throws HeroException {
2000        if (this.getProjectConfigTrace())
2001            trace.debug("setEditNode: node=" + node + " role=" + role +" description=" + description + " deadline=" + deadline);
2002        if (!isAdminOfProject(this.getCaller()))
2003        {
2004            if (this.getProjectConfigTrace())
2005                trace.error("Only the Admin of the project is allowed to do this operation... ");
2006            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2007        }
2008        this.setNodeDeadline(node,deadline);
2009        this.setNodeDescription(node,description);
2010        this.setNodeRole(node,role);
2011    }
2012    
2013    /**
2014     * Set the edge condition. This condition is evaluated at run-time in order to perform activity transition.
2015     * To set the condition you have to use beanshell language (Lightweight Scripting for Java).<br>
2016     * <strong>The next line illustrates the use of setEdgeCondition method:<br><br></strong>
2017     *
2018     * ...<br>
2019     * String condition = "partial_status.equals(\"ok\")";<br>
2020     * <strong>yourProjectSessionInstance</strong>.setEdgeCondition("edgeName",condition);<br><br>
2021     *
2022     * The engine evaluates on the fly the condition by using the If statement. In the previous sample,
2023     * if the value of the property "partial_status" is equals to "ok" the result of this condition is true.
2024     *
2025     * @param edge edge name
2026     * @param condition condition of the edge
2027     * @ejb:interface-method view-type="both"
2028     * @ejb:transaction type="Required"
2029     * @throws HeroException
2030     *
2031     **/

2032    public void setEdgeCondition(String JavaDoc edge, String JavaDoc condition)
2033    throws HeroException {
2034        if (this.getProjectConfigTrace())
2035            trace.info("parameters: name=" + edge + " condition=" + condition + " process name = " + this.getName()+ " started by " + this.getCaller());
2036        if (!isAdminOfProject(this.getCaller()))
2037        {
2038            if (this.getProjectConfigTrace())
2039                trace.error("Only the Admin of the project is allowed to do this operation... ");
2040            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2041        }
2042        BnEdgeLocal e = mProject.getBnEdge(edge);
2043        e.setCondition(condition);
2044    }
2045    
2046    /**
2047     * Set the node deadline. Activity deadline is the lastest date in which the activity must be finished.
2048     *
2049     * @param name the name of the node
2050     * @param date date of the deadline
2051     * @ejb:interface-method view-type="both"
2052     * @ejb:transaction type="Required"
2053     * @throws HeroException
2054     * @deprecated replaced by setDeadlines(String name, Collection co)
2055     *
2056     **/

2057    public void setNodeDeadline(String JavaDoc name, long date) throws HeroException {
2058        if (this.getProjectConfigTrace())
2059            trace.info("parameters: name=" + name + " deadline=" + date + " process name = " + this.getName()+ " started by " + this.getCaller());
2060        if (!isAdminOfProject(this.getCaller()))
2061        {
2062            if (this.getProjectConfigTrace())
2063                trace.error("Only the Admin of the project is allowed to do this operation... ");
2064            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2065        }
2066        if (new java.sql.Date JavaDoc(date).before(new Date JavaDoc()))
2067            throw new HeroException("This date is before the current date !!");
2068        
2069        //Call setNodeDeadlines()
2070
ArrayList JavaDoc ar = new ArrayList JavaDoc();
2071        ar.add(new Long JavaDoc(date));
2072        setNodeDeadlines(name, ar);
2073    }
2074    
2075    /**
2076     * Set a collection of deadlines for the node.
2077     * Activity deadline is the lastest date in which the activity must be finished.
2078     *
2079     * @param name the name of the node
2080     * @param co collection of dates of the deadline
2081     * @ejb:interface-method view-type="both"
2082     * @ejb:transaction type="Required"
2083     * @throws HeroException
2084     *
2085     **/

2086    public void setNodeDeadlines(String JavaDoc name, Collection JavaDoc co) throws HeroException {
2087        Iterator JavaDoc it = co.iterator();
2088        
2089        if (this.getProjectConfigTrace())
2090            trace.info("parameters: name=" + name + " collection of deadlines " + " process name = " + this.getName()+ " started by " + this.getCaller());
2091            while (it.hasNext()){
2092                trace.info("deadline = " + ((Long JavaDoc)it.next()).longValue() );
2093            }
2094        if (!isAdminOfProject(this.getCaller()))
2095        {
2096            if (this.getProjectConfigTrace())
2097                trace.error("Only the Admin of the project is allowed to do this operation... ");
2098            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2099        }
2100        // set the collection of deadlines
2101
it = co.iterator();
2102        ArrayList JavaDoc ar = new ArrayList JavaDoc();
2103        BnNodeLocal nd = mProject.getBnNode(name);
2104        while (it.hasNext()){
2105            long d = ((Long JavaDoc)it.next()).longValue();
2106            if (new java.sql.Date JavaDoc(d).before(new Date JavaDoc()))
2107                throw new HeroException("The date of the deadline : " + d + " is before the current date !!");
2108            Date JavaDoc date = new java.sql.Date JavaDoc(d);
2109            ar.add(date);
2110        }
2111        nd.setDeadlines(ar);
2112
2113        if (nd.getState()== Constants.Nd.READY && nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE))
2114            BonitaDeadline.getInstance().startDeadlines(name, mProject.getId());
2115            
2116        String JavaDoc projectName = this.getName();
2117        jms.sendNodeEvent(SETNODEDEADLINES,projectName,name,nd.getType(),nd.getState(),this.getCaller());
2118        
2119    }
2120
2121    /**
2122     * Set a collection of relativeDeadlines for the node.
2123     *
2124     * @param name the name of the node
2125     * @param co collection of dates of the deadline
2126     * @ejb:interface-method view-type="both"
2127     * @ejb:transaction type="Required"
2128     * @throws HeroException
2129     *
2130     **/

2131    public void setNodeRelativeDeadlines(String JavaDoc name, Collection JavaDoc co) throws HeroException {
2132        Iterator JavaDoc it = co.iterator();
2133        
2134        if (this.getProjectConfigTrace())
2135            trace.info("parameters: name=" + name + " collection of relativeDeadlines " + " process name = " + this.getName()+ " started by " + this.getCaller());
2136            while (it.hasNext()){
2137                trace.info("deadline = " + ((Long JavaDoc)it.next()).longValue() );
2138            }
2139        if (!isAdminOfProject(this.getCaller()))
2140        {
2141            if (this.getProjectConfigTrace())
2142                trace.error("Only the Admin of the project is allowed to do this operation... ");
2143            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2144        }
2145        // set the collection of relativeDeadlines
2146
it = co.iterator();
2147        ArrayList JavaDoc ar = new ArrayList JavaDoc();
2148        BnNodeLocal nd = mProject.getBnNode(name);
2149        while (it.hasNext()){
2150            long d = ((Long JavaDoc)it.next()).longValue();
2151            Date JavaDoc date = new java.sql.Date JavaDoc(d);
2152            ar.add(date);
2153        }
2154        nd.setRelativeDeadlines(ar);
2155
2156        if (nd.getState()== Constants.Nd.READY && nd.getBnProject().getType().equals(Constants.Pj.COOPERATIVE))
2157            BonitaDeadline.getInstance().startDeadlines(name, mProject.getId());
2158            
2159        String JavaDoc projectName = this.getName();
2160        jms.sendNodeEvent(SETNODEDEADLINES,projectName,name,nd.getType(),nd.getState(),this.getCaller());
2161        
2162    }
2163    
2164    /**
2165     * Set the node relative deadline. Activity deadline is the lastest date in which the activity must be finished.
2166     *
2167     * @param name the name of the node
2168     * @param date date of the deadline
2169     * @ejb:interface-method view-type="both"
2170     * @ejb:transaction type="Required"
2171     * @throws HeroException
2172     * @deprecated replaced by setRelativeDeadlines(String name, Collection co)
2173     *
2174     **/

2175    public void setNodeRelativeDeadline(String JavaDoc name, long date) throws HeroException {
2176        if (this.getProjectConfigTrace())
2177            trace.info("parameters: name=" + name + " deadline=" + date + " process name = " + this.getName()+ " started by " + this.getCaller());
2178        if (!isAdminOfProject(this.getCaller()))
2179        {
2180            if (this.getProjectConfigTrace())
2181                trace.error("Only the Admin of the project is allowed to do this operation... ");
2182            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2183        }
2184        //Call setNodeRelativeDeadlines()
2185
ArrayList JavaDoc ar = new ArrayList JavaDoc();
2186        ar.add(new Long JavaDoc(date));
2187        setNodeRelativeDeadlines(name, ar);
2188    }
2189    
2190    /**
2191     * Set the node description. Node description represents, explicity, execution related information
2192     * of this task.
2193     *
2194     * @param name the name of the node
2195     * @param descriptio description of the node
2196     * @ejb:interface-method view-type="both"
2197     * @ejb:transaction type="Required"
2198     * @throws HeroException
2199     *
2200     **/

2201    public void setNodeDescription(String JavaDoc name, String JavaDoc description)
2202    throws HeroException {
2203        if (this.getProjectConfigTrace())
2204            trace.info("parameters: name="+ name+ " description="+ description + " process name = " + this.getName()+ " started by " + this.getCaller());
2205        if (!isAdminOfProject(this.getCaller()))
2206        {
2207            if (this.getProjectConfigTrace())
2208                trace.error("Only the Admin of the project is allowed to do this operation... ");
2209            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2210        }
2211        BnNodeLocal nd = mProject.getBnNode(name);
2212        nd.setDescription(description);
2213    }
2214    
2215    /**
2216     * Set the node hook value.
2217     *
2218     * @param name name of the node
2219     * @param hook hookName of the node
2220     * @param value new script value of this hook
2221     * @ejb:interface-method view-type="both"
2222     * @ejb:transaction type="Required"
2223     * @throws HeroException
2224     *
2225     **/

2226    public void setNodeInterHookValue(String JavaDoc node, String JavaDoc hook, String JavaDoc value)
2227    throws HeroException {
2228        if (this.getProjectConfigTrace())
2229            trace.info("parameters: node="+ node+ " hook="+ hook+ " value="+ value+ " process name = " + this.getName()+ " started by " + this.getCaller());
2230        if (!isAdminOfProject(this.getCaller()))
2231        {
2232            if (this.getProjectConfigTrace())
2233                trace.error("Only the Admin of the project is allowed to do this operation... ");
2234            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2235        }
2236        BnNodeLocal nd = mProject.getBnNode(node);
2237        Collection JavaDoc hooks = nd.getBnInterHooks();
2238        for (Iterator JavaDoc ih = hooks.iterator(); ih.hasNext();) {
2239            BnNodeInterHookLocal hk = (BnNodeInterHookLocal) ih.next();
2240            if (hk.getName().equals(hook)) {
2241                hk.setScript(value);
2242            }
2243        }
2244    }
2245    
2246    /**
2247     * Set the hook value. This value is the new hook script associated to all project nodes
2248     *
2249     * @param hook hookName of the node
2250     * @param value new script value of this hook
2251     * @ejb:interface-method view-type="both"
2252     * @ejb:transaction type="Required"
2253     * @throws HeroException
2254     *
2255     **/

2256    public void setInterHookValue(String JavaDoc hook, String JavaDoc value)
2257    throws HeroException {
2258        if (this.getProjectConfigTrace())
2259            trace.info("parameters: hook=" + hook + " value=" + value+ " process name = " + this.getName()+ " started by " + this.getCaller());
2260        if (!isAdminOfProject(this.getCaller()))
2261        {
2262            if (this.getProjectConfigTrace())
2263                trace.error("Only the Admin of the project is allowed to do this operation... ");
2264            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2265        }
2266        Collection JavaDoc hooks = mProject.getBnInterHooks();
2267        for (Iterator JavaDoc ih = hooks.iterator(); ih.hasNext();) {
2268            BnProjectInterHookLocal hk = (BnProjectInterHookLocal) ih.next();
2269            if (hk.getName().equals(hook)) {
2270                hk.setScript(value);
2271            }
2272        }
2273    }
2274    
2275    /**
2276     * Unset a user role in this project.
2277     *
2278     * @param userName name of the user
2279     * @param roleName name of the role
2280     * @ejb:interface-method view-type="both"
2281     * @ejb:transaction type="Required"
2282     * @throws HeroException
2283     *
2284     **/

2285    
2286    public void unsetUserRole(String JavaDoc userName, String JavaDoc roleName) throws HeroException{
2287        if (this.getProjectConfigTrace())
2288            trace.info("parameters: userName=" + userName + " roleName=" + roleName + " process name = " + this.getName()+ " started by " + this.getCaller());
2289        BnUserLocal mUser;
2290        BnUserLocalHome uHome;
2291        BnRoleLocalHome rHome;
2292        BnRoleLocal mRole;
2293        UserServiceLocalHome ushome;
2294        UserServiceLocal ul;
2295        if (!isAdminOfProject(this.getCaller()))
2296        {
2297            if (this.getProjectConfigTrace())
2298                trace.error("Only the Admin of the project is allowed to do this operation... ");
2299            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2300        }
2301        try {
2302            uHome = hero.interfaces.BnUserUtil.getLocalHome();
2303            rHome = hero.interfaces.BnRoleUtil.getLocalHome();
2304            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
2305        } catch (javax.naming.NamingException JavaDoc be) {
2306            if (this.getProjectConfigTrace())
2307                trace.error(be.getMessage());
2308            throw new HeroException(be.getMessage());
2309        }
2310        try {
2311            ul = ushome.create();
2312            mUser = ul.findUser(userName);
2313        } catch (Exception JavaDoc fe) {
2314            if (this.getProjectConfigTrace())
2315                trace.error("User does not exist " + fe.getMessage());
2316            throw new HeroException("User does not exist");
2317        }
2318        
2319        Collection JavaDoc userRoles = this.getUserRolesInProject(userName);
2320        Iterator JavaDoc i = userRoles.iterator();
2321        while (i.hasNext())
2322        {
2323            BnRoleValue role = (BnRoleValue)i.next();
2324            if (role.getName().equals(roleName))
2325            {
2326                try {
2327                    mRole = rHome.findByName(role.getName(),mProject.getId());
2328                    mUser.getBnRoles().remove(mRole);
2329                } catch (javax.ejb.FinderException JavaDoc fe) {
2330                    if (this.getProjectConfigTrace())
2331                        trace.error("Role does not exist " + fe.getMessage());
2332                    throw new HeroException("Role does not exist");
2333                }
2334            }
2335        }
2336        
2337        jms.sendUserRoleEvent(UNSETUSERROLE,this.getName(),userName,roleName);
2338    }
2339    
2340    /**
2341     * Unset a user for this project
2342     *
2343     * @param userName The name of the user
2344     *
2345     * @ejb:interface-method view-type="both"
2346     * @ejb:transaction type="Required"
2347     * @throws HeroException
2348     *
2349     **/

2350    public void unsetUser(String JavaDoc userName) throws HeroException {
2351        if (this.getProjectConfigTrace())
2352            trace.info(" Parameter: name=" + userName + " process name = "+this.getName()+ " started by " + this.getCaller());
2353        UserServiceLocalHome ushome;
2354        UserServiceLocal ul;
2355        if (!isAdminOfProject(this.getCaller()))
2356        {
2357            if (this.getProjectConfigTrace())
2358                trace.error("Only the Admin of the project is allowed to do this operation... ");
2359            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2360        }
2361        BnUserLocalHome uHome;
2362        BnRoleLocalHome rHome;
2363        BnUserLocal mUser;
2364        try {
2365            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
2366            uHome = hero.interfaces.BnUserUtil.getLocalHome();
2367            rHome = hero.interfaces.BnRoleUtil.getLocalHome();
2368        } catch (javax.naming.NamingException JavaDoc be) {
2369            if (this.getProjectConfigTrace())
2370                trace.error(be.getMessage());
2371            throw new HeroException(be.getMessage());
2372        }
2373        try {
2374            ul = ushome.create();
2375            mUser = ul.findUser(userName);
2376        } catch (Exception JavaDoc fe) {
2377            if (this.getProjectConfigTrace())
2378                trace.error("User does not exist " + fe.getMessage());
2379            throw new HeroException("User does not exist");
2380        }
2381        Collection JavaDoc cUsers = mProject.getBnUsers();
2382        if (cUsers.contains(mUser))
2383            mProject.getBnUsers().remove(mUser);
2384        else
2385        {
2386            if (this.getProjectConfigTrace())
2387                trace.error("User does not exist in the project...");
2388            throw new HeroException("User does not exist in the project");
2389        }
2390                
2391    }
2392    
2393    /**
2394     * Set the node in traditional mode. When a node is traditional the anticipable attribute is false. This
2395     * method must be used if you want to execute this activity in a traditional model.
2396     *
2397     * @param name name of the node
2398     * @ejb:interface-method view-type="both"
2399     * @ejb:transaction type="Required"
2400     * @throws HeroException
2401     *
2402     **/

2403    public void setNodeTraditional(String JavaDoc name) throws HeroException {
2404        if (this.getProjectConfigTrace())
2405            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
2406        if (!isAdminOfProject(this.getCaller()))
2407        {
2408            if (this.getProjectConfigTrace())
2409                trace.error("Only the Admin of the project is allowed to do this operation... ");
2410            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2411        }
2412        BnNodeLocal nd = mProject.getBnNode(name);
2413        nd.setAnticipable(false);
2414        nd.setTransition(NodeState.make(nd.getType(), false));
2415    }
2416    
2417    /**
2418     * Set the node in anticipable mode.
2419     *
2420     * @param name the name of the node
2421     * @ejb:interface-method view-type="both"
2422     * @ejb:transaction type="Required"
2423     * @throws HeroException
2424     *
2425     **/

2426    public void setNodeAnticipable(String JavaDoc name) throws HeroException {
2427        if (this.getProjectConfigTrace())
2428            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
2429        if (!isAdminOfProject(this.getCaller()))
2430        {
2431            if (this.getProjectConfigTrace())
2432                trace.error("Only the Admin of the project is allowed to do this operation... ");
2433            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2434        }
2435        BnNodeLocal nd = mProject.getBnNode(name);
2436        nd.setAnticipable(true);
2437        nd.setTransition(NodeState.make(nd.getType(), true));
2438    }
2439    
2440    /**
2441     * Set the node in automatic mode. The responsible of the activity execution is now the engine.
2442     *
2443     * @param name the name of the node
2444     * @ejb:interface-method view-type="both"
2445     * @ejb:transaction type="Required"
2446     * @throws HeroException
2447     *
2448     **/

2449    public void setNodeAutomatic(String JavaDoc name) throws HeroException {
2450        if (this.getProjectConfigTrace())
2451            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
2452        if (!isAdminOfProject(this.getCaller()))
2453        {
2454            if (this.getProjectConfigTrace())
2455                trace.error("Only the Admin of the project is allowed to do this operation... ");
2456            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2457        }
2458        BnNodeLocal nd = mProject.getBnNode(name);
2459        //nd.setAutomatic(true);
2460
nd.setTransition(NodeState.make(5, true));
2461        //nd.setTransition(NodeState.make(nd.getType(),true));
2462
// this.addNodeHok(name,"hero.hook.AutomaticHook",hero.interfaces.Constants.Nd.CREATE,Hook.JAVA);
2463
}
2464    
2465    /**
2466     * Set the node type. Change the current type of the node (if node is not executing).<br><br>
2467     *
2468     * Possibles node types are:<br>
2469     * hero.interfaces.Constants.Nd.AND_JOIN_NODE<br>
2470     * hero.interfaces.Constants.Nd.OR_JOIN_NODE<br>
2471     * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE<br>
2472     * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE<br>
2473     *
2474     * @param name the name of the node
2475     * @ejb:interface-method view-type="both"
2476     * @ejb:transaction type="Required"
2477     * @throws HeroException
2478     *
2479     **/

2480    public void setNodeType(String JavaDoc name, int type) throws HeroException {
2481        if (this.getProjectConfigTrace())
2482            trace.info("parameters: name=" + name + " type" + type + " process name = " + this.getName()+ " started by " + this.getCaller());
2483        if (!isAdminOfProject(this.getCaller()))
2484        {
2485            if (this.getProjectConfigTrace())
2486                trace.error("Only the Admin of the project is allowed to do this operation... ");
2487            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2488        }
2489        BnNodeLocal nd = mProject.getBnNode(name);
2490        nd.setType(type);
2491        nd.setTransition(NodeState.make(nd.getType(), true));
2492        nd.setActivation(EdgeState.make(nd.getType()));
2493    }
2494    
2495    /**
2496     * Set a property of a node. A property is a pair key/value representing workflow relevant data. By using
2497     * propagate argument we can specify if we want to propagate this property.
2498     *
2499     * @param nodeName the name of the node
2500     * @param key the key of the property
2501     * @param value the name of the property
2502     * @param propagate if it is a propagation property
2503     * @ejb:interface-method view-type="both"
2504     * @ejb:transaction type="Required"
2505     * @throws HeroException
2506     *
2507     **/

2508    public void setNodeProperty(String JavaDoc nodeName,String JavaDoc key,String JavaDoc value,boolean propagate)
2509    throws HeroException {
2510        BnNodePropertyLocalHome pHome;
2511        BnNodePropertyLocal propertyLocal;
2512        if (!isAdminOfProject(this.getCaller()))
2513        {
2514            if (mProject.getName().matches(".*_instance.*") && !isUserInNodeRole(nodeName))
2515            {
2516                if (this.getProjectConfigTrace())
2517                    trace.error("You are not allowed to set/update properties of this node... ");
2518                throw new HeroException("You are not allowed to set/update properties of this node... ");
2519            }
2520        }
2521        if (this.getProjectConfigTrace())
2522            trace.info("parameters: node="+ nodeName+ " key="+ key+ " value="+ value + " process name = " + this.getName()+ " started by " + this.getCaller());
2523        
2524        BnNodeLocal nd = mProject.getBnNode(nodeName);
2525        
2526        try {
2527            pHome = BnNodePropertyUtil.getLocalHome();
2528        } catch (javax.naming.NamingException JavaDoc ne) {
2529            if (this.getProjectConfigTrace())
2530                trace.error(ne.getMessage());
2531            throw new HeroException(ne.getMessage());
2532        }
2533        Collection JavaDoc c = null;
2534        try {
2535            c = pHome.findByTheKey(nd.getId(), key);
2536        } catch (FinderException JavaDoc fe) {
2537            if (this.getProjectConfigTrace())
2538                trace.error(fe.getMessage());
2539            throw new HeroException(fe.getMessage());
2540        }
2541        if (!c.isEmpty()) {
2542            propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
2543            propertyLocal.setTheValue(value);
2544            propertyLocal.setPropagate(propagate);
2545        } else {
2546            try {
2547                propertyLocal = pHome.create(key, value);
2548                propertyLocal.setBnNode(nd);
2549                propertyLocal.setPropagate(propagate);
2550            } catch (InvalidValueException ie) {
2551                if (this.getProjectConfigTrace())
2552                    trace.error(ie.getMessage());
2553                throw new HeroException(ie.getMessage());
2554            } catch (javax.ejb.CreateException JavaDoc ce) {
2555                if (this.getProjectConfigTrace())
2556                    trace.error(ce.getMessage());
2557                throw new HeroException(ce.getMessage());
2558            }
2559        }
2560    }
2561    
2562    /**
2563     * Set a property of a node. A property is a pair key/value representing workflow relevant data. With
2564     * this method the property is propagated within others nodes.
2565     *
2566     * @param nodeName the name of the node
2567     * @param key the key of the property
2568     * @param value the name of the property
2569     * @ejb:interface-method view-type="both"
2570     * @ejb:transaction type="Required"
2571     * @throws HeroException
2572     *
2573     **/

2574    
2575    public void setNodeProperty(String JavaDoc nodeName, String JavaDoc key, String JavaDoc value)
2576    throws HeroException {
2577        BnNodePropertyLocalHome pHome;
2578        BnNodePropertyLocal propertyLocal = null;
2579        
2580        if (!isAdminOfProject(this.getCaller()))
2581        {
2582            if (mProject.getName().matches(".*_instance.*") && !isUserInNodeRole(nodeName))
2583            {
2584                if (this.getProjectConfigTrace())
2585                    trace.error("You are not allowed to set/update properties of this node... ");
2586                throw new HeroException("You are not allowed to set/update properties of this node... ");
2587            }
2588        }
2589        if (this.getProjectConfigTrace())
2590            trace.info("parameters: node="+ nodeName+ " key="+ key+ " value="+ value + " process name = " + this.getName()+ " started by " + this.getCaller());
2591        BnNodeLocal nd = mProject.getBnNode(nodeName);
2592        
2593        try {
2594            pHome = BnNodePropertyUtil.getLocalHome();
2595        } catch (javax.naming.NamingException JavaDoc ne) {
2596            if (this.getProjectConfigTrace())
2597                trace.error(ne.getMessage());
2598            throw new HeroException(ne.getMessage());
2599        }
2600        Collection JavaDoc c = null;
2601        try {
2602            c = pHome.findByTheKey(nd.getId(), key);
2603        } catch (FinderException JavaDoc fe) {
2604            if (this.getProjectConfigTrace())
2605                trace.error(fe.getMessage());
2606            throw new HeroException(fe.getMessage());
2607        }
2608        
2609        if (!c.isEmpty()) {
2610            
2611            propertyLocal = (BnNodePropertyLocal) (c.toArray())[0];
2612            if (propertyLocal.getPossibleValues() == null || propertyLocal.getPossibleValues().contains(value))
2613                propertyLocal.setTheValue(value);
2614            else
2615                throw new HeroException("This value is not one of possibles values defined for the property...");
2616
2617            
2618        } else {
2619            try {
2620                propertyLocal = pHome.create(key, value);
2621                propertyLocal.setBnNode(nd);
2622                
2623            } catch (InvalidValueException ie) {
2624                if (this.getProjectConfigTrace())
2625                    trace.error(ie.getMessage());
2626                throw new HeroException(ie.getMessage());
2627            } catch (javax.ejb.CreateException JavaDoc ce) {
2628                if (this.getProjectConfigTrace())
2629                    trace.error(ce.getMessage());
2630                throw new HeroException(ce.getMessage());
2631            }
2632        }
2633    }
2634    
2635    /**
2636     * Set a property of the project. A property is a pair key/value representing workflow relevant data. This
2637     * methods creates a new property that can be accessed from all activites of the project.
2638     *
2639     * @param key the key of the property
2640     * @param value the name of the property
2641     * @ejb:interface-method view-type="both"
2642     * @ejb:transaction type="Required"
2643     * @throws HeroException
2644     *
2645     **/

2646    public void setProperty(String JavaDoc key, String JavaDoc value) throws HeroException {
2647        if (this.getProjectConfigTrace())
2648            trace.info("parameters: key=" + key + " value=" + value + " process name = " + this.getName()+ " started by " + this.getCaller());
2649        if (!isAdminOfProject(this.getCaller()))
2650        {
2651            if (this.getProjectConfigTrace())
2652                trace.error("Only the Admin of the project is allowed to do this operation... ");
2653            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2654        }
2655        BnProjectPropertyLocalHome pHome;
2656        BnProjectPropertyLocal ppLocal = null;
2657        
2658        try {
2659            pHome = BnProjectPropertyUtil.getLocalHome();
2660        } catch (javax.naming.NamingException JavaDoc ne) {
2661            if (this.getProjectConfigTrace())
2662                trace.error(ne.getMessage());
2663            throw new HeroException(ne.getMessage());
2664        }
2665        Collection JavaDoc c = null;
2666        try {
2667            c = pHome.findByTheKey(mProject.getId(), key);
2668        } catch (FinderException JavaDoc fe) {
2669            if (this.getProjectConfigTrace())
2670                trace.error(fe.getMessage());
2671            throw new HeroException(fe.getMessage());
2672        }
2673        
2674        if (!c.isEmpty()) {
2675            
2676            ppLocal = (BnProjectPropertyLocal) (c.toArray())[0];
2677            if (ppLocal.getPossibleValues() == null || ppLocal.getPossibleValues().contains(value))
2678                ppLocal.setTheValue(value);
2679            else
2680                throw new HeroException("This value is not one of possibles values defined for the property...");
2681            
2682        } else {
2683            try {
2684                ppLocal = pHome.create(key, value);
2685                ppLocal.setBnProject(mProject);
2686                
2687            } catch (InvalidValueException ie) {
2688                if (this.getProjectConfigTrace())
2689                    trace.error(ie.getMessage());
2690                throw new HeroException(ie.getMessage());
2691            } catch (javax.ejb.CreateException JavaDoc ce) {
2692                if (this.getProjectConfigTrace())
2693                    trace.error(ce.getMessage());
2694                throw new HeroException(ce.getMessage());
2695            }
2696        }
2697    }
2698    
2699    /**
2700     * Set property possible values for a specific node. Values argument represent the values which are accepted
2701     * as possible property values.
2702     *
2703     * @param nodeName the name of the node
2704     * @param key property key
2705     * @param values possible values
2706     * @ejb:interface-method view-type="both"
2707     * @ejb:transaction type="Required"
2708     * @throws HeroException
2709     *
2710     **/

2711    public void setNodePropertyPossibleValues(String JavaDoc nodeName, String JavaDoc key, Collection JavaDoc values)
2712    throws HeroException {
2713        BnNodePropertyLocalHome pHome;
2714        BnNodePropertyLocal propertyLocal;
2715        if (!isAdminOfProject(this.getCaller()))
2716        {
2717            if (mProject.getName().matches(".*_instance.*") && !isUserInNodeRole(nodeName))
2718            {
2719                if (this.getProjectConfigTrace())
2720                    trace.error("You are not allowed to set/update properties of this node... ");
2721                throw new HeroException("You are not allowed to set/update properties of this node... ");
2722            }
2723        }
2724        if (this.getProjectConfigTrace())
2725            trace.info("parameters: node="+ nodeName+ " key="+ key+ " values="+ values + " process name = " + this.getName()+ " started by " + this.getCaller());
2726        
2727        BnNodeLocal nd = mProject.getBnNode(nodeName);
2728        
2729        try {
2730            pHome = BnNodePropertyUtil.getLocalHome();
2731        } catch (javax.naming.NamingException JavaDoc ne) {
2732            if (this.getProjectConfigTrace())
2733                trace.error(ne.getMessage());
2734            throw new HeroException(ne.getMessage());
2735        }
2736        Collection JavaDoc c = null;
2737        try {
2738            c = pHome.findByTheKey(nd.getId(), key);
2739        } catch (FinderException JavaDoc fe) {
2740            if (this.getProjectConfigTrace())
2741                trace.error(fe.getMessage());
2742            throw new HeroException(fe.getMessage());
2743        }
2744        if (c.isEmpty()) {
2745            try {
2746                propertyLocal = pHome.create(key, values);
2747                propertyLocal.setBnNode(nd);
2748            } catch (InvalidValueException ie) {
2749                if (this.getProjectConfigTrace())
2750                    trace.error(ie.getMessage());
2751                throw new HeroException(ie.getMessage());
2752            } catch (javax.ejb.CreateException JavaDoc ce) {
2753                if (this.getProjectConfigTrace())
2754                    trace.error(ce.getMessage());
2755                throw new HeroException(ce.getMessage());
2756            }
2757        }
2758    }
2759    
2760    /**
2761     * Set property possible values. Values argument represent the values which are accepted
2762     * as possible property values.
2763     *
2764     * @param key property key
2765     * @param values possible values
2766     * @ejb:interface-method view-type="both"
2767     * @ejb:transaction type="Required"
2768     * @throws HeroException
2769     *
2770     **/

2771    public void setPropertyPossibleValues(String JavaDoc key, Collection JavaDoc values)
2772    throws HeroException {
2773        BnProjectPropertyLocalHome pHome;
2774        BnProjectPropertyLocal propertyLocal;
2775        if (!isAdminOfProject(this.getCaller()))
2776        {
2777            if (this.getProjectConfigTrace())
2778                trace.error("Only the Admin of the project is allowed to do this operation... ");
2779            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2780        }
2781        if (this.getProjectConfigTrace())
2782            trace.info("parameters: key="+ key+ " values="+ values + " process name = " + this.getName()+ " started by " + this.getCaller());
2783                
2784        try {
2785            pHome = BnProjectPropertyUtil.getLocalHome();
2786        } catch (javax.naming.NamingException JavaDoc ne) {
2787            if (this.getProjectConfigTrace())
2788                trace.error(ne.getMessage());
2789            throw new HeroException(ne.getMessage());
2790        }
2791        Collection JavaDoc c = null;
2792        try {
2793            c = pHome.findByTheKey(mProject.getId(),key);
2794        } catch (FinderException JavaDoc fe) {
2795            if (this.getProjectConfigTrace())
2796                trace.error(fe.getMessage());
2797            throw new HeroException(fe.getMessage());
2798        }
2799        if (c.isEmpty()) {
2800            try {
2801                propertyLocal = pHome.create(key, values);
2802                propertyLocal.setBnProject(mProject);
2803            } catch (InvalidValueException ie) {
2804                if (this.getProjectConfigTrace())
2805                    trace.error(ie.getMessage());
2806                throw new HeroException(ie.getMessage());
2807            } catch (javax.ejb.CreateException JavaDoc ce) {
2808                if (this.getProjectConfigTrace())
2809                    trace.error(ce.getMessage());
2810                throw new HeroException(ce.getMessage());
2811            }
2812        }
2813    }
2814    
2815    // -------------------------------------------------------------------------
2816
// Set Methods only accessibles by the workflow Engine
2817
// -------------------------------------------------------------------------
2818

2819    /**
2820     * Execute a node hook.
2821     *
2822     * @param nodeName the name of the node
2823     * @param event the event
2824     * @ejb:interface-method view-type="local"
2825     * @ejb:transaction type="Supports"
2826     * @throws HeroException
2827     *
2828     **/

2829    public void hookEvent(String JavaDoc nodeName, String JavaDoc event) throws HeroException {
2830        if (this.getProjectConfigTrace())
2831            trace.info("parameters: node=" + nodeName + " event=" + event + " process name = " + this.getName()+ " started by " + this.getCaller());
2832        if (!isAdminOfProject(this.getCaller()))
2833        {
2834            if (this.getProjectConfigTrace())
2835                trace.error("Only the Admin of the project is allowed to do this operation... ");
2836            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
2837        }
2838        Collection JavaDoc hooks;
2839        BnNodeLocal node;
2840        
2841        node = mProject.getBnNode(nodeName);
2842        hooks = node.getBnHooks();
2843        for (Iterator JavaDoc i = hooks.iterator(); i.hasNext();) {
2844            BnNodeHookLocal hk = (BnNodeHookLocal) i.next();
2845            if (hk.getEvent().equalsIgnoreCase(event)) {
2846                hero.hook.Hook h =
2847                    hero.hook.Hook.make(hk.getName(), event, hk.getType());
2848                h.execute(this, event, node);
2849            }
2850        }
2851    }
2852    
2853    
2854    /**
2855     * Propagate node properties. Propagates all node properties to connected nodes.
2856     * @param nodeName the name of the Node
2857     * @ejb:interface-method view-type="local"
2858     * @ejb:transaction type="Required"
2859     * @throws HeroException
2860     *
2861     **/

2862    public void propagateNodeProperties(String JavaDoc nodeName) throws HeroException {
2863        if (this.getProjectConfigTrace())
2864            trace.info("parameter: name=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
2865        
2866        BnNodePropertyLocalHome pHome;
2867        BnNodePropertyLocal propertyLocal = null;
2868        
2869        BnNodeLocal nd = mProject.getBnNode(nodeName);
2870        
2871        Collection JavaDoc c = nd.getBnProperties();
2872        Collection JavaDoc c2 = nd.getOutBnEdges();
2873
2874        if ((!c.isEmpty()) && (!c2.isEmpty())) {
2875            BnNodePropertyLocal p;
2876            BnEdgeLocal ed;
2877            for (Iterator JavaDoc i = c.iterator(); i.hasNext();) {
2878                p = (BnNodePropertyLocal) i.next();
2879                for (Iterator JavaDoc i2 = c2.iterator(); i2.hasNext();) {
2880                    ed = (BnEdgeLocal) i2.next();
2881                    if (p.getPropagate())
2882                    {
2883                        this.setNodePropertyPossibleValues((ed.getOutBnNode()).getName(),p.getTheKey(),p.getPossibleValues());
2884                        if (p.getTheValue()!=null || p.getPossibleValues().size()==0)
2885                            this.setNodeProperty((ed.getOutBnNode()).getName(),p.getTheKey(),p.getTheValue(),true);
2886                    }
2887                }
2888            }
2889        }
2890    }
2891    
2892    
2893    /**
2894     * Set the node state. Set start date of this node when starts the execution and the end date when node
2895     * is terminated.
2896     *
2897     * @param name name of the node
2898     * @param state new state of the node
2899     * @ejb:interface-method view-type="local"
2900     * @ejb:transaction type="Required"
2901     * @throws HeroException
2902     *
2903     **/

2904    public void setNodeState(BnNodeLocal node, int state) throws HeroException {
2905        if (this.getProjectConfigTrace())
2906            trace.info("parameters: name=" + node.getName() + " state=" + state + " process name = " + this.getName()+ " started by " + this.getCaller());
2907        
2908        node.setState(state);
2909        if (state == hero.interfaces.Constants.Nd.EXECUTING || state == hero.interfaces.Constants.Nd.ANTICIPATING) {
2910            node.setStartDate(new java.util.Date JavaDoc());
2911        }
2912        else if (state == hero.interfaces.Constants.Nd.TERMINATED) {
2913            if (!(node.getStartDate() !=null))
2914                node.setStartDate(new java.util.Date JavaDoc());
2915            node.setEndDate(new java.util.Date JavaDoc());
2916            //this.propagateNodeProperties(node.getName());
2917
}
2918        else if (state == hero.interfaces.Constants.Nd.DEAD)
2919        {
2920            if (!(node.getStartDate() !=null))
2921                node.setStartDate(new java.util.Date JavaDoc());
2922            node.setEndDate(new java.util.Date JavaDoc());
2923        }
2924        jms.sendNodeEvent(SETNODESTATE,this.getName(),node.getName(),node.getType(),state,this.getCaller());
2925    }
2926    
2927    /**
2928     * Set all initial roles to ready if node does not has in edges.
2929     *
2930     * @ejb:interface-method view-type="local"
2931     * @ejb:transaction type="Required"
2932     * @throws HeroException
2933     *
2934     **/

2935    public void setNodesReady() throws HeroException {
2936        if (this.getProjectConfigTrace())
2937            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
2938        try{
2939            Collection JavaDoc nodes = mProject.getBnNodes();
2940            Iterator JavaDoc nds = nodes.iterator();
2941            while (nds.hasNext()) // first activities are initial
2942
{
2943                BnNodeLocal subNode = (BnNodeLocal)nds.next();
2944                if (this.getNodeInEdges(subNode.getName()).size()==0 && subNode.getState()==Constants.Nd.INITIAL
2945                    && (subNode.getType()==Constants.Nd.AND_JOIN_AUTOMATIC_NODE || subNode.getType()==Constants.Nd.OR_JOIN_AUTOMATIC_NODE))
2946                {
2947                    this.setNodeState(subNode,Constants.Nd.READY);
2948                    EngineLocalHome enghome;
2949                    try {
2950                        enghome = hero.interfaces.EngineUtil.getLocalHome();
2951                        EngineLocal engine = enghome.create();
2952                        engine.startActivity(mProject.getName(), subNode.getName());
2953                    } catch (javax.naming.NamingException JavaDoc ne) {
2954                        throw new HeroException(ne.getMessage());
2955                    }
2956                }
2957                else if (this.getNodeInEdges(subNode.getName()).size()==0 && subNode.getState()==Constants.Nd.INITIAL)
2958                    this.setNodeState(subNode,Constants.Nd.READY);
2959            }
2960        }catch (Exception JavaDoc ans){
2961            if (this.getProjectConfigTrace())
2962                trace.error("Error in setNodeReady " + ans.getMessage());
2963            throw new HeroException("Error in setNodeReady");
2964        }
2965    }
2966    
2967    /**
2968     * Propagate subProcess activity properties to subProcess
2969     *
2970     * @param node the name of the node
2971     * @ejb:interface-method view-type="local"
2972     * @ejb:transaction type="Required"
2973     * @throws HeroException
2974     *
2975     **/

2976    
2977    public void propagatesParentProperties(String JavaDoc node) throws HeroException {
2978        if (this.getProjectConfigTrace())
2979            trace.info("parameter: nodeName=" + node + " process name = " + this.getName()+ " started by " + this.getCaller());
2980        BnProjectLocal pl = mProject;
2981        try{
2982            Collection JavaDoc props = mProject.getBnNode(node).getBnProperties();
2983            this.initProject(node);
2984            Iterator JavaDoc i = props.iterator();
2985            while (i.hasNext())
2986            {
2987                BnNodePropertyLocal prop = (BnNodePropertyLocal)i.next();
2988                this.setPropertyPossibleValues(prop.getTheKey(),prop.getPossibleValues());
2989                if (prop.getTheValue()!=null || prop.getPossibleValues().size()==0)
2990                    this.setProperty(prop.getTheKey(),prop.getTheValue());
2991            }
2992            this.setNodesReady();
2993            mProject=pl;
2994        }catch (Exception JavaDoc ans){ans.printStackTrace();
2995            mProject=pl;
2996            if (this.getProjectConfigTrace())
2997                trace.error("Error in propagatesParentProperties " + ans.getMessage());
2998            throw new HeroException("Error in propagatesParentProperties");}
2999    }
3000    
3001    /**
3002     * Propagate subProcess properties to subProcess activity.
3003     *
3004     * @param node the name of the node
3005     * @ejb:interface-method view-type="local"
3006     * @ejb:transaction type="Required"
3007     * @throws HeroException
3008     *
3009     **/

3010    
3011    public void propagatesSubProcessProperties(String JavaDoc node) throws HeroException {
3012        if (this.getProjectConfigTrace())
3013            trace.info("parameter: nodeName=" + node + " process name = " + this.getName()+ " started by " + this.getCaller());
3014        BnProjectLocal pl = mProject;
3015        try{
3016            this.initProject(node);
3017            Collection JavaDoc props = this.getProperties();
3018            mProject = pl;
3019            Iterator JavaDoc i = props.iterator();
3020            while (i.hasNext())
3021            {
3022                BnProjectPropertyValue prop = (BnProjectPropertyValue)i.next();
3023                this.setNodePropertyPossibleValues(node,prop.getTheKey(),prop.getPossibleValues());
3024                if (prop.getTheValue()!=null || prop.getPossibleValues().size()==0)
3025                    this.setNodeProperty(node,prop.getTheKey(),prop.getTheValue(),true);
3026            }
3027        }catch (Exception JavaDoc ans){ans.printStackTrace();
3028        mProject=pl;
3029        if (this.getProjectConfigTrace())
3030            trace.error("Error in propagatesSubProcessProperties " + ans.getMessage());
3031        throw new HeroException("Error in propagatesSubProcessProperties ");}
3032    }
3033    
3034    /**
3035     * Set the edge state
3036     *
3037     * @param bean of the edge
3038     * @param new state of the edge
3039     * @ejb:interface-method view-type="local"
3040     * @ejb:transaction type="Required"
3041     * @throws HeroException
3042     *
3043     **/

3044    public void setEdgeState(BnEdgeLocal edge, int state)
3045    throws HeroException {
3046        if (this.getProjectConfigTrace())
3047            trace.info("parameters: name=" + edge.getName() + " state=" + state + " process name = " + this.getName()+ " started by " + this.getCaller());
3048        edge.setState(state);
3049        jms.sendEdgeEvent(SETEDGESTATE,this.getName(),edge.getName(),edge.getInBnNode().getName(),edge.getOutBnNode().getName(),this.getCaller());
3050    }
3051    
3052    /**
3053     * Set the agent state
3054     *
3055     * @param agent bean of the Agent
3056     * @param new state of the Agent
3057     * @ejb:interface-method view-type="both"
3058     * @ejb:transaction type="Required"
3059     * @throws HeroException
3060     *
3061     **/

3062    public void setAgentState(BnAgentLocal agent, int state)
3063    throws HeroException {
3064        if (this.getProjectConfigTrace())
3065            trace.info("parameters: name=" + agent.getName() + " state=" + state + " state=" + state + " process name = " + this.getName()+ " started by " + this.getCaller());
3066        agent.setState(state);
3067        // jms.sendEdgeEvent(SETEDGESTATE,this.getName(),edge.getName(),edge.getInBnNode().getName(),edge.getOutBnNode().getName(),this.getCaller());
3068
}
3069    
3070    /**
3071     * Set the agentEdge state
3072     *
3073     * @param agentEdge bean of the BnAgentEdge
3074     * @param new state of the BnAgentEdge
3075     * @ejb:interface-method view-type="local"
3076     * @ejb:transaction type="Required"
3077     * @throws HeroException
3078     *
3079     **/

3080    public void setAgentEdgeState(BnAgentEdgeLocal agentEdge, int state)
3081    throws HeroException {
3082        if (this.getProjectConfigTrace())
3083            trace.info("parameters: name="+ agentEdge.getName()+ " state="+ state + " state=" + state + " process name = " + this.getName()+ " started by " + this.getCaller());
3084        agentEdge.setState(state);
3085        // jms.sendEdgeEvent(SETEDGESTATE,this.getName(),edge.getName(),edge.getInBnNode().getName(),edge.getOutBnNode().getName(),this.getCaller());
3086
}
3087    
3088    /**
3089     * Set the name of the node executor. Set the name of the user which is executing the activity.
3090     *
3091     * @param name the name of the node
3092     * @ejb:interface-method view-type="local"
3093     * @ejb:transaction type="Required"
3094     * @throws HeroException
3095     *
3096     **/

3097    public void setNodeExecutor(String JavaDoc name) throws HeroException {
3098        if (this.getProjectConfigTrace())
3099            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3100        
3101        BnUserLocalHome uHome;
3102        BnUserLocal user;
3103        try {
3104            uHome = BnUserUtil.getLocalHome();
3105        } catch (javax.naming.NamingException JavaDoc ne) {
3106            if (this.getProjectConfigTrace())
3107                trace.error(ne.getMessage());
3108            throw new HeroException(ne.getMessage());
3109        }
3110        BnNodeLocal nd = mProject.getBnNode(name);
3111        String JavaDoc executor = this.getCaller();
3112        Collection JavaDoc users = mProject.getBnUsers();
3113        Iterator JavaDoc i = users.iterator();
3114        while (i.hasNext())
3115        {
3116            BnUserLocal ul = (BnUserLocal)i.next();
3117            if (ul.getName().equals(executor))
3118            {
3119                nd.setExecutor(executor);
3120                break;
3121            }
3122        }
3123        /*try {
3124            user = uHome.findByName(executor);
3125        } catch (FinderException fe) {
3126            if (this.getProjectConfigTrace())
3127                trace.error("BnUser " + executor + " does not exists " + fe.getMessage());
3128            throw new HeroException("BnUser " + executor + " does not exists");
3129        }
3130        nd.setExecutor(user);*/

3131        jms.sendNodeEvent(SETNODEEXECUTOR,this.getName(),name,nd.getType(),nd.getState(),this.getCaller());
3132    }
3133    
3134    
3135    // -------------------------------------------------------------------------
3136
// Get business methods
3137
// -------------------------------------------------------------------------
3138

3139    /**
3140     * Get the node description. Node description represents, explicity, execution related information
3141     * of this task.
3142     *
3143     * @param name of the node
3144     * @return String - description of the node
3145     * @ejb:interface-method view-type="both"
3146     * @ejb:transaction type="Supports"
3147     * @throws HeroException
3148     *
3149     **/

3150    public String JavaDoc getNodeDescription(String JavaDoc name) throws HeroException {
3151        if (this.getProjectConfigTrace())
3152            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3153        BnNodeLocal nd = mProject.getBnNode(name);
3154        return (nd.getDescription());
3155    }
3156    
3157    /**
3158     * Get the node hook value. This method returns the hook script associated to this node
3159     *
3160     * @param name the name of the node
3161     * @param hook hookName of the node
3162     * @return String - script associated to this hook
3163     * @ejb:interface-method view-type="both"
3164     * @ejb:transaction type="Supports"
3165     * @throws HeroException
3166     *
3167     **/

3168    public String JavaDoc getNodeInterHookValue(String JavaDoc node, String JavaDoc hook)
3169    throws HeroException {
3170        if (!isAdminOfProject(this.getCaller()))
3171        {
3172            if (this.getProjectConfigTrace())
3173                trace.error("Only the Admin of the project is allowed to do this operation... ");
3174            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
3175        }
3176        String JavaDoc value = null;
3177        if (this.getProjectConfigTrace())
3178            trace.info("parameters: node=" + node + " hook=" + hook + " process name = " + this.getName()+ " started by " + this.getCaller());
3179        BnNodeLocal nd = mProject.getBnNode(node);
3180        Collection JavaDoc hooks = nd.getBnInterHooks();
3181        for (Iterator JavaDoc ih = hooks.iterator(); ih.hasNext();) {
3182            BnNodeInterHookLocal hk = (BnNodeInterHookLocal) ih.next();
3183            if (hk.getName().equals(hook)) {
3184                value = hk.getScript();
3185            }
3186        }
3187        return value;
3188    }
3189    
3190    /**
3191     * Get the inter hook value script. This method returns the hook script associated to all project nodes.
3192     *
3193     * @param hook hook name
3194     * @return String - script associated to this hook
3195     * @ejb:interface-method view-type="both"
3196     * @ejb:transaction type="Supports"
3197     * @throws HeroException
3198     *
3199     **/

3200    public String JavaDoc getInterHookValue(String JavaDoc hook) throws HeroException {
3201        String JavaDoc value = null;
3202        if (!isAdminOfProject(this.getCaller()))
3203        {
3204            if (this.getProjectConfigTrace())
3205                trace.error("Only the Admin of the project is allowed to do this operation... ");
3206            throw new AdminException("Only the Admin of the project is allowed to do this operation... ");
3207        }
3208        if (this.getProjectConfigTrace())
3209            trace.info("parameter: hook=" + hook + " process name = " + this.getName()+ " started by " + this.getCaller());
3210        Collection JavaDoc hooks = mProject.getBnInterHooks();
3211        for (Iterator JavaDoc ih = hooks.iterator(); ih.hasNext();) {
3212            BnProjectInterHookLocal hk = (BnProjectInterHookLocal) ih.next();
3213            if (hk.getName().equals(hook)) {
3214                value = hk.getScript();
3215            }
3216        }
3217        return value;
3218    }
3219    
3220    /**
3221     * Get the ProjectValue (historique). Returns project information: project attributes, nodes, edges,
3222     * hooks, properties...
3223     *
3224     * @return BnProjectValue object - project data
3225     * @ejb:interface-method view-type="both"
3226     * @ejb:transaction type="Required"
3227     * @throws HeroException
3228     *
3229     **/

3230    public BnProjectValue getDetails() throws HeroException {
3231        if (this.getProjectConfigTrace())
3232            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3233        return mProject.getBnProjectValue();
3234    }
3235    
3236    /**
3237     * Get ProjectName
3238     * @return String - project name
3239     *
3240     * @ejb:interface-method view-type="both"
3241     * @ejb:transaction type="Supports"
3242     * @throws HeroException
3243     *
3244     **/

3245    public String JavaDoc getName() throws HeroException {
3246        if (mProject!=null)
3247        {
3248            trace.info(" process name = " + mProject.getName()+ " started by " + this.getCaller());
3249            return mProject.getName();
3250        }
3251        return null;
3252    }
3253    
3254    /**
3255     * Get creator of the project. The user that created the project
3256     * @return String - project creator
3257     *
3258     * @ejb:interface-method view-type="both"
3259     * @ejb:transaction type="Supports"
3260     * @throws HeroException
3261     *
3262     **/

3263    
3264    public String JavaDoc getCreator() throws HeroException {
3265        if (this.getProjectConfigTrace())
3266            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3267        return mProject.getCreator();
3268    }
3269    
3270    /**
3271     * Get status of the project. Active/Hidden
3272     * @return String - project status
3273     *
3274     * @ejb:interface-method view-type="both"
3275     * @ejb:transaction type="Supports"
3276     * @throws HeroException
3277     *
3278     **/

3279    
3280    public String JavaDoc getStatus() throws HeroException {
3281        if (this.getProjectConfigTrace())
3282            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3283        return mProject.getStatus();
3284    }
3285    
3286    /**
3287     * Get type of the project. Cooperative/Model/Instance
3288     * @return String - project type
3289     *
3290     * @ejb:interface-method view-type="both"
3291     * @ejb:transaction type="Supports"
3292     * @throws HeroException
3293     *
3294     **/

3295    
3296    public String JavaDoc getType() throws HeroException {
3297        if (this.getProjectConfigTrace())
3298            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3299        return mProject.getType();
3300    }
3301    
3302    
3303    /**
3304     * Get all roles of the project
3305     * @return Collection of BnRoleLocal objects - roles of the project
3306     *
3307     * @ejb:interface-method view-type="both"
3308     * @ejb:transaction type="Supports"
3309     * @throws HeroException
3310     *
3311     **/

3312    public Collection JavaDoc getRoles() throws HeroException {
3313        if (this.getProjectConfigTrace())
3314            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3315        Collection JavaDoc roles = mProject.getBnRoles();
3316        ArrayList JavaDoc result = new ArrayList JavaDoc();
3317        for (Iterator JavaDoc i = roles.iterator(); i.hasNext();) {
3318            result.add((BnRoleLocal) i.next());
3319        }
3320        return result;
3321    }
3322    
3323    /**
3324     * Get all roles values of the project
3325     * @return Collection of BnRoleValue objects - roles of the project
3326     *
3327     * @ejb:interface-method view-type="both"
3328     * @ejb:transaction type="Supports"
3329     * @throws HeroException
3330     *
3331     **/

3332    public Collection JavaDoc getRolesValue() throws HeroException {
3333        if (this.getProjectConfigTrace())
3334            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3335        Collection JavaDoc roles = mProject.getBnRoles();
3336        ArrayList JavaDoc result = new ArrayList JavaDoc();
3337        for (Iterator JavaDoc i = roles.iterator(); i.hasNext();) {
3338            BnRoleLocal rl =(BnRoleLocal) i.next();
3339            result.add(rl.getBnRoleValue());
3340        }
3341        return result;
3342    }
3343    
3344    /**
3345     * Get the value of this role in the project
3346     * @return BnRoleValue - role of the project
3347     *
3348     * @ejb:interface-method view-type="both"
3349     * @ejb:transaction type="Supports"
3350     * @throws HeroException
3351     *
3352     **/

3353    public BnRoleValue getRoleValue(String JavaDoc roleName) throws HeroException {
3354        if (this.getProjectConfigTrace())
3355            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3356        try {
3357            BnRoleLocalHome roleh = (BnRoleLocalHome)BnRoleUtil.getLocalHome();
3358            BnRoleLocal rolel = roleh.findByName(roleName, mProject.getId());
3359            return (rolel.getBnRoleValue());
3360        } catch (Exception JavaDoc pfe) {
3361            throw new HeroException("This Role does not exist in this project : " + roleName);
3362        }
3363    }
3364    
3365    /**
3366     * Get performer assign of this node.
3367     *
3368     * @return BnNodePerformerAssignValue of this node
3369     *
3370     * @param nodeName the name of the node
3371     * @ejb:interface-method view-type="both"
3372     * @ejb:transaction type="Required"
3373     * @throws HeroException
3374     *
3375     **/

3376    public BnNodePerformerAssignValue getNodePerformerAssign(String JavaDoc nodeName) throws HeroException {
3377        // logs trace
3378
if (this.getProjectConfigTrace())
3379            trace.debug("parameter: nodeName=" + nodeName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3380                                
3381        BnNodeLocal node = null;
3382    
3383        // Get objet node local with findByName from BnNodeBean
3384
try {
3385            BnNodeLocalHome nodeh = (BnNodeLocalHome)BnNodeUtil.getLocalHome();
3386            node = nodeh.findByName(nodeName, mProject.getId());
3387        } catch (Exception JavaDoc pfe) {
3388            throw new HeroException("The bnNode does not exist for node : " + nodeName);
3389        }
3390        if (node.getBnNodePerformerAssign()!=null)
3391            return (node.getBnNodePerformerAssign().getBnNodePerformerAssignValue());
3392        else
3393            return null;
3394    }
3395    
3396    /**
3397     * Get all roles names of the project
3398     * @return String Collection - roles names of this projects
3399     *
3400     * @ejb:interface-method view-type="both"
3401     * @ejb:transaction type="Supports"
3402     * @throws HeroException
3403     *
3404     **/

3405    public Collection JavaDoc getRolesNames() throws HeroException {
3406        if (this.getProjectConfigTrace())
3407            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3408        Collection JavaDoc roles = mProject.getBnRoles();
3409        ArrayList JavaDoc result = new ArrayList JavaDoc();
3410        for (Iterator JavaDoc i = roles.iterator(); i.hasNext();) {
3411            result.add(((BnRoleLocal) i.next()).getName());
3412        }
3413        return result;
3414    }
3415    
3416    
3417    /**
3418     * Get all user roles. This method returns all the roles for this user in differents projects.
3419     *
3420     * @param userName The name of the user
3421     * @return Collection of BnRoleLOcal objects - roles of the user in differents projects
3422     *
3423     * @ejb:interface-method view-type="both"
3424     * @ejb:transaction type="Supports"
3425     * @throws HeroException
3426     *
3427     **/

3428    public Collection JavaDoc getUserRoles(String JavaDoc userName) throws HeroException {
3429        if (this.getProjectConfigTrace())
3430            trace.info("parameter: userName=" + userName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3431        BnUserLocalHome uHome;
3432        BnUserLocal user;
3433        try {
3434            uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome();
3435        } catch (javax.naming.NamingException JavaDoc be) {
3436            if (this.getProjectConfigTrace())
3437                trace.error(be.getMessage());
3438            throw new HeroException(be.getMessage());
3439        }
3440        try {
3441            user = uHome.findByName(userName);
3442        } catch (FinderException JavaDoc f) {
3443            if (this.getProjectConfigTrace())
3444                trace.error("FinderException " + f.getMessage());
3445            throw new HeroException("FinderException");
3446        }
3447        Collection JavaDoc roles = user.getBnRoles();
3448        ArrayList JavaDoc result = new ArrayList JavaDoc();
3449        for (Iterator JavaDoc i = roles.iterator(); i.hasNext();) {
3450            result.add((BnRoleLocal) i.next());
3451        }
3452        return result;
3453    }
3454    
3455    /**
3456     * Get user roles in the current project. Returns the roles of this user in the current project.
3457     *
3458     * @param userName The name of the user
3459     * @return Collection of BnRoleValue objects - roles of the user in this project
3460     *
3461     * @ejb:interface-method view-type="both"
3462     * @ejb:transaction type="Supports"
3463     * @throws HeroException
3464     *
3465     **/

3466    public Collection JavaDoc getUserRolesInProject(String JavaDoc userName)
3467    throws HeroException {
3468        if (this.getProjectConfigTrace())
3469            trace.info("parameter: userName=" + userName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3470        BnUserLocalHome uHome;
3471        BnUserLocal user;
3472        ArrayList JavaDoc result = new ArrayList JavaDoc();
3473        try {
3474            uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome();
3475        } catch (javax.naming.NamingException JavaDoc be) {
3476            if (this.getProjectConfigTrace())
3477                trace.error(be.getMessage());
3478            throw new HeroException(be.getMessage());
3479        }
3480        try {
3481            user = uHome.findByName(userName);
3482        } catch (FinderException JavaDoc f) {
3483            if (this.getProjectConfigTrace())
3484                trace.error("FinderException " + f.getMessage());
3485            throw new HeroException("FinderException");
3486        }
3487        Collection JavaDoc userRoles = user.getBnRoles();
3488        Collection JavaDoc projectRoles = mProject.getBnRoles();
3489        for (Iterator JavaDoc i = userRoles.iterator(); i.hasNext();) {
3490            BnRoleLocal ur = (BnRoleLocal) i.next();
3491            for (Iterator JavaDoc j = projectRoles.iterator(); j.hasNext();) {
3492                BnRoleLocal up = (BnRoleLocal) j.next();
3493                if (ur.getId() == up.getId())
3494                    result.add(ur.getBnRoleValue());
3495            }
3496        }
3497        return result;
3498    }
3499    
3500    /**
3501     * Get users matching with given role in the current project.
3502     *
3503     * @param roleName The name of the role
3504     * @return Collection of String - users matching with this role
3505     *
3506     * @ejb:interface-method view-type="both"
3507     * @ejb:transaction type="Supports"
3508     * @throws HeroException
3509     *
3510     **/

3511    public Collection JavaDoc getUsersRole(String JavaDoc roleName)
3512    throws HeroException {
3513        if (this.getProjectConfigTrace())
3514            trace.info("parameter: roleName=" + roleName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3515        BnRoleLocalHome rHome;
3516        BnRoleLocal role;
3517        ArrayList JavaDoc result = new ArrayList JavaDoc();
3518        try {
3519            rHome = (BnRoleLocalHome) hero.interfaces.BnRoleUtil.getLocalHome();
3520        } catch (javax.naming.NamingException JavaDoc be) {
3521            if (this.getProjectConfigTrace())
3522                trace.error(be.getMessage());
3523            throw new HeroException(be.getMessage());
3524        }
3525        try {
3526            role = rHome.findByName(roleName,mProject.getId());
3527        } catch (FinderException JavaDoc f) {
3528            if (this.getProjectConfigTrace())
3529                trace.error("FinderException " + f.getMessage());
3530            throw new HeroException("FinderException");
3531        }
3532        Collection JavaDoc usersR = role.getBnUsers();
3533        Iterator JavaDoc users = usersR.iterator();
3534        while (users.hasNext())
3535        {
3536            BnUserLocal user = (BnUserLocal) users.next();
3537            result.add(user.getName());
3538        }
3539        return result;
3540    }
3541    
3542    /**
3543     * Get user roles in project names. Returns the role names of the user in the current project
3544     *
3545     * @param userName The name of the user
3546     * @return String Collection - role names of this user in the current project
3547     *
3548     * @ejb:interface-method view-type="both"
3549     * @ejb:transaction type="Supports"
3550     * @throws HeroException
3551     *
3552     **/

3553    public Collection JavaDoc getUserRolesInProjectNames(String JavaDoc userName)
3554    throws HeroException {
3555        if (this.getProjectConfigTrace())
3556            trace.info("parameter: userName=" + userName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3557        BnUserLocalHome uHome;
3558        BnUserLocal user;
3559        ArrayList JavaDoc result = new ArrayList JavaDoc();
3560        try {
3561            uHome = (BnUserLocalHome) hero.interfaces.BnUserUtil.getLocalHome();
3562        } catch (javax.naming.NamingException JavaDoc be) {
3563            if (this.getProjectConfigTrace())
3564                trace.error(be.getMessage());
3565            throw new HeroException(be.getMessage());
3566        }
3567        try {
3568            user = uHome.findByName(userName);
3569        } catch (FinderException JavaDoc f) {
3570            if (this.getProjectConfigTrace())
3571                trace.error("FinderException " + f.getMessage());
3572            throw new HeroException("FinderException");
3573        }
3574        
3575        Collection JavaDoc userRoles = user.getBnRoles();
3576        Collection JavaDoc projectRoles = mProject.getBnRoles();
3577        for (Iterator JavaDoc i = userRoles.iterator(); i.hasNext();) {
3578            BnRoleLocal ur = (BnRoleLocal) i.next();
3579            for (Iterator JavaDoc j = projectRoles.iterator(); j.hasNext();) {
3580                BnRoleLocal up = (BnRoleLocal) j.next();
3581                if (ur.getId().equals(up.getId()))
3582                    result.add(ur.getBnRoleValue().getName());
3583            }
3584        }
3585        return result;
3586    }
3587    
3588    /**
3589     * Get node role. Returns the role information.
3590     *
3591     * @param nodeName The name of the node
3592     * @return BnRoleLocal object - the role data
3593     * @ejb:interface-method view-type="both"
3594     * @ejb:transaction type="Supports"
3595     * @throws HeroException
3596     *
3597     **/

3598    public BnRoleLocal getNodeRole(String JavaDoc nodeName) throws HeroException {
3599        if (this.getProjectConfigTrace())
3600            trace.info("parameter: nodeName=" + nodeName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3601        BnNodeLocal nd = mProject.getBnNode(nodeName);
3602        return ((BnRoleLocal) nd.getBnRole());
3603    }
3604    
3605    /**
3606     * Get the edge Condition. This condition is evaluated at run-time in order to perform activity transition.
3607     * This condition follows the beanshell syntax (Lightweight Scripting for Java).<br>
3608     *
3609     * @param edge the edge/transition name
3610     * @return String - edge condition
3611     * @ejb:interface-method view-type="both"
3612     * @ejb:transaction type="Supports"
3613     * @throws HeroException
3614     *
3615     **/

3616    public String JavaDoc getEdgeCondition(String JavaDoc edge)
3617    throws HeroException {
3618        if (this.getProjectConfigTrace())
3619            trace.info("parameter: name=" + edge+ " process name = " + this.getName()+ " started by " + this.getCaller());
3620        BnEdgeLocal e = mProject.getBnEdge(edge);
3621        return(e.getCondition());
3622    }
3623    
3624    /**
3625     * Returns if the node is set to be executed in anticipated mode.
3626     *
3627     * @param name name of the node
3628     * @return boolean - if anticipable node is set to this node.
3629     * @ejb:interface-method view-type="both"
3630     * @ejb:transaction type="Required"
3631     * @throws HeroException
3632     *
3633     **/

3634    public boolean getNodeAnticipable(String JavaDoc name) throws HeroException {
3635        if (this.getProjectConfigTrace())
3636            trace.info("parameter: name=" + name+ " process name = " + this.getName()+ " started by " + this.getCaller());
3637        BnNodeLocal nd = mProject.getBnNode(name);
3638        return (nd.getAnticipable());
3639    }
3640    
3641    /**
3642     * Get node role name. Obtains the role name of this node.
3643     *
3644     * @param nodeName The name of the node
3645     * @return String - the role name of this node
3646     *
3647     * @ejb:interface-method view-type="both"
3648     * @ejb:transaction type="Supports"
3649     * @throws HeroException
3650     *
3651     **/

3652    public String JavaDoc getNodeRoleName(String JavaDoc nodeName) throws HeroException {
3653        if (this.getProjectConfigTrace())
3654            trace.info("parameter: nodeName=" + nodeName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3655        BnNodeLocal nd = mProject.getBnNode(nodeName);
3656        return (((BnRoleLocal) nd.getBnRole()).getName());
3657    }
3658    
3659    /**
3660     * Get node deadline. Activity deadline is the lastest date in which the activity must be finished.
3661     *
3662     * @param nodeName The name of the node
3663     * @return String - deadline of this node
3664     *
3665     * @ejb:interface-method view-type="both"
3666     * @ejb:transaction type="Supports"
3667     * @throws HeroException
3668     * @deprecated replaced by getNodeDeadlines(String name, Collection co)
3669     *
3670     **/

3671    public String JavaDoc getNodeDeadline(String JavaDoc nodeName) throws HeroException {
3672        if (this.getProjectConfigTrace())
3673            trace.info("parameter: nodeName=" + nodeName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3674        BnNodeLocal nd = mProject.getBnNode(nodeName);
3675        if (nd.getDeadlines().size() != 0) {
3676            Collection JavaDoc co = nd.getDeadlines();
3677            Iterator JavaDoc it = co.iterator();
3678            Date JavaDoc date = null;
3679            while (it.hasNext()){
3680                date = (Date JavaDoc)it.next();
3681            }
3682            return (date.toString());
3683        }
3684        else
3685            return (null);
3686        /*
3687        if (nd.getDeadline() != null)
3688            return (nd.getDeadline().toString());
3689        else
3690            return (null);
3691        */

3692    }
3693    
3694    /**
3695     * Get collection of deadlines for the node. Activity deadline is the lastest date in which the activity must be finished.
3696     *
3697     * @param nodeName The name of the node
3698     * @return Collection - collection of deadlines of this node
3699     *
3700     * @ejb:interface-method view-type="both"
3701     * @ejb:transaction type="Supports"
3702     * @throws HeroException
3703     *
3704     **/

3705    public Collection JavaDoc getNodeDeadlines(String JavaDoc nodeName) throws HeroException {
3706        if (this.getProjectConfigTrace())
3707            trace.info("parameter: nodeName=" + nodeName+ " process name = " + this.getName()+ " started by " + this.getCaller());
3708        BnNodeLocal nd = mProject.getBnNode(nodeName);
3709        if (nd.getDeadlines() != null)
3710            return (nd.getDeadlines());
3711        else
3712            return (null);
3713    }
3714
3715    
3716    /**
3717     * Get the node Value. Returns node information.
3718     *
3719     * @param name the name of the Node
3720     * @return BnNodeValue object - node data.
3721     *
3722     * @ejb:interface-method view-type="both"
3723     * @ejb:transaction type="Supports"
3724     * @throws HeroException
3725     *
3726     **/

3727    public BnNodeValue getNodeValue(String JavaDoc name) throws HeroException {
3728        if (this.getProjectConfigTrace())
3729            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3730        BnNodeLocalHome nHome;
3731        BnNodeLocal mNode;
3732        BnNodeValue nv;
3733        try {
3734            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
3735        } catch (javax.naming.NamingException JavaDoc be) {
3736            if (this.getProjectConfigTrace())
3737                trace.error(be.getMessage());
3738            throw new HeroException(be.getMessage());
3739        }
3740        try {
3741            mNode = nHome.findByName(name, mProject.getId());
3742        } catch (FinderException JavaDoc fe) {
3743            if (this.getProjectConfigTrace())
3744                trace.error("In Node does not exist " + fe.getMessage());
3745            throw new HeroException("In Node does not exist");
3746        }
3747        nv = mNode.getBnNodeValue();
3748        return nv;
3749    }
3750    
3751    /**
3752     * Get the Agent Value.
3753     *
3754     * @param name the name of the Agent
3755     * @return BnAgentValue object - agent data.
3756     *
3757     * @ejb:interface-method view-type="both"
3758     * @ejb:transaction type="Supports"
3759     * @throws HeroException
3760     *
3761     **/

3762    public BnAgentValue getAgentValue(String JavaDoc name) throws HeroException {
3763        if (this.getProjectConfigTrace())
3764            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3765        BnAgentLocalHome nHome;
3766        BnAgentLocal mAgent;
3767        BnAgentValue av;
3768        try {
3769            nHome = hero.interfaces.BnAgentUtil.getLocalHome();
3770        } catch (javax.naming.NamingException JavaDoc be) {
3771            if (this.getProjectConfigTrace())
3772                trace.error(be.getMessage());
3773            throw new HeroException(be.getMessage());
3774        }
3775        try {
3776            mAgent = nHome.findByName(name, mProject.getId());
3777        } catch (FinderException JavaDoc fe) {
3778            if (this.getProjectConfigTrace())
3779                trace.error("In BnAgent does not exist " + fe.getMessage());
3780            throw new HeroException("In BnAgent does not exist");
3781        }
3782        av = mAgent.getBnAgentValue();
3783        return av;
3784    }
3785    
3786    /**
3787     * Get the AgentEdge Value
3788     *
3789     * @param name the name of the BnAgentEdge
3790     * @return BnAgentEdgeValue object - agentEdge data.
3791     *
3792     * @ejb:interface-method view-type="both"
3793     * @ejb:transaction type="Supports"
3794     * @throws HeroException
3795     *
3796     **/

3797    public BnAgentEdgeValue getAgentEdgeValue(String JavaDoc name)
3798    throws HeroException {
3799        if (this.getProjectConfigTrace())
3800            trace.info("parameter: name=" + name);
3801        BnAgentEdgeLocalHome nHome;
3802        BnAgentEdgeLocal mAgentEdge;
3803        BnAgentEdgeValue av;
3804        try {
3805            nHome = hero.interfaces.BnAgentEdgeUtil.getLocalHome();
3806        } catch (javax.naming.NamingException JavaDoc be) {
3807            if (this.getProjectConfigTrace())
3808                trace.error(be.getMessage());
3809            throw new HeroException(be.getMessage());
3810        }
3811        try {
3812            mAgentEdge = nHome.findByName(name, mProject.getId());
3813        } catch (FinderException JavaDoc fe) {
3814            if (this.getProjectConfigTrace())
3815                trace.error("In BnAgentEdge does not exist " + fe.getMessage());
3816            throw new HeroException("In BnAgentEdge does not exist");
3817        }
3818        av = mAgentEdge.getBnAgentEdgeValue();
3819        if (this.getProjectConfigTrace())
3820            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3821        return av;
3822    }
3823    
3824    /**
3825     * Get the node Light Value. Returns node basic information.
3826     *
3827     * @param name the name of the Node
3828     * @return BnNodeLightValue object - agentEdge data.
3829     *
3830     * @ejb:interface-method view-type="both"
3831     * @ejb:transaction type="Supports"
3832     * @throws HeroException
3833     *
3834     **/

3835    public BnNodeLightValue getNodeLightValue(String JavaDoc name)
3836    throws HeroException {
3837        if (this.getProjectConfigTrace())
3838            trace.info("parameter: name=" + name);
3839        BnNodeLocalHome nHome;
3840        BnNodeLocal mNode;
3841        BnNodeLightValue nv;
3842        try {
3843            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
3844        } catch (javax.naming.NamingException JavaDoc be) {
3845            if (this.getProjectConfigTrace())
3846                trace.error(be.getMessage());
3847            throw new HeroException(be.getMessage());
3848        }
3849        try {
3850            mNode = nHome.findByName(name, mProject.getId());
3851        } catch (FinderException JavaDoc fe) {
3852            if (this.getProjectConfigTrace())
3853                trace.error("In Node does not exist " + fe.getMessage());
3854            throw new HeroException("In Node does not exist");
3855        }
3856        nv = mNode.getBnNodeLightValue();
3857        return nv;
3858    }
3859    
3860    
3861    /**
3862     * Get the edge value.
3863     *
3864     * @param name the name of the edge
3865     * @return BnEdgeValue object - edge data.
3866     *
3867     * @ejb:interface-method view-type="both"
3868     * @ejb:transaction type="Supports"
3869     * @throws HeroException
3870     *
3871     **/

3872    public BnEdgeValue getEdgeValue(String JavaDoc name) throws HeroException {
3873        if (this.getProjectConfigTrace())
3874            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3875        BnEdgeLocalHome eHome;
3876        BnEdgeLocal mEdge;
3877        BnEdgeValue ev;
3878        try {
3879            eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
3880        } catch (javax.naming.NamingException JavaDoc be) {
3881            if (this.getProjectConfigTrace())
3882                trace.error(be.getMessage());
3883            throw new HeroException(be.getMessage());
3884        }
3885        try {
3886            mEdge = eHome.findByName(name, mProject.getId());
3887        } catch (FinderException JavaDoc fe) {
3888            if (this.getProjectConfigTrace())
3889                trace.error("BnEdge does not exist " + fe.getMessage());
3890            throw new HeroException("BnEdge does not exist");
3891        }
3892        ev = mEdge.getBnEdgeValue();
3893        return ev;
3894    }
3895    
3896    /**
3897     * Get the node executor. Get the name of the user which is executing the activity.
3898     *
3899     * @param name the name of the node
3900     * @return String - the user executor of this node
3901     * @ejb:interface-method view-type="both"
3902     * @ejb:transaction type="Supports"
3903     * @throws HeroException
3904     *
3905     **/

3906    public String JavaDoc getNodeExecutor(String JavaDoc name) throws HeroException {
3907        if (this.getProjectConfigTrace())
3908            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3909        BnNodeLocal nd = mProject.getBnNode(name);
3910        //BnUserLocal ul = nd.getExecutor();
3911
//return (ul.getName());
3912
return nd.getExecutor();
3913    }
3914    
3915    /**
3916     * Get the state of the node. The possible states for a node are:<br><br>
3917     *
3918     * hero.interfaces.Constants.Nd.INITIAL<br>
3919     * hero.interfaces.Constants.Nd.READY<br>
3920     * hero.interfaces.Constants.Nd.DEAD<br>
3921     * hero.interfaces.Constants.Nd.ANTICIPABLE<br>
3922     * hero.interfaces.Constants.Nd.ANTICIPATING<br>
3923     * hero.interfaces.Constants.Nd.EXECUTING<br>
3924     * hero.interfaces.Constants.Nd.TERMINATED<br>
3925     *
3926     * @param name of the node
3927     * @return int - The state of the node
3928     * @ejb:interface-method view-type="both"
3929     * @ejb:transaction type="Supports"
3930     * @throws HeroException
3931     *
3932     **/

3933    public int getNodeState(String JavaDoc name) throws HeroException {
3934        if (this.getProjectConfigTrace())
3935            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3936        BnNodeLocal nd = mProject.getBnNode(name);
3937        return (nd.getState());
3938    }
3939    
3940    /**
3941     * Get the type of the node. Possibles node types are:<br><br>
3942     *
3943     * hero.interfaces.Constants.Nd.AND_JOIN_NODE<br>
3944     * hero.interfaces.Constants.Nd.OR_JOIN_NODE<br>
3945     * hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE<br>
3946     * hero.interfaces.Constants.Nd.OR_JOIN_AUTOMATIC_NODE<br>
3947     *
3948     * @param name of the node
3949     * @return int - The type of the node
3950     * @ejb:interface-method view-type="both"
3951     * @ejb:transaction type="Supports"
3952     * @throws HeroException
3953     *
3954     **/

3955    public int getNodeType(String JavaDoc name) throws HeroException {
3956        if (this.getProjectConfigTrace())
3957            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
3958        BnNodeLocal nd = mProject.getBnNode(name);
3959        return (nd.getType());
3960    }
3961    
3962    /**
3963     * Get all users of the project. Obtains the user names of the project
3964     * @return String Collection - user names in project
3965     *
3966     * @ejb:interface-method view-type="both"
3967     * @ejb:transaction type="Supports"
3968     * @throws HeroException
3969     *
3970     **/

3971    public Collection JavaDoc getUsers() throws HeroException {
3972        if (this.getProjectConfigTrace())
3973            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3974        Collection JavaDoc users = mProject.getBnUsers();
3975        ArrayList JavaDoc result = new ArrayList JavaDoc();
3976        for (Iterator JavaDoc i = users.iterator(); i.hasNext();) {
3977            result.add(((BnUserLocal) i.next()).getName());
3978        }
3979        return result;
3980    }
3981    
3982    /**
3983     * Return all registered users. Get user names of Bonita System
3984     * @return String Collection - all user names
3985     *
3986     * @ejb:interface-method view-type="both"
3987     * @ejb:transaction type="Supports"
3988     * @throws HeroException
3989     *
3990     **/

3991    public Collection JavaDoc getAllUsers() throws HeroException {
3992        if (this.getProjectConfigTrace())
3993            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
3994        UserServiceLocalHome ushome;
3995        UserServiceLocal ul;
3996        Collection JavaDoc users;
3997        try {
3998            ushome = (UserServiceLocalHome) hero.interfaces.UserServiceUtil.getLocalHome();
3999        } catch (javax.naming.NamingException JavaDoc be) {
4000            if (this.getProjectConfigTrace())
4001                trace.error(be.getMessage());
4002            throw new HeroException(be.getMessage());
4003        }
4004        try {
4005            ul = ushome.create();
4006            users = ul.findUsers();
4007        } catch (Exception JavaDoc fe) {
4008            if (this.getProjectConfigTrace())
4009                trace.error("Error in find users " + fe.getMessage());
4010            throw new HeroException("Error in find users ");
4011        }
4012        ArrayList JavaDoc result = new ArrayList JavaDoc();
4013        for (Iterator JavaDoc i = users.iterator(); i.hasNext();) {
4014            Map JavaDoc user = (Map JavaDoc)i.next();
4015            result.add(user.get("name"));
4016        }
4017        return result;
4018    }
4019    
4020    /**
4021     * Get all node names of the project
4022     *
4023     * @return String Collection - all node names
4024     * @ejb:interface-method view-type="both"
4025     * @ejb:transaction type="Supports"
4026     * @throws HeroException
4027     *
4028     **/

4029    public Collection JavaDoc getNodesNames() throws HeroException {
4030        if (this.getProjectConfigTrace())
4031            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4032        
4033        // Vector names = new Vector();
4034
ArrayList JavaDoc names = new ArrayList JavaDoc();
4035        Collection JavaDoc nodes = mProject.getBnNodes();
4036        Iterator JavaDoc i = nodes.iterator();
4037        while (i.hasNext()) {
4038            BnNodeLocal n = (BnNodeLocal) i.next();
4039            names.add(n.getName());
4040        }
4041        return ((Collection JavaDoc) names);
4042    }
4043    
4044    /**
4045     * Get all edges names of the project
4046     * @return String Collection - all edges names of the project
4047     *
4048     * @ejb:interface-method view-type="both"
4049     * @ejb:transaction type="Supports"
4050     * @throws HeroException
4051     *
4052     **/

4053    public Collection JavaDoc getEdgesNames() throws HeroException {
4054        if (this.getProjectConfigTrace())
4055            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4056        // Vector names = new Vector();
4057
ArrayList JavaDoc names = new ArrayList JavaDoc();
4058        Collection JavaDoc edges = mProject.getBnEdges();
4059        Iterator JavaDoc i = edges.iterator();
4060        while (i.hasNext()) {
4061            BnEdgeLocal n = (BnEdgeLocal) i.next();
4062            names.add(n.getName());
4063        }
4064        return ((Collection JavaDoc) names);
4065    }
4066    
4067    /**
4068     * Get edge in node. Returns the name of in node
4069     * @param edgeName the name ot the edge
4070     * @return String - the name of in node
4071     *
4072     * @ejb:interface-method view-type="both"
4073     * @ejb:transaction type="Supports"
4074     * @throws HeroException
4075     *
4076     **/

4077    public String JavaDoc getEdgeInNode(String JavaDoc edgeName) throws HeroException {
4078        if (this.getProjectConfigTrace())
4079            trace.info("parameter: edgeName" + edgeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4080        BnEdgeLocal e = mProject.getBnEdge(edgeName);
4081        return (((BnNodeLocal) e.getInBnNode()).getName());
4082    }
4083    
4084    /**
4085     * Get edge out node. Returns the name of out node
4086     * @param edgeName the name ot the edge
4087     * @return String - the name of out node
4088     *
4089     * @ejb:interface-method view-type="both"
4090     * @ejb:transaction type="Supports"
4091     * @throws HeroException
4092     *
4093     **/

4094    public String JavaDoc getEdgeOutNode(String JavaDoc edgeName) throws HeroException {
4095        if (this.getProjectConfigTrace())
4096            trace.info("parameter: edgeName" + edgeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4097        BnEdgeLocal e = mProject.getBnEdge(edgeName);
4098        return (((BnNodeLocal) e.getOutBnNode()).getName());
4099    }
4100    
4101    /**
4102     * Get all in edges of the node
4103     *
4104     * @param name the name ot the node
4105     * @return String Collection - get in edges of the node
4106     *
4107     * @ejb:interface-method view-type="both"
4108     * @ejb:transaction type="Supports"
4109     * @throws HeroException
4110     *
4111     **/

4112    public Collection JavaDoc getNodeInEdges(String JavaDoc name) throws HeroException {
4113        if (this.getProjectConfigTrace())
4114            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
4115        
4116        Collection JavaDoc in = new ArrayList JavaDoc();
4117        BnNodeLocal nd = mProject.getBnNode(name);
4118        
4119        Collection JavaDoc edgesIn = nd.getInBnEdges();
4120        Iterator JavaDoc i = edgesIn.iterator();
4121        while (i.hasNext())
4122            in.add(((BnEdgeLocal) i.next()).getName());
4123        return (in);
4124    }
4125    
4126    /**
4127     * Get all out edges of the node
4128     
4129     * @param name the name ot the node
4130     * @return String Collection - get out edges of the node
4131     *
4132     * @ejb:interface-method view-type="both"
4133     * @ejb:transaction type="Supports"
4134     * @throws HeroException
4135     *
4136     **/

4137    public Collection JavaDoc getNodeOutEdges(String JavaDoc name) throws HeroException {
4138        if (this.getProjectConfigTrace())
4139            trace.info("parameter: name=" + name + " process name = " + this.getName()+ " started by " + this.getCaller());
4140        
4141        Collection JavaDoc out = new ArrayList JavaDoc();
4142        BnNodeLocal nd = mProject.getBnNode(name);
4143        
4144        Collection JavaDoc edgesOut = nd.getOutBnEdges();
4145        Iterator JavaDoc i = edgesOut.iterator();
4146        while (i.hasNext())
4147            out.add(((BnEdgeLocal) i.next()).getName());
4148        return (out);
4149    }
4150    
4151    /**
4152     * Get Node properties. Get a list of pair key/value properties associated to the node.
4153     *
4154     * @param nodeName the name of the node
4155     * @return Collection of BnNodePropertyValue objects - all node properties
4156     * @ejb:interface-method view-type="both"
4157     * @ejb:transaction type="Supports"
4158     * @throws HeroException
4159     *
4160     **/

4161    public Collection JavaDoc getNodeProperties(String JavaDoc nodeName) throws HeroException {
4162        if (this.getProjectConfigTrace())
4163            trace.info("parameter: name=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4164        Collection JavaDoc prp = new ArrayList JavaDoc();
4165        BnNodePropertyLocal pl;
4166        
4167        BnNodeLocal nd = mProject.getBnNode(nodeName);
4168        
4169        Collection JavaDoc pls = nd.getBnProperties();
4170        
4171        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4172            pl = (BnNodePropertyLocal) i.next();
4173            prp.add(pl.getBnNodePropertyValue());
4174        }
4175        return (prp);
4176    }
4177    
4178    /**
4179     * Get Node property value. Get a pair key/value properties associated to the node.
4180     *
4181     * @param nodeName the name of the node
4182     * @param key Property key
4183     * @return BnNodePropertyValue object - node property data
4184     * @ejb:interface-method view-type="both"
4185     * @ejb:transaction type="Supports"
4186     * @throws HeroException
4187     *
4188     **/

4189    public BnNodePropertyValue getNodeProperty(String JavaDoc nodeName, String JavaDoc key) throws HeroException {
4190        if (this.getProjectConfigTrace())
4191            trace.info("parameters: node=" + nodeName + " key=" + key + " process name = " + this.getName()+ " started by " + this.getCaller());
4192        BnNodePropertyLocal pl;
4193        BnNodeLocal nd = mProject.getBnNode(nodeName);
4194        Collection JavaDoc pls = nd.getBnProperties();
4195        
4196        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4197            pl = (BnNodePropertyLocal) i.next();
4198            if (pl.getTheKey().equals(key))
4199                return (pl.getBnNodePropertyValue());
4200
4201        }
4202        return (null);
4203    }
4204    
4205    /**
4206     * Get property value of the project. Get a pair key/value properties associated to this project.
4207     *
4208     * @param key Property key
4209     * @return BnProjectPropertyValue object - property data
4210     * @ejb:interface-method view-type="both"
4211     * @ejb:transaction type="Supports"
4212     * @throws HeroException
4213     *
4214     **/

4215    public BnProjectPropertyValue getProperty(String JavaDoc key) throws HeroException {
4216        if (this.getProjectConfigTrace())
4217            trace.info("parameter: key=" + key + " process name = " + this.getName()+ " started by " + this.getCaller());
4218        BnProjectPropertyLocal pl;
4219        Collection JavaDoc pls = mProject.getBnProperties();
4220        
4221        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4222            pl = (BnProjectPropertyLocal) i.next();
4223            if (pl.getTheKey().equals(key))
4224                return (pl.getBnProjectPropertyValue());
4225        }
4226        return (null);
4227    }
4228    
4229    /**
4230     * Get Node hooks of the project. Get hooks of the node. Method to get the list of Java or TCL hooks of the node.
4231     *
4232     * @param nodeName the name of the node
4233     * @return Collection of BnNodeHookValue - all node hooks
4234     * @ejb:interface-method view-type="both"
4235     * @ejb:transaction type="Supports"
4236     * @throws HeroException
4237     *
4238     **/

4239    public Collection JavaDoc getNodeHooks(String JavaDoc nodeName) throws HeroException {
4240        if (this.getProjectConfigTrace())
4241            trace.info("parameter: node=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4242        Collection JavaDoc hk = new ArrayList JavaDoc();
4243        BnNodeHookLocal pl;
4244        
4245        BnNodeLocal nd = mProject.getBnNode(nodeName);
4246        
4247        Collection JavaDoc pls = nd.getBnHooks();
4248        
4249        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4250            pl = (BnNodeHookLocal) i.next();
4251            hk.add(pl.getBnNodeHookValue());
4252        }
4253        return (hk);
4254    }
4255    
4256    /**
4257     * Get Interactive Node hooks of the project
4258     *
4259     * @param nodeName the name of the node
4260     * @return Collection of BnNodeInterHookValue objects - all node hooks
4261     * @ejb:interface-method view-type="both"
4262     * @ejb:transaction type="Supports"
4263     * @throws HeroException
4264     *
4265     **/

4266    public Collection JavaDoc getNodeInterHooks(String JavaDoc nodeName) throws HeroException {
4267        if (this.getProjectConfigTrace())
4268            trace.info("parameter: node=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4269
4270        Collection JavaDoc hk = new ArrayList JavaDoc();
4271        BnNodeInterHookLocal pl;
4272        
4273        BnNodeLocal nd = mProject.getBnNode(nodeName);
4274        
4275        Collection JavaDoc pls = nd.getBnInterHooks();
4276        
4277        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4278            pl = (BnNodeInterHookLocal) i.next();
4279            hk.add(pl.getBnNodeInterHookValue());
4280        }
4281        return (hk);
4282    }
4283    
4284    /**
4285     * Get role mappers of the project.
4286     *
4287     * @return Collection of BnRoleMapperValue - all role mappers
4288     * @ejb:interface-method view-type="both"
4289     * @ejb:transaction type="Supports"
4290     * @throws HeroException
4291     *
4292     **/

4293    public Collection JavaDoc getRoleMappers() throws HeroException {
4294        if (this.getProjectConfigTrace())
4295            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4296
4297        Collection JavaDoc cm = new ArrayList JavaDoc();
4298        BnRoleMapperLocal mapperL = null;
4299        BnRoleLocal roleL = null;
4300        Collection JavaDoc cr = mProject.getBnRoles();
4301        
4302        for (Iterator JavaDoc i = cr.iterator(); i.hasNext();) {
4303            roleL = (BnRoleLocal) i.next();
4304            // get the mapper if exists
4305
mapperL = roleL.getBnRoleMapper();
4306            if ( mapperL != null){
4307                cm.add(mapperL.getBnRoleMapperValue());
4308            }
4309        }
4310        return (cm);
4311    }
4312    
4313    /**
4314     * Get Interactive hooks of the project. Returns hooks assigned to project nodes.
4315     *
4316     * @return Collection of ProjectInterHookValue - project inter hooks
4317     * @ejb:interface-method view-type="both"
4318     * @ejb:transaction type="Supports"
4319     * @throws HeroException
4320     *
4321     **/

4322    public Collection JavaDoc getInterHooks() throws HeroException {
4323        if (this.getProjectConfigTrace())
4324            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4325
4326        Collection JavaDoc hk = new ArrayList JavaDoc();
4327        BnProjectInterHookLocal pl;
4328        Collection JavaDoc pls = mProject.getBnInterHooks();
4329        
4330        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4331            pl = (BnProjectInterHookLocal) i.next();
4332            hk.add(pl.getBnProjectInterHookValue());
4333        }
4334        return (hk);
4335    }
4336    
4337    
4338    /**
4339     * Get Node inter hook of the project
4340     *
4341     * @param nodeName the name of the node
4342     * @param interHook name of the hooks
4343     * @return BnNodeInterHookValue object - node hook data
4344     * @ejb:interface-method view-type="both"
4345     * @ejb:transaction type="Supports"
4346     * @throws HeroException
4347     *
4348     **/

4349    public BnNodeInterHookValue getNodeInterHook(String JavaDoc nodeName, String JavaDoc interHook) throws HeroException {
4350        if (this.getProjectConfigTrace())
4351            trace.info("parameters: node=" + nodeName + " key=" + interHook + " process name = " + this.getName()+ " started by " + this.getCaller());
4352        BnNodeInterHookLocal hl;
4353        BnNodeLocal nd = mProject.getBnNode(nodeName);
4354        Collection JavaDoc hls = nd.getBnInterHooks();
4355        
4356        for (Iterator JavaDoc i = hls.iterator(); i.hasNext();) {
4357            hl = (BnNodeInterHookLocal) i.next();
4358            if (hl.getName().equals(interHook))
4359                return (hl.getBnNodeInterHookValue());
4360        }
4361        return (null);
4362    }
4363    
4364    /**
4365     * Get properties key of the project. A property is a pair key/value representing workflow relevant data. This
4366     * methods obtains properties key of the project.
4367     * @return Collection of String - all project properties
4368     * @ejb:interface-method view-type="both"
4369     * @ejb:transaction type="Supports"
4370     * @throws HeroException
4371     *
4372     **/

4373    public Collection JavaDoc getPropertiesKey() throws HeroException {
4374        if (this.getProjectConfigTrace())
4375            trace.info("started by " + this.getCaller());
4376        Collection JavaDoc prp = new ArrayList JavaDoc();
4377        BnProjectPropertyLocal ppl;
4378        
4379        Collection JavaDoc pls = mProject.getBnProperties();
4380        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4381            ppl = (BnProjectPropertyLocal) i.next();
4382            prp.add(ppl.getBnProjectPropertyValue().getTheKey());
4383        }
4384        return (prp);
4385    }
4386    
4387    /**
4388     * Get Iterations of the project. An Iteration is composed by a condition and two nodes: from and to.
4389     * @return Collection of BnIterationLightValue - all project iterations
4390     * @ejb:interface-method view-type="both"
4391     * @ejb:transaction type="Supports"
4392     * @throws HeroException
4393     *
4394     **/

4395    public Object JavaDoc[] getIterations() throws HeroException {
4396        if (this.getProjectConfigTrace())
4397            trace.info("started by " + this.getCaller());
4398        Collection JavaDoc ite = new ArrayList JavaDoc();
4399        BnIterationLocal itel;
4400        
4401        Collection JavaDoc itls = mProject.getBnIterations();
4402        for (Iterator JavaDoc i = itls.iterator(); i.hasNext();) {
4403            itel = (BnIterationLocal) i.next();
4404            BnIterationLightValue iv = (BnIterationLightValue)itel.getBnIterationLightValue();
4405            ite.add(iv);
4406        }
4407        return (ite.toArray());
4408    }
4409    
4410    /**
4411     * Get node destination of this iteration. An Iteration is composed by a condition and two nodes: from and to.
4412     * @return String - To node
4413     * @ejb:interface-method view-type="both"
4414     * @ejb:transaction type="Supports"
4415     * @throws HeroException
4416     *
4417     **/

4418    public String JavaDoc getToIteration(String JavaDoc from) throws HeroException {
4419        if (this.getProjectConfigTrace())
4420            trace.info("parameters: from=" + from+"started by " + this.getCaller());
4421        BnIterationLocalHome iteh;
4422        
4423        try {
4424            iteh = BnIterationUtil.getLocalHome();
4425        } catch (javax.naming.NamingException JavaDoc ne) {
4426            if (this.getProjectConfigTrace())
4427                trace.error(ne.getMessage());
4428            throw new HeroException(ne.getMessage());
4429        }
4430        try {
4431            BnIterationLocal it = iteh.findByFrom(mProject.getId(),from);
4432            return(it.getToNode());
4433        } catch (FinderException JavaDoc fe) {
4434            if (this.getProjectConfigTrace())
4435                trace.error(fe.getMessage());
4436            return (null);
4437        }
4438    }
4439    
4440    /**
4441     * Verifies if this node starts an iteration
4442     * @return String - from node
4443     * @ejb:interface-method view-type="both"
4444     * @ejb:transaction type="Supports"
4445     * @throws HeroException
4446     *
4447     **/

4448    public boolean getIterationExist(String JavaDoc from) throws HeroException {
4449        if (this.getProjectConfigTrace())
4450            trace.info("parameters: from=" + from+"started by " + this.getCaller());
4451        BnIterationLocalHome iteh;
4452        
4453        try {
4454            iteh = BnIterationUtil.getLocalHome();
4455        } catch (javax.naming.NamingException JavaDoc ne) {
4456            if (this.getProjectConfigTrace())
4457                trace.error(ne.getMessage());
4458            throw new HeroException(ne.getMessage());
4459        }
4460        try {
4461            BnIterationLocal it = iteh.findByFrom(mProject.getId(),from);
4462            return(true);
4463        } catch (FinderException JavaDoc fe) {
4464            return (false);
4465        }
4466    }
4467    
4468    /**
4469     * Get iteration condition
4470     * @return String - from node
4471     * @ejb:interface-method view-type="both"
4472     * @ejb:transaction type="Supports"
4473     * @throws HeroException
4474     *
4475     **/

4476    public String JavaDoc getIterationCondition(String JavaDoc from) throws HeroException {
4477        if (this.getProjectConfigTrace())
4478            trace.info("parameters: from=" + from+"started by " + this.getCaller());
4479        BnIterationLocalHome iteh;
4480        
4481        try {
4482            iteh = BnIterationUtil.getLocalHome();
4483        } catch (javax.naming.NamingException JavaDoc ne) {
4484            if (this.getProjectConfigTrace())
4485                trace.error(ne.getMessage());
4486            throw new HeroException(ne.getMessage());
4487        }
4488        try {
4489            BnIterationLocal it = iteh.findByFrom(mProject.getId(),from);
4490            return(it.getCondition());
4491        } catch (FinderException JavaDoc fe) {
4492            if (this.getProjectConfigTrace())
4493                trace.error(fe.getMessage());
4494            return (null);
4495        }
4496    }
4497    
4498    /**
4499     * Get properties of the project. A property is a pair key/value representing workflow relevant data. This
4500     * method obtains properties of the project.
4501     * @return Collection of ProjectPropertyValue - all project properties
4502     * @ejb:interface-method view-type="both"
4503     * @ejb:transaction type="Supports"
4504     * @throws HeroException
4505     *
4506     **/

4507    public Collection JavaDoc getProperties() throws HeroException {
4508        if (this.getProjectConfigTrace())
4509            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4510        Collection JavaDoc prp = new ArrayList JavaDoc();
4511        BnProjectPropertyLocal ppl;
4512        
4513        Collection JavaDoc pls = mProject.getBnProperties();
4514        for (Iterator JavaDoc i = pls.iterator(); i.hasNext();) {
4515            ppl = (BnProjectPropertyLocal) i.next();
4516            prp.add(ppl.getBnProjectPropertyValue());
4517        }
4518        return (prp);
4519    }
4520    
4521    /**
4522     * Get hooks of the project. Method to get the list of Java or TCL hooks of the project
4523     *
4524     * @return Collection of BnProjectHooksValue - all project hook
4525     * @ejb:interface-method view-type="both"
4526     * @ejb:transaction type="Supports"
4527     * @throws HeroException
4528     *
4529     **/

4530    public Collection JavaDoc getHooks() throws HeroException {
4531        if (this.getProjectConfigTrace())
4532            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4533        Collection JavaDoc hooks = new ArrayList JavaDoc();
4534        BnProjectHookLocal phl;
4535        
4536        Collection JavaDoc hks = mProject.getBnHooks();
4537        for (Iterator JavaDoc i = hks.iterator(); i.hasNext();) {
4538            phl = (BnProjectHookLocal) i.next();
4539            hooks.add(phl.getBnProjectHookValue());
4540        }
4541        return (hooks);
4542    }
4543    
4544    
4545    /**
4546     * Get the project name of this instance
4547     *
4548     * @param instanceName the name of the instance
4549     * @return String - the project name
4550     * @ejb:interface-method view-type="both"
4551     * @ejb:transaction type="Supports"
4552     * @throws HeroException
4553     *
4554     **/

4555    public String JavaDoc getProjectNameOfInstance(String JavaDoc instanceName) throws HeroException {
4556        if (this.getProjectConfigTrace())
4557            trace.info("parameters: instanceName=" + instanceName + " process name = " + this.getName()+ " started by " + this.getCaller());
4558        if (instanceName.matches(".*"+"_instance"+".*")){
4559            int i = instanceName.indexOf("_instance");
4560            return(instanceName.substring(0,i));
4561        }
4562        else {
4563            throw new HeroException(instanceName+" is not a project instance...");
4564        }
4565    }
4566    
4567    /**
4568     * Get the parent project of this project
4569     *
4570     * @return String - the parent project of this project
4571     * @ejb:interface-method view-type="both"
4572     * @ejb:transaction type="Supports"
4573     * @throws HeroException
4574     *
4575     **/

4576    public String JavaDoc getParent() throws HeroException {
4577        if (this.getProjectConfigTrace())
4578            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4579        return(mProject.getParent());
4580    }
4581    
4582    /**
4583     * Test if projects nodes are terminated
4584     *
4585     * @return boolean - the result of the test
4586     * @ejb:interface-method view-type="both"
4587     * @ejb:transaction type="Supports"
4588     * @throws HeroException
4589     *
4590     **/

4591    public boolean isTerminated() {
4592        Collection JavaDoc nodes = mProject.getBnNodes();
4593        Iterator JavaDoc i = nodes.iterator();
4594        while (i.hasNext()) {
4595            BnNodeLocal node = (BnNodeLocal) i.next();
4596            int state = node.getState();
4597            if (state != hero.interfaces.Constants.Nd.TERMINATED
4598                    && state != hero.interfaces.Constants.Nd.EXPIRED
4599                    && state != hero.interfaces.Constants.Nd.DEAD)
4600                return false;
4601        }
4602        return true;
4603    }
4604    
4605    // -------------------------------------------------------------------------
4606
// Struts business methods
4607
// -------------------------------------------------------------------------
4608

4609    /**
4610     * Get the StrutsNode. Returns node information with a specific java bean structure (useful in
4611     * struts web applications).
4612     *
4613     * @param nodeName the name of the Node
4614     * @return BnStrutsNodeValue object - node data.
4615     * @ejb:interface-method view-type="both"
4616     * @ejb:transaction type="Supports"
4617     * @throws HeroException
4618     *
4619     **/

4620    public StrutsNodeValue getStrutsNode(String JavaDoc nodeName)
4621    throws HeroException {
4622        if (this.getProjectConfigTrace())
4623            trace.info("parameter: nodeName=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4624        
4625        BnNodeLocalHome nHome;
4626        BnNodeLocal n;
4627        try {
4628            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
4629        } catch (javax.naming.NamingException JavaDoc be) {
4630            if (this.getProjectConfigTrace())
4631                trace.error(be.getMessage());
4632            throw new HeroException(be.getMessage());
4633        }
4634        try {
4635            if (this.getProjectConfigTrace())
4636                trace.info("getStrutsNode: nodeName=" + nodeName);
4637            n = nHome.findByName(nodeName, mProject.getId());
4638            
4639            StrutsNodeValue snv = new StrutsNodeValue();
4640            snv.setProjectName(mProject.getName());
4641            snv.setName(n.getName());
4642            snv.setCreator(n.getCreator());
4643            snv.setRole(n.getBnRole().getName());
4644            snv.setState(
4645                    hero.interfaces.Constants.Nd.nodeStateName[n.getState()]);
4646            snv.setType(hero.interfaces.Constants.Nd.nodeTypeName[n.getType()]);
4647            if (n.getDescription() != null)
4648                snv.setDescription(n.getDescription());
4649            if (n.getExecutor() != null)
4650                snv.setExecutor(n.getExecutor());
4651            snv.setAnticipable(n.getAnticipable());
4652            /* Modif MBL
4653            if (n.getDeadline() != null)
4654                snv.setDeadline(n.getDeadline().toString());
4655            */

4656            
4657             if (n.getDeadlines().size() != 0) {
4658                    Collection JavaDoc co = n.getDeadlines();
4659                    Iterator JavaDoc it = co.iterator();
4660                    Date JavaDoc date = null;
4661                    while (it.hasNext()){
4662                        date = (Date JavaDoc)it.next();
4663                    }
4664            snv.setDeadline(date.toString());
4665            }
4666            return (snv);
4667        } catch (FinderException JavaDoc fe) {
4668            if (this.getProjectConfigTrace())
4669                trace.error("In BnNode does not exist " + fe.getMessage());
4670            throw new HeroException("In BnNode does not exist");
4671        }
4672    }
4673    
4674    
4675    /**
4676     * Get the project nodes. Returns project nodes data.
4677     *
4678     * @return Array of StrutsNodeValue - all project nodes
4679     * @ejb:interface-method view-type="both"
4680     * @ejb:transaction type="Supports"
4681     * @throws HeroException
4682     *
4683     **/

4684    public Object JavaDoc[] getNodes() throws HeroException {
4685        if (this.getProjectConfigTrace())
4686            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4687        //ProjectNodes nb = new ProjectNodes();
4688
ArrayList JavaDoc ns = new ArrayList JavaDoc();
4689        Collection JavaDoc nodes = new ArrayList JavaDoc();
4690        
4691        nodes = mProject.getBnNodes();
4692        Iterator JavaDoc i = nodes.iterator();
4693        while (i.hasNext()) {
4694            BnNodeLocal n = (BnNodeLocal) i.next();
4695            StrutsNodeValue snv = new StrutsNodeValue();
4696            snv.setProjectName(mProject.getName());
4697            snv.setName(n.getName());
4698            snv.setCreator(n.getCreator());
4699            snv.setRole(n.getBnRole().getName());
4700            snv.setState(Constants.Nd.nodeStateName[n.getState()]);
4701            snv.setType(Constants.Nd.nodeTypeName[n.getType()]);
4702            if (n.getDescription() != null)
4703                snv.setDescription(n.getDescription());
4704            if (n.getExecutor() != null)
4705                snv.setExecutor(n.getExecutor());
4706            snv.setAnticipable(n.getAnticipable());
4707            /* Modif MBL
4708            if (n.getDeadline() != null)
4709                snv.setDeadline(n.getDeadline().toString());
4710            */

4711            if (n.getDeadlines().size() != 0) {
4712                Collection JavaDoc co = n.getDeadlines();
4713                Iterator JavaDoc it = co.iterator();
4714                Date JavaDoc date = null;
4715                while (it.hasNext()){
4716                    date = (Date JavaDoc)it.next();
4717                }
4718                snv.setDeadline(date.toString());
4719            }
4720            
4721            ns.add(snv);
4722        }
4723        return (ns.toArray());
4724    }
4725    
4726    /**
4727     * Get the StrutsNodes. Returns nodes information with a specific java bean structure (useful in
4728     * struts web applications).
4729     *
4730     * @return Collection of StrutsNodeValue - all project nodes
4731     * @ejb:interface-method view-type="both"
4732     * @ejb:transaction type="Supports"
4733     * @throws HeroException
4734     *
4735     **/

4736    public Collection JavaDoc getStrutsNodes() throws HeroException {
4737        if (this.getProjectConfigTrace())
4738            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4739        
4740        //ctor strutsNodes = new Vector();
4741
ArrayList JavaDoc strutsNodes = new ArrayList JavaDoc();
4742        Collection JavaDoc nodes = mProject.getBnNodes();
4743        Iterator JavaDoc i = nodes.iterator();
4744        while (i.hasNext()) {
4745            BnNodeLocal n = (BnNodeLocal) i.next();
4746            StrutsNodeValue snv = new StrutsNodeValue();
4747            snv.setName(n.getName());
4748            snv.setCreator(n.getCreator());
4749            snv.setRole(n.getBnRole().getName());
4750            snv.setState(
4751                    hero.interfaces.Constants.Nd.nodeStateName[n.getState()]);
4752            snv.setType(hero.interfaces.Constants.Nd.nodeTypeName[n.getType()]);
4753            snv.setDescription(n.getDescription());
4754            if (n.getExecutor() != null)
4755                snv.setExecutor(n.getExecutor());
4756            snv.setAnticipable(n.getAnticipable());
4757            /* modif MBL
4758            if (n.getDeadline() != null)
4759                snv.setDeadline(n.getDeadline().toString());
4760            */

4761            if (n.getDeadlines().size() != 0) {
4762                Collection JavaDoc co = n.getDeadlines();
4763                Iterator JavaDoc it = co.iterator();
4764                Date JavaDoc date = null;
4765                while (it.hasNext()){
4766                    date = (Date JavaDoc)it.next();
4767                }
4768                snv.setDeadline(date.toString());
4769            }
4770            strutsNodes.add(snv);
4771        }
4772        return ((Collection JavaDoc) strutsNodes);
4773    }
4774    
4775    /**
4776     * Get the Edges of the Node. Returns node edges information with a specific java bean structure (useful in
4777     * struts web applications).
4778     *
4779     * @param nodeName the name of the Node
4780     * @return Collection of StrutsEdgeValue - all node edges
4781     * @ejb:interface-method view-type="both"
4782     * @ejb:transaction type="Supports"
4783     * @throws HeroException
4784     *
4785     **/

4786    public Collection JavaDoc getStrutsNodeEdges(String JavaDoc nodeName)
4787    throws HeroException {
4788        if (this.getProjectConfigTrace())
4789            trace.info("parameter: nodeName=" + nodeName + " process name = " + this.getName()+ " started by " + this.getCaller());
4790        
4791        BnNodeLocalHome nHome;
4792        BnNodeLocal mNode;
4793        BnNodeValue nv;
4794        
4795        // Vector edges = new Vector();
4796
ArrayList JavaDoc edges = new ArrayList JavaDoc();
4797        
4798        try {
4799            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
4800        } catch (javax.naming.NamingException JavaDoc be) {
4801            if (this.getProjectConfigTrace())
4802                trace.error(be.getMessage());
4803            throw new HeroException(be.getMessage());
4804        }
4805        try {
4806            mNode = nHome.findByName(nodeName, mProject.getId());
4807        } catch (FinderException JavaDoc fe) {
4808            if (this.getProjectConfigTrace())
4809                trace.error("In Node does not exist " + fe.getMessage());
4810            throw new HeroException("In Node does not exist");
4811        }
4812        Collection JavaDoc in = mNode.getInBnEdges();
4813        Collection JavaDoc out = mNode.getOutBnEdges();
4814        
4815        Iterator JavaDoc iin = in.iterator();
4816        while (iin.hasNext()) {
4817            StrutsEdgeValue sev = new StrutsEdgeValue();
4818            hero.interfaces.BnEdgeLocal actualEdge =(hero.interfaces.BnEdgeLocal) iin.next();
4819            sev.setState(hero.interfaces.Constants.Ed.edgeStateName[actualEdge.getState()]);
4820            sev.setInNode(((BnNodeLocal) actualEdge.getInBnNode()).getName());
4821            sev.setOutNode(((BnNodeLocal) actualEdge.getOutBnNode()).getName());
4822            edges.add(sev);
4823        }
4824        
4825        Iterator JavaDoc iout = out.iterator();
4826        while (iout.hasNext()) {
4827            StrutsEdgeValue sev = new StrutsEdgeValue();
4828            BnEdgeLocal actualEdge = (BnEdgeLocal) iout.next();
4829            sev.setState(hero.interfaces.Constants.Ed.edgeStateName[actualEdge.getState()]);
4830            sev.setInNode(((BnNodeLocal) actualEdge.getInBnNode()).getName());
4831            sev.setOutNode(((BnNodeLocal) actualEdge.getOutBnNode()).getName());
4832            edges.add(sev);
4833        }
4834        return ((Collection JavaDoc) edges);
4835    }
4836    
4837    /**
4838     * Get the StrutsEdges. Returns project edges information with a specific java bean structure (useful in
4839     * struts web applications).
4840     *
4841     * @return Collection of StrutsEdgeValue - all project edges
4842     * @ejb:interface-method view-type="both"
4843     * @ejb:transaction type="Supports"
4844     * @throws HeroException
4845     *
4846     **/

4847    public Collection JavaDoc getStrutsEdges() throws HeroException {
4848        if (this.getProjectConfigTrace())
4849            trace.info(" process name = " + this.getName()+ " started by " + this.getCaller());
4850        
4851        // Vector strutsEdges = new Vector();
4852
ArrayList JavaDoc strutsEdges = new ArrayList JavaDoc();
4853        Collection JavaDoc edges = mProject.getBnEdges();
4854        Iterator JavaDoc i = edges.iterator();
4855        while (i.hasNext()) {
4856            BnEdgeLocal e = (BnEdgeLocal) i.next();
4857            StrutsEdgeValue sev = new StrutsEdgeValue();
4858            sev.setName(e.getName());
4859            sev.setState(
4860                    hero.interfaces.Constants.Ed.edgeStateName[e.getState()]);
4861            sev.setInNode(e.getInBnNode().getName());
4862            sev.setOutNode(e.getOutBnNode().getName());
4863            strutsEdges.add(sev);
4864        }
4865        return ((Collection JavaDoc) strutsEdges);
4866    }
4867    
4868    /**
4869     * Import all the nodes, hooks and edges of a project to the current project
4870     *
4871     * @param projectname the name of the project
4872     * @ejb:interface-method view-type="both"
4873     * @ejb:transaction type="Required"
4874     * @throws HeroException
4875     *
4876     **/

4877    public void importProject(String JavaDoc projectName) throws HeroException {
4878        if (this.getProjectConfigTrace())
4879            trace.info("parameter: project=" + projectName + " process name = " + this.getName()+ " started by " + this.getCaller());
4880        importProject(projectName, "");
4881    }
4882    
4883    // -------------------------------------------------------------------------
4884
// ejbCreate and initProject business methods
4885
// -------------------------------------------------------------------------
4886

4887    /**
4888     * Import all the nodes, hooks, properties and edges of a project to the current project
4889     *
4890     * @param projectname the name of the project
4891     * @param prefix the prefix of names for the project
4892     * @ejb:interface-method view-type="both"
4893     * @ejb:transaction type="Required"
4894     * @throws HeroException
4895     *
4896     **/

4897    public void importProject(String JavaDoc projectName, String JavaDoc prefix)
4898    throws HeroException {
4899        if (this.getProjectConfigTrace())
4900            trace.info("parameters: project=" + projectName + " prefix=" + prefix + " process name = " + this.getName()+ " started by " + this.getCaller());
4901        try {
4902            BnProjectLocalHome opHome = hero.interfaces.BnProjectUtil.getLocalHome();
4903            BnProjectLocal oldProject = opHome.findByName(projectName);
4904            String JavaDoc actualProject = this.getName();
4905            
4906            BnProjectValue pv = oldProject.getBnProjectValue();
4907            
4908            mProject.setType(oldProject.getType());
4909            mProject.setStatus(Constants.Pj.ACTIVE);
4910            
4911            // Project Properties (default value)
4912
Collection JavaDoc props = oldProject.getBnProperties();
4913            for (Iterator JavaDoc i = props.iterator(); i.hasNext();) {
4914                BnProjectPropertyLocal prop = (BnProjectPropertyLocal) i.next();
4915                this.setProperty(prop.getTheKey(),prop.getTheValue());
4916            }
4917            
4918            //Project InterHooks
4919
Collection JavaDoc hooks = oldProject.getBnInterHooks();
4920            for (Iterator JavaDoc i = hooks.iterator(); i.hasNext();) {
4921                BnProjectInterHookLocal hk = (BnProjectInterHookLocal) i.next();
4922                this.addInterHook(hk.getName(),hk.getEvent(),hk.getType(),hk.getScript());
4923            }
4924            
4925            //Project Hooks
4926
Collection JavaDoc pHooks = oldProject.getBnHooks();
4927            for (Iterator JavaDoc i = pHooks.iterator(); i.hasNext();) {
4928                BnProjectHookLocal hk = (BnProjectHookLocal) i.next();
4929                this.addHook(hk.getName(),hk.getEvent(),hk.getType());
4930            }
4931            
4932            Collection JavaDoc roles = oldProject.getBnRoles();
4933            for (Iterator JavaDoc i = roles.iterator(); i.hasNext();)
4934            {
4935                BnRoleLocal ro = (BnRoleLocal)i.next();
4936                String JavaDoc roleName = ro.getName();
4937                // add mapper for the instance
4938
if (!containsRole(roleName))
4939                    this.addRole(roleName, ro.getDescription());
4940                if (ro.getBnRoleMapper()!=null)
4941                    this.addRoleMapper(ro.getName(),ro.getBnRoleMapper().getName(),ro.getBnRoleMapper().getType());
4942            }
4943            
4944            // Copy not connected nodes
4945
Collection JavaDoc allNodes = oldProject.getBnNodes();
4946            Iterator JavaDoc no = allNodes.iterator();
4947            while (no.hasNext()) {
4948                BnNodeLocal node = (BnNodeLocal) no.next();
4949                if (node.getInBnEdges().isEmpty()&& node.getOutBnEdges().isEmpty()) {
4950                    // New Instance if activity is a subProcess
4951
String JavaDoc newNodeName=node.getName();
4952                    if (node.getType() == hero.interfaces.Constants.Nd.SUB_PROCESS_NODE) {
4953                        Iterator JavaDoc pr = subProjects.iterator();
4954                        boolean exit = false;
4955                        while (pr.hasNext()) {
4956                            String JavaDoc nodePr = (String JavaDoc) pr.next();
4957                            if (nodePr.equals(newNodeName)) {
4958                                newNodeName = actualProject + nodePr;
4959                                exit = true;
4960                            }
4961                        }
4962                        try {
4963                            if (!exit) {
4964                                this.initProject(newNodeName, actualProject + newNodeName);
4965                                subProjects.add(newNodeName);
4966                                newNodeName = actualProject + newNodeName;
4967                                mProject = opHome.findByName(actualProject);
4968                            }
4969                        } catch (Exception JavaDoc ce) {
4970                            if (this.getProjectConfigTrace())
4971                                trace.error(ce.getMessage());
4972                            ce.printStackTrace();
4973                        }
4974                    }
4975                    
4976                    this.addNode(newNodeName, node.getType());
4977                    if (!node.getAnticipable())
4978                        this.setNodeTraditional(newNodeName);
4979                    /* modif MBL
4980                    if (node.getDeadline()!=null)
4981                        this.setNodeDeadline(newNodeName,node.getDeadline().getTime());
4982                    if (node.getRelativeDeadline()!=null)
4983                        this.setNodeRelativeDeadline(newNodeName,node.getRelativeDeadline().getTime());
4984                    */

4985                    
4986                    // For deadlines
4987
if (node.getDeadlines().size()!=0){
4988                        Collection JavaDoc co = node.getDeadlines();
4989                        Iterator JavaDoc it = co.iterator();
4990                        ArrayList JavaDoc ar = new ArrayList JavaDoc();
4991                        while (it.hasNext()){
4992                        Date JavaDoc date = (Date JavaDoc)it.next();
4993                        ar.add(new Long JavaDoc(date.getTime()));
4994                        }
4995                        this.setNodeDeadlines(newNodeName,ar);
4996                    }
4997                    // For relative deadlines
4998
if (node.getRelativeDeadlines().size()!=0){
4999                        Collection JavaDoc co = node.getRelativeDeadlines();
5000                        Iterator JavaDoc it = co.iterator();
5001                        ArrayList JavaDoc ar = new ArrayList JavaDoc();
5002                        while (it.hasNext()){
5003                        Date JavaDoc date = (Date JavaDoc)it.next();
5004                        ar.add(new Long JavaDoc(date.getTime()));
5005                        }
5006                        this.setNodeRelativeDeadlines(newNodeName,ar);
5007                    }
5008                    this.setNodeRole(newNodeName,node.getBnRole().getName());
5009                    this.setNodeDescription(newNodeName, node.getDescription());
5010                    
5011                    //Node InterHooks
5012
Collection JavaDoc nodeHooks = node.getBnInterHooks();
5013                    for (Iterator JavaDoc j = nodeHooks.iterator(); j.hasNext();) {
5014                        BnNodeInterHookLocal nh = (BnNodeInterHookLocal) j.next();
5015                        try {
5016                            this.addNodeInterHook(newNodeName,nh.getName(),nh.getEvent(),nh.getType(),nh.getScript());
5017                        } catch (Exception JavaDoc ih) {
5018                            if (this.getProjectConfigTrace())
5019                                trace.error(ih.getMessage());
5020                        }; // For subProcess Instance consistency
5021
}
5022                    
5023                    //Node Hooks
5024
Collection JavaDoc nHooks = node.getBnHooks();
5025                    for (Iterator JavaDoc j = nHooks.iterator(); j.hasNext();) {
5026                        BnNodeHookLocal nh = (BnNodeHookLocal) j.next();
5027                        try {
5028                            this.addNodeHook(newNodeName,nh.getName(),nh.getEvent(),nh.getType());
5029                        } catch (Exception JavaDoc ih) {}; // For subProcess Instance consistency
5030
}
5031                }
5032            }
5033            
5034            Collection JavaDoc edges = oldProject.getBnEdges();
5035            Iterator JavaDoc e = edges.iterator();
5036            while (e.hasNext())
5037            {
5038                BnEdgeLocal ed = (BnEdgeLocal)e.next();
5039                BnNodeLocal nodeIn = ed.getInBnNode();
5040                BnNodeLocal nodeOut = ed.getOutBnNode();
5041                BnNodeLocal[] nodes = { nodeIn, nodeOut };
5042                String JavaDoc newNodeNameIn = null;
5043                String JavaDoc newNodeNameOut = null;
5044                for (int n = 0; n < nodes.length; n++) {
5045                    String JavaDoc newNodeName = nodes[n].getName();
5046                    // New Instance if activity is a subProcess
5047
if (nodes[n].getType()== hero.interfaces.Constants.Nd.SUB_PROCESS_NODE){
5048                        Iterator JavaDoc pr = subProjects.iterator();
5049                        boolean exit = false;
5050                        while (pr.hasNext()) {
5051                            String JavaDoc nodePr = (String JavaDoc) pr.next();
5052                            if (nodePr.equals(newNodeName)) {
5053                                newNodeName = actualProject+nodePr;
5054                                exit = true;
5055                            }
5056                        }
5057                        try {
5058                            if (!exit) {
5059                                this.initProject(newNodeName,actualProject+newNodeName);
5060                                subProjects.add(newNodeName);
5061                                newNodeName=actualProject+newNodeName;
5062                                mProject = opHome.findByName(actualProject);
5063                            }
5064                        }catch(Exception JavaDoc ce){
5065                            if (this.getProjectConfigTrace())
5066                                trace.error(ce.getMessage());
5067                            ce.printStackTrace();
5068                        }
5069                    }
5070                    try {
5071                        this.addNode(newNodeName, nodes[n].getType());
5072                        if (!nodes[n].getAnticipable())
5073                            this.setNodeTraditional(newNodeName);
5074                        /* modif MBL
5075                        if (nodes[n].getDeadline()!=null)
5076                            this.setNodeDeadline(newNodeName,nodes[n].getDeadline().getTime());
5077                        if (nodes[n].getRelativeDeadline()!=null)
5078                            this.setNodeRelativeDeadline(newNodeName,nodes[n].getRelativeDeadline().getTime());
5079                        */

5080                        
5081                        // For deadlines
5082
if (nodes[n].getDeadlines().size()!=0){
5083                            Collection JavaDoc co = nodes[n].getDeadlines();
5084                            Iterator JavaDoc it = co.iterator();
5085                            ArrayList JavaDoc ar = new ArrayList JavaDoc();
5086                            while (it.hasNext()){
5087                            Date JavaDoc date = (Date JavaDoc)it.next();
5088                            ar.add(new Long JavaDoc(date.getTime()));
5089                            }
5090                            this.setNodeDeadlines(newNodeName,ar);
5091                        }
5092                        // For relative deadlines
5093
if (nodes[n].getRelativeDeadlines().size()!=0){
5094                            Collection JavaDoc co = nodes[n].getRelativeDeadlines();
5095                            Iterator JavaDoc it = co.iterator();
5096                            ArrayList JavaDoc ar = new ArrayList JavaDoc();
5097                            while (it.hasNext()){
5098                            Date JavaDoc date = (Date JavaDoc)it.next();
5099                            ar.add(new Long JavaDoc(date.getTime()));
5100                            }
5101                            this.setNodeRelativeDeadlines(newNodeName,ar);
5102                        }
5103                        this.setNodeRole(newNodeName,nodes[n].getBnRole().getName());
5104                        this.setNodeDescription(newNodeName,nodes[n].getDescription());
5105                        
5106                        //Node InterHooks
5107
BnNodeLocal nd = oldProject.getBnNode(nodes[n].getName());
5108                        Collection JavaDoc nodeHooks = nd.getBnInterHooks();
5109                        for (Iterator JavaDoc j = nodeHooks.iterator(); j.hasNext();) {
5110                            BnNodeInterHookLocal nh = (BnNodeInterHookLocal) j.next();
5111                            try {
5112                                this.addNodeInterHook(newNodeName,nh.getName(),nh.getEvent(),nh.getType(),nh.getScript());
5113                            } catch (Exception JavaDoc ih) {
5114                                if (this.getProjectConfigTrace())
5115                                    trace.error(ih.getMessage());
5116                            }; // For subProcess Instance consistency
5117
}
5118                        
5119                        //Node Hooks
5120
Collection JavaDoc nHooks = nd.getBnHooks();
5121                        for (Iterator JavaDoc j = nHooks.iterator(); j.hasNext();) {
5122                            BnNodeHookLocal nh = (BnNodeHookLocal) j.next();
5123                            try {
5124                                this.addNodeHook(newNodeName,nh.getName(),nh.getEvent(),nh.getType());
5125                            } catch (Exception JavaDoc ih) {}; // For subProcess Instance consistency
5126
}
5127                                                
5128                    } catch (Exception JavaDoc an) {
5129                        if (this.getProjectConfigTrace())
5130                            trace.error(an.getMessage());
5131                    }; // Node already exist
5132
if (n == 0)
5133                        newNodeNameIn = newNodeName;
5134                    else
5135                        newNodeNameOut = newNodeName;
5136                }
5137                
5138                String JavaDoc edgeName = this.addEdge(newNodeNameIn, newNodeNameOut);
5139                this.setEdgeCondition(edgeName, ed.getCondition());
5140            }
5141            
5142            // Project Iterations
5143
Collection JavaDoc ites = oldProject.getBnIterations();
5144            Iterator JavaDoc iterations = ites.iterator();
5145            while (iterations.hasNext())
5146            {
5147                BnIterationLocal ite = (BnIterationLocal)iterations.next();
5148                this.addIteration(ite.getFromNode(),ite.getToNode(),ite.getCondition());
5149            }
5150            
5151            // Users and roles
5152

5153            BnUserLightValue[] users = pv.getBnUsers();
5154            int uIndex = 0;
5155            for (uIndex=0;uIndex<users.length;uIndex++)
5156            {
5157                BnUserLightValue userP = users[uIndex];
5158                try {
5159                    this.addUser(userP.getName());
5160                } catch (Exception JavaDoc eUser) {
5161                    if (this.getProjectConfigTrace())
5162                        trace.error(eUser.getMessage());
5163                    jms.sendProjectEvent(ADDUSERPROJECT,mProject.getName(),userP.getName());
5164                }
5165                mProject = oldProject;
5166                Collection JavaDoc userRoles = this.getUserRolesInProjectNames(userP.getName());
5167                mProject = opHome.findByName(actualProject);
5168                Iterator JavaDoc ir = userRoles.iterator();
5169                while (ir.hasNext())
5170                    this.setUserRole(userP.getName(),(String JavaDoc) ir.next());
5171            }
5172            
5173            
5174        } catch (FinderException JavaDoc e) {
5175            if (this.getProjectConfigTrace())
5176                trace.error("Cannot find project " + e.getMessage());
5177            throw new HeroException("Cannot find project " + e.getMessage());
5178        } catch (javax.naming.NamingException JavaDoc ne) {
5179            if (this.getProjectConfigTrace())
5180                trace.error(ne.getMessage());
5181            throw new HeroException(ne.getMessage());
5182        }
5183    }
5184    
5185    /**
5186     * Import Project instance. Import all the nodes, hooks, properties,edges and users of a project instant to the
5187     * current project
5188     *
5189     * @param projectname the name of the project
5190     * @param instance the instance name of the project
5191     * @ejb:interface-method view-type="both"
5192     * @ejb:transaction type="Required"
5193     * @throws HeroException
5194     *
5195     **/

5196    public String JavaDoc importInstance(BonitaProjectValue pv, String JavaDoc instance)
5197    throws HeroException {
5198        BnUserLocalHome uhome = null;
5199        BnRoleLocalHome rhome = null;
5200        BnProjectConfigLocalHome pchome = null;
5201        BnProjectLocalHome opHome = null;
5202        UserServiceLocalHome ushome;
5203        
5204        if (this.getProjectConfigTrace())
5205            trace.info("parameter: project=" + pv.getName() + " process name = " + this.getName()+ " started by " + this.getCaller());
5206        try {
5207            uhome = hero.interfaces.BnUserUtil.getLocalHome();
5208            rhome = hero.interfaces.BnRoleUtil.getLocalHome();
5209            pchome = hero.interfaces.BnProjectConfigUtil.getLocalHome();
5210            opHome = hero.interfaces.BnProjectUtil.getLocalHome();
5211            
5212            String JavaDoc creator = this.getCaller();
5213            mProject = opHome.create(instance,creator);
5214            mProject.setType(Constants.Pj.INSTANCE);
5215            mProject.setStatus(Constants.Pj.ACTIVE);
5216            
5217            instance=mProject.getName();
5218            mProject.setParent(mProject.getName()); // Only for subprocesses
5219
mProject.setModel(pv);
5220            mProject.setBnProjectConfig(pchome.create(pv.getProjectConfig(),instance));
5221            
5222            BnUserLocal user = uhome.findByName(creator);
5223            mProject.getBnUsers().add(user);
5224            // role admin is added
5225
BnRoleValue rv = new BnRoleValue();
5226            rv.setName(hero.interfaces.Constants.ADMIN);
5227            rv.setDescription("the admin role");
5228            BnRoleLocal role = rhome.create(rv);
5229            mProject.getBnRoles().add(role);
5230            // Set User Role
5231
user.getBnRoles().add(role);
5232            
5233            // role InitialRole is added
5234
rv = new BnRoleValue();
5235            rv.setName(hero.interfaces.Constants.INITIALROLE);
5236            rv.setDescription("the initial role for nodes");
5237            role = rhome.create(rv);
5238            mProject.getBnRoles().add(role);
5239            
5240            if (!creator.equals(Constants.ADMIN))
5241            {
5242                // role username is added
5243
rv = new BnRoleValue();
5244                rv.setName(creator);
5245                rv.setDescription(creator+" user role");
5246                role = rhome.create(rv);
5247                mProject.getBnRoles().add(role);
5248                // Set User Role
5249
user.getBnRoles().add(role);
5250            }
5251            
5252            // Project Properties
5253
Collection JavaDoc propers = pv.getProperties();
5254            Iterator JavaDoc props = propers.iterator();
5255            while (props.hasNext())
5256            {
5257                BonitaPropertyValue prop = (BonitaPropertyValue) props.next();
5258                this.setPropertyPossibleValues(prop.getKey(),prop.getPossibleValues());
5259                if (prop.getValue()!=null || prop.getPossibleValues().size()==0)
5260                    this.setProperty(prop.getKey(),prop.getValue());
5261                
5262            }
5263            // Project Roles
5264
Collection JavaDoc roles = pv.getRoles();
5265            Iterator JavaDoc allRoles = roles.iterator();
5266            while (allRoles.hasNext())
5267            {
5268                BonitaRoleValue ro = (BonitaRoleValue)allRoles.next();
5269                String JavaDoc roleName = ro.getName();
5270                // add mapper for the instance
5271
if (!containsRole(roleName))
5272                    this.addRole(roleName, ro.getDescription());
5273                if (ro.getMapper()!=null)
5274                    this.addRoleMapper(ro.getName(),ro.getMapper().getName(),ro.getMapper().getType());
5275            }
5276            
5277            // First activity/ies
5278
Collection JavaDoc nds = pv.getNodes();
5279            Iterator JavaDoc nodes = nds.iterator();
5280            while (nodes.hasNext())
5281            {
5282                BonitaNodeValue nd = (BonitaNodeValue)nodes.next();
5283                if (nd.getInEdges().isEmpty())
5284                {
5285                    String JavaDoc newNodeName = nd.getName();
5286                    if (nd.getType() == Constants.Nd.SUB_PROCESS_NODE) // First activity is a subProcess
5287
{
5288                        newNodeName = this.instantiateProject(newNodeName);
5289                        mProject.setParent(instance);
5290                        mProject = opHome.findByName(instance);
5291                    }
5292                    
5293                    this.addNode(newNodeName,nd.getType());
5294                    if (!nd.getAnticipable())
5295                        this.setNodeTraditional(newNodeName);
5296                                            
5297                    // For Deadlines
5298
if (nd.getDeadlines().size()!=0){
5299                        Collection JavaDoc co = nd.getDeadlines();
5300                        Iterator JavaDoc it = co.iterator();
5301                        ArrayList JavaDoc ar = new ArrayList JavaDoc();
5302                        while (it.hasNext()){
5303                        Date JavaDoc date = (Date JavaDoc)it.next();
5304                        ar.add(new Long JavaDoc(date.getTime()));
5305                        }
5306                        this.setNodeDeadlines(newNodeName,ar);
5307                    }
5308                    // For relative Deadlines
5309
if (nd.getRelativeDeadlines().size()!=0){
5310                        Collection JavaDoc co = nd.getRelativeDeadlines();
5311                        Iterator JavaDoc it = co.iterator();
5312                        ArrayList JavaDoc ar = new ArrayList JavaDoc();
5313                        while (it.hasNext()){
5314                        Date JavaDoc date = (Date JavaDoc)it.next();
5315                        ar.add(new Long JavaDoc(date.getTime()));
5316                        }
5317                        this.setNodeRelativeDeadlines(newNodeName,ar);
5318                    }
5319                    this.setNodeRole(newNodeName,nd.getRole());
5320                    this.setNodeDescription(newNodeName,nd.getDescription());
5321                    if (!nd.getProjectParent().equals(nd.getProjectName()))
5322                        this.setNodeState(mProject.getBnNode(newNodeName),Constants.Nd.INITIAL);
5323                    
5324                    if (nd.getPerformer()!=null)
5325                        this.addNodePerformerAssign(newNodeName,nd.getPerformer().getName(),nd.getPerformer().getType(),nd.getPerformer().getPropertyName());
5326                    
5327                    Collection JavaDoc nodeProp = nd.getProperties();
5328                    Iterator JavaDoc nodeProps = nodeProp.iterator();
5329                    while (nodeProps.hasNext())
5330                    {
5331                        BonitaPropertyValue ndProp = (BonitaPropertyValue)nodeProps.next();
5332                        this.setNodePropertyPossibleValues(newNodeName,ndProp.getKey(),ndProp.getPossibleValues());
5333                        if (ndProp.getValue()!=null || ndProp.getPossibleValues().size()==0)
5334                            this.setNodeProperty(newNodeName,ndProp.getKey(),ndProp.getValue(),ndProp.getPropagate());
5335                    }
5336                                                                            
5337                    // For Deadlines or relative deadlines
5338
if (nd.getDeadlines().size()!=0 || nd.getRelativeDeadlines().size()!=0)
5339                        BonitaDeadline.getInstance().startDeadlines(newNodeName, mProject.getId());
5340                    
5341                    // Project Iterations
5342
Collection JavaDoc iterations = pv.getIterations();
5343                    Iterator JavaDoc iter = iterations.iterator();
5344                    while (iter.hasNext())
5345                    {
5346                        BonitaIterationValue iteration = (BonitaIterationValue) iter.next();
5347                        String JavaDoc from = iteration.getFromNode();
5348                        if (newNodeName.matches(from+"_instance.*") || newNodeName.equals(from))
5349                        {
5350                            this.addIteration(newNodeName, newNodeName,iteration.getCondition());
5351                            break;
5352                        }
5353                    }
5354                    if ((nd.getType()==Constants.Nd.SUB_PROCESS_NODE || nd.getType()==Constants.Nd.AND_JOIN_AUTOMATIC_NODE || nd.getType()==Constants.Nd.OR_JOIN_AUTOMATIC_NODE)
5355                            && (nd.getProjectParent().equals(nd.getProjectName())))
5356                    {
5357                        EngineLocalHome enghome;
5358                        try {
5359                            enghome = hero.interfaces.EngineUtil.getLocalHome();
5360                            EngineLocal engine = enghome.create();
5361                            engine.startActivity(mProject.getName(), newNodeName);
5362                        } catch (javax.naming.NamingException JavaDoc ne) {
5363                            throw new HeroException(ne.getMessage());
5364                        }
5365                    }
5366
5367                }
5368            }
5369            Collection JavaDoc users = pv.getUsers();
5370            Iterator JavaDoc usersI = users.iterator();
5371            while(usersI.hasNext())
5372            {
5373                BonitaUserValue userP = (BonitaUserValue)usersI.next();
5374                try {
5375                    this.addUserLocal(userP.getName());
5376                } catch (Exception JavaDoc eUser) {
5377                    if (this.getProjectConfigTrace())
5378                        trace.error(eUser.getMessage());
5379                }
5380                Collection JavaDoc userRoles = userP.getRoles();
5381                Iterator JavaDoc ir = userRoles.iterator();
5382                while (ir.hasNext())
5383                {
5384                    String JavaDoc roleName = (String JavaDoc) ir.next();
5385                    this.setUserRoleLocal(userP.getName(),roleName);
5386                }
5387            }
5388            mProject.setCreationDate(new Date JavaDoc());
5389            
5390            // mapper execution
5391
this.mapRole();
5392            jms.sendProjectEvent(ADDUSERPROJECT, instance, creator);
5393            return instance;
5394        } catch (javax.naming.NamingException JavaDoc ne) {
5395            if (this.getProjectConfigTrace())
5396                trace.error(ne.getMessage());
5397            throw new HeroException(ne.getMessage());
5398        } catch (Exception JavaDoc ce) {ce.printStackTrace();
5399            if (this.getProjectConfigTrace())
5400                trace.error("Instantiate process error " + ce.getMessage());
5401            throw new HeroException("Instantiate process error " + ce.getMessage());
5402        }
5403    }
5404    
5405    /**
5406     * Creates a cooperative workflow or init the Project Session Bean for this cooperative workflow/instance. You have to call this method after "create" call. After that
5407     * all methods of ProjectSession API are available.
5408     *
5409     * @param projectName project name
5410     * @ejb:interface-method view-type="both"
5411     * @ejb:transaction type="Required"
5412     * @throws HeroException
5413     **/

5414    public void initProject(String JavaDoc projectName) throws HeroException {
5415        Context JavaDoc lContext;
5416        UserServiceLocalHome ushome = null;
5417        mProject=null;
5418        if (this.getProjectConfigTrace())
5419            trace.info("parameter: project=" + projectName + " started by " + this.getCaller());
5420        if (projectName.equals(""))
5421            throw new HeroException("Project name can not be empty...");
5422        try {
5423            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
5424            
5425            UserServiceLocal ul = ushome.create();
5426            ul.findUserLocal(this.getCaller());
5427        } catch (Exception JavaDoc ce) {
5428            if (this.getProjectConfigTrace())
5429                trace.error(ce.getMessage());
5430            throw new HeroException(ce.getMessage());
5431        }
5432        try {
5433            if (!this.isInProject(projectName))
5434                throw new AccessException("You don't have access to this project !!");
5435            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5436            this.mProject = pHome.findByName(projectName);
5437        } catch (javax.naming.NamingException JavaDoc ne) {
5438            if (this.getProjectConfigTrace())
5439                trace.error(ne.getMessage());
5440            throw new HeroException(ne.getMessage());
5441        } catch (javax.ejb.FinderException JavaDoc fe) {
5442            try{
5443                this.createProcess(projectName); // Create Process
5444
mProject.setType(Constants.Pj.COOPERATIVE);
5445                mProject.setStatus(Constants.Pj.ACTIVE);
5446            }catch (CreateException JavaDoc ce){
5447                if (this.getProjectConfigTrace())
5448                    trace.error(ce.getMessage());
5449                throw new HeroException(ce.getMessage());
5450            }
5451        }
5452    }
5453    
5454    /**
5455     * Creates a workflow process model or Init the Project Session Bean for this model. You have to call this method after "create" call. After that
5456     * all methods of ProjectSession API are available.
5457     *
5458     * @param modelName model name
5459     * @ejb:interface-method view-type="both"
5460     * @ejb:transaction type="Required"
5461     * @throws HeroException
5462     **/

5463    public void initModel(String JavaDoc modelName) throws HeroException {
5464        Context JavaDoc lContext;
5465        UserServiceLocalHome ushome = null;
5466        mProject=null;
5467        if (this.getProjectConfigTrace())
5468            trace.info("parameter: project=" + modelName + " started by " + this.getCaller());
5469        if (modelName.equals(""))
5470            throw new HeroException("Project name can not be empty...");
5471        try {
5472            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
5473            UserServiceLocal ul = ushome.create();
5474            ul.findUserLocal(this.getCaller());
5475        } catch (Exception JavaDoc ce) {
5476            if (this.getProjectConfigTrace())
5477                trace.error(ce.getMessage());
5478            throw new HeroException(ce.getMessage());
5479        }
5480        try {
5481            if (!this.isInProject(modelName))
5482                throw new AccessException("You don't have access to this project !!");
5483            
5484            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5485            this.mProject = pHome.findByName(modelName);
5486        } catch (javax.naming.NamingException JavaDoc ne) {
5487            if (this.getProjectConfigTrace())
5488                trace.error(ne.getMessage());
5489            throw new HeroException(ne.getMessage());
5490        } catch (javax.ejb.FinderException JavaDoc fe) {
5491            try{
5492                this.createProcess(modelName); // Create Process
5493
mProject.setType(Constants.Pj.MODEL);
5494                mProject.setStatus(Constants.Pj.ACTIVE);
5495            }catch (CreateException JavaDoc ce){
5496                if (this.getProjectConfigTrace())
5497                    trace.error(ce.getMessage());
5498                throw new HeroException(ce.getMessage());
5499            }
5500        }
5501    }
5502    
5503    /**
5504     * init the Project Session Bean (clone project).You have to call this method after "create" call. After that
5505     * the project is cloned and all methods of ProjectSession API are available.
5506     *
5507     * @throws HeroException
5508     * @param oldProject the name of the project to clone
5509     * @param newProject the name of the project clone.
5510     * @ejb:interface-method view-type="both"
5511     * @ejb:transaction type="Required"
5512     * @throws CreateException
5513     **/

5514    public void initProject(String JavaDoc oldProject, String JavaDoc newProject)
5515    throws CreateException JavaDoc {
5516     try{
5517        if (this.getProjectConfigTrace())
5518            trace.info("parameters: oldProject="+ oldProject+ " newProject="+ newProject + " started by " + this.getCaller());
5519        Context JavaDoc lContext;
5520        BnUserLocalHome uhome = null;
5521        BnRoleLocalHome rhome = null;
5522        BnProjectConfigLocalHome pchome = null;
5523        UserServiceLocalHome ushome;
5524        try {
5525            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
5526            UserServiceLocal ul = ushome.create();
5527            ul.findUserLocal(this.getCaller());
5528        } catch (Exception JavaDoc ce) {
5529            if (this.getProjectConfigTrace())
5530                trace.error(ce.getMessage());
5531            throw new HeroException(ce.getMessage());
5532        }
5533        if (oldProject.equals("") || newProject.equals(""))
5534            throw new CreateException JavaDoc("Project name can not be empty...");
5535        try {
5536            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5537            uhome = hero.interfaces.BnUserUtil.getLocalHome();
5538            rhome = hero.interfaces.BnRoleUtil.getLocalHome();
5539            pchome = hero.interfaces.BnProjectConfigUtil.getLocalHome();
5540            mProject = pHome.findByName(newProject);
5541        } catch (javax.naming.NamingException JavaDoc ne) {
5542            if (this.getProjectConfigTrace())
5543                trace.error(ne.getMessage());
5544            throw new CreateException JavaDoc(ne.getMessage());
5545        } catch (javax.ejb.FinderException JavaDoc fe) {
5546            if (this.getProjectConfigTrace())
5547                trace.error(fe.getMessage());
5548            // The project has to be created
5549
try {
5550                String JavaDoc creator = this.getCaller();
5551                mProject = pHome.create(newProject, creator);
5552                mProject.setParent(newProject);
5553                BonitaProjectValue pv = new BonitaProjectValue();
5554                pv.setName(newProject);
5555                mProject.setModel(pv);
5556                
5557                BnUserLocal user = uhome.findByName(creator);
5558                mProject.getBnUsers().add(user);
5559                mProject.setBnProjectConfig(pchome.create());
5560                
5561                // role admin is added
5562
BnRoleValue rv = new BnRoleValue();
5563                rv.setName(hero.interfaces.Constants.ADMIN);
5564                rv.setDescription("the admin role");
5565                BnRoleLocal role = rhome.create(rv);
5566                mProject.getBnRoles().add(role);
5567                // Set User Role
5568
user.getBnRoles().add(role);
5569                
5570                // role InitialRole is added
5571
rv = new BnRoleValue();
5572                rv.setName(hero.interfaces.Constants.INITIALROLE);
5573                rv.setDescription("the initial role for nodes");
5574                role = rhome.create(rv);
5575                mProject.getBnRoles().add(role);
5576                
5577                if (!creator.equals(Constants.ADMIN))
5578                {
5579                    // role username is added
5580
rv = new BnRoleValue();
5581                    rv.setName(creator);
5582                    rv.setDescription(creator+" user role");
5583                    role = rhome.create(rv);
5584                    mProject.getBnRoles().add(role);
5585                    // Set User Role
5586
user.getBnRoles().add(role);
5587                }
5588                
5589                importProject(oldProject);
5590                mProject.setCreationDate(new Date JavaDoc());
5591                
5592                jms.sendProjectEvent(ADDUSERPROJECT, newProject, creator);
5593                
5594            } catch (FinderException JavaDoc fie) {
5595                if (this.getProjectConfigTrace())
5596                    trace.error(fie.getMessage());
5597                throw new CreateException JavaDoc(fie.getMessage());
5598            } catch (InvalidValueException ie) {
5599                if (this.getProjectConfigTrace())
5600                    trace.error(ie.getMessage());
5601                throw new CreateException JavaDoc(ie.getMessage());
5602            } catch (HeroException he) {
5603                if (this.getProjectConfigTrace())
5604                    trace.error(he.getMessage());
5605                throw new CreateException JavaDoc(he.getMessage());
5606            }
5607        }
5608     }catch(HeroException traceEx){traceEx.printStackTrace();}
5609    }
5610    
5611    /**
5612     * Project instance. You have to call this method after "create" call. After that
5613     * you have an instance of the project and all methods of ProjectSession API are available.
5614     *
5615     * @param project the name of the project to instance
5616     * @return String - the name of the project instance
5617     * @ejb:interface-method view-type="both"
5618     * @ejb:transaction type="Supports"
5619     * @throws CreateException
5620     **/

5621    public String JavaDoc instantiateProject(String JavaDoc project) throws CreateException JavaDoc {
5622      Context JavaDoc lContext;
5623      String JavaDoc instance=null;
5624      UserServiceLocalHome ushome;
5625      try{
5626        if (this.getProjectConfigTrace())
5627            trace.info("parameter: project=" + project + " started by " + this.getCaller());
5628        try {
5629            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5630            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
5631            UserServiceLocal ul = ushome.create();
5632            ul.findUserLocal(this.getCaller());
5633        } catch (Exception JavaDoc ce) {
5634            if (this.getProjectConfigTrace())
5635                trace.error(ce.getMessage());
5636            throw new HeroException(ce.getMessage());
5637        }
5638        if (project.equals(""))
5639            throw new CreateException JavaDoc("Project name can not be empty !!");
5640        if (project.matches(".*_instance.*"))
5641            throw new CreateException JavaDoc("You cannot instantiate an instance !!");
5642        try {
5643            try {
5644                pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5645                mProject = pHome.findByName(project);
5646            } catch (javax.naming.NamingException JavaDoc ne) {
5647                throw new BonitaServiceException(ne.getMessage());
5648            } catch (javax.ejb.FinderException JavaDoc fe) {throw new BonitaServiceException(fe.getMessage());}
5649            
5650            BonitaProjectValue pv=null;
5651            if (mProject.getModel().getType() != null) // model is not yet initialized
5652
pv=mProject.getModel();
5653            else
5654            {
5655                pv = BonitaProjectLocator.generateProjectValue(project);
5656                mProject.setModel(pv);
5657            }
5658            if (!pv.getType().equals(Constants.Pj.MODEL))
5659                throw new BonitaServiceException("This process is not instantiable. Only model processes can be instantiated !!");
5660            
5661            if (pv.getStatus().equals(Constants.Pj.HIDDEN))
5662                throw new BonitaServiceException("This model is not ACTIVE. Active the model before instantiate it !!");
5663            
5664            instance=project+"_instance";
5665            instance=((ProjectSessionLocal)mContext.getEJBLocalObject()).importInstance(pv, instance);
5666        } catch (BonitaServiceException e) {
5667          throw new CreateException JavaDoc(e.getMessage());
5668        }
5669                                
5670        if (this.getProjectConfigLog())
5671        thelog.debug("User: "+ this.getCaller() + " instantiates project: " + project + ". " +instance + " is created");
5672      }catch(HeroException traceEx){traceEx.printStackTrace();}
5673    return (instance);
5674    }
5675            
5676    /**
5677     * Creates the Project Session Bean. This method is the first one to invoke in order to
5678     * use ProjectSession API. If the user is not authorized this method throws an exception.
5679     *
5680     * @throws CreateException
5681     *
5682     * @ejb:create-method view-type="both"
5683     **/

5684    
5685    public void ejbCreate() throws CreateException JavaDoc {
5686        this.caller = mContext.getCallerPrincipal().getName();
5687    }
5688    
5689    /**
5690     * Internal Enterprise Java Beans method.
5691     **/

5692    public void ejbPostCreate(String JavaDoc oldProject, String JavaDoc newProject)
5693    throws CreateException JavaDoc, RemoteException JavaDoc {
5694    }
5695    
5696    /**
5697     * Internal Enterprise Java Beans method.
5698     **/

5699    public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
5700        mContext = context;
5701        try{
5702            JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
5703            this.jms=home.create();
5704            this.bonitaConfig = new BonitaConfig();
5705        }catch(Exception JavaDoc e){throw new EJBException JavaDoc(e.getMessage());}
5706    }
5707    
5708    /**
5709     * Internal Enterprise Java Beans method.
5710     **/

5711    
5712    public void ejbRemove() {
5713    }
5714    
5715    /**
5716     * Internal Enterprise Java Beans method.
5717     **/

5718    
5719    public void ejbActivate() {
5720    }
5721    
5722    /**
5723     * Internal Enterprise Java Beans method.
5724     **/

5725    
5726    public void ejbPassivate() {
5727    }
5728    
5729    // Utility methods
5730

5731    
5732    private void createProcess(String JavaDoc projectName)throws HeroException, CreateException JavaDoc
5733    {
5734        BnUserLocalHome uhome = null;
5735        BnRoleLocalHome rhome = null;
5736        BnProjectConfigLocalHome pchome = null;
5737        try {
5738            pHome = hero.interfaces.BnProjectUtil.getLocalHome();
5739            uhome = hero.interfaces.BnUserUtil.getLocalHome();
5740            rhome = hero.interfaces.BnRoleUtil.getLocalHome();
5741            pchome = hero.interfaces.BnProjectConfigUtil.getLocalHome();
5742        } catch (javax.naming.NamingException JavaDoc ne) {
5743            if (this.getProjectConfigTrace())
5744                trace.error(ne.getMessage());
5745            throw new CreateException JavaDoc(ne.getMessage());
5746        }
5747        // The project has to be created
5748
try {
5749            String JavaDoc creator = this.getCaller();
5750            mProject = pHome.create(projectName, creator);
5751            mProject.setParent(projectName);
5752            BonitaProjectValue pv = new BonitaProjectValue();
5753            pv.setName(projectName);
5754            mProject.setModel(pv);
5755            mProject.setBnProjectConfig(pchome.create());
5756
5757            BnUserLocal user = uhome.findByName(creator);
5758            mProject.getBnUsers().add(user);
5759            
5760            // role admin is added
5761
BnRoleValue rv = new BnRoleValue();
5762            rv.setName(hero.interfaces.Constants.ADMIN);
5763            rv.setDescription("the admin role");
5764            BnRoleLocal role = rhome.create(rv);
5765            mProject.getBnRoles().add(role);
5766            
5767            // Set User Role
5768
user.getBnRoles().add(role);
5769            
5770            // role InitialRole is added
5771
rv = new BnRoleValue();
5772            rv.setName(hero.interfaces.Constants.INITIALROLE);
5773            rv.setDescription("the initial role for nodes");
5774            role = rhome.create(rv);
5775            mProject.getBnRoles().add(role);
5776            
5777            if (!creator.equals(Constants.ADMIN))
5778            {
5779                // role username is added
5780
rv = new BnRoleValue();
5781                rv.setName(creator);
5782                rv.setDescription(creator+" user role");
5783                role = rhome.create(rv);
5784                mProject.getBnRoles().add(role);
5785                // Set User Role
5786
user.getBnRoles().add(role);
5787            }
5788
5789            mProject.setCreationDate(new Date JavaDoc());
5790            
5791            jms.sendProjectEvent(ADDUSERPROJECT, projectName, creator);
5792        } catch (FinderException JavaDoc fie) {
5793            if (this.getProjectConfigTrace())
5794                trace.error(fie.getMessage());
5795            throw new HeroException(fie.getMessage());
5796        } catch (InvalidValueException ie) {
5797            if (this.getProjectConfigTrace())
5798                trace.error(ie.getMessage());
5799            throw new HeroException(ie.getMessage());
5800        } catch (Exception JavaDoc he) {
5801            if (this.getProjectConfigTrace())
5802                trace.error(he.getMessage());
5803            throw new HeroException(he.getMessage());
5804        }
5805    }
5806    
5807    private boolean isInProject(String JavaDoc projectName) throws HeroException{
5808        if (mContext.getCallerPrincipal().getName().equals(Constants.SECURITY_ROLE))
5809            return true;
5810        BnProjectLocalHome phome = null;
5811        BnProjectLocal plocal = null;
5812        try {
5813            phome = hero.interfaces.BnProjectUtil.getLocalHome();
5814            plocal = phome.findByName(projectName);
5815            Collection JavaDoc users = plocal.getBnUsers();
5816            Iterator JavaDoc usrs = users.iterator();
5817            while (usrs.hasNext())
5818            {
5819                if (((BnUserLocal)usrs.next()).getName().equals(this.getCaller()))
5820                    return true;
5821            }
5822            return false;
5823            
5824        } catch (javax.naming.NamingException JavaDoc ne) {
5825            throw new HeroException(ne.getMessage());
5826        } catch (FinderException JavaDoc fie) {return true;} // The project does not exist
5827
}
5828    
5829    
5830    /**
5831     * Verifies whether the user is admin of this project/instance
5832     *
5833     * @param project the name of the project to instance
5834     * @ejb:interface-method view-type="both"
5835     * @ejb:transaction type="Supports"
5836     * @throws CreateException
5837     **/

5838    public boolean isAdminOfProject(String JavaDoc projectName) throws HeroException{
5839        if (mContext.getCallerPrincipal().getName().equals(Constants.SECURITY_ROLE))
5840            return true;
5841        Collection JavaDoc projects = this.getUserRolesInProjectNames(this.getCaller());
5842        Iterator JavaDoc i = projects.iterator();
5843        while (i.hasNext()) {
5844            String JavaDoc roleName = (String JavaDoc) i.next();
5845            if (roleName.equals(Constants.ADMIN))
5846                return true;
5847        }
5848        return false;
5849    }
5850    
5851    private boolean isProjectHidden() throws HeroException{
5852        if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
5853            return true;
5854        else
5855            return false;
5856    }
5857    
5858    private boolean isUserInNodeRole(String JavaDoc nodeName) throws HeroException{
5859        BnNodeLocalHome nhome = null;
5860        BnNodeLocal nlocal = null;
5861        try {
5862            nhome = hero.interfaces.BnNodeUtil.getLocalHome();
5863            nlocal = nhome.findByName(nodeName,mProject.getId());
5864            Collection JavaDoc users = nlocal.getBnRole().getBnUsers();
5865            
5866            Iterator JavaDoc i = users.iterator();
5867            while (i.hasNext()) {
5868                BnUserLocal user = (BnUserLocal) i.next();
5869                String JavaDoc userName = user.getName();
5870                if (userName.equals(this.getCaller()))
5871                    return true;
5872            }
5873        } catch (javax.naming.NamingException JavaDoc ne) {
5874            throw new HeroException(ne.getMessage());
5875        } catch (FinderException JavaDoc fie) {
5876            throw new HeroException(fie.getMessage());
5877        }
5878        return false;
5879    }
5880    
5881    private boolean checkDynamics(String JavaDoc out) throws HeroException {
5882        BnNodeLocal nodeout = mProject.getBnNode(out);
5883        if ((nodeout.getState() == hero.interfaces.Constants.Nd.INITIAL)
5884                || (nodeout.getState() == hero.interfaces.Constants.Nd.READY)
5885                || (nodeout.getState() == hero.interfaces.Constants.Nd.ANTICIPABLE))
5886            return true;
5887        return false;
5888    }
5889    
5890    // Execute RoleMappers for this instance. This method obtain the users list matching with a
5891
// specific role and add them to the instance. To improuve performance, this method uses the
5892
// adduserlocal and setUserRoleLocal methods below.
5893
private void mapRole() throws HeroException {
5894        try {
5895            String JavaDoc creator = this.getCaller();
5896            Collection JavaDoc mappers = new ArrayList JavaDoc();
5897            Collection JavaDoc roles = mProject.getBnRoles();
5898            BnRoleMapperLocal mapper = null;
5899            Iterator JavaDoc it = roles.iterator();
5900            it = roles.iterator();
5901            while (it.hasNext()){
5902                BnRoleLocal role = (BnRoleLocal) it.next();
5903                mapper = role.getBnRoleMapper();
5904                if (mapper != null){
5905                    hero.mapper.Mapper h = hero.mapper.Mapper.make(mapper.getName(), mapper.getType());
5906                    Collection JavaDoc users = h.execute(this, mapper.getType(), role, creator);
5907                    if (mapper.getType()==(Constants.Mapper.PROPERTIES))
5908                        this.setUserRoleLocal(creator,role.getName());
5909                    else
5910                    {
5911                        Iterator JavaDoc i = users.iterator();
5912                        while (i.hasNext())
5913                        {
5914                            String JavaDoc userName = (String JavaDoc)i.next();
5915                            this.addUserLocal(userName);
5916                            this.setUserRoleLocal(userName,role.getName());
5917                        }
5918                    }
5919                }
5920            }
5921        } catch (HeroException he) {
5922            throw new HeroException(he.getMessage());
5923        }
5924    }
5925    
5926    private void addUserLocal(String JavaDoc userName) throws HeroException
5927    {
5928        BnUserLocalHome uHome;
5929        BnRoleLocalHome rHome;
5930        BnUserLocal mUser;
5931        UserServiceLocalHome ushome;
5932        try {
5933            uHome = hero.interfaces.BnUserUtil.getLocalHome();
5934            rHome = hero.interfaces.BnRoleUtil.getLocalHome();
5935        } catch (javax.naming.NamingException JavaDoc be) {
5936            throw new HeroException(be.getMessage());
5937        }
5938        try {
5939            ushome = hero.interfaces.UserServiceUtil.getLocalHome();
5940            UserServiceLocal ul = ushome.create();
5941            mUser = ul.findUserLocal(userName);
5942        } catch (Exception JavaDoc ce) {
5943            throw new HeroException(ce.getMessage());
5944        }
5945        Collection JavaDoc cUsers = mProject.getBnUsers();
5946        if (!cUsers.contains(mUser))
5947        {
5948            cUsers.add(mUser);
5949            if (!userName.equals(Constants.ADMIN))
5950                this.addRole(userName, "BnUser BnRole");
5951            this.setUserRoleLocal(userName, userName);
5952        }
5953    }
5954    
5955    private void setUserRoleLocal(String JavaDoc userName, String JavaDoc roleName) throws HeroException
5956    {
5957        BnRoleLocalHome roleh;
5958        BnUserLocalHome userh;
5959        try {
5960            roleh = BnRoleUtil.getLocalHome();
5961            userh = BnUserUtil.getLocalHome();
5962        } catch (javax.naming.NamingException JavaDoc ne) {
5963            throw new HeroException(ne.getMessage());
5964        }
5965        try {
5966            BnUserLocal user = userh.findByName(userName);
5967            BnRoleLocal role = roleh.findByName(roleName, mProject.getId());
5968            user.getBnRoles().add(role);
5969        } catch (Exception JavaDoc fe) {
5970            throw new HeroException(fe.getMessage());
5971        }
5972    
5973    }
5974    
5975    private void performAssign() throws HeroException {
5976        // logs trace
5977
if (this.getProjectConfigTrace())
5978            trace.debug("perform assign ");
5979        try {
5980            String JavaDoc creator = this.getCaller();
5981            Collection JavaDoc performers = new ArrayList JavaDoc();
5982            Collection JavaDoc nodes = mProject.getBnNodes();
5983            BnNodePerformerAssignLocal performerAssign = null;
5984            Iterator JavaDoc it = nodes.iterator();
5985            
5986            it = nodes.iterator();
5987            while (it.hasNext()){
5988                BnNodeLocal node = (BnNodeLocal) it.next();
5989                performerAssign = node.getBnNodePerformerAssign();
5990                if (performerAssign != null){
5991                    hero.performerAssign.PerformerAssign h = hero.performerAssign.PerformerAssign.make(performerAssign.getName(), performerAssign.getType());
5992                    h.execute(this, performerAssign.getType(), node, creator);
5993                }
5994            }
5995        } catch (HeroException he) {
5996            throw new HeroException(he.getMessage());
5997        }
5998        
5999    }
6000    
6001    private boolean checkStructuralConstraints(String JavaDoc in, String JavaDoc out) throws HeroException {
6002        visited.add(in);
6003        BnNodeLocal nodeout = mProject.getBnNode(out);
6004        if (visited.contains(out))
6005            return false;
6006        Collection JavaDoc edges = nodeout.getOutBnEdges();
6007        Iterator JavaDoc i = edges.iterator();
6008        while (i.hasNext())
6009        {
6010            BnEdgeLocal edge = (BnEdgeLocal)i.next();
6011            if (!visited.contains(edge.getInBnNode().getName()) && ! checkStructuralConstraints(edge.getInBnNode().getName(),edge.getOutBnNode().getName()))
6012                return false;
6013        }
6014        
6015        return true;
6016    }
6017    
6018    private boolean checkDuplicateEdge(String JavaDoc in, String JavaDoc out)
6019    throws HeroException {
6020        Collection JavaDoc edges = mProject.getBnEdges();
6021        Iterator JavaDoc i = edges.iterator();
6022        while (i.hasNext()) {
6023            BnEdgeLocal edge = (BnEdgeLocal) i.next();
6024            if ((edge.getInBnNode().getName()).equals(in)
6025                    && (edge.getOutBnNode().getName()).equals(out))
6026                return false;
6027        }
6028        return true;
6029    }
6030    
6031    private boolean checkDuplicateAgentEdge(String JavaDoc in, String JavaDoc out)
6032    throws HeroException {
6033        Collection JavaDoc edges = mProject.getBnAgentEdges();
6034        Iterator JavaDoc i = edges.iterator();
6035        while (i.hasNext()) {
6036            BnAgentEdgeLocal edge = (BnAgentEdgeLocal) i.next();
6037            if ((edge.getInBnAgent().getName()).equals(in)
6038                    && (edge.getOutBnNode().getName()).equals(out))
6039                return false;
6040        }
6041        return true;
6042    }
6043    
6044    
6045    /**
6046     * Copy node. Internal method used in processes instantiation.
6047     *
6048     * @param name of the new node
6049     * @param node the BnNodeLocal object of the copied node.
6050     * @param inNode the BnNodeLocal in node object of the new node.
6051     * @ejb:interface-method view-type="local"
6052     * @ejb:transaction type="Required"
6053     *
6054     **/

6055    public void copyNode(String JavaDoc nodeName, BonitaNodeValue node) throws HeroException {
6056        if (this.getProjectConfigTrace())
6057            trace.debug("copyNode: nodeName=" + nodeName + " node=" + node.getName()+ " inNode=");
6058        BnNodeLocalHome nHome;
6059        BnNodeLocal mNode;
6060        BnUserLocalHome uHome;
6061        BnNodePerformerAssignLocal ppLocal;
6062        BnNodePerformerAssignLocalHome performerAssignh;
6063        
6064        try {
6065            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
6066            uHome = hero.interfaces.BnUserUtil.getLocalHome();
6067            performerAssignh = BnNodePerformerAssignUtil.getLocalHome();
6068        } catch (javax.naming.NamingException JavaDoc be) {
6069            if (this.getProjectConfigTrace())
6070                trace.error(be.getMessage());
6071            throw new HeroException(be.getMessage());
6072        }
6073        try {
6074            if (nodeName.equals(""))
6075                throw new HeroException("Node name can not be empty...");
6076            
6077            // Creates node and set the role
6078
BnNodeLocal nd = nHome.create(nodeName, node.getType());
6079            BnNodeValue ndata = nd.getBnNodeValue();
6080            ndata.setCreationDate(new java.util.Date JavaDoc());
6081            nd.setBnNodeValue(ndata);
6082            Collection JavaDoc cNodes = mProject.getBnNodes();
6083            cNodes.add(nd);
6084            
6085            nd.setCreator(node.getCreator());
6086            nd.setExecutor(node.getExecutor()); // Only for JOnAS consistency
6087

6088            BnRoleLocalHome rHome = BnRoleUtil.getLocalHome();
6089            BnRoleLocal role = rHome.findByName(node.getRole(),mProject.getId());
6090            nd.setBnRole(role);
6091            
6092            if (!node.getAnticipable()) // Anticipable/traditional mode
6093
{
6094                nd.setAnticipable(false);
6095                nd.setTransition(NodeState.make(nd.getType(), false));
6096            }
6097            nd.setDescription(node.getDescription()); // Node description
6098

6099            //For Deadlines
6100
if (node.getDeadlines().size()!=0)
6101                nd.setDeadlines(node.getDeadlines());
6102            //For relative Deadlines
6103
if (node.getRelativeDeadlines().size()!=0)
6104                nd.setRelativeDeadlines(node.getRelativeDeadlines());
6105            
6106            if (node.getPerformer() != null) // Node Performer assignment
6107
{
6108                ppLocal = performerAssignh.create(node.getPerformer().getName(),
6109                        node.getPerformer().getType(),
6110                        node.getPerformer().getPropertyName());
6111                ppLocal.setBnNode(nd);
6112            }
6113        
6114            if (node.getType() == Constants.Nd.SUB_PROCESS_NODE)
6115            {
6116                try {
6117                    BnProjectLocal pl = pHome.findByName(nodeName);
6118                    pl.setParent(mProject.getName());
6119                } catch (javax.ejb.FinderException JavaDoc pe) {
6120                    if (this.getProjectConfigTrace())
6121                        trace.error("Project "+ nodeName+ " does not exist " + pe.getMessage());
6122                    throw new HeroException("Project "+ nodeName+ " does not exist");}
6123            }
6124            // Tell the world
6125
jms.sendNodeEvent(ADDNODE,this.getName(),nodeName,nd.getType(),nd.getState(),this.getCaller());
6126            
6127        } catch (InvalidValueException ie) {
6128            if (this.getProjectConfigTrace())
6129                trace.error(ie.getMessage());
6130            throw new HeroException(ie.getMessage());
6131        } catch (CreateException JavaDoc ce) {
6132            if (this.getProjectConfigTrace())
6133                trace.error(ce.getMessage());
6134            throw new HeroException(ce.getMessage());
6135        } catch (FinderException JavaDoc fe) {
6136            if (this.getProjectConfigTrace())
6137                trace.error(fe.getMessage());
6138            throw new HeroException(fe.getMessage());
6139        } catch (javax.naming.NamingException JavaDoc ne) {
6140            if (this.getProjectConfigTrace())
6141                trace.error(ne.getMessage());
6142            throw new HeroException(ne.getMessage());
6143        }
6144    }
6145    
6146    /**
6147     * Copy node edge. Internal method used in processes instantiation.
6148     *
6149     * @param name of the new node
6150     * @param inNode the BnNodeLocal in node object of the new node.
6151     * @param edge the BnEdgeLocal edge object from the project model.
6152     * @ejb:interface-method view-type="local"
6153     * @ejb:transaction type="Required"
6154     *
6155     **/

6156    public void copyEdge(String JavaDoc nodeName, BnNodeLocal inNode, BonitaEdgeValue edge ) throws HeroException {
6157        if (this.getProjectConfigTrace())
6158            trace.debug("copyEdge: nodeName=" + nodeName + " inNode=" + inNode.getName()+" edge=" + edge.getName());
6159        BnEdgeLocalHome eHome;
6160        BnEdgeLocal mEdge;
6161        BnNodeLocalHome nHome;
6162        BnNodeLocal mNode;
6163        
6164        try {
6165            nHome = hero.interfaces.BnNodeUtil.getLocalHome();
6166            eHome = hero.interfaces.BnEdgeUtil.getLocalHome();
6167        } catch (javax.naming.NamingException JavaDoc be) {
6168            if (this.getProjectConfigTrace())
6169                trace.error(be.getMessage());
6170            throw new HeroException(be.getMessage());
6171        }
6172        try {
6173            BnNodeLocal nd = nHome.findByName(nodeName, mProject.getId());
6174            
6175            try{
6176                mEdge = eHome.create();
6177                mEdge.setBnProject(mProject);
6178                mEdge.setInBnNode(inNode);
6179                mEdge.setOutBnNode(nd);
6180                mEdge.setCondition(edge.getCondition());
6181                
6182                int inState = Constants.Nd.READY;
6183                if (inNode.getState() == Constants.Nd.ANTICIPATING)
6184                    inState = Constants.Nd.ANTICIPABLE;
6185                
6186                int edgeState = hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][inState];
6187                this.setEdgeState(mEdge, edgeState);
6188                // mEdge.setState(edgeState);
6189
int newOperation = nd.getActivation().state(nd);
6190                int newState = nd.getTransition().computeState(nd, newOperation);
6191                if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION) {
6192                    throw new HeroException("AddEdge generated a bad Node transition");
6193                }
6194                this.setNodeState(nd, newState);
6195                
6196                jms.sendEdgeEvent(ADDEDGE,this.getName(),mEdge.getName(),inNode.getName(),nd.getName(),this.getCaller());
6197            }catch (hero.util.NodeStartedException nse) {} // Instances execution consistency
6198
} catch (InvalidValueException ie) {
6199            if (this.getProjectConfigTrace())
6200                trace.error(ie.getMessage());
6201            throw new HeroException(ie.getMessage());
6202        } catch (CreateException JavaDoc ce) {
6203            if (this.getProjectConfigTrace())
6204                trace.error(ce.getMessage());
6205            throw new HeroException(ce.getMessage());
6206        } catch (FinderException JavaDoc fe) {
6207            if (this.getProjectConfigTrace())
6208                trace.error(fe.getMessage());
6209            throw new HeroException(fe.getMessage());
6210        }
6211    }
6212    
6213    /**
6214     * Test if the project contains this user
6215     * @param userName The name of the user to associate to the project
6216     * @return boolean - true is the user belongs to the project
6217     *
6218     * @ejb:interface-method view-type="both"
6219     * @ejb:transaction type="Supports"
6220     * @throws HeroException
6221     *
6222     **/

6223    public boolean containsUser(String JavaDoc userName) throws HeroException {
6224        if (this.getProjectConfigTrace())
6225            trace.debug("containsUser : name=" + userName);
6226        BnUserLightValue[] uv = mProject.getBnProjectValue().getBnUsers();
6227        for (int i = 0; i < uv.length; i++) {
6228            if (uv[i].getName().equalsIgnoreCase(userName))
6229                return true;
6230        }
6231        return false;
6232    }
6233    
6234    private boolean containsRole(String JavaDoc roleName) {
6235        BnRoleValue[] rv = mProject.getBnProjectValue().getBnRoles();
6236        for (int i = 0; i < rv.length; i++) {
6237            if (rv[i].getName().equalsIgnoreCase(roleName))
6238                return true;
6239        }
6240        return false;
6241    }
6242    
6243    private Collection JavaDoc getNodeInEdges(BnNodeLocal nd ){
6244        Collection JavaDoc edgeValues = new ArrayList JavaDoc();
6245        Collection JavaDoc edges = nd.getInBnEdges();
6246        Iterator JavaDoc nodeEdges = edges.iterator();
6247        while (nodeEdges.hasNext())
6248            edgeValues.add(((BnEdgeLocal)nodeEdges.next()).getBnEdgeValue());
6249        return edgeValues;
6250        
6251    }
6252    
6253    private boolean getProjectConfigLog() throws HeroException{
6254        if (this.getName()!=null)
6255            return (bonitaConfig.getProcessLog(this.getName()));
6256        else
6257            return true;
6258    }
6259    
6260    private boolean getProjectConfigTrace() throws HeroException{
6261        if (this.getName()!=null)
6262            return (bonitaConfig.getProcessTrace(this.getName()));
6263        else
6264            return true;
6265    }
6266    
6267    private void addIterationInstance(String JavaDoc from, String JavaDoc to, String JavaDoc condition) throws HeroException {
6268        BnIterationLocalHome iteh;
6269        try {
6270            iteh = BnIterationUtil.getLocalHome();
6271        } catch (javax.naming.NamingException JavaDoc ne) {
6272            throw new HeroException(ne.getMessage());
6273        }
6274            
6275        BnIterationLightValue iv = new BnIterationLightValue();
6276        iv.setFromNode(from);
6277        iv.setToNode(to);
6278        iv.setCondition(condition);
6279        try {
6280            BnIterationLocal il = iteh.create(iv);
6281            mProject.getBnIterations().add(il);
6282            jms.sendIterationEvent(ADDITERATION,this.getName(), from, to);
6283        } catch (Exception JavaDoc ce) {
6284            throw new HeroException(ce.getMessage());
6285        }
6286    }
6287            
6288    /**
6289     * Local method
6290     * @ejb:interface-method view-type="local"
6291     * @ejb:transaction type="Supports"
6292     * @throws HeroException
6293     *
6294     **/

6295    public String JavaDoc getCaller() {
6296        return this.caller;
6297    }
6298    
6299    
6300    /**
6301     * Local method
6302     * @ejb:interface-method view-type="local"
6303     * @ejb:transaction type="Supports"
6304     * @throws HeroException
6305     *
6306     **/

6307    public void setCaller(String JavaDoc user) {
6308        this.caller=user;
6309    }
6310    
6311}
6312
Popular Tags