Class ServiceName

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<ServiceName>

    public final class ServiceName
    extends java.lang.Object
    implements java.lang.Comparable<ServiceName>, java.io.Serializable
    Service name class.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ServiceName​(ServiceName parent, java.lang.String name)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ServiceName append​(java.lang.String... parts)
      Create a service name by appending name parts using this as a parent to the new ServiceName.
      ServiceName append​(ServiceName serviceName)
      Create a service name by appending name parts of the provided ServiceName using this as a parent.
      private static int calculateHashCode​(ServiceName parent, java.lang.String name)  
      ServiceName commonAncestorOf​(ServiceName other)
      Return the service name that is the nearest common ancestor of the this name and the given one.
      int compareTo​(ServiceName o)
      Compare two service names lexicographically.
      private int compareTo​(ServiceName o, int remainingLength)  
      boolean equals​(java.lang.Object o)
      Compare this service name to another service name.
      boolean equals​(ServiceName o)
      Compare this service name to another service name.
      java.lang.String getCanonicalName()
      Get the canonical name of this service name.
      private java.lang.StringBuilder getCanonicalName​(java.lang.StringBuilder target)  
      ServiceName getParent()
      Get the parent (enclosing) service name.
      java.lang.String getSimpleName()
      Get the simple (unqualified) name of this service.
      int hashCode()
      Return the hash code of this service name.
      private static java.lang.IllegalArgumentException invalidCodePoint​(int i)  
      private static java.lang.IllegalArgumentException invalidNameCharacter​(int i)  
      boolean isParentOf​(ServiceName other)
      Determine whether this service name is the same as, or a parent of, the given service name.
      static boolean isValidNameSegment​(java.lang.String part)
      Indicates if the name segment is valid.
      int length()
      Get the length (in segments) of this service name.
      static ServiceName of​(java.lang.String... parts)
      Create a ServiceName from a series of String parts.
      static ServiceName of​(ServiceName parent, java.lang.String... parts)
      Create a ServiceName from a series of String parts and a parent service name.
      static ServiceName parse​(java.lang.String original)
      Parse a string-form service name.
      private void readObject​(java.io.ObjectInputStream ois)  
      java.lang.String[] toArray()
      Convert this service name into an array of strings containing the segments of the name.
      private java.lang.String[] toArray​(int len)  
      java.lang.String toString()
      Get a string representation of this service name.
      private static java.lang.IllegalArgumentException unexpectedEnd()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • validNameSegmentPattern

        private static final java.util.regex.Pattern validNameSegmentPattern
      • name

        private final java.lang.String name
      • canonicalName

        private volatile java.lang.String canonicalName
      • hashCode

        private final transient int hashCode
      • canonicalNameUpdater

        private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ServiceName,​java.lang.String> canonicalNameUpdater
      • JBOSS

        public static final ServiceName JBOSS
        The root name "jboss".
      • hashCodeField

        private static final java.lang.reflect.Field hashCodeField
    • Constructor Detail

      • ServiceName

        private ServiceName​(ServiceName parent,
                            java.lang.String name)
    • Method Detail

      • of

        public static ServiceName of​(java.lang.String... parts)
        Create a ServiceName from a series of String parts.
        Parameters:
        parts - The string representations of the service name segments
        Returns:
        A ServiceName instance
      • of

        public static ServiceName of​(ServiceName parent,
                                     java.lang.String... parts)
        Create a ServiceName from a series of String parts and a parent service name.
        Parameters:
        parent - The parent ServiceName for this name
        parts - The string representations of the service name segments
        Returns:
        A ServiceName instance
      • calculateHashCode

        private static int calculateHashCode​(ServiceName parent,
                                             java.lang.String name)
      • append

        public ServiceName append​(java.lang.String... parts)
        Create a service name by appending name parts using this as a parent to the new ServiceName.
        Parameters:
        parts - The parts to append
        Returns:
        A new ServiceName
      • append

        public ServiceName append​(ServiceName serviceName)
        Create a service name by appending name parts of the provided ServiceName using this as a parent.
        Parameters:
        serviceName - The service name to use as the parts to append
        Returns:
        A new ServiceName
      • length

        public int length()
        Get the length (in segments) of this service name.
        Returns:
        the length
      • getParent

        public ServiceName getParent()
        Get the parent (enclosing) service name.
        Returns:
        the parent name
      • getSimpleName

        public java.lang.String getSimpleName()
        Get the simple (unqualified) name of this service.
        Returns:
        the simple name
      • isParentOf

        public boolean isParentOf​(ServiceName other)
        Determine whether this service name is the same as, or a parent of, the given service name.
        Parameters:
        other - the other name
        Returns:
        true if this service name is a parent
      • commonAncestorOf

        public ServiceName commonAncestorOf​(ServiceName other)
        Return the service name that is the nearest common ancestor of the this name and the given one.
        Parameters:
        other - the other name
        Returns:
        the nearest common ancestor, or null if they are unrelated
      • equals

        public boolean equals​(java.lang.Object o)
        Compare this service name to another service name. This is done by comparing the parents and leaf name of each service name.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        o - the other service name
        Returns:
        true if they are equal, false if they are not equal or the argument is not a service name or is null
      • equals

        public boolean equals​(ServiceName o)
        Compare this service name to another service name. This is done by comparing the parents and leaf name of each service name.
        Parameters:
        o - the other service name
        Returns:
        true if they are equal, false if they are not equal or the argument is null
      • hashCode

        public int hashCode()
        Return the hash code of this service name.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code
      • toString

        public java.lang.String toString()
        Get a string representation of this service name.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the string representation
      • getCanonicalName

        public java.lang.String getCanonicalName()
        Get the canonical name of this service name.
        Returns:
        the canonical name
      • isValidNameSegment

        public static boolean isValidNameSegment​(java.lang.String part)
        Indicates if the name segment is valid.
        Parameters:
        part - a name segment
        Returns:
        true if part is valid
      • parse

        public static ServiceName parse​(java.lang.String original)
                                 throws java.lang.IllegalArgumentException
        Parse a string-form service name. If the given name contains quoted sections (surrounded by '"' characters), then the section will be parsed as a quoted string with optional escaped characters. The set of valid escapes is similar to what is supported by the JLS (§3.3 and §3.10.6), with one exception: the string \0 is always parsed as a NUL character (0) and not as an octal escape sequence. Control characters are not allowed in any part of a name and must be escaped in a quoted section if they are present in the service name string. Whitespace characters are allowed only in a quoted section.
        Parameters:
        original - the string form of a service name
        Returns:
        a ServiceName instance
        Throws:
        java.lang.IllegalArgumentException - if the original is not valid
      • unexpectedEnd

        private static java.lang.IllegalArgumentException unexpectedEnd()
      • invalidCodePoint

        private static java.lang.IllegalArgumentException invalidCodePoint​(int i)
      • invalidNameCharacter

        private static java.lang.IllegalArgumentException invalidNameCharacter​(int i)
      • getCanonicalName

        private java.lang.StringBuilder getCanonicalName​(java.lang.StringBuilder target)
      • compareTo

        public int compareTo​(ServiceName o)
        Compare two service names lexicographically.
        Specified by:
        compareTo in interface java.lang.Comparable<ServiceName>
        Parameters:
        o - the other name
        Returns:
        -1 if this name collates before the argument, 1 if it collates after, or 0 if they are equal
      • compareTo

        private int compareTo​(ServiceName o,
                              int remainingLength)
      • readObject

        private void readObject​(java.io.ObjectInputStream ois)
                         throws java.lang.ClassNotFoundException,
                                java.io.IOException
        Throws:
        java.lang.ClassNotFoundException
        java.io.IOException
      • toArray

        public java.lang.String[] toArray()
        Convert this service name into an array of strings containing the segments of the name. If this array is passed into of(String...) it will yield a ServiceName which is equal to this one.
        Returns:
        the string array
      • toArray

        private java.lang.String[] toArray​(int len)