
uk.org.retep.xmpp.JIDResource Maven / Gradle / Ivy
/*
* Copyright (c) 1998-2007, Peter T Mount
* All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see .
*
*
*
* GNU GENERAL PUBLIC LICENSE - CLASSPATH EXCEPTION
*
*
*
* Linking this library statically or dynamically with other modules
* is making a combined work based on this library. Thus, the terms
* and conditions of the GNU General Public License cover the whole
* combination.
*
*
*
* As a special exception, the copyright holders of this library give
* you permission to link this library with independent modules to
* produce an executable, regardless of the license terms of these
* independent modules, and to copy and distribute the resulting
* executable under terms of your choice, provided that you also meet,
* for each linked independent module, the terms and conditions of the
* license of that module.
*
*
*
* An independent module is a module which is either not derived from or based
* on this library, or a module who's classes extend those within this library
* as part of the implementation of the library.
*
*
*
* If you modify this library, you may extend this exception to your version
* of the library, but you are not obligated to do so. If you do not wish to
* do so, delete this exception statement from your version.
*
*/
package uk.org.retep.xmpp;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import net.jcip.annotations.ThreadSafe;
import org.terracotta.modules.annotations.HonorTransient;
import org.terracotta.modules.annotations.InstrumentedClass;
/**
*
* Subclass of JID which is optimised for matching one or more components of
* a JID.
*
*
*
* For example: You have a JID called "name%[email protected]" and a
* JIDResource of "msn.server.com", when JIDResource.equals( JID ) is called
* it will return true because the domain's match.
*
*
*
* This class is used by a server to route messages via multiple transports.
*
*
* @author peter
*/
@ThreadSafe
@HonorTransient
@InstrumentedClass
public class JIDResource
extends JID
implements Externalizable
{
static final long serialVersionUID = 2233984628143280590L;
/**
* Construct a new JID based on node and domain.
* This will form the JID node@domain
* @param node JID Node
* @param domain JID Domain
*/
public JIDResource( String node, String domain )
{
super( node, domain );
}
/**
* Construct a new JID based on node, domain and resource.
* This will form the JID node@domain/resource
* @param node JID node
* @param domain JID domain
* @param resource JID resource
*/
public JIDResource( String node, String domain, String resource )
{
super( node, domain, resource );
}
/**
* Construct a JID from it's string representation
* @param jid String representation of a JID
* @throws uk.org.retep.xmpp.XMPPException if the JID is null or invalid
*/
// public JIDResource( String jid )
// throws XMPPException
// {
// super( jid );
// }
/**
* Construct a copy of another JID
* @param jid JID to copy
*/
public JIDResource( JID jid )
{
super( jid );
}
public JIDResource( ObjectInput in )
throws IOException, ClassNotFoundException
{
super( in );
}
/**
* Equality
* @param obj to test
* @return true if obj equals this JID
*/
@Override
public boolean equals( Object obj )
{
boolean ret = equalsWithoutResource( obj );
if( ret )
{
// It must be a jid for ret to be true here, see equalsWithoutResource()
JID jid = JID.class.cast( obj );
ret = getResource( ) == null ? true : getResource( ).
equals( jid.getResource( ) );
}
return ret;
}
@Override
public int hashCode()
{
int h = 1;
if(getDomain() != null )
{
h = (31 * h) + getDomain().hashCode( );
}
if( getResource() != null )
{
h = (31 * h) + getResource().hashCode( );
}
return h;
}
@Override
public boolean equalsWithoutResource( Object obj )
{
if( obj == null || !(obj instanceof JID) )
{
return false;
}
JID jid = JID.class.cast( obj );
boolean ret = getNode( ) == null ? true : getNode( ).
equals( jid.getNode( ) );
if( ret )
{
ret = getDomain( ) == null ? true : getDomain( ).
equals( jid.getDomain( ) );
}
return ret;
}
}