public final class Link extends 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 and can be used to create instances of
Invocation.Builder
in order to follow links.
The methods toString()
and valueOf(java.lang.String)
can be used to serialize
and de-serialize a link into a link header (RFC 5988).
Client.invocation(javax.ws.rs.core.Link)
Modifier and Type | Class and Description |
---|---|
static class |
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 String |
REL
Rel link param from RFC 5988.
|
static String |
TITLE
Title link param from RFC 5988.
|
static String |
TYPE
Type link param from RFC 5988.
|
Constructor and Description |
---|
Link() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
Equality test for links.
|
static Link.Builder |
fromLink(Link link)
Create a new builder instance initialized from another link.
|
static Link.Builder |
fromResource(Class<?> resource,
String rel)
Generate a relative link from a resource class.
|
static Link.Builder |
fromResourceMethod(Class<?> resource,
String method)
Generate a relative link by introspecting a resource method.
|
static Link.Builder |
fromResourceMethod(Class<?> resource,
String method,
String rel)
Generate a relative link by introspecting a resource method.
|
static Link.Builder |
fromUri(String uri)
Create a new builder instance initialized from an existing URI
represented as a string.
|
static Link.Builder |
fromUri(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.
|
Map<String,String> |
getParams()
Returns an immutable map that includes all the link parameters
defined on this link.
|
String |
getRel()
Returns the value associated with the link "rel" param, or
null if this param is not specified. |
List<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.
|
String |
getTitle()
Returns the value associated with the link "title" param, or
null if this param is not specified. |
String |
getType()
Returns the value associated with the link "type" param, or
null if this param is not specified. |
URI |
getUri()
Returns the underlying URI associated with this link.
|
UriBuilder |
getUriBuilder()
Convenience method that returns a
UriBuilder
initialized with this link's underlying URI. |
int |
hashCode()
Hash code computation for links.
|
String |
toString()
Returns a string representation as a link header (RFC 5988).
|
static Link |
valueOf(String value)
Simple parser to convert link header string representations into a link.
|
public static final String TITLE
public static final String REL
public static final String TYPE
public URI getUri()
public UriBuilder getUriBuilder()
UriBuilder
initialized with this link's underlying URI.public String getRel()
null
if this param is not specified.null
.public List<String> getRels()
public String getTitle()
null
if this param is not specified.null
.public String getType()
null
if this param is not specified.null
.public Map<String,String> getParams()
public boolean equals(Object other)
public int hashCode()
public String toString()
public static Link valueOf(String value) throws IllegalArgumentException
link ::= '<' uri '>' (';' link-param)* link-param ::= name '=' quoted-stringSee RFC 5988 for more information.
value
- String representation.IllegalArgumentException
- if a syntax error is found.public static Link.Builder fromUri(URI uri) throws IllegalArgumentException
uri
- a URI that will be used to initialize the builder.IllegalArgumentException
- if uri is null
.public static Link.Builder fromUri(String uri) throws IllegalArgumentException
uri
- a URI that will be used to initialize the builder.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 fromResourceMethod(Class<?> resource, String method) throws IllegalArgumentException
fromResourceMethod(resource, method, method)
where
the method name is used as the value of the "rel" parameter.resource
- resource class.method
- name of resource method.IllegalArgumentException
- if any argument is null
or no method is found.fromResourceMethod(java.lang.Class, java.lang.String, java.lang.String)
public static Link.Builder fromResourceMethod(Class<?> resource, String method, String rel) throws IllegalArgumentException
Generate a relative link by introspecting a resource method. Finds the first method of a given name and generates a link with the appropriate URI and values for "type" and "rel".
The value of "type" is set to be the first media-type in @Produces
,
and is omitted if that annotation is not present on the method or class. The value
of "rel" must be specified as an argument to this method.
resource
- resource class.method
- name of resource method.rel
- value of "rel"
parameter.IllegalArgumentException
- if any argument is null
or no method is found.UriBuilder.fromMethod(java.lang.Class, java.lang.String)
public static Link.Builder fromResource(Class<?> resource, String rel)
Generate a relative link from a resource class. The value of "type" is set to be
the first media-type in @Produces
, and is omitted if that annotation is
not present on the or class. The value of "rel" must be specified as an argument
to this method.
resource
- resource class.rel
- value of "rel"
parameter.IllegalArgumentException
- if any argument is null
or no method is found.UriBuilder.fromResource(java.lang.Class)
Copyright © 2013. All Rights Reserved.