Source Code Cross Referenced for MailToolAgent.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 org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
004:        import org.enhydra.shark.api.client.wfservice.WMEntity;
005:        import org.enhydra.shark.api.internal.toolagent.AppParameter;
006:        import org.enhydra.shark.api.internal.toolagent.ApplicationBusy;
007:        import org.enhydra.shark.api.internal.toolagent.ApplicationNotDefined;
008:        import org.enhydra.shark.api.internal.toolagent.ApplicationNotStarted;
009:        import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException;
010:
011:        /**
012:         * Tool agent that sends or receives e-mail.
013:         * 
014:         * This tool agent now supports also sending the
015:         * mail with attachments.
016:         * 
017:         * 
018:         * @author Paloma Trigueros
019:         * @author Sasa Bojanic
020:         * 
021:         */
022:        public class MailToolAgent extends AbstractToolAgent {
023:
024:            public static final long APP_MODE_SEND = 0;
025:
026:            public static final long APP_MODE_RECEIVE = 1;
027:
028:            public void invokeApplication(WMSessionHandle shandle, long handle,
029:                    WMEntity appInfo, WMEntity toolInfo,
030:                    String applicationName, String procInstId, String assId,
031:                    AppParameter[] parameters, Integer appMode)
032:                    throws ApplicationNotStarted, ApplicationNotDefined,
033:                    ApplicationBusy, ToolAgentGeneralException {
034:
035:                //		for(int i=0; i<parameters.length; i++) {
036:                //			System.out.println("[Actual="+parameters[i].the_actual_name + "][Formal=" + parameters[i].the_formal_name+ "]");
037:                //		}
038:
039:                super 
040:                        .invokeApplication(shandle, handle, appInfo, toolInfo,
041:                                applicationName, procInstId, assId, parameters,
042:                                appMode);
043:
044:                try {
045:                    status = APP_STATUS_RUNNING;
046:
047:                    if (appName == null || appName.trim().length() == 0) {
048:                        readParamsFromExtAttributes((String) parameters[0].the_value);
049:                    }
050:
051:                    if (appName == null || appName.trim().length() == 0) {
052:                        appName = "org.enhydra.shark.toolagent.DefaultMailMessageHandler";
053:                    }
054:
055:                    ClassLoader cl = getClass().getClassLoader();
056:                    Class c = cl.loadClass(appName);
057:                    MailMessageHandler mch = (MailMessageHandler) c
058:                            .newInstance();
059:
060:                    // Get parameters - ignore 1. param, these are ext.attribs
061:                    AppParameter[] aps = new AppParameter[parameters.length - 1];
062:                    System.arraycopy(parameters, 1, aps, 0, aps.length);
063:
064:                    mch.configure(this .cus, shandle, procInstId, assId, aps);
065:
066:                    long am = 0;
067:                    if (appMode != null
068:                            && appMode.intValue() == APP_MODE_RECEIVE) {
069:                        am = 1;
070:                    }
071:
072:                    if (am == APP_MODE_SEND) {
073:                        // Send the message
074:                        System.out.println("Sending mail...");
075:                        mch.sendMail();
076:                        System.out.println("Mail sent.");
077:                    }
078:                    // Receive the message
079:                    else if (am == APP_MODE_RECEIVE) {
080:                        System.out.println("Receiving mail...");
081:                        String mailSubject = mch.receiveMail();
082:                        System.out.println("Mail received:" + mailSubject);
083:                    }
084:
085:                    status = APP_STATUS_FINISHED;
086:
087:                } catch (ClassNotFoundException cnf) {
088:                    cus.error(shandle, "MailToolAgent - application " + appName
089:                            + " terminated incorrectly, can't find class: "
090:                            + cnf);
091:                    status = APP_STATUS_INVALID;
092:                    throw new ApplicationNotDefined("Can't find class "
093:                            + appName, cnf);
094:                } catch (NoClassDefFoundError ncdfe) {
095:                    cus
096:                            .error(
097:                                    shandle,
098:                                    "MailToolAgent - application "
099:                                            + appName
100:                                            + " terminated incorrectly, can't find class definition: "
101:                                            + ncdfe);
102:                    status = APP_STATUS_INVALID;
103:                    throw new ApplicationNotDefined("Class " + appName
104:                            + " can't be executed", ncdfe);
105:                } catch (Throwable ex) {
106:                    cus.error(shandle, "MailToolAgent - application " + appName
107:                            + " terminated incorrectly: " + ex);
108:                    status = APP_STATUS_INVALID;
109:                    throw new ToolAgentGeneralException(ex);
110:                }
111:            }
112:
113:            public String getInfo(WMSessionHandle shandle)
114:                    throws ToolAgentGeneralException {
115:                String i = "Sends and receives mail messages."
116:                        + "\nThere is a MailMessageHandler interface defined that is used to actually "
117:                        + "\nhandle mails. We gave default implementation of this interface, but one can "
118:                        + "\ncreate its own implementation. This interface is specifically defined for this "
119:                        + "\ntool agent, and it is not part of Shark's APIs."
120:                        + "\nWhen performing mappings, you should set application name to be the full class "
121:                        + "\nname of the implementation class of MailMessageHandler interface."
122:                        + "\n"
123:                        + "\nTo be able to work with our DefaultMailMessageHandler, you must define some "
124:                        + "\nproperties, and here is a section from shark's configuration file \"Shark.conf\" "
125:                        + "\nthat defines these properties:"
126:                        + "\n# the parameters for retrieving mails, possible values for protocol are \"pop3\" and \"imap\""
127:                        + "\nDefaultMailMessageHandler.IncomingMailServer=someserver.co.yu"
128:                        + "\nDefaultMailMessageHandler.IncomingMailProtocol=pop3"
129:                        + "\nDefaultMailMessageHandler.StoreFolderName=INBOX"
130:                        + "\nDefaultMailMessageHandler.IMAPPortNo=143"
131:                        + "\nDefaultMailMessageHandler.POP3PortNo=110"
132:                        + "\n"
133:                        + "\n# the parameters for sending mails"
134:                        + "\nDefaultMailMessageHandler.SMTPMailServer=someserver.co.yu"
135:                        + "\nDefaultMailMessageHandler.SMTPPortNo=25"
136:                        + "\nDefaultMailMessageHandler.SourceAddress=shark@objectweb.org"
137:                        + "\n"
138:                        + "\n# credentials"
139:                        + "\nDefaultMailMessageHandler.Login=shark"
140:                        + "\nDefaultMailMessageHandler.Password=sharkspwd"
141:                        + "\n"
142:                        + "\nThis tool agent is able to understand the extended attributes with the following names:"
143:                        + "\n     * AppName - value of this attribute should represent the full class name of "
144:                        + "\n                 MailMessageHandler interface implementation that will handle mails"
145:                        + "\n     * AppMode - value of this attribute should represent the mode of execution, "
146:                        + "\n                 if set to 0 (zero), tool agent will send mails, and if set to 1 it "
147:                        + "\n                 will receive mails"
148:                        + "\n"
149:                        + "\n NOTE: Tool agent will read extended attributes only if they are called through"
150:                        + "\n       Default tool agent (not by shark directly) and this is the case when information "
151:                        + "\n       on which tool agent to start for XPDL application definition is not contained in mappings";
152:                return i;
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.