FileDocCategorySizeDatePackage
SipAddress.javaAPI DocphoneME MR2 API (J2ME)9164Wed May 02 18:00:42 BST 2007javax.microedition.sip

SipAddress

public class SipAddress extends Object
SipAddress provides a generic SIP address parser.
see
JSR180 spec, v 1.0.1, p 52-57

Fields Summary
private gov.nist.siplite.address.Address
address
the nist-siplite corresponding address
Constructors Summary
public SipAddress(String address)
Construct a new SipAddress from string.

see
JSR180 spec, v 1.0.1, p 60

        try {
            this.address =
                    StackConnector.addressFactory.createAddress(address);
        } catch (ParseException pe) {
            throw new IllegalArgumentException(pe.getMessage());
        }

        // NullPointerException may be thrown in case if address is null.
        // We don't catch it because TCK expects this exception.
    
public SipAddress(String displayName, String URI)
Construct a new SipAddress from display name and URI.

param
displayName - user display name
param
URI - SIP URI
throws
IllegalArgumentException - if there was an error in parsing the arguments.

        try {
            URI uri = StackConnector.addressFactory.createURI(URI);
            this.address =
                StackConnector.addressFactory.createAddress(displayName, uri);
            if (false == address.isSIPAddress()) {
                throw new IllegalArgumentException("Wrong requested scheme");
            }
        } catch (ParseException pe) {
            throw new IllegalArgumentException(pe.getMessage());
        } catch (java.lang.NullPointerException pe) {
            throw new IllegalArgumentException(pe.getMessage());
        }
    
Methods Summary
public java.lang.StringgetDisplayName()
Returns the display name of SIP address.

return
display name or null if not available

        return address.getDisplayName();
    
public java.lang.StringgetHost()
Returns the host part of the SIP address.

return
host part of this address.

        return address.getHost();
    
public java.lang.StringgetParameter(java.lang.String name)
Returns the value associated with the named URI parameter.

param
name - the name of the parameter
return
the value of the named parameter, or empty string for parameters without value and null if the parameter is not defined

        return address.getParameter(name);
    
public java.lang.String[]getParameterNames()
Returns a String array of all parameter names.

return
String array of parameter names. Returns null if the address does not have any parameters.

        return address.getParameterNames();
    
public intgetPort()
Returns the port number of the SIP address. If port number is not set, return 5060. If the address is wildcard "*" return 0.

return
the port number

        return address.getPort();
    
public java.lang.StringgetScheme()
Returns the scheme of SIP address.

return
the scheme of this SIP address e.g. sip or sips

        return address.getScheme();
    
public java.lang.StringgetURI()
Returns the URI part of the address (without parameters) i.e. scheme:user@host:port.

return
the URI part of the address

        return address.getPlainURI();
    
public java.lang.StringgetUser()
Returns the user part of SIP address.

return
user part of SIP address. Returns null if the user part is missing.

        return address.getUser();
    
public voidremoveParameter(java.lang.String name)
Removes the named URI parameter.

param
name - name of the parameter to be removed

        URI uri = address.getURI();
        if (uri.isSipURI())
            ((SipURI)uri).removeParameter(name);
        // IMPL_NOTE : do something for the tel URL
    
public voidsetDisplayName(java.lang.String name)
Sets the display name. Empty string "" removes the display name.

param
name - display name
throws
IllegalArgumentException - if the display name is invalid

        address.setDisplayName(name);
    
public voidsetHost(java.lang.String host)
Sets the host part of the SIP address.

param
host - host part
throws
IllegalArgumentException - if the post part is invalid

        address.setHost(host);
    
public voidsetParameter(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.

param
name - the named URI parameter
param
value - the value
throws
IllegalArgumentException - if the parameter is invalid RFC 3261, chapter 19.1.1 SIP and SIPS URI Components "URI parameters" p.149

        address.setParameter(name, value);
    
public voidsetPort(int port)
Sets the port number of the SIP address. Valid range is 0-65535, where 0 means that the port number is removed from the address URI.

param
port port number, valid range 0-65535, 0 means that port number is removed from the address URI.
throws
IllegalArgumentException if the port number is invalid.

        if (port < 0 || port > 65535) {
            throw new IllegalArgumentException("Invalid port: " + port);
        }

        URI uri = address.getURI();
        if (uri.isSipURI()) {
            if (port == 0) {
                ((SipURI)uri).removePort();
            } else {
                ((SipURI)uri).setPort(port);
            }
        }
        // IMPL_NOTE : do something for the tel URL
    
public voidsetScheme(java.lang.String scheme)
Sets the scheme of SIP address. Valid scheme format is defined in RFC 3261 [1] p.224

param
scheme the scheme of SIP address
throws
IllegalArgumentException if the scheme is invalid

        address.getURI().setScheme(scheme);
    
public voidsetURI(java.lang.String URI)
Sets the URI part of the SIP address (without parameters) i.e. scheme:user@host:port. Possible URI parameters are ignored.

param
URI - URI part
throws
IllegalArgumentException - if the URI is invalid

        address.setURI(URI);
    
public voidsetUser(java.lang.String user)
Sets the user part of SIP address.

param
user - the user part
throws
IllegalArgumentException - if the user part is invalid

        address.setUser(user);
    
public java.lang.StringtoString()
Returns a fully qualified SIP address, with display name, URI and URI parameters. If display name is not specified only a SIP URI is returned. If the port is not explicitly set (to 5060 or other value) it will be omitted from the address URI in returned String.

return
a fully qualified SIP name address, SIP or SIPS URI

        return address.toString();