io.quarkus.resteasy.reactive.links.runtime.RestLinksProviderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-rest-links Show documentation
Show all versions of quarkus-rest-links Show documentation
Web Links support for Quarkus REST. Inject web links into response HTTP headers by annotating your endpoint resources.
The newest version!
package io.quarkus.resteasy.reactive.links.runtime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import jakarta.ws.rs.core.Link;
import jakarta.ws.rs.core.UriInfo;
import io.quarkus.resteasy.reactive.links.RestLinksProvider;
final class RestLinksProviderImpl implements RestLinksProvider {
private static LinksContainer linksContainer;
private static GetterAccessorsContainer getterAccessorsContainer;
private final UriInfo uriInfo;
static void setLinksContainer(LinksContainer context) {
RestLinksProviderImpl.linksContainer = context;
}
static void setGetterAccessorsContainer(GetterAccessorsContainer getterAccessorsContainer) {
RestLinksProviderImpl.getterAccessorsContainer = getterAccessorsContainer;
}
RestLinksProviderImpl(UriInfo uriInfo) {
this.uriInfo = uriInfo;
}
@Override
public Collection getTypeLinks(Class> elementType) {
verifyInit();
List linkInfoList = linksContainer.getForClass(elementType);
List links = new ArrayList<>(linkInfoList.size());
for (LinkInfo linkInfo : linkInfoList) {
if (linkInfo.getPathParameters().size() == 0) {
links.add(linkBuilderFor(linkInfo).build());
}
}
return links;
}
@Override
public Collection getInstanceLinks(T instance) {
verifyInit();
List linkInfoList = linksContainer.getForClass(instance.getClass());
List links = new ArrayList<>(linkInfoList.size());
for (LinkInfo linkInfo : linkInfoList) {
links.add(linkBuilderFor(linkInfo).build(getPathParameterValues(linkInfo, instance)));
}
return links;
}
private Link.Builder linkBuilderFor(LinkInfo linkInfo) {
Link.Builder builder = Link.fromUriBuilder(uriInfo.getBaseUriBuilder().path(linkInfo.getPath()))
.rel(linkInfo.getRel());
if (linkInfo.getTitle() != null) {
builder.title(linkInfo.getTitle());
}
if (linkInfo.getType() != null) {
builder.type(linkInfo.getType());
}
return builder;
}
private Object[] getPathParameterValues(LinkInfo linkInfo, Object instance) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy