Methods Summary |
---|
public java.lang.Object | clone()Clone this structure.
Address retval = new Address();
retval.addressType = this.addressType;
if (displayName != null) {
retval.displayName = new String(displayName);
}
if (address != null) {
retval.address = (URI) address.clone();
}
return (Object) retval;
|
public java.lang.String | encode()Encodes the address as a string and return it.
if (this.addressType == WILD_CARD) {
return "*";
}
StringBuffer encoding = new StringBuffer();
if (displayName != null) {
// Now the quotes are added to the displayName in AddressParser
// if they presented in the original header
encoding.append(displayName).append(Separators.SP);
}
if (address != null) {
if (addressType == NAME_ADDR || displayName != null) {
encoding.append(Separators.LESS_THAN);
}
encoding.append(address.encode());
if (addressType == NAME_ADDR || displayName != null) {
encoding.append(Separators.GREATER_THAN);
}
}
return encoding.toString();
|
public boolean | equals(java.lang.Object other)Compares two address specs for equality.
if (!this.getClass().equals(other.getClass())) {
return false;
}
Address that = (Address) other;
if (this.addressType == WILD_CARD &&
that.addressType != WILD_CARD) {
return false;
}
// Ignore the display name; only compare the address spec.
boolean retval = this.address.equals(that.address);
return retval;
|
public int | getAddressType()Gets the address type.
return addressType;
|
public java.lang.String | getDisplayName()Gets the display name.
return displayName;
|
public java.lang.String | getHost()Gets the host name from the address.
// if the address is wildcard ("*"), all properties are null
if (this.addressType == WILD_CARD) {
return null;
}
if (address.isSipURI()) {
// IMPL_NOTE: why not SipURI.getHost()?
return ((SipURI) address).getHostPort().getHost().getHostname();
}
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
"getHost() for wrong URI");
}
return null;
|
public HostPort | getHostPort()Gets the host port portion of the address spec.
// if the address is wildcard ("*"), all properties are null
if (this.addressType == WILD_CARD) {
return null;
}
if (address.isSipURI()) {
return ((SipURI) address).getHostPort();
}
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
"Wrong URI HostPort request");
}
return null;
|
public java.lang.String | getParameter(java.lang.String name)Returns the value associated with the named URI parameter.
URI uri = getURI();
if (uri.isSipURI()) {
return ((SipURI)uri).getParameter(name);
}
// IMPL_NOTE : return something for the tel URL
return null;
|
public java.lang.String[] | getParameterNames()Returns a String array of all parameter names.
if (addressType == WILD_CARD) {
return null;
}
Vector parameterNameList;
if (address.isSipURI()) {
parameterNameList = ((SipURI)address).getParameterNames();
} else if (address.isTelURL()) {
parameterNameList = ((TelURL)address).getParameterNames();
} else {
return null;
}
if (null == parameterNameList || parameterNameList.size() == 0) {
return null;
}
String parameterNames[] = new String[parameterNameList.size()];
for (int i = 0; i < parameterNameList.size(); i++)
parameterNames[i] = (String)parameterNameList.elementAt(i);
return parameterNames;
|
public java.lang.String | getPlainURI()Returns the URI part of the address (without parameters)
i.e. scheme:user@host:port.
if (addressType == WILD_CARD) {
return null;
}
return address.getPlainURI();
|
public int | getPort()Gets the port from the imbedded URI. This assumes that a SIP URL
is encapsulated in this address object.
// if the address is wildcard ("*"), return 0
if (this.addressType == WILD_CARD) {
return 0;
}
if (address.isSipURI()) {
SipURI uri = (SipURI) address;
int port = uri.getPort();
if (port < 0) {
port = uri.getDefaultPort();
}
return port;
}
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
"getPort() for wrong URI");
}
// if the port is not set, return the default (5060)
return 5060;
|
public java.lang.String | getScheme()Returns the scheme of SIP address.
if (addressType == WILD_CARD) {
return null;
}
return address.getScheme();
|
public URI | getURI()Returns the URI address of this Address. The type of URI can be
determined by the scheme.
return this.address;
|
public java.lang.String | getUser()Returns the user part of SIP address.
// RFC3261 p.222
// SIP-URI = "sip:" [ userinfo ] hostport
// uri-parameters [ headers ]
// SIPS-URI = "sips:" [ userinfo ] hostport
// uri-parameters [ headers ]
// userinfo = ( user / telephone-subscriber ) [ ":" password ] "@"
//
// This function returns user name/telephon number + password if it is
// existing
//
// if the address is wildcard ("*"), all properties are null
if (addressType == WILD_CARD) {
return null;
}
if (address.isSipURI()) {
SipURI uri = (SipURI) address;
String psswd = uri.getUserPassword();
if (null != psswd) {
return new String(uri.getUser() +
Separators.COLON +
psswd);
} else {
return uri.getUser();
}
} else if (address.isTelURL()) {
// IMPL_NOTE: Do we have TelURL only?
return ((TelURL) address).getPhoneNumber();
} else {
return null;
}
|
public java.lang.String | getUserAtHostPort()Gets the user@host:port for the address field. This assumes
that the encapsulated object is a SipURI.
// if the address is wildcard ("*"), all properties are null
if (addressType == WILD_CARD) {
return null;
}
if (address.isSipURI()) {
SipURI uri = (SipURI) address;
return uri.getUserAtHostPort();
}
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_JSR180,
"getUserAtHostPort() for wrong URI");
}
return address.toString();
|
public boolean | hasDisplayName()return true if DisplayName exist.
return (displayName != null);
|
public boolean | isSIPAddress()Return true if the embedded URI is a sip URI.
return address.isSipURI();
|
public boolean | isWildcard()This determines if this address is a wildcard address. That is
Address.getAddress.getUserInfo() == *;
return this.addressType == WILD_CARD;
|
public void | removeDisplayName()remove the displayName field
displayName = null;
|
public void | removeParameter(java.lang.String parameterName)Removes a parameter from the address.
// if the address is wildcard ("*"), all properties are null
if (this.addressType == WILD_CARD) {
return;
}
if (address.isSipURI()) {
((SipURI) address).removeParameter(parameterName);
}
|
public void | setAddressType(int atype)Sets the address type. The address can be NAME_ADDR, ADDR_SPEC or
WILD_CARD.
addressType = atype;
|
public void | setDisplayName(java.lang.String dn)Sets the display name member.
if (null == dn) {
throw new IllegalArgumentException("Null pointer argument");
}
if (dn.equals("")) {
// JSR180: Empty string "" removes the display name.
// getDisplayName() returns null if
// the display name is not available.
displayName = null;
} else {
if (false == Lexer.isValidDisplayName(dn)) {
throw new
IllegalArgumentException("Invalid display name " +
dn);
}
displayName = dn;
addressType = NAME_ADDR;
}
|
public void | setHost(java.lang.String host)Sets the host part of the SIP address.
if (address.isSipURI()) {
((SipURI)address).setHost(host);
} else
((TelURL)address).setPostDial(host);
|
public void | setParameter(java.lang.String name, java.lang.String value)Sets the named URI parameter to the specified value. If the
value is null
the parameter is interpreted as a parameter without value.
Existing parameter will be overwritten, otherwise the parameter
is added.
// Validating the name.
if (!Lexer.isValidName(name)) {
throw new IllegalArgumentException("Invalid parameter's name.");
}
// Validating the value.
if (!Lexer.isValidParameterValue(value)) {
throw new IllegalArgumentException("Invalid parameter's value.");
}
URI uri = getURI();
if (uri.isSipURI()) {
try {
((SipURI)uri).setParameter(name, value);
} catch (ParseException pe) {
throw new IllegalArgumentException(pe.getMessage());
}
}
// IMPL_NOTE : do something for the tel URL
|
public void | setURI(URI addr)Sets the address field.
address = (URI) addr;
|
public void | setURI(java.lang.String URI)Parses and creates the URI field.
URI uri = null;
try {
uri = StackConnector.addressFactory.createURI(URI);
} catch (ParseException pe) {
throw new IllegalArgumentException(pe.getMessage());
}
if (uri == null)
throw new IllegalArgumentException("The URI is invalid");
if (uri.isSipURI()) {
((SipURI)uri).clearUriParms();
// copy parameters value from old uri
if (address.isSipURI()) {
SipURI addr = (SipURI)address;
Vector names = addr.getParameterNames();
String value;
String name;
for (int i = 0; i < names.size(); i++) {
name = (String)names.elementAt(i);
value = addr.getParameter(name);
try {
((SipURI)uri).setParameter(name, value);
} catch (ParseException ex) {
// intentionally ignored
// parameters were parsed already
}
}
}
}
setURI(uri);
|
public void | setUser(java.lang.String user)Sets the user part of the embedded URI.
// if the address is wildcard ("*"), all properties are null
if (addressType == WILD_CARD) {
return;
}
if (address.isSipURI()) {
SipURI uri = (SipURI) address;
int colonPos;
if (null != user &&
(colonPos = user.indexOf(Separators.COLON)) != -1) {
uri.setUser(user.substring(0, colonPos));
uri.setUserPassword(user.substring(colonPos + 1));
} else {
uri.setUser(user);
uri.clearPassword();
}
} else if (address.isTelURL()) {
// IMPL_NOTE : check if the tel number is valid
((TelURL) address).setPhoneNumber(user);
} else {
throw new IllegalArgumentException("Can't set a user " +
"for this type of address");
}
|
public java.lang.String | toString()Creates a string representation of the address object.
return encode();
|