1 package org.enhydra.shark.toolagent; 2 3 4 import org.enhydra.shark.api.RootError; 5 import org.enhydra.shark.api.SharkTransaction; 6 import org.enhydra.shark.api.internal.toolagent.AppParameter; 7 import org.enhydra.shark.api.internal.toolagent.ApplicationBusy; 8 import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined; 9 import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted; 10 import org.enhydra.shark.api.internal.toolagent.SessionHandle; 11 import org.enhydra.shark.api.internal.toolagent.ToolAgent; 12 import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException; 13 import org.enhydra.shark.xpdl.elements.ExtendedAttribute; 14 import org.enhydra.shark.xpdl.elements.ExtendedAttributes; 15 16 23 public class DefaultToolAgent extends AbstractToolAgent { 24 25 private final static String TOOL_AGENT_CLASS_EXT_ATTR_NAME="ToolAgentClass"; 26 27 private String taClass; 28 private String callingAppName; 29 private Integer callingAppMode; 30 31 public void invokeApplication (SharkTransaction t, 32 long handle, 33 String applicationName, 34 String procInstId, 35 String assId, 36 AppParameter[] parameters, 37 Integer appMode) 38 throws ApplicationNotStarted, ApplicationNotDefined, 39 ApplicationBusy, ToolAgentGeneralException { 40 41 super.invokeApplication(t,handle,applicationName,procInstId,assId,parameters,appMode); 42 43 try { 44 status=APP_STATUS_RUNNING; 45 46 String extAttribs=(String )parameters[0].the_value; 47 readParamsFromExtAttributes(extAttribs); 48 49 51 Class cls=null; 52 53 try { 54 cls=Class.forName(taClass); 55 } catch (ClassNotFoundException cnfe1) { 56 cls = ToolAgentLoader.load(cus,taClass); 57 } 58 59 60 61 ToolAgent ta=(ToolAgent)cls.newInstance(); 62 ta.configure(cus); 63 64 SessionHandle taShandle; 66 try { 67 taShandle=ta.connect(t,username,password,engineName,scope); 68 } catch (org.enhydra.shark.api.internal.toolagent.ConnectFailed cf) { 69 cus.error("Default Tool Agent - connection to Tool agent "+taClass+" failed !"); 70 throw cf; 71 } 72 ta.invokeApplication(t,taShandle.getHandle(),callingAppName,procInstId,assId,parameters,callingAppMode); 73 status=ta.requestAppStatus(t,taShandle.getHandle(),procInstId,assId,parameters); 74 ta.disconnect(t,taShandle); 76 77 } catch (ClassNotFoundException cnf) { 78 cus.error("DefaultToolAgent - application "+appName+" terminated incorrectly, can't find class: "+cnf); 79 throw new ApplicationNotDefined("Can't find class "+taClass,cnf); 80 } catch (NoClassDefFoundError ncdfe) { 81 cus.error("DefaultToolAgent - application "+appName+" terminated incorrectly, can't find class definition: "+ncdfe); 82 throw new ApplicationNotDefined("Class "+appName+" can't be executed",ncdfe); 83 } catch (Throwable ex) { 84 cus.error("DefaultToolAgent - application "+appName+" terminated incorrectly: "+ex); 86 status=APP_STATUS_INVALID; 87 if (ex instanceof ToolAgentGeneralException) { 88 throw (ToolAgentGeneralException)ex; 89 } else if (ex instanceof ApplicationNotStarted) { 90 throw (ApplicationNotStarted)ex; 91 } else if (ex instanceof ApplicationNotDefined) { 92 throw (ApplicationNotDefined)ex; 93 } else if (ex instanceof ApplicationBusy) { 94 throw (ApplicationBusy)ex; 95 } else { 96 throw new RootError("Unexpected error",ex); 97 } 98 } 99 } 100 101 public String getInfo (SharkTransaction t) throws ToolAgentGeneralException { 102 String i="It is used to execute other tool agents based on XPDL extended attributes"+ 103 "\nof appropriate Application definition. It is called by kernel if there are"+ 104 "\nno mapping information for some XPDL Application definition"; 105 return i; 106 } 107 108 protected ExtendedAttributes readParamsFromExtAttributes (String extAttribs) throws Exception { 109 String oldAppName=appName; 110 Integer oldAppMode=appMode; 111 ExtendedAttributes eas=super.readParamsFromExtAttributes(extAttribs); 112 callingAppName=appName; 113 callingAppMode=appMode; 114 appName=oldAppName; 115 appMode=oldAppMode; 116 ExtendedAttribute ea=eas.getFirstExtendedAttributeForName(TOOL_AGENT_CLASS_EXT_ATTR_NAME); 117 if (ea!=null) { 118 taClass=ea.getVValue(); 119 } 120 return eas; 121 } 122 123 } 124 | Popular Tags |