Class PresentationAddress

java.lang.Object
com.isode.dsapi.syntax.IsodeSyntax<DSE.PSAPaddr>
com.isode.dsapi.syntax.PresentationAddress
All Implemented Interfaces:
Comparable<PresentationAddress>

public class PresentationAddress extends IsodeSyntax<DSE.PSAPaddr> implements Comparable<PresentationAddress>
Class representation of an PresentationAddress value.

This is an immutable class.

This class works by holding an DSE.PSAPaddr object, and providing a slightly more user-friendly set of methods which access and manipulate fields inside that object.

The ASN for a PresentationAddress is:

 PresentationAddress ::= SEQUENCE {
    pSelector  [0] OCTET STRING OPTIONAL,
    sSelector  [1] OCTET STRING OPTIONAL,
    tSelector  [2] OCTET STRING OPTIONAL,
    nAddresses [3] SET SIZE (1..MAX) OF OCTET STRING

Examples:

"0aZ-."/'0aff'H/'00'H/TELEX+00728722+IP-APP+11+127.0.0.1

"0aZ-."//TELEX+00728722+RFC-1006+03+127.0.0.1|URI+0000+URL+itot://[FFEF::1]| TELEX+00728722+RFC-1006+03+localhost+19000/

Since:
15.0
Author:
mv
  • Constructor Details

    • PresentationAddress

      public PresentationAddress(Selector presentationSelector, Selector sessionSelector, Selector transportSelector, List<NetworkAddress> naList) throws BadValueException, BadSyntaxException
      Create a new presentation address object from the given input.
      Parameters:
      presentationSelector - Presentation selector.
      sessionSelector - Session selector.
      transportSelector - Transport selector.
      naList - List containing network addresses.
      Throws:
      BadValueException - if any of the input is not a valid or the resulting presentation address is not valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(Selector presentationSelector, Selector sessionSelector, Selector transportSelector, NetworkAddress na) throws BadValueException, BadSyntaxException
      Create a new presentation address object from the given input. This can be used when there is a single network address in the presentation address.
      Parameters:
      presentationSelector - Presentation selector.
      sessionSelector - Session selector.
      transportSelector - Transport selector.
      na - A single network address.
      Throws:
      BadValueException - if any of the input is not a valid or the resulting presentation address is not valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(List<NetworkAddress> naList) throws BadValueException, BadSyntaxException
      Create a new presentation address object from the given input. This can be used when there is no selector in the presentation address.
      Parameters:
      naList - List containing network addresses.
      Throws:
      BadValueException - if the input is not a valid or the resulting presentation address is not valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(NetworkAddress na) throws BadValueException, BadSyntaxException
      Create a new presentation address object from the given input. This can be used when there is a single network address and no selectors in the presentation address.
      Parameters:
      na - A single network address.
      Throws:
      BadValueException - if the input is not a valid or the resulting presentation address is not valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(String paStr) throws BadValueException, BadSyntaxException
      Create a new presentation address object from a string representation.
      Parameters:
      paStr - String representation. Must not be null.
      Throws:
      BadValueException - if the input is not a valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(PresentationAddress paToCopy, String hostName) throws BadSyntaxException, 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:
      paToCopy - object to copy, must not be null
      hostName - Host name, must not be null
      Throws:
      BadValueException - if any of the input is not a valid or the resulting presentation address is not valid.
      BadSyntaxException - if it is not possible to parse the presentation address.
    • PresentationAddress

      public PresentationAddress(PresentationAddress paToCopy, String hostName, int portNo) throws BadValueException, BadSyntaxException
      Creates a copy of a PresentationAddress. But with the host names and port no replaced by the given value.
      Parameters:
      paToCopy - The Presentation Address to copy. This can not be null.
      hostName - The new value for host name. This can not be null.
      portNo - The new port no.
      Throws:
      BadValueException - If any of the input is invalid
      BadSyntaxException - If it was not possible to parse the PresentationAddress
      Since:
      16.0
    • PresentationAddress

      public PresentationAddress(byte[] ber) throws BadValueException, BadSyntaxException
      Create a new presentation address object from a byte array containing the BER representation of the object.
      Parameters:
      ber - BER representation of value. Must not be null.
      Throws:
      BadValueException - if ber doesn't hold a valid value for this attribute type
      BadSyntaxException - if it is not possible to parse the presentation address.
  • Method Details

    • getSyntaxInfo

      protected IsodeSyntax.SyntaxInfo getSyntaxInfo() throws BadSyntaxException
      Description copied from class: IsodeSyntax
      Subclasses must implement a method which returns a SyntaxInfo object that can be used by the IsodeSyntax class.
      Specified by:
      getSyntaxInfo in class IsodeSyntax<DSE.PSAPaddr>
      Returns:
      a SyntaxInfo describing the syntax represented by the subclass.
      Throws:
      BadSyntaxException - if no SyntaxInfo is available for this syntax.
    • parse

      protected void parse(byte[] berRepresentation) throws BadValueException
      Description copied from class: IsodeSyntax
      Set the object to contain a value based on the specified BER representation. If the BER is not valid, and exception will be thrown and the object will retain its previous value.

      Subclasses must implement a suitable syntax-specific method, which will contain code like this:

       protected void parse(byte[] berRepresentation) throws BadValueException  {
          com.isode.asn.modules.MHSR.GlobalDomainIdentifie savedVal = asnVal;
          try {
             asnVal = ASNConv.decode(
                   berRepresentation,
                   com.isode.asn.modules.MHSR.GlobalDomainIdentifier.class);
          } catch (BadValueException e) {
             asnVal = savedVal;
             throw e;
          }
       }
       
      (Replace the second parameter to the decode() method with a reference to the appropriate class).
      Specified by:
      parse in class IsodeSyntax<DSE.PSAPaddr>
      Parameters:
      berRepresentation - putative value in BER
      Throws:
      BadValueException
    • reset

      public void reset()
      Description copied from class: IsodeSyntax
      Clear all fields in the object. Following this operation, the object may not be a valid value, so may need to have fields set in it to become one.

      Subclasses should implement a method which clears all the asn fields, e.g.

         asnVal = new MHSR.GlobalDomainIdentifier();
         asnVal.setAdministration_domain_name(new AdministrationDomainName());
         asnVal.setCountry_name(new CountryName());
       
      Note that this method is called by the IsodeSyntax() constructor.
      Specified by:
      reset in class IsodeSyntax<DSE.PSAPaddr>
    • getMaxAddresses

      public static int getMaxAddresses()
      Static function returning the maximum number of network addresses allowed in a presentation address.
      Returns:
      Maximum number of network addresses in a presentation address.
    • getNetworkAddresses

      public List<NetworkAddress> getNetworkAddresses()
      Returns the vector containing the network addresses.
      Returns:
      List containing the network addresses.
    • getTransportSelector

      public Selector getTransportSelector()
      Returns the transport selector.
      Returns:
      Transport selector; NULL if absent.
    • getSessionSelector

      public Selector getSessionSelector()
      Returns the session selector.
      Returns:
      Session selector; NULL if absent.
    • getPresentationSelector

      public Selector getPresentationSelector()
      Returns the Presentation selector.
      Returns:
      presentation selector; NULL if absent.
    • getSelectorDisplay

      public static String getSelectorDisplay(Selector pSel, Selector sSel, Selector tSel)
      Parameters:
      pSel - Presentation selector, can be null
      sSel - Session selector, can be null
      tSel - Transport selector, can be null
      Returns:
      String form of selectors to display.
    • getSelectorDisplay

      public String getSelectorDisplay()
      Returns:
      String form of selectors to display.
    • getDisplayString

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

      public String getHostnames()
      Returns a String containing the names of any hosts that are contained in this object. Any hostname will only appear once in the returned String, regardless of how many separate network addresses refer to it. Multiple hostnames will be separated by a vertical bar ("|"), and will be ordered alphabetically

      So, for example

      • "psel"//"tsel"/URI+0000+URL+itot://william.isode.net:19999
        --> "william.isode.net"
      • URI+0000+URL+itot://william:19999|URI+0000+URL+itot://funky:1999|URI+0000+URL+itot://william:1999
        --> "funky|william"
      If no host names are available, the method returns an empty String ("")
      Returns:
      a String containing all the distinct hostnames that are contained in this object.
    • getFriendlyString

      public String getFriendlyString()
      Return a String containing a short "user-friendly" version of the PresentationAddress. The intention is that this String be used in situations where we want to enough information that's likely to allow the user to identify the address without having to overload the user with a full-blown String representation.

      The current implementation simply calls getHostnames(). A future implementation may do something more elaborate.

      Returns:
      a String representation of the PresentationAddress which contains enough information to be useful in most cases. If it's not possible to make a short name, then this method returns the empty String "".
    • getCanonicalForm

      public PresentationAddress getCanonicalForm() throws BadSyntaxException
      The selectors and network addresses are converted to their canonical forms. The network address list is sorted and duplicates are removed.
      Returns:
      canonical form of object.
      Throws:
      BadSyntaxException - if it is not possible to parse the presentation address.
    • equals

      public boolean equals(Object other)
      Description copied from class: IsodeSyntax
      Performs equality testing using the syntax handler for the relevant attribute type.

      Note that this method uses JNI to constructs AttributeValues and then call the syntax handler's comparison function, so it may not be ideal for use in resource-constrained situations (e.g. calling it loads of times in a loop)

      Overrides:
      equals in class IsodeSyntax<DSE.PSAPaddr>
      Parameters:
      other - another object of the same attribute type
      Returns:
      true if other is the same object, or one which has a valid value that matches this object's value so far as the syntax handler is concerned. A value of false means that object contains a different value, or that it is not possible to compare the values because no suitable syntax handler is available.
    • hashCode

      public int hashCode()
      Description copied from class: IsodeSyntax
      Returns a hashcode suitable for use by the Collection classes
      Overrides:
      hashCode in class IsodeSyntax<DSE.PSAPaddr>
      Returns:
      a hash code value for this object.
    • compareTo

      public int compareTo(PresentationAddress o)
      Specified by:
      compareTo in interface Comparable<PresentationAddress>
    • getAllAddresses

      public Set<String> getAllAddresses(boolean hostname, boolean ipv4, boolean ipv6, boolean removeLoopback)
      Returns the set of host names derived from the network address(es) of the presentation address. Also resolves the host names to IPv4 and IPv6 addresses and adds to returned set.

      Any item will only appear once in the returned set, regardless of how many separate network addresses refer to it or how many host names resolve to it.

      If no items are available as per request, the method returns an empty set.

      Parameters:
      hostname - TRUE if non-IPv4 and non-IPv6 host names need to be included in the set
      ipv4 - TRUE if IPv4 addresses need to be included in the set
      ipv6 - TRUE if IPv6 addresses need to be included in the set
      removeLoopback - TRUE if loopback addresses need to be removed
      Returns:
      set containing requested items
    • createDefaultServerAddress

      public static PresentationAddress createDefaultServerAddress(String hostStr) throws BadValueException, BadSyntaxException
      The default server address for a given host name consists of an ITOT and an LDAP network address. This method creates such a presentation address.
      Parameters:
      hostStr - Host name, must not be null
      Throws:
      BadValueException - if the host name is invalid or empty
      BadSyntaxException - if it is not possible to parse the presentation address.
    • createDefaultServerAddress

      public static PresentationAddress createDefaultServerAddress(String hostStr, boolean withMesh) throws BadValueException, BadSyntaxException
      The default server address for a given host name consists of an ITOT and an LDAP network address. This method creates such a presentation address.
      Parameters:
      hostStr - Host name, must not be null
      withMesh - Whether address should contain a multimaster address.
      Returns:
      Presentation address representing the default server address
      Throws:
      BadValueException - if the host name is invalid or empty
      BadSyntaxException - if it is not possible to parse the presentation address.