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

Hop

public class Hop extends Object
Routing algorithms return a list of hops to which the request is routed.

Fields Summary
protected String
host
Current host.
protected int
port
Port number.
protected String
transport
Connection transport.
protected boolean
explicitRoute
Explicit route from a ROUTE header.
protected boolean
defaultRoute
Default route from the proxy addr.
protected boolean
uriRoute
URI route from the requestURI.
Constructors Summary
public Hop(String hostName, int portNumber, String trans)
Create new hop given host, port and transport.

param
hostName hostname
param
portNumber port
param
trans transport
throws
IllegalArgument exception if some parameter has invalid value.

        
        if (portNumber < 0) {
            throw new IllegalArgumentException("Invalid port: " + portNumber);
        }
        
        host = hostName;
        port = portNumber;
        
        if (trans == null)
            transport = "UDP";
        else if (trans == "")
            transport = "UDP";
        else
            transport = trans;
    
public Hop(String hop)
Creates new Hop

param
hop is a hop string in the form of host:port/Transport
throws
IllegalArgument exception if string is not properly formatted or null.

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
                "create hop for " + hop);
        }
        
        if (hop == null)
            throw new IllegalArgumentException("Null arg!");
        
        try {
            StringTokenizer stringTokenizer = new StringTokenizer(hop + "/");
            String hostPort = stringTokenizer.getNextToken('/");
            // Skip over the slash.
            stringTokenizer.getNextChar();
            // get the transport string.
            transport = stringTokenizer.getNextToken('/").trim();
            if (transport == null)
                transport = "UDP";
            else if (transport == "")
                transport = "UDP";
            if (Utils.compareToIgnoreCase(transport, "UDP") != 0 &&
                    Utils.compareToIgnoreCase(transport, "TCP") != 0) {
                System.out.println("Bad transport string " + transport);
                throw new IllegalArgumentException(hop);
            }
            stringTokenizer = new StringTokenizer(hostPort+":");
            host = stringTokenizer.getNextToken(':");
            if (host == null || host.equals(""))
                throw new IllegalArgumentException("no host!");
            stringTokenizer.consume(1);
            String portString = null;
            portString = stringTokenizer.getNextToken(':");
            
            if (portString == null || portString.equals("")) {
                throw new IllegalArgumentException("no port!");
                // port = 5060;
            } else {
                try {
                    port = Integer.parseInt(portString);
                } catch (NumberFormatException ex) {
                    throw new IllegalArgumentException("Bad port spec");
                }
            }
            defaultRoute = true;
        } catch (ParseException ex) {
            throw new IllegalArgumentException("Bad hop");
        }
        
    
Methods Summary
public booleanequals(java.lang.Object other)
Compares fro equivalence.

param
other the object to compare
return
true if the object matches

        if (other.getClass().equals(this.getClass())) {
            Hop otherhop = (Hop) other;
            return (otherhop.host.equals(this.host) &&
                    otherhop.port == this.port);
        } else return false;
    
public java.lang.StringgetHost()
Retruns the host string.

return
host String

        return host;
    
public intgetPort()
Returns the port.

return
port integer.

        return port;
    
public java.lang.StringgetTransport()
Returns the transport string.

return
the transport string

        return transport;
    
public booleanisDefaultRoute()
Return true if this is a default route (next hop proxy address).

return
true if this is the default route

        return defaultRoute;
    
public booleanisExplicitRoute()
Return true if this is an explicit route (extacted from a ROUTE Header).

return
the explicit route

        return explicitRoute;
    
public booleanisURIRoute()
Return true if this is uriRoute.

return
true if this is the URI route

 return uriRoute; 
public voidsetDefaultRouteFlag()
Set the defaultRouteFlag.

 defaultRoute = true; 
public voidsetExplicitRouteFlag()
Set the explicitRoute flag.

 explicitRoute = true; 
public voidsetURIRouteFlag()
Set the URIRoute flag.

 uriRoute = true; 
public java.lang.StringtoString()
Encodes contents int a string.

return
encoded string of object contents

        return host + ":" + port + "/" + transport;