From 9f4fe2a9c5939e39ee089a881cb0b2770f2a538b Mon Sep 17 00:00:00 2001 From: Miel Vander Sande Date: Mon, 4 Jan 2016 16:20:41 +0100 Subject: [PATCH] Cleanup and finished interface renaming --- .../datasource/AbstractRequestProcessor.java | 10 +++++----- ...tractRequestProcessorForTriplePatterns.java | 6 +++--- .../datasource/DataSourceFactory.java | 6 +++--- .../datasource/IDataSourceType.java | 4 ++-- .../datasource/IFragmentRequestProcessor.java | 8 ++++---- .../datasource/hdt/HdtDataSourceType.java | 6 +++--- .../datasource/tdb/JenaTDBDataSourceType.java | 6 +++--- .../DataSourceCreationException.java | 16 ++++++++++++++++ .../exceptions/DataSourceException.java | 18 ++++++++++++------ .../DataSourceNotFoundException.java | 11 ++--------- .../UnknownDataSourceTypeException.java | 7 +++---- .../fragments/FragmentRequestParserBase.java | 6 +++--- .../fragments/IFragmentRequestParser.java | 6 +++--- ...st.java => ILinkedDataFragmentRequest.java} | 2 +- .../fragments/LinkedDataFragmentBase.java | 8 ++++---- .../LinkedDataFragmentRequestBase.java | 4 ++-- .../tpf/ITriplePatternFragmentRequest.java | 4 ++-- .../fragments/tpf/TPFRequestParser.java | 4 ++-- .../servlet/LinkedDataFragmentServlet.java | 4 ++-- .../org/linkeddatafragments/TestSuite.java | 5 ----- 20 files changed, 75 insertions(+), 66 deletions(-) create mode 100644 src/org/linkeddatafragments/exceptions/DataSourceCreationException.java rename src/org/linkeddatafragments/fragments/{LinkedDataFragmentRequest.java => ILinkedDataFragmentRequest.java} (95%) diff --git a/src/org/linkeddatafragments/datasource/AbstractRequestProcessor.java b/src/org/linkeddatafragments/datasource/AbstractRequestProcessor.java index eba9953..096c21e 100644 --- a/src/org/linkeddatafragments/datasource/AbstractRequestProcessor.java +++ b/src/org/linkeddatafragments/datasource/AbstractRequestProcessor.java @@ -1,7 +1,7 @@ package org.linkeddatafragments.datasource; import org.linkeddatafragments.fragments.ILinkedDataFragment; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; /** * Base class for implementations of {@link IFragmentRequestProcessor}. @@ -16,22 +16,22 @@ public void close() {} @Override final public ILinkedDataFragment createRequestedFragment( - final LinkedDataFragmentRequest request ) + final ILinkedDataFragmentRequest request ) throws IllegalArgumentException { return getWorker( request ).createRequestedFragment(); } abstract protected Worker getWorker( - final LinkedDataFragmentRequest request ) + final ILinkedDataFragmentRequest request ) throws IllegalArgumentException; abstract static protected class Worker { - public final LinkedDataFragmentRequest request; + public final ILinkedDataFragmentRequest request; - public Worker( final LinkedDataFragmentRequest request ) + public Worker( final ILinkedDataFragmentRequest request ) { this.request = request; } diff --git a/src/org/linkeddatafragments/datasource/AbstractRequestProcessorForTriplePatterns.java b/src/org/linkeddatafragments/datasource/AbstractRequestProcessorForTriplePatterns.java index 171df1b..e15ef76 100644 --- a/src/org/linkeddatafragments/datasource/AbstractRequestProcessorForTriplePatterns.java +++ b/src/org/linkeddatafragments/datasource/AbstractRequestProcessorForTriplePatterns.java @@ -3,7 +3,7 @@ import com.hp.hpl.jena.rdf.model.Model; import org.linkeddatafragments.fragments.ILinkedDataFragment; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; import org.linkeddatafragments.fragments.tpf.ITriplePatternElement; import org.linkeddatafragments.fragments.tpf.ITriplePatternFragment; import org.linkeddatafragments.fragments.tpf.TriplePatternFragmentImpl; @@ -30,7 +30,7 @@ { @Override protected final Worker getWorker( - final LinkedDataFragmentRequest request ) + final ILinkedDataFragmentRequest request ) throws IllegalArgumentException { if ( request instanceof ITriplePatternFragmentRequest ) { @@ -61,7 +61,7 @@ public Worker( public ILinkedDataFragment createRequestedFragment() throws IllegalArgumentException { - final long limit = LinkedDataFragmentRequest.TRIPLESPERPAGE; + final long limit = ILinkedDataFragmentRequest.TRIPLESPERPAGE; final long offset; if ( request.isPageRequest() ) offset = limit * ( request.getPageNumber() - 1L ); diff --git a/src/org/linkeddatafragments/datasource/DataSourceFactory.java b/src/org/linkeddatafragments/datasource/DataSourceFactory.java index b64505f..d23741d 100644 --- a/src/org/linkeddatafragments/datasource/DataSourceFactory.java +++ b/src/org/linkeddatafragments/datasource/DataSourceFactory.java @@ -1,7 +1,7 @@ package org.linkeddatafragments.datasource; import com.google.gson.JsonObject; -import org.linkeddatafragments.exceptions.DataSourceException; +import org.linkeddatafragments.exceptions.DataSourceCreationException; import org.linkeddatafragments.exceptions.UnknownDataSourceTypeException; /** @@ -16,9 +16,9 @@ public class DataSourceFactory { * * @param config * @return datasource interface - * @throws DataSourceException + * @throws DataSourceCreationException */ - public static IDataSource create(JsonObject config) throws DataSourceException { + public static IDataSource create(JsonObject config) throws DataSourceCreationException { String title = config.getAsJsonPrimitive("title").getAsString(); String description = config.getAsJsonPrimitive("description").getAsString(); String typeName = config.getAsJsonPrimitive("type").getAsString(); diff --git a/src/org/linkeddatafragments/datasource/IDataSourceType.java b/src/org/linkeddatafragments/datasource/IDataSourceType.java index f4c100c..6380f90 100644 --- a/src/org/linkeddatafragments/datasource/IDataSourceType.java +++ b/src/org/linkeddatafragments/datasource/IDataSourceType.java @@ -1,6 +1,6 @@ package org.linkeddatafragments.datasource; -import org.linkeddatafragments.exceptions.DataSourceException; +import org.linkeddatafragments.exceptions.DataSourceCreationException; import com.google.gson.JsonObject; @@ -28,5 +28,5 @@ public interface IDataSourceType IDataSource createDataSource( final String title, final String description, final JsonObject settings ) - throws DataSourceException; + throws DataSourceCreationException; } diff --git a/src/org/linkeddatafragments/datasource/IFragmentRequestProcessor.java b/src/org/linkeddatafragments/datasource/IFragmentRequestProcessor.java index 1b6a4bb..ba6bd80 100644 --- a/src/org/linkeddatafragments/datasource/IFragmentRequestProcessor.java +++ b/src/org/linkeddatafragments/datasource/IFragmentRequestProcessor.java @@ -4,11 +4,11 @@ import org.linkeddatafragments.fragments.ILinkedDataFragment; import org.linkeddatafragments.fragments.ILinkedDataFragment; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; /** - * Processes {@link LinkedDataFragmentRequest}s and returns + * Processes {@link ILinkedDataFragmentRequest}s and returns * the requested {@link ILinkedDataFragment}s. * * @author Olaf Hartig @@ -16,6 +16,6 @@ public interface IFragmentRequestProcessor extends Closeable { ILinkedDataFragment createRequestedFragment( - final LinkedDataFragmentRequest request ) + final ILinkedDataFragmentRequest request ) throws IllegalArgumentException; } diff --git a/src/org/linkeddatafragments/datasource/hdt/HdtDataSourceType.java b/src/org/linkeddatafragments/datasource/hdt/HdtDataSourceType.java index 2826c2f..0ae1afa 100644 --- a/src/org/linkeddatafragments/datasource/hdt/HdtDataSourceType.java +++ b/src/org/linkeddatafragments/datasource/hdt/HdtDataSourceType.java @@ -5,7 +5,7 @@ import org.linkeddatafragments.datasource.IDataSource; import org.linkeddatafragments.datasource.IDataSourceType; -import org.linkeddatafragments.exceptions.DataSourceException; +import org.linkeddatafragments.exceptions.DataSourceCreationException; import com.google.gson.JsonObject; @@ -20,7 +20,7 @@ public class HdtDataSourceType implements IDataSourceType public IDataSource createDataSource( final String title, final String description, final JsonObject settings ) - throws DataSourceException + throws DataSourceCreationException { final String fname = settings.getAsJsonPrimitive("file").getAsString(); final File file = new File( fname ); @@ -28,7 +28,7 @@ public IDataSource createDataSource( final String title, try { return new HdtDataSource(title, description, file.getAbsolutePath()); } catch (IOException ex) { - throw new DataSourceException(ex); + throw new DataSourceCreationException(ex); } } diff --git a/src/org/linkeddatafragments/datasource/tdb/JenaTDBDataSourceType.java b/src/org/linkeddatafragments/datasource/tdb/JenaTDBDataSourceType.java index 3be3dea..599b16d 100644 --- a/src/org/linkeddatafragments/datasource/tdb/JenaTDBDataSourceType.java +++ b/src/org/linkeddatafragments/datasource/tdb/JenaTDBDataSourceType.java @@ -4,7 +4,7 @@ import org.linkeddatafragments.datasource.IDataSource; import org.linkeddatafragments.datasource.IDataSourceType; -import org.linkeddatafragments.exceptions.DataSourceException; +import org.linkeddatafragments.exceptions.DataSourceCreationException; import com.google.gson.JsonObject; @@ -20,7 +20,7 @@ public class JenaTDBDataSourceType implements IDataSourceType public IDataSource createDataSource( final String title, final String description, final JsonObject settings ) - throws DataSourceException + throws DataSourceCreationException { final String dname = settings.getAsJsonPrimitive("directory").getAsString(); final File dir = new File( dname ); @@ -28,7 +28,7 @@ public IDataSource createDataSource( final String title, try { return new JenaTDBDataSource(title, description, dir); } catch (Exception ex) { - throw new DataSourceException(ex); + throw new DataSourceCreationException(ex); } } diff --git a/src/org/linkeddatafragments/exceptions/DataSourceCreationException.java b/src/org/linkeddatafragments/exceptions/DataSourceCreationException.java new file mode 100644 index 0000000..6fd9499 --- /dev/null +++ b/src/org/linkeddatafragments/exceptions/DataSourceCreationException.java @@ -0,0 +1,16 @@ +package org.linkeddatafragments.exceptions; + +/** + * + * @author mielvandersande + */ +public class DataSourceCreationException extends DataSourceException { + + public DataSourceCreationException(Throwable cause) { + super(cause); + } + + public DataSourceCreationException(String datasourceName, String message) { + super(datasourceName, "Could not create DataSource - " + message); + } +} diff --git a/src/org/linkeddatafragments/exceptions/DataSourceException.java b/src/org/linkeddatafragments/exceptions/DataSourceException.java index fb6bd6a..10fb1c0 100644 --- a/src/org/linkeddatafragments/exceptions/DataSourceException.java +++ b/src/org/linkeddatafragments/exceptions/DataSourceException.java @@ -1,17 +1,23 @@ package org.linkeddatafragments.exceptions; +import org.linkeddatafragments.datasource.IDataSource; + /** * * @author mielvandersande */ -public class DataSourceException extends Exception { - private static final long serialVersionUID = 1L; +abstract public class DataSourceException extends Exception { public DataSourceException(Throwable cause) { - super(cause.getMessage()); + super(cause); } - public DataSourceException(String message) { - super("Could not create DataSource: " + message); - } + public DataSourceException(String datasourceName, String message) { + super("Error for datasource '" + datasourceName + "': " + message); + } + + public DataSourceException(IDataSource datasource, String message) { + this(datasource.getTitle(), message); + } + } diff --git a/src/org/linkeddatafragments/exceptions/DataSourceNotFoundException.java b/src/org/linkeddatafragments/exceptions/DataSourceNotFoundException.java index aeb721c..d002aa6 100644 --- a/src/org/linkeddatafragments/exceptions/DataSourceNotFoundException.java +++ b/src/org/linkeddatafragments/exceptions/DataSourceNotFoundException.java @@ -1,19 +1,12 @@ package org.linkeddatafragments.exceptions; -import org.linkeddatafragments.datasource.IDataSource; - /** * * @author mielvandersande */ -public class DataSourceNotFoundException extends Exception { - private static final long serialVersionUID = 1L; - - public DataSourceNotFoundException(Throwable cause) { - super(cause.getMessage()); - } +public class DataSourceNotFoundException extends DataSourceException { public DataSourceNotFoundException(String dataSourceName) { - super("Data source " + dataSourceName + " not found."); + super(dataSourceName, "Datasource not found."); } } diff --git a/src/org/linkeddatafragments/exceptions/UnknownDataSourceTypeException.java b/src/org/linkeddatafragments/exceptions/UnknownDataSourceTypeException.java index e7dc9fc..5c7b358 100644 --- a/src/org/linkeddatafragments/exceptions/UnknownDataSourceTypeException.java +++ b/src/org/linkeddatafragments/exceptions/UnknownDataSourceTypeException.java @@ -4,10 +4,9 @@ * * @author mielvandersande */ -public class UnknownDataSourceTypeException extends DataSourceException { - private static final long serialVersionUID = 1L; - +public class UnknownDataSourceTypeException extends DataSourceCreationException { + public UnknownDataSourceTypeException(String type) { - super("Type " + type + " does not exist."); + super("", "Type " + type + " does not exist."); } } diff --git a/src/org/linkeddatafragments/fragments/FragmentRequestParserBase.java b/src/org/linkeddatafragments/fragments/FragmentRequestParserBase.java index 210cb1e..5910f7b 100644 --- a/src/org/linkeddatafragments/fragments/FragmentRequestParserBase.java +++ b/src/org/linkeddatafragments/fragments/FragmentRequestParserBase.java @@ -12,7 +12,7 @@ abstract public class FragmentRequestParserBase implements IFragmentRequestParser { @Override - final public LinkedDataFragmentRequest parseIntoFragmentRequest( + final public ILinkedDataFragmentRequest parseIntoFragmentRequest( final HttpServletRequest httpRequest, final ConfigReader config ) throws IllegalArgumentException @@ -40,7 +40,7 @@ public Worker( final HttpServletRequest request, this.config = config; final String givenPageNumber = request.getParameter( - LinkedDataFragmentRequest.PARAMETERNAME_PAGE ); + ILinkedDataFragmentRequest.PARAMETERNAME_PAGE ); if ( givenPageNumber != null ) { long pageNumber; try { @@ -57,7 +57,7 @@ public Worker( final HttpServletRequest request, } } - abstract public LinkedDataFragmentRequest createFragmentRequest() + abstract public ILinkedDataFragmentRequest createFragmentRequest() throws IllegalArgumentException; public String getFragmentURL() { diff --git a/src/org/linkeddatafragments/fragments/IFragmentRequestParser.java b/src/org/linkeddatafragments/fragments/IFragmentRequestParser.java index 64cf59f..99cde96 100644 --- a/src/org/linkeddatafragments/fragments/IFragmentRequestParser.java +++ b/src/org/linkeddatafragments/fragments/IFragmentRequestParser.java @@ -5,7 +5,7 @@ import org.linkeddatafragments.config.ConfigReader; /** - * Parses HTTP requests into specific {@link LinkedDataFragmentRequest}s. + * Parses HTTP requests into specific {@link ILinkedDataFragmentRequest}s. * * @author Olaf Hartig */ @@ -13,13 +13,13 @@ public interface IFragmentRequestParser { /** * Parses the given HTTP request into a specific - * {@link LinkedDataFragmentRequest}. + * {@link ILinkedDataFragmentRequest}. * * @throws IllegalArgumentException * If the given HTTP request cannot be interpreted (perhaps due to * missing request parameters). */ - LinkedDataFragmentRequest parseIntoFragmentRequest( + ILinkedDataFragmentRequest parseIntoFragmentRequest( final HttpServletRequest httpRequest, final ConfigReader config ) throws IllegalArgumentException; diff --git a/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequest.java b/src/org/linkeddatafragments/fragments/ILinkedDataFragmentRequest.java similarity index 95% rename from src/org/linkeddatafragments/fragments/LinkedDataFragmentRequest.java rename to src/org/linkeddatafragments/fragments/ILinkedDataFragmentRequest.java index 3cc12c0..eebfa81 100644 --- a/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequest.java +++ b/src/org/linkeddatafragments/fragments/ILinkedDataFragmentRequest.java @@ -5,7 +5,7 @@ * * @author Olaf Hartig */ -public interface LinkedDataFragmentRequest +public interface ILinkedDataFragmentRequest { public final static long TRIPLESPERPAGE = 100L; public final static String PARAMETERNAME_PAGE = "page"; diff --git a/src/org/linkeddatafragments/fragments/LinkedDataFragmentBase.java b/src/org/linkeddatafragments/fragments/LinkedDataFragmentBase.java index a87f13f..9da713c 100644 --- a/src/org/linkeddatafragments/fragments/LinkedDataFragmentBase.java +++ b/src/org/linkeddatafragments/fragments/LinkedDataFragmentBase.java @@ -51,7 +51,7 @@ public boolean isLastPage() { @Override public long getMaxPageSize() { - return LinkedDataFragmentRequest.TRIPLESPERPAGE; + return ILinkedDataFragmentRequest.TRIPLESPERPAGE; } /** @@ -113,7 +113,7 @@ public void addControls( final Model model ) final Resource firstPageId = model.createResource( - pagedURL.setParameter(LinkedDataFragmentRequest.PARAMETERNAME_PAGE, + pagedURL.setParameter(ILinkedDataFragmentRequest.PARAMETERNAME_PAGE, "1").toString() ); fragmentId.addProperty( CommonResources.HYDRA_FIRSTPAGE, firstPageId ); @@ -122,7 +122,7 @@ public void addControls( final Model model ) final String prevPageNumber = Long.toString( pageNumber - 1 ); final Resource prevPageId = model.createResource( - pagedURL.setParameter(LinkedDataFragmentRequest.PARAMETERNAME_PAGE, + pagedURL.setParameter(ILinkedDataFragmentRequest.PARAMETERNAME_PAGE, prevPageNumber).toString() ); fragmentId.addProperty( CommonResources.HYDRA_PREVIOUSPAGE, prevPageId ); @@ -132,7 +132,7 @@ public void addControls( final Model model ) final String nextPageNumber = Long.toString( pageNumber + 1 ); final Resource nextPageId = model.createResource( - pagedURL.setParameter(LinkedDataFragmentRequest.PARAMETERNAME_PAGE, + pagedURL.setParameter(ILinkedDataFragmentRequest.PARAMETERNAME_PAGE, nextPageNumber).toString() ); fragmentId.addProperty( CommonResources.HYDRA_NEXTPAGE, nextPageId ); diff --git a/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequestBase.java b/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequestBase.java index d8e5d25..4cc6030 100644 --- a/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequestBase.java +++ b/src/org/linkeddatafragments/fragments/LinkedDataFragmentRequestBase.java @@ -1,12 +1,12 @@ package org.linkeddatafragments.fragments; /** - * Base class for implementations of {@link LinkedDataFragmentRequest}. + * Base class for implementations of {@link ILinkedDataFragmentRequest}. * * @author Olaf Hartig */ public abstract class LinkedDataFragmentRequestBase - implements LinkedDataFragmentRequest + implements ILinkedDataFragmentRequest { public final String fragmentURL; public final String datasetURL; diff --git a/src/org/linkeddatafragments/fragments/tpf/ITriplePatternFragmentRequest.java b/src/org/linkeddatafragments/fragments/tpf/ITriplePatternFragmentRequest.java index 61fd04a..07d026a 100644 --- a/src/org/linkeddatafragments/fragments/tpf/ITriplePatternFragmentRequest.java +++ b/src/org/linkeddatafragments/fragments/tpf/ITriplePatternFragmentRequest.java @@ -1,6 +1,6 @@ package org.linkeddatafragments.fragments.tpf; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; /** * Represents a request of a Triple Pattern Fragment (TPF). @@ -14,7 +14,7 @@ * @author Olaf Hartig */ public interface ITriplePatternFragmentRequest - extends LinkedDataFragmentRequest + extends ILinkedDataFragmentRequest { public final static String PARAMETERNAME_SUBJ = "subject"; public final static String PARAMETERNAME_PRED = "predicate"; diff --git a/src/org/linkeddatafragments/fragments/tpf/TPFRequestParser.java b/src/org/linkeddatafragments/fragments/tpf/TPFRequestParser.java index fb0f1e2..eaa06d4 100644 --- a/src/org/linkeddatafragments/fragments/tpf/TPFRequestParser.java +++ b/src/org/linkeddatafragments/fragments/tpf/TPFRequestParser.java @@ -5,7 +5,7 @@ import org.linkeddatafragments.config.ConfigReader; import org.linkeddatafragments.fragments.FragmentRequestParserBase; import org.linkeddatafragments.fragments.IFragmentRequestParser; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; import org.linkeddatafragments.util.TriplePatternElementParser; /** @@ -44,7 +44,7 @@ public Worker( final HttpServletRequest request, } @Override - public LinkedDataFragmentRequest createFragmentRequest() + public ILinkedDataFragmentRequest createFragmentRequest() throws IllegalArgumentException { return new TriplePatternFragmentRequestImpl( diff --git a/src/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java b/src/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java index ccd5b1f..1ef06e2 100644 --- a/src/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java +++ b/src/org/linkeddatafragments/servlet/LinkedDataFragmentServlet.java @@ -27,7 +27,7 @@ import org.linkeddatafragments.exceptions.DataSourceNotFoundException; import org.linkeddatafragments.fragments.FragmentRequestParserBase; import org.linkeddatafragments.fragments.ILinkedDataFragment; -import org.linkeddatafragments.fragments.LinkedDataFragmentRequest; +import org.linkeddatafragments.fragments.ILinkedDataFragmentRequest; import org.linkeddatafragments.util.MIMEParse; /** @@ -141,7 +141,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro try { final IDataSource dataSource = getDataSource( request ); - final LinkedDataFragmentRequest ldfRequest = + final ILinkedDataFragmentRequest ldfRequest = dataSource.getRequestParser() .parseIntoFragmentRequest( request, config ); diff --git a/src/test/java/org/linkeddatafragments/TestSuite.java b/src/test/java/org/linkeddatafragments/TestSuite.java index 0ce6d2e..3faaaea 100644 --- a/src/test/java/org/linkeddatafragments/TestSuite.java +++ b/src/test/java/org/linkeddatafragments/TestSuite.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package test.java.org.linkeddatafragments; import org.junit.runner.RunWith;