FileDocCategorySizeDatePackage
PrincipalImpl.javaAPI DocJava SE 5 API3612Fri Aug 26 14:55:02 BST 2005com.sun.jmx.snmp.IPAcl

PrincipalImpl

public class PrincipalImpl extends Object implements Serializable, Principal
Principal represents a host.
version
4.15 12/19/03
author
Sun Microsystems, Inc

Fields Summary
private InetAddress[]
add
Constructors Summary
public PrincipalImpl()
Constructs a principal with the local host.

  
                
         
	add = new InetAddress[1];
        add[0] = java.net.InetAddress.getLocalHost();
    
public PrincipalImpl(String hostName)
Construct a principal using the specified host.

The host can be either:

  • a host name
  • an IP address

param
hostName the host used to make the principal.

        if ((hostName.equals("localhost")) || (hostName.equals("127.0.0.1"))) {
	    add = new InetAddress[1];
            add[0] = java.net.InetAddress.getByName(hostName);
	}
        else
            add = java.net.InetAddress.getAllByName( hostName );
    
public PrincipalImpl(InetAddress address)
Constructs a principal using an Internet Protocol (IP) address.

param
address the Internet Protocol (IP) address.

        add = new InetAddress[1];
	add[0] = address;
    
Methods Summary
public booleanequals(java.lang.Object a)
Compares this principal to the specified object. Returns true if the object passed in matches the principal represented by the implementation of this interface.

param
a the principal to compare with.
return
true if the principal passed in is the same as that encapsulated by this principal, false otherwise.

        if (a instanceof PrincipalImpl){
	    for(int i = 0; i < add.length; i++) {
		if(add[i].equals ((InetAddress)((PrincipalImpl) a).getAddress()))
		    return true;
	    }
	    return false;
        } else {
            return false;
        }
    
public java.net.InetAddressgetAddress()
Returns the Internet Protocol (IP) address for this principal. In case of multiple address, the first one is returned.

return
the Internet Protocol (IP) address for this principal.

        return add[0];
    
public java.net.InetAddress[]getAddresses()
Returns the Internet Protocol (IP) address for this principal. In case of multiple address, the first one is returned.

return
the array of Internet Protocol (IP) addresses for this principal.

        return add;
    
public java.lang.StringgetName()
Returns the name of this principal.

return
the name of this principal.

        return add[0].toString();	
    
public inthashCode()
Returns a hashcode for this principal.

return
a hashcode for this principal.

        return add[0].hashCode();
    
public java.lang.StringtoString()
Returns a string representation of this principal. In case of multiple address, the first one is returned.

return
a string representation of this principal.

        return ("PrincipalImpl :"+add[0].toString());