Class NetworkAddress

java.lang.Object
com.isode.dsapi.syntax.NetworkAddress
All Implemented Interfaces:
Comparable<NetworkAddress>

public class NetworkAddress extends Object implements Comparable<NetworkAddress>
This class stores information about a network address in the following formats: TELEX, URI and OTHER. The following address types are supported: ITOT, ITOTS, LDAP, LDAPS, IDM (in the future) and OTHER.

This is an immutable class.

Examples:

TELEX+00728722+IP-APP+11+127.0.0.1

TELEX+00728722+RFC-1006+03+localhost+19000

URI+0000+URL+itot://localhost:19000

URI+0000+URL+itots://localhost:19000

URI+0001+URL+ldaps://mv@127.0.0.1/

Future enhancements:

  1. Support IDM addresses.
Since:
15.0
Author:
mv
  • Constructor Details

    • NetworkAddress

      public NetworkAddress(String str) throws BadValueException
      Constructor to create an object with the given data.
      Parameters:
      str - String representation of the network address.
      Throws:
      BadValueException - if the input is invalid.
    • NetworkAddress

      public NetworkAddress(NetworkAddress.Type type, TelexData telexData) throws BadValueException
      Constructor to create an object with the given data.
      Parameters:
      type - Type of the network address.
      telexData - TELEX data format of the network address.
      Throws:
      BadValueException - if the input is invalid. Note that ITOTS does not support TelextData.
    • NetworkAddress

      public NetworkAddress(NetworkAddress.Type type, URIData uriData) throws BadValueException
      Constructor to create an object with the given data.
      Parameters:
      type - Type of the network address.
      uriData - URI data format of the network address.
      Throws:
      BadValueException - if the input is invalid.
    • NetworkAddress

      public NetworkAddress(NetworkAddress.Type type, String otherStr) throws BadValueException
      Constructor to create an object with the given data.
      Parameters:
      type - Type of the network address.
      otherStr - OTHER format of the network address.
      Throws:
      BadValueException - if the input is invalid.
    • NetworkAddress

      public NetworkAddress(NetworkAddress naToCopy, String hostName) throws BadValueException
      Constructor to create an object which is a copy of the given object but replaces the host name with the given host name. If the object to copy does not contain a host name, the constructed object contains the same information as the object to copy.
      Parameters:
      naToCopy - object to copy, must not be null
      hostName - Host name, must not be null
      Throws:
      BadValueException - if any of the input is invalid.
    • NetworkAddress

      public NetworkAddress(NetworkAddress naToCopy, String hostName, int portNo) throws BadValueException
      Creates a copy of a NetworkAddress, but with the hostName and portNo replaced with given values.
      Parameters:
      naToCopy - The NetworkAddress to copy. This can not be null.
      hostName - The new value for hostName. This can not be null.
      portNo - The new value for port no.
      Throws:
      BadValueException - Thrown if any of the input is invalid.
      Since:
      16.0
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getType

      public NetworkAddress.Type getType()
      Returns the type of the network address.
      Returns:
      Type of the network address.
    • getFormat

      public NetworkAddress.Format getFormat()
      Returns the format of the network address.
      Returns:
      Format of the network address.
    • getTelexData

      public TelexData getTelexData()
      Returns the TELEX data of the network address.
      Returns:
      TELEX data of the network address; NULL if the network address is not in the TELEX format.
    • getURIData

      public URIData getURIData()
      Returns the URI data of the network address.
      Returns:
      URI data of the network address; NULL if the network address is not in the URI format.
    • getHost

      public String getHost()
      Returns the host name of the network address if the network address is not in the OTHER format.
      Returns:
      Host name of the network address; NULL if the network address is in the OTHER format.
    • getPort

      public int getPort()
      Returns the port of the network address if the network address is not in the OTHER format.
      Returns:
      Port of the network address; -1 if the network address is in the OTHER format.
    • getOtherStr

      public String getOtherStr()
      Returns the OTHER data of the network address.
      Returns:
      OTHER data of the network address; NULL if the network address is not in the OTHER format.
    • convertInternetToItot

      public static String convertInternetToItot(String str)
      If the network address is stored using the "Internet=" MACRO but with the hostname (as in the old bind profile), then the presentation address syntax handler would convert the hostname into an IP address. If the caller wants to avoid that, they may convert the network address into an ITOT format that preserves the hostname. This function does just that.
      Parameters:
      str - String representation of a network address.
      Returns:
      ITOT form of the network address if the given address is in the "Internet=" form and the host name is not IPv4; the given string is returned as it is in all other circumstances.
    • getDisplayString

      public String getDisplayString()
      Returns string form to display.
      Returns:
      String form to display.
    • getCanonicalForm

      public NetworkAddress getCanonicalForm()
      The telex DATA and URI data are converted to their canonical forms. Other string is converted to lower case.
      Returns:
      canonical form of object.
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(NetworkAddress o)
      Specified by:
      compareTo in interface Comparable<NetworkAddress>
    • createNetworkAddress

      public static NetworkAddress createNetworkAddress(NetworkAddress.Type type, String hostStr, int port) throws BadValueException
      The network address for a given host name and port is returned. If the host is in IPv4 format, the network address is in telex format, otherwise in URI format - except for NetworkAddress.Type.ITOTS which is always in URI format.
      Parameters:
      type - any type except NetworkAddress.Type.OTHER
      hostStr - Host name
      port - port
      Returns:
      created network address, will never be null
      Throws:
      BadValueException - if the input is invalid