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());
<