Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
Product of NIST/ITL Advanced Networking Technologies Division (ANTD). * /
 
 package gov.nist.javax.sip.address;
 
 /*
  * BUG Fix from Antonis Kadris.
  */
Address structure. Imbeds a URI and adds a display name.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.14 $ $Date: 2010-07-27 10:55:29 $
 
 public final class AddressImpl
     extends NetObject
     implements javax.sip.address.Address {
 
 
     private static final long serialVersionUID = 429592779568617259L;

    
Constant field.
 
     public static final int NAME_ADDR = 1;

    
constant field.
 
     public static final int ADDRESS_SPEC = 2;

    
Constant field.
 
     public static final int WILD_CARD = 3;
 
     protected int addressType;

    
displayName field
 
     protected String displayName;

    
address field
 
     protected GenericURI address;

    
Match on the address only. Dont care about the display name.
 
 
     public boolean match(Object other) {
         // TODO -- add the matcher;
         if (other == null)
             return true;
         if (!(other instanceof Address))
             return false;
         else {
             AddressImpl that = (AddressImplother;
             if (that.getMatcher() != null)
                 return that.getMatcher().match(this.encode());
             else if (that.displayName != null && this. == null)
                 return false;
             else if (that.displayName == null)
                 return .match(that.address);
             else
                 return .equalsIgnoreCase(that.displayName)
                     && .match(that.address);
         }
 
     }

    
Get the host port portion of the address spec.

Returns:
host:port in a HostPort structure.
    public HostPort getHostPort() {
        if (!( instanceof SipUri))
            throw new RuntimeException("address is not a SipUri");
        SipUri uri = (SipUri;
        return uri.getHostPort();
    }

    
Get the port from the imbedded URI. This assumes that a SIP URL is encapsulated in this address object.

Returns:
the port from the address.
    public int getPort() {
        if (!( instanceof SipUri))
            throw new RuntimeException("address is not a SipUri");
        SipUri uri = (SipUri;
        return uri.getHostPort().getPort();
    }

    
Get the user@host:port for the address field. This assumes that the encapsulated object is a SipUri.

Returns:
string containing user@host:port.
    public String getUserAtHostPort() {
        if ( instanceof SipUri) {
            SipUri uri = (SipUri;
            return uri.getUserAtHostPort();
        } else
            return .toString();
    }

    
Get the host name from the address.

Returns:
the host name.
    public String getHost() {
        if (!( instanceof SipUri))
            throw new RuntimeException("address is not a SipUri");
        SipUri uri = (SipUri;
        return uri.getHostPort().getHost().getHostname();
    }

    
Remove a parameter from the address.

Parameters:
parameterName is the name of the parameter to remove.
    public void removeParameter(String parameterName) {
        if (!( instanceof SipUri))
            throw new RuntimeException("address is not a SipUri");
        SipUri uri = (SipUri;
        uri.removeParameter(parameterName);
    }

    
Encode the address as a string and return it.

Returns:
String canonical encoded version of this address.
    public String encode() {
        return encode(new StringBuilder()).toString();
    }
    public StringBuilder encode(StringBuilder buffer) {
        if (this. == ) {
            buffer.append('*');
        }
        else {
            if ( != null) {
                buffer.append()
                        .append()
                        .append()
                        .append();
            }
            if ( != null) {                               
                if ( ==  ||  != null)
                    buffer.append();
                .encode(buffer);
                if ( ==  ||  != null)
                    buffer.append();
            }
        }
        return buffer;
    }
    public AddressImpl() {
        this. = ;
    }

    
Get the address type;

Returns:
int
    public int getAddressType() {
        return ;
    }

    
Set the address type. The address can be NAME_ADDR, ADDR_SPEC or WILD_CARD

Parameters:
atype int to set
    public void setAddressType(int atype) {
         = atype;
    }

    
get the display name

Returns:
String
    public String getDisplayName() {
        return ;
    }

    
Set the displayName member

Parameters:
displayName String to set
    public void setDisplayName(String displayName) {
        this. = displayName;
        this. = ;
    }

    
Set the address field

Parameters:
address SipUri to set
    public void setAddess(javax.sip.address.URI address) {
        this. = (GenericURIaddress;
    }

    
hashCode impelmentation
    public int hashCode() {
        return this..hashCode();
    }

    
Compare two address specs for equality.

Parameters:
other Object to compare this this address
Returns:
boolean
    public boolean equals(Object other) {
        if (this==otherreturn true;
        if (other instanceof Address) {
            final Address o = (Addressother;
            // Don't compare display name (?)
            return this.getURI().equalso.getURI() );
        }
        return false;
    }

    
return true if DisplayName exist.

Returns:
boolean
    public boolean hasDisplayName() {
        return ( != null);
    }

    
remove the displayName field
    public void removeDisplayName() {
         = null;
    }

    
Return true if the imbedded URI is a sip URI.

Returns:
true if the imbedded URI is a SIP URI.
    public boolean isSIPAddress() {
        return  instanceof SipUri;
    }

    
Returns the URI address of this Address. The type of URI can be determined by the scheme.

Returns:
address parmater of the Address object
    public URI getURI() {
        return this.;
    }

    
This determines if this address is a wildcard address. That is Address.getAddress.getUserInfo() == *;

Returns:
true if this name address is a wildcard, false otherwise.
    public boolean isWildcard() {
        return this. == ;
    }

    
Sets the URI address of this Address. The URI can be either a TelURL or a SipURI.

Parameters:
address - the new URI address value of this NameAddress.
    public void setURI(URI address) {
        this. = (GenericURIaddress;
    }

    
Set the user name for the imbedded URI.

Parameters:
user -- user name to set for the imbedded URI.
    public void setUser(String user) {
        ((SipUrithis.).setUser(user);
    }

    
Mark this a wild card address type. Also set the SIP URI to a special wild card address.
    public void setWildCardFlag() {
        this. = ;
        this. = new SipUri();
        ((SipUri)this.).setUser("*");
    }
    public Object clone() {
        AddressImpl retval = (AddressImplsuper.clone();
        if (this. != null)
            retval.address = (GenericURIthis..clone();
        return retval;
    }
New to GrepCode? Check out our FAQ X