Hyperspace::REST::Collection Class Referenceabstract

The base class for Collections. More...

Inheritance diagram for Hyperspace::REST::Collection:

Public Member Functions

 Collection (const QByteArray &path, ResourceFactory *factory)
 
QByteArray path () const
 
void deleteResource (const QByteArray &waveId, const QByteArray &resourceId, const ByteArrayHash &attributes, const QByteArray &payload)
 
void getResource (const QByteArray &waveId, const QByteArray &resourceId, const ByteArrayHash &attributes, const QByteArray &payload)
 
void postResource (const QByteArray &waveId, const QByteArray &resourceId, const ByteArrayHash &attributes, const QByteArray &payload)
 
void putResource (const QByteArray &waveId, const QByteArray &resourceId, const ByteArrayHash &attributes, const QByteArray &payload)
 
void head (const QByteArray &waveId, const ByteArrayHash &attributes, const QByteArray &payload) Q_DECL_OVERRIDE
 Sends back a BadRequest Rebound by default. More...
 
- Public Member Functions inherited from Hyperspace::AbstractWaveTarget
virtual void get (const QByteArray &waveId, const ByteArrayHash &attributes, const QByteArray &payload)=0
 Implement Wave GET method. More...
 
virtual void httpDelete (const QByteArray &waveId, const ByteArrayHash &attributes, const QByteArray &payload)=0
 Implement Wave DELETE method. More...
 
virtual void post (const QByteArray &waveId, const ByteArrayHash &attributes, const QByteArray &payload)=0
 Implement Wave POST method. More...
 
virtual void put (const QByteArray &waveId, const ByteArrayHash &attributes, const QByteArray &payload)=0
 Implement Wave PUT method. More...
 

Protected Member Functions

ResourceFactoryfactory () const
 
virtual ResourceloadResource (const QByteArray &id)=0
 

Additional Inherited Members

- Protected Slots inherited from Hyperspace::AbstractWaveTarget
void sendRebound (const Hyperspace::Rebound &rebound)
 Send a rebound for a received wave. More...
 

Detailed Description

The base class for Collections.

Collections are mainly used as containers for Resources, but can also act as a resource themselves. A Resource must be part of a collection to be exported.

The default collection object is not reimplementing any method of AbstractWaveTarget, and acts as a base for a fully abstract collection. You usually want to use KeyValueCollection or one of its subclasses unless you're looking at a very specific use case.

Each Collection has a ResourceFactory associated to it, which serves as a helper for constructing Resources based on their ID. Collection automatically bridges calls to resources, and automatically loads and caches resources generated by the Factory. You usually don't need to call loadResource explicitly, but rely on the resource access methods instead when reimplementing Collection.

See also
Hyperspace::REST::KeyValueCollection
Hyperspace::REST::ResourceFactory

Constructor & Destructor Documentation

Hyperspace::REST::Collection::Collection ( const QByteArray &  path,
ResourceFactory factory 
)
explicit

Constructs a collection.

path The path to this collection, relative to the Gate's base target path. factory The ResourceFactory for this collection.

Member Function Documentation

QByteArray Hyperspace::REST::Collection::path ( ) const
Returns
The path to this collection, relative to the Gate's base target path.
void Hyperspace::REST::Collection::deleteResource ( const QByteArray &  waveId,
const QByteArray &  resourceId,
const ByteArrayHash &  attributes,
const QByteArray &  payload 
)

Invokes Hyperspace::AbstractWaveTarget::httpDelete on a Resource of this collection, or automatically sends a NotFound Rebound if the resource does not exist or can't be loaded.

waveId The internal waveId. resourceId The ID of the target resource. attributes The wave's attributes. payload The wave payload, if any.

void Hyperspace::REST::Collection::getResource ( const QByteArray &  waveId,
const QByteArray &  resourceId,
const ByteArrayHash &  attributes,
const QByteArray &  payload 
)

Invokes Hyperspace::AbstractWaveTarget::get on a Resource of this collection, or automatically sends a NotFound Rebound if the resource does not exist or can't be loaded.

waveId The internal waveId. resourceId The ID of the target resource. attributes The wave's attributes. payload The wave payload, if any.

void Hyperspace::REST::Collection::postResource ( const QByteArray &  waveId,
const QByteArray &  resourceId,
const ByteArrayHash &  attributes,
const QByteArray &  payload 
)

Invokes Hyperspace::AbstractWaveTarget::post on a Resource of this collection, or automatically sends a NotFound Rebound if the resource does not exist or can't be loaded.

waveId The internal waveId. resourceId The ID of the target resource. attributes The wave's attributes. payload The wave payload, if any.

void Hyperspace::REST::Collection::putResource ( const QByteArray &  waveId,
const QByteArray &  resourceId,
const ByteArrayHash &  attributes,
const QByteArray &  payload 
)

Invokes Hyperspace::AbstractWaveTarget::put on a Resource of this collection, or automatically sends a NotFound Rebound if the resource does not exist or can't be loaded.

waveId The internal waveId. resourceId The ID of the target resource. attributes The wave's attributes. payload The wave payload, if any.

void Hyperspace::REST::Collection::head ( const QByteArray &  waveId,
const ByteArrayHash &  attributes,
const QByteArray &  payload 
)
virtual

Sends back a BadRequest Rebound by default.

Implements Hyperspace::AbstractWaveTarget.

ResourceFactory * Hyperspace::REST::Collection::factory ( ) const
protected
Returns
This Collection's ResourceFactory
virtual Resource* Hyperspace::REST::Collection::loadResource ( const QByteArray &  id)
protectedpure virtual

Loads a resource from the Factory and returns it.

Must be reimplemented by Collection implementations, mainly due to different caching policies.

id The ID of the Resource to be loaded.

Returns
The loaded resource, or a null pointer if the resource could not be loaded.

Implemented in Hyperspace::REST::FixedCachedCollection.