KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > grapheditor > WFPersistence


1 package hero.client.grapheditor;
2
3 /*
4 *
5 * WFPersistence.java -
6 * Copyright (C) 2003 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
25 import hero.interfaces.Constants;
26
27 import java.util.Iterator JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import javax.swing.JOptionPane JavaDoc;
32 import hero.util.BonitaClient;
33 import hero.util.ProjectNodes;
34 import hero.net.ProjectSession.StrutsNodeValue;
35 import javax.swing.ImageIcon JavaDoc;
36 import java.text.SimpleDateFormat JavaDoc;
37
38 public class WFPersistence {
39
40     // private String userAcces = "all";
41
private String JavaDoc projectName;
42     public boolean permission = false;
43     private String JavaDoc endpoint = null;
44     private String JavaDoc url = null;
45     private String JavaDoc userPassword = null;
46     public BonitaClient soapclient;
47     private ProjectNodes pn = new ProjectNodes();
48     public final static String JavaDoc imageBase = "images/";
49     public final static ImageIcon JavaDoc icon = new ImageIcon JavaDoc(Thread.currentThread().getContextClassLoader().getResource(imageBase + "icon.png"));
50
51     public WFPersistence(String JavaDoc managerProject, BonitaClient soapclient) throws Exception JavaDoc{
52             this.soapclient = soapclient;
53             soapclient.openProject(managerProject);
54             projectName = managerProject;
55             permission = isInRole(this.getUser(), Constants.ADMIN);
56     }
57
58     public boolean openProject(String JavaDoc projectName) throws Exception JavaDoc {
59         soapclient.openProject(projectName);
60         this.projectName = projectName;
61         this.setProjectNodes();
62         return true;
63     }
64
65     public boolean createProject(String JavaDoc projectName) throws Exception JavaDoc {
66
67         if (exists(projectName)) {
68             return false;
69         }
70
71         soapclient.createProject(projectName);
72         // userAcces = "All";
73
this.projectName = projectName;
74         return true;
75
76     }
77     
78     public boolean createModel(String JavaDoc modelName) throws Exception JavaDoc {
79
80         if (exists(modelName)) {
81             return false;
82         }
83
84         soapclient.createModel(modelName);
85         // userAcces = "All";
86
this.projectName = modelName;
87         return true;
88
89     }
90
91     public boolean cloneProject(String JavaDoc projectSrc, String JavaDoc projectDest)
92         throws Exception JavaDoc {
93         if (exists(projectDest)) {
94             return false;
95         }
96         soapclient.cloneProject(projectSrc, projectDest);
97         // userAcces = "All";
98
this.projectName = projectDest;
99         return true;
100     }
101     
102     public boolean cloneSubProject(String JavaDoc projectSrc, String JavaDoc projectDest)
103             throws Exception JavaDoc {
104             soapclient.cloneProject(projectSrc, projectDest);
105             return true;
106         }
107
108     public String JavaDoc getUser() throws Exception JavaDoc {
109         return (soapclient.getUser());
110     }
111
112     public boolean hasPermission() {
113         return permission;
114     }
115
116     private boolean exists(String JavaDoc name) throws Exception JavaDoc {
117         String JavaDoc prj;
118         Collection JavaDoc projects = soapclient.getProjects();
119         Iterator JavaDoc i = projects.iterator();
120         while (i.hasNext()) {
121             prj = (String JavaDoc) i.next();
122             if (prj.equalsIgnoreCase(name)) {
123                 return true;
124             }
125         }
126         return false;
127     }
128
129     public Object JavaDoc[] getProjects() throws Exception JavaDoc {
130         Collection JavaDoc projects = soapclient.getProjects();
131         return (projects.toArray());
132     }
133
134     public boolean containsNode(String JavaDoc value) throws Exception JavaDoc {
135         Collection JavaDoc nodes = soapclient.getNodes();
136         Iterator JavaDoc i = nodes.iterator();
137         while (i.hasNext()) {
138             String JavaDoc nodeName = (String JavaDoc) i.next();
139             if (value.equalsIgnoreCase(nodeName)) {
140                 return true;
141             }
142         }
143         return false;
144     }
145     
146     public boolean containsProject(String JavaDoc value) throws Exception JavaDoc {
147         Collection JavaDoc projects = soapclient.getProjects();
148         Iterator JavaDoc i = projects.iterator();
149         while (i.hasNext()) {
150             String JavaDoc projectName = (String JavaDoc) i.next();
151             if (value.equalsIgnoreCase(projectName)) {
152                 return true;
153             }
154         }
155         return false;
156     }
157
158     public Object JavaDoc[] getNodes() throws Exception JavaDoc {
159         Collection JavaDoc nodes = soapclient.getNodes();
160         return (nodes.toArray());
161     }
162
163     public Object JavaDoc[] getEdges() throws Exception JavaDoc {
164         Collection JavaDoc nodes = soapclient.getEdges();
165         return (nodes.toArray());
166     }
167
168     public void addNode(String JavaDoc name, String JavaDoc type) throws Exception JavaDoc {
169         soapclient.addNode(name, type);
170     }
171     
172     public void addNodeSubProcess(String JavaDoc name, String JavaDoc projectName) throws Exception JavaDoc {
173         soapclient.addNodeSubProcess(name, projectName);
174     }
175
176     public boolean deleteNode(String JavaDoc node) throws Exception JavaDoc {
177         soapclient.deleteNode(node);
178         return true;
179     }
180     
181     public boolean deleteProject(String JavaDoc project) throws Exception JavaDoc {
182         soapclient.deleteProject(project);
183         return true;
184     }
185
186     public void deleteEdges(Object JavaDoc[] edges) throws Exception JavaDoc {
187         soapclient.deleteEdges(edges);
188     }
189
190     public String JavaDoc addEdge(String JavaDoc src, String JavaDoc dest) throws Exception JavaDoc {
191         return soapclient.addEdge(src, dest);
192     }
193
194     public String JavaDoc setEdgeCondition(String JavaDoc edgeName, String JavaDoc condition)
195         throws Exception JavaDoc {
196         soapclient.setEdgeCondition(edgeName, condition);
197         return edgeName;
198     }
199     
200     public String JavaDoc getEdgeCondition(String JavaDoc edgeName)
201         throws Exception JavaDoc {
202         return (soapclient.getEdgeCondition(edgeName));
203     }
204
205     public String JavaDoc getState(String JavaDoc name) throws Exception JavaDoc {
206         int state = soapclient.getNodeState(name);
207         switch (state) {
208             case Constants.Nd.INITIAL :
209                 return ("Initial");
210             case Constants.Nd.READY :
211                 return ("READY");
212             case Constants.Nd.ANTICIPABLE :
213                 return ("Anticipable");
214             case Constants.Nd.ANTICIPATING :
215                 return ("Anticipating");
216             case Constants.Nd.EXECUTING :
217                 return ("Executing");
218             case Constants.Nd.EXECUTED :
219                 return ("Executed");
220             case Constants.Nd.TERMINATED :
221                 return ("Terminated");
222             case Constants.Nd.ANT_SUSPENDED :
223                 return ("Ant_suspended");
224             case Constants.Nd.EXEC_SUSPENDED :
225                 return ("Exec_suspended");
226         }
227         return ("");
228     }
229
230     public int getNodeState(String JavaDoc name) throws Exception JavaDoc {
231         /* Object[] nodes = this.pn.getNodes();
232             for (int i=0;i<nodes.length;i++)
233             {
234                 StrutsNodeValue node = (StrutsNodeValue) nodes[i];
235                 if ((node.getName()).equals(name))
236                     return(new Integer(node.getState()).intValue());
237             }
238         return(0);*/

239         return(soapclient.getNodeState(name));
240     }
241     
242     public int getNodeType(String JavaDoc name) throws Exception JavaDoc {
243                 /*Object[] nodes = this.pn.getNodes();
244                 for (int i=0;i<nodes.length;i++)
245                 {
246                     StrutsNodeValue node = (StrutsNodeValue) nodes[i];
247                     if ((node.getName()).equals(name))
248                         return(new Integer(node.getType()).intValue());
249                 }
250             return(0);*/

251         return(soapclient.getNodeType(name));
252         }
253
254     public String JavaDoc getEdgeInNode(String JavaDoc name) throws Exception JavaDoc {
255         return (soapclient.getEdgeInNode(name));
256     }
257
258     public String JavaDoc getEdgeOutNode(String JavaDoc name) throws Exception JavaDoc {
259         return (soapclient.getEdgeOutNode(name));
260     }
261
262     public boolean isActive(String JavaDoc name)
263         throws Exception JavaDoc { //Only used by WFmanager.updateStatus
264
int state = soapclient.getNodeState(name);
265         switch (state) {
266             case Constants.Nd.INITIAL :
267                 return false;
268             case Constants.Nd.READY :
269                 return false;
270             case Constants.Nd.ANTICIPABLE :
271                 return false;
272             case Constants.Nd.ANTICIPATING :
273                 return true;
274             case Constants.Nd.EXECUTING :
275                 return true;
276             case Constants.Nd.EXECUTED :
277                 return false;
278             case Constants.Nd.TERMINATED :
279                 return true;
280             case Constants.Nd.ANT_SUSPENDED :
281                 return false;
282             case Constants.Nd.EXEC_SUSPENDED :
283                 return false;
284         }
285         return false;
286     }
287
288     public String JavaDoc getType(String JavaDoc name) throws Exception JavaDoc {
289         return (soapclient.getType(name));
290     }
291
292     public String JavaDoc getRole(String JavaDoc name) throws Exception JavaDoc {
293         return (soapclient.getRole(name));
294     }
295
296     public void setNodeRole(String JavaDoc node, String JavaDoc newRole) throws Exception JavaDoc {
297         soapclient.setNodeRole(node, newRole);
298         this.setProjectNodeRole(node,newRole);
299     }
300
301     public String JavaDoc getDeadline(String JavaDoc name) throws Exception JavaDoc {
302         this.setProjectNodes();
303         return (soapclient.getDeadline(name));
304     }
305
306     public void setDeadline(String JavaDoc name, long dl) throws Exception JavaDoc {
307         soapclient.setDeadline(name, dl);
308     }
309
310     public String JavaDoc getNodeInterHookValue(String JavaDoc nodeName, String JavaDoc hookName)
311         throws Exception JavaDoc {
312         return (soapclient.getNodeInterHookValue(nodeName, hookName));
313     }
314     
315     public String JavaDoc getProjectInterHookValue(String JavaDoc hookName)
316         throws Exception JavaDoc {
317         return (soapclient.getProjectInterHookValue(hookName));
318     }
319
320     public String JavaDoc getNodeDescription(String JavaDoc nodeName) throws Exception JavaDoc {
321         return (soapclient.getNodeDescription(nodeName));
322     }
323
324     public void setNodeDescription(String JavaDoc nodeName, String JavaDoc description)
325         throws Exception JavaDoc {
326         soapclient.setNodeDescription(nodeName, description);
327         this.setProjectNodeDescription(nodeName,description);
328     }
329
330     public void setNodeTraditional(String JavaDoc nodeName)
331         throws Exception JavaDoc {
332         soapclient.setNodeTraditional(nodeName);
333     }
334     
335     public void setNodeAnticipable(String JavaDoc nodeName)
336         throws Exception JavaDoc {
337         soapclient.setNodeAnticipable(nodeName);
338     }
339
340     public boolean getNodeAnticipable(String JavaDoc nodeName)
341         throws Exception JavaDoc {
342         return(soapclient.getNodeAnticipable(nodeName));
343     }
344
345     public void setNodeInterHookValue(String JavaDoc nodeName,String JavaDoc hookName,String JavaDoc value)
346         throws Exception JavaDoc {
347         soapclient.setNodeInterHookValue(nodeName, hookName, value);
348     }
349     
350     public void setProjectInterHookValue(String JavaDoc hookName,String JavaDoc value)
351         throws Exception JavaDoc {
352         soapclient.setProjectInterHookValue(hookName, value);
353     }
354
355     public Object JavaDoc[] getRoles() throws Exception JavaDoc {
356         Collection JavaDoc roles = soapclient.getRoles();
357         return (roles.toArray());
358     }
359
360     public Object JavaDoc[] getUsersInProject() throws Exception JavaDoc {
361         Collection JavaDoc users = soapclient.getUsersInProject();
362         return (users.toArray());
363     }
364
365     public Object JavaDoc[] getAllUsers() throws Exception JavaDoc {
366         Collection JavaDoc users = soapclient.getAllUsers();
367         return (users.toArray());
368     }
369
370     public void addUser(String JavaDoc name) throws Exception JavaDoc {
371         soapclient.addUser(name);
372     }
373
374     public void addRole(String JavaDoc name, String JavaDoc desc) throws Exception JavaDoc {
375         soapclient.addRole(name, desc);
376     }
377
378     public void addNodeProperty(String JavaDoc nodeName,String JavaDoc key,String JavaDoc value,boolean propagate)
379         throws Exception JavaDoc {
380         soapclient.addNodeProperty(nodeName, key, value, propagate);
381     }
382
383     public void addProjectProperty(String JavaDoc key,String JavaDoc value)
384         throws Exception JavaDoc {
385         soapclient.addProjectProperty(key, value);
386     }
387
388     public void setUserRole(String JavaDoc name, String JavaDoc role) throws Exception JavaDoc {
389         soapclient.setUserRole(name, role);
390     }
391     
392     public void addRoleMapper(String JavaDoc role, String JavaDoc mapper, String JavaDoc type) throws Exception JavaDoc {
393         soapclient.addRoleMapper(role,mapper,type);
394     }
395     
396     public void addPerformerAssigment(String JavaDoc node, String JavaDoc performerName, String JavaDoc type, String JavaDoc property) throws Exception JavaDoc {
397         soapclient.addNodePerformerAssigment(node,performerName,type,property);
398     }
399     
400     public void setEditNode(String JavaDoc node, String JavaDoc role, String JavaDoc description, Date JavaDoc deadline) throws Exception JavaDoc {
401         soapclient.setEditNode(node, role, description, deadline.getTime());
402         this.setProjectNodeRole(node,role);
403         this.setProjectNodeDescription(node,description);
404         this.setProjectNodeDeadline(node,deadline.getTime());
405     }
406
407     public void addNodeInterHook(String JavaDoc nodeName,String JavaDoc hookName,String JavaDoc event,String JavaDoc value)
408         throws Exception JavaDoc {
409         soapclient.addNodeInterHook(nodeName, hookName, event, value);
410     }
411     
412     public void addProjectInterHook(String JavaDoc hookName,String JavaDoc event,String JavaDoc value)
413         throws Exception JavaDoc {
414         soapclient.addProjectInterHook(hookName, event, value);
415     }
416
417     public void addIteration(String JavaDoc from,String JavaDoc to, String JavaDoc condition)
418         throws Exception JavaDoc {
419         soapclient.addIteration(from, to, condition);
420     }
421
422     public Collection JavaDoc getIterations()
423         throws Exception JavaDoc {
424         return(soapclient.getIterations());
425     }
426
427
428     public boolean isInRole(String JavaDoc name, String JavaDoc role) throws Exception JavaDoc {
429         return (soapclient.isInRole(name, role));
430     }
431
432     public String JavaDoc getProjectName() {
433         return this.projectName;
434     }
435
436     public String JavaDoc getStateString(int state) throws Exception JavaDoc {
437         switch (state) {
438             case Constants.Nd.INITIAL :
439                 return ("INITIAL");
440             case Constants.Nd.READY :
441                 return ("READY");
442             case Constants.Nd.ANTICIPABLE :
443                 return ("ANTICIPABLE");
444             case Constants.Nd.ANTICIPATING :
445                 return ("ANTICIPATING");
446             case Constants.Nd.EXECUTING :
447                 return ("EXECUTING");
448             case Constants.Nd.EXECUTED :
449                 return ("EXECUTED");
450             case Constants.Nd.TERMINATED :
451                 return ("TERMINATED");
452             case Constants.Nd.ANT_SUSPENDED :
453                 return ("ANT_SUSPENDED");
454             case Constants.Nd.EXEC_SUSPENDED :
455                 return ("EXEC_SUSPENDED");
456         }
457         return ("");
458     }
459     
460     public int getStateInt(String JavaDoc state) throws Exception JavaDoc {
461         if (state.equals("INITIAL"))
462             return Constants.Nd.INITIAL;
463         if (state.equals("READY"))
464             return Constants.Nd.READY;
465         if (state.equals("ANTICIPABLE"))
466             return Constants.Nd.ANTICIPABLE;
467         if (state.equals("ANTICIPATING"))
468             return Constants.Nd.ANTICIPATING;
469         if (state.equals("EXECUTING"))
470             return Constants.Nd.EXECUTING;
471         if (state.equals("TERMINATED"))
472             return Constants.Nd.TERMINATED;
473         return (-1);
474     }
475     
476
477     public String JavaDoc getTypeString(int type) throws Exception JavaDoc {
478         switch (type) {
479             case Constants.Nd.AND_JOIN_NODE :
480                 return ("And Join");
481             case Constants.Nd.OR_JOIN_NODE :
482                 return ("Or Join");
483             case Constants.Nd.AND_JOIN_AUTOMATIC_NODE :
484                 return ("And Join Automatic");
485             case Constants.Nd.OR_JOIN_AUTOMATIC_NODE :
486                 return ("Or Join Automatic");
487         }
488         return ("");
489     }
490
491     public void setProjectNodes() throws Exception JavaDoc {
492         this.pn.setNodes(soapclient.getProjectNodes());
493     }
494     
495     public Object JavaDoc[] getProjectNodes() throws Exception JavaDoc {
496             return(soapclient.getProjectNodes());
497         }
498         
499     public Object JavaDoc[] getProjectNodesArray() throws Exception JavaDoc {
500         return(this.pn.getNodes());
501     }
502
503     public Collection JavaDoc getProperties() throws Exception JavaDoc {
504         return(soapclient.getProperties());
505     }
506
507     public void windowMessage(String JavaDoc msg) {
508         JOptionPane.showMessageDialog(null, msg);
509     }
510     
511     // Local Model operations
512

513     public StrutsNodeValue getProjectNode(String JavaDoc nodeName) throws Exception JavaDoc {
514         /*Collection nodes = this.pn.getNodes();
515         Iterator i = nodes.iterator();
516         while (i.hasNext()) {*/

517         Object JavaDoc[] nodes = this.pn.getNodes();
518         for (int i=0;i<nodes.length;i++)
519         {
520         StrutsNodeValue node = (StrutsNodeValue)nodes[i];
521             if ((node.getName()).equals(nodeName))
522                 return node;
523         }
524         return null;
525         //return(soapclient.getStrutsNode(nodeName));
526
}
527         
528     public void setProjectNodeState(String JavaDoc nodeName, int state) throws Exception JavaDoc {
529             Object JavaDoc[] nodes = this.pn.getNodes();
530             for (int i=0;i<nodes.length;i++)
531             {
532             StrutsNodeValue node = (StrutsNodeValue) nodes[i];
533                 if ((node.getName()).equals(nodeName))
534                     node.setState(this.getStateString(state));
535             }
536         }
537         
538     public void setProjectNodeRole(String JavaDoc nodeName, String JavaDoc role) throws Exception JavaDoc {
539             Object JavaDoc[] nodes = this.pn.getNodes();
540             for (int i=0;i<nodes.length;i++)
541             {
542               StrutsNodeValue node = (StrutsNodeValue) nodes[i];
543               if ((node.getName()).equals(nodeName))
544                     node.setRole(role);
545               }
546             }
547
548     public void setProjectNodeDescription(String JavaDoc nodeName, String JavaDoc description) throws Exception JavaDoc {
549             Object JavaDoc[] nodes = this.pn.getNodes();
550             for (int i=0;i<nodes.length;i++)
551             {
552                 StrutsNodeValue node = (StrutsNodeValue) nodes[i];
553                 if ((node.getName()).equals(nodeName))
554                     node.setDescription(description);
555             }
556         }
557         
558     public void setProjectNodeDeadline(String JavaDoc nodeName, long deadline) throws Exception JavaDoc {
559                 Object JavaDoc[] nodes = this.pn.getNodes();
560                 for (int i=0;i<nodes.length;i++)
561                 {
562                 StrutsNodeValue node = (StrutsNodeValue) nodes[i];
563                     if ((node.getName()).equals(nodeName)){
564                       SimpleDateFormat JavaDoc df = new SimpleDateFormat JavaDoc("yyyy-MM-dd");
565                       node.setDeadline(df.format(df.parse(new java.sql.Date JavaDoc(deadline).toString())));
566                     }
567                 }
568             }
569         
570 } // WFPersistence
571

572
Popular Tags