Source Code Cross Referenced for AbstractToolAgent.java in  » Workflow-Engines » shark » org » enhydra » shark » toolagent » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » shark » org.enhydra.shark.toolagent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.enhydra.shark.toolagent;
002:
003:        import java.util.ArrayList;
004:
005:        import org.enhydra.shark.api.client.wfmc.wapi.WMConnectInfo;
006:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
007:        import org.enhydra.shark.api.client.wfservice.WMEntity;
008:        import org.enhydra.shark.api.internal.toolagent.AppParameter;
009:        import org.enhydra.shark.api.internal.toolagent.ApplicationBusy;
010:        import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined;
011:        import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted;
012:        import org.enhydra.shark.api.internal.toolagent.ApplicationNotStopped;
013:        import org.enhydra.shark.api.internal.toolagent.ConnectFailed;
014:        import org.enhydra.shark.api.internal.toolagent.InvalidProcessInstance;
015:        import org.enhydra.shark.api.internal.toolagent.InvalidSessionHandle;
016:        import org.enhydra.shark.api.internal.toolagent.InvalidToolAgentHandle;
017:        import org.enhydra.shark.api.internal.toolagent.InvalidWorkitem;
018:        import org.enhydra.shark.api.internal.toolagent.ToolAgent;
019:        import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException;
020:        import org.enhydra.shark.api.internal.working.CallbackUtilities;
021:        import org.enhydra.shark.utilities.MiscUtilities;
022:        import org.enhydra.shark.utilities.SizeLimitedToolAgentMap;
023:        import org.enhydra.shark.xpdl.XMLUtil;
024:        import org.enhydra.shark.xpdl.XPDLConstants;
025:        import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
026:        import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
027:
028:        /**
029:         * Base class for all tool agents we implement. If one wants to extend this class and
030:         * create tool agent, he should override invokeApplication method.
031:         * 
032:         * @author Sasa Bojanic
033:         */
034:        public abstract class AbstractToolAgent implements  ToolAgent {
035:
036:            public static final String COMMA_SEPARATOR_STR = ",";
037:            public static final String SEMICOLON_SEPARATOR_STR = ";";
038:
039:            public static final String APP_NAME_EXT_ATTR_NAME = "AppName";
040:
041:            public static final String APP_MODE_EXT_ATTR_NAME = "AppMode";
042:
043:            protected WMConnectInfo wmci;
044:
045:            protected WMSessionHandle tashandle;
046:
047:            protected WMSessionHandle shandle;
048:
049:            protected WMEntity appInfo;
050:
051:            protected WMEntity toolInfo;
052:
053:            protected long handle;
054:
055:            protected String appName;
056:
057:            protected String procInstId;
058:
059:            protected String assId;
060:
061:            protected AppParameter[] parameters;
062:
063:            protected Integer appMode;
064:
065:            protected long status = ToolAgent.APP_STATUS_ACTIVE;
066:
067:            protected CallbackUtilities cus;
068:
069:            protected static SizeLimitedToolAgentMap extAttributes = null;
070:
071:            public void configure(CallbackUtilities cus) throws Exception {
072:                this .cus = cus;
073:
074:                if (AbstractToolAgent.extAttributes == null) {
075:                    int eacs = -1;
076:                    try {
077:                        eacs = Integer.parseInt(cus.getProperty(
078:                                "AbstractToolAgent.extAttribsCacheSize", "-1"));
079:                    } catch (Exception ex) {
080:                    }
081:                    AbstractToolAgent.extAttributes = new SizeLimitedToolAgentMap(
082:                            eacs);
083:                }
084:            }
085:
086:            public WMSessionHandle connect(WMConnectInfo ci)
087:                    throws ConnectFailed, ToolAgentGeneralException {
088:
089:                this .wmci = ci;
090:                tashandle = new WMSessionHandle();
091:                tashandle.setId(0);
092:                tashandle.setVendorData(ci.getUserIdentification());
093:
094:                return tashandle;
095:            }
096:
097:            public void disconnect(WMSessionHandle shandle)
098:                    throws InvalidSessionHandle, ToolAgentGeneralException {
099:
100:                if (!this .tashandle.equals(shandle))
101:                    throw new InvalidSessionHandle();
102:            }
103:
104:            public void invokeApplication(WMSessionHandle shandle, long handle,
105:                    WMEntity appInfo, WMEntity toolInfo,
106:                    String applicationName, String procInstId, String assId,
107:                    AppParameter[] parameters, Integer appMode)
108:                    throws ApplicationNotStarted, ApplicationNotDefined,
109:                    ApplicationBusy, ToolAgentGeneralException {
110:
111:                this .shandle = shandle;
112:                this .appInfo = appInfo;
113:                this .toolInfo = toolInfo;
114:                this .handle = handle;
115:                this .appName = applicationName;
116:                this .procInstId = procInstId;
117:                this .assId = assId;
118:                this .parameters = parameters;
119:                this .appMode = appMode;
120:                this .status = ToolAgent.APP_STATUS_ACTIVE;
121:
122:            }
123:
124:            public long requestAppStatus(WMSessionHandle shandle, long handle,
125:                    WMEntity toolInfo, String procInstId, String assId,
126:                    AppParameter[] parameters) throws ApplicationBusy,
127:                    InvalidToolAgentHandle, InvalidWorkitem,
128:                    InvalidProcessInstance, ToolAgentGeneralException {
129:
130:                if (this .handle == handle) {
131:                    // System.out.println("Status for class "+getClass().getName()+" = "+status);
132:                    if (!(status == APP_STATUS_FINISHED
133:                            || status == APP_STATUS_TERMINATED || status == APP_STATUS_INVALID)) {
134:                        // System.out.println("Throwing AB exc");
135:                        throw new ApplicationBusy();
136:                    }
137:                    if (status != APP_STATUS_INVALID) {
138:                        copyParams(getReturnParameters(), parameters);
139:                        // ai.getReturnParameters(),parameters);
140:                    }
141:                    return status;
142:                } else {
143:                    throw new InvalidToolAgentHandle("TA "
144:                            + getClass().getName()
145:                            + " - Can't find app for [handle=" + handle
146:                            + ",pId=" + procInstId + ",assId=" + assId + "]");
147:                }
148:            }
149:
150:            public void terminateApp(WMSessionHandle shandle, long handle,
151:                    WMEntity toolInfo, String procInstId, String assId)
152:                    throws ApplicationNotStopped, InvalidWorkitem,
153:                    InvalidProcessInstance, ApplicationBusy,
154:                    ToolAgentGeneralException {
155:                cus
156:                        .info(shandle,
157:                                "Terminating tool agent applications not implemented !!!");
158:                throw new ApplicationNotStopped();
159:            }
160:
161:            public String getInfo(WMSessionHandle shandle)
162:                    throws ToolAgentGeneralException {
163:                return "";
164:            }
165:
166:            protected ExtendedAttributes readParamsFromExtAttributes(
167:                    String extAttribs) throws Exception {
168:                ExtendedAttributes eas = (ExtendedAttributes) AbstractToolAgent.extAttributes
169:                        .get(extAttribs);
170:                if (eas == null) {
171:                    if (extAttribs != null && !extAttribs.trim().equals("")) {
172:                        try {
173:                            eas = XMLUtil
174:                                    .destringyfyExtendedAttributes(extAttribs);
175:                            eas.setReadOnly(true);
176:                            eas.initCaches();
177:                        } catch (Throwable ex) {
178:                            // System.out.println("FAiled to destr");
179:                            cus.warn(shandle, "AbstractToolAgent -> "
180:                                    + ex.getMessage());
181:                        }
182:                    }
183:
184:                    // if (AbstractToolAgent.extAttributes.getMaximumSize()>0) {
185:                    AbstractToolAgent.extAttributes.put(extAttribs, eas);
186:                    // }
187:                }
188:                ExtendedAttribute ea = eas
189:                        .getFirstExtendedAttributeForName(AbstractToolAgent.APP_NAME_EXT_ATTR_NAME);
190:                if (ea != null) {
191:                    appName = ea.getVValue();
192:                }
193:                ea = eas
194:                        .getFirstExtendedAttributeForName(AbstractToolAgent.APP_MODE_EXT_ATTR_NAME);
195:                if (ea != null) {
196:                    try {
197:                        appMode = new Integer(Integer.parseInt(ea.getVValue()));
198:                    } catch (Exception ex) {
199:                    }
200:                }
201:                return eas;
202:            }
203:
204:            protected AppParameter[] getReturnParameters() {
205:                // preparing result
206:                ArrayList returnValues = new ArrayList();
207:                if (parameters != null) {
208:                    for (int i = 0; i < parameters.length; i++) {
209:                        if (parameters[i].the_mode
210:                                .equals(XPDLConstants.FORMAL_PARAMETER_MODE_OUT)
211:                                || parameters[i].the_mode
212:                                        .equals(XPDLConstants.FORMAL_PARAMETER_MODE_INOUT)) {
213:                            returnValues.add(parameters[i]);
214:                        }
215:                    }
216:                }
217:                AppParameter[] retParameters = (AppParameter[]) returnValues
218:                        .toArray(new AppParameter[returnValues.size()]);
219:
220:                return retParameters;
221:            }
222:
223:            public static void copyParams(AppParameter[] taApps,
224:                    AppParameter[] apps) {
225:                if (taApps != null) {
226:                    for (int i = 0; i < taApps.length; i++) {
227:                        AppParameter taApp = taApps[i];
228:                        for (int j = 0; j < apps.length; j++) {
229:                            if (apps[j].the_actual_name
230:                                    .equals(taApp.the_actual_name)) {
231:                                apps[j].the_value = taApp.the_value;
232:                            }
233:                        }
234:                    }
235:                }
236:            }
237:
238:            public static AppParameter getParameterByName(
239:                    AppParameter[] sharkParameters, String name)
240:                    throws Exception {
241:                if (sharkParameters != null) {
242:                    for (int i = 0; i < sharkParameters.length; i++) {
243:                        if (name.equals(sharkParameters[i].the_formal_name)) {
244:                            return sharkParameters[i];
245:                        }
246:                    }
247:                }
248:                return null;
249:            }
250:
251:            public static String getParameterString(
252:                    AppParameter[] sharkParameters, String parameterName)
253:                    throws Exception {
254:                AppParameter param = AbstractToolAgent.getParameterByName(
255:                        sharkParameters, parameterName);
256:                if (param != null && param.the_value != null) {
257:                    return param.the_value.toString();
258:                }
259:                return "";
260:            }
261:
262:            public static String[] getParameterStringArray(
263:                    AppParameter[] sharkParameters, String parameterName,
264:                    String separatorStr) throws Exception {
265:                AppParameter param = AbstractToolAgent.getParameterByName(
266:                        sharkParameters, parameterName);
267:                String[] ret = null;
268:                if (param != null && param.the_value != null) {
269:                    String pval = param.the_value.toString();
270:                    ret = MiscUtilities.tokenize(pval, separatorStr);
271:                }
272:                return ret;
273:            }
274:
275:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.