KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > workflowadmin > instantiation > actions > InstantiateProcess


1 package org.enhydra.shark.corbaclient.workflowadmin.instantiation.actions;
2
3 import java.awt.event.*;
4 import java.util.*;
5 import javax.swing.*;
6
7 import org.omg.WfBase.*;
8 import org.omg.WorkflowModel.*;
9 import org.omg.CORBA.ORB JavaDoc;
10 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
11 import org.omg.PortableServer.POA JavaDoc;
12 import org.omg.PortableServer.POAHelper JavaDoc;
13 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
14 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
15 import org.omg.PortableServer.POAPackage.ObjectNotActive JavaDoc;
16 import org.enhydra.shark.corbaclient.*;
17 import org.enhydra.shark.corbaclient.workflowadmin.*;
18 import org.enhydra.shark.corbaclient.workflowadmin.instantiation.*;
19
20 /**
21  * Creates new process from process definition.
22  *
23  * @author Sasa Bojanic
24  * @version 1.0
25  */

26 public class InstantiateProcess extends ActionBase {
27     private POA JavaDoc rootPOA;
28
29     public InstantiateProcess(ProcessInstantiationManagement pim) {
30         super(pim);
31     }
32
33     public void actionPerformed(ActionEvent e) {
34         ProcessInstantiationManagement pim = (ProcessInstantiationManagement) actionPanel;
35         SharkAdmin workflowAdmin = pim.getWorkflowAdmin();
36         WfProcessMgr spm = pim.getSelectedProcessMgr();
37         try {
38             if (spm != null) {
39
40                 ProcessInstantiatorInterface pi = pim.getProcessInstantiator();
41                 WfRequester wfReq = null;
42                 if (SharkClient.POA)
43                     wfReq = WfRequesterHelper.narrow(((ProcessInstantiatorPOA) pi)._this_object());
44                 else
45                     wfReq = WfRequesterHelper.narrow(((ProcessInstantiatorCORBA) pi));
46
47                 WfProcess proc = spm.create_process(wfReq);
48                 // if process has to receive some initial values, fill it
49
NameValue[] context = proc.process_context();
50                 Map contextSig = WorkflowUtilities.
51                 makeLinkedHashMap(SharkAdmin.getExecAmin().getProcessMgrInputSignatureByMgrName(spm.name()));
52
53                 ArrayList formalPars = new ArrayList();
54                 if (context != null && context.length > 0) {
55                     for (int i = 0; i < context.length; i++) {
56                         if (contextSig.containsKey(context[i].the_name)) {
57                             formalPars.add(context[i]);
58                         }
59                     }
60                 }
61                 if (formalPars.size() > 0) {
62                     NameValue[] initContext = new NameValue[formalPars.size()];
63                     formalPars.toArray(initContext);
64                     int updateVar = JOptionPane.showConfirmDialog(workflowAdmin.getFrame(),
65                             ResourceManager.getLanguageDependentString("MessageDoYouWantToUpdateProcessVariables"),
66                             ResourceManager.getLanguageDependentString("ProcessInstantiationManagementKey"),
67                             JOptionPane.YES_NO_OPTION,
68                             JOptionPane.QUESTION_MESSAGE);
69                     if (updateVar == JOptionPane.YES_OPTION) {
70                         UpdateVariables upvd =
71                         new UpdateVariables(workflowAdmin.getFrame(),
72                                 ResourceManager.getLanguageDependentString("DialogUpdateProcessVariables"),
73                                 proc.key(),
74                                 initContext,
75                                 null);
76                         upvd.showDialog();
77                         if (context != null) {
78                             proc.set_process_context(initContext);
79                         }
80                     }
81                 }
82
83                 proc.start();
84                 pim.getProcessInstantiator().addPerformer(proc);
85                 pim.getTreeSelectionListener().valueChanged(null);
86                 workflowAdmin.refresh(true);
87
88             }
89         } catch (NotEnabled ne) {
90             JOptionPane.showMessageDialog(workflowAdmin.getFrame(),
91                     ResourceManager.getLanguageDependentString("WarningProcessInstantiationForSelectedDefinitionIsCurrentlyDisabled"),
92                     workflowAdmin.getAppTitle(), JOptionPane.ERROR_MESSAGE);
93         } catch (Exception JavaDoc ex) {
94             ex.printStackTrace();
95             System.out.println("Error while instantiating process: " + ex);
96         }
97     }
98 }
99
Popular Tags