#372 - Polishing.
Updated authors and copyright years, some minor refactorings.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,8 @@ import java.util.Map;
|
||||
* Factory for {@link LinkBuilder} instances.
|
||||
*
|
||||
* @author Ricardo Gladwell
|
||||
* @author Andrew Naydyonock
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface LinkBuilderFactory<T extends LinkBuilder> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,23 +15,25 @@
|
||||
*/
|
||||
package org.springframework.hateoas.jaxrs;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
import org.springframework.hateoas.LinkBuilder;
|
||||
import org.springframework.hateoas.core.AnnotationMappingDiscoverer;
|
||||
import org.springframework.hateoas.core.LinkBuilderSupport;
|
||||
import org.springframework.hateoas.core.MappingDiscoverer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
import org.springframework.web.util.UriComponents;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link LinkBuilder} to derive URI mappings from a JAX-RS {@link Path} annotation.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Kamill Sokol
|
||||
* @author Andrew Naydyonock
|
||||
*/
|
||||
public class JaxRsLinkBuilder extends LinkBuilderSupport<JaxRsLinkBuilder> {
|
||||
|
||||
@@ -60,36 +62,40 @@ public class JaxRsLinkBuilder extends LinkBuilderSupport<JaxRsLinkBuilder> {
|
||||
* Creates a new {@link JaxRsLinkBuilder} instance to link to the {@link Path} mapping tied to the given class binding
|
||||
* the given parameters to the URI template.
|
||||
*
|
||||
* @param service the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param resourceType the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param parameters additional parameters to bind to the URI template declared in the annotation, must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static JaxRsLinkBuilder linkTo(Class<?> service, Object... parameters) {
|
||||
public static JaxRsLinkBuilder linkTo(Class<?> resourceType, Object... parameters) {
|
||||
|
||||
JaxRsLinkBuilder builder = new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping());
|
||||
Assert.notNull(resourceType, "Controller type must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(service)).build();
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(resourceType)).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
return builder.slash(expandedComponents);
|
||||
|
||||
return new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping()).slash(expandedComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link JaxRsLinkBuilder} instance to link to the {@link Path} mapping tied to the given class binding
|
||||
* the given parameters to the URI template.
|
||||
*
|
||||
* @param service the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param resourceType the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param parameters map of additional parameters to bind to the URI template declared in the annotation, must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static JaxRsLinkBuilder linkTo(Class<?> service, Map<String, ?> parameters) {
|
||||
public static JaxRsLinkBuilder linkTo(Class<?> resourceType, Map<String, ?> parameters) {
|
||||
|
||||
JaxRsLinkBuilder builder = new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping());
|
||||
Assert.notNull(resourceType, "Controller type must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(service)).build();
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(DISCOVERER.getMapping(resourceType)).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
return builder.slash(expandedComponents);
|
||||
|
||||
return new JaxRsLinkBuilder(ServletUriComponentsBuilder.fromCurrentServletMapping()).slash(expandedComponents);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,16 +15,17 @@
|
||||
*/
|
||||
package org.springframework.hateoas.jaxrs;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.hateoas.LinkBuilder;
|
||||
import org.springframework.hateoas.LinkBuilderFactory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Factory for {@link LinkBuilder} instances based on the path mapping annotated on the given JAX-RS service.
|
||||
*
|
||||
* @author Ricardo Gladwell
|
||||
* @author Oliver Gierke
|
||||
* @author Andrew Naydyonock
|
||||
*/
|
||||
public class JaxRsLinkBuilderFactory implements LinkBuilderFactory<JaxRsLinkBuilder> {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import static org.springframework.util.StringUtils.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -45,6 +45,7 @@ import org.springframework.web.util.UriTemplate;
|
||||
* @author Kamill Sokol
|
||||
* @author Greg Turnquist
|
||||
* @author Kevin Conaway
|
||||
* @author Andrew Naydyonock
|
||||
*/
|
||||
public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuilder> {
|
||||
|
||||
@@ -91,45 +92,44 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
*/
|
||||
public static ControllerLinkBuilder linkTo(Class<?> controller, Object... parameters) {
|
||||
|
||||
Assert.notNull(controller);
|
||||
Assert.notNull(controller, "Controller must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
|
||||
ControllerLinkBuilder builder = new ControllerLinkBuilder(getBuilder());
|
||||
String mapping = DISCOVERER.getMapping(controller);
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(mapping == null ? "/" : mapping).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
|
||||
return builder.slash(expandedComponents);
|
||||
return new ControllerLinkBuilder(getBuilder()).slash(expandedComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ControllerLinkBuilder} with a base of the mapping annotated to the given controller class.
|
||||
* Parameter map is used to fill up potentially available path variables in the class scope request mapping.
|
||||
*
|
||||
* @param controller the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param parameters additional parameters to bind to the URI template declared in the annotation, must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static ControllerLinkBuilder linkTo(Class<?> controller, Map<String, ?> parameters) {
|
||||
|
||||
Assert.notNull(controller, "Controller must not be null!");
|
||||
Assert.notNull(parameters, "Parameters must not be null!");
|
||||
|
||||
String mapping = DISCOVERER.getMapping(controller);
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(mapping == null ? "/" : mapping).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
|
||||
return new ControllerLinkBuilder(getBuilder()).slash(expandedComponents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link ControllerLinkBuilder} with a base of the mapping annotated to the given controller class.
|
||||
* Parameter map is used to fill up potentially available path variables in the class scope request
|
||||
* mapping.
|
||||
*
|
||||
* @param controller the class to discover the annotation on, must not be {@literal null}.
|
||||
* @param parameters additional parameters to bind to the URI template declared in the annotation, must not be
|
||||
* {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
public static ControllerLinkBuilder linkTo(Class<?> controller, Map<String, ?> parameters) {
|
||||
|
||||
Assert.notNull(controller);
|
||||
|
||||
ControllerLinkBuilder builder = new ControllerLinkBuilder(getBuilder());
|
||||
String mapping = DISCOVERER.getMapping(controller);
|
||||
|
||||
UriComponents uriComponents = UriComponentsBuilder.fromUriString(mapping == null ? "/" : mapping).build();
|
||||
UriComponents expandedComponents = uriComponents.expand(parameters);
|
||||
|
||||
return builder.slash(expandedComponents);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.springframework.hateoas.MethodLinkBuilderFactory#linkTo(Method, Object...)
|
||||
*/
|
||||
public static ControllerLinkBuilder linkTo(Method method, Object... parameters) {
|
||||
return linkTo(method.getDeclaringClass(), method, parameters);
|
||||
return linkTo(method.getDeclaringClass(), method, parameters);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -56,6 +56,7 @@ import org.springframework.web.util.UriTemplate;
|
||||
* @author Ross Turner
|
||||
* @author Oemer Yildiz
|
||||
* @author Kevin Conaway
|
||||
* @author Andrew Naydyonock
|
||||
*/
|
||||
public class ControllerLinkBuilderFactory implements MethodLinkBuilderFactory<ControllerLinkBuilder> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user