Source Code Cross Referenced for StandardToolAgentManager.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:        import java.util.Collections;
005:        import java.util.Iterator;
006:        import java.util.List;
007:        import java.util.Map;
008:        import java.util.Properties;
009:
010:        import org.enhydra.shark.api.RootError;
011:        import org.enhydra.shark.api.client.wfmc.wapi.WMConnectInfo;
012:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
013:        import org.enhydra.shark.api.client.wfservice.WMEntity;
014:        import org.enhydra.shark.api.internal.appmappersistence.ApplicationMap;
015:        import org.enhydra.shark.api.internal.appmappersistence.ApplicationMappingManager;
016:        import org.enhydra.shark.api.internal.toolagent.AppParameter;
017:        import org.enhydra.shark.api.internal.toolagent.ConnectFailed;
018:        import org.enhydra.shark.api.internal.toolagent.ToolAgent;
019:        import org.enhydra.shark.api.internal.toolagent.ToolAgentManager;
020:        import org.enhydra.shark.api.internal.working.CallbackUtilities;
021:
022:        /**
023:         * Standard manager for creating and invoking tool agents.
024:         * 
025:         * @author Sasa Bojanic
026:         * @version 1.0
027:         */
028:        public class StandardToolAgentManager implements  ToolAgentManager {
029:            public static final String APPLICATION_MAPPING_CLASS_NAME_PROPERTY = "StandardToolAgentManager.ApplicationMapPersistenceManagerClassName";
030:
031:            public static final String DEFAULT_TOOL_AGENT = "DefaultToolAgent";
032:
033:            private ApplicationMappingManager applicationMappings;
034:
035:            private final static String TOOL_AGENT_PREFIX = "ToolAgent.";
036:
037:            private List toolAgents = new ArrayList();
038:
039:            private CallbackUtilities cus;
040:
041:            private String defaultToolAgentClassName;
042:
043:            public void configure(CallbackUtilities cus) throws Exception {
044:                this .cus = cus;
045:                defaultToolAgentClassName = cus.getProperty(DEFAULT_TOOL_AGENT,
046:                        "org.enhydra.shark.toolagent.DefaultToolAgent");
047:
048:                createToolAgentList();
049:
050:                String ammClassName = cus
051:                        .getProperty(APPLICATION_MAPPING_CLASS_NAME_PROPERTY);
052:
053:                ClassLoader cl = getClass().getClassLoader();
054:
055:                try {
056:                    applicationMappings = (ApplicationMappingManager) cl
057:                            .loadClass(ammClassName).newInstance();
058:                    applicationMappings.configure(cus);
059:                    cus
060:                            .info(
061:                                    null,
062:                                    "StandardToolAgentManager -> Working with '"
063:                                            + ammClassName
064:                                            + "' implementation of ApplicationMapPersistence API");
065:                } catch (Exception ex) {
066:                    boolean throwError = true;
067:                    String msg = "StandardToolAgentManager -> Can't work - ";
068:                    if (ammClassName == null || ammClassName.trim().equals("")) {
069:                        msg = "StandardToolAgentManager -> Working without ApplicationMapPersistence API implementation - ";
070:                        msg += "ApplicationMapPersistenceManager is not specified.";
071:                        throwError = false;
072:                    } else if (applicationMappings == null) {
073:                        msg += "Can't find ApplicationMapPersistenceManager class '"
074:                                + ammClassName + "' in classpath!";
075:                    } else {
076:                        msg += "Problems while configuring ApplicationMapPersistenceManager!";
077:                    }
078:                    cus.info(null, msg);
079:                    if (throwError) {
080:                        throw new RootError(msg, ex);
081:                    }
082:                }
083:            }
084:
085:            /**
086:             * Returns all tool agents specified in shark's properties.
087:             */
088:            public List getDefinedToolAgents(WMSessionHandle shandle)
089:                    throws Exception {
090:                return Collections.unmodifiableList(toolAgents);
091:            }
092:
093:            public ToolAgent createToolAgent(WMSessionHandle shandle,
094:                    String className) throws Exception {
095:
096:                Class cls = null;
097:
098:                try {
099:                    cls = Class.forName(className);
100:                } catch (ClassNotFoundException cnfe1) {
101:                    cls = ToolAgentLoader.load(cus, className);
102:                }
103:
104:                ToolAgent ta = (ToolAgent) cls.newInstance();
105:                ta.configure(cus);
106:                return ta;
107:            }
108:
109:            public void invokeToolAgent(WMSessionHandle shandle,
110:                    WMEntity appInfo, WMEntity toolInfo, AppParameter[] aprs,
111:                    String procId, String actId, String assId) throws Exception {
112:                // find mapped procedure - but we can also live without mapping
113:                // manager (but we can't without ToolAgentFactory
114:                ApplicationMappingManager mm = getApplicationMapPersistenceManager();
115:                ApplicationMap tad = null;
116:                if (mm != null) {
117:                    tad = mm.getApplicationMap(shandle, appInfo.getPkgId(),
118:                            appInfo.getPkgVer(), appInfo.getWpId(), appInfo
119:                                    .getId());
120:                }
121:                WMSessionHandle tashandle = null;
122:                String tacn = (tad != null) ? tad.getToolAgentClassName()
123:                        : defaultToolAgentClassName;
124:                String uname = (tad != null) ? tad.getUsername() : "";
125:                String pwd = (tad != null) ? tad.getPassword() : "";
126:                String appN = (tad != null) ? tad.getApplicationName() : "";
127:                Integer appM = (tad != null) ? tad.getApplicationMode() : null;
128:
129:                ToolAgent ta = createToolAgent(shandle, tacn);
130:
131:                WMConnectInfo wmci = new WMConnectInfo(uname, pwd, cus
132:                        .getProperty("enginename", "imaobihostrezube"), "");
133:                // try to connect to the tool agent
134:                try {
135:                    tashandle = ta.connect(wmci);
136:                } catch (ConnectFailed cf) {
137:                    cus.error(shandle, "Activity" + actId
138:                            + " - connection to Tool agent " + tacn
139:                            + " failed !");
140:                    throw cf;
141:                }
142:
143:                long appStatus;
144:                ta.invokeApplication(shandle, tashandle.getId(), appInfo,
145:                        toolInfo, appN, procId, assId, aprs, appM);
146:
147:                appStatus = ta.requestAppStatus(shandle, tashandle.getId(),
148:                        toolInfo, procId, assId, aprs);
149:                // System.err.println("TAM get status "+appStatus+" for underlying TA");
150:                if (appStatus == ToolAgent.APP_STATUS_INVALID) {
151:                    // System.err.println("TAM catched invalid APPS and throwing exc");
152:                    ta.disconnect(tashandle);
153:                    throw new Exception("Tool agent status is invalid!");
154:                }
155:                ta.disconnect(tashandle);
156:
157:            }
158:
159:            private void createToolAgentList() {
160:                String taName = null;
161:                String className = null;
162:                Properties props = cus.getProperties();
163:
164:                Iterator it = props.entrySet().iterator();
165:                while (it.hasNext()) {
166:                    try {
167:                        Map.Entry me = (Map.Entry) it.next();
168:                        taName = me.getKey().toString();
169:                        if (taName.startsWith(TOOL_AGENT_PREFIX)) {
170:                            taName = taName.substring(TOOL_AGENT_PREFIX
171:                                    .length());
172:                            className = me.getValue().toString();
173:                            toolAgents.add(className);
174:                        }
175:                    } catch (Throwable ex) {
176:                        // ex.printStackTrace();
177:                        cus
178:                                .error(
179:                                        null,
180:                                        "StandardToolAgentManager -> Error when retrieving list of tool agents from properties!!!");
181:                    }
182:                }
183:            }
184:
185:            public ApplicationMappingManager getApplicationMapPersistenceManager() {
186:                return applicationMappings;
187:            }
188:
189:            public String[][] getToolAgentsInfo(WMSessionHandle shandle)
190:                    throws Exception {
191:                List l = getDefinedToolAgents(shandle);
192:                String[][] ret = new String[l.size()][2];
193:                for (int i = 0; i < l.size(); i++) {
194:                    String tan = (String) l.get(i);
195:                    ret[i][0] = new String(tan);
196:                    ret[i][1] = new String(createToolAgent(shandle, tan)
197:                            .getInfo(shandle));
198:                }
199:
200:                return ret;
201:            }
202:
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.