#848 - Renamed RelProvider to LinkRelationProvider.

This commit is contained in:
Oliver Drotbohm
2019-03-04 10:04:27 +01:00
parent 92120fd755
commit 5c046e6858
22 changed files with 153 additions and 150 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 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.
@@ -19,11 +19,11 @@ import org.springframework.hateoas.LinkRelation;
import org.springframework.plugin.core.Plugin;
/**
* API to provide relation types for collections and items of the given type.
* API to provide {@link LinkRelation}s for collections and items of the given type.
*
* @author Oliver Gierke
*/
public interface RelProvider extends Plugin<Class<?>> {
public interface LinkRelationProvider extends Plugin<Class<?>> {
/**
* Returns the relation type to be used to point to an item resource of the given type.

View File

@@ -21,20 +21,20 @@ import java.util.Map;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.LinkRelationProvider;
/**
* @author Oliver Gierke
* @author Alexander Baetz
* @author Greg Turnquist
*/
public class AnnotationRelProvider implements RelProvider, Ordered {
public class AnnotationLinkRelationProvider implements LinkRelationProvider, Ordered {
private final Map<Class<?>, Relation> annotationCache = new HashMap<>();
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForCollectionResource(java.lang.Class)
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
@@ -50,7 +50,7 @@ public class AnnotationRelProvider implements RelProvider, Ordered {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForSingleResource(java.lang.Object)
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getItemResourceRelFor(Class<?> type) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 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.
@@ -17,18 +17,41 @@ package org.springframework.hateoas.server.core;
import org.springframework.core.Ordered;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.util.StringUtils;
/**
* Default implementation of {@link RelProvider} to simply use the uncapitalized version of the given type's name as
* single resource rel as well as an appended {@code List} for the collection resource rel.
* Default implementation of {@link LinkRelationProvider} to simply use the uncapitalized version of the given type's
* name as item resource {@link LinkRelation} as well as an appended {@code List} for the collection resource
* {@link LinkRelation}.
*
* @author Oliver Gierke
* @author Greg Turnquist
*/
public class DefaultRelProvider implements RelProvider, Ordered {
public class DefaultLinkRelationProvider implements LinkRelationProvider, Ordered {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()) + "List");
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getItemResourceRelFor(Class<?> type) {
return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()));
}
/*
* (non-Javadoc)
* @see org.springframework.core.Ordered#getOrder()
*/
@Override
public int getOrder() {
return Ordered.LOWEST_PRECEDENCE;
@@ -42,22 +65,4 @@ public class DefaultRelProvider implements RelProvider, Ordered {
public boolean supports(Class<?> delimiter) {
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForCollectionResource(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()) + "List");
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForSingleResource(java.lang.Class)
*/
@Override
public LinkRelation getItemResourceRelFor(Class<?> type) {
return LinkRelation.of(StringUtils.uncapitalize(type.getSimpleName()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 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,27 +15,24 @@
*/
package org.springframework.hateoas.server.core;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.util.Assert;
/**
* @author Oliver Gierke
*/
public class DelegatingRelProvider implements RelProvider {
@RequiredArgsConstructor
public class DelegatingLinkRelationProvider implements LinkRelationProvider {
private final PluginRegistry<RelProvider, Class<?>> providers;
public DelegatingRelProvider(PluginRegistry<RelProvider, Class<?>> providers) {
Assert.notNull(providers, "RelProviders must not be null!");
this.providers = providers;
}
private final @NonNull PluginRegistry<LinkRelationProvider, Class<?>> providers;
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForSingleResource(java.lang.Class)
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getItemResourceRelFor(Class<?> type) {
@@ -44,7 +41,7 @@ public class DelegatingRelProvider implements RelProvider {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForCollectionResource(java.lang.Class)
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(java.lang.Class<?> type) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2019 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.
@@ -17,20 +17,20 @@ package org.springframework.hateoas.server.core;
import org.atteo.evo.inflector.English;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.LinkRelationProvider;
/**
* {@link RelProvider} implementation using the Evo Inflector implementation of an algorithmic approach to English
* plurals.
* {@link LinkRelationProvider} implementation using the Evo Inflector implementation of an algorithmic approach to
* English plurals.
*
* @see http://www.csse.monash.edu.au/~damian/papers/HTML/Plurals.html
* @author Oliver Gierke
*/
public class EvoInflectorRelProvider extends DefaultRelProvider {
public class EvoInflectorLinkRelationProvider extends DefaultLinkRelationProvider {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.core.DefaultRelProvider#getCollectionResourceRelFor(java.lang.Class)
* @see org.springframework.hateoas.server.core.DefaultLinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> type) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2019 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.
@@ -18,24 +18,25 @@ package org.springframework.hateoas.server.mvc;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.hateoas.LinkRelation;
import org.springframework.hateoas.server.ExposesResourceFor;
import org.springframework.hateoas.server.RelProvider;
import org.springframework.hateoas.server.LinkRelationProvider;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.util.Assert;
/**
* @author Oliver Gierke
*/
public class ControllerRelProvider implements RelProvider {
public class ControllerLinkRelationProvider implements LinkRelationProvider {
private final Class<?> controllerType;
private final Class<?> entityType;
private final PluginRegistry<RelProvider, Class<?>> providers;
private final PluginRegistry<LinkRelationProvider, Class<?>> providers;
public ControllerRelProvider(Class<?> controller, PluginRegistry<RelProvider, Class<?>> providers) {
public ControllerLinkRelationProvider(Class<?> controller, PluginRegistry<LinkRelationProvider, Class<?>> providers) {
Assert.notNull(controller, "Controller must not be null!");
ExposesResourceFor annotation = AnnotationUtils.findAnnotation(controller, ExposesResourceFor.class);
Assert.notNull(annotation, "Controller must be annotated with ExposesResourceFor!");
this.controllerType = controller;
@@ -45,22 +46,22 @@ public class ControllerRelProvider implements RelProvider {
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForCollectionResource(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> resource) {
return providers.getRequiredPluginFor(entityType).getCollectionResourceRelFor(resource);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.RelProvider#getRelForSingleResource(java.lang.Class)
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getItemResourceRelFor(Class<?> resource) {
return providers.getRequiredPluginFor(entityType).getItemResourceRelFor(resource);
}
/*
* (non-Javadoc)
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
*/
@Override
public LinkRelation getCollectionResourceRelFor(Class<?> resource) {
return providers.getRequiredPluginFor(entityType).getCollectionResourceRelFor(resource);
}
/*
* (non-Javadoc)
* @see org.springframework.plugin.core.Plugin#supports(java.lang.Object)