diff --git a/src/main/java/org/springframework/hateoas/server/core/AnnotationMappingDiscoverer.java b/src/main/java/org/springframework/hateoas/server/core/AnnotationMappingDiscoverer.java index 01d30a7c..187886aa 100644 --- a/src/main/java/org/springframework/hateoas/server/core/AnnotationMappingDiscoverer.java +++ b/src/main/java/org/springframework/hateoas/server/core/AnnotationMappingDiscoverer.java @@ -33,11 +33,13 @@ import org.springframework.web.bind.annotation.RequestMethod; /** * {@link MappingDiscoverer} implementation that inspects mappings from a particular annotation. - * + * * @author Oliver Gierke * @author Mark Paluch * @author Greg Turnquist + * @deprecated since 1.2, not for removal but for hiding within the package in 1.3 */ +@Deprecated public class AnnotationMappingDiscoverer implements MappingDiscoverer { private static final Pattern MULTIPLE_SLASHES = Pattern.compile("/{2,}"); @@ -48,7 +50,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { /** * Creates an {@link AnnotationMappingDiscoverer} for the given annotation type. Will lookup the {@code value} * attribute by default. - * + * * @param annotation must not be {@literal null}. */ public AnnotationMappingDiscoverer(Class annotation) { @@ -57,7 +59,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { /** * Creates an {@link AnnotationMappingDiscoverer} for the given annotation type and attribute name. - * + * * @param annotation must not be {@literal null}. * @param mappingAttributeName if {@literal null}, it defaults to {@code value}. */ @@ -69,7 +71,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { this.mappingAttributeName = mappingAttributeName; } - /* + /* * (non-Javadoc) * @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class) */ @@ -84,7 +86,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { return mapping.length == 0 ? null : mapping[0]; } - /* + /* * (non-Javadoc) * @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.reflect.Method) */ @@ -96,7 +98,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { return getMapping(method.getDeclaringClass(), method); } - /* + /* * (non-Javadoc) * @see org.springframework.hateoas.core.MappingDiscoverer#getMapping(java.lang.Class, java.lang.reflect.Method) */ @@ -120,7 +122,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { /** * Extract {@link org.springframework.web.bind.annotation.RequestMapping}'s list of {@link RequestMethod}s into an * array of {@link String}s. - * + * * @param type * @param method * @return @@ -171,7 +173,7 @@ public class AnnotationMappingDiscoverer implements MappingDiscoverer { /** * Joins the given mappings making sure exactly one slash. - * + * * @param typeMapping must not be {@literal null} or empty. * @param mapping must not be {@literal null} or empty. * @return diff --git a/src/main/java/org/springframework/hateoas/server/mvc/PropertyResolvingMappingDiscoverer.java b/src/main/java/org/springframework/hateoas/server/core/PropertyResolvingMappingDiscoverer.java similarity index 95% rename from src/main/java/org/springframework/hateoas/server/mvc/PropertyResolvingMappingDiscoverer.java rename to src/main/java/org/springframework/hateoas/server/core/PropertyResolvingMappingDiscoverer.java index 18c4faa0..9cb88689 100644 --- a/src/main/java/org/springframework/hateoas/server/mvc/PropertyResolvingMappingDiscoverer.java +++ b/src/main/java/org/springframework/hateoas/server/core/PropertyResolvingMappingDiscoverer.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.hateoas.server.mvc; +package org.springframework.hateoas.server.core; import java.lang.reflect.Method; import java.util.Collection; -import org.springframework.hateoas.server.core.MappingDiscoverer; import org.springframework.http.HttpMethod; import org.springframework.lang.Nullable; import org.springframework.util.Assert; diff --git a/src/main/java/org/springframework/hateoas/server/core/WebHandler.java b/src/main/java/org/springframework/hateoas/server/core/WebHandler.java index 490eea7a..3e09138b 100644 --- a/src/main/java/org/springframework/hateoas/server/core/WebHandler.java +++ b/src/main/java/org/springframework/hateoas/server/core/WebHandler.java @@ -22,16 +22,7 @@ import static org.springframework.web.util.UriComponents.UriTemplateVariables.*; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiFunction; import java.util.function.Function; @@ -68,8 +59,9 @@ import org.springframework.web.util.UriTemplate; */ public class WebHandler { - private static final MappingDiscoverer DISCOVERER = CachingMappingDiscoverer - .of(new AnnotationMappingDiscoverer(RequestMapping.class)); + @SuppressWarnings("deprecation") // + public static final MappingDiscoverer DISCOVERER = CachingMappingDiscoverer + .of(new PropertyResolvingMappingDiscoverer(new AnnotationMappingDiscoverer(RequestMapping.class))); private static final Map> AFFORDANCES_CACHE = new ConcurrentReferenceHashMap<>(); @@ -169,7 +161,7 @@ public class WebHandler { } List affordances = AFFORDANCES_CACHE.computeIfAbsent( - AffordanceKey.of(invocation.getTargetType(), invocation.getMethod(), components), + new AffordanceKey(invocation.getTargetType(), invocation.getMethod(), components), key -> SpringAffordanceBuilder.create(key.type, key.method, key.href.toUriString(), DISCOVERER)); return creator.createBuilder(components, variables, affordances); @@ -242,46 +234,49 @@ public class WebHandler { private final Method method; private final UriComponents href; - private AffordanceKey(Class type, Method method, UriComponents href) { + AffordanceKey(Class type, Method method, UriComponents href) { this.type = type; this.method = method; this.href = href; } - public static AffordanceKey of(Class type, Method method, UriComponents href) { - return new AffordanceKey(type, method, href); - } - - public Class getType() { - return this.type; - } - - public Method getMethod() { - return this.method; - } - - public UriComponents getHref() { - return this.href; - } - + /* + * (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { - if (this == o) + if (this == o) { return true; - if (!(o instanceof AffordanceKey)) + } + + if (!(o instanceof AffordanceKey)) { return false; + } + AffordanceKey that = (AffordanceKey) o; - return Objects.equals(this.type, that.type) && Objects.equals(this.method, that.method) + + return Objects.equals(this.type, that.type) // + && Objects.equals(this.method, that.method) // && Objects.equals(this.href, that.href); } + /* + * (non-Javadoc) + * @see java.lang.Object#hashCode() + */ @Override public int hashCode() { return Objects.hash(this.type, this.method, this.href); } + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override public String toString() { return "WebHandler.AffordanceKey(type=" + this.type + ", method=" + this.method + ", href=" + this.href + ")"; } diff --git a/src/main/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilder.java b/src/main/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilder.java index 2a5fadab..76c374f0 100644 --- a/src/main/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilder.java +++ b/src/main/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilder.java @@ -24,14 +24,11 @@ import java.util.Map; import org.springframework.hateoas.Affordance; import org.springframework.hateoas.Link; import org.springframework.hateoas.TemplateVariables; -import org.springframework.hateoas.server.core.AnnotationMappingDiscoverer; -import org.springframework.hateoas.server.core.CachingMappingDiscoverer; import org.springframework.hateoas.server.core.DummyInvocationUtils; -import org.springframework.hateoas.server.core.MappingDiscoverer; import org.springframework.hateoas.server.core.TemplateVariableAwareLinkBuilderSupport; import org.springframework.hateoas.server.core.UriTemplateFactory; +import org.springframework.hateoas.server.core.WebHandler; import org.springframework.util.Assert; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.util.DefaultUriTemplateHandler; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; @@ -52,8 +49,6 @@ import org.springframework.web.util.UriTemplate; @SuppressWarnings("deprecation") public class WebMvcLinkBuilder extends TemplateVariableAwareLinkBuilderSupport { - private static final MappingDiscoverer DISCOVERER = CachingMappingDiscoverer - .of(new PropertyResolvingMappingDiscoverer(new AnnotationMappingDiscoverer(RequestMapping.class))); private static final WebMvcLinkBuilderFactory FACTORY = new WebMvcLinkBuilderFactory(); private static final CustomUriTemplateHandler HANDLER = new CustomUriTemplateHandler(); @@ -94,7 +89,7 @@ public class WebMvcLinkBuilder extends TemplateVariableAwareLinkBuilderSupport