KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > session > EngineBean


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

24 import hero.interfaces.BnAgentEdgeLocal;
25 import hero.interfaces.BnAgentLocal;
26 import hero.interfaces.BnEdgeLocal;
27 import hero.interfaces.BnNodeLocal;
28 import hero.interfaces.BnNodePropertyLocal;
29 import hero.interfaces.BnProjectPropertyLocal;
30 import hero.interfaces.BnProjectLocal;
31 import hero.interfaces.BnProjectLocalHome;
32 import hero.interfaces.BnProjectUtil;
33 import hero.interfaces.BnNodePropertyValue;
34 import hero.interfaces.BnProjectPropertyValue;
35 import hero.interfaces.ProjectSessionLocal;
36 import hero.interfaces.ProjectSessionLocalHome;
37 import hero.interfaces.ProjectSessionUtil;
38 import hero.util.BonitaConfig;
39 import hero.util.BonitaProjectLocator;
40 import hero.util.BonitaServiceException;
41 import hero.util.BonitaServiceValue;
42 import hero.util.EngineException;
43 import hero.util.EventConstants;
44 import hero.util.HeroException;
45 import hero.util.HeroHookException;
46 import hero.util.BonitaDeadline;
47 import hero.interfaces.JMSServicesSessionUtil;
48 import hero.interfaces.JMSServicesSessionLocalHome;
49 import hero.interfaces.JMSServicesSessionLocal;
50 import hero.interfaces.UserServiceLocalHome;
51 import hero.interfaces.UserServiceLocal;
52
53 import hero.interfaces.BnNodePerformerAssignLocal;
54 import hero.interfaces.BnUserLocal;
55 import hero.interfaces.BnUserLocalHome;
56 import hero.util.MailNotification;
57 import hero.util.values.BonitaEdgeValue;
58 import hero.util.values.BonitaHookValue;
59 import hero.util.values.BonitaInterHookValue;
60 import hero.util.values.BonitaIterationValue;
61 import hero.util.values.BonitaNodeValue;
62 import hero.util.values.BonitaProjectValue;
63 import hero.util.values.BonitaPropertyValue;
64 import hero.interfaces.Constants;
65
66 import java.util.Collection JavaDoc;
67 import java.util.ArrayList JavaDoc;
68 import java.util.Iterator JavaDoc;
69 import java.util.Map JavaDoc;
70 import java.util.Date JavaDoc;
71
72 import javax.ejb.CreateException JavaDoc;
73 import javax.ejb.EJBException JavaDoc;
74 import javax.ejb.FinderException JavaDoc;
75 import javax.ejb.SessionBean JavaDoc;
76 import javax.ejb.SessionContext JavaDoc;
77
78 import org.apache.log4j.Logger;
79
80 import bsh.Interpreter;
81
82 /**
83  * Session Bean Template
84  *
85  * @ejb:bean name="Engine"
86  * display-name="Engine Bean"
87  * type="Stateless"
88  * transaction-type="Container"
89  * jndi-name="ejb/hero/Engine"
90  * local-jndi-name="ejb/hero/Engine_L"
91  *
92  * @ejb:ejb-ref ejb-name="BnProject"
93  * ref-name="myhero/BnProject"
94  * @ejb:transaction type="Required"
95  * @ejb.security-identity run-as="SuperAdmin"
96  * @jonas.bean
97  * ejb-name="Engine"
98  * jndi-name="ejb/hero/Engine"
99  **/

100
101 public class EngineBean implements SessionBean JavaDoc, Constants {
102
103     // -------------------------------------------------------------------------
104
// Static
105
// -------------------------------------------------------------------------
106
// Utility variable
107
private static final Logger log = Logger.getLogger("log");
108
109     // -------------------------------------------------------------------------
110
// Members
111
// -------------------------------------------------------------------------
112

113     private SessionContext JavaDoc mContext;
114
115     private BnProjectLocal mProject;
116     private ProjectSessionLocal mPSession;
117     private JMSServicesSessionLocal jms;
118     private boolean raiseError = false;
119     private ArrayList JavaDoc visited = new ArrayList JavaDoc();
120     private Collection JavaDoc iterationPath = new ArrayList JavaDoc();
121     private BonitaConfig bonitaConfig;
122     
123     private BonitaProjectValue model=null;
124
125     // -------------------------------------------------------------------------
126
// Methods
127
// -------------------------------------------------------------------------
128
/**
129      * Terminates the project
130      * @ejb:interface-method view-type="both"
131      *
132      **/

133     public void terminate(String JavaDoc projectName)
134     throws EngineException, HeroException {
135         if (this.getProjectConfigLog(projectName))
136             log.debug("Start terminate the project = " + projectName + " started by " + mContext.getCallerPrincipal().getName());
137         BnProjectLocalHome pHome;
138         BnProjectLocal pLocal;
139         ProjectSessionLocalHome psHome;
140         ProjectSessionLocal temp = mPSession; // For subprocess consistence
141
try {
142             psHome = ProjectSessionUtil.getLocalHome();
143             pHome = BnProjectUtil.getLocalHome();
144         } catch (javax.naming.NamingException JavaDoc ne) {
145             throw new HeroException(ne.getMessage());
146         }
147         try {
148             mPSession = psHome.create();
149             mPSession.setCaller(mContext.getCallerPrincipal().getName());
150             mPSession.initProject(projectName);
151             pLocal = pHome.findByName(projectName);
152             if (mProject.getType().equals(Constants.Pj.INSTANCE))
153             {
154                 if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
155                     throw new EngineException("Project is hidden. You cannot terminate an instance of a hidden model !!");
156             }
157             else if(mProject.getStatus().equals(Constants.Pj.HIDDEN))
158                 throw new EngineException("Project is hidden. You cannot terminate a hidden project !!");
159             if (nodesTerminated(pLocal.getBnNodes())) {
160                 pLocal.setState(hero.interfaces.Constants.Pj.TERMINATED);
161                 pLocal.setEndDate(new java.util.Date JavaDoc());
162             } else {
163                 throw new EngineException("Project cannot be terminated. Some nodes are still active");
164             }
165         } catch (FinderException JavaDoc fe) {
166             throw new HeroException("Project does not exist " + projectName);
167         } catch (CreateException JavaDoc he) {
168             throw new HeroException("ProjectSession Error" + projectName);
169         }
170         if (this.getProjectConfigLog(projectName))
171             log.debug(logProjectProperties("Properties after terminated: ")+ ", project = " + projectName+" started by " + mContext.getCallerPrincipal().getName());
172         mPSession = temp;
173         if (this.getProjectConfigLog(projectName))
174             log.debug("End terminate the project = " + projectName+" started by " + mContext.getCallerPrincipal().getName());
175     }
176     
177     /**
178      * Starts the activity nodeName
179      * @param nodeName the name of the activity
180      * @ejb:interface-method view-type="both"
181      *
182      **/

183     public void startActivity(String JavaDoc projectName, String JavaDoc nodeName)
184     throws EngineException, HeroException {
185         if (this.getProjectConfigLog(projectName))
186             log.debug("Start startActivity = " + nodeName +" of the project = " + projectName + " started by " + mContext.getCallerPrincipal().getName());
187         ProjectSessionLocalHome psHome;
188         BnProjectLocalHome pHome;
189         try {
190             psHome = ProjectSessionUtil.getLocalHome();
191             pHome = BnProjectUtil.getLocalHome();
192         } catch (javax.naming.NamingException JavaDoc ne) {
193             throw new HeroException(ne.getMessage());
194         }
195         try {
196             mProject = pHome.findByName(projectName);
197             if (mProject.getType().equals(Constants.Pj.INSTANCE))
198             {
199                 if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
200                     throw new EngineException("Project is hidden. You cannot start an activity of a hidden model !!");
201             }
202             else if(mProject.getStatus().equals(Constants.Pj.HIDDEN))
203                 throw new EngineException("Project is hidden. You cannot start an activity of a hidden project !!");
204             mPSession = psHome.create();
205             mPSession.setCaller(mContext.getCallerPrincipal().getName());
206             mPSession.initProject(projectName);
207         } catch (FinderException JavaDoc fe) {
208             throw new HeroException("Project does not exist " + projectName);
209         } catch (CreateException JavaDoc he) {
210             throw new HeroException("ProjectSession Error" + projectName);
211         }
212         try {
213             if (mProject.getType().equals(Constants.Pj.COOPERATIVE))
214                 mProject.setModel(BonitaProjectLocator.generateProjectValue(mProject.getName()));
215         } catch (BonitaServiceException e) {e.printStackTrace();
216           throw new HeroException(e.getMessage());
217         }
218         if (this.getProjectConfigLog(projectName))
219             log.debug(logActivityProperties(nodeName, "Properties before start")+ ", activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
220         BnNodeLocal nd = mProject.getBnNode(nodeName);
221         if ( (nd.getActivityPerformer() != null && ( nd.getActivityPerformer()).equals(mContext.getCallerPrincipal().getName())) || ! (nd.getActivityPerformer() != null))
222         {
223             execute(nodeName, hero.interfaces.Constants.Nd.START);
224             if (mProject.getState()== hero.interfaces.Constants.Pj.INITIAL)
225                 mProject.setState(hero.interfaces.Constants.Pj.STARTED);
226             if (raiseError == true)
227             {
228                 raiseError = false;
229                 throw new HeroHookException("An error is produced during the execution of a BeforeStart hook...");
230             }
231         }
232         else
233             throw new HeroException("Only activity performer can execute this activity.");
234         if (this.getProjectConfigLog(projectName))
235             log.debug("End of start activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
236         if (this.getProjectConfigLog(projectName))
237             log.debug(logActivityProperties(nodeName, "Properties after start")+ ", activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
238         
239     }
240     
241     /**
242      * Starts the activity nodeName
243      * @param nodeName the name of the activity
244      * @ejb:interface-method view-type="both"
245      *
246      **/

247     public void terminateActivity(String JavaDoc projectName, String JavaDoc nodeName)
248     throws EngineException, HeroException {
249         if (this.getProjectConfigLog(projectName))
250             log.debug("Start terminateActivity = " + nodeName +" of the project = " + projectName + " started by " + mContext.getCallerPrincipal().getName());
251         ProjectSessionLocalHome psHome;
252         BnProjectLocalHome pHome;
253         try {
254             psHome = ProjectSessionUtil.getLocalHome();
255             pHome = BnProjectUtil.getLocalHome();
256         } catch (javax.naming.NamingException JavaDoc ne) {
257             throw new HeroException(ne.getMessage());
258         }
259         try {
260             mProject = pHome.findByName(projectName);
261             if (mProject.getType().equals(Constants.Pj.INSTANCE))
262             {
263                 if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
264                     throw new EngineException("Project is hidden. You cannot terminate an activity of a hidden model !!");
265             }
266             else if(mProject.getStatus().equals(Constants.Pj.HIDDEN))
267                 throw new EngineException("Project is hidden. You cannot terminate an activity of a hidden project !!");
268             mPSession = psHome.create();
269             mPSession.setCaller(mContext.getCallerPrincipal().getName());
270             mPSession.initProject(projectName);
271             //this.getProjectModel();
272
} catch (FinderException JavaDoc fe) {
273             throw new HeroException("Project does not exist " + projectName);
274         } catch (CreateException JavaDoc he) {
275             throw new HeroException("ProjectSession Error" + projectName);
276         }
277         if (this.getProjectConfigLog(projectName))
278             log.debug(logActivityProperties(nodeName, "Properties before terminate")+ ", activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
279         execute(nodeName, hero.interfaces.Constants.Nd.TERMINATE);
280         if (raiseError == true)
281         {
282             raiseError = false;
283             throw new HeroHookException("An error is produced during the execution of a hook...");
284         }
285         if (this.getProjectConfigLog(projectName))
286             log.debug("End of terminate activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
287         if (this.getProjectConfigLog(projectName))
288             log.debug(logActivityProperties(nodeName, "Properties after terminate")+ ", activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
289         // Automatically terminates subProcess activity
290
if (!mProject.getParent().equals(mProject.getName()))
291         {
292             if (mPSession.isTerminated())
293                 this.terminateActivity(mProject.getParent(),mProject.getName());
294         }
295     }
296     
297     /**
298      * Starts the activity nodeName
299      * @param nodeName the name of the activity
300      * @ejb:interface-method view-type="both"
301      *
302      **/

303     public void cancelActivity(String JavaDoc projectName, String JavaDoc nodeName)
304     throws EngineException, HeroException {
305         if (this.getProjectConfigLog(projectName))
306             log.debug("Start cancelActivity = " + nodeName +" of the project = " + projectName + " started by " + mContext.getCallerPrincipal().getName());
307         ProjectSessionLocalHome psHome;
308         BnProjectLocalHome pHome;
309         try {
310             psHome = ProjectSessionUtil.getLocalHome();
311             pHome = BnProjectUtil.getLocalHome();
312         } catch (javax.naming.NamingException JavaDoc ne) {
313             throw new HeroException(ne.getMessage());
314         }
315         try {
316             mProject = pHome.findByName(projectName);
317             if (mProject.getType().equals(Constants.Pj.INSTANCE))
318             {
319                 if (mProject.getStatus().equals(Constants.Pj.HIDDEN))
320                     throw new EngineException("Project is hidden. You cannot cancel an activity of a hidden model !!");
321             }
322             else if(mProject.getStatus().equals(Constants.Pj.HIDDEN))
323                 throw new EngineException("Project is hidden. You cannot cancel an activity of a hidden project !!");
324             mPSession = psHome.create();
325             mPSession.setCaller(mContext.getCallerPrincipal().getName());
326             mPSession.initProject(projectName);
327             //this.getProjectModel();
328
} catch (FinderException JavaDoc fe) {
329             throw new HeroException("Project does not exist " + projectName);
330         } catch (CreateException JavaDoc he) {
331             throw new HeroException("ProjectSession Error" + projectName);
332         }
333         execute(nodeName, hero.interfaces.Constants.Nd.CANCEL);
334         if (this.getProjectConfigLog(projectName))
335             log.debug("End of cancel activity = " + nodeName + "of project = " +projectName+" started by " + mContext.getCallerPrincipal().getName());
336     }
337     
338     /**
339      * Suspend the activity nodeName
340      * @param nodeName the name of the activity
341      * @ejb:interface-method view-type="both"
342      *
343      **/

344     public void suspendActivity(String JavaDoc projectName, String JavaDoc nodeName)
345     throws EngineException, HeroException {
346         //log.debug("suspendActivity: nodeName=" + nodeName);
347
ProjectSessionLocalHome psHome;
348         BnProjectLocalHome pHome;
349         try {
350             psHome = ProjectSessionUtil.getLocalHome();
351             pHome = BnProjectUtil.getLocalHome();
352         } catch (javax.naming.NamingException JavaDoc ne) {
353             throw new HeroException(ne.getMessage());
354         }
355         try {
356             mProject = pHome.findByName(projectName);
357             mPSession = psHome.create();
358             mPSession.setCaller(mContext.getCallerPrincipal().getName());
359             mPSession.initProject(projectName);
360         } catch (FinderException JavaDoc fe) {
361             throw new HeroException("Project does not exist " + projectName);
362         } catch (CreateException JavaDoc he) {
363             throw new HeroException("ProjectSession Error" + projectName);
364         }
365         execute(nodeName, hero.interfaces.Constants.Nd.SUSPEND);
366     }
367     
368     /**
369      * Non_Automatic operation method that resume specify activity
370      */

371     
372     /**
373      * Resume the activity nodeName
374      * @param nodeName the name of the activity
375      * @ejb:interface-method view-type="both"
376      *
377      **/

378     public void resumeActivity(String JavaDoc projectName, String JavaDoc nodeName)
379     throws EngineException, HeroException {
380         //log.debug("resumeActivity: nodeName=" + nodeName);
381
ProjectSessionLocalHome psHome;
382         BnProjectLocalHome pHome;
383         try {
384             psHome = ProjectSessionUtil.getLocalHome();
385             pHome = BnProjectUtil.getLocalHome();
386         } catch (javax.naming.NamingException JavaDoc ne) {
387             throw new HeroException(ne.getMessage());
388         }
389         try {
390             mProject = pHome.findByName(projectName);
391             mPSession = psHome.create();
392             mPSession.setCaller(mContext.getCallerPrincipal().getName());
393             mPSession.initProject(projectName);
394         } catch (FinderException JavaDoc fe) {
395             throw new HeroException("Project does not exist " + projectName);
396         } catch (CreateException JavaDoc he) {
397             throw new HeroException("ProjectSession Error" + projectName);
398         }
399         execute(nodeName, hero.interfaces.Constants.Nd.RESUME);
400     }
401     
402     /**
403      * Active an External Agent
404      * @param agentName the name of the external agent
405      * @ejb:interface-method view-type="both"
406      *
407      **/

408     public void activeAgent(String JavaDoc projectName, String JavaDoc agentName)
409     throws EngineException, HeroException {
410         //log.debug("activeAgent: agentName=" + agentName);
411
BnAgentLocal ag;
412         ProjectSessionLocalHome psHome;
413         BnProjectLocalHome pHome;
414         try {
415             psHome = ProjectSessionUtil.getLocalHome();
416             pHome = BnProjectUtil.getLocalHome();
417         } catch (javax.naming.NamingException JavaDoc ne) {
418             throw new HeroException(ne.getMessage());
419         }
420         try {
421             mProject = pHome.findByName(projectName);
422             mPSession = psHome.create();
423             mPSession.setCaller(mContext.getCallerPrincipal().getName());
424             mPSession.initProject(projectName);
425             ag = mProject.getBnAgent(agentName);
426             mPSession.setAgentState(ag, hero.interfaces.Constants.Ag.ACTIVE);
427             Collection JavaDoc edges = ag.getOutEdges();
428             if (!edges.isEmpty())
429                 modifyAgentEdges(edges);
430         } catch (FinderException JavaDoc fe) {
431             throw new HeroException("Project does not exist " + projectName);
432         } catch (CreateException JavaDoc he) {
433             throw new HeroException("ProjectSession Error" + projectName);
434         }
435     }
436     
437     // Utility method
438
private void execute(String JavaDoc _node, int operation) throws HeroException, EngineException {
439         //log.debug("execute: node="+ _node+" operation="+ hero.interfaces.Constants.Nd.operationName[operation]);
440

441         BnNodeLocal nd;
442         nd = mProject.getBnNode(_node);
443         
444         int newState = nd.getTransition().computeState(nd, operation);
445         //if (this.getProjectConfigLog(mPSession.getName()))
446
//log.debug("Execute: New node State "+ _node+ " :"+ hero.interfaces.Constants.Nd.nodeStateName[newState]);
447

448             if (newState == hero.interfaces.Constants.Nd.BAD_TRANSITION)
449                 throw new EngineException("Bad state transition " + _node);
450             
451         if (newState != nd.getState()) {
452             if (newState == hero.interfaces.Constants.Nd.TERMINATED) {
453                 if (nd.getType()== hero.interfaces.Constants.Nd.SUB_PROCESS_NODE)
454                 {
455                     this.terminate(_node);
456                     mPSession.propagatesSubProcessProperties(_node);
457                 }
458                 jms.sendProjectEvent(EventConstants.TERMINATED,mProject.getName(),_node,mContext.getCallerPrincipal().getName());
459                 this.hookExecute(_node, hero.interfaces.Constants.Nd.BEFORETERMINATE);
460                 mPSession.propagateNodeProperties(_node);
461             } else if (newState == hero.interfaces.Constants.Nd.EXECUTING) {
462                 if (nd.getType()== hero.interfaces.Constants.Nd.SUB_PROCESS_NODE)
463                     mPSession.propagatesParentProperties(_node);
464                 jms.sendProjectEvent(EventConstants.START,mProject.getName(),_node,mContext.getCallerPrincipal().getName());
465                 this.hookExecute(_node, hero.interfaces.Constants.Nd.BEFORESTART);
466             } else if (newState == hero.interfaces.Constants.Nd.ANTICIPATING) {
467                 jms.sendProjectEvent(EventConstants.ANTICIPATING,mProject.getName(),_node,mContext.getCallerPrincipal().getName());
468                 this.hookExecute(_node,hero.interfaces.Constants.Nd.ANTICIPATE);
469             } else if (newState == hero.interfaces.Constants.Nd.DEAD) {
470                 mPSession.propagateNodeProperties(_node);
471                 jms.sendProjectEvent(EventConstants.CANCELED,mProject.getName(),_node,mContext.getCallerPrincipal().getName());
472                 this.hookExecute(_node, hero.interfaces.Constants.Nd.ONCANCEL);
473             }
474             
475             if (activityStarted(newState)) {
476                 this.hookExecute(_node,hero.interfaces.Constants.Nd.AFTERSTART);
477             }
478             
479             // Activities iteration
480
if ((newState == hero.interfaces.Constants.Nd.TERMINATED || newState == hero.interfaces.Constants.Nd.DEAD) && mPSession.getIterationExist(nd.getName()))
481             {
482                 mPSession.setNodeState(nd,hero.interfaces.Constants.Nd.INITIAL);
483                 String JavaDoc preNode = mPSession.getToIteration(nd.getName());
484                 String JavaDoc condition = mPSession.getIterationCondition(nd.getName());
485                 
486                 if (preNode != null && (evaluateCondition(condition, nd))==Constants.CONDITION_TRUE)
487                 {
488                     this.setIterationPathInitial(nd.getName(),preNode);
489                     BnNodeLocal preNodeLocal = mProject.getBnNode(preNode);
490                     // First iteration activity is set to ready
491
mPSession.setNodeState(preNodeLocal,hero.interfaces.Constants.Nd.READY);
492                     
493                     // If activity type equals Automatic or SubProcess
494
if (preNodeLocal.getType() == Constants.Nd.AND_JOIN_AUTOMATIC_NODE || preNodeLocal.getType() == Constants.Nd.OR_JOIN_AUTOMATIC_NODE || preNodeLocal.getType() == Constants.Nd.SUB_PROCESS_NODE)
495                         this.execute(preNode,Constants.Nd.START);
496                     this.hookExecute(preNode, hero.interfaces.Constants.Nd.ONREADY);//
497
if ( preNodeLocal.getBnNodePerformerAssign() != null)
498                         this.performAssign(preNodeLocal);
499                 }
500                 else if (preNode != null)
501                 {
502                     if (newState == hero.interfaces.Constants.Nd.TERMINATED)
503                         mPSession.setNodeState(nd,hero.interfaces.Constants.Nd.TERMINATED);
504                     else
505                         mPSession.setNodeState(nd,hero.interfaces.Constants.Nd.DEAD);
506                     activeStandByEdges(nd.getName(),preNode);
507                 }
508             }
509             else
510             {
511                 mPSession.setNodeState(nd, newState);
512                 mPSession.setNodeExecutor(_node);
513             }
514                 if (newState == hero.interfaces.Constants.Nd.READY && (nd.getDeadlines().size() != 0 || nd.getRelativeDeadlines().size() != 0)) {
515                     BonitaDeadline.getInstance().startDeadlines(_node,nd.getBnProject().getId());
516                 } else {
517                     // For deadlines
518
if ((newState == hero.interfaces.Constants.Nd.TERMINATED || newState == hero.interfaces.Constants.Nd.DEAD)
519                             && nd.getDeadlines().size() != 0) {
520                         Collection JavaDoc co = nd.getDeadlines();
521                         Iterator JavaDoc it = co.iterator();
522                         while (it.hasNext()) {
523                             long date = ((java.sql.Date JavaDoc) it.next()).getTime();
524                             if (date > new Date JavaDoc().getTime())
525                                 ;
526                             BonitaDeadline.getInstance().removeNodeNotification(mProject.getName(),_node, date);
527                         }
528                     }
529                     // For relative deadlines
530
if ((newState == hero.interfaces.Constants.Nd.TERMINATED || newState == hero.interfaces.Constants.Nd.DEAD)
531                             && nd.getRelativeDeadlines().size() != 0) {
532                         Collection JavaDoc co = nd.getRelativeDeadlines();
533                         Iterator JavaDoc it = co.iterator();
534                         while (it.hasNext()) {
535                             long date = ((java.sql.Date JavaDoc) it.next()).getTime();
536                             if (new Date JavaDoc().getTime() + date > new Date JavaDoc().getTime());
537                             BonitaDeadline.getInstance().removeNodeNotification(mProject.getName(), _node, date);
538                         }
539                     }
540                 }
541                 try {
542                     if (newState == hero.interfaces.Constants.Nd.READY && nd.getBnNodePerformerAssign() != null)
543                         this.performAssign(nd);
544                     else if (newState==hero.interfaces.Constants.Nd.READY)
545                             this.hookExecute(_node, hero.interfaces.Constants.Nd.ONREADY);
546                 } catch (Exception JavaDoc e){
547                     e.printStackTrace();
548                     throw new HeroException("Error when call of performAssign()!!!");
549                 }
550                 Collection JavaDoc edges = nd.getOutBnEdges();
551                 if (edges.isEmpty() && isInstance(mProject.getName()) && newState != Constants.Nd.INITIAL){
552                     if (!instanceWasModified(nd))
553                     {
554                         this.generateOutNodes(nd);
555                         if (newState == Constants.Nd.DEAD)
556                             mPSession.propagateNodeProperties(_node);
557                         edges = nd.getOutBnEdges();
558                     }
559                 }
560                 modifyNodeEdges(newState, edges);
561             }
562         //}
563

564         if (newState == hero.interfaces.Constants.Nd.TERMINATED)
565             this.hookExecute(_node, hero.interfaces.Constants.Nd.AFTERTERMINATE);
566         
567         if (newState == hero.interfaces.Constants.Nd.EXECUTING && nd.getType() == hero.interfaces.Constants.Nd.AND_JOIN_AUTOMATIC_NODE)
568             this.execute(_node,hero.interfaces.Constants.Nd.TERMINATE);
569     }
570     
571     private void performAssign(BnNodeLocal nd) throws HeroException {
572         try {
573             BnNodePerformerAssignLocal performerAssign = null;
574             BnUserLocal mUser;
575             UserServiceLocalHome ushome;
576             UserServiceLocal ul;
577             String JavaDoc creator = mContext.getCallerPrincipal().getName();
578             performerAssign = nd.getBnNodePerformerAssign();
579             hero.performerAssign.PerformerAssign h = hero.performerAssign.PerformerAssign.make(performerAssign.getName(), performerAssign.getType());
580             h.execute(this, performerAssign.getType(), nd, creator);
581             
582             // send notification to the activityPerformer of the node
583
String JavaDoc activityPerformerName = nd.getActivityPerformer();
584             
585             try {
586                 BnUserLocalHome userhome=hero.interfaces.BnUserUtil.getLocalHome();
587                 ushome=hero.interfaces.UserServiceUtil.getLocalHome();
588                 mUser=userhome.findByName(activityPerformerName);
589                 
590             } catch (javax.naming.NamingException JavaDoc ne) {
591                 throw new HeroException(ne.getMessage());
592             } catch (javax.ejb.FinderException JavaDoc fe) {
593                 throw new HeroException(activityPerformerName+" does not exists");
594             }
595             try{
596                 ul= ushome.create();
597                 Map JavaDoc infos = ul.getUserInfos(mUser.getName());
598                 if (infos.get("email")!=null) {
599                     MailNotification mailNotif = new MailNotification();
600                     mailNotif.initMailService();
601                     mailNotif.sendMail((String JavaDoc)infos.get("email"),"Bonita Notification: activity assigned to you","Hello,\n\n For the Project: " + mProject.getName()+ ",\nthe activity for the node : " + nd.getName() + "\nis ready to be started by you.\n\nPlease connect to the Bonita manager application." );
602                 }
603             } catch (Exception JavaDoc e){
604                 throw new HeroException("Activity assign Notification fails" + e.getMessage());
605             }
606             
607         } catch (HeroException he) {
608             he.printStackTrace();
609             throw new HeroException("Error in performerAssignment" + he.getMessage());
610         }
611     }
612     
613     /**
614      * Method that consult new node state value and modify out edges (state
615      * propagation)
616      */

617     
618     private void modifyNodeEdges(int nodeState, Collection JavaDoc edges)
619     throws HeroException, EngineException {
620         int newEdgeState;
621         Iterator JavaDoc i = edges.iterator();
622         while (i.hasNext()) {
623             BnEdgeLocal edge = (BnEdgeLocal) i.next();
624             boolean inNode = nodeExistInIteration(edge.getInBnNode().getName());
625             boolean outNode = nodeExistInIteration(edge.getOutBnNode().getName());
626             if ((inNode && outNode) || (!inNode && !outNode) ||(!inNode && outNode)) // ! StandBy edges (for nodes iteration)
627
{
628                 if (nodeState != hero.interfaces.Constants.Nd.TERMINATED && nodeState != hero.interfaces.Constants.Nd.DEAD) {
629                     newEdgeState =hero.interfaces.Constants.edgeTransition[Constants.CONDITION_TRUE][nodeState];
630                     mPSession.setEdgeState(edge, newEdgeState);
631                     edgeChanged(edge);
632                 } else {
633                     newEdgeState =hero.interfaces.Constants.edgeTransition[evaluateCondition(edge.getCondition(),edge.getInBnNode())][nodeState];
634                     if (edge.getState() != newEdgeState) {
635                         mPSession.setEdgeState(edge, newEdgeState);
636                         edgeChanged(edge);
637                     }
638                 }
639             }
640         }
641     }
642         
643     /**
644      * Method that find the standBy edges of the iteration and active them.
645      */

646     
647     private void activeStandByEdges(String JavaDoc lastNode, String JavaDoc firstNode) throws HeroException {
648         ArrayList JavaDoc nodes = new ArrayList JavaDoc();
649         boolean stop = false; int index=0;
650         
651         Collection JavaDoc activeEdges = mPSession.getNodeOutEdges(lastNode);
652         Iterator JavaDoc j = activeEdges.iterator();
653         while (j.hasNext())
654         {
655             String JavaDoc aEdge = (String JavaDoc)j.next();
656             if (!nodes.contains(mPSession.getEdgeOutNode(aEdge)))
657             {
658                 BnEdgeLocal ed = mProject.getBnEdge(aEdge);
659                 int newEdgeState =hero.interfaces.Constants.edgeTransition[evaluateCondition(ed.getCondition(),ed.getInBnNode())][mPSession.getNodeState(lastNode)];
660                 
661                 mPSession.setEdgeState(ed, newEdgeState);
662                 edgeChanged(ed);
663             }
664         }
665         while (!stop)
666         {
667             Collection JavaDoc edges = mPSession.getNodeInEdges(lastNode);
668             Iterator JavaDoc i = edges.iterator();
669             while (i.hasNext())
670             {
671                 String JavaDoc edgeName = (String JavaDoc)i.next();
672                 if (!nodes.contains(mPSession.getEdgeInNode(edgeName)))
673                     nodes.add(mPSession.getEdgeInNode(edgeName));
674             }
675             if (nodes.size()==0)
676                 nodes.add(firstNode);
677             String JavaDoc actNode = (String JavaDoc)nodes.get(index);
678             activeEdges = mPSession.getNodeOutEdges(actNode);
679             j = activeEdges.iterator();
680             while (j.hasNext())
681             {
682                 String JavaDoc aEdge = (String JavaDoc)j.next();
683                 if (!nodes.contains(mPSession.getEdgeOutNode(aEdge)))
684                 {
685                     BnEdgeLocal ed = mProject.getBnEdge(aEdge);
686                     int newEdgeState =hero.interfaces.Constants.edgeTransition[evaluateCondition(ed.getCondition(), ed.getInBnNode())][mPSession.getNodeState(actNode)];
687                     
688                     mPSession.setEdgeState(ed, newEdgeState);
689                     edgeChanged(ed);
690                 }
691             }
692             lastNode = (String JavaDoc)nodes.get(index);
693             if (lastNode.equals(firstNode))
694             {
695                 stop=true;
696                 nodes.remove(lastNode);
697             }
698             index++;
699         }
700     }
701     
702     /**
703      * Method that find the existing nodes between lastNode and firstNode)
704      */

705     private boolean nodeExistInIteration(String JavaDoc node) throws HeroException {
706         
707         Collection JavaDoc ite = mProject.getModel().getIterations();
708         Iterator JavaDoc iter = ite.iterator();
709         
710         while (iter.hasNext())
711         {
712             BonitaIterationValue iv = (BonitaIterationValue)iter.next();
713             if (isInstance(node))
714                 node = getModel(node);
715             if (isNodeInIterationPath(iv.getFromNode(), iv.getToNode(),node) || node.equals(iv.getFromNode()))
716             {
717                 mPSession.initProject(mProject.getName());
718                 return true;
719             }
720         }
721         mPSession.initProject(mProject.getName());
722         return false;
723     }
724     
725     private boolean isNodeInIterationPath(String JavaDoc in, String JavaDoc out, String JavaDoc node) throws HeroException {
726         if (isInstance(in))
727             in = getModel(in);
728         if (isInstance(out))
729             out = getModel(out);
730         if (isInstance(node))
731             node = getModel(node);
732         
733         BonitaNodeValue nd = BonitaServiceValue.getNodeFromCache(mProject.getModel(),in);
734         Collection JavaDoc edges = nd.getInEdges();
735         Iterator JavaDoc eds = edges.iterator();
736         while (eds.hasNext())
737         {
738             BonitaEdgeValue ed = (BonitaEdgeValue)eds.next();
739             String JavaDoc edgeNode = ed.getInNode();
740             if (edgeNode.equals(node))
741             {
742                 iterationPath.add(node);
743                 return true;
744             }
745             if (edgeNode.equals(out))
746                 return false;
747             else
748                 if (isNodeInIterationPath(edgeNode,out,node))
749                     return true;
750         }
751         return false;
752     }
753     
754     private void setIterationPathInitial(String JavaDoc in, String JavaDoc out) throws HeroException
755     {
756         if (!in.equals(out)) {
757             ArrayList JavaDoc nodes = new ArrayList JavaDoc();
758             BnNodeLocal actualNode = mProject.getBnNode(in);
759             if (actualNode.getType() == Nd.SUB_PROCESS_NODE)
760                 initSubProcess(actualNode.getName());
761             nodes.add(actualNode);
762             while (!(actualNode.getName()).equals(out) || !nodes.isEmpty()) {
763                 nodes.remove(actualNode);
764                 Collection JavaDoc edges = actualNode.getInBnEdges();
765                 Iterator JavaDoc eds = edges.iterator();
766                 while (eds.hasNext()) {
767                     BnEdgeLocal ed = (BnEdgeLocal) eds.next();
768                     BnNodeLocal node = ed.getInBnNode();
769                     if (isNodeInIterationPath(in, out, node.getName())) {
770                         mPSession.setNodeState(node, Constants.Nd.INITIAL);
771                         if (node.getType() == Nd.SUB_PROCESS_NODE)
772                             initSubProcess(node.getName());
773                         mPSession.setEdgeState(ed, Constants.Ed.INITIAL);
774                         nodes.add(node);
775                     }
776                 }
777                 if (!nodes.isEmpty())
778                     actualNode = (BnNodeLocal) nodes.get(0);
779
780             }
781         }
782     }
783     
784     /**
785      * Method that propagate the AgentEdges state
786      */

787     private void modifyAgentEdges(Collection JavaDoc edges)
788     throws HeroException, EngineException {
789         Iterator JavaDoc i = edges.iterator();
790         while (i.hasNext()) {
791             BnAgentEdgeLocal edge = (BnAgentEdgeLocal) i.next();
792             mPSession.setAgentEdgeState(edge,hero.interfaces.Constants.Ed.ANTICIPATING);
793             BnNodeLocal nd = edge.getOutBnNode();
794             int operation = nd.getActivation().state(nd);
795             execute(nd.getName(), hero.interfaces.Constants.Nd.ANTACTIVE);
796         }
797     }
798     
799     private void edgeChanged(BnEdgeLocal edge)
800     throws HeroException, EngineException {
801         BnNodeLocal nd = edge.getOutBnNode();
802         if (nd.getState() != hero.interfaces.Constants.Nd.DEAD) {
803             int operation = nd.getActivation().state(nd);
804             execute(nd.getName(), operation);
805         }
806     }
807     
808     private Collection JavaDoc getNodeInEdges(BnNodeLocal nd ){
809         Collection JavaDoc edgeValues = new ArrayList JavaDoc();
810         Collection JavaDoc edges = nd.getInBnEdges();
811         Iterator JavaDoc nodeEdges = edges.iterator();
812         while (nodeEdges.hasNext())
813             edgeValues.add(((BnEdgeLocal)nodeEdges.next()).getBnEdgeValue());
814         return edgeValues;
815         
816     }
817     
818     private boolean activityStarted(int state) throws HeroException {
819         return (
820                 state == hero.interfaces.Constants.Nd.ANTICIPATING
821                 || state == hero.interfaces.Constants.Nd.EXECUTING);
822     }
823     
824     private void hookExecute(String JavaDoc nodeName, String JavaDoc eventName)
825     throws HeroException, HeroHookException {
826         Collection JavaDoc hooks;
827         Collection JavaDoc interHooks;
828         BnNodeLocal node;
829         BonitaProjectValue currentProject;
830         try {
831             node = mProject.getBnNode(nodeName);
832             model = mProject.getModel();
833             
834             if (nodeName.matches(".*_instance.*"))
835                 nodeName=nodeName.substring(0,nodeName.indexOf("_instance"));
836
837             BonitaNodeValue nodeLocal;
838             if (mProject.getType().equals(Constants.Pj.COOPERATIVE))
839                 nodeLocal = BonitaServiceValue.getNode(mProject,nodeName);
840             else
841                 nodeLocal = BonitaServiceValue.getNodeFromCache(model,nodeName);
842                     
843             hooks = nodeLocal.getHooks();
844             for (Iterator JavaDoc i = hooks.iterator(); i.hasNext();) {
845                 BonitaHookValue hk = (BonitaHookValue) i.next();
846                 if (hk.getEvent().equalsIgnoreCase(eventName)) {
847                     hero.hook.Hook h = hero.hook.Hook.make(hk.getName(), eventName, hk.getType());
848                     if (this.getProjectConfigLog(mPSession.getName()))
849                         log.debug("hookExecute, eventName = " + eventName+" nodeName = "+nodeName+" projectName = "+mProject.getName());
850                     h.execute(this, eventName, node);
851                 }
852             }
853             
854             interHooks = nodeLocal.getInterHooks();
855             for (Iterator JavaDoc i = interHooks.iterator(); i.hasNext();) {
856                 BonitaInterHookValue hk = (BonitaInterHookValue)i.next();
857                 if (hk.getEvent().equalsIgnoreCase(eventName)) {
858                     hero.hook.Hook h = hero.hook.Hook.make(hk.getName(), eventName, hk.getType(), hk.getScript());
859                     if (this.getProjectConfigLog(mPSession.getName()))
860                         log.debug("hookExecute, eventName = " + eventName+" nodeName = "+nodeName+" projectName = "+mProject.getName());
861                     h.execute(this, eventName, node);
862                 }
863             }
864             
865             if (mProject.getType().equals(Constants.Pj.COOPERATIVE))
866                 hooks = BonitaServiceValue.getProjectHooks(mProject);
867             else
868                 hooks = model.getHooks();
869             for (Iterator JavaDoc i = hooks.iterator(); i.hasNext();) {
870                 BonitaHookValue hk = (BonitaHookValue) i.next();
871                 if (hk.getEvent().equalsIgnoreCase(eventName)) {
872                     hero.hook.Hook h = hero.hook.Hook.make(hk.getName(), eventName, hk.getType());
873                     if (this.getProjectConfigLog(mPSession.getName()))
874                         log.debug("hookExecute, eventName = " + eventName+" nodeName = "+nodeName+" projectName = "+mProject.getName());
875                     h.execute(this, eventName, node);
876                 }
877             }
878             
879             if (mProject.getType().equals(Constants.Pj.COOPERATIVE))
880                 hooks = BonitaServiceValue.getProjectInterHooks(mProject);
881             else
882                 interHooks = model.getInterHooks();
883             for (Iterator JavaDoc i = interHooks.iterator(); i.hasNext();) {
884                 BonitaInterHookValue hk = (BonitaInterHookValue) i.next();
885                 if (hk.getEvent().equalsIgnoreCase(eventName)) {
886                     hero.hook.Hook h = hero.hook.Hook.make(hk.getName(), eventName, hk.getType(),hk.getScript());
887                     if (this.getProjectConfigLog(mPSession.getName()))
888                         log.debug("hookExecute, eventName = " + eventName+" nodeName = "+nodeName+" projectName = "+mProject.getName());
889                     h.execute(this, eventName, node);
890                 }
891             }
892         }catch(HeroHookException hh){
893             if (this.getProjectConfigLog(mPSession.getName()))
894                 log.error("hookExecute ERROR, eventName = " + eventName+" nodeName = "+nodeName+" projectName = "+mProject.getName()+" Error message: "+hh.getMessage());
895             if (eventName.equals(hero.interfaces.Constants.Nd.AFTERSTART) || eventName.equals(hero.interfaces.Constants.Nd.BEFORETERMINATE)
896                     || eventName.equals(hero.interfaces.Constants.Nd.ANTICIPATE) || eventName.equals(hero.interfaces.Constants.Nd.ONCANCEL)) {
897                 mContext.setRollbackOnly();
898                     throw new HeroHookException("Cannot execute hook "+hh.getMessage());
899             }
900             else
901                 raiseError = true;
902         };
903     }
904     
905     private boolean nodesTerminated(Collection JavaDoc nodes) {
906         Iterator JavaDoc i = nodes.iterator();
907         while (i.hasNext()) {
908             BnNodeLocal node = (BnNodeLocal) i.next();
909             int state = node.getState();
910             if (state != hero.interfaces.Constants.Nd.TERMINATED
911                     && state != hero.interfaces.Constants.Nd.EXPIRED
912                     && state != hero.interfaces.Constants.Nd.DEAD)
913                 return false;
914         }
915         return true;
916     }
917     
918     public int evaluateCondition(String JavaDoc condition, BnNodeLocal node) {
919         try {
920             if (condition != null) {
921                 condition = "import hero.interfaces.BnNodeLocal;\n"
922                     + "boolean evalCondition (Object node) {\n\n\n"
923                     + "return("
924                     + condition
925                     + ");"
926                     + "}";
927                 Interpreter i = new Interpreter();
928                 
929                 // BnNode properties mapping
930

931                 Collection JavaDoc prop = node.getBnProperties();
932                 for (Iterator JavaDoc props = prop.iterator(); props.hasNext();) {
933                     BnNodePropertyLocal pl = (BnNodePropertyLocal) props.next();
934                     i.set(pl.getTheKey(), pl.getTheValue());
935                 }
936                 
937                 //Project properties mapping
938
BnProjectLocal project = node.getBnProject();
939                 Collection JavaDoc projectProp = project.getBnProperties();
940                 for (Iterator JavaDoc props=projectProp.iterator();props.hasNext();) {
941                     BnProjectPropertyLocal pP=(BnProjectPropertyLocal)props.next();
942                     i.set(pP.getTheKey(),pP.getTheValue());
943                 }
944                 i.set("node",node);
945                 i.eval(condition);
946                 i.eval("result=evalCondition(node)");
947                 if (((Boolean JavaDoc) i.get("result")).booleanValue() == true)
948                     return (Constants.CONDITION_TRUE);
949                 else
950                     return (Constants.CONDITION_FALSE);
951             } else
952                 return (Constants.CONDITION_TRUE);
953         } catch (Exception JavaDoc t) {
954             t.printStackTrace();
955             return (Constants.CONDITION_FALSE);
956         }
957     }
958     
959     private String JavaDoc logActivityProperties(String JavaDoc nodeName, String JavaDoc prelog)
960     throws HeroException {
961         Collection JavaDoc np = mPSession.getNodeProperties(nodeName);
962         Iterator JavaDoc i = np.iterator();
963         String JavaDoc thelog = prelog;
964         if (np.size() != 0) {
965             while (i.hasNext()) {
966                 thelog = thelog + " key= '";
967                 BnNodePropertyValue property = (BnNodePropertyValue) i.next();
968                 thelog = thelog + property.getTheKey();
969                 thelog = thelog + "' value = '" + property.getTheValue() + "'";
970             }
971         } else
972             thelog = prelog + " No property";
973         return thelog;
974     }
975     private String JavaDoc logProjectProperties(String JavaDoc prelog) throws HeroException {
976         Collection JavaDoc np = mPSession.getProperties();
977         Iterator JavaDoc i = np.iterator();
978         String JavaDoc thelog = prelog;
979         if (np.size() != 0) {
980             while (i.hasNext()) {
981                 thelog = thelog + " key= '";
982                 BnProjectPropertyValue property =
983                     (BnProjectPropertyValue) i.next();
984                 thelog = thelog + property.getTheKey();
985                 thelog = thelog + "' value = '" + property.getTheValue() + "'";
986             }
987         } else
988             thelog = prelog + " No property";
989         return thelog;
990     }
991     
992     // Init activities of the subProcess project (used in subProcess activities iteration)
993
private void initSubProcess(String JavaDoc subProcess) throws HeroException {
994         ProjectSessionLocalHome psh;
995         ProjectSessionLocal psj;
996         BnProjectLocalHome ph;
997         BnProjectLocal pj;
998         try{
999             psh = ProjectSessionUtil.getLocalHome();
1000            psj = psh.create();
1001            psj.initProject(subProcess);
1002            
1003            ph = BnProjectUtil.getLocalHome();
1004            pj = ph.findByName(subProcess);
1005            Collection JavaDoc nodes = pj.getBnNodes();
1006            Iterator JavaDoc nds = nodes.iterator();
1007            while (nds.hasNext())
1008            {
1009                BnNodeLocal node = (BnNodeLocal)nds.next();
1010                if (node.getType() == Nd.SUB_PROCESS_NODE)
1011                    this.initSubProcess(node.getName());
1012                psj.setNodeState(node,hero.interfaces.Constants.Nd.INITIAL);
1013            }
1014        } catch (Exception JavaDoc e) {
1015            throw new HeroException(e.getMessage());
1016        }
1017    }
1018    
1019    private void generateOutNodes(BnNodeLocal nd) throws HeroException {
1020        BonitaNodeValue parentNode;
1021        model = mProject.getModel();
1022        if (nd.getName().matches(".*_instance.*")) // node is a subProcess
1023
parentNode = BonitaServiceValue.getNodeFromCache(model,this.getModel(nd.getName()));
1024        else
1025            parentNode = BonitaServiceValue.getNodeFromCache(model,nd.getName());
1026        Collection JavaDoc outEdges = parentNode.getOutEdges();
1027        Iterator JavaDoc edges = outEdges.iterator();
1028        while (edges.hasNext()) {
1029            BonitaEdgeValue edge = (BonitaEdgeValue) edges.next();
1030            BonitaNodeValue node = BonitaServiceValue.getNodeFromCache(model,edge.getOutNode());
1031            String JavaDoc nodeName = node.getName();
1032            
1033            if (node.getType() == Nd.SUB_PROCESS_NODE) // Node is a subprocess
1034
{
1035                try {
1036                    BnProjectLocal temp = mProject;
1037                    // Save BnProjectLocal reference before instantiation
1038
BnProjectLocalHome opHome = BnProjectUtil.getLocalHome();
1039                    nodeName = mPSession.instantiateProject(nodeName);
1040                    // Create instance of the subProcess
1041
mProject = opHome.findByName(nodeName);
1042                    mProject.setParent(nd.getBnProject().getName());
1043                    // Set subProcess parent
1044
mProject = temp; // Go back to the instance saved.
1045
mPSession.initProject(mProject.getName());
1046                } catch (Exception JavaDoc e) {
1047                    throw new HeroException(e.getMessage());
1048                }
1049            }
1050            if (!this.nodeExist(nodeName))
1051                mPSession.copyNode(nodeName,node);
1052            
1053            // Copy Node Properties (default value)
1054
Collection JavaDoc nodeProp = node.getProperties();
1055            Iterator JavaDoc nodeProps = nodeProp.iterator();
1056            while (nodeProps.hasNext())
1057            {
1058                BonitaPropertyValue ndProp = (BonitaPropertyValue)nodeProps.next();
1059                mPSession.setNodePropertyPossibleValues(nodeName,ndProp.getKey(),ndProp.getPossibleValues());
1060                mPSession.setNodeProperty(nodeName,ndProp.getKey(),ndProp.getValue(),ndProp.getPropagate());
1061            }
1062            mPSession.copyEdge(nodeName,nd, edge);
1063            
1064            // If in activity was automatic propagate properties to new ones
1065
if (nd.getType() == Constants.Nd.AND_JOIN_AUTOMATIC_NODE || nd.getType() == Constants.Nd.OR_JOIN_AUTOMATIC_NODE)
1066                mPSession.propagateNodeProperties(nd.getName());
1067                                        
1068            // Project Iterations
1069
Collection JavaDoc iterations = model.getIterations();
1070            Iterator JavaDoc iter = iterations.iterator();
1071            while (iter.hasNext())
1072            {
1073                BonitaIterationValue iteration = (BonitaIterationValue) iter.next();
1074                String JavaDoc from = iteration.getFromNode();
1075                if (nodeName.matches(from+"_instance.*") || nodeName.equals(from))
1076                {
1077                    try{
1078                        mPSession.addIteration(nodeName, this.nodeConvertion(iteration.getToNode()),iteration.getCondition());
1079                    }catch(Exception JavaDoc it){}// maybe the iteration was already created
1080
}
1081            }
1082        }
1083    }
1084    
1085    // Get the name of the project model of this instance
1086
private String JavaDoc getModel(String JavaDoc instanceName) {
1087        int i = instanceName.indexOf("_instance");
1088        return (instanceName.substring(0, i));
1089    }
1090    
1091    private boolean isInstance(String JavaDoc name) {
1092        return (name.matches(".*_instance.*"));
1093    }
1094    
1095    private String JavaDoc nodeConvertion(String JavaDoc name) {
1096        Collection JavaDoc nodes = mProject.getBnNodes();
1097        Iterator JavaDoc nds = nodes.iterator();
1098        while (nds.hasNext())
1099        {
1100            String JavaDoc node = ((BnNodeLocal)nds.next()).getName();
1101            if (node.matches(name+"_.*"))
1102                return node;
1103        }
1104        return name;
1105    }
1106    
1107    private boolean nodeExist(String JavaDoc node) throws HeroException{
1108        return(mPSession.getNodesNames().contains(node));
1109    }
1110    
1111    private boolean getProjectConfigLog(String JavaDoc projectName) throws HeroException{
1112        return (bonitaConfig.getProcessLog(projectName));
1113    }
1114
1115    private boolean instanceWasModified(BnNodeLocal node) throws HeroException{
1116        model = mProject.getModel();
1117        String JavaDoc name = node.getName();
1118        if (this.isInstance(name))
1119            name = this.getModel(node.getName());
1120        if (BonitaServiceValue.getNodeFromCache(model,name)==null)
1121            return true;
1122        return false;
1123    }
1124    
1125    /**
1126     *
1127     * @throws CreateException
1128     *
1129     * @ejb:create-method view-type="both"
1130     **/

1131    public void ejbCreate() throws CreateException JavaDoc {
1132        try{
1133            JMSServicesSessionLocalHome home = JMSServicesSessionUtil.getLocalHome();
1134            jms=home.create();
1135        }catch(Exception JavaDoc e){throw new CreateException JavaDoc(e.getMessage());}
1136    }
1137    
1138    public void setSessionContext(final javax.ejb.SessionContext JavaDoc context) {
1139        mContext = context;
1140        try{
1141            this.bonitaConfig = new BonitaConfig();
1142        }catch(Exception JavaDoc e){throw new EJBException JavaDoc(e.getMessage());}
1143    }
1144    
1145    public void ejbRemove() {
1146    }
1147    
1148    public void ejbActivate() {
1149    }
1150    
1151    public void ejbPassivate() {
1152    }
1153    
1154}
1155
Popular Tags