Skip to content

Commit

Permalink
Cleanup and finished interface renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Miel Vander Sande committed Jan 4, 2016
1 parent 541c48f commit 9f4fe2a
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -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}.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +30,7 @@
{
@Override
protected final Worker<CTT,NVT,AVT> getWorker(
final LinkedDataFragmentRequest request )
final ILinkedDataFragmentRequest request )
throws IllegalArgumentException
{
if ( request instanceof ITriplePatternFragmentRequest<?,?,?> ) {
Expand Down Expand Up @@ -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 );
Expand Down
6 changes: 3 additions & 3 deletions src/org/linkeddatafragments/datasource/DataSourceFactory.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/org/linkeddatafragments/datasource/IDataSourceType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.linkeddatafragments.datasource;

import org.linkeddatafragments.exceptions.DataSourceException;
import org.linkeddatafragments.exceptions.DataSourceCreationException;

import com.google.gson.JsonObject;

Expand Down Expand Up @@ -28,5 +28,5 @@ public interface IDataSourceType
IDataSource createDataSource( final String title,
final String description,
final JsonObject settings )
throws DataSourceException;
throws DataSourceCreationException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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 <a href="http://olafhartig.de">Olaf Hartig</a>
*/
public interface IFragmentRequestProcessor extends Closeable
{
ILinkedDataFragment createRequestedFragment(
final LinkedDataFragmentRequest request )
final ILinkedDataFragmentRequest request )
throws IllegalArgumentException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,15 +20,15 @@ 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 );

try {
return new HdtDataSource(title, description, file.getAbsolutePath());
} catch (IOException ex) {
throw new DataSourceException(ex);
throw new DataSourceCreationException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,15 +20,15 @@ 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 );

try {
return new JenaTDBDataSource(title, description, dir);
} catch (Exception ex) {
throw new DataSourceException(ex);
throw new DataSourceCreationException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 12 additions & 6 deletions src/org/linkeddatafragments/exceptions/DataSourceException.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -57,7 +57,7 @@ public Worker( final HttpServletRequest request,
}
}

abstract public LinkedDataFragmentRequest createFragmentRequest()
abstract public ILinkedDataFragmentRequest createFragmentRequest()
throws IllegalArgumentException;

public String getFragmentURL() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
import org.linkeddatafragments.config.ConfigReader;

/**
* Parses HTTP requests into specific {@link LinkedDataFragmentRequest}s.
* Parses HTTP requests into specific {@link ILinkedDataFragmentRequest}s.
*
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
public interface LinkedDataFragmentRequest
public interface ILinkedDataFragmentRequest
{
public final static long TRIPLESPERPAGE = 100L;
public final static String PARAMETERNAME_PAGE = "page";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean isLastPage() {

@Override
public long getMaxPageSize() {
return LinkedDataFragmentRequest.TRIPLESPERPAGE;
return ILinkedDataFragmentRequest.TRIPLESPERPAGE;
}

/**
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.linkeddatafragments.fragments;

/**
* Base class for implementations of {@link LinkedDataFragmentRequest}.
* Base class for implementations of {@link ILinkedDataFragmentRequest}.
*
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
public abstract class LinkedDataFragmentRequestBase
implements LinkedDataFragmentRequest
implements ILinkedDataFragmentRequest
{
public final String fragmentURL;
public final String datasetURL;
Expand Down
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -14,7 +14,7 @@
* @author <a href="http://olafhartig.de">Olaf Hartig</a>
*/
public interface ITriplePatternFragmentRequest<ConstantTermType,NamedVarType,AnonVarType>
extends LinkedDataFragmentRequest
extends ILinkedDataFragmentRequest
{
public final static String PARAMETERNAME_SUBJ = "subject";
public final static String PARAMETERNAME_PRED = "predicate";
Expand Down
Loading

0 comments on commit 9f4fe2a

Please sign in to comment.