Strabon

changeset 945:2fbf6954f8dc

added an Endpoint interface moving all methods of SpatialEndpoint interface to it and used generics for the RDF format. Now SpatialEndpoint is an abstract class implementing the Endpoint interface instantiating the RDF format template with the stSPARQLQueryResultsFormat class. Replaced SpatialEndpointImpl by HTTPClient which undertakes the initialization of HttpClient which then can be used for making HTTP connections.
author Babis Nikolaou <charnik@di.uoa.gr>
date Fri Mar 29 18:10:21 2013 +0200 (2013-03-29)
parents e197d4742126
children cf2557c8fcd4
files endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/Endpoint.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/HTTPClient.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/Endpoint.java	Fri Mar 29 18:10:21 2013 +0200
     1.3 @@ -0,0 +1,72 @@
     1.4 +/**
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 + *
     1.9 + * Copyright (C) 2013, Pyravlos Team
    1.10 + *
    1.11 + * http://www.strabon.di.uoa.gr/
    1.12 + */
    1.13 +package eu.earthobservatory.org.StrabonEndpoint.client;
    1.14 +
    1.15 +import java.io.IOException;
    1.16 +import java.net.URL;
    1.17 +
    1.18 +import org.openrdf.query.resultio.TupleQueryResultFormat;
    1.19 +import org.openrdf.rio.RDFFormat;
    1.20 +
    1.21 +/**
    1.22 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    1.23 + *
    1.24 + */
    1.25 +public interface Endpoint<T extends TupleQueryResultFormat> {
    1.26 +	/**
    1.27 +	 * Executes a SPARQL query on the Endpoint and get the results
    1.28 +	 * in the format specified by <code>T</code>. Format <code>T</code>
    1.29 +	 * should be an instance of class (or a subclass) {@link TupleQueryResultFormat}.   
    1.30 +	 * 
    1.31 +	 * @param sparqlQuery
    1.32 +	 * @param format
    1.33 +	 * @return
    1.34 +	 * @throws IOException
    1.35 +	 */
    1.36 +	public EndpointResult query(String sparqlQuery, T format) throws IOException;
    1.37 +	
    1.38 +	/**
    1.39 +	 * Stores the RDF <code>data</code> which are in the RDF format
    1.40 +	 * <code>format</code> in the named graph specified by the URL
    1.41 +	 * <code>namedGraph</code>.
    1.42 +	 * 
    1.43 +	 * @param data 
    1.44 +	 * @param format
    1.45 +	 * @param namedGraph
    1.46 +	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    1.47 +	 */
    1.48 +	public boolean store(String data, RDFFormat format, URL namedGraph);
    1.49 +	
    1.50 +	/**
    1.51 +	 * Stores the RDF data located at <code>data</code> which are in the
    1.52 +	 * RDF format <code>format</code> in the named graph specified by the
    1.53 +	 * URL <code>namedGraph</code>.
    1.54 +	 * 
    1.55 +	 * @param data
    1.56 +	 * @param format
    1.57 +	 * @param namedGraph
    1.58 +	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    1.59 +	 */
    1.60 +	public boolean store(URL data, RDFFormat format, URL namedGraph);
    1.61 +	
    1.62 +	/**
    1.63 +	 * Executes the SPARQL Update query specified in <code>sparqlUpdate</code>.
    1.64 +	 * 
    1.65 +	 * @param sparqlUpdate
    1.66 +	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    1.67 +	 */
    1.68 +	public boolean update(String sparqlUpdate);
    1.69 +	
    1.70 +	public EndpointResult describe(String sparqlDescribe);
    1.71 +	
    1.72 +	public EndpointResult construct(String sparqlConstruct);
    1.73 +	
    1.74 +	public EndpointResult ask(String sparqlAsk);
    1.75 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/HTTPClient.java	Fri Mar 29 18:10:21 2013 +0200
     2.3 @@ -0,0 +1,112 @@
     2.4 +/**
     2.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     2.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     2.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     2.8 + *
     2.9 + * Copyright (C) 2012, Pyravlos Team
    2.10 + *
    2.11 + * http://www.strabon.di.uoa.gr/
    2.12 + */
    2.13 +package eu.earthobservatory.org.StrabonEndpoint.client;
    2.14 +
    2.15 +import org.apache.http.client.HttpClient;
    2.16 +import org.apache.http.conn.ClientConnectionManager;
    2.17 +import org.apache.http.impl.client.DefaultHttpClient;
    2.18 +import org.apache.http.impl.conn.PoolingClientConnectionManager;
    2.19 +
    2.20 +/**
    2.21 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    2.22 + *
    2.23 + */
    2.24 +public abstract class HTTPClient {
    2.25 +
    2.26 +	/**
    2.27 +	 * The host on which the endpoint is located.
    2.28 +	 */
    2.29 +	protected String host;
    2.30 +	
    2.31 +	/**
    2.32 +	 * The port of the host.
    2.33 +	 */
    2.34 +	protected int port;
    2.35 +	
    2.36 +	/**
    2.37 +	 * The name of the endpoint.
    2.38 +	 * 
    2.39 +	 * This is useful for {@link StrabonEndpoint} instances that are usually
    2.40 +	 * deployed in a tomcat container as web applications.
    2.41 +	 */
    2.42 +	protected String endpointName;
    2.43 +	
    2.44 +	/**
    2.45 +	 * The username to be used in case the endpoint requires authentication.
    2.46 +	 */
    2.47 +	protected String user;
    2.48 +	
    2.49 +	/**
    2.50 +	 * The password to be used in case the endpoint requires authentication.
    2.51 +	 */
    2.52 +	protected String password;
    2.53 +	
    2.54 +	/**
    2.55 +	 * The connection manager that manages sharing of connections to endpoints
    2.56 +	 * among several threads.
    2.57 +	 */
    2.58 +	private ClientConnectionManager connectionManager;
    2.59 +	
    2.60 +	/**
    2.61 +	 * The HttpClient to be used for connecting to an endpoint.
    2.62 +	 */
    2.63 +	protected HttpClient hc;
    2.64 +	
    2.65 +	public HTTPClient(String host, int port) {
    2.66 +		this(host, port, "/");
    2.67 +	}
    2.68 +	
    2.69 +	public HTTPClient(String host, int port, String endpointName) {
    2.70 +		this.host = host;
    2.71 +		this.port = port;
    2.72 +		
    2.73 +		this.endpointName = (endpointName == null ? "":endpointName);
    2.74 +		
    2.75 +		// create a connection manager for allowing the users of this class use threads
    2.76 +		connectionManager = new PoolingClientConnectionManager();
    2.77 +		
    2.78 +		// create an HttpClient instance that establishes connections based on the connection manager
    2.79 +		hc = new DefaultHttpClient(connectionManager);
    2.80 +	}
    2.81 +		
    2.82 +	public String getHost() {
    2.83 +		return host;
    2.84 +	}
    2.85 +	
    2.86 +	public int getPort() {
    2.87 +		return port;
    2.88 +	}
    2.89 +	
    2.90 +	public void setUser(String user) {
    2.91 +		this.user = user;
    2.92 +	}
    2.93 +	
    2.94 +	public void setPassword(String pass) {
    2.95 +		this.password = pass;
    2.96 +	}
    2.97 +	
    2.98 +	public String getUser() {
    2.99 +		return user;
   2.100 +	}
   2.101 +	
   2.102 +	public String getPassword() {
   2.103 +		return password;
   2.104 +	}
   2.105 +	
   2.106 +	/**
   2.107 +	 * Returns a URL (actually a {@link String}) for establishing connections
   2.108 +	 * to an endpoint based on the information given to the constructor. 
   2.109 +	 * 
   2.110 +	 * @return
   2.111 +	 */
   2.112 +	protected String getConnectionURL() {
   2.113 +		return "http://" + host + ":" + port + "/" + endpointName; 
   2.114 +	}
   2.115 +}
     3.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java	Thu Mar 28 21:07:05 2013 +0200
     3.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java	Fri Mar 29 18:10:21 2013 +0200
     3.3 @@ -3,62 +3,63 @@
     3.4   * License, v. 2.0. If a copy of the MPL was not distributed with this
     3.5   * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     3.6   *
     3.7 - * Copyright (C) 2012, Pyravlos Team
     3.8 + * Copyright (C) 2012, 2013, Pyravlos Team
     3.9   *
    3.10   * http://www.strabon.di.uoa.gr/
    3.11   */
    3.12  package eu.earthobservatory.org.StrabonEndpoint.client;
    3.13  
    3.14 -import java.io.IOException;
    3.15 -import java.net.URL;
    3.16 -
    3.17  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    3.18 -import org.openrdf.rio.RDFFormat;
    3.19  
    3.20  /**
    3.21   * Every SPARQL endpoint that supports storing and querying of
    3.22 - * spatial RDF data should implement the {@link SpatialEndpoint}
    3.23 - * interface. 
    3.24 + * spatial RDF data should extend the {@link SpatialEndpoint}
    3.25 + * abstract class. 
    3.26   * 
    3.27   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    3.28   */
    3.29 -public interface SpatialEndpoint {
    3.30 -
    3.31 -	public EndpointResult query(String sparqlQuery, stSPARQLQueryResultFormat format) throws IOException;
    3.32 +public abstract class SpatialEndpoint extends HTTPClient implements Endpoint<stSPARQLQueryResultFormat> {
    3.33 +	
    3.34 +	
    3.35 +	public SpatialEndpoint(String host, int port) {
    3.36 +		super(host, port);
    3.37 +	}
    3.38 +	
    3.39 +	public SpatialEndpoint(String host, int port, String endpointName) {
    3.40 +		super(host, port, endpointName);
    3.41 +	}
    3.42 +		
    3.43 +	public String getHost() {
    3.44 +		return host;
    3.45 +	}
    3.46 +	
    3.47 +	public int getPort() {
    3.48 +		return port;
    3.49 +	}
    3.50 +	
    3.51 +	public void setUser(String user) {
    3.52 +		this.user = user;
    3.53 +	}
    3.54 +	
    3.55 +	public void setPassword(String pass) {
    3.56 +		this.password = pass;
    3.57 +	}
    3.58 +	
    3.59 +	public String getUser() {
    3.60 +		return user;
    3.61 +	}
    3.62 +	
    3.63 +	public String getPassword() {
    3.64 +		return password;
    3.65 +	}
    3.66  	
    3.67  	/**
    3.68 -	 * Stores the RDF <code>data</code> which are in the RDF format
    3.69 -	 * <code>format</code> in the named graph specified by the URL
    3.70 -	 * <code>namedGraph</code>.
    3.71 +	 * Returns a URL (actually a {@link String}) for establishing connections
    3.72 +	 * to an endpoint based on the information given to the constructor. 
    3.73  	 * 
    3.74 -	 * @param data 
    3.75 -	 * @param format
    3.76 -	 * @param namedGraph
    3.77 -	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    3.78 +	 * @return
    3.79  	 */
    3.80 -	public boolean store(String data, RDFFormat format, URL namedGraph);
    3.81 -	
    3.82 -	/**
    3.83 -	 * Stores the RDF data located at <code>data</code> which are in the
    3.84 -	 * RDF format <code>format</code> in the named graph specified by the
    3.85 -	 * URL <code>namedGraph</code>.
    3.86 -	 * 
    3.87 -	 * @param data
    3.88 -	 * @param format
    3.89 -	 * @param namedGraph
    3.90 -	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    3.91 -	 */
    3.92 -	public boolean store(URL data, RDFFormat format, URL namedGraph);
    3.93 -	
    3.94 -	/**
    3.95 -	 * Executes the SPARQL Update query specified in <code>sparqlUpdate</code>.
    3.96 -	 * 
    3.97 -	 * @param sparqlUpdate
    3.98 -	 * @return <code>true</code> if store was successful, <code>false</code> otherwise
    3.99 -	 */
   3.100 -	public boolean update(String sparqlUpdate);
   3.101 -	
   3.102 -	public EndpointResult describe(String sparqlDescribe);
   3.103 -	
   3.104 -	public EndpointResult construct(String sparqlConstruct);
   3.105 +	protected String getConnectionURL() {
   3.106 +		return "http://" + host + ":" + port + "/" + endpointName; 
   3.107 +	}
   3.108  }
     4.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java	Thu Mar 28 21:07:05 2013 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,112 +0,0 @@
     4.4 -/**
     4.5 - * This Source Code Form is subject to the terms of the Mozilla Public
     4.6 - * License, v. 2.0. If a copy of the MPL was not distributed with this
     4.7 - * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4.8 - *
     4.9 - * Copyright (C) 2012, Pyravlos Team
    4.10 - *
    4.11 - * http://www.strabon.di.uoa.gr/
    4.12 - */
    4.13 -package eu.earthobservatory.org.StrabonEndpoint.client;
    4.14 -
    4.15 -import org.apache.http.client.HttpClient;
    4.16 -import org.apache.http.conn.ClientConnectionManager;
    4.17 -import org.apache.http.impl.client.DefaultHttpClient;
    4.18 -import org.apache.http.impl.conn.PoolingClientConnectionManager;
    4.19 -
    4.20 -/**
    4.21 - * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    4.22 - *
    4.23 - */
    4.24 -public abstract class SpatialEndpointImpl implements SpatialEndpoint {
    4.25 -
    4.26 -	/**
    4.27 -	 * The host on which the endpoint is located.
    4.28 -	 */
    4.29 -	protected String host;
    4.30 -	
    4.31 -	/**
    4.32 -	 * The port of the host.
    4.33 -	 */
    4.34 -	protected int port;
    4.35 -	
    4.36 -	/**
    4.37 -	 * The name of the endpoint.
    4.38 -	 * 
    4.39 -	 * This is useful for {@link StrabonEndpoint} instances that are usually
    4.40 -	 * deployed in a tomcat container as web applications.
    4.41 -	 */
    4.42 -	protected String endpointName;
    4.43 -	
    4.44 -	/**
    4.45 -	 * The username to be used in case the endpoint requires authentication.
    4.46 -	 */
    4.47 -	protected String user;
    4.48 -	
    4.49 -	/**
    4.50 -	 * The password to be used in case the endpoint requires authentication.
    4.51 -	 */
    4.52 -	protected String password;
    4.53 -	
    4.54 -	/**
    4.55 -	 * The connection manager that manages sharing of connections to endpoints
    4.56 -	 * among several threads.
    4.57 -	 */
    4.58 -	private ClientConnectionManager connectionManager;
    4.59 -	
    4.60 -	/**
    4.61 -	 * The HttpClient to be used for connecting to an endpoint.
    4.62 -	 */
    4.63 -	protected HttpClient hc;
    4.64 -	
    4.65 -	public SpatialEndpointImpl(String host, int port) {
    4.66 -		this(host, port, "/");
    4.67 -	}
    4.68 -	
    4.69 -	public SpatialEndpointImpl(String host, int port, String endpointName) {
    4.70 -		this.host = host;
    4.71 -		this.port = port;
    4.72 -		
    4.73 -		this.endpointName = (endpointName == null ? "":endpointName);
    4.74 -		
    4.75 -		// create a connection manager for allowing the users of this class use threads
    4.76 -		connectionManager = new PoolingClientConnectionManager();
    4.77 -		
    4.78 -		// create an HttpClient instance that establishes connections based on the connection manager
    4.79 -		hc = new DefaultHttpClient(connectionManager);
    4.80 -	}
    4.81 -		
    4.82 -	public String getHost() {
    4.83 -		return host;
    4.84 -	}
    4.85 -	
    4.86 -	public int getPort() {
    4.87 -		return port;
    4.88 -	}
    4.89 -	
    4.90 -	public void setUser(String user) {
    4.91 -		this.user = user;
    4.92 -	}
    4.93 -	
    4.94 -	public void setPassword(String pass) {
    4.95 -		this.password = pass;
    4.96 -	}
    4.97 -	
    4.98 -	public String getUser() {
    4.99 -		return user;
   4.100 -	}
   4.101 -	
   4.102 -	public String getPassword() {
   4.103 -		return password;
   4.104 -	}
   4.105 -	
   4.106 -	/**
   4.107 -	 * Returns a URL (actually a {@link String}) for establishing connections
   4.108 -	 * to an endpoint based on the information given to the constructor. 
   4.109 -	 * 
   4.110 -	 * @return
   4.111 -	 */
   4.112 -	protected String getConnectionURL() {
   4.113 -		return "http://" + host + ":" + port + "/" + endpointName; 
   4.114 -	}
   4.115 -}
     5.1 --- a/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Thu Mar 28 21:07:05 2013 +0200
     5.2 +++ b/endpoint-client/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java	Fri Mar 29 18:10:21 2013 +0200
     5.3 @@ -33,7 +33,7 @@
     5.4   * 
     5.5   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
     5.6   */
     5.7 -public class StrabonEndpoint extends SpatialEndpointImpl {
     5.8 +public class StrabonEndpoint extends SpatialEndpoint {
     5.9  
    5.10  	public StrabonEndpoint(String host, int port) {
    5.11  		super(host, port);
    5.12 @@ -147,6 +147,11 @@
    5.13  		throw new UnsupportedOperationException();
    5.14  	}
    5.15  	
    5.16 +	@Override
    5.17 +	public EndpointResult ask(String sparqlAsk) {
    5.18 +		throw new UnsupportedOperationException();
    5.19 +	}
    5.20 +	
    5.21  	public static void main(String args[]) {
    5.22  		if (args.length < 4) {
    5.23  			System.err.println("Usage: eu.earthobservatory.org.StrabonEndpoint.client.StrabonEndpoint <HOST> <PORT> <APPNAME> [<FORMAT>]");