org.jabber.jabberbeans.util
Class JID

java.lang.Object
  |
  +--org.jabber.jabberbeans.util.JID
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class JID
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable

A JID is a jabber identifier, signifying a resource in the Jabber protocol. Format: [User@]server[/resource]

See Also:
Serialized Form

Constructor Summary
JID(java.lang.String server)
          Creates a new JID instance, with only a server being specified.
JID(java.lang.String username, java.lang.String server, java.lang.String resource)
          Creates a new JID instance, based on the server and user and resource strings.
 
Method Summary
 int compare(java.lang.Object o)
          compare returns true if these objects are equivalent.
static int compare(java.lang.Object o, java.lang.Object o2)
          compare returns true if these objects are equivalent.
 int compareTo(java.lang.Object o)
          compareTo returns true if these objects are equivalent.
 boolean equals(JID u)
          equals returns true if these objects are equivalent.
 boolean equals(java.lang.Object obj)
          equals returns true if these objects are equivalent.
static JID fromString(java.lang.String input)
          fromString is a static method that creates a new JID based on an input string in URI format.
 java.lang.String getResource()
          Returns the resource if one was specified, otherwise null
 java.lang.String getServer()
          Returns the server name of the JID
 JID getSimpleJID()
          getSimpleJID returns the current jid without the resource
 java.lang.String getUsername()
          Returns the username of the JID if one was specified, othewise null
 int hashCode()
          hashCode returns the hash code of the jid in lowercase
 java.lang.String normalize()
          normalize returns a normalized string, This means that the username and server have been lowercased and the resource remains the same
static java.lang.String normalize(JID j)
          normalize returns a normalized string from the jid taken This means that the username and server have been lowercased and the resource remains the same
 java.lang.String toPrettyString()
          Deprecated. use toSimpleString() instead, will be removed before 1.0
 java.lang.String toSimpleString()
          toSimpleString returns a string of the current jid sans(minus) the resource
 java.lang.String toString()
          Creates a string representing the JID.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JID

public JID(java.lang.String server)
Creates a new JID instance, with only a server being specified.

Parameters:
server - String naming the server.
Throws:
java.lang.RuntimeException - if the server field is null, as that would be an invalid JID.

JID

public JID(java.lang.String username,
           java.lang.String server,
           java.lang.String resource)
Creates a new JID instance, based on the server and user and resource strings. the Username and Resource can optionally be set to null.

Parameters:
username - String value holding the username, or null
server - String value holding the server name
resource - String value holding the resource, or null
Throws:
java.lang.RuntimeException - if the server field is null (as that would be an invalid JID)
Method Detail

fromString

public static JID fromString(java.lang.String input)
fromString is a static method that creates a new JID based on an input string in URI format.

Parameters:
input - String value containing a URI JID
Returns:
a JID value if we can parse this into a JID, null otherwise

getUsername

public java.lang.String getUsername()
Returns the username of the JID if one was specified, othewise null

Returns:
String holding the username, or null

getServer

public java.lang.String getServer()
Returns the server name of the JID

Returns:
String holding the server name

getResource

public java.lang.String getResource()
Returns the resource if one was specified, otherwise null

Returns:
String holding the resource name, or null

getSimpleJID

public JID getSimpleJID()
getSimpleJID returns the current jid without the resource

Returns:
a JID value

toString

public java.lang.String toString()
Creates a string representing the JID. Note to get a URI, you need to prefix this with "jabber:". In communications with the server, the jabber: tag is not required.

Overrides:
toString in class java.lang.Object
Returns:
String value representing the JID.

toPrettyString

public java.lang.String toPrettyString()
Deprecated. use toSimpleString() instead, will be removed before 1.0

Creates a 'user friendly' string, with parameters for things like logins stripped off. It is preferable in some cases to return this instead of a full JID to a user information screen, so people don't freak out that their password or other information is being specified.

Returns:
a String value

toSimpleString

public java.lang.String toSimpleString()
toSimpleString returns a string of the current jid sans(minus) the resource

Returns:
a String value

equals

public boolean equals(JID u)
equals returns true if these objects are equivalent. It takes into account that usernames and servers are case-insensitive, and that resources are case sensitive. It also takes into account that usernames and resources are optional, but requires them to be specified in both or none of the two JIDs being compared.

Parameters:
u - a JID we are comparing to this one
Returns:
a boolean that is true when the JIDs are equivalent

equals

public boolean equals(java.lang.Object obj)
equals returns true if these objects are equivalent. It takes into account that usernames and servers are case-insensitive, and that resources are case sensitive. It also takes into account that usernames and resources are optional, but requires them to be specified in both or none of the two JIDs being compared.

Overrides:
equals in class java.lang.Object
Parameters:
obj - a Object we are comparing to this one
Returns:
a boolean that is true when the objects are equivalent

compareTo

public int compareTo(java.lang.Object o)
compareTo returns true if these objects are equivalent. It takes into account that usernames and servers are case-insensitive, and that resources are case sensitive. It also takes into account that usernames and resources are optional, but requires them to be specified in both or none of the two JIDs being compared.

Specified by:
compareTo in interface java.lang.Comparable
Returns:
a int that determines lexographical significance

compare

public int compare(java.lang.Object o)
compare returns true if these objects are equivalent. It takes into account that usernames and servers are case-insensitive, and that resources are case sensitive. It also takes into account that usernames and resources are optional, but requires them to be specified in both or none of the two JIDs being compared.

Returns:
a int that determines lexographical significance

compare

public static int compare(java.lang.Object o,
                          java.lang.Object o2)
compare returns true if these objects are equivalent. It takes into account that usernames and servers are case-insensitive, and that resources are case sensitive. It also takes into account that usernames and resources are optional, but requires them to be specified in both or none of the two JIDs being compared.

Returns:
a int that determines lexographical significance

hashCode

public int hashCode()
hashCode returns the hash code of the jid in lowercase

Overrides:
hashCode in class java.lang.Object
Returns:
a int that is the hash code

normalize

public static java.lang.String normalize(JID j)
normalize returns a normalized string from the jid taken This means that the username and server have been lowercased and the resource remains the same

Returns:
a String that is normalized

normalize

public java.lang.String normalize()
normalize returns a normalized string, This means that the username and server have been lowercased and the resource remains the same

Returns:
a String that is normalized