Skip to content

Commit

Permalink
Merge pull request #30 from hartig/ClosableFragments
Browse files Browse the repository at this point in the history
Makes fragments closable
  • Loading branch information
mielvds committed Jan 9, 2016
2 parents 9f4fe2a + 0ad4fc3 commit cee284a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.linkeddatafragments.fragments;

import java.io.Closeable;

import com.hp.hpl.jena.rdf.model.StmtIterator;

/**
* Represents any possible Linked Data Fragment.
*
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
public interface ILinkedDataFragment
public interface ILinkedDataFragment extends Closeable
{
/**
* Returns an iterator over the RDF data of this fragment (possibly only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ protected LinkedDataFragmentBase( final String fragmentURL,
this.isLastPage = isLastPage;
}

/**
* Does nothing. May be overridden by subclasses that hold some objects
* that need to be closed (such as iterators from the underlying data
* source).
*/
@Override
public void close() {}

@Override
public boolean isPageOnly() {
return true;
Expand Down
17 changes: 14 additions & 3 deletions src/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ private IDataSource getDataSource(HttpServletRequest request) throws DataSourceN

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
ILinkedDataFragment fragment = null;
try {
final IDataSource dataSource = getDataSource( request );

final ILinkedDataFragmentRequest ldfRequest =
dataSource.getRequestParser()
.parseIntoFragmentRequest( request, config );

final ILinkedDataFragment fragment =
dataSource.getRequestProcessor()
.createRequestedFragment( ldfRequest );
fragment = dataSource.getRequestProcessor()
.createRequestedFragment( ldfRequest );

final Model output = ModelFactory.createDefaultModel();
output.setNsPrefixes(config.getPrefixes());
Expand Down Expand Up @@ -176,6 +176,17 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
throw new ServletException(ex1);
}
}
finally {
// close the fragment
if ( fragment != null ) {
try {
fragment.close();
}
catch ( Exception e ) {
// ignore
}
}
}
}

}

0 comments on commit cee284a

Please sign in to comment.