Spring Hateoas

org.springframework.hateoas.mvc
Class ResourceAssemblerSupport<T,D extends ResourceSupport>

java.lang.Object
  extended by org.springframework.hateoas.mvc.ResourceAssemblerSupport<T,D>
All Implemented Interfaces:
ResourceAssembler<T,D>
Direct Known Subclasses:
IdentifiableResourceAssemblerSupport

public abstract class ResourceAssemblerSupport<T,D extends ResourceSupport>
extends Object
implements ResourceAssembler<T,D>

Base class to implement ResourceAssemblers. Will automate ResourceSupport instance creation and make sure a self-link is always added.

Author:
Oliver Gierke

Constructor Summary
ResourceAssemblerSupport(Class<?> controllerClass, Class<D> resourceType)
          Creates a new ResourceAssemblerSupport using the given controller class and resource type.
 
Method Summary
protected  D createResourceWithId(Object id, T entity)
          Creates a new resource with a self link to the given id.
protected  D createResourceWithId(Object id, T entity, Object... parameters)
           
protected  D instantiateResource(T entity)
          Instantiates the resource object.
 List<D> toResources(Iterable<? extends T> entities)
          Converts all given entities into resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.hateoas.ResourceAssembler
toResource
 

Constructor Detail

ResourceAssemblerSupport

public ResourceAssemblerSupport(Class<?> controllerClass,
                                Class<D> resourceType)
Creates a new ResourceAssemblerSupport using the given controller class and resource type.

Parameters:
controllerClass - must not be null.
resourceType - must not be null.
Method Detail

toResources

public List<D> toResources(Iterable<? extends T> entities)
Converts all given entities into resources.

Parameters:
entities - must not be null.
Returns:
See Also:
ResourceAssembler.toResource(Object)

createResourceWithId

protected D createResourceWithId(Object id,
                                 T entity)
Creates a new resource with a self link to the given id.

Parameters:
entity - must not be null.
id - must not be null.
Returns:

createResourceWithId

protected D createResourceWithId(Object id,
                                 T entity,
                                 Object... parameters)

instantiateResource

protected D instantiateResource(T entity)
Instantiates the resource object. Default implementation will assume a no-arg constructor and use reflection but can be overridden to manually set up the object instance initially (e.g. to improve performance if this becomes an issue).

Parameters:
entity -
Returns:

Spring Hateoas

Copyright © 2012-2014-2014 Pivotal, Inc.. All Rights Reserved.