Commit 47d52817 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Simple code cleanup (tabs to spaces)

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@4382 b35dd754-fafc-0310-a699-88a17e54d16e
parent 009225d2
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>IM Gateway Changelog</title> <title>IM Gateway Changelog</title>
<style type="text/css"> <style type="text/css">
BODY { BODY {
font-size : 100%; font-size : 100%;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>IM Gateway Readme</title> <title>IM Gateway Readme</title>
<style type="text/css"> <style type="text/css">
BODY { BODY {
font-size : 100%; font-size : 100%;
......
login.title=Admin Console
externalgateway.startup=Started external gateway {0}. externalgateway.startup=Started external gateway {0}.
externalgateway.filenotfound=Configuration file {0} not found: {1} externalgateway.filenotfound=Configuration file {0} not found: {1}
externalgateway.invalidconfig=Invalid configuratino file: {0} externalgateway.invalidconfig=Invalid configuratino file: {0}
externalgateway.missingconfig=Unable to locate config.properties in classpath. \ externalgateway.missingconfig=Unable to locate config.properties in classpath. \
Either specify on the command line the config properties or include it in the proper jar file. Either specify on the command line the config properties or include it in the proper jar file.
externalgateway.invalidcommandline=Invalid command line option. {0} externalgateway.invalidcommandline=Invalid command line option. {0}
externalgateway.usingdefaultgateway=Using default gateway "{0}" with secret passphrase "{1}". externalgateway.usingdefaultgateway=Using default gateway "{0}" with secret passphrase "{1}".
externalgateway.addcomponentfailed=Unable to add component. Please ensure that the domain ({0}) is correct and matches the secret phrase ({1}) on the server. Error from server: {2} externalgateway.addcomponentfailed=Unable to add component. Please ensure that the domain ({0}) is correct and matches the secret phrase ({1}) on the server. Error from server: {2}
......
STATUS_AVAILABLE = "Available"; STATUS_AVAILABLE = "Available";
STATUS_BRB = "Be right back"; STATUS_BRB = "Be right back";
STATUS_BUSY = "Busy"; STATUS_BUSY = "Busy";
STATUS_NOTATHOME = "Not at home"; STATUS_NOTATHOME = "Not at home";
STATUS_NOTATDESK = "Not at desk"; STATUS_NOTATDESK = "Not at desk";
STATUS_NOTINOFFICE = "Not in office"; STATUS_NOTINOFFICE = "Not in office";
STATUS_ONPHONE = "On the phone"; STATUS_ONPHONE = "On the phone";
STATUS_ONVACATION = "On vacation"; STATUS_ONVACATION = "On vacation";
STATUS_OUTTOLUNCH = "Out to lunch"; STATUS_OUTTOLUNCH = "Out to lunch";
STATUS_STEPPEDOUT = "Stepped out"; STATUS_STEPPEDOUT = "Stepped out";
STATUS_INVISIBLE = "Invisible"; STATUS_INVISIBLE = "Invisible";
STATUS_CUSTOM = "<custom>"; STATUS_CUSTOM = "<custom>";
STATUS_IDLE = "Zzz"; STATUS_IDLE = "Zzz";
STATUS_OFFLINE = "Offline"; STATUS_OFFLINE = "Offline";
STATUS_TYPING = "Typing"; STATUS_TYPING = "Typing";
\ No newline at end of file
...@@ -25,40 +25,40 @@ public interface Gateway extends Endpoint { ...@@ -25,40 +25,40 @@ public interface Gateway extends Endpoint {
* Node naming coventions * Node naming coventions
* @return Name The gateway name (JID Node) * @return Name The gateway name (JID Node)
*/ */
public String getName(); public String getName();
/** /**
* Sets the name, or node, of the gateway. This should comply with JID * Sets the name, or node, of the gateway. This should comply with JID
* Node naming coventions * Node naming coventions
*/ */
public void setName(String newname); public void setName(String newname);
/** /**
* A textual description of the gateway * A textual description of the gateway
* @return description * @return description
*/ */
public String getDescription(); public String getDescription();
/** /**
* The domain name * The domain name
* @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
......
...@@ -26,45 +26,45 @@ import org.xmpp.packet.Packet; ...@@ -26,45 +26,45 @@ import org.xmpp.packet.Packet;
*/ */
public class YahooGateway extends BaseGateway { public class YahooGateway extends BaseGateway {
/** The YAHOO. */
private static String YAHOO = "yahoo";
/** /** The YAHOO. */
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName() private static String YAHOO = "yahoo";
*/
@Override /**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getName()
*/
@Override
public String getName() { public String getName() {
return YAHOO; return YAHOO;
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String) * @see org.jivesoftware.wildfire.gateway.BaseGateway#setName(String)
*/ */
@Override @Override
public void setName(String newname) { public void setName(String newname) {
YAHOO = newname; YAHOO = newname;
} }
/** /**
* @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription() * @see org.jivesoftware.wildfire.gateway.BaseGateway#getDescription()
*/ */
@Override @Override
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");
/** /**
* @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet) * @see org.jivesoftware.wildfire.gateway.Endpoint#sendPacket(Packet)
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException { public void sendPacket(@SuppressWarnings("unused") Packet packet) throws ComponentException {
// do nothing. // do nothing.
} }
/** /**
* @param jid * @param jid
......
...@@ -57,11 +57,11 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -57,11 +57,11 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
/** 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.
...@@ -84,30 +84,30 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -84,30 +84,30 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
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.
*/ */
// public void updatePresence() { // public void updatePresence() {
// if(isConnected()) { // if(isConnected()) {
// //
// for(YahooGroup group : session.getGroups()) { // for(YahooGroup group : session.getGroups()) {
// Vector members = group.getMembers(); // Vector members = group.getMembers();
// for(Object member : members) { // for(Object member : members) {
// YahooUser user = (YahooUser)member; // YahooUser user = (YahooUser)member;
// logger.info("Adding foreign contact: " + user.getId()); // logger.info("Adding foreign contact: " + user.getId());
// String foreignId = user.getId(); // String foreignId = user.getId();
// NormalizedJID whois = NormalizedJID.wrap(gateway.whois(foreignId)); // NormalizedJID whois = NormalizedJID.wrap(gateway.whois(foreignId));
// AbstractForeignContact fc = PersistenceManager.Factory.get(gateway) // AbstractForeignContact fc = PersistenceManager.Factory.get(gateway)
// .getContactManager().getRoster(this.jid) // .getContactManager().getRoster(this.jid)
...@@ -121,90 +121,90 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -121,90 +121,90 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
// logger.warning("Invalid Yahoo user"); // logger.warning("Invalid Yahoo user");
// continue; // continue;
// } // }
// if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) { // if(fc.status.getValue() != null && !fc.status.getValue().equalsIgnoreCase(user.getCustomStatusMessage())) {
// logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status}); // logger.log(Level.FINE, "yahoogatewaysession.status", new Object[] {fc.status});
// try { // try {
// Presence p = new Presence(); // Presence p = new Presence();
// if(!fc.status.isSubscribed()) { // if(!fc.status.isSubscribed()) {
// p.setType(Presence.Type.subscribe); // p.setType(Presence.Type.subscribe);
// fc.status.setSubscribed(true); // fc.status.setSubscribed(true);
// } // }
// p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain()); // p.setFrom(user.getId() + "@" + gateway.getName() + "." + gateway.getDomain());
// p.setTo(this.jid); // p.setTo(this.jid);
// gateway.sendPacket(p); // gateway.sendPacket(p);
// //
// } catch (Exception e) { // } catch (Exception e) {
// e.printStackTrace(); // e.printStackTrace();
// } // }
// } // }
// //
// } // }
// } // }
// } // }
// } // }
/** /**
* Login to the Yahoo! Messenger serverice * Login to the Yahoo! Messenger serverice
* @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
public void run() { public void run() {
try { try {
session.login(getSubscriptionInfo().username, session.login(getSubscriptionInfo().username,
new String(getSubscriptionInfo().password)); new String(getSubscriptionInfo().password));
/** /**
* Password is stored in the JVM as a string in JVM * Password is stored in the JVM as a string in JVM
* util termination. * util termination.
*/ */
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?
*/ */
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
*/ */
public synchronized void logout() throws Exception { public synchronized void logout() throws Exception {
logger.info("[" + this.jid + "]" + getSubscriptionInfo().username + " logged out."); logger.info("[" + this.jid + "]" + getSubscriptionInfo().username + " logged out.");
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 + "]"; }
/** /**
...@@ -212,23 +212,23 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo ...@@ -212,23 +212,23 @@ public class YahooGatewaySession extends AbstractGatewaySession implements Endpo
* @return ID the jid for this session. * @return ID the jid for this session.
* @see org.xmpp.packet.JID * @see org.xmpp.packet.JID
*/ */
public String getId() { public String getId() {
return this.jid.toBareJID(); return this.jid.toBareJID();
} }
/** /**
* Returns all the contacts associated with this Session. * Returns all the contacts associated with this Session.
* @return contacts A list of <code>String</code>s. * @return contacts A list of <code>String</code>s.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
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;
} }
/** /**
* Return the <code>JID</code> for this session. * Return the <code>JID</code> for this session.
......
...@@ -27,30 +27,30 @@ import org.xmpp.packet.JID; ...@@ -27,30 +27,30 @@ import org.xmpp.packet.JID;
* @version 1.0 * @version 1.0
*/ */
public abstract class AbstractForeignContact implements Serializable, ForeignContact { public abstract class AbstractForeignContact implements Serializable, ForeignContact {
/** /**
* The serialVersionUID * The serialVersionUID
*/ */
private static final long serialVersionUID = 1L; 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.
*/ */
public final String id; public final String id;
/** /**
* The status of this contact. * The status of this contact.
* *
* @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.
*/ */
...@@ -67,14 +67,14 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -67,14 +67,14 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @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.
* *
...@@ -82,24 +82,24 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon ...@@ -82,24 +82,24 @@ public abstract class AbstractForeignContact implements Serializable, ForeignCon
* @param status the current status of the contact. * @param status the current status of the contact.
* @param gateway the gateway the foreign contact is associated with. * @param gateway the gateway the foreign contact is associated with.
*/ */
public AbstractForeignContact(String id, Status status, Gateway gateway) { public AbstractForeignContact(String id, Status status, Gateway gateway) {
this.id = id; this.id = id;
this.status = status; this.status = status;
this.gatewayDomain = gateway.getDomain(); this.gatewayDomain = gateway.getDomain();
this.gatewayName = gateway.getName(); this.gatewayName = gateway.getName();
} }
/** /**
* @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
* @throws ClassNotFoundException * @throws ClassNotFoundException
......
...@@ -31,11 +31,11 @@ public class ContactManager implements Serializable { ...@@ -31,11 +31,11 @@ public class ContactManager implements Serializable {
*/ */
ContactManager() { } ContactManager() { }
/** /**
* The serialVersionUID * The serialVersionUID
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* The fcs * The fcs
* *
...@@ -43,27 +43,27 @@ public class ContactManager implements Serializable { ...@@ -43,27 +43,27 @@ public class ContactManager implements Serializable {
*/ */
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.
* *
* @param name The <code>JID</code> to lookup. * @param name The <code>JID</code> to lookup.
* @return roster The roster for the <code>JID</code>. * @return roster The roster for the <code>JID</code>.
*/ */
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.
...@@ -73,12 +73,12 @@ public class ContactManager implements Serializable { ...@@ -73,12 +73,12 @@ public class ContactManager implements Serializable {
} }
/** /**
* Remove the <code>JID</code> from the contact list. * Remove the <code>JID</code> from the contact list.
* *
* @param jid * @param jid
*/ */
void remove(NormalizedJID jid) { void remove(NormalizedJID jid) {
contactLists.remove(jid); contactLists.remove(jid);
} }
} }
...@@ -28,12 +28,12 @@ import org.xmpp.packet.JID; ...@@ -28,12 +28,12 @@ import org.xmpp.packet.JID;
*/ */
public final class NormalizedJID implements Serializable { public final class NormalizedJID implements Serializable {
/** /**
* The JID. * The JID.
* *
* @see JID * @see JID
*/ */
public final String JID; public final String JID;
/** /**
* The toStringValue. Stored to increase efficiency. * The toStringValue. Stored to increase efficiency.
...@@ -42,65 +42,65 @@ public final class NormalizedJID implements Serializable { ...@@ -42,65 +42,65 @@ public final class NormalizedJID implements Serializable {
*/ */
private final String toStringValue; private final String toStringValue;
/** /**
* The serialVersionUID. * The serialVersionUID.
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Construct a new <code>NormalizedJID</code> * Construct a new <code>NormalizedJID</code>
* @param jid * @param jid
*/ */
private NormalizedJID(JID jid) { private NormalizedJID(JID jid) {
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()
*/ */
@Override @Override
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.
* *
* @param jid * @param jid
* @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 +109,12 @@ public final class NormalizedJID implements Serializable { ...@@ -109,12 +109,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>();
} }
...@@ -47,102 +47,102 @@ import org.xmpp.packet.JID; ...@@ -47,102 +47,102 @@ import org.xmpp.packet.JID;
* *
*/ */
public class PersistenceManager implements Serializable { public class PersistenceManager implements Serializable {
/** /**
* 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.
* *
* @see Gateway * @see Gateway
*/ */
@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>
* *
* @see Factory * @see Factory
*/ */
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
* @return persistenceManager returns a <code>PersistenceManager</code> * @return persistenceManager returns a <code>PersistenceManager</code>
* @see PersistenceManager * @see PersistenceManager
*/ */
public static synchronized PersistenceManager get(Gateway gateway) { public static synchronized PersistenceManager get(Gateway gateway) {
PersistenceManager rm = instances.get(gateway); PersistenceManager rm = instances.get(gateway);
if(rm == null) { if(rm == null) {
rm = new PersistenceManager(gateway); rm = new PersistenceManager(gateway);
instances.put(gateway, rm); instances.put(gateway, rm);
} }
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>.
* *
* @param gateway * @param gateway
*/ */
private PersistenceManager(Gateway gateway) { private PersistenceManager(Gateway gateway) {
this.gateway = gateway; this.gateway = gateway;
db = new File("/tmp/." + this.gateway.getName().toLowerCase() + ".dat"); db = new File("/tmp/." + this.gateway.getName().toLowerCase() + ".dat");
load(gateway); load(gateway);
timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS); timer.scheduleAtFixedRate(archiver, 5, 5, TimeUnit.SECONDS);
} }
/** /**
* Unregister a JID. * Unregister a JID.
* @param jid * @param jid
*/ */
public void remove(JID jid) { public void remove(JID jid) {
String bareJID = jid.toBareJID(); String bareJID = jid.toBareJID();
try { try {
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 {
/** /**
* The key is stored in the registry so the key is as secure as the * The key is stored in the registry so the key is as secure as the
* registry is secure. * registry is secure.
...@@ -160,62 +160,62 @@ public class PersistenceManager implements Serializable { ...@@ -160,62 +160,62 @@ public class PersistenceManager implements Serializable {
CipherInputStream cis = new CipherInputStream(new FileInputStream(db), c); CipherInputStream cis = new CipherInputStream(new FileInputStream(db), c);
ObjectInputStream is = new ObjectInputStream(cis); ObjectInputStream is = new ObjectInputStream(cis);
contactManager = (ContactManager)is.readObject() ; contactManager = (ContactManager)is.readObject() ;
registrar = (Registrar) is.readObject() ; registrar = (Registrar) is.readObject() ;
is.close(); is.close();
} catch (Exception e) { } catch (Exception e) {
if(db.exists()) { 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.
*
* @see java.util.concurrent.ScheduledExecutorService
*/
private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
/**
* The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
/** /**
* Responsible for flushing the in-memory database. * A timer for executing tasks related to PersistanceManager.
*/ *
private final Runnable archiver = new Runnable() { * @see java.util.concurrent.ScheduledExecutorService
public void run() { */
try { private final ScheduledExecutorService timer = Executors.newScheduledThreadPool(1, new BackgroundThreadFactory());
store(); /**
} catch (Exception e) { * The serialVersionUID.
*
* @see PersistenceManager
*/
private static final long serialVersionUID = 1L;
/**
* The logger.
*
* @see PersistenceManager
*/
private static final Logger logger = Logger.getLogger("PersistenceManager", "gateway_i18n");
/**
* Responsible for flushing the in-memory database.
*/
private final Runnable archiver = new Runnable() {
public void run() {
try {
store();
} 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());
...@@ -234,28 +234,28 @@ public class PersistenceManager implements Serializable { ...@@ -234,28 +234,28 @@ public class PersistenceManager implements Serializable {
c.init(Cipher.ENCRYPT_MODE, key); c.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream os = new CipherOutputStream(new FileOutputStream(db), c); CipherOutputStream os = new CipherOutputStream(new FileOutputStream(db), c);
ObjectOutputStream oos = new ObjectOutputStream(os); ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(contactManager); oos.writeObject(contactManager);
oos.writeObject(registrar); oos.writeObject(registrar);
oos.flush(); oos.flush();
oos.close(); oos.close();
} }
/** /**
* @return Returns the contactManager. * @return Returns the contactManager.
*/ */
public ContactManager getContactManager() { public ContactManager getContactManager() {
return contactManager; return contactManager;
} }
/** /**
* @return Returns the registrar. * @return Returns the registrar.
*/ */
public Registrar getRegistrar() { public Registrar getRegistrar() {
return registrar; return registrar;
} }
/** /**
......
...@@ -32,13 +32,13 @@ import org.xmpp.packet.JID; ...@@ -32,13 +32,13 @@ import org.xmpp.packet.JID;
* @version 1.0 * @version 1.0
*/ */
public class Registrar implements Serializable { public class Registrar implements Serializable {
/** /**
* The serialVersionUID. * The serialVersionUID.
* *
* @see Registrar * @see Registrar
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** /**
* Construct a new <code>Registrar</code>. * Construct a new <code>Registrar</code>.
*/ */
...@@ -46,52 +46,52 @@ public class Registrar implements Serializable { ...@@ -46,52 +46,52 @@ public class Registrar implements Serializable {
createSessionCache(); createSessionCache();
} }
/** /**
* Initializes a new session cache * Initializes a new session cache
*/ */
private void createSessionCache() { private void createSessionCache() {
sessions = new HashMap<JID, GatewaySession>(); sessions = new HashMap<JID, GatewaySession>();
} }
/** /**
* 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)
* @param id
* @return true/false
*/
public boolean isRegistered(NormalizedJID id) {
return registrar.containsKey(id);
}
/** /**
* Determine if the JID is registered (based on the bare JID) * Add a JID to the registrar.
* @param id * @param id
* @return true/false * @param info
*/ */
public boolean isRegistered(NormalizedJID id) { public void add(JID id, SubscriptionInfo info) {
return registrar.containsKey(id); registrar.put(NormalizedJID.wrap(id), info);
} //timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Add a JID to the registrar. /**
* @param id * Get the Session for a JID.
* @param info
*/
public void add(JID id, SubscriptionInfo info) {
registrar.put(NormalizedJID.wrap(id), info);
//timer.scheduleAtFixedRate(info, 10, 10, TimeUnit.SECONDS);
}
/**
* Get the Session for a JID.
* *
* @param jid the <code>JID</code> * @param jid the <code>JID</code>
* @return session the gateway session * @return session the gateway session
* @throws Exception * @throws Exception
*/ */
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");
} }
...@@ -104,21 +104,21 @@ public class Registrar implements Serializable { ...@@ -104,21 +104,21 @@ public class Registrar implements Serializable {
sessions.put(jid, session); sessions.put(jid, session);
} }
return sessions.get(jid); return sessions.get(jid);
} }
/** /**
* @return collection of subscriptionInfos * @return collection of subscriptionInfos
*/ */
public Collection<SubscriptionInfo> getAllGatewaySessions() { public Collection<SubscriptionInfo> getAllGatewaySessions() {
return registrar.values(); return registrar.values();
} }
/** /**
* @param gateway * @param gateway
*/ */
void setGateway(Gateway gateway) { void setGateway(Gateway gateway) {
this.gateway = gateway; this.gateway = gateway;
} }
/** /**
* The gateway. * The gateway.
...@@ -126,21 +126,21 @@ public class Registrar implements Serializable { ...@@ -126,21 +126,21 @@ public class Registrar implements Serializable {
* @see Gateway * @see Gateway
*/ */
private transient Gateway gateway; private transient Gateway gateway;
/** /**
* The logger. * The logger.
* *
* @see Registrar * @see Registrar
*/ */
private static final Logger logger = Logger.getLogger("Registrar"); private static final Logger logger = Logger.getLogger("Registrar");
/** /**
* Removes the NormalizedJID from the registrar. * Removes the NormalizedJID from the registrar.
* @param jid * @param jid
*/ */
void remove(JID jid) { void remove(JID jid) {
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 {
...@@ -149,7 +149,7 @@ public class Registrar implements Serializable { ...@@ -149,7 +149,7 @@ public class Registrar implements Serializable {
// silently ignore // silently ignore
} }
} }
} }
/** /**
* @param ois * @param ois
......
...@@ -18,40 +18,40 @@ import java.io.Serializable; ...@@ -18,40 +18,40 @@ import java.io.Serializable;
* @author Noah Campbell * @author Noah Campbell
*/ */
public final class Status implements Serializable { public final class Status implements Serializable {
/** The serialVersionUID. */ /** The serialVersionUID. */
private static final long serialVersionUID = 1L; 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.
*/ */
...@@ -64,5 +64,5 @@ public final class Status implements Serializable { ...@@ -64,5 +64,5 @@ public final class Status implements Serializable {
public void setOnline(boolean online) { public void setOnline(boolean online) {
this.online = online; this.online = online;
} }
} }
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