org.apache.stanbol.enhancer.servicesapi.helper
Class ContentItemImpl

java.lang.Object
  extended by org.apache.stanbol.enhancer.servicesapi.helper.ContentItemImpl
All Implemented Interfaces:
ContentItem
Direct Known Subclasses:
InMemoryContentItem, WebContentItem

public abstract class ContentItemImpl
extends java.lang.Object
implements ContentItem

A generic ContentItem implementation that takes the uri, main content part and the graph used to store the metadata as parameter.

This content item consisting initially of a single blob. Subclasses don't have to care about multi-parts aspects of content item. By inheriting from this class the ability for clients to add additional parts is ensured.

Even through this class does implement the full ContentItem interface it is marked as abstract and has only a protected constructor because it is not intended that users directly instantiate it. The intended usage is to create subclasses that instantiate ContentItmes with specific combinations of Blob nad MGraph implementations.

Examples are:

TODO (rwesten): check if we want this to be an abstract class or if there are reasons to have a general purpose ContentItem implementation


Field Summary
protected static java.lang.String MAIN_BLOB_SUFFIX
           
protected  java.util.concurrent.locks.Lock readLock
           
protected  java.util.concurrent.locks.Lock writeLock
           
 
Constructor Summary
protected ContentItemImpl(org.apache.clerezza.rdf.core.UriRef uri, Blob main, org.apache.clerezza.rdf.core.MGraph metadata)
           
 
Method Summary
 java.lang.Object addPart(org.apache.clerezza.rdf.core.UriRef uriRef, java.lang.Object object)
          Add a new part to this ContentItem
 boolean equals(java.lang.Object o)
           
 Blob getBlob()
          Final getter retrieving the Blob via getPart(UriRef, Class) with getUri()+MAIN_BLOB_SUFFIX
 java.util.concurrent.locks.ReadWriteLock getLock()
          Read/write lock used to synchronise access to the metadata and the content parts of this content item.
 org.apache.clerezza.rdf.core.access.LockableMGraph getMetadata()
          Optional metadata
 java.lang.String getMimeType()
          The MimeType.
<T> T
getPart(int index, java.lang.Class<T> clazz)
          A content item may consists of multiple parts, while the part with index 0 should always be a blob, higher position may be used by Enhancer to story arbitrary objects, such objects can be used for accessing the precomputations of EnhancementEngines previous in the chain.
<T> T
getPart(org.apache.clerezza.rdf.core.UriRef uri, java.lang.Class<T> clazz)
          Each part of the content item has a URI.
 org.apache.clerezza.rdf.core.UriRef getPartUri(int index)
          Get the uri of the part at the specified index
 java.io.InputStream getStream()
          The binary content stream.
 org.apache.clerezza.rdf.core.UriRef getUri()
          The Uri of this ContentItem (either supplied by client or generated by Stanbol Enhancer)
 int hashCode()
           
 void removePart(int index)
          Removes a part - other than the main content part - from this ContentItem
 void removePart(org.apache.clerezza.rdf.core.UriRef uriRef)
          Removes a part - other than the main content part - from this ContentItem
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAIN_BLOB_SUFFIX

protected static final java.lang.String MAIN_BLOB_SUFFIX
See Also:
Constant Field Values

readLock

protected final java.util.concurrent.locks.Lock readLock

writeLock

protected final java.util.concurrent.locks.Lock writeLock
Constructor Detail

ContentItemImpl

protected ContentItemImpl(org.apache.clerezza.rdf.core.UriRef uri,
                          Blob main,
                          org.apache.clerezza.rdf.core.MGraph metadata)
Method Detail

getLock

public final java.util.concurrent.locks.ReadWriteLock getLock()
Description copied from interface: ContentItem
Read/write lock used to synchronise access to the metadata and the content parts of this content item.

The lock used by the LockableMGraph.getLock() MUST BE the same as the lock returned by this Instance. This is to avoid deadlocks when using a lock while iterating over the metadata and simultaneously accessing the content parts. In other words calling contentItem.getLock() == contentItem.getMetadata().getLock() MUST BE true

Specified by:
getLock in interface ContentItem
Returns:
the lock used for the content parts and the LockableMGraph containing the metadata of this content item.

getBlob

public final Blob getBlob()
Final getter retrieving the Blob via getPart(UriRef, Class) with getUri()+MAIN_BLOB_SUFFIX

Specified by:
getBlob in interface ContentItem
Returns:
the blob at index 0

getStream

public final java.io.InputStream getStream()
Description copied from interface: ContentItem
The binary content stream. Shortcut for ContentItem.getBlob().getStream()

Specified by:
getStream in interface ContentItem
Returns:
the InputStream

getMimeType

public final java.lang.String getMimeType()
Description copied from interface: ContentItem
The MimeType. Shortcut for ContentItem.getBlob().getMimeType().

Specified by:
getMimeType in interface ContentItem
Returns:
the MimeType as string

getPart

public <T> T getPart(org.apache.clerezza.rdf.core.UriRef uri,
                     java.lang.Class<T> clazz)
          throws NoSuchPartException
Description copied from interface: ContentItem
Each part of the content item has a URI. EnhancementEngines typically access parts by their Uri as the position may vary depending on the chain.

Specified by:
getPart in interface ContentItem
Throws:
NoSuchPartException - if no part with the parsed uri exists

getPartUri

public org.apache.clerezza.rdf.core.UriRef getPartUri(int index)
                                               throws NoSuchPartException
Description copied from interface: ContentItem
Get the uri of the part at the specified index

Specified by:
getPartUri in interface ContentItem
Throws:
NoSuchPartException - if no part with the parsed index exists

getPart

public <T> T getPart(int index,
                     java.lang.Class<T> clazz)
          throws NoSuchPartException
Description copied from interface: ContentItem
A content item may consists of multiple parts, while the part with index 0 should always be a blob, higher position may be used by Enhancer to story arbitrary objects, such objects can be used for accessing the precomputations of EnhancementEngines previous in the chain.

Specified by:
getPart in interface ContentItem
Throws:
NoSuchPartException - if no part with the parsed index exists

addPart

public java.lang.Object addPart(org.apache.clerezza.rdf.core.UriRef uriRef,
                                java.lang.Object object)
Description copied from interface: ContentItem
Add a new part to this ContentItem

Specified by:
addPart in interface ContentItem
Parameters:
uriRef - the URI of the part
object - the part
Returns:
the part replaced by the parsed object or null if no part with the parsed URI was present

removePart

public void removePart(int index)
Description copied from interface: ContentItem
Removes a part - other than the main content part - from this ContentItem

Specified by:
removePart in interface ContentItem
Parameters:
index - the index of the part to remove. NOTE that index '0' - the main content part - can NOT be removed!

removePart

public void removePart(org.apache.clerezza.rdf.core.UriRef uriRef)
Description copied from interface: ContentItem
Removes a part - other than the main content part - from this ContentItem

Specified by:
removePart in interface ContentItem
Parameters:
uriRef - the uri of the part to remove. NOTE that the part with the uri getPartUri(0) - the main content part - can NOT be removed!

getUri

public org.apache.clerezza.rdf.core.UriRef getUri()
Description copied from interface: ContentItem
The Uri of this ContentItem (either supplied by client or generated by Stanbol Enhancer)

Specified by:
getUri in interface ContentItem

getMetadata

public org.apache.clerezza.rdf.core.access.LockableMGraph getMetadata()
Description copied from interface: ContentItem
Optional metadata

Specified by:
getMetadata in interface ContentItem

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2010-2012 The Apache Software Foundation. All Rights Reserved.