1 package org.enhydra.shark.toolagent; 2 3 4 import java.io.IOException ; 5 6 import org.enhydra.shark.api.SharkTransaction; 7 import org.enhydra.shark.api.internal.toolagent.AppParameter; 8 import org.enhydra.shark.api.internal.toolagent.ApplicationBusy; 9 import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined; 10 import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted; 11 import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException; 12 import org.enhydra.shark.xpdl.XPDLConstants; 13 14 19 public class RuntimeApplicationToolAgent extends AbstractToolAgent { 20 21 public static final long APP_MODE_SYNCHRONOUS=0; 22 public static final long APP_MODE_ASYNCHRONOUS=1; 23 24 25 private Process p; 26 27 public void invokeApplication (SharkTransaction t, 28 long handle, 29 String applicationName, 30 String procInstId, 31 String assId, 32 AppParameter[] parameters, 33 Integer appMode) 34 throws ApplicationNotStarted, ApplicationNotDefined, 35 ApplicationBusy, ToolAgentGeneralException { 36 37 super.invokeApplication(t,handle,applicationName,procInstId,assId,parameters,appMode); 38 39 try { 40 status=APP_STATUS_RUNNING; 41 42 StringBuffer buffer = new StringBuffer (); 43 44 if (appName==null || appName.trim().length()==0) { 45 readParamsFromExtAttributes((String )parameters[0].the_value); 46 } 47 48 buffer.append(appName); 49 50 buffer.append(" "); 52 if (parameters!=null) { 53 for (int i=1; i<parameters.length; i++) { 54 if(parameters[i].the_mode.equals(XPDLConstants.FORMAL_PARAMETER_MODE_IN) || 55 parameters[i].the_mode.equals(XPDLConstants.FORMAL_PARAMETER_MODE_INOUT)) { 56 try { 57 buffer.append((String )parameters[i].the_value); 58 buffer.append(" "); 59 } catch (Throwable ex) {} 60 } 61 } 62 } 63 64 Runtime rt = Runtime.getRuntime(); 65 p = rt.exec(buffer.toString().substring(0,buffer.length()-1)); 66 if (appMode!=null && appMode.intValue()==APP_MODE_SYNCHRONOUS) { 67 p.waitFor(); 68 } 69 70 status=APP_STATUS_FINISHED; 71 72 } catch (IOException ioe) { 73 cus.error("RuntimeApplicationToolAgent - application "+appName+" terminated incorrectly, can't find executable: "+ioe); 74 throw new ApplicationNotDefined("Can't find executable "+appName,ioe); 75 } catch (Throwable ex) { 76 cus.error("RuntimeApplicationToolAgent - application "+appName+" terminated incorrectly "+ex); 77 status=APP_STATUS_INVALID; 78 throw new ToolAgentGeneralException(ex); 79 } 80 81 } 82 83 91 92 public String getInfo (SharkTransaction t) throws ToolAgentGeneralException { 93 String i="Executes some system applications like notepad or any other executable application."+ 94 "\nIt is important that this application should be in the system path of machine where shark is running." + 95 "\nf you use application mode 0 (zero), the tool agent will wait until the executable application "+ 96 "\nis completed, and if you choose application status other then 0 the tool agent will finish its work as "+ 97 "\nsoon as the executable application is started (this usually happens immediately), and shark "+ 98 "\nwill proceed to the next activity, even if the executable application is still running "+ 99 "\n(this is asynchronous starting of some external applications)"+ 100 "\nThis tool agent accepts parameters (AppParameter class instances), but does not modify any."+ 101 "\nThe parameters sent to this tool agents, for which the corresponding application definition "+ 102 "\nformal parameters are of \"IN\" type, and whose data type is string, are added as suffixes to "+ 103 "\nthe application name, and resulting application that is started could be something like "+ 104 "\n \"notepad c:\\Shark\\readme\""+ 105 "\n"+ 106 "\nThis tool agent is able to understand the extended attributes with the following names:"+ 107 "\n * AppName - value of this attribute should represent the executable application name to "+ 108 "\n be executed by tool agent (must be in a system path)"+ 109 "\n * AppMode - value of this attribute should represent the mode of execution, if set to "+ 110 "\n 0 (zero), tool agent will wait until the executable application is finished."+ 111 "\n"+ 112 "\n NOTE: Tool agent will read extended attributes only if they are called through"+ 113 "\n Default tool agent (not by shark directly) and this is the case when information "+ 114 "\n on which tool agent to start for XPDL application definition is not contained in mappings"; 115 return i; 116 } 117 118 119 } 120 | Popular Tags |