Replaced Resource(s)Processor with ResourceEnricher.
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.codehaus.jackson.annotate.JsonUnwrapped;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -39,11 +41,13 @@ public class Resource<T> extends ResourceSupport {
|
||||
* Creates a new {@link Resource} with the given content.
|
||||
*
|
||||
* @param content must not be {@literal null}.
|
||||
* @param links the links to add to the {@link Resource}.
|
||||
*/
|
||||
public Resource(T content) {
|
||||
public Resource(T content, Link... links) {
|
||||
|
||||
Assert.notNull(content, "Content must not be null!");
|
||||
this.content = content;
|
||||
this.add(Arrays.asList(links));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,21 +15,20 @@
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
|
||||
/**
|
||||
* SPI to let user code manipulate the {@link Resources} returned by the framework.
|
||||
* SPI interface to allow components to enrich the {@link ResourceSupport} instances returned from Spring MVC
|
||||
* controllers.
|
||||
*
|
||||
* @param T the concrete Resource<T> extension
|
||||
* @see Resource
|
||||
* @see Resources
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface ResourcesProcessor<T extends Resources<?>> {
|
||||
public interface ResourceEnricher<T extends ResourceSupport> {
|
||||
|
||||
/**
|
||||
* Callback to allow the manipulation of the given {@link Resources} before rendering.
|
||||
* Enriches the given resource, add links, alter the domain data etc.
|
||||
*
|
||||
* @param resources the standard {@link Resources} provided by the framework
|
||||
* @param entities the entities backing the {@link Resources} instance.
|
||||
* @return
|
||||
* @param resource
|
||||
*/
|
||||
Resources<?> process(T resources);
|
||||
void enrich(T resource);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.hateoas;
|
||||
|
||||
|
||||
/**
|
||||
* SPI to let user code manipulate a {@link Resource} by the framework.
|
||||
*
|
||||
* @param T the concrete Resource<T> extension
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface ResourceProcessor<T extends Resource<?>> {
|
||||
|
||||
/**
|
||||
* Callback to allow the manipulation of the given {@link Resource} before rendering.
|
||||
*
|
||||
* @param resource the standard resource prepared by the framework.
|
||||
* @param entity the entity backing the resource
|
||||
* @return a {@link Resource} object (could be a completely different one)
|
||||
*/
|
||||
Resource<?> process(T resource);
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.hateoas;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -50,13 +51,15 @@ public class Resources<T extends Resource<?>> extends ResourceSupport implements
|
||||
* Creates a {@link Resources} instance with the given content.
|
||||
*
|
||||
* @param content must not be {@literal null}.
|
||||
* @param links the links to be added to the {@link Resources}.
|
||||
*/
|
||||
public Resources(Collection<T> content) {
|
||||
public Resources(Collection<T> content, Link... links) {
|
||||
|
||||
Assert.notNull(content);
|
||||
|
||||
this.content = new ArrayList<T>();
|
||||
this.content.addAll(content);
|
||||
this.add(Arrays.asList(links));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user