Class BasePrefixResourceName<T,​E extends Exception>

    • Field Detail

      • wildcardMatch

        protected final T wildcardMatch
        The object to return on a wildcard match.
      • superResourceMatch

        protected final T superResourceMatch
        The object to return on a super-resource match.
      • subResourceMatch

        protected final T subResourceMatch
        The object to return on a sub-resource match.
      • noMatch

        protected final T noMatch
        The object to return on no match.
      • exactMatch

        protected final T exactMatch
        The object to return on an exact match.
      • delimiter

        protected String delimiter
        Delimiter.
      • caseSensitive

        protected boolean caseSensitive
        Whether matching is case sensitive.
      • wildcard

        protected String wildcard
        String indicating default wild card pattern.
      • wildcardLength

        protected int wildcardLength
        String indicating default wild card pattern length.
      • oneLevelWildcard

        protected String oneLevelWildcard
        String indicating default one level wild card pattern.
      • oneLevelWildcardLength

        protected int oneLevelWildcardLength
        String indicating default one level wild card pattern length.
      • wildcardEmbedded

        protected boolean wildcardEmbedded
        boolean indicating if the wild card pattern is embedded in the one level wild card pattern eg. wildcard is "*" while one level wild card pattern is "-*-".
      • oneLevelWildcardEmbedded

        protected boolean oneLevelWildcardEmbedded
        boolean indicating if the one level wild card pattern is embedded in the wild card pattern eg. one level wildcard is "*" while wild card pattern is "-*-".
      • debug

        protected Debug debug
        Debug instance.
    • Constructor Detail

      • BasePrefixResourceName

        protected BasePrefixResourceName​(Debug debug,
                                         T exactMatch,
                                         T noMatch,
                                         T subResourceMatch,
                                         T superResourceMatch,
                                         T wildcardMatch)
        Constructs a new BasePrefixResourceName instance.
        Parameters:
        debug - The debug instance.
        exactMatch - The object to return on an exact match.
        noMatch - The object to return on no match.
        subResourceMatch - The object to return on a sub-resource match.
        superResourceMatch - The object to return on a super-resource match.
        wildcardMatch - The object to return on a wildcard match.
    • Method Detail

      • initialize

        public void initialize​(Map configParams)
        Initializes the resource name with configuration information, usally set by the administrators. The main configration information retrived is mainly like wild card pattern used, one level wild card pattern used, case sensitivity etc. Subclasses may want to populate the following protected fields:
        • delimiter
        • caseSensitive
        • wildcard
        • oneLevelWildcard
        • oneLevelWildcardLength
        • wildcardLength
        • wildcardEmbedded
        • oneLevelWildcardEmbedded
        Specified by:
        initialize in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        configParams - configuration parameters as a map. The keys of the map are the configuration paramaters. Each key is corresponding to one String value which specifies the configuration paramater value.
      • getServiceTypeNames

        public Set<String> getServiceTypeNames()
        Description copied from interface: BaseResourceName
        Returns the service type names for which the resource name object can be used.
        Specified by:
        getServiceTypeNames in interface BaseResourceName<T,​E extends Exception>
        Returns:
        service type names for which the resource comparator can be used
      • compare

        public T compare​(String requestResource,
                         String targetResource,
                         boolean wildcardCompare)
        Compares two resources. Description: The targetResource may contain wildcard or one level wildcard pattern but not both which matches zero or more characters. The wildcard character can show up anywhere within the string. The targetResource can contain any number of one type of wildcard characters. Based on the type of wild card in the resource either regular wildcard comparison is done or one level wild card comparison is done. One of the five possible match types is returned based on how the two resource strings are related. The comparison starts from the beginning of the resource strings. ResourceMatch.NO_MATCH means two resources don't match. ResourceMatch.EXACT_MATCH means two resources match. ResourceMatch.SUB_RESOURCE_MATCH means targetResource is the sub resource of the requestResource. ResourceMatch.SUPER_RESOURCE_MATCH means targetResource is the super resource of the requestResource. ResourceMatch.WILDCARD_MATCH means two resources match with respect to the wildcard.
        Specified by:
        compare in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        requestResource - name of the resource which will be compared
        targetResource - name of the resource which will be compared with
        wildcardCompare - flag for wildcard comparison
        Returns:
        returns ResourceMatch that specifies if the resources are exact match, or otherwise.
      • normalizeTargetResource

        protected String normalizeTargetResource​(String targetResource)
        If further normalization of targetResource is required during comparison, it can be added here.
        Parameters:
        targetResource - The target resource from the compare method.
        Returns:
        The normalized target resource (unmodified by default).
      • normalizeRequestResource

        protected String normalizeRequestResource​(String requestResource)
        If further normalization of requestResource is required during comparison, it can be added here.
        Parameters:
        requestResource - The target resource from the compare method.
        Returns:
        The normalized target resource (unmodified by default).
      • oneLevelWildcardCompare

        public T oneLevelWildcardCompare​(String requestResource,
                                         String targetResource,
                                         boolean wildcardCompare)
        Compares two resources containing one level wild card(s). Description: The targetResource may contain one level wildcard '-*-' ( configurable) which matches zero or more characters, at the same level. So a/b/-*-/d will WILDCARD_MATCH a/b/df/d where -*- matches 'df' but not a/b/c/f/d since -*- does not match "c/f". So in other words the matching pattern for the one level wildcard cannot go across delimiter boundary. The wildcard character can show up anywhere within the string. The targetResource can contain any number of wildcard characters. One of the five possible match types is returned based on how the two resource strings are related. The comparison starts from the beginning of the reource strings. ResourceMatch.NO_MATCH means two resources don't match. ResourceMatch.EXACT_MATCH means two resources match. ResourceMatch.SUB_RESOURCE_MATCH means targetResource is the sub resource of the requestResource. ResourceMatch.SUPER_RESOURCE_MATCH means targetResource is the super resource of the requestResource. ResourceMatch.WILDCARD_MATCH means two resources match with respect to the wildcard.
        Parameters:
        requestResource - name of the resource which will be compared
        targetResource - name of the resource which will be compared with
        wildcardCompare - flag for wildcard comparison
        Returns:
        returns ResourceMatch that specifies if the resources are exact match, or otherwise.
      • append

        public String append​(String superResource,
                             String subResource)
        Appends sub-resource to super-resource.
        Specified by:
        append in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        superResource - name of the super-resource to be appended to
        subResource - name of the sub-resource to be appended
        Returns:
        returns the combination resource.
      • getSubResource

        public String getSubResource​(String resource,
                                     String superResource)
        Gets sub-resource from an original resource minus a super resource. This is the complementary method of append().
        Specified by:
        getSubResource in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        resource - name of the original resource consisting of the second parameter superResource and the returned value
        superResource - name of the super-resource which the first parameter begins with.
        Returns:
        returns the sub-resource which the first paramter ends with. If the first parameter doesn't begin with the the first parameter, then the return value is null.
      • split

        public String[] split​(String res)
        Splits the given resource name.
        Specified by:
        split in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        res - the resource name to be split
        Returns:
        an array of (String) split resource names
      • canonicalize

        public String canonicalize​(String res)
                            throws E extends Exception
        This method is used to canonicalize a prefix resource It throws an Exception if both regular multi wildcard and one level wild card appears is same resource String. Also removes ( purges) mutiple consecutive delimiters to 1, in the URI.
        • So http://xyz.com///abc///d becomes http://xyz.com/abc/d where "/" is the delimiter.
        Specified by:
        canonicalize in interface BaseResourceName<T,​E extends Exception>
        Parameters:
        res - the prefix resource string to be canonicalized
        Returns:
        the prefix resource string in its canonicalized form.
        Throws:
        E - if resource is invalid
        E extends Exception
      • constructResourceInvalidException

        protected abstract E constructResourceInvalidException​(Object[] args)
        Construct the exception that will be thrown if the resource is invalid during canonicalize.
        Parameters:
        args - The exception arguments.
        Returns:
        An exception.