diff --git a/src/main/java/org/springframework/hateoas/Resource.java b/src/main/java/org/springframework/hateoas/Resource.java index 57f35797..46694038 100644 --- a/src/main/java/org/springframework/hateoas/Resource.java +++ b/src/main/java/org/springframework/hateoas/Resource.java @@ -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 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)); } /** diff --git a/src/main/java/org/springframework/hateoas/ResourcesProcessor.java b/src/main/java/org/springframework/hateoas/ResourceEnricher.java similarity index 59% rename from src/main/java/org/springframework/hateoas/ResourcesProcessor.java rename to src/main/java/org/springframework/hateoas/ResourceEnricher.java index e8f98ec7..76107041 100644 --- a/src/main/java/org/springframework/hateoas/ResourcesProcessor.java +++ b/src/main/java/org/springframework/hateoas/ResourceEnricher.java @@ -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 extension + * @see Resource + * @see Resources * @author Oliver Gierke */ -public interface ResourcesProcessor> { +public interface ResourceEnricher { /** - * 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); } diff --git a/src/main/java/org/springframework/hateoas/ResourceProcessor.java b/src/main/java/org/springframework/hateoas/ResourceProcessor.java deleted file mode 100644 index 9c5c4fde..00000000 --- a/src/main/java/org/springframework/hateoas/ResourceProcessor.java +++ /dev/null @@ -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 extension - * @author Oliver Gierke - */ -public interface ResourceProcessor> { - - /** - * 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); -} diff --git a/src/main/java/org/springframework/hateoas/Resources.java b/src/main/java/org/springframework/hateoas/Resources.java index e90ec5a3..17d9743f 100644 --- a/src/main/java/org/springframework/hateoas/Resources.java +++ b/src/main/java/org/springframework/hateoas/Resources.java @@ -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> 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 content) { + public Resources(Collection content, Link... links) { Assert.notNull(content); this.content = new ArrayList(); this.content.addAll(content); + this.add(Arrays.asList(links)); } /**