KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > event > XMPPBridgeFactory


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20 package org.apache.cayenne.event;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import org.apache.cayenne.CayenneRuntimeException;
26
27 /**
28  * A factory of XMPPBridge. Note that to deploy an XMPPBridge, you need to have
29  * <em>smack.jar</em> library in the runtime.
30  *
31  * @since 1.2
32  * @author Andrus Adamchik
33  */

34 public class XMPPBridgeFactory implements EventBridgeFactory {
35
36     public static final String JavaDoc XMPP_HOST_PROPERTY = "cayenne.XMPPBridge.xmppHost";
37
38     /**
39      * An optional property, port 5222 is used as default XMPP port.
40      */

41     public static final String JavaDoc XMPP_PORT_PROPERTY = "cayenne.XMPPBridge.xmppPort";
42
43     /**
44      * An optional property, "conference" is used as default chat service.
45      */

46     public static final String JavaDoc XMPP_CHAT_SERVICE_PROPERTY = "cayenne.XMPPBridge.xmppChatService";
47
48     public static final String JavaDoc XMPP_SECURE_CONNECTION_PROPERTY = "cayenne.XMPPBridge.xmppSecure";
49     public static final String JavaDoc XMPP_LOGIN_PROPERTY = "cayenne.XMPPBridge.xmppLogin";
50     public static final String JavaDoc XMPP_PASSWORD_PROPERTY = "cayenne.XMPPBridge.xmppPassword";
51
52     public EventBridge createEventBridge(
53             Collection JavaDoc localSubjects,
54             String JavaDoc externalSubject,
55             Map JavaDoc properties) {
56
57         String JavaDoc chatService = (String JavaDoc) properties.get(XMPP_CHAT_SERVICE_PROPERTY);
58         String JavaDoc host = (String JavaDoc) properties.get(XMPP_HOST_PROPERTY);
59
60         String JavaDoc loginId = (String JavaDoc) properties.get(XMPP_LOGIN_PROPERTY);
61         String JavaDoc password = (String JavaDoc) properties.get(XMPP_PASSWORD_PROPERTY);
62
63         String JavaDoc secureConnectionString = (String JavaDoc) properties
64                 .get(XMPP_SECURE_CONNECTION_PROPERTY);
65         boolean secureConnection = "true".equalsIgnoreCase(secureConnectionString);
66
67         String JavaDoc portString = (String JavaDoc) properties.get(XMPP_PORT_PROPERTY);
68         int port = -1;
69         if (portString != null) {
70
71             try {
72                 port = Integer.parseInt(portString);
73             }
74             catch (NumberFormatException JavaDoc e) {
75                 throw new CayenneRuntimeException("Invalid port: " + portString);
76             }
77         }
78
79         XMPPBridge bridge = new XMPPBridge(localSubjects, externalSubject);
80
81         bridge.setXmppHost(host);
82         bridge.setXmppPort(port);
83         bridge.setChatService(chatService);
84         bridge.setSecureConnection(secureConnection);
85         bridge.setLoginId(loginId);
86         bridge.setPassword(password);
87
88         return bridge;
89     }
90 }
91
Popular Tags