org.apache.abdera.protocol.server.impl
Class AbstractEntityCollectionAdapter<T>

java.lang.Object
  extended by org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
      extended by org.apache.abdera.protocol.server.impl.AbstractEntityCollectionAdapter<T>
Type Parameters:
T - The entity that this is backed by.
All Implemented Interfaces:
CollectionAdapter, CollectionInfo, MediaCollectionAdapter, Transactional
Direct Known Subclasses:
EmployeeCollectionAdapter, JcrCollectionAdapter

public abstract class AbstractEntityCollectionAdapter<T>
extends AbstractCollectionAdapter

By extending this class it becomes easy to build Collections which are backed by a set of entities - such as a database row, domain objects, or files.


Constructor Summary
AbstractEntityCollectionAdapter()
           
 
Method Summary
protected  void addContent(Entry e, T doc, RequestContext request)
          Adds the atom:content element to an entry
protected  String addEntryDetails(RequestContext request, Entry e, IRI feedIri, T entryObj)
          Add the details to an entry
protected  void addFeedDetails(Feed feed, RequestContext request)
          Adds the selected entries to the Feed document.
protected  String addMediaContent(IRI feedIri, Entry entry, T entryObj, RequestContext request)
          Add media content details to a media-link entry
protected  ResponseContext buildGetMediaResponse(String id, T entryObj)
          Creates a ResponseContext for a GET media request.
protected  ResponseContext createMediaEntry(RequestContext request)
          Create a media entry
protected  ResponseContext createNonMediaEntry(RequestContext request)
          Create a regular entry
 ResponseContext deleteEntry(RequestContext request)
          Delete an entry from the collection
abstract  void deleteEntry(String resourceName, RequestContext request)
          Delete an entry
 ResponseContext deleteMedia(RequestContext request)
          Delete a media resource from the collection
 void deleteMedia(String resourceName, RequestContext request)
          Delete a media resource.
 List<Person> getAuthors(T entry, RequestContext request)
          Get the authors for an entry.
abstract  Object getContent(T entry, RequestContext request)
          Get the content for the entry.
 String getContentType(T entry)
          Get the content-type for the entry.
abstract  Iterable<T> getEntries(RequestContext request)
          Get the listing of entries requested
 ResponseContext getEntry(RequestContext request)
          Get an entry from the collection
abstract  T getEntry(String resourceName, RequestContext request)
          Get a specific entry
protected  Entry getEntryFromCollectionProvider(RequestContext request)
           
 ResponseContext getFeed(RequestContext request)
          Get the collections Atom feed document
protected  String getFeedIriForEntry(T entryObj, RequestContext request)
          Get the Feed IRI
abstract  String getId(T entry)
          Gets the UUID for the specified entry.
protected  String getLink(String name, T entryObj, IRI feedIri, RequestContext request)
           
protected  String getLink(String name, T entryObj, IRI feedIri, RequestContext request, boolean absolute)
           
protected  String getLink(T entryObj, IRI feedIri, RequestContext request)
           
protected  String getLink(T entryObj, IRI feedIri, RequestContext request, boolean absolute)
           
 ResponseContext getMedia(RequestContext request)
          Get a media resource
 String getMediaName(T entry)
          Get the name of the media resource.
 InputStream getMediaStream(T entry)
          Get an input stream for the media resource.
abstract  String getName(T entry)
          Get the name of the entry resource (used to construct links)
protected  String getQueryParameters(T entryObj, RequestContext request)
           
 Text getSummary(T entry, RequestContext request)
          Get the summary of the entry.
abstract  String getTitle(T entry)
          Get the title fo the entry
abstract  Date getUpdated(T entry)
          Get the value to use in the atom:updated element
 ResponseContext headEntry(RequestContext request)
          Get metadata for an entry from the collection
 ResponseContext headMedia(RequestContext request)
          Get metdata for a media resource
 boolean isMediaEntry(T entry)
          True if this entry is a media-link entry.
 ResponseContext postEntry(RequestContext request)
          Post a new entry to the collection
abstract  T postEntry(String title, IRI id, String summary, Date updated, List<Person> authors, Content content, RequestContext request)
          Create a new entry
 T postMedia(javax.activation.MimeType mimeType, String slug, InputStream inputStream, RequestContext request)
          Post a new media resource to the collection.
 ResponseContext postMedia(RequestContext request)
          Add a new media resource to the collection, resulting in the creation of a new Media Link Entry.
 ResponseContext putEntry(RequestContext request)
          Update an existing entry
abstract  void putEntry(T entry, String title, Date updated, List<Person> authors, String summary, Content content, RequestContext request)
          Update an entry.
 ResponseContext putMedia(RequestContext request)
          Update a media resource
 void putMedia(T entryObj, javax.activation.MimeType contentType, String slug, InputStream inputStream, RequestContext request)
          Update a media resource.
 
Methods inherited from class org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter
asCollectionElement, buildCreateEntryResponse, buildGetEntryResponse, buildGetFeedResponse, buildHeadEntryResponse, buildPostMediaEntryResponse, compensate, createErrorResponse, createFeedBase, end, extensionRequest, getAccepts, getAuthor, getCategories, getCategoriesInfo, getEntryFromRequest, getHref, getHref, getId, getResourceName, optionsEntry, optionsMedia, setHref, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.abdera.protocol.server.CollectionInfo
getTitle
 

Constructor Detail

AbstractEntityCollectionAdapter

public AbstractEntityCollectionAdapter()
Method Detail

postEntry

public abstract T postEntry(String title,
                            IRI id,
                            String summary,
                            Date updated,
                            List<Person> authors,
                            Content content,
                            RequestContext request)
                     throws ResponseContextException
Create a new entry

Parameters:
title - The title of the entry (assumes that type="text")
id - The value of the atom:id element
summary - The summary of the entry
updated - The value of the atom:updated element
authors - Listing of atom:author elements
context - The content of the entry
request - The request context
Throws:
ResponseContextException

postMedia

public ResponseContext postMedia(RequestContext request)
Description copied from interface: MediaCollectionAdapter
Add a new media resource to the collection, resulting in the creation of a new Media Link Entry.

Specified by:
postMedia in interface MediaCollectionAdapter
Overrides:
postMedia in class AbstractCollectionAdapter

putMedia

public ResponseContext putMedia(RequestContext request)
Description copied from interface: MediaCollectionAdapter
Update a media resource

Specified by:
putMedia in interface MediaCollectionAdapter
Overrides:
putMedia in class AbstractCollectionAdapter

putMedia

public void putMedia(T entryObj,
                     javax.activation.MimeType contentType,
                     String slug,
                     InputStream inputStream,
                     RequestContext request)
              throws ResponseContextException
Update a media resource. By default this method is not allowed. Implementations must override this method to support media resource updates

Parameters:
entryObj -
contentType - The mime-type of the media resource
slug - The value of the Slug request header
inputStream - An input stream providing access to the request payload
request - The request context
Throws:
ResponseContextException

postEntry

public ResponseContext postEntry(RequestContext request)
Description copied from interface: CollectionAdapter
Post a new entry to the collection


getLink

protected String getLink(T entryObj,
                         IRI feedIri,
                         RequestContext request)
                  throws ResponseContextException
Throws:
ResponseContextException

getLink

protected String getLink(T entryObj,
                         IRI feedIri,
                         RequestContext request,
                         boolean absolute)
                  throws ResponseContextException
Throws:
ResponseContextException

getLink

protected String getLink(String name,
                         T entryObj,
                         IRI feedIri,
                         RequestContext request)

getLink

protected String getLink(String name,
                         T entryObj,
                         IRI feedIri,
                         RequestContext request,
                         boolean absolute)

getQueryParameters

protected String getQueryParameters(T entryObj,
                                    RequestContext request)

postMedia

public T postMedia(javax.activation.MimeType mimeType,
                   String slug,
                   InputStream inputStream,
                   RequestContext request)
            throws ResponseContextException
Post a new media resource to the collection. By default, this method is not supported. Implementations must override this method to support posting media resources

Parameters:
mimeType - The mime-type of the resource
slug - The value of the Slug header
inputStream - An InputStream providing access to the request payload
request - The request context
Throws:
ResponseContextException

deleteEntry

public ResponseContext deleteEntry(RequestContext request)
Description copied from interface: CollectionAdapter
Delete an entry from the collection


deleteEntry

public abstract void deleteEntry(String resourceName,
                                 RequestContext request)
                          throws ResponseContextException
Delete an entry

Parameters:
resourceName - The entry to delete
request - The request context
Throws:
ResponseContextException

deleteMedia

public ResponseContext deleteMedia(RequestContext request)
Description copied from interface: MediaCollectionAdapter
Delete a media resource from the collection

Specified by:
deleteMedia in interface MediaCollectionAdapter
Overrides:
deleteMedia in class AbstractCollectionAdapter

deleteMedia

public void deleteMedia(String resourceName,
                        RequestContext request)
                 throws ResponseContextException
Delete a media resource. By default this method is not supported. Implementations must override this method to support deleting media resources

Throws:
ResponseContextException

getAuthors

public List<Person> getAuthors(T entry,
                               RequestContext request)
                        throws ResponseContextException
Get the authors for an entry. By default this returns null. Implementations must override in order to providing a listing of authors for an entry

Throws:
ResponseContextException

getContent

public abstract Object getContent(T entry,
                                  RequestContext request)
                           throws ResponseContextException
Get the content for the entry.

Throws:
ResponseContextException

getContentType

public String getContentType(T entry)
Get the content-type for the entry. By default this operation is not supported.


getEntries

public abstract Iterable<T> getEntries(RequestContext request)
                                throws ResponseContextException
Get the listing of entries requested

Throws:
ResponseContextException

getEntry

public ResponseContext getEntry(RequestContext request)
Description copied from interface: CollectionAdapter
Get an entry from the collection


getEntry

public abstract T getEntry(String resourceName,
                           RequestContext request)
                    throws ResponseContextException
Get a specific entry

Parameters:
resourceName - The entry to get
request - The request context
Throws:
ResponseContextException

headEntry

public ResponseContext headEntry(RequestContext request)
Description copied from interface: CollectionAdapter
Get metadata for an entry from the collection

Specified by:
headEntry in interface CollectionAdapter
Overrides:
headEntry in class AbstractCollectionAdapter

headMedia

public ResponseContext headMedia(RequestContext request)
Description copied from interface: MediaCollectionAdapter
Get metdata for a media resource

Specified by:
headMedia in interface MediaCollectionAdapter
Overrides:
headMedia in class AbstractCollectionAdapter

getFeed

public ResponseContext getFeed(RequestContext request)
Description copied from interface: CollectionAdapter
Get the collections Atom feed document


addFeedDetails

protected void addFeedDetails(Feed feed,
                              RequestContext request)
                       throws ResponseContextException
Adds the selected entries to the Feed document. By default, this will set the feed's atom:updated element to the current date and time

Throws:
ResponseContextException

getId

public abstract String getId(T entry)
                      throws ResponseContextException
Gets the UUID for the specified entry.

Parameters:
entry -
Returns:
Throws:
ResponseContextException

getMedia

public ResponseContext getMedia(RequestContext request)
Description copied from interface: MediaCollectionAdapter
Get a media resource

Specified by:
getMedia in interface MediaCollectionAdapter
Overrides:
getMedia in class AbstractCollectionAdapter

buildGetMediaResponse

protected ResponseContext buildGetMediaResponse(String id,
                                                T entryObj)
                                         throws ResponseContextException
Creates a ResponseContext for a GET media request. By default, this returns a MediaResponseContext containing the media resource. The last-modified header will be set.

Throws:
ResponseContextException

getMediaName

public String getMediaName(T entry)
                    throws ResponseContextException
Get the name of the media resource. By default this method is unsupported. Implementations must override.

Throws:
ResponseContextException

getMediaStream

public InputStream getMediaStream(T entry)
                           throws ResponseContextException
Get an input stream for the media resource. By default this method is unsupported. Implementations must override.

Throws:
ResponseContextException

getName

public abstract String getName(T entry)
                        throws ResponseContextException
Get the name of the entry resource (used to construct links)

Throws:
ResponseContextException

getTitle

public abstract String getTitle(T entry)
                         throws ResponseContextException
Get the title fo the entry

Throws:
ResponseContextException

getUpdated

public abstract Date getUpdated(T entry)
                         throws ResponseContextException
Get the value to use in the atom:updated element

Throws:
ResponseContextException

isMediaEntry

public boolean isMediaEntry(T entry)
                     throws ResponseContextException
True if this entry is a media-link entry. By default this always returns false. Implementations must override to support media link entries

Throws:
ResponseContextException

putEntry

public ResponseContext putEntry(RequestContext request)
Description copied from interface: CollectionAdapter
Update an existing entry


getFeedIriForEntry

protected String getFeedIriForEntry(T entryObj,
                                    RequestContext request)
Get the Feed IRI


putEntry

public abstract void putEntry(T entry,
                              String title,
                              Date updated,
                              List<Person> authors,
                              String summary,
                              Content content,
                              RequestContext request)
                       throws ResponseContextException
Update an entry.

Parameters:
entry - The entry to update
title - The new title of the entry
updated - The new value of atom:updated
authors - To new listing of authors
summary - The new summary
content - The new content
request - The request context
Throws:
ResponseContextException

addContent

protected void addContent(Entry e,
                          T doc,
                          RequestContext request)
                   throws ResponseContextException
Adds the atom:content element to an entry

Throws:
ResponseContextException

addEntryDetails

protected String addEntryDetails(RequestContext request,
                                 Entry e,
                                 IRI feedIri,
                                 T entryObj)
                          throws ResponseContextException
Add the details to an entry

Parameters:
request - The request context
e - The entry
feedIri - The feed IRI
entryObj -
Throws:
ResponseContextException

getSummary

public Text getSummary(T entry,
                       RequestContext request)
                throws ResponseContextException
Get the summary of the entry. By default this returns null.

Throws:
ResponseContextException

addMediaContent

protected String addMediaContent(IRI feedIri,
                                 Entry entry,
                                 T entryObj,
                                 RequestContext request)
                          throws ResponseContextException
Add media content details to a media-link entry

Parameters:
feedIri - The feed iri
entry - The entry object
entryObj -
request - The request context
Throws:
ResponseContextException

createMediaEntry

protected ResponseContext createMediaEntry(RequestContext request)
Create a media entry

Parameters:
request - The request context

createNonMediaEntry

protected ResponseContext createNonMediaEntry(RequestContext request)
Create a regular entry

Parameters:
request - The request context

getEntryFromCollectionProvider

protected Entry getEntryFromCollectionProvider(RequestContext request)
                                        throws ResponseContextException
Throws:
ResponseContextException


Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.