stateblock NetAddressNames augments RNetAddress {
addstate RNetAddress.address: java.net.InetAddress;
addstate RNetAddress.aname: String; // if address cannot be created
addstate RNetAddress.port: int; // port value of -1 used to represent unknown port
precode RNetAddress (adr: java.net.InetAddress, p: int) {
address = adr;
port = p;
}
precode RNetAddress (name: String, p: int) {
try {
// This is necessary only for testing (comparing to SecurityManager).
if (NCheck.isChecking ()) {
NCheck.noChecking ();
address = java.net.InetAddress.getByName (name);
NCheck.resumeChecking ();
} else {
address = java.net.InetAddress.getByName (name);
}
} catch (java.net.UnknownHostException e) {
address = null;
aname = name;
}
port = p;
}
precode RNetAddress (adr: java.net.InetAddress) {
address = adr;
port = -1;
}
precode setPort (p: int) {
port = p;
}
helper getName () returns String {
if (address != null) {
return address.getHostName ();
} else {
return aname;
}
}
helper getPort () returns int {
return port;
}
helper isMulticast () returns boolean {
return address.isMulticastAddress ();
}
helper getInetAddress () returns java.net.InetAddress {
return address;
}
helper toString () returns String {
return getName () + ":" + getPort ();
}
}
Naccio Home Page
University of Virginia, Computer Science