Strabon
changeset 669:130f6aca1765
added interface (SpatialEndpoint) that endpoints with spatial capabilities should implement. Added a prototype abstract class implementing this interface (SpatialEndpointImpl). Added a StrabonEndpoint class extending the abstract class (NOT complete yet)
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Tue Oct 30 21:18:40 2012 +0200 (2012-10-30) |
parents | b3c5b5e0a552 |
children | f443dfe30f78 |
files | endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java endpoint/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/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpoint.java Tue Oct 30 21:18:40 2012 +0200 1.3 @@ -0,0 +1,36 @@ 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) 2012, 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.net.URL; 1.16 + 1.17 +import org.openrdf.rio.RDFFormat; 1.18 + 1.19 +/** 1.20 + * Every SPARQL endpoint that supports storing and querying of 1.21 + * spatial RDF data should implement the {@link SpatialEndpoint} 1.22 + * interface. 1.23 + * 1.24 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 1.25 + */ 1.26 +public interface SpatialEndpoint { 1.27 + 1.28 + public String query(String sparqlQuery, String format); 1.29 + 1.30 + public boolean store(String data, RDFFormat format); 1.31 + 1.32 + public boolean store(URL data, RDFFormat format); 1.33 + 1.34 + public boolean update(String sparqlUpdate); 1.35 + 1.36 + public boolean describe(String sparqlDescribe); 1.37 + 1.38 + public boolean construct(String sparqlConstruct); 1.39 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/SpatialEndpointImpl.java Tue Oct 30 21:18:40 2012 +0200 2.3 @@ -0,0 +1,111 @@ 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.commons.httpclient.HttpClient; 2.16 +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; 2.17 + 2.18 +/** 2.19 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 2.20 + * 2.21 + */ 2.22 +public abstract class SpatialEndpointImpl implements SpatialEndpoint { 2.23 + 2.24 + /** 2.25 + * The host on which the endpoint is located. 2.26 + */ 2.27 + protected String host; 2.28 + 2.29 + /** 2.30 + * The port of the host. 2.31 + */ 2.32 + protected int port; 2.33 + 2.34 + /** 2.35 + * The name of the endpoint. 2.36 + * 2.37 + * This is useful for {@link StrabonEndpoint} instances that are usually 2.38 + * deployed in a tomcat container as web applications. 2.39 + */ 2.40 + protected String endpointName; 2.41 + 2.42 + /** 2.43 + * The username to be used in case the endpoint requires authentication. 2.44 + */ 2.45 + protected String user; 2.46 + 2.47 + /** 2.48 + * The password to be used in case the endpoint requires authentication. 2.49 + */ 2.50 + protected String password; 2.51 + 2.52 + /** 2.53 + * The connection manager that manages sharing of connections to endpoints 2.54 + * among several threads. 2.55 + */ 2.56 + private MultiThreadedHttpConnectionManager connectionManager; 2.57 + 2.58 + /** 2.59 + * The HttpClient to be used for connecting to an endpoint. 2.60 + */ 2.61 + protected HttpClient hc; 2.62 + 2.63 + public SpatialEndpointImpl(String host, int port) { 2.64 + this(host, port, "/"); 2.65 + } 2.66 + 2.67 + public SpatialEndpointImpl(String host, int port, String endpointName) { 2.68 + this.host = host; 2.69 + this.port = port; 2.70 + 2.71 + // make the name of the endpoint end with a slash 2.72 + this.endpointName = (endpointName != null && !endpointName.endsWith("/")) ? endpointName+"/":""; 2.73 + 2.74 + // create a connection manager for allowing the users of this class use threads 2.75 + connectionManager = new MultiThreadedHttpConnectionManager(); 2.76 + 2.77 + // create an HttpClient instance that establishes connections based on the connection manager 2.78 + hc = new HttpClient(connectionManager); 2.79 + } 2.80 + 2.81 + public String getHost() { 2.82 + return host; 2.83 + } 2.84 + 2.85 + public int getPort() { 2.86 + return port; 2.87 + } 2.88 + 2.89 + public void setUser(String user) { 2.90 + this.user = user; 2.91 + } 2.92 + 2.93 + public void setPassword(String pass) { 2.94 + this.password = pass; 2.95 + } 2.96 + 2.97 + public String getUser() { 2.98 + return user; 2.99 + } 2.100 + 2.101 + public String getPassword() { 2.102 + return password; 2.103 + } 2.104 + 2.105 + /** 2.106 + * Returns a URL (actually a {@link String}) for establishing connections 2.107 + * to an endpoint based on the information given to the constructor. 2.108 + * 2.109 + * @return 2.110 + */ 2.111 + protected String getConnectionURL() { 2.112 + return "http://" + host + ":" + port + "/" + endpointName; 2.113 + } 2.114 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/endpoint/src/main/java/eu/earthobservatory/org/StrabonEndpoint/client/StrabonEndpoint.java Tue Oct 30 21:18:40 2012 +0200 3.3 @@ -0,0 +1,69 @@ 3.4 +/** 3.5 + * This Source Code Form is subject to the terms of the Mozilla Public 3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 3.8 + * 3.9 + * Copyright (C) 2012, Pyravlos Team 3.10 + * 3.11 + * http://www.strabon.di.uoa.gr/ 3.12 + */ 3.13 +package eu.earthobservatory.org.StrabonEndpoint.client; 3.14 + 3.15 +import java.net.URL; 3.16 + 3.17 +import org.apache.commons.httpclient.HttpMethod; 3.18 +import org.apache.commons.httpclient.methods.PostMethod; 3.19 +import org.openrdf.rio.RDFFormat; 3.20 + 3.21 +/** 3.22 + * This class is the implementation of a java client for accessing 3.23 + * StrabonEndpoint instances. 3.24 + * 3.25 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 3.26 + */ 3.27 +public class StrabonEndpoint extends SpatialEndpointImpl { 3.28 + 3.29 + public StrabonEndpoint(String host, int port) { 3.30 + super(host, port); 3.31 + } 3.32 + 3.33 + @Override 3.34 + public String query(String sparqlQuery, String format) { 3.35 + // create a post method to execute 3.36 + HttpMethod post = new PostMethod(getConnectionURL()); 3.37 + 3.38 + // set the query parameter 3.39 + post.getParams().setParameter("query", sparqlQuery); 3.40 + 3.41 + // set the accept format 3.42 + post.setRequestHeader("Accept", "???"); 3.43 + 3.44 + return null; 3.45 + } 3.46 + 3.47 + @Override 3.48 + public boolean store(String data, RDFFormat format) { 3.49 + return false; 3.50 + } 3.51 + 3.52 + @Override 3.53 + public boolean store(URL data, RDFFormat format) { 3.54 + return false; 3.55 + } 3.56 + 3.57 + @Override 3.58 + public boolean update(String sparqlUpdate) { 3.59 + return false; 3.60 + } 3.61 + 3.62 + @Override 3.63 + public boolean describe(String sparqlDescribe) { 3.64 + return false; 3.65 + } 3.66 + 3.67 + @Override 3.68 + public boolean construct(String sparqlConstruct) { 3.69 + return false; 3.70 + } 3.71 + 3.72 +}