diff options
author | Nick Hudson <nick.hudson@isode.com> | 2012-01-16 12:14:02 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-01-18 11:03:48 (GMT) |
commit | 6665e38f97f95dd6e0fc574dc65a1be37b2b101f (patch) | |
tree | a780670c4a15abca042a0c75fa172b40b1808a22 /src/com | |
parent | 839db071f46d083b86996f514f5fe0f2d6aee80a (diff) | |
download | stroke-6665e38f97f95dd6e0fc574dc65a1be37b2b101f.zip stroke-6665e38f97f95dd6e0fc574dc65a1be37b2b101f.tar.bz2 |
Add toString to some more classes
Also made "Stanza" be an abstract class and had its ".toString()" include
the name of the subclass which is involved, so that the subclasses don't
have to do that themselves.
Also added null check to existing HostAddress.toString() method
Also fixed Remko copyright in Connector class
Test-information:
Stuff is displayed as expected in debugger.
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/isode/stroke/client/ClientOptions.java | 16 | ||||
-rw-r--r-- | src/com/isode/stroke/client/CoreClient.java | 7 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/IQ.java | 8 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Message.java | 2 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Presence.java | 7 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Stanza.java | 17 | ||||
-rw-r--r-- | src/com/isode/stroke/elements/Status.java | 8 | ||||
-rw-r--r-- | src/com/isode/stroke/network/Connector.java | 15 | ||||
-rw-r--r-- | src/com/isode/stroke/network/HostAddress.java | 7 | ||||
-rw-r--r-- | src/com/isode/stroke/network/HostAddressPort.java | 7 | ||||
-rw-r--r-- | src/com/isode/stroke/network/JavaConnection.java | 11 |
11 files changed, 86 insertions, 19 deletions
diff --git a/src/com/isode/stroke/client/ClientOptions.java b/src/com/isode/stroke/client/ClientOptions.java index 99b3242..10dc8b3 100644 --- a/src/com/isode/stroke/client/ClientOptions.java +++ b/src/com/isode/stroke/client/ClientOptions.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited, London, England. + * Copyright (c) 2011-2012 Isode Limited, London, England. * All rights reserved. */ /* @@ -9,7 +9,7 @@ package com.isode.stroke.client; /** - * + * Options for a client connection */ public class ClientOptions { @@ -17,13 +17,22 @@ public class ClientOptions { NeverUseTLS, UseTLSWhenAvailable - }; + } public ClientOptions() { useStreamCompression = true; useTLS = UseTLS.UseTLSWhenAvailable; useStreamResumption = false; } + + @Override + public String toString() { + return + "useStreamCompression:" + useStreamCompression + + "; useStreamResumption:" + useStreamResumption + + "; " + useTLS; + } + /** * Whether ZLib stream compression should be used when available. * @@ -42,4 +51,5 @@ public class ClientOptions { * Default: false */ public boolean useStreamResumption; + } diff --git a/src/com/isode/stroke/client/CoreClient.java b/src/com/isode/stroke/client/CoreClient.java index cc9fd61..828906c 100644 --- a/src/com/isode/stroke/client/CoreClient.java +++ b/src/com/isode/stroke/client/CoreClient.java @@ -395,6 +395,13 @@ public class CoreClient { return jid_; } } + + @Override + public String toString() + { + return "CoreClient for \"" + jid_ + "\"" + + "; session " + (isAvailable() ? "" : "un") + "available"; + } /** * The user should add a listener to this signal, which will be called when diff --git a/src/com/isode/stroke/elements/IQ.java b/src/com/isode/stroke/elements/IQ.java index 098dfaf..78d4d6a 100644 --- a/src/com/isode/stroke/elements/IQ.java +++ b/src/com/isode/stroke/elements/IQ.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ /* @@ -11,7 +11,7 @@ package com.isode.stroke.elements; import com.isode.stroke.jid.JID; public class IQ extends Stanza { - public enum Type {Get, Set, Result, Error}; + public enum Type {Get, Set, Result, Error} private Type type_; @@ -55,4 +55,8 @@ public class IQ extends Stanza { return iq; } + @Override + public String toString() { + return super.toString() + " Type=" + type_; + } } diff --git a/src/com/isode/stroke/elements/Message.java b/src/com/isode/stroke/elements/Message.java index 67903ae..5cfb58f 100644 --- a/src/com/isode/stroke/elements/Message.java +++ b/src/com/isode/stroke/elements/Message.java @@ -56,6 +56,6 @@ public class Message extends Stanza { @Override public String toString() { - return "Message " + super.toString() + " subject=\"" + getSubject() + "\""; + return super.toString() + " subject=\"" + getSubject() + "\""; } } diff --git a/src/com/isode/stroke/elements/Presence.java b/src/com/isode/stroke/elements/Presence.java index 9c8a870..acf0a40 100644 --- a/src/com/isode/stroke/elements/Presence.java +++ b/src/com/isode/stroke/elements/Presence.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ /* @@ -66,4 +66,9 @@ public class Presence extends Stanza { public void setPriority(int priority) { updatePayload(new Priority(priority)); } + + @Override + public String toString() { + return super.toString() + " Type=" + type_; + } } diff --git a/src/com/isode/stroke/elements/Stanza.java b/src/com/isode/stroke/elements/Stanza.java index 85b9d00..036ec8b 100644 --- a/src/com/isode/stroke/elements/Stanza.java +++ b/src/com/isode/stroke/elements/Stanza.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ /* @@ -13,9 +13,9 @@ import com.isode.stroke.jid.JID; import java.util.Vector; /** - * Basic XMPP stanza. + * Base class for all types of XMPP stanza. */ -public class Stanza implements Element { +public abstract class Stanza implements Element { private String id_; private JID from_; private JID to_; @@ -83,9 +83,18 @@ public class Stanza implements Element { id_ = id; } + /** + * Returns debug-friendly String description of this Stanza, which will + * include the subclass's name (e.g. "Presence"). + * @return a debug-friendly String. + */ @Override public String toString() { - return "Stanza from \"" + from_ + "\" to \"" + to_ + "\"" + + String className = this.getClass().getSimpleName(); + + // Include actual stanza type based on class name of the object + return className + + " stanza from \"" + from_ + "\" to \"" + to_ + "\"" + " id=\"" + id_ + "\""; } diff --git a/src/com/isode/stroke/elements/Status.java b/src/com/isode/stroke/elements/Status.java index 250917d..215703b 100644 --- a/src/com/isode/stroke/elements/Status.java +++ b/src/com/isode/stroke/elements/Status.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ /* @@ -26,4 +26,10 @@ public class Status extends Payload { public String getText() { return text_; } + + @Override + public String toString() { + return "Status : " + text_; + } + } diff --git a/src/com/isode/stroke/network/Connector.java b/src/com/isode/stroke/network/Connector.java index 9b086fa..01fd114 100644 --- a/src/com/isode/stroke/network/Connector.java +++ b/src/com/isode/stroke/network/Connector.java @@ -1,10 +1,9 @@ /* - * Copyright (c) 2010 Remko Tronçon - * Licensed under the GNU General Public License v3. - * See Documentation/Licenses/GPLv3.txt for more information. + * Copyright (c) 2010-2012, Isode Limited, London, England. + * All rights reserved. */ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010 Remko Tronçon * All rights reserved. */ package com.isode.stroke.network; @@ -195,6 +194,14 @@ public class Connector { private void handleTimeout() { finish(null); } + + @Override + public String toString() { + return "Connector to \"" + hostname + "\" " + + (currentConnection == null ? "not connected" : "using " + currentConnection); + } + + private String hostname; private DomainNameResolver resolver; private ConnectionFactory connectionFactory; diff --git a/src/com/isode/stroke/network/HostAddress.java b/src/com/isode/stroke/network/HostAddress.java index 94ae1f7..7145fb3 100644 --- a/src/com/isode/stroke/network/HostAddress.java +++ b/src/com/isode/stroke/network/HostAddress.java @@ -26,6 +26,11 @@ public class HostAddress { @Override public String toString() { + // toString() should always be callable without risking + // NullPointerException + if (address_ == null) { + return "<no address>"; + } return address_.getHostAddress(); } @@ -51,6 +56,6 @@ public class HostAddress { InetAddress getInetAddress() { return address_; } - + private final InetAddress address_; } diff --git a/src/com/isode/stroke/network/HostAddressPort.java b/src/com/isode/stroke/network/HostAddressPort.java index 66ba3a7..c7d46a4 100644 --- a/src/com/isode/stroke/network/HostAddressPort.java +++ b/src/com/isode/stroke/network/HostAddressPort.java @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ /* - * Copyright (c) 2010, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.network; @@ -52,6 +52,11 @@ public class HostAddressPort { public boolean isValid() { return address_.isValid() && port_ > 0; } + + @Override + public String toString() { + return address_ + ":" + port_; + } private HostAddress address_; private int port_; } diff --git a/src/com/isode/stroke/network/JavaConnection.java b/src/com/isode/stroke/network/JavaConnection.java index 29ec0e0..d014f5d 100644 --- a/src/com/isode/stroke/network/JavaConnection.java +++ b/src/com/isode/stroke/network/JavaConnection.java @@ -4,7 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ /* - * Copyright (c) 2010-2011, Isode Limited, London, England. + * Copyright (c) 2010-2012, Isode Limited, London, England. * All rights reserved. */ package com.isode.stroke.network; @@ -169,6 +169,15 @@ public class JavaConnection extends Connection implements EventOwner { public HostAddressPort getLocalAddress() { return new HostAddressPort(new HostAddress(socket_.getLocalAddress()), socket_.getLocalPort()); } + + @Override + public String toString() + { + return "JavaConnection " + + (socket_ == null ? "with no socket configured" : "for " + getLocalAddress()) + + (disconnecting_ ? " (disconnecting)" : ""); + } + private final EventLoop eventLoop_; private boolean disconnecting_ = false; private Socket socket_; |