Class ResourceIdentifier


  • public final class ResourceIdentifier
    extends java.lang.Object
    Defines a common format for wrapping existing unique identifiers to provide additional context. This class provides utility method: #of(String) to parse an existing identifier or the ability to generate new identifiers by using provided context with method #of(String, String, String).

    Resource identifier specification:

    Resource Identifiers contain 4 components, prefixed by a format identifier ri and separated with periods: ri.<service>.<instance>.<type>.<locator>

    1. Service: a string that represents the service (or application) that namespaces the rest of the identifier. Must conform with regex pattern [a-z][a-z0-9\-]*
    2. Instance: an optionally empty string that represents a specific service cluster, to allow disambiguation of artifacts from different service clusters. Must conform to regex pattern ([a-z0-9][a-z0-9\-]*)?
    3. Type: a service-specific resource type to namespace a group of locators. Must conform to regex pattern [a-z][a-z0-9\-]*
    4. Locator: a string used to uniquely locate the specific resource. Must conform to regex pattern [a-zA-Z0-9\-\._]+
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Compares the specified object with this identifier for equality.
      java.lang.String getInstance()
      Returns the instance component.
      java.lang.String getLocator()
      Returns the locator component.
      java.lang.String getService()
      Returns the service component.
      java.lang.String getType()
      Returns the type component.
      int hashCode()
      Returns the hash code value for identifier.
      static boolean isValid​(java.lang.String rid)
      Checks if the input string is a valid resource identifier as defined in the specification.
      static boolean isValidInstance​(java.lang.String instance)
      Checks if the input string is a valid instance as defined in the specification.
      static boolean isValidLocator​(java.lang.String locator)
      Checks if the input string is a valid locator as defined in the specification.
      static boolean isValidService​(java.lang.String service)
      Checks if the input string is a valid service as defined in the specification.
      static boolean isValidType​(java.lang.String type)
      Checks if the input string is a valid type as defined in the specification.
      static ResourceIdentifier of​(java.lang.String rid)
      Generates a new resource identifier object from the input string.
      static ResourceIdentifier of​(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.String locator)
      Generates a new resource identifier object from each of the 4 input components.
      static ResourceIdentifier of​(java.lang.String service, java.lang.String instance, java.lang.String type, java.lang.String firstLocatorComponent, java.lang.String... locatorComponents)
      Generates a new resource identifier object from each of the input components.
      java.lang.String toString()
      Returns a string representation of this ResourceIdentifier.
      static ResourceIdentifier valueOf​(java.lang.String rid)
      Same as of(String).
      • Methods inherited from class java.lang.Object

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

      • getService

        public java.lang.String getService()
        Returns the service component.
        Returns:
        the service component from this identifier
      • getInstance

        public java.lang.String getInstance()
        Returns the instance component.
        Returns:
        the instance component from this identifier
      • getType

        public java.lang.String getType()
        Returns the type component.
        Returns:
        the type component from this identifier
      • getLocator

        public java.lang.String getLocator()
        Returns the locator component.
        Returns:
        the locator component from this identifier
      • toString

        public java.lang.String toString()
        Returns a string representation of this ResourceIdentifier. The string representation follows the format specification using the "ri" header followed by the 4 components separated by periods.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of this identifier
      • hashCode

        public int hashCode()
        Returns the hash code value for identifier. The hash code is calculated using the Java Objects.hash(Object...) method over each of the 4 components.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        the hash code value for this identifier
      • equals

        public boolean equals​(java.lang.Object obj)
        Compares the specified object with this identifier for equality. Returns true if and only if the specified object is also a resource identifier and contain exactly the same values for all 4 components.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to be compared for equality with this identifier
        Returns:
        true if the specified object is equal to this identifier, false otherwise
      • isValid

        public static boolean isValid​(java.lang.String rid)
        Checks if the input string is a valid resource identifier as defined in the specification.
        Parameters:
        rid - the input string to be checked
        Returns:
        true if and only if the input satisfy the resource identifier specification, false otherwise.
      • isValidService

        public static boolean isValidService​(java.lang.String service)
        Checks if the input string is a valid service as defined in the specification.
        Parameters:
        service - the input string to be checked
        Returns:
        true if and only if the input satisfy the service specification, false otherwise.
      • isValidInstance

        public static boolean isValidInstance​(java.lang.String instance)
        Checks if the input string is a valid instance as defined in the specification.
        Parameters:
        instance - the input string to be checked
        Returns:
        true if and only if the input satisfy the instance specification, false otherwise.
      • isValidType

        public static boolean isValidType​(java.lang.String type)
        Checks if the input string is a valid type as defined in the specification.
        Parameters:
        type - the input string to be checked
        Returns:
        true if and only if the input satisfy the type specification, false otherwise.
      • isValidLocator

        public static boolean isValidLocator​(java.lang.String locator)
        Checks if the input string is a valid locator as defined in the specification.
        Parameters:
        locator - the input string to be checked
        Returns:
        true if and only if the input satisfy the locator specification, false otherwise.
      • of

        public static ResourceIdentifier of​(java.lang.String rid)
        Generates a new resource identifier object from the input string. This method will validate that the input is a valid resource identifier string as defined by the specification prior to creating the object.
        Parameters:
        rid - the input string to be converted to a resource identifier
        Returns:
        a resource identifier object representing the input string
        Throws:
        java.lang.IllegalArgumentException - if the input string is not a valid resource identifier
      • of

        public static ResourceIdentifier of​(java.lang.String service,
                                            java.lang.String instance,
                                            java.lang.String type,
                                            java.lang.String locator)
        Generates a new resource identifier object from each of the 4 input components. Each component must satisfy the requirements as defined by the specification.
        Parameters:
        service - input representing the service component
        instance - input representing the instance component
        type - input representing the type component
        locator - input representing the locator component
        Returns:
        a resource identifier object representing the input components
        Throws:
        java.lang.IllegalArgumentException - if any of the inputs do not satisfy the resource identifier specification
      • of

        public static ResourceIdentifier of​(java.lang.String service,
                                            java.lang.String instance,
                                            java.lang.String type,
                                            java.lang.String firstLocatorComponent,
                                            java.lang.String... locatorComponents)
        Generates a new resource identifier object from each of the input components. The locator component is produced by joining together locatorComponent and locatorComponents with the default separator.
        Parameters:
        service - input representing the service component
        instance - input representing the instance component
        type - input representing the type component
        firstLocatorComponent - the first part of the locator component
        locatorComponents - the remaining locator components
        Returns:
        a resource identifier object representing the input components
        Throws:
        java.lang.IllegalArgumentException - if any of the inputs do not satisfy the resource identifier specification