1 11 12 13 package com.sun.jmx.snmp.IPAcl; 14 15 16 17 import java.net.InetAddress ; 18 import java.net.UnknownHostException ; 19 import java.io.Serializable ; 20 21 22 28 29 class PrincipalImpl implements java.security.Principal , Serializable { 30 private InetAddress [] add = null; 31 32 35 public PrincipalImpl () throws UnknownHostException { 36 add = new InetAddress [1]; 37 add[0] = java.net.InetAddress.getLocalHost(); 38 } 39 40 51 public PrincipalImpl(String hostName) throws UnknownHostException { 52 if ((hostName.equals("localhost")) || (hostName.equals("127.0.0.1"))) { 53 add = new InetAddress [1]; 54 add[0] = java.net.InetAddress.getByName(hostName); 55 } 56 else 57 add = java.net.InetAddress.getAllByName( hostName ); 58 } 59 60 65 public PrincipalImpl(InetAddress address) { 66 add = new InetAddress [1]; 67 add[0] = address; 68 } 69 70 75 public String getName() { 76 return add[0].toString(); 77 } 78 79 87 public boolean equals(Object a) { 88 if (a instanceof PrincipalImpl){ 89 for(int i = 0; i < add.length; i++) { 90 if(add[i].equals ((InetAddress )((PrincipalImpl) a).getAddress())) 91 return true; 92 } 93 return false; 94 } else { 95 return false; 96 } 97 } 98 99 104 public int hashCode(){ 105 return add[0].hashCode(); 106 } 107 108 113 public String toString() { 114 return ("PrincipalImpl :"+add[0].toString()); 115 } 116 117 122 public InetAddress getAddress(){ 123 return add[0]; 124 } 125 126 131 public InetAddress [] getAddresses(){ 132 return add; 133 } 134 } 135 136 | Popular Tags |