Class AddressTemplate

  • All Implemented Interfaces:
    Iterable<String>

    public final class AddressTemplate
    extends Object
    implements Iterable<String>
    Template for a DMR address which might contain multiple variable parts.

    An address template can be defined using the following BNF:

     <address template> ::= "/" | <segment>
     <segment>          ::= <tuple> | <segment>"/"<tuple>
     <tuple>            ::= <variable> | <key>"="<value>
     <variable>         ::= "{"<alpha>"}"
     <key>              ::= <alpha>
     <value>            ::= <variable> | <alpha> | "*"
     <alpha>            ::= <upper> | <lower>
     <upper>            ::= "A" | "B" | … | "Z"
     <lower>            ::= "a" | "b" | … | "z"
     

    Following variables are supported: - {domain.controller} - {selected.profile} - {selected.group} - {selected.server-config} - {selected.server}

    To get a fully qualified address from an address template use the method resolve(). For standalone mode the variables will resolve to an empty string. The values of the variables are managed by the StatementContext.

     AddressTemplate a2 = AddressTemplate.of("{selected.profile}");
     AddressTemplate a3 = AddressTemplate.of("{selected.profile}/subsystem=mail");
     AddressTemplate a4 = AddressTemplate.of("{selected.profile}/subsystem=mail/mail-session=*");
     
    • Method Detail

      • of

        public static AddressTemplate of​(String template)
        Creates a new address template from an encoded string template.
      • hashCode

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

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        the string representation of this address template
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if this template contains no tokens, false otherwise
      • size

        public int size()
        Returns:
        the number of tokens
      • append

        public AddressTemplate append​(String template)
        Appends the specified encoded template to this template and returns a new template. If the specified template does not start with a slash, '/' is automatically appended. '/' characters inside values must have been encoded using ModelNodeHelper.encodeValue(String).
        Parameters:
        template - the encoded template to append (makes no difference whether it starts with '/' or not)
        Returns:
        a new template
      • subTemplate

        public AddressTemplate subTemplate​(int fromIndex,
                                           int toIndex)
        Works like List.subList(int, int) over the tokens of this template and throws the same exceptions.
        Parameters:
        fromIndex - low endpoint (inclusive) of the sub template
        toIndex - high endpoint (exclusive) of the sub template
        Returns:
        a new address template containing the specified tokens.
        Throws:
        IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
      • getParent

        public AddressTemplate getParent()
        Returns:
        the parent address template or the root template
      • replaceWildcards

        public AddressTemplate replaceWildcards​(String wildcard,
                                                String... wildcards)
        Replaces one or more wildcards with the specified values starting from left to right and returns a new address template.

        This method does not resolve the address template. The returned template is still unresolved.

        Parameters:
        wildcard - the first wildcard (mandatory)
        wildcards - more wildcards (optional)
        Returns:
        a new (still unresolved) address template with the wildcards replaced by the specified values.
      • firstName

        public String firstName()
        Returns:
        the name of the first segment or null if this address template is empty.
      • firstValue

        public String firstValue()
        Returns:
        the value of the first segment or null if this address template is empty.
      • lastName

        public String lastName()
        Returns:
        the name of the last segment or null if this address template is empty.
      • lastValue

        public String lastValue()
        Returns:
        the value of the last segment or null if this address template is empty.
      • isOptional

        public boolean isOptional()
      • resolve

        public ResourceAddress resolve​(StatementContext context,
                                       String... wildcards)
        Resolve this address template against the specified statement context.
        Parameters:
        context - the statement context
        wildcards - An optional list of values which are used to resolve any wildcards in this address template from left to right
        Returns:
        a fully qualified resource address which might be empty, but which does not contain any tokens
      • jsAppend

        public AddressTemplate jsAppend​(Object address)
        Append an address to this addrress template and return a new one.
        Parameters:
        address - The address to append.
        Returns:
        a new address template with the specified address added at the end.