package org.jboss.mx.remoting;
import java.io.Serializable;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.jboss.remoting.ident.Identity;
import org.jboss.remoting.loading.ClassUtil;
import org.jboss.remoting.ConnectionFailedException;
public class MBeanLocator implements Serializable
{
static final long serialVersionUID = -95280512054710509L;
private final Identity identity;
private final ObjectName objectName;
private final MBeanServerLocator locator;
public MBeanLocator (MBeanServerLocator sl, ObjectName obj)
{
this.identity = sl.getIdentity();
this.locator = sl;
this.objectName = obj;
}
public boolean equals ( Object o )
{
if ( this == o ) return true;
if ( !( o instanceof MBeanLocator ) ) return false;
final MBeanLocator mBeanLocator = (MBeanLocator) o;
if ( identity != null ? !identity.equals ( mBeanLocator.identity ) : mBeanLocator.identity != null ) return false;
if ( locator != null ? !locator.equals ( mBeanLocator.locator ) : mBeanLocator.locator != null ) return false;
if ( objectName != null ? !objectName.equals ( mBeanLocator.objectName ) : mBeanLocator.objectName != null ) return false;
return true;
}
public int hashCode ()
{
int result;
result = ( identity != null ? identity.hashCode () : 0 );
result = 29 * result + ( objectName != null ? objectName.hashCode () : 0 );
result = 29 * result + ( locator != null ? locator.hashCode () : 0 );
return result;
}
public MBeanServerLocator getServerLocator ()
{
return this.locator;
}
public final Identity getIdentity ()
{
return this.identity;
}
public final ObjectName getObjectName ()
{
return objectName;
}
public String toString ()
{
return "MBeanLocator [server:"+locator+",mbean:"+objectName+"]";
}
public boolean isSameJVM (MBeanLocator locator)
{
return locator!=null && locator.locator.equals(this.locator);
}
public Object narrow (Class interfaceCl)
{
Class cl[]=ClassUtil.getInterfacesFor(interfaceCl);
return narrow (cl);
}
public MBeanServer getMBeanServer ()
throws ConnectionFailedException
{
return locator.getMBeanServer();
}
public Object narrow (Class interfaces[])
{
return MoveableMBean.create(this,interfaces);
}
}