FileDocCategorySizeDatePackage
AddressFactory.javaAPI DocphoneME MR2 API (J2ME)8224Wed May 02 18:00:42 BST 2007gov.nist.siplite.address

AddressFactory

public class AddressFactory extends Object
Implementation of the JAIN-SIP address factory.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
public AddressFactory()
Creates a new instance ofAddressFactoryImpl.

    
Methods Summary
public AddresscreateAddress(java.lang.String displayName, URI uri)
Creates anAddress with the new display name and URI attribute values.

param
displayName - the new string value of the display name of the address. A null value does not set the display name.
param
uri - the new URI value of the address.
throws
ParseException which signals that an error has been reached unexpectedly while parsing the displayName value.
return
the new address

        if (uri == null)
            throw new NullPointerException("null URI");
        Address addressImpl = new Address();
        if (displayName != null) addressImpl.setDisplayName(displayName);
        addressImpl.setURI(uri);
        return addressImpl;

    
public AddresscreateAddress(URI uri)
Creates a new address.

param
uri the location to use
return
the address
exception
NullPointerException if uri is null

        if (uri == null)
            throw new NullPointerException("null address");
        Address addressImpl = new Address();
        addressImpl.setURI(uri);
        return addressImpl;
    
public AddresscreateAddress(java.lang.String address)
Creates anAddress with the new address string value. The address string is parsed in order to create the new Address instance. Create with a String value of "*" creates a wildcard address. The wildcard can be determined if (SipURIAddress.getURI).getUser() == *;.

param
address the new string value of the address.
return
the new Address
throws
ParseException which signals that an error has been reached unexpectedly while parsing the address value.
exception
NullPointerException if address is null

        if (address == null)
            throw new NullPointerException("null address");

        if (address.equals("*")) {
            Address addressImpl = new Address();
            addressImpl.setAddressType(Address.WILD_CARD);
            return addressImpl;
        } else {
            StringMsgParser smp = new StringMsgParser();
            return smp.parseAddress(address);
        }
    
public SipURIcreateSipURI(java.lang.String uri)
Creates a sip uri.

param
uri the uri to parse.
return
the new URI

        if (uri == null)
            throw new NullPointerException("null URI");
        try {
            StringMsgParser smp = new StringMsgParser();
            SipURI sipUri = smp.parseSIPUrl(uri);
            return (SipURI) sipUri;
        } catch (ParseException ex) {
            // throw new java.netURISyntaxException(uri, ex.getMessage());
            throw new ParseException(ex.getMessage(), 0);
        }

    
public SipURIcreateSipURI(java.lang.String user, java.lang.String host)
Creates a SipURI.

param
user the user
param
host the host.
return
the new SIP URI

        if (host == null)
            throw new NullPointerException("null host");

        StringBuffer uriString = new StringBuffer("sip:");
        if (user != null) {
            uriString.append(user);
            uriString.append("@");
        }

        // if host is an IPv6 string we should enclose it in sq brackets
        if (host.indexOf(':") != host.lastIndexOf(':")
        && host.trim().charAt(0) != '[")
            host = '[" + host + ']";

        uriString.append(host);

        StringMsgParser smp = new StringMsgParser();
        try {

            SipURI sipUri = smp.parseSIPUrl(uriString.toString());
            return sipUri;
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
    
public TelURLcreateTelURL(java.lang.String uri)
Creates a TelURL based on given URI string. The scheme or '+' should not be included in the phoneNumber string argument.

param
uri the new string value of the phoneNumber.
return
the new telephone URL
throws
URISyntaxException if the URI string is malformed.

        if (uri == null)
            throw new NullPointerException("null url");
        String telUrl = "tel:" + uri;
        try {
            StringMsgParser smp = new StringMsgParser();
            TelURL timp = (TelURL) smp.parseUrl(telUrl);
            return (TelURL) timp;
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
    
public URIcreateURI(java.lang.String uri)
Creates a URI based on given URI string. The URI string is parsed in order to create the new URI instance. Depending on the scheme the returned may or may not be aSipURI or TelURL cast as a URI.

param
uri the new string value of the URI.
return
the new SIP URI
throws
URISyntaxException if the URI string is malformed.
exception
NullPointerException if uri is null

        if (uri == null)
            throw new NullPointerException("null arg");
        try {
            Lexer lexer = new Lexer("sip_urlLexer", uri);
            Token token = lexer.peekNextToken();
            // For cases when URI begins with "<" and for TCK passing
            if (token.getTokenType() == LexerCore.LESS_THAN) {
                lexer.consume();
                token = lexer.peekNextToken();
                uri = uri.substring(uri.indexOf(LexerCore.LESS_THAN)+1,
                              uri.lastIndexOf(LexerCore.GREATER_THAN));
            }
            URLParser urlParser = new URLParser(uri);
            String scheme = token.getTokenValue();
            if (scheme == null || !Lexer.isValidScheme(scheme))
                throw new ParseException("bad scheme", 0);
            if (Utils.equalsIgnoreCase(scheme, SIPConstants.SCHEME_SIP)) {
                return (URI) urlParser.sipURL(token);
            } else if (Utils.equalsIgnoreCase(scheme,
                                              SIPConstants.SCHEME_SIPS)) {
                return (URI) urlParser.sipURL(token);
            } else if (Utils.equalsIgnoreCase(scheme,
                                              SIPConstants.SCHEME_TEL)) {
                return (URI) urlParser.telURL();
            }
        } catch (ParseException ex) {
            throw new ParseException(ex.getMessage(), 0);
        }
        return new URI(uri);