DATAREST-261 - Fixed RepositoryRelProvider registration.

We now register a RepositoryRelProvider that hadn't been exported before so that clients using a RelProvider will automatically see potentially customized rels for repositories.

Changed RepositoryRelProvider to lazily depend on the ResourceMappings as will be requested eagerly for injection into the configuration class itself.
This commit is contained in:
Oliver Gierke
2014-02-27 14:53:24 +01:00
parent f409106139
commit aa5316fb69
4 changed files with 34 additions and 9 deletions

View File

@@ -15,6 +15,9 @@
*/
package org.springframework.data.rest.core.support;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.hateoas.RelProvider;
import org.springframework.util.Assert;
@@ -24,16 +27,17 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
*/
@Order(Ordered.LOWEST_PRECEDENCE + 10)
public class RepositoryRelProvider implements RelProvider {
private final ResourceMappings mappings;
private final ObjectFactory<ResourceMappings> mappings;
/**
* Creates a new {@link RepositoryRelProvider} for the given {@link ResourceMappings}.
*
* @param mappings must not be {@literal null}.
*/
public RepositoryRelProvider(ResourceMappings mappings) {
public RepositoryRelProvider(ObjectFactory<ResourceMappings> mappings) {
Assert.notNull(mappings, "ResourceMappings must not be null!");
this.mappings = mappings;
@@ -45,7 +49,7 @@ public class RepositoryRelProvider implements RelProvider {
*/
@Override
public String getCollectionResourceRelFor(Class<?> type) {
return mappings.getMappingFor(type).getRel();
return mappings.getObject().getMappingFor(type).getRel();
}
/*
@@ -54,7 +58,7 @@ public class RepositoryRelProvider implements RelProvider {
*/
@Override
public String getItemResourceRelFor(Class<?> type) {
return mappings.getMappingFor(type).getItemResourceRel();
return mappings.getObject().getMappingFor(type).getItemResourceRel();
}
/*
@@ -63,6 +67,6 @@ public class RepositoryRelProvider implements RelProvider {
*/
@Override
public boolean supports(Class<?> delimiter) {
return mappings.hasMappingFor(delimiter);
return mappings.getObject().hasMappingFor(delimiter);
}
}