Source Code Cross Referenced for Jabber.java in  » Workflow-Engines » bonita-v3.1 » hero » ra » jabber » 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 » bonita v3.1 » hero.ra.jabber 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package hero.ra.jabber;
002:
003:        /**
004:         *
005:         * Bonita
006:         * Copyright (C) 1999 Bull S.A.
007:         * Bull 68 route de versailles  78434 Louveciennes Cedex France
008:         * Further information: bonita@objectweb.org
009:         *
010:         * This library is free software; you can redistribute it and/or
011:         * modify it under the terms of the GNU Lesser General Public
012:         * License as published by the Free Software Foundation; either
013:         * version 2.1 of the License, or any later version.
014:         *
015:         * This library is distributed in the hope that it will be useful,
016:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
017:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
018:         * Lesser General Public License for more details.
019:         *
020:         * You should have received a copy of the GNU Lesser General Public
021:         * License along with this library; if not, write to the Free Software
022:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
023:         * USA
024:         *
025:         *
026:         --------------------------------------------------------------------------
027:         * $Id$
028:         *
029:         --------------------------------------------------------------------------
030:         */
031:
032:        import com.echomine.jabber.*;
033:        import com.echomine.net.*;
034:
035:        import java.util.HashMap;
036:        import java.util.List;
037:
038:        import javax.management.MBeanServer;
039:        import javax.management.MBeanServerFactory;
040:        import javax.management.ObjectName;
041:
042:        import hero.ra.BonitaService;
043:
044:        public class Jabber implements  BonitaService, JabberMBean {
045:            /** Password used for the Jabber session */
046:            private String password = null;
047:
048:            /** Port used for the Jabber session */
049:            private int port = 0;
050:
051:            /** Host used for the Jabber session */
052:            private String host = null;
053:
054:            /** Jabber Session */
055:            private JabberSession jabberSession;
056:
057:            /** Jabber Context */
058:            private JabberContext jabberContext;
059:
060:            /** User name used for the Jabber session */
061:            private String user = null;
062:
063:            /**
064:             * Connects to the Jabber server based on User, Password, Host and Port
065:             * class attributes.
066:             */
067:            private void connect() {
068:                // Initialize the Jabber context
069:                jabberContext = new JabberContext(user, password, host);
070:
071:                // Create an instance of the Jabber session factory
072:                com.echomine.jabber.Jabber jabber = new com.echomine.jabber.Jabber();
073:
074:                // Create the new session
075:                jabberSession = jabber.createSession(jabberContext);
076:
077:                // Connect to the server
078:                try {
079:                    jabberSession.connect(host, port);
080:                } catch (Exception e) {
081:                    System.err.println(" Jabber service -> Connection Failed:"
082:                            + e.getMessage());
083:                }
084:
085:                // Connect to the Jabber server
086:                try {
087:                    jabberSession.getUserService().login();
088:                } catch (Exception e) {
089:                    System.err.println(" Jabber service -> Login Failed:"
090:                            + e.getMessage());
091:                }
092:
093:            }
094:
095:            /**
096:             * Invoked when the service is stopped
097:             */
098:            public void stopService() {
099:                /*
100:                 * The session may is null when the Jabber feature is turned off or if
101:                 * a problem occured during initialization
102:                 */
103:                if (jabberSession != null) {
104:                    try {
105:                        jabberSession.disconnect();
106:                    } catch (Exception e) {
107:                        System.err
108:                                .println(" Jabber service -> Disconnect Failed:"
109:                                        + e.getMessage());
110:                    }
111:
112:                    jabberSession = null;
113:                }
114:            }
115:
116:            /**
117:             * Invoked when the service is started
118:             */
119:            public void startService() throws Exception {
120:                // Retrieve the MBean Server
121:                ObjectName confObjName = new ObjectName(
122:                        "bonita:type=bonitaservice,name=Config");
123:                List list = MBeanServerFactory.findMBeanServer(null);
124:                MBeanServer mServer = (MBeanServer) list.iterator().next();
125:
126:                /*
127:                 * MBean Attributes are retrieved by name so that Configuration classes
128:                 * do not need to be packaged in the RAR.
129:                 */
130:                boolean enabled = ((Boolean) mServer.getAttribute(confObjName,
131:                        "JabberEnabled")).booleanValue();
132:
133:                // If the configuration indicates that the Jabber feature is on
134:                if (enabled) {
135:                    // Retrieve configuration attributes.
136:                    password = (String) mServer.getAttribute(confObjName,
137:                            "JabberPassword");
138:                    port = ((Integer) mServer.getAttribute(confObjName,
139:                            "JabberPort")).intValue();
140:                    host = (String) mServer.getAttribute(confObjName,
141:                            "JabberHost");
142:                    user = (String) mServer.getAttribute(confObjName,
143:                            "JabberUser");
144:
145:                    // Connect to the Jabber service
146:                    connect();
147:                }
148:            }
149:
150:            /**
151:             * Sends a Jabber message to the specified JID
152:             */
153:            public synchronized boolean sendMessage(String JID,
154:                    String resource, String subject, String messageBody) {
155:                try {
156:                    JabberChatMessage msg = new JabberChatMessage(
157:                            JabberChatMessage.TYPE_NORMAL);
158:                    msg.setSubject(subject);
159:                    msg.setBody(messageBody);
160:                    msg.setTo(JID);
161:                    jabberSession.sendMessage(msg);
162:                    return true;
163:                } catch (Exception e) {
164:                    System.err
165:                            .println(" Jabber service -> Send Message Failed:"
166:                                    + e.getMessage());
167:                }
168:
169:                return false;
170:            }
171:
172:            /**
173:             * Registers a new user to Jabber server
174:             */
175:            public synchronized boolean registerUser(String login,
176:                    String password, String email, String name) {
177:                boolean status = true;
178:                jabberSession.disconnect();
179:                com.echomine.jabber.Jabber jabber = new com.echomine.jabber.Jabber();
180:                JabberSession session = jabber.createSession(jabberContext);
181:
182:                try {
183:                    session.connect(host, port);
184:                    HashMap fields = new HashMap();
185:                    fields.put("username", login);
186:                    fields.put("password", password);
187:                    fields.put("email", email);
188:                    fields.put("name", name);
189:
190:                    try {
191:                        session.getUserService().register(
192:                                jabberContext.getServerName(), fields);
193:                    } catch (JabberMessageException ex) {
194:                        status = false;
195:                        System.err.println(" Jabber service ->" + ex);
196:                    }
197:
198:                    session.disconnect();
199:                    connect();
200:                    return status;
201:                } catch (Exception e) {
202:                    System.err.println(" Jabber service ->" + e);
203:                }
204:
205:                connect();
206:
207:                return false;
208:            }
209:
210:            /**
211:             * Add to Roster
212:             */
213:            public synchronized boolean addToRoster(String login,
214:                    String password, String contactJID, String contactName,
215:                    String contactGroup) {
216:                boolean status = true;
217:                jabberSession.disconnect();
218:                com.echomine.jabber.Jabber jabber = new com.echomine.jabber.Jabber();
219:                JabberContext context = new JabberContext(login, password, host);
220:                JabberSession session = jabber.createSession(context);
221:
222:                try {
223:                    session.connect(host, port);
224:                    session.getUserService().login();
225:
226:                    try {
227:                        session.getRosterService().addToRoster(contactJID,
228:                                contactName, contactGroup, true);
229:                        session.getPresenceService().subscribe(contactJID);
230:                    } catch (Exception ex) {
231:                        status = false;
232:                        System.err.println(" Jabber service ->" + ex);
233:                    }
234:
235:                    session.disconnect();
236:                    connect();
237:
238:                    return status;
239:                } catch (Exception e) {
240:                    System.err.println(" Jabber service ->" + e);
241:                }
242:
243:                connect();
244:                return false;
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.