Commit d0b565b4 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Lots of code cleanup. Removal of Serialization. Filled in versions.txt.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4409 b35dd754-fafc-0310-a699-88a17e54d16e
parent 88bfdf89
...@@ -18,7 +18,6 @@ import org.xmpp.packet.Packet; ...@@ -18,7 +18,6 @@ import org.xmpp.packet.Packet;
* underlying implementation, providing translation if necessary. * underlying implementation, providing translation if necessary.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public interface Endpoint { public interface Endpoint {
......
...@@ -16,11 +16,10 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -16,11 +16,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @author Noah Campbell * @author Noah Campbell
*/ */
public class EndpointValve { public class EndpointValve {
/** The valve handle. */ /** The valve handle. */
private final AtomicBoolean open; private final AtomicBoolean open;
/** /**
* Construct a new <code>EndpointValve</code>. The valve is closed by * Construct a new <code>EndpointValve</code>. The valve is closed by
* default. * default.
...@@ -28,7 +27,7 @@ public class EndpointValve { ...@@ -28,7 +27,7 @@ public class EndpointValve {
public EndpointValve() { public EndpointValve() {
this(false); this(false);
} }
/** /**
* Construct a new <code>EndpointValve</code>. * Construct a new <code>EndpointValve</code>.
* *
...@@ -38,27 +37,25 @@ public class EndpointValve { ...@@ -38,27 +37,25 @@ public class EndpointValve {
this.open = new AtomicBoolean(open); this.open = new AtomicBoolean(open);
} }
/** /**
* @return open If the valve is open or not. * @return open If the valve is open or not.
*/ */
public boolean isOpen() { public boolean isOpen() {
return this.open.get(); return this.open.get();
} }
/** /**
* Open the valve and let any pending message get processed. * Open the valve and let any pending message get processed.
*/ */
public void open() { public void open() {
this.open.set(true); this.open.set(true);
} }
/** /**
* Close the valve and queue any new messeages destine for the endpoint. * Close the valve and queue any new messeages destine for the endpoint.
*/ */
public void close() { public void close() {
this.open.set(false); this.open.set(false);
} }
} }
...@@ -16,7 +16,6 @@ import org.xmpp.packet.JID; ...@@ -16,7 +16,6 @@ import org.xmpp.packet.JID;
* A gateway to an external or legacy messaging system. * A gateway to an external or legacy messaging system.
* *
* @author ncampbell * @author ncampbell
* @version 1.0
*/ */
public interface Gateway extends Endpoint { public interface Gateway extends Endpoint {
...@@ -44,30 +43,31 @@ public interface Gateway extends Endpoint { ...@@ -44,30 +43,31 @@ public interface Gateway extends Endpoint {
* @return domain * @return domain
*/ */
public String getDomain(); public String getDomain();
/** /**
* Lookup a contact name for the JID * Lookup a contact name for the JID
* @param jid The jabber id * @param jid The jabber id
* @return contact The legacy name * @return contact The legacy name
*/ */
public String whois(JID jid); public String whois(JID jid);
/** /**
* Lookup a JID for a legacy contact name * Lookup a JID for a legacy contact name
* @param contact The name of legacy contact * @param contact The name of legacy contact
* @return JID * @return JID
*/ */
public JID whois(String contact); public JID whois(String contact);
/** /**
* The JID of the gateway * The JID of the gateway
* @return JID * @return JID
*/ */
public JID getJID(); public JID getJID();
/** /**
* Return the session gateway for this gateway * Return the session gateway for this gateway
* @return SessionFactory * @return SessionFactory
*/ */
public SessionFactory getSessionFactory(); public SessionFactory getSessionFactory();
} }
...@@ -27,6 +27,7 @@ import java.util.Hashtable; ...@@ -27,6 +27,7 @@ import java.util.Hashtable;
* @author Daniel Henninger * @author Daniel Henninger
*/ */
public class GatewayPlugin implements Plugin { public class GatewayPlugin implements Plugin {
/** /**
* Represents all configured gateway handlers. * Represents all configured gateway handlers.
*/ */
...@@ -102,4 +103,5 @@ public class GatewayPlugin implements Plugin { ...@@ -102,4 +103,5 @@ public class GatewayPlugin implements Plugin {
gwInstance.stopInstance(); gwInstance.stopInstance();
} }
} }
} }
...@@ -49,7 +49,7 @@ public interface GatewaySession { ...@@ -49,7 +49,7 @@ public interface GatewaySession {
* @return boolean * @return boolean
*/ */
public boolean isConnected(); public boolean isConnected();
/** /**
* Returns all sessions associated with this session/login. * Returns all sessions associated with this session/login.
* *
...@@ -57,7 +57,7 @@ public interface GatewaySession { ...@@ -57,7 +57,7 @@ public interface GatewaySession {
* @see java.util.List * @see java.util.List
*/ */
public List<ForeignContact> getContacts(); public List<ForeignContact> getContacts();
/** /**
* Return the endpoint for the legacy system. * Return the endpoint for the legacy system.
* *
...@@ -65,7 +65,7 @@ public interface GatewaySession { ...@@ -65,7 +65,7 @@ public interface GatewaySession {
* @return Endpoint legacy endpoint. * @return Endpoint legacy endpoint.
*/ */
public Endpoint getLegacyEndpoint(); public Endpoint getLegacyEndpoint();
/** /**
* Get the Jabber endpoint. * Get the Jabber endpoint.
* *
...@@ -89,7 +89,7 @@ public interface GatewaySession { ...@@ -89,7 +89,7 @@ public interface GatewaySession {
* @return status The status for the particular JID. * @return status The status for the particular JID.
*/ */
public String getStatus(JID id); public String getStatus(JID id);
/** /**
* Add a contact to this session. This method will typically update the * Add a contact to this session. This method will typically update the
* roster on the legacy system. * roster on the legacy system.
...@@ -99,7 +99,7 @@ public interface GatewaySession { ...@@ -99,7 +99,7 @@ public interface GatewaySession {
* @see org.xmpp.packet.JID * @see org.xmpp.packet.JID
*/ */
public void addContact(JID jid) throws Exception; public void addContact(JID jid) throws Exception;
/** /**
* Remove a contact from this session. This will typically update the * Remove a contact from this session. This will typically update the
* roster on the legacy system. * roster on the legacy system.
...@@ -109,7 +109,7 @@ public interface GatewaySession { ...@@ -109,7 +109,7 @@ public interface GatewaySession {
* @see org.xmpp.packet.JID * @see org.xmpp.packet.JID
*/ */
public void removeContact(JID jid) throws Exception; public void removeContact(JID jid) throws Exception;
/** /**
* Sets the XMPP Server endpoint. * Sets the XMPP Server endpoint.
* *
...@@ -117,7 +117,7 @@ public interface GatewaySession { ...@@ -117,7 +117,7 @@ public interface GatewaySession {
* @see org.jivesoftware.wildfire.gateway.Endpoint * @see org.jivesoftware.wildfire.gateway.Endpoint
*/ */
public void setJabberEndpoint(Endpoint jabberEndpoint); public void setJabberEndpoint(Endpoint jabberEndpoint);
/** /**
* Get the gateway that is associated with this session. Every session * Get the gateway that is associated with this session. Every session
* has an orinating gateway from which is was created. * has an orinating gateway from which is was created.
...@@ -127,7 +127,6 @@ public interface GatewaySession { ...@@ -127,7 +127,6 @@ public interface GatewaySession {
*/ */
public Gateway getGateway(); public Gateway getGateway();
/** /**
* The session will return a foreign contact identified by the JID. If it * The session will return a foreign contact identified by the JID. If it
* does not exist then an exception will be thrown. The Session is responsible * does not exist then an exception will be thrown. The Session is responsible
...@@ -139,4 +138,5 @@ public interface GatewaySession { ...@@ -139,4 +138,5 @@ public interface GatewaySession {
* @throws UnknownForeignContactException * @throws UnknownForeignContactException
*/ */
public ForeignContact getContact(JID to) throws UnknownForeignContactException; public ForeignContact getContact(JID to) throws UnknownForeignContactException;
} }
...@@ -57,4 +57,5 @@ public enum GatewayType { ...@@ -57,4 +57,5 @@ public enum GatewayType {
* A gateway to a service not covered by the other options.. * A gateway to a service not covered by the other options..
*/ */
other other
}
\ No newline at end of file }
...@@ -24,7 +24,6 @@ import org.xmpp.packet.Packet; ...@@ -24,7 +24,6 @@ import org.xmpp.packet.Packet;
* XMPP server. * XMPP server.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class JabberEndpoint implements Endpoint { public class JabberEndpoint implements Endpoint {
...@@ -73,20 +72,21 @@ public class JabberEndpoint implements Endpoint { ...@@ -73,20 +72,21 @@ public class JabberEndpoint implements Endpoint {
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet) * @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/ */
public void sendPacket(Packet packet) throws ComponentException { public void sendPacket(Packet packet) throws ComponentException {
if(valve.isOpen()) { if (valve.isOpen()) {
/** /**
* Push all pending packets to the XMPP Server. * Push all pending packets to the XMPP Server.
*/ */
while(!queue.isEmpty()) { while (!queue.isEmpty()) {
this.componentManager.sendPacket(this.component, queue.poll()); this.componentManager.sendPacket(this.component, queue.poll());
} }
this.componentManager.sendPacket(this.component, packet); this.componentManager.sendPacket(this.component, packet);
} else { }
else {
queue.add(packet); queue.add(packet);
logger.log(Level.FINE, "jabberendpoint.sendpacketenqueue", packet.getFrom()); logger.log(Level.FINE, "jabberendpoint.sendpacketenqueue", packet.getFrom());
} }
} }
/** The backlog queue. */ /** The backlog queue. */
private final ConcurrentLinkedQueue<Packet> queue = new ConcurrentLinkedQueue<Packet>(); private final ConcurrentLinkedQueue<Packet> queue = new ConcurrentLinkedQueue<Packet>();
......
...@@ -14,10 +14,9 @@ package org.jivesoftware.wildfire.gateway; ...@@ -14,10 +14,9 @@ package org.jivesoftware.wildfire.gateway;
* {@code SessionFactory} is used to generate a new {@code GatewaySession}. * {@code SessionFactory} is used to generate a new {@code GatewaySession}.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public interface SessionFactory { public interface SessionFactory {
/** /**
* Return a new instance of a {@code GatewaySession}. * Return a new instance of a {@code GatewaySession}.
* *
...@@ -25,4 +24,5 @@ public interface SessionFactory { ...@@ -25,4 +24,5 @@ public interface SessionFactory {
* @return gatewaySession The gateway session. * @return gatewaySession The gateway session.
*/ */
public GatewaySession newInstance(SubscriptionInfo info); public GatewaySession newInstance(SubscriptionInfo info);
}
\ No newline at end of file }
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
package org.jivesoftware.wildfire.gateway; package org.jivesoftware.wildfire.gateway;
import java.io.Serializable;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/** /**
...@@ -22,8 +20,8 @@ import org.xmpp.packet.JID; ...@@ -22,8 +20,8 @@ import org.xmpp.packet.JID;
* *
* @author Noah Campbell * @author Noah Campbell
*/ */
public class SubscriptionInfo implements Serializable { public class SubscriptionInfo {
/** /**
* Construct a new <code>SubscriptionInfo</code> * Construct a new <code>SubscriptionInfo</code>
* @param username The username * @param username The username
...@@ -33,27 +31,27 @@ public class SubscriptionInfo implements Serializable { ...@@ -33,27 +31,27 @@ public class SubscriptionInfo implements Serializable {
this.username = username; this.username = username;
this.password = password; this.password = password;
} }
/** /**
* Has the session been registered on the client? * Has the session been registered on the client?
*/ */
public boolean clientRegistered; public boolean clientRegistered;
/** /**
* Has the server registered with the client? * Has the server registered with the client?
*/ */
public boolean serverRegistered; public boolean serverRegistered;
/** /**
* The username. * The username.
*/ */
public String username; public String username;
/** /**
* The password. * The password.
*/ */
public String password; public String password;
/** /**
* The jid. * The jid.
* *
...@@ -61,4 +59,4 @@ public class SubscriptionInfo implements Serializable { ...@@ -61,4 +59,4 @@ public class SubscriptionInfo implements Serializable {
*/ */
public transient JID jid; public transient JID jid;
} }
\ No newline at end of file
...@@ -24,6 +24,7 @@ import org.xmpp.packet.Packet; ...@@ -24,6 +24,7 @@ import org.xmpp.packet.Packet;
* @author Daniel Henninger * @author Daniel Henninger
*/ */
public class OSCARGateway extends BaseGateway { public class OSCARGateway extends BaseGateway {
/* Gateway Name String */ /* Gateway Name String */
private static String NameString = "oscar"; private static String NameString = "oscar";
...@@ -69,4 +70,5 @@ public class OSCARGateway extends BaseGateway { ...@@ -69,4 +70,5 @@ public class OSCARGateway extends BaseGateway {
Log.debug("Getting session instance"); Log.debug("Getting session instance");
return new OSCARGatewaySession(info, this); return new OSCARGatewaySession(info, this);
} }
} }
/**
* $Revision$
* $Date$
*
* Copyright (C) 2006 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.wildfire.gateway.protocols.oscar; package org.jivesoftware.wildfire.gateway.protocols.oscar;
import java.util.ArrayList; import java.util.ArrayList;
......
...@@ -29,20 +29,12 @@ import ymsg.network.event.SessionNotifyEvent; ...@@ -29,20 +29,12 @@ import ymsg.network.event.SessionNotifyEvent;
* for the ymsg9 library. * for the ymsg9 library.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class NoopSessionListener implements SessionListener { public class NoopSessionListener implements SessionListener {
/** The logger. @see java.util.logging.Logger */ /** The logger. @see java.util.logging.Logger */
private static final Logger logger = Logger.getLogger("NoopSessionListener"); private static final Logger logger = Logger.getLogger("NoopSessionListener");
/**
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
*/
/**
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
*/
/** /**
* @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent) * @see ymsg.network.event.SessionListener#fileTransferReceived(ymsg.network.event.SessionFileTransferEvent)
*/ */
...@@ -55,7 +47,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -55,7 +47,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void connectionClosed(SessionEvent arg0) { public void connectionClosed(SessionEvent arg0) {
logger.info(arg0.toString()); logger.info(arg0.toString());
} }
/** /**
...@@ -63,7 +54,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -63,7 +54,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void listReceived(SessionEvent arg0) { public void listReceived(SessionEvent arg0) {
logger.info(arg0.toString()); logger.info(arg0.toString());
} }
/** /**
...@@ -71,7 +61,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -71,7 +61,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void messageReceived(SessionEvent arg0) { public void messageReceived(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -79,7 +68,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -79,7 +68,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void buzzReceived(SessionEvent arg0) { public void buzzReceived(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -87,7 +75,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -87,7 +75,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void offlineMessageReceived(SessionEvent arg0) { public void offlineMessageReceived(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -95,7 +82,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -95,7 +82,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void errorPacketReceived(SessionErrorEvent arg0) { public void errorPacketReceived(SessionErrorEvent arg0) {
logger.severe(arg0.toString()); logger.severe(arg0.toString());
} }
/** /**
...@@ -111,7 +97,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -111,7 +97,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void newMailReceived(SessionNewMailEvent arg0) { public void newMailReceived(SessionNewMailEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -119,7 +104,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -119,7 +104,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void notifyReceived(SessionNotifyEvent arg0) { public void notifyReceived(SessionNotifyEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -127,7 +111,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -127,7 +111,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void contactRequestReceived(SessionEvent arg0) { public void contactRequestReceived(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -135,7 +118,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -135,7 +118,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void contactRejectionReceived(SessionEvent arg0) { public void contactRejectionReceived(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -143,7 +125,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -143,7 +125,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void conferenceInviteReceived(SessionConferenceEvent arg0) { public void conferenceInviteReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -151,7 +132,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -151,7 +132,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void conferenceInviteDeclinedReceived(SessionConferenceEvent arg0) { public void conferenceInviteDeclinedReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -159,18 +139,13 @@ public class NoopSessionListener implements SessionListener { ...@@ -159,18 +139,13 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void conferenceLogonReceived(SessionConferenceEvent arg0) { public void conferenceLogonReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/
/** /**
* @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent) * @see ymsg.network.event.SessionListener#conferenceLogoffReceived(ymsg.network.event.SessionConferenceEvent)
*/ */
public void conferenceLogoffReceived(SessionConferenceEvent arg0) { public void conferenceLogoffReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -178,7 +153,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -178,7 +153,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void conferenceMessageReceived(SessionConferenceEvent arg0) { public void conferenceMessageReceived(SessionConferenceEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -186,7 +160,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -186,7 +160,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void friendsUpdateReceived(SessionFriendEvent arg0) { public void friendsUpdateReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -194,7 +167,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -194,7 +167,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void friendAddedReceived(SessionFriendEvent arg0) { public void friendAddedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -202,7 +174,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -202,7 +174,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void friendRemovedReceived(SessionFriendEvent arg0) { public void friendRemovedReceived(SessionFriendEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -210,7 +181,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -210,7 +181,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void chatLogonReceived(SessionChatEvent arg0) { public void chatLogonReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -218,7 +188,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -218,7 +188,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void chatLogoffReceived(SessionChatEvent arg0) { public void chatLogoffReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -226,7 +195,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -226,7 +195,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void chatMessageReceived(SessionChatEvent arg0) { public void chatMessageReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -234,7 +202,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -234,7 +202,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void chatUserUpdateReceived(SessionChatEvent arg0) { public void chatUserUpdateReceived(SessionChatEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
/** /**
...@@ -242,6 +209,6 @@ public class NoopSessionListener implements SessionListener { ...@@ -242,6 +209,6 @@ public class NoopSessionListener implements SessionListener {
*/ */
public void chatConnectionClosed(SessionEvent arg0) { public void chatConnectionClosed(SessionEvent arg0) {
logger.finest(arg0.toString()); logger.finest(arg0.toString());
} }
} }
...@@ -24,19 +24,12 @@ import ymsg.network.YahooUser; ...@@ -24,19 +24,12 @@ import ymsg.network.YahooUser;
/** /**
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class YahooForeignContact extends AbstractForeignContact { public class YahooForeignContact extends AbstractForeignContact {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The yahoo user. */ /** The yahoo user. */
final private YahooUser user; final private YahooUser user;
/** /**
* Construct a new <code>YahooForeignContact</code>. * Construct a new <code>YahooForeignContact</code>.
* @param user A YahooUser * @param user A YahooUser
...@@ -57,7 +50,6 @@ public class YahooForeignContact extends AbstractForeignContact { ...@@ -57,7 +50,6 @@ public class YahooForeignContact extends AbstractForeignContact {
} }
/** /**
* @param user2 * @param user2
* @return * @return
...@@ -65,39 +57,69 @@ public class YahooForeignContact extends AbstractForeignContact { ...@@ -65,39 +57,69 @@ public class YahooForeignContact extends AbstractForeignContact {
private Status getStatusMessage(YahooUser user2, Status status) { private Status getStatusMessage(YahooUser user2, Status status) {
long id = user2.getStatus(); long id = user2.getStatus();
status.setOnline(true); status.setOnline(true);
if( StatusConstants.STATUS_AVAILABLE == id) { status.updateValue( resource.getString("STATUS_AVAILABLE" )); if (StatusConstants.STATUS_AVAILABLE == id) {
} else if( StatusConstants.STATUS_BRB == id) { status.updateValue( resource.getString("STATUS_BRB " )); status.updateValue(resource.getString("STATUS_AVAILABLE"));
} else if( StatusConstants.STATUS_BUSY == id) { status.updateValue( resource.getString("STATUS_BUSY" )); }
} else if( StatusConstants.STATUS_NOTATHOME == id) { status.updateValue( resource.getString("STATUS_NOTATHOME" )); else if (StatusConstants.STATUS_BRB == id) {
} else if( StatusConstants.STATUS_NOTATDESK == id) { status.updateValue( resource.getString("STATUS_NOTATDESK" )); status.updateValue(resource.getString("STATUS_BRB"));
} else if( StatusConstants.STATUS_NOTINOFFICE == id) { status.updateValue( resource.getString("STATUS_NOTINOFFICE" )); }
} else if( StatusConstants.STATUS_ONPHONE == id) { status.updateValue( resource.getString("STATUS_ONPHONE" )); else if (StatusConstants.STATUS_BUSY == id) {
} else if( StatusConstants.STATUS_ONVACATION == id) { status.updateValue( resource.getString("STATUS_ONVACATION" )); status.updateValue(resource.getString("STATUS_BUSY"));
} else if( StatusConstants.STATUS_OUTTOLUNCH == id) { status.updateValue( resource.getString("STATUS_OUTTOLUNCH" )); }
} else if( StatusConstants.STATUS_STEPPEDOUT == id) { status.updateValue( resource.getString("STATUS_STEPPEDOUT" )); else if (StatusConstants.STATUS_NOTATHOME == id) {
} else if( StatusConstants.STATUS_INVISIBLE == id) { status.updateValue( resource.getString("STATUS_INVISIBLE" )); status.updateValue(resource.getString("STATUS_NOTATHOME"));
} else if( StatusConstants.STATUS_BAD == id) { status.updateValue( resource.getString("STATUS_BAD" )); // Bad login? }
} else if( StatusConstants.STATUS_LOCKED == id) { status.updateValue( resource.getString("STATUS_LOCKED" )); // You've been naughty else if (StatusConstants.STATUS_NOTATDESK == id) {
} else if( StatusConstants.STATUS_CUSTOM == id) { status.updateValue( user.getCustomStatusMessage() ); status.updateValue(resource.getString("STATUS_NOTATDESK"));
} else if( StatusConstants.STATUS_IDLE == id) { status.updateValue( resource.getString("STATUS_IDLE" )); }
} else if( StatusConstants.STATUS_OFFLINE == id) { status.setOnline(false); else if (StatusConstants.STATUS_NOTINOFFICE == id) {
} else if( StatusConstants.STATUS_TYPING == id) { status.updateValue( resource.getString("STATUS_TYPING" )); status.updateValue(resource.getString("STATUS_NOTINOFFICE"));
}
} else { else if (StatusConstants.STATUS_ONPHONE == id) {
logger.log(Level.WARNING, "yahooforeigncontact.unabletolocatestatus"); status.updateValue(resource.getString("STATUS_ONPHONE"));
status.updateValue( "????" ); }
else if (StatusConstants.STATUS_ONVACATION == id) {
status.updateValue(resource.getString("STATUS_ONVACATION"));
}
else if (StatusConstants.STATUS_OUTTOLUNCH == id) {
status.updateValue(resource.getString("STATUS_OUTTOLUNCH"));
}
else if (StatusConstants.STATUS_STEPPEDOUT == id) {
status.updateValue(resource.getString("STATUS_STEPPEDOUT"));
} }
else if (StatusConstants.STATUS_INVISIBLE == id) {
status.updateValue(resource.getString("STATUS_INVISIBLE"));
else if (StatusConstants.STATUS_BAD == id) {
status.updateValue(resource.getString("STATUS_BAD")); // Bad login?
}
else if (StatusConstants.STATUS_LOCKED == id) {
status.updateValue(resource.getString("STATUS_LOCKED")); // You've been naughty
}
else if (StatusConstants.STATUS_CUSTOM == id) {
status.updateValue(user.getCustomStatusMessage());
}
else if (StatusConstants.STATUS_IDLE == id) {
status.updateValue(resource.getString("STATUS_IDLE"));
}
else if (StatusConstants.STATUS_OFFLINE == id) {
status.setOnline(false);
}
else if (StatusConstants.STATUS_TYPING == id) {
status.updateValue(resource.getString("STATUS_TYPING"));
}
else {
logger.log(Level.WARNING, "yahooforeigncontact.unabletolocatestatus");
status.updateValue("????");
}
return status; return status;
} }
/** The logger. */ /** The logger. */
final static private Logger logger = Logger.getLogger("yahooforeigncontact", final static private Logger logger = Logger.getLogger("yahooforeigncontact",
"gateway_i18n"); "gateway_i18n");
/** The resource. */ /** The resource. */
private static ResourceBundle resource = PropertyResourceBundle.getBundle("yahoostatus"); private static ResourceBundle resource = PropertyResourceBundle.getBundle("yahoostatus");
......
...@@ -22,14 +22,12 @@ import org.xmpp.packet.Packet; ...@@ -22,14 +22,12 @@ import org.xmpp.packet.Packet;
/** /**
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class YahooGateway extends BaseGateway { public class YahooGateway extends BaseGateway {
/** The YAHOO. */ /** The YAHOO. */
private static String YAHOO = "yahoo"; private static String YAHOO = "yahoo";
/** /**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName() * @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/ */
...@@ -53,8 +51,7 @@ public class YahooGateway extends BaseGateway { ...@@ -53,8 +51,7 @@ public class YahooGateway extends BaseGateway {
public String getDescription() { public String getDescription() {
return "Yahoo! Gateway (ymsg9)"; return "Yahoo! Gateway (ymsg9)";
} }
/** The logger. @see java.util.logging.Logger */ /** The logger. @see java.util.logging.Logger */
static public final Logger logger = Logger.getLogger("YahooGateway"); static public final Logger logger = Logger.getLogger("YahooGateway");
...@@ -101,4 +98,5 @@ public class YahooGateway extends BaseGateway { ...@@ -101,4 +98,5 @@ public class YahooGateway extends BaseGateway {
protected GatewaySession getSessionInstance(SubscriptionInfo info) { protected GatewaySession getSessionInstance(SubscriptionInfo info) {
return new YahooGatewaySession(info, this); return new YahooGatewaySession(info, this);
} }
} }
...@@ -47,29 +47,24 @@ import ymsg.network.YahooUser; ...@@ -47,29 +47,24 @@ import ymsg.network.YahooUser;
* Manages the session to the underlying legacy system. * Manages the session to the underlying legacy system.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class YahooGatewaySession extends AbstractGatewaySession implements Endpoint { public class YahooGatewaySession extends AbstractGatewaySession implements Endpoint {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The logger. */ /** The logger. */
private static Logger logger = Logger.getLogger("YahooGatewaySession", "gateway_i18n"); private static Logger logger = Logger.getLogger("YahooGatewaySession", "gateway_i18n");
/** /**
* Yahoo Session * Yahoo Session
*/ */
public final Session session; public final Session session;
/** /**
* The JID associated with this session. * The JID associated with this session.
* *
* @see org.xmpp.packet.JID * @see org.xmpp.packet.JID
*/ */
private final JID jid; // JID associated with this session private final JID jid; // JID associated with this session
/** /**
* Initialize a new session object for Yahoo! * Initialize a new session object for Yahoo!
* *
...@@ -79,23 +74,20 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -79,23 +74,20 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
public YahooGatewaySession(SubscriptionInfo info, Gateway gateway) { public YahooGatewaySession(SubscriptionInfo info, Gateway gateway) {
super(info, gateway); super(info, gateway);
this.jid = info.jid; this.jid = info.jid;
session = new Session(); session = new Session();
session.addSessionListener(new YahooSessionListener(this)); session.addSessionListener(new YahooSessionListener(this));
} }
/** The attemptingLogin. */ /** The attemptingLogin. */
private boolean attemptingLogin = false; private boolean attemptingLogin = false;
/** The loginFailed. */ /** The loginFailed. */
private boolean loginFailed = false; private boolean loginFailed = false;
/** The loginFailedCount. */ /** The loginFailedCount. */
private int loginFailedCount = 0; private int loginFailedCount = 0;
/** /**
* Manage presense information. * Manage presense information.
*/ */
...@@ -148,7 +140,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -148,7 +140,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
* @throws Exception * @throws Exception
*/ */
public synchronized void login() throws Exception { public synchronized void login() throws Exception {
if(!isConnected() && !loginFailed && !attemptingLogin) { if (!isConnected() && !loginFailed && !attemptingLogin) {
attemptingLogin = true; attemptingLogin = true;
new Thread() { new Thread() {
@Override @Override
...@@ -163,26 +155,26 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -163,26 +155,26 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username}); logger.log(Level.INFO, "yahoogatewaysession.login", new Object[]{jid, getSubscriptionInfo().username});
getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through getJabberEndpoint().getValve().open(); // allow any buffered messages to pass through
// updatePresence(); // updatePresence();
} catch (LoginRefusedException lre) { }
catch (LoginRefusedException lre) {
session.reset(); session.reset();
if( loginFailedCount++ > 3) { if (loginFailedCount++ > 3) {
loginFailed = true; loginFailed = true;
} }
logger.warning("Login failed for " + getSubscriptionInfo().username); logger.warning("Login failed for " + getSubscriptionInfo().username);
}
catch (IOException ioe) {
} catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }
attemptingLogin = false; attemptingLogin = false;
} }
}.run(); // intentionally not forked. }.run(); // intentionally not forked.
} else { }
else {
logger.warning(this.jid + " is already logged in"); logger.warning(this.jid + " is already logged in");
} }
} }
/** /**
* Is the connection connected? * Is the connection connected?
* @return connected is the session connected? * @return connected is the session connected?
...@@ -190,7 +182,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -190,7 +182,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
public boolean isConnected() { public boolean isConnected() {
return session.getSessionStatus() == Session.MESSAGING; return session.getSessionStatus() == Session.MESSAGING;
} }
/** /**
* Logout from Yahoo! * Logout from Yahoo!
* @throws Exception * @throws Exception
...@@ -200,12 +192,14 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -200,12 +192,14 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
session.logout(); session.logout();
session.reset(); session.reset();
} }
/** /**
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
@Override @Override
public String toString() { return "[" + this.getSubscriptionInfo().username + " CR:" + clientRegistered + " SR:" + serverRegistered + "]"; } public String toString() {
return "[" + this.getSubscriptionInfo().username + " CR:" + clientRegistered + " SR:" + serverRegistered + "]";
}
/** /**
* Return the id of this session as a <code>String</code>. * Return the id of this session as a <code>String</code>.
...@@ -224,7 +218,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -224,7 +218,7 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
public List<ForeignContact> getContacts() { public List<ForeignContact> getContacts() {
Map users = session.getUsers(); Map users = session.getUsers();
ArrayList<ForeignContact> contacts = new ArrayList<ForeignContact>(users.size()); ArrayList<ForeignContact> contacts = new ArrayList<ForeignContact>(users.size());
for(YahooUser user : (Collection<YahooUser>)session.getUsers().values()) { for (YahooUser user : (Collection<YahooUser>)session.getUsers().values()) {
contacts.add(new YahooForeignContact(user, this.gateway)); contacts.add(new YahooForeignContact(user, this.gateway));
} }
return contacts; return contacts;
...@@ -255,12 +249,12 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -255,12 +249,12 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
* @return String status of JID * @return String status of JID
*/ */
public String getStatus(JID to) { public String getStatus(JID to) {
Map table = this.session.getUsers(); Map table = this.session.getUsers();
if(isConnected() && table != null && to.getNode() != null && table.containsKey(to.getNode())) { if (isConnected() && table != null && to.getNode() != null && table.containsKey(to.getNode())) {
YahooUser user = this.session.getUser(to.getNode()); YahooUser user = this.session.getUser(to.getNode());
return user.getCustomStatusMessage(); return user.getCustomStatusMessage();
} else { }
else {
return null; return null;
} }
} }
...@@ -294,11 +288,12 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -294,11 +288,12 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
*/ */
public void sendPacket(Packet packet) { public void sendPacket(Packet packet) {
logger.log(Level.FINE, packet.toString()); logger.log(Level.FINE, packet.toString());
if(packet instanceof Message) { if (packet instanceof Message) {
Message m = (Message)packet; Message m = (Message)packet;
try { try {
session.sendMessage(packet.getTo().getNode(), m.getBody()); session.sendMessage(packet.getTo().getNode(), m.getBody());
} catch (IOException ioe) { }
catch (IOException ioe) {
logger.warning(ioe.getLocalizedMessage()); logger.warning(ioe.getLocalizedMessage());
} }
} }
...@@ -309,9 +304,10 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -309,9 +304,10 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
*/ */
public ForeignContact getContact(JID to) throws UnknownForeignContactException { public ForeignContact getContact(JID to) throws UnknownForeignContactException {
String node = to.getNode(); String node = to.getNode();
if(node == null || node.length() == 0) throw new UnknownForeignContactException("invalidnode", node.toString()); if (node == null || node.length() == 0) throw new UnknownForeignContactException("invalidnode", node.toString());
YahooUser user = session.getUser(node); YahooUser user = session.getUser(node);
if(user == null) throw new UnknownForeignContactException("invaliduser"); if (user == null) throw new UnknownForeignContactException("invaliduser");
return new YahooForeignContact(session.getUser(to.getNode()), this.gateway); return new YahooForeignContact(session.getUser(to.getNode()), this.gateway);
} }
} }
...@@ -27,7 +27,6 @@ import ymsg.network.event.SessionNewMailEvent; ...@@ -27,7 +27,6 @@ import ymsg.network.event.SessionNewMailEvent;
* api. * api.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class YahooSessionListener extends NoopSessionListener { public class YahooSessionListener extends NoopSessionListener {
...@@ -35,10 +34,10 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -35,10 +34,10 @@ public class YahooSessionListener extends NoopSessionListener {
* Gateway session associated with this listener. * Gateway session associated with this listener.
*/ */
private YahooGatewaySession gatewaySession; private YahooGatewaySession gatewaySession;
/** The logger. */ /** The logger. */
private static final Logger logger = Logger.getLogger("YahooSessionListener"); private static final Logger logger = Logger.getLogger("YahooSessionListener");
/** /**
* Creates a YahooSessionListener that will translate events from the Yahoo! * Creates a YahooSessionListener that will translate events from the Yahoo!
* connection into XMPP formated packets. * connection into XMPP formated packets.
...@@ -61,7 +60,8 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -61,7 +60,8 @@ public class YahooSessionListener extends NoopSessionListener {
message.setBody("New Mail Received (" + snme.getMailCount() + ")"); message.setBody("New Mail Received (" + snme.getMailCount() + ")");
message.setType(Message.Type.headline); message.setType(Message.Type.headline);
gatewaySession.getJabberEndpoint().sendPacket(message); gatewaySession.getJabberEndpoint().sendPacket(message);
} catch (Exception e) { }
catch (Exception e) {
logger.severe("Unable to send message: " + e.getLocalizedMessage()); logger.severe("Unable to send message: " + e.getLocalizedMessage());
} }
} }
...@@ -81,7 +81,8 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -81,7 +81,8 @@ public class YahooSessionListener extends NoopSessionListener {
message.setFrom(this.gatewaySession.getGateway().whois(sessionEvent.getFrom())); message.setFrom(this.gatewaySession.getGateway().whois(sessionEvent.getFrom()));
gatewaySession.getJabberEndpoint().sendPacket(message); gatewaySession.getJabberEndpoint().sendPacket(message);
logger.fine(message.getElement().asXML()); logger.fine(message.getElement().asXML());
} catch (Exception e) { }
catch (Exception e) {
logger.severe("unable to send message: "+ e.getLocalizedMessage()); logger.severe("unable to send message: "+ e.getLocalizedMessage());
} }
} }
...@@ -93,12 +94,12 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -93,12 +94,12 @@ public class YahooSessionListener extends NoopSessionListener {
public void friendsUpdateReceived(SessionFriendEvent event) { public void friendsUpdateReceived(SessionFriendEvent event) {
try { try {
updateStatus(event); updateStatus(event);
} catch (Exception e) { }
catch (Exception e) {
logger.log(Level.SEVERE, "yahoosessionlistener.friendupdateerror", e.getLocalizedMessage()); logger.log(Level.SEVERE, "yahoosessionlistener.friendupdateerror", e.getLocalizedMessage());
} }
} }
/** /**
* Update a friends status. * Update a friends status.
* *
...@@ -125,7 +126,8 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -125,7 +126,8 @@ public class YahooSessionListener extends NoopSessionListener {
message.setBody(sessionEvent.getMessage()); message.setBody(sessionEvent.getMessage());
message.setFrom(this.gatewaySession.getGateway().whois(sessionEvent.getFrom())); message.setFrom(this.gatewaySession.getGateway().whois(sessionEvent.getFrom()));
gatewaySession.getJabberEndpoint().sendPacket(message); gatewaySession.getJabberEndpoint().sendPacket(message);
} catch (Exception e) { }
catch (Exception e) {
logger.severe("unable to send message: "+ e.getLocalizedMessage()); logger.severe("unable to send message: "+ e.getLocalizedMessage());
} }
} }
...@@ -155,7 +157,5 @@ public class YahooSessionListener extends NoopSessionListener { ...@@ -155,7 +157,5 @@ public class YahooSessionListener extends NoopSessionListener {
// TODO Auto-generated method stub // TODO Auto-generated method stub
super.friendRemovedReceived(arg0); super.friendRemovedReceived(arg0);
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
package org.jivesoftware.wildfire.gateway.roster; package org.jivesoftware.wildfire.gateway.roster;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
...@@ -24,14 +23,9 @@ import org.xmpp.packet.JID; ...@@ -24,14 +23,9 @@ import org.xmpp.packet.JID;
* All maintanence information pretaining to a gateway user. * All maintanence information pretaining to a gateway user.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public abstract class AbstractForeignContact implements Serializable, ForeignContact { public abstract class AbstractForeignContact implements ForeignContact {
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/** /**
* The id for this contact. This maps directly to the legacy userid. * The id for this contact. This maps directly to the legacy userid.
*/ */
...@@ -43,38 +37,38 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -43,38 +37,38 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @see Status * @see Status
*/ */
public final Status status; public final Status status;
/** /**
* The jid associated with this foreign contact. * The jid associated with this foreign contact.
* *
* @see JID * @see JID
*/ */
private transient JID jid; private transient JID jid;
/** /**
* The gatewayDomain. * The gatewayDomain.
*/ */
private final String gatewayDomain; private final String gatewayDomain;
/** /**
* The gatewayName. * The gatewayName.
*/ */
private final String gatewayName; private final String gatewayName;
/** /**
* The associatedSessions that are currently active for this <code>ForeignContact</code>. * The associatedSessions that are currently active for this <code>ForeignContact</code>.
* *
* @see java.util.Set * @see java.util.Set
*/ */
private transient Set<GatewaySession> associatedSessions = new HashSet<GatewaySession>(); private transient Set<GatewaySession> associatedSessions = new HashSet<GatewaySession>();
/** /**
* The format for a JID * The format for a JID
* *
* @see java.text.MessageFormat * @see java.text.MessageFormat
*/ */
private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}"); private static final MessageFormat mf = new MessageFormat("{0}@{1}.{2}");
/** /**
* Create a ForeignContact relating to the gateway it originated from. * Create a ForeignContact relating to the gateway it originated from.
* *
...@@ -93,12 +87,12 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -93,12 +87,12 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getJid() * @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#getJid()
*/ */
public JID getJid() { public JID getJid() {
if(jid == null) { if (jid == null) {
jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain})); jid = new JID(mf.format(new Object[]{id, gatewayName, gatewayDomain}));
} }
return jid; return jid;
} }
/** /**
* @param in * @param in
* @throws IOException * @throws IOException
...@@ -110,28 +104,28 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -110,28 +104,28 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
associatedSessions = new HashSet<GatewaySession>(); associatedSessions = new HashSet<GatewaySession>();
getJid(); getJid();
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#addSession(org.jivesoftware.wildfire.gateway.GatewaySession) * @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#addSession(org.jivesoftware.wildfire.gateway.GatewaySession)
*/ */
public void addSession(GatewaySession session) { public void addSession(GatewaySession session) {
associatedSessions.add(session); associatedSessions.add(session);
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#removeSession(org.jivesoftware.wildfire.gateway.GatewaySession) * @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#removeSession(org.jivesoftware.wildfire.gateway.GatewaySession)
*/ */
public void removeSession(GatewaySession session) { public void removeSession(GatewaySession session) {
associatedSessions.remove(session); associatedSessions.remove(session);
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#isConnected() * @see org.jivesoftware.wildfire.gateway.roster.ForeignContact#isConnected()
*/ */
public boolean isConnected() { public boolean isConnected() {
boolean connected = true; boolean connected = true;
for(GatewaySession session : associatedSessions) { for (GatewaySession session : associatedSessions) {
if(!session.isConnected()) { if (!session.isConnected()) {
connected = false; connected = false;
break; break;
} }
...@@ -144,10 +138,11 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -144,10 +138,11 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof AbstractForeignContact) { if (obj instanceof AbstractForeignContact) {
AbstractForeignContact fc = (AbstractForeignContact)obj; AbstractForeignContact fc = (AbstractForeignContact)obj;
return fc.id.equalsIgnoreCase(this.id); return fc.id.equalsIgnoreCase(this.id);
} else { }
else {
return super.equals(obj); return super.equals(obj);
} }
} }
...@@ -167,7 +162,5 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -167,7 +162,5 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
public String toString() { public String toString() {
return "Foreign Contact: " + this.getJid() + "[Gateway: " + this.gatewayName + ", Connected: " + isConnected() + "]"; return "Foreign Contact: " + this.getJid() + "[Gateway: " + this.gatewayName + ", Connected: " + isConnected() + "]";
} }
} }
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
package org.jivesoftware.wildfire.gateway.roster; package org.jivesoftware.wildfire.gateway.roster;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
...@@ -24,31 +23,26 @@ import org.xmpp.packet.JID; ...@@ -24,31 +23,26 @@ import org.xmpp.packet.JID;
* *
* @author Noah Campbell * @author Noah Campbell
*/ */
public class ContactManager implements Serializable { public class ContactManager {
/** /**
* Construct a new <code>ContactManager</code> * Construct a new <code>ContactManager</code>
*/ */
ContactManager() { } ContactManager() { }
/**
* The serialVersionUID
*/
private static final long serialVersionUID = 1L;
/** /**
* The fcs * The fcs
* *
* @see java.util.Set * @see java.util.Set
*/ */
private final Set<AbstractForeignContact> fcs = new HashSet<AbstractForeignContact>(); private final Set<AbstractForeignContact> fcs = new HashSet<AbstractForeignContact>();
/** /**
* Maintain a mapping of JIDs to their contact list. * Maintain a mapping of JIDs to their contact list.
*/ */
private final Map<NormalizedJID, Roster> contactLists = private final Map<NormalizedJID, Roster> contactLists =
new HashMap<NormalizedJID, Roster>(); new HashMap<NormalizedJID, Roster>();
/** /**
* Return a roster for a JID. * Return a roster for a JID.
* *
...@@ -57,14 +51,14 @@ public class ContactManager implements Serializable { ...@@ -57,14 +51,14 @@ public class ContactManager implements Serializable {
*/ */
public synchronized Roster getRoster(JID name) { public synchronized Roster getRoster(JID name) {
Roster r = contactLists.get(NormalizedJID.wrap(name)); Roster r = contactLists.get(NormalizedJID.wrap(name));
if(r == null) { if (r == null) {
r = new Roster(); r = new Roster();
contactLists.put(NormalizedJID.wrap(name), r); contactLists.put(NormalizedJID.wrap(name), r);
} }
return r; return r;
} }
/** /**
* @return foreignContacts A {@code java.util.Set} of {@code ForeignContact}s. * @return foreignContacts A {@code java.util.Set} of {@code ForeignContact}s.
*/ */
...@@ -72,7 +66,6 @@ public class ContactManager implements Serializable { ...@@ -72,7 +66,6 @@ public class ContactManager implements Serializable {
return this.fcs; return this.fcs;
} }
/** /**
* Remove the <code>JID</code> from the contact list. * Remove the <code>JID</code> from the contact list.
* *
...@@ -81,4 +74,5 @@ public class ContactManager implements Serializable { ...@@ -81,4 +74,5 @@ public class ContactManager implements Serializable {
void remove(NormalizedJID jid) { void remove(NormalizedJID jid) {
contactLists.remove(jid); contactLists.remove(jid);
} }
} }
...@@ -15,7 +15,6 @@ import org.xmpp.packet.JID; ...@@ -15,7 +15,6 @@ import org.xmpp.packet.JID;
/** /**
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public interface ForeignContact { public interface ForeignContact {
...@@ -46,16 +45,14 @@ public interface ForeignContact { ...@@ -46,16 +45,14 @@ public interface ForeignContact {
* @return connected * @return connected
*/ */
public boolean isConnected(); public boolean isConnected();
/** /**
* Return the translated status for the contact. * Return the translated status for the contact.
* *
* @return Status * @return Status
*/ */
public Status getStatus(); public Status getStatus();
/** /**
* Return the name of the contact. * Return the name of the contact.
* *
......
...@@ -10,23 +10,18 @@ ...@@ -10,23 +10,18 @@
package org.jivesoftware.wildfire.gateway.roster; package org.jivesoftware.wildfire.gateway.roster;
import java.io.Serializable;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/**
* @author Noah Campbell
*
*/
/** /**
* Ignore the resource portion of the JID. * Ignore the resource portion of the JID.
* *
* @author Noah Campbell * @author Noah Campbell
* *
*/ */
public final class NormalizedJID implements Serializable { public final class NormalizedJID {
/** /**
* The JID. * The JID.
...@@ -34,18 +29,13 @@ public final class NormalizedJID implements Serializable { ...@@ -34,18 +29,13 @@ public final class NormalizedJID implements Serializable {
* @see JID * @see JID
*/ */
public final String JID; public final String JID;
/** /**
* The toStringValue. Stored to increase efficiency. * The toStringValue. Stored to increase efficiency.
* *
* @see NormalizedJID * @see NormalizedJID
*/ */
private final String toStringValue; private final String toStringValue;
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/** /**
* Construct a new <code>NormalizedJID</code> * Construct a new <code>NormalizedJID</code>
...@@ -55,28 +45,30 @@ public final class NormalizedJID implements Serializable { ...@@ -55,28 +45,30 @@ public final class NormalizedJID implements Serializable {
JID = jid.toBareJID(); JID = jid.toBareJID();
toStringValue = JID + " (normalized)"; toStringValue = JID + " (normalized)";
} }
/** /**
* @see java.lang.Object#equals(java.lang.Object) * @see java.lang.Object#equals(java.lang.Object)
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if(obj instanceof NormalizedJID) { if (obj instanceof NormalizedJID) {
NormalizedJID jid = (NormalizedJID)obj; NormalizedJID jid = (NormalizedJID)obj;
return JID.equalsIgnoreCase(jid.JID); return JID.equalsIgnoreCase(jid.JID);
} else if(obj instanceof JID) { }
else if (obj instanceof JID) {
JID jid = new JID( ((JID)obj).toBareJID() ); JID jid = new JID( ((JID)obj).toBareJID() );
return JID.equalsIgnoreCase(jid.toBareJID()); return JID.equalsIgnoreCase(jid.toBareJID());
} else if( obj instanceof String) { }
else if (obj instanceof String) {
JID jid = new JID((String)obj); JID jid = new JID((String)obj);
jid = new JID(jid.toBareJID()); jid = new JID(jid.toBareJID());
return JID.equalsIgnoreCase(jid.toBareJID()); return JID.equalsIgnoreCase(jid.toBareJID());
} else { }
else {
return super.equals(obj); return super.equals(obj);
} }
} }
/** /**
* @see java.lang.Object#hashCode() * @see java.lang.Object#hashCode()
*/ */
...@@ -84,7 +76,7 @@ public final class NormalizedJID implements Serializable { ...@@ -84,7 +76,7 @@ public final class NormalizedJID implements Serializable {
public int hashCode() { public int hashCode() {
return JID.hashCode(); return JID.hashCode();
} }
/** /**
* Wrap a <code>JID</code> and return a <code>NormalizedJID</code>. If the * Wrap a <code>JID</code> and return a <code>NormalizedJID</code>. If the
* <code>JID</code> has already been wrapped, then the cached version is returned. * <code>JID</code> has already been wrapped, then the cached version is returned.
...@@ -93,15 +85,16 @@ public final class NormalizedJID implements Serializable { ...@@ -93,15 +85,16 @@ public final class NormalizedJID implements Serializable {
* @return normalizedJID * @return normalizedJID
*/ */
public static NormalizedJID wrap(JID jid) { public static NormalizedJID wrap(JID jid) {
if(cache.containsKey(jid)) { if (cache.containsKey(jid)) {
return cache.get(jid); return cache.get(jid);
} else { }
else {
NormalizedJID nJID = new NormalizedJID(jid); NormalizedJID nJID = new NormalizedJID(jid);
cache.put(jid, nJID); cache.put(jid, nJID);
return nJID; return nJID;
} }
} }
/** /**
* @see java.lang.Object#toString() * @see java.lang.Object#toString()
*/ */
...@@ -109,12 +102,12 @@ public final class NormalizedJID implements Serializable { ...@@ -109,12 +102,12 @@ public final class NormalizedJID implements Serializable {
public String toString() { public String toString() {
return toStringValue; return toStringValue;
} }
/** /**
* The cache of <code>NormailzedJID</code>s. * The cache of <code>NormailzedJID</code>s.
* *
* @see java.util.Map * @see java.util.Map
*/ */
private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>(); private transient static final Map<JID, NormalizedJID> cache = new ConcurrentHashMap<JID, NormalizedJID>();
} }
...@@ -15,7 +15,6 @@ import java.io.FileInputStream; ...@@ -15,7 +15,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -46,22 +45,22 @@ import org.xmpp.packet.JID; ...@@ -46,22 +45,22 @@ import org.xmpp.packet.JID;
* @author Noah Campbell * @author Noah Campbell
* *
*/ */
public class PersistenceManager implements Serializable { public class PersistenceManager {
/** /**
* The contactManager. * The contactManager.
* *
* @see ContactManager * @see ContactManager
*/ */
private ContactManager contactManager = null; private ContactManager contactManager = null;
/** /**
* The registrar. * The registrar.
* *
* @see Registrar * @see Registrar
*/ */
private Registrar registrar = null; private Registrar registrar = null;
/** /**
* The gateway. * The gateway.
* *
...@@ -69,13 +68,14 @@ public class PersistenceManager implements Serializable { ...@@ -69,13 +68,14 @@ public class PersistenceManager implements Serializable {
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
private Gateway gateway; private Gateway gateway;
/** /**
* Factory for accessing the various RosterManagers. * Factory for accessing the various RosterManagers.
* *
* @author Noah Campbell * @author Noah Campbell
*/ */
public final static class Factory { public final static class Factory {
/** /**
* The <code>PersistanceManager</code> associated with a particular * The <code>PersistanceManager</code> associated with a particular
* <code>Gateway</code> * <code>Gateway</code>
...@@ -84,7 +84,7 @@ public class PersistenceManager implements Serializable { ...@@ -84,7 +84,7 @@ public class PersistenceManager implements Serializable {
*/ */
private final static Map<Gateway, PersistenceManager> instances = private final static Map<Gateway, PersistenceManager> instances =
new HashMap<Gateway, PersistenceManager>(); new HashMap<Gateway, PersistenceManager>();
/** /**
* Given a <code>Gateway</code> return a <code>PersistenceManager</code> * Given a <code>Gateway</code> return a <code>PersistenceManager</code>
* @param gateway * @param gateway
...@@ -99,12 +99,12 @@ public class PersistenceManager implements Serializable { ...@@ -99,12 +99,12 @@ public class PersistenceManager implements Serializable {
} }
return rm; return rm;
} }
} }
/** The db file. */ /** The db file. */
private final File db; private final File db;
/** /**
* Construct a new <code>PersistanceManager</code>. * Construct a new <code>PersistanceManager</code>.
* *
...@@ -117,8 +117,7 @@ public class PersistenceManager implements Serializable { ...@@ -117,8 +117,7 @@ public class PersistenceManager implements Serializable {
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS); timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
} }
/** /**
* Unregister a JID. * Unregister a JID.
* @param jid * @param jid
...@@ -129,17 +128,17 @@ public class PersistenceManager implements Serializable { ...@@ -129,17 +128,17 @@ public class PersistenceManager implements Serializable {
NormalizedJID njid = NormalizedJID.wrap(jid); NormalizedJID njid = NormalizedJID.wrap(jid);
contactManager.remove(njid); contactManager.remove(njid);
registrar.remove(jid); registrar.remove(jid);
} catch (Exception e) { }
catch (Exception e) {
logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage()); logger.severe("Unable to remove " + bareJID + ": " + e.getLocalizedMessage());
} }
} }
/** /**
* Load the roster manager (we simply read a binary file from the file system). * Load the roster manager (we simply read a binary file from the file system).
* @param gateway * @param gateway
*/ */
private void load(Gateway gateway) { private void load(Gateway gateway) {
ContactManager contactManager = null; ContactManager contactManager = null;
Registrar registrar = null; Registrar registrar = null;
try { try {
...@@ -149,7 +148,7 @@ public class PersistenceManager implements Serializable { ...@@ -149,7 +148,7 @@ public class PersistenceManager implements Serializable {
*/ */
byte[] rawKey = Preferences.systemNodeForPackage(this.getClass()).getByteArray(".key", null); byte[] rawKey = Preferences.systemNodeForPackage(this.getClass()).getByteArray(".key", null);
if(rawKey == null) { if (rawKey == null) {
logger.log(GatewayLevel.SECURITY, "persistencemanager.nokey"); logger.log(GatewayLevel.SECURITY, "persistencemanager.nokey");
return; return;
} }
...@@ -164,38 +163,34 @@ public class PersistenceManager implements Serializable { ...@@ -164,38 +163,34 @@ public class PersistenceManager implements Serializable {
contactManager = (ContactManager)is.readObject() ; contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ; registrar = (Registrar) is.readObject() ;
is.close(); is.close();
} catch (Exception e) { }
if(db.exists()) { catch (Exception e) {
if (db.exists()) {
db.delete(); db.delete();
} }
logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e); logger.log(Level.WARNING, "persistencemanager.loadrosterfailed",e);
} finally { }
finally {
this.contactManager = (contactManager != null) ? contactManager : new ContactManager(); this.contactManager = (contactManager != null) ? contactManager : new ContactManager();
this.registrar = (registrar != null) ? registrar : new Registrar(); this.registrar = (registrar != null) ? registrar : new Registrar();
this.registrar.setGateway(gateway); // re-vitialize the registrar. this.registrar.setGateway(gateway); // re-vitialize the registrar.
} }
} }
/** /**
* A timer for executing tasks related to PersistanceManager. * A timer for executing tasks related to PersistanceManager.
* *
* @see java.util.concurrent.ScheduledExecutorService * @see java.util.concurrent.ScheduledExecutorService
*/ */
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory()); private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/** /**
* The logger. * The logger.
* *
* @see PersistenceManager * @see PersistenceManager
*/ */
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n"); private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
/** /**
* Responsible for flushing the in-memory database. * Responsible for flushing the in-memory database.
*/ */
...@@ -203,32 +198,31 @@ public class PersistenceManager implements Serializable { ...@@ -203,32 +198,31 @@ public class PersistenceManager implements Serializable {
public void run() { public void run() {
try { try {
store(); store();
} catch (Exception e) { }
catch (Exception e) {
logger.log(Level.WARNING, "persistencemanager.unabletoflush", e); logger.log(Level.WARNING, "persistencemanager.unabletoflush", e);
e.printStackTrace(); e.printStackTrace();
} }
} }
}; };
/** /**
* Write the contact manager and registrar to the file system. * Write the contact manager and registrar to the file system.
* *
* @throws Exception * @throws Exception
*/ */
public synchronized void store() throws Exception { public synchronized void store() throws Exception {
Preferences prefs = Preferences.systemNodeForPackage(this.getClass()); Preferences prefs = Preferences.systemNodeForPackage(this.getClass());
byte[] rawKey = prefs.getByteArray(".key", null); byte[] rawKey = prefs.getByteArray(".key", null);
if(rawKey == null) { if (rawKey == null) {
logger.log(GatewayLevel.SECURITY, "persistencemanager.gennewkey"); logger.log(GatewayLevel.SECURITY, "persistencemanager.gennewkey");
KeyGenerator kg = KeyGenerator.getInstance("AES"); KeyGenerator kg = KeyGenerator.getInstance("AES");
SecretKey key = kg.generateKey(); SecretKey key = kg.generateKey();
rawKey = key.getEncoded(); rawKey = key.getEncoded();
prefs.putByteArray(".key", rawKey); prefs.putByteArray(".key", rawKey);
} }
SecretKeySpec key = new SecretKeySpec(rawKey, "AES"); SecretKeySpec key = new SecretKeySpec(rawKey, "AES");
Cipher c = Cipher.getInstance("AES"); Cipher c = Cipher.getInstance("AES");
c.init(Cipher.ENCRYPT_MODE, key); c.init(Cipher.ENCRYPT_MODE, key);
...@@ -238,10 +232,8 @@ public class PersistenceManager implements Serializable { ...@@ -238,10 +232,8 @@ public class PersistenceManager implements Serializable {
oos.writeObject(registrar); oos.writeObject(registrar);
oos.flush(); oos.flush();
oos.close(); oos.close();
} }
/** /**
* @return Returns the contactManager. * @return Returns the contactManager.
*/ */
...@@ -249,7 +241,6 @@ public class PersistenceManager implements Serializable { ...@@ -249,7 +241,6 @@ public class PersistenceManager implements Serializable {
return contactManager; return contactManager;
} }
/** /**
* @return Returns the registrar. * @return Returns the registrar.
*/ */
...@@ -257,7 +248,6 @@ public class PersistenceManager implements Serializable { ...@@ -257,7 +248,6 @@ public class PersistenceManager implements Serializable {
return registrar; return registrar;
} }
/** /**
* @see java.lang.Object#finalize() * @see java.lang.Object#finalize()
*/ */
...@@ -267,4 +257,5 @@ public class PersistenceManager implements Serializable { ...@@ -267,4 +257,5 @@ public class PersistenceManager implements Serializable {
this.timer.shutdownNow(); this.timer.shutdownNow();
logger.log(Level.FINER, "persistencemanager.registrarFinalize"); logger.log(Level.FINER, "persistencemanager.registrarFinalize");
} }
} }
...@@ -12,7 +12,6 @@ package org.jivesoftware.wildfire.gateway.roster; ...@@ -12,7 +12,6 @@ package org.jivesoftware.wildfire.gateway.roster;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -29,23 +28,16 @@ import org.xmpp.packet.JID; ...@@ -29,23 +28,16 @@ import org.xmpp.packet.JID;
* legacy system and the XMPP Server. * legacy system and the XMPP Server.
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
*/ */
public class Registrar implements Serializable { public class Registrar {
/**
* The serialVersionUID.
*
* @see Registrar
*/
private static final long serialVersionUID = 1L;
/** /**
* Construct a new <code>Registrar</code>. * Construct a new <code>Registrar</code>.
*/ */
Registrar() { Registrar() {
createSessionCache(); createSessionCache();
} }
/** /**
* Initializes a new session cache * Initializes a new session cache
*/ */
...@@ -57,13 +49,14 @@ public class Registrar implements Serializable { ...@@ -57,13 +49,14 @@ public class Registrar implements Serializable {
* GatewaySessions are maintained in the registration * GatewaySessions are maintained in the registration
*/ */
private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>(); private final Map<NormalizedJID, SubscriptionInfo> registrar = new HashMap<NormalizedJID, SubscriptionInfo>();
/** /**
* The <code>GatewaySessions</code> mapped by <code>JID</code> * The <code>GatewaySessions</code> mapped by <code>JID</code>
* *
* @see java.util.Map * @see java.util.Map
*/ */
private transient Map<JID, GatewaySession> sessions; private transient Map<JID, GatewaySession> sessions;
/** /**
* Determine if the JID is registered (based on the bare JID) * Determine if the JID is registered (based on the bare JID)
* @param id * @param id
...@@ -72,7 +65,7 @@ public class Registrar implements Serializable { ...@@ -72,7 +65,7 @@ public class Registrar implements Serializable {
public boolean isRegistered(NormalizedJID id) { public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id); return registrar.containsKey(id);
} }
/** /**
* Add a JID to the registrar. * Add a JID to the registrar.
* @param id * @param id
...@@ -82,7 +75,7 @@ public class Registrar implements Serializable { ...@@ -82,7 +75,7 @@ public class Registrar implements Serializable {
registrar.put(NormalizedJID.wrap(id), info); registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS); //timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
} }
/** /**
* Get the Session for a JID. * Get the Session for a JID.
* *
...@@ -92,10 +85,10 @@ public class Registrar implements Serializable { ...@@ -92,10 +85,10 @@ public class Registrar implements Serializable {
*/ */
public GatewaySession getGatewaySession(JID jid) throws Exception { public GatewaySession getGatewaySession(JID jid) throws Exception {
SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid)); SubscriptionInfo info = registrar.get(NormalizedJID.wrap(jid));
if(info == null) { if (info == null) {
throw new IllegalStateException("Please register before attempting to get a session"); throw new IllegalStateException("Please register before attempting to get a session");
} }
if(!sessions.containsKey(jid)) { if (!sessions.containsKey(jid)) {
info.jid = jid; info.jid = jid;
GatewaySession session = this.gateway.getSessionFactory().newInstance(info); GatewaySession session = this.gateway.getSessionFactory().newInstance(info);
...@@ -119,14 +112,14 @@ public class Registrar implements Serializable { ...@@ -119,14 +112,14 @@ public class Registrar implements Serializable {
void setGateway(Gateway gateway) { void setGateway(Gateway gateway) {
this.gateway = gateway; this.gateway = gateway;
} }
/** /**
* The gateway. * The gateway.
* *
* @see Gateway * @see Gateway
*/ */
private transient Gateway gateway; private transient Gateway gateway;
/** /**
* The logger. * The logger.
* *
...@@ -142,15 +135,16 @@ public class Registrar implements Serializable { ...@@ -142,15 +135,16 @@ public class Registrar implements Serializable {
NormalizedJID wrapped = NormalizedJID.wrap(jid); NormalizedJID wrapped = NormalizedJID.wrap(jid);
registrar.remove(wrapped); registrar.remove(wrapped);
GatewaySession session = sessions.get(jid); GatewaySession session = sessions.get(jid);
if(session.isConnected()) { if (session.isConnected()) {
try { try {
session.logout(); session.logout();
} catch (Exception e) { }
catch (Exception e) {
// silently ignore // silently ignore
} }
} }
} }
/** /**
* @param ois * @param ois
* @throws IOException * @throws IOException
...@@ -160,4 +154,5 @@ public class Registrar implements Serializable { ...@@ -160,4 +154,5 @@ public class Registrar implements Serializable {
ois.defaultReadObject(); ois.defaultReadObject();
this.createSessionCache(); this.createSessionCache();
} }
} }
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
package org.jivesoftware.wildfire.gateway.roster; package org.jivesoftware.wildfire.gateway.roster;
import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
...@@ -23,19 +22,13 @@ import org.jivesoftware.wildfire.gateway.Gateway; ...@@ -23,19 +22,13 @@ import org.jivesoftware.wildfire.gateway.Gateway;
* to a particular <code>JID</code> * to a particular <code>JID</code>
* *
* @author Noah Campbell * @author Noah Campbell
* @version 1.0
* *
* @see AbstractForeignContact * @see AbstractForeignContact
* @see org.xmpp.packet.JID * @see org.xmpp.packet.JID
* @deprecated * @deprecated
*/ */
public class Roster implements Serializable { public class Roster {
/**
* The serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/** /**
* The foreignContacts. * The foreignContacts.
* *
...@@ -54,7 +47,6 @@ public class Roster implements Serializable { ...@@ -54,7 +47,6 @@ public class Roster implements Serializable {
* @return ForeignContact * @return ForeignContact
*/ */
public ForeignContact getForeignContact(String foreignId, Gateway gateway) { public ForeignContact getForeignContact(String foreignId, Gateway gateway) {
AbstractForeignContact fc = this.foreignContacts.get(foreignId); AbstractForeignContact fc = this.foreignContacts.get(foreignId);
if(fc == null) { if(fc == null) {
// fc = new ForeignContact(foreignId, new Status(), gateway); // fc = new ForeignContact(foreignId, new Status(), gateway);
...@@ -69,5 +61,5 @@ public class Roster implements Serializable { ...@@ -69,5 +61,5 @@ public class Roster implements Serializable {
public Collection<AbstractForeignContact> getAll() { public Collection<AbstractForeignContact> getAll() {
return Collections.unmodifiableCollection(this.foreignContacts.values()); return Collections.unmodifiableCollection(this.foreignContacts.values());
} }
} }
...@@ -10,59 +10,58 @@ ...@@ -10,59 +10,58 @@
package org.jivesoftware.wildfire.gateway.roster; package org.jivesoftware.wildfire.gateway.roster;
import java.io.Serializable;
/** /**
* Status object. * Status object.
* *
* @author Noah Campbell * @author Noah Campbell
*/ */
public final class Status implements Serializable { public final class Status {
/** The serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The subscribed. */ /** The subscribed. */
private boolean subscribed = false; private boolean subscribed = false;
/** The online. */ /** The online. */
private boolean online = false; private boolean online = false;
/** The value. */ /** The value. */
private String value; private String value;
/** /**
* @return status a string representation of the status's state. * @return status a string representation of the status's state.
*/ */
public String getValue() { return value; } public String getValue() { return value; }
/** /**
* @param value the new value of the status * @param value the new value of the status
*/ */
public void updateValue(String value) { this.value = value; } public void updateValue(String value) { this.value = value; }
/** /**
* @return Returns the subscribed. * @return Returns the subscribed.
*/ */
public boolean isSubscribed() { public boolean isSubscribed() {
return subscribed; return subscribed;
} }
/** /**
* @param subscribed The subscribed to set. * @param subscribed The subscribed to set.
*/ */
public void setSubscribed(boolean subscribed) { public void setSubscribed(boolean subscribed) {
this.subscribed = subscribed; this.subscribed = subscribed;
} }
/** /**
* @return Returns the online. * @return Returns the online.
*/ */
public boolean isOnline() { public boolean isOnline() {
return this.online; return this.online;
} }
/** /**
* @param online The online to set. * @param online The online to set.
*/ */
public void setOnline(boolean online) { public void setOnline(boolean online) {
this.online = online; this.online = online;
} }
} }
...@@ -21,7 +21,7 @@ public class UnknownForeignContactException extends Exception { ...@@ -21,7 +21,7 @@ public class UnknownForeignContactException extends Exception {
/** The args. */ /** The args. */
private final Object[] args; private final Object[] args;
/** /**
* Constructs a new <code>UnknownForeignContactException</code>. * Constructs a new <code>UnknownForeignContactException</code>.
*/ */
...@@ -62,4 +62,5 @@ public class UnknownForeignContactException extends Exception { ...@@ -62,4 +62,5 @@ public class UnknownForeignContactException extends Exception {
super(cause); super(cause);
args = new Object[0]; args = new Object[0];
} }
}
\ No newline at end of file }
...@@ -19,10 +19,9 @@ import java.util.concurrent.ThreadFactory; ...@@ -19,10 +19,9 @@ import java.util.concurrent.ThreadFactory;
*/ */
public class BackgroundThreadFactory implements ThreadFactory { public class BackgroundThreadFactory implements ThreadFactory {
/** The background thread group. */ /** The background thread group. */
private static ThreadGroup group = new ThreadGroup("background"); private static ThreadGroup group = new ThreadGroup("background");
/** /**
* @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable) * @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
*/ */
...@@ -33,5 +32,4 @@ public class BackgroundThreadFactory implements ThreadFactory { ...@@ -33,5 +32,4 @@ public class BackgroundThreadFactory implements ThreadFactory {
return thread; return thread;
} }
} }
...@@ -24,6 +24,7 @@ import org.jivesoftware.util.PropertyEventDispatcher; ...@@ -24,6 +24,7 @@ import org.jivesoftware.util.PropertyEventDispatcher;
* @author Daniel Henninger * @author Daniel Henninger
*/ */
public class GatewayInstance { public class GatewayInstance {
private ComponentManager componentManager; private ComponentManager componentManager;
private String serviceName = null; private String serviceName = null;
private String nameOfClass = null; private String nameOfClass = null;
...@@ -31,6 +32,13 @@ public class GatewayInstance { ...@@ -31,6 +32,13 @@ public class GatewayInstance {
private Boolean enabled = false; private Boolean enabled = false;
private Boolean running = false; private Boolean running = false;
/**
* Creates a new gateway instance.
*
* @param subdomain Part of gateway domain prepended to server domain.
* @param classname Full name/path of class associated with instance.
* @param componentManager Component manager managing this instance.
*/
public GatewayInstance(String subdomain, String classname, ComponentManager componentManager) { public GatewayInstance(String subdomain, String classname, ComponentManager componentManager) {
this.serviceName = subdomain; this.serviceName = subdomain;
this.nameOfClass = classname; this.nameOfClass = classname;
...@@ -38,18 +46,36 @@ public class GatewayInstance { ...@@ -38,18 +46,36 @@ public class GatewayInstance {
enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+serviceName+"Enabled", false); enabled = JiveGlobals.getBooleanProperty("plugin.gateway."+serviceName+"Enabled", false);
} }
/**
* Retrieves the name of the service (aka, subdomain)
*
* @return name of the service
*/
public String getName() { public String getName() {
return serviceName; return serviceName;
} }
/**
* Returns whether this gateway instance is enabled.
*
* @return true or false if instance is enabled
*/
public Boolean isEnabled() { public Boolean isEnabled() {
return enabled; return enabled;
} }
/**
* Returns whether this gateway instance is currently running.
*
* @return true or false if instance is currently running
*/
public Boolean isRunning() { public Boolean isRunning() {
return running; return running;
} }
/**
* Enables the gateway instance and starts it if it's not already running.
*/
public void enable() { public void enable() {
enabled = true; enabled = true;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "true"); JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "true");
...@@ -58,6 +84,9 @@ public class GatewayInstance { ...@@ -58,6 +84,9 @@ public class GatewayInstance {
} }
} }
/**
* Disables the gateway instance and stops it if it's running.
*/
public void disable() { public void disable() {
enabled = false; enabled = false;
JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "false"); JiveGlobals.setProperty("plugin.gateway."+serviceName+"Enabled", "false");
...@@ -66,6 +95,9 @@ public class GatewayInstance { ...@@ -66,6 +95,9 @@ public class GatewayInstance {
} }
} }
/**
* Starts the gateway instance if it's enabled and not already running.
*/
public void startInstance() { public void startInstance() {
if (!enabled || running) { if (!enabled || running) {
return; return;
...@@ -101,6 +133,9 @@ public class GatewayInstance { ...@@ -101,6 +133,9 @@ public class GatewayInstance {
} }
} }
/**
* Stops the gateway instance if it's running.
*/
public void stopInstance() { public void stopInstance() {
if (!running) { if (!running) {
return; return;
...@@ -117,4 +152,5 @@ public class GatewayInstance { ...@@ -117,4 +152,5 @@ public class GatewayInstance {
gateway = null; gateway = null;
running = false; running = false;
} }
} }
...@@ -20,10 +20,9 @@ import java.util.logging.Level; ...@@ -20,10 +20,9 @@ import java.util.logging.Level;
*/ */
public class GatewayLevel extends Level { public class GatewayLevel extends Level {
/** SECURITY log level. */ /** SECURITY log level. */
public static final Level SECURITY = new GatewayLevel("SECURITY", 501); public static final Level SECURITY = new GatewayLevel("SECURITY", 501);
/** /**
* Construct a new <code>GatewayLevel</code>. * Construct a new <code>GatewayLevel</code>.
* *
...@@ -34,7 +33,4 @@ public class GatewayLevel extends Level { ...@@ -34,7 +33,4 @@ public class GatewayLevel extends Level {
super(name, value, "gateway_i18n"); super(name, value, "gateway_i18n");
} }
/** The serialVersionUID. */ }
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment