use of org.apache.stanbol.enhancer.servicesapi.NoSuchPartException in project stanbol by apache.
the class ExecutionMetadataHelper method initExecutionMetadataContentPart.
/**
* Getter/Initialiser for the execution metadata content part of the parsed
* content item. This part is expected to be registered with the URI
* {@link ExecutionMetadata#CHAIN_EXECUTION}. If it does not already exist
* this method creates an empty graph and register it with the parsed
* content item otherwise it returns the existing part registered under that
* URI.<p>
* Typically users will also want to use
* {@link #initExecutionMetadata(Graph, Graph, IRI, String, boolean)}
* to initialise the state based on the grpah returned by this method.
* NOTES:<ul>
* <li> If a content part is registered under the URI
* {@link ExecutionMetadata#CHAIN_EXECUTION} that is not of type
* {@link Graph} this method will replace it with an empty {@link Graph}.
* <li> This method acquires a write lock on the content item while checking
* for the content part.
* </ul>
* @param contentItem the contentItem
* @return the {@link Graph} with the execution metadata as registered as
* content part with the URI {@link ExecutionMetadata#CHAIN_EXECUTION} to
* the {@link ContentItem}
* @throws IllegalArgumentException if the parsed content itme is <code>null</code>.
*/
public static Graph initExecutionMetadataContentPart(ContentItem contentItem) {
if (contentItem == null) {
throw new IllegalArgumentException("The parsed ContentItme MUST NOT be NULL!");
}
Graph executionMetadata;
contentItem.getLock().writeLock().lock();
try {
try {
executionMetadata = contentItem.getPart(CHAIN_EXECUTION, Graph.class);
} catch (NoSuchPartException e) {
executionMetadata = new IndexedGraph();
contentItem.addPart(CHAIN_EXECUTION, executionMetadata);
}
} finally {
contentItem.getLock().writeLock().unlock();
}
return executionMetadata;
}
Aggregations