com.realtime.xmpp.types
Class JID

java.lang.Object
  |
  +--com.realtime.xmpp.types.JID

public class JID
extends java.lang.Object

Manage a Jabber identifier. The identifier takes the form [node@]domain[/resource] where both node and resource are optional.

This class provides fast parsing and minimal object creation through late binding of the identifier elements to strings.

Note that this class supports zero-length nodes and resources. If a JID is created as user@home/ then the node will be 'user' and the resource will be a zero length string. Whereas a JID of home/play will have a null user, and a resource of 'play'. The simple rule is that when a delimiter (either @ or /) is specified, then a string will be available.

Version:
1.0 Copyright © 2002 Real Time Entertainment Group, LLC - All rights reserved.
Author:
Mike Prince

Field Summary
protected  boolean m_bHashed
           
protected  int m_nHash
           
protected  int m_pAt
           
protected  int m_pSlash
           
protected  java.lang.String m_sDomain
           
protected  java.lang.String m_sJid
           
protected  java.lang.String m_sNode
           
protected  java.lang.String m_sResource
           
 
Constructor Summary
JID(java.lang.String sJid)
          Create a JID from a simple string.
JID(java.lang.String sNode, java.lang.String sDomain, java.lang.String sResource)
          Create the JID from a node, domain and resource.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compare two JIDs for equality.
 java.lang.String getDomain()
          Provide the domain.
 java.lang.String getNode()
          Provide the node, or null if there is none.
 java.lang.String getResource()
          Provide the resource, or null if there was none.
 int hashCode()
          Generate a hashcode.
static void main(java.lang.String[] argv)
           
 JID pruneResource()
          Provide a JID equivalent to this JID, but without the resource.
 JID setResource(java.lang.String sResource)
          Add a resource to a JID.
protected static void test(java.lang.String sJid, java.lang.String sNegativeTest)
           
 java.lang.String toString()
          Provide the original string used to create the jid.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

m_pAt

protected int m_pAt

m_pSlash

protected int m_pSlash

m_sJid

protected java.lang.String m_sJid

m_sNode

protected java.lang.String m_sNode

m_sDomain

protected java.lang.String m_sDomain

m_sResource

protected java.lang.String m_sResource

m_bHashed

protected boolean m_bHashed

m_nHash

protected int m_nHash
Constructor Detail

JID

public JID(java.lang.String sNode,
           java.lang.String sDomain,
           java.lang.String sResource)

Create the JID from a node, domain and resource.

Parameters:
sNode - The node, or null. * @param sDomain The domain, the MUST NOT be null. * @param sResource The resource, or null.

JID

public JID(java.lang.String sJid)

Create a JID from a simple string.

The string takes the form [node@]host[/resource] where both node and resource are optional.

* @param sJid The JID to parse.

Method Detail

getNode

public java.lang.String getNode()

Provide the node, or null if there is none.

* @return The node, or null if there was none.


getDomain

public java.lang.String getDomain()

Provide the domain.

* @return The domain.


getResource

public java.lang.String getResource()

Provide the resource, or null if there was none.

Returns:
The resource, or null if there was none.

pruneResource

public JID pruneResource()

Provide a JID equivalent to this JID, but without the resource. If this JID does not have a resource, then a handle to the existing JID is returned.

* @return If this JID has a resource, a new JID with just the node and domain is created. Otherwise, a handle to the existing JID is returned.


setResource

public JID setResource(java.lang.String sResource)

Add a resource to a JID. IF the resource is the same as the existing one, the current JID is returned. If the resource is different, a new JID will be created with the new resource.

* @param sResource * @return A JID with the new resource.


toString

public java.lang.String toString()

Provide the original string used to create the jid.

* @return A simple Jabber compliant string of the form [node@]domain[/resource], where both node and resource are optional.

Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)

Compare two JIDs for equality. Honors the Jabber spec by doing case insensitive compares of the domain and node portion of the Jabber id.

* @param obj The JID to compare with. May either be a JID or a String.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Generate a hashcode.

* @see java.lang.Object#hashCode()

Overrides:
hashCode in class java.lang.Object

test

protected static void test(java.lang.String sJid,
                           java.lang.String sNegativeTest)

main

public static void main(java.lang.String[] argv)


Copyright © 2002,2003 Real Time Entertainment Group, LLC. All Rights Reserved.