@Beta
public class ResourceName
extends java.lang.Object
implements java.util.Map<java.lang.String,java.lang.String>
A resource name is represented by PathTemplate, an assignment to variables in
the template, and an optional endpoint. The ResourceName class implements
the map interface (unmodifiable) to work with the variable assignments, and has methods
to reproduce the string representation of the name, to construct new names, and to dereference
names into resources.
As a resource name essentially represents a match of a path template against a string, it can be also used for other purposes than naming resources. However, not all provided methods may make sense in all applications.
Usage examples:
PathTemplate template = PathTemplate.create("shelves/*/books/*");
ResourceName resourceName = ResourceName.create(template, "shelves/s1/books/b1");
assert resourceName.get("$1").equals("b1");
assert resourceName.parentName().toString().equals("shelves/s1/books");
| Modifier and Type | Class and Description |
|---|---|
static interface |
ResourceName.Resolver
Represents a resource name resolver which can be registered with this class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Deprecated.
|
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
static ResourceName |
create(PathTemplate template,
java.util.Map<java.lang.String,java.lang.String> values)
Creates a new resource name from a template and a value assignment for variables.
|
static ResourceName |
create(PathTemplate template,
java.lang.String path)
Creates a new resource name based on given template and path.
|
static ResourceName |
createFromFullName(PathTemplate template,
java.lang.String path)
Creates a new resource name based on given template and path, where the path contains an
endpoint.
|
java.lang.String |
endpoint()
Returns the endpoint of this resource name, or null if none is defined.
|
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> |
entrySet() |
boolean |
equals(java.lang.Object obj) |
java.lang.String |
get(java.lang.Object key) |
boolean |
hasEndpoint()
Checks whether the resource name has an endpoint.
|
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
ResourceName |
parentName()
Returns the parent resource name.
|
java.lang.String |
put(java.lang.String key,
java.lang.String value)
Deprecated.
|
void |
putAll(java.util.Map<? extends java.lang.String,? extends java.lang.String> m)
Deprecated.
|
static void |
registerResourceNameResolver(ResourceName.Resolver resolver)
Sets the resource name resolver which is used by the
resolve(Class, String) method. |
java.lang.String |
remove(java.lang.Object key)
Deprecated.
|
<T> T |
resolve(java.lang.Class<T> resourceType,
java.lang.String version)
Attempts to resolve a resource name into a resource, by calling the associated API.
|
int |
size() |
boolean |
startsWith(ResourceName parentName)
Returns true of the resource name starts with the parent resource name, i.e.
|
PathTemplate |
template()
Gets the template associated with this resource name.
|
java.lang.String |
toString() |
java.util.Collection<java.lang.String> |
values() |
ResourceName |
withEndpoint(java.lang.String endpoint)
Returns a resource name with specified endpoint.
|
public static void registerResourceNameResolver(ResourceName.Resolver resolver)
resolve(Class, String) method.
By default, no resolver is registered.public static ResourceName create(PathTemplate template, java.lang.String path)
ValidationException - if the path does not match the template.public static ResourceName create(PathTemplate template, java.util.Map<java.lang.String,java.lang.String> values)
ValidationException - if not all variables in the template are bound.@Nullable public static ResourceName createFromFullName(PathTemplate template, java.lang.String path)
public java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in interface java.util.Map<java.lang.String,java.lang.String>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Map<java.lang.String,java.lang.String>hashCode in class java.lang.Objectpublic PathTemplate template()
public boolean hasEndpoint()
@Nullable public java.lang.String endpoint()
public ResourceName withEndpoint(java.lang.String endpoint)
public ResourceName parentName()
shelves/s1/books/b1, the
parent is shelves/s1/books.public boolean startsWith(ResourceName parentName)
public <T> T resolve(java.lang.Class<T> resourceType,
@Nullable
java.lang.String version)
public int size()
size in interface java.util.Map<java.lang.String,java.lang.String>public boolean isEmpty()
isEmpty in interface java.util.Map<java.lang.String,java.lang.String>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.String,java.lang.String>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<java.lang.String,java.lang.String>public java.lang.String get(java.lang.Object key)
get in interface java.util.Map<java.lang.String,java.lang.String>@Deprecated
public java.lang.String put(java.lang.String key,
java.lang.String value)
put in interface java.util.Map<java.lang.String,java.lang.String>@Deprecated public java.lang.String remove(java.lang.Object key)
remove in interface java.util.Map<java.lang.String,java.lang.String>@Deprecated public void putAll(java.util.Map<? extends java.lang.String,? extends java.lang.String> m)
putAll in interface java.util.Map<java.lang.String,java.lang.String>@Deprecated public void clear()
clear in interface java.util.Map<java.lang.String,java.lang.String>public java.util.Set<java.lang.String> keySet()
keySet in interface java.util.Map<java.lang.String,java.lang.String>public java.util.Collection<java.lang.String> values()
values in interface java.util.Map<java.lang.String,java.lang.String>public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.String>> entrySet()
entrySet in interface java.util.Map<java.lang.String,java.lang.String>