public abstract class Link
extends java.lang.Object
Class representing hypermedia links. A hypermedia link may include additional parameters beyond its underlying URI.
Parameters such as rel
or type
provide additional meta-data. Links in responses can be
followed by creating an Invocation.Builder
or a
WebTarget
.
The methods toString()
and valueOf(java.lang.String)
can be used to serialize and de-serialize a link into a link
header (RFC 5988).
Modifier and Type | Class and Description |
---|---|
static interface |
Link.Builder
Builder class for hypermedia links.
|
static class |
Link.JaxbAdapter
An implementation of JAXB
XmlAdapter that maps the JAX-RS
Link type to a value that can be marshalled and unmarshalled by JAXB. |
static class |
Link.JaxbLink
Value type for
Link that can be marshalled and
unmarshalled by JAXB. |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REL
Rel link param from RFC 5988.
|
static java.lang.String |
TITLE
Title link param from RFC 5988.
|
static java.lang.String |
TYPE
Type link param from RFC 5988.
|
Constructor and Description |
---|
Link() |
Modifier and Type | Method and Description |
---|---|
static Link.Builder |
fromLink(Link link)
Create a new builder instance initialized from another link.
|
static Link.Builder |
fromMethod(java.lang.Class<?> resource,
java.lang.String method)
Convenience method to build a link from a resource.
|
static Link.Builder |
fromPath(java.lang.String path)
Convenience method to build a link from a path.
|
static Link.Builder |
fromResource(java.lang.Class<?> resource)
Convenience method to build a link from a resource.
|
static Link.Builder |
fromUri(java.lang.String uri)
Create a new builder instance initialized from an existing URI represented as a string.
|
static Link.Builder |
fromUri(java.net.URI uri)
Create a new builder instance initialized from an existing URI.
|
static Link.Builder |
fromUriBuilder(UriBuilder uriBuilder)
Create a new builder instance initialized from a URI builder.
|
abstract java.util.Map<java.lang.String,java.lang.String> |
getParams()
Returns an immutable map that includes all the link parameters defined on this link.
|
abstract java.lang.String |
getRel()
Returns the value associated with the link
rel param, or null if this param is not specified. |
abstract java.util.List<java.lang.String> |
getRels()
Returns the value associated with the link
rel param as a list of strings or the empty list if rel is
not defined. |
abstract java.lang.String |
getTitle()
Returns the value associated with the link
title param, or null if this param is not specified. |
abstract java.lang.String |
getType()
Returns the value associated with the link
type param, or null if this param is not specified. |
abstract java.net.URI |
getUri()
Returns the underlying URI associated with this link.
|
abstract UriBuilder |
getUriBuilder()
Convenience method that returns a
UriBuilder initialized with this link's underlying URI. |
abstract java.lang.String |
toString()
Returns a string representation as a link header (RFC 5988).
|
static Link |
valueOf(java.lang.String value)
Simple parser to convert link header string representations into a link.
|
public static final java.lang.String TITLE
public static final java.lang.String REL
public static final java.lang.String TYPE
public abstract java.net.URI getUri()
public abstract UriBuilder getUriBuilder()
UriBuilder
initialized with this link's underlying URI.public abstract java.lang.String getRel()
rel
param, or null
if this param is not specified.null
.public abstract java.util.List<java.lang.String> getRels()
rel
param as a list of strings or the empty list if rel
is
not defined.public abstract java.lang.String getTitle()
title
param, or null
if this param is not specified.null
.public abstract java.lang.String getType()
type
param, or null
if this param is not specified.null
.public abstract java.util.Map<java.lang.String,java.lang.String> getParams()
rel
, title
and type
.public abstract java.lang.String toString()
toString
in class java.lang.Object
public static Link valueOf(java.lang.String value)
link ::= '<' uri 'gt;' (';' link-param)* link-param ::= name '=' quoted-stringSee RFC 5988 for more information.
value
- String representation.java.lang.IllegalArgumentException
- if a syntax error is found.Link.Builder.link(java.lang.String)
public static Link.Builder fromUri(java.net.URI uri)
uri
- a URI that will be used to initialize the builder.java.lang.IllegalArgumentException
- if uri is null
.public static Link.Builder fromUri(java.lang.String uri)
uri
- a URI that will be used to initialize the builder.java.lang.IllegalArgumentException
- if uri is null
.public static Link.Builder fromUriBuilder(UriBuilder uriBuilder)
uriBuilder
- instance of URI builder.public static Link.Builder fromLink(Link link)
link
- other link used for initialization.public static Link.Builder fromPath(java.lang.String path)
fromUriBuilder(UriBuilder.fromPath(path))
.path
- a URI path that will be used to initialize the Link, may contain URI template parameters.java.lang.IllegalArgumentException
- if path is null
.public static Link.Builder fromResource(java.lang.Class<?> resource)
Link.fromUriBuilder({@link UriBuilder#fromResource UriBuilder.fromResource(resource)})
. Note that the link
URI passed to the Link.Builder
instance returned by this method is relative. Should the link be built as
absolute, a base URI
has to be specified in the builder prior to building the new
link instance. For example, on a server side a UriInfo.getBaseUri()
may be typically used to define the base
URI of a link created using this method.resource
- a root resource whose Path
value will be used to initialize the builder.link builder
instance.java.lang.IllegalArgumentException
- if resource is not annotated with Path
or resource is
null
.UriInfo.getBaseUri()
public static Link.Builder fromMethod(java.lang.Class<?> resource, java.lang.String method)
Link.fromUriBuilder({@link UriBuilder#fromMethod(Class, String) UriBuilder.fromMethod(resource, method)})
.
Note that the link URI passed to the Link.Builder
instance returned by this method is relative. Should the
link be built as absolute, a base URI
has to be specified in the builder prior to
building the new link instance. For example, on a server side a UriInfo.getBaseUri()
may be typically used to
define the base URI of a link created using this method.resource
- the resource containing the method.method
- the name of the method whose Path
value will be used to obtain the path to append.java.lang.IllegalArgumentException
- if resource or method is null
, or there is more than or less than one
variant of the method annotated with Path
.UriInfo.getBaseUri()