javax.microedition.sip
Class SipAddress

java.lang.Object
  extended byjavax.microedition.sip.SipAddress

public class SipAddress
extends java.lang.Object

SipAddress provides a generic SIP address parser. This class can be used to parse either full SIP name addresses like: BigGuy <sip:[email protected]> or SIP/SIPS URIs like: sip:[email protected];user=phone or sips:[email protected];transport=tcp.

Correspondingly, valid SIP addresses can be constructed with this class.

SipAddress has following functional requirements:
- SipAddress does not escape address strings.
- SipAddress ignores headers part of SIP URI.
- SipAddress valid scheme format is the same as defined in SIP BNF for absolute URI.
- The valid Contact address "*" is accepted in SipAddress. In this case all properties will be null and port number is 0. Yet toString() method will return the value "*".

Reference, SIP 3261 [1] p.153 Example SIP and SIPS URIs and p.228 name-addr in SIP BNF specification.


Constructor Summary
SipAddress(java.lang.String address)
          Construct a new SipAddress from string.
SipAddress(java.lang.String displayName, java.lang.String URI)
          Construct a new SipAddress from display name and URI.
 
Method Summary
 java.lang.String getDisplayName()
          Returns the display name of SIP address.
 java.lang.String getHost()
          Returns the host part of the SIP address.
 java.lang.String getParameter(java.lang.String name)
          Returns the value associated with the named URI parameter.
 java.lang.String[] getParameterNames()
          Returns a String array of all parameter names.
 int getPort()
          Returns the port number of the SIP address.
 java.lang.String getScheme()
          Returns the scheme of SIP address.
 java.lang.String getURI()
          Returns the URI part of the address (without parameters) i.e.
 java.lang.String getUser()
          Returns the user part of SIP address.
 void removeParameter(java.lang.String name)
          Removes the named URI parameter.
 void setDisplayName(java.lang.String name)
          Sets the display name.
 void setHost(java.lang.String host)
          Sets the host part of the SIP address.
 void setParameter(java.lang.String name, java.lang.String value)
          Sets the named URI parameter to the specified value.
 void setPort(int port)
          Sets the port number of the SIP address.
 void setScheme(java.lang.String scheme)
          Sets the scheme of SIP address.
 void setURI(java.lang.String URI)
          Sets the URI part of the SIP address (without parameters) i.e.
 void setUser(java.lang.String user)
          Sets the user part of SIP address.
 java.lang.String toString()
          Returns a fully qualified SIP address, with display name, URI and URI parameters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SipAddress

public SipAddress(java.lang.String address)
           throws java.lang.IllegalArgumentException
Construct a new SipAddress from string. The string can be either name address:

Display Name <sip:user:password@host:port;uri-parameters>

or plain SIP URI:

sip:user:password@host:port;uri-parameters

Parameters:
address - SIP address as String
Throws:
java.lang.IllegalArgumentException - if there was an error in parsing the address.

SipAddress

public SipAddress(java.lang.String displayName,
                  java.lang.String URI)
           throws java.lang.IllegalArgumentException
Construct a new SipAddress from display name and URI.

Parameters:
displayName - user display name
URI - SIP URI
Throws:
java.lang.IllegalArgumentException - if there was an error in parsing the arguments.
Method Detail

getDisplayName

public java.lang.String getDisplayName()
Returns the display name of SIP address.

Returns:
display name or null if not available

setDisplayName

public void setDisplayName(java.lang.String name)
                    throws java.lang.IllegalArgumentException
Sets the display name. Empty string "" removes the display name.

Throws:
java.lang.IllegalArgumentException - if the display name is invalid

getScheme

public java.lang.String getScheme()
Returns the scheme of SIP address.

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

setScheme

public void setScheme(java.lang.String scheme)
               throws java.lang.IllegalArgumentException
Sets the scheme of SIP address. Valid scheme format is defined in RFC 3261 [1] p.224

Throws:
java.lang.IllegalArgumentException - if the scheme is invalid

getUser

public java.lang.String getUser()
Returns the user part of SIP address.

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

setUser

public void setUser(java.lang.String user)
             throws java.lang.IllegalArgumentException
Sets the user part of SIP address.

Throws:
java.lang.IllegalArgumentException - if the user part is invalid

getURI

public java.lang.String getURI()
Returns the URI part of the address (without parameters) i.e. scheme:user@host:port.

Returns:
the URI part of the address

setURI

public void setURI(java.lang.String URI)
            throws java.lang.IllegalArgumentException
Sets the URI part of the SIP address (without parameters) i.e. scheme:user@host:port. Possible URI parameters are ignored.

Throws:
java.lang.IllegalArgumentException - if the URI is invalid

getHost

public java.lang.String getHost()
Returns the host part of the SIP address.

Returns:
host part of this address.

setHost

public void setHost(java.lang.String host)
             throws java.lang.IllegalArgumentException
Sets the host part of the SIP address.

Throws:
java.lang.IllegalArgumentException - if the host is invalid

getPort

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

Returns:
the port number

setPort

public void setPort(int port)
             throws java.lang.IllegalArgumentException
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.

Parameters:
port - port number, valid range 0-65535, 0 means that port number is removed from the address URI
Throws:
java.lang.IllegalArgumentException - if the port number is invalid

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value associated with the named URI parameter.

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

setParameter

public void setParameter(java.lang.String name,
                         java.lang.String value)
                  throws java.lang.IllegalArgumentException
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.

Throws:
java.lang.IllegalArgumentException - if the parameter is invalid RFC 3261, chapter 19.1.1 SIP and SIPS URI Components "URI parameters" p.149

removeParameter

public void removeParameter(java.lang.String name)
Removes the named URI parameter.


getParameterNames

public java.lang.String[] getParameterNames()
Returns a String array of all parameter names.

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

toString

public java.lang.String toString()
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.

Returns:
a fully qualified SIP name address, SIP or SIPS URI


Copyright © 2004 Nokia Corporation. All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.