Class BasePrefixResourceName<T,E extends Exception>
- java.lang.Object
-
- org.forgerock.openam.shared.resourcename.BasePrefixResourceName<T,E>
-
- Type Parameters:
T- The type that the compare method is going to return instances of.E- The exception type thrown by the canonicalize method.
- All Implemented Interfaces:
BaseResourceName<T,E>
- Direct Known Subclasses:
BaseURLResourceName,PrefixResourceName,PrefixResourceName,PrefixResourceName
public abstract class BasePrefixResourceName<T,E extends Exception> extends Object implements BaseResourceName<T,E>
A generic 'prefix' implementation of BaseResourceName.- See Also:
BaseResourceName
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancaseSensitiveWhether matching is case sensitive.protected DebugdebugDebug instance.protected StringdelimiterDelimiter.protected TexactMatchThe object to return on an exact match.protected TnoMatchThe object to return on no match.protected StringoneLevelWildcardString indicating default one level wild card pattern.protected booleanoneLevelWildcardEmbeddedboolean 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 "-*-".protected intoneLevelWildcardLengthString indicating default one level wild card pattern length.protected TsubResourceMatchThe object to return on a sub-resource match.protected TsuperResourceMatchThe object to return on a super-resource match.protected StringwildcardString indicating default wild card pattern.protected booleanwildcardEmbeddedboolean 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 "-*-".protected intwildcardLengthString indicating default wild card pattern length.protected TwildcardMatchThe object to return on a wildcard match.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Stringappend(String superResource, String subResource)Appends sub-resource to super-resource.Stringcanonicalize(String res)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.Tcompare(String requestResource, String targetResource, boolean wildcardCompare)Compares two resources.protected abstract EconstructResourceInvalidException(Object[] args)Construct the exception that will be thrown if the resource is invalid during canonicalize.Set<String>getServiceTypeNames()Returns the service type names for which the resource name object can be used.StringgetSubResource(String resource, String superResource)Gets sub-resource from an original resource minus a super resource.voidinitialize(Map configParams)Initializes the resource name with configuration information, usally set by the administrators.protected StringnormalizeRequestResource(String requestResource)If further normalization ofrequestResourceis required during comparison, it can be added here.protected StringnormalizeTargetResource(String targetResource)If further normalization oftargetResourceis required during comparison, it can be added here.ToneLevelWildcardCompare(String requestResource, String targetResource, boolean wildcardCompare)Compares two resources containing one level wild card(s).String[]split(String res)Splits the given resource name.
-
-
-
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:delimitercaseSensitivewildcardoneLevelWildcardoneLevelWildcardLengthwildcardLengthwildcardEmbeddedoneLevelWildcardEmbedded
- Specified by:
initializein interfaceBaseResourceName<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 oneStringvalue which specifies the configuration paramater value.
-
getServiceTypeNames
public Set<String> getServiceTypeNames()
Description copied from interface:BaseResourceNameReturns the service type names for which the resource name object can be used.- Specified by:
getServiceTypeNamesin interfaceBaseResourceName<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:
comparein interfaceBaseResourceName<T,E extends Exception>- Parameters:
requestResource- name of the resource which will be comparedtargetResource- name of the resource which will be compared withwildcardCompare- flag for wildcard comparison- Returns:
- returns
ResourceMatchthat specifies if the resources are exact match, or otherwise.
-
normalizeTargetResource
protected String normalizeTargetResource(String targetResource)
If further normalization oftargetResourceis 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 ofrequestResourceis 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 comparedtargetResource- name of the resource which will be compared withwildcardCompare- flag for wildcard comparison- Returns:
- returns
ResourceMatchthat 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:
appendin interfaceBaseResourceName<T,E extends Exception>- Parameters:
superResource- name of the super-resource to be appended tosubResource- 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:
getSubResourcein interfaceBaseResourceName<T,E extends Exception>- Parameters:
resource- name of the original resource consisting of the second parameter superResource and the returned valuesuperResource- 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:
splitin interfaceBaseResourceName<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:
canonicalizein interfaceBaseResourceName<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 invalidE extends Exception
-
-