You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2013/02/21 12:23:27 UTC
[16/19] MARMOTTA-104: renamed packages in ldpath (resolved)
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-jena/src/main/java/org/apache/marmotta/ldpath/backend/jena/GenericJenaBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-jena/src/main/java/org/apache/marmotta/ldpath/backend/jena/GenericJenaBackend.java b/libraries/ldpath/ldpath-backend-jena/src/main/java/org/apache/marmotta/ldpath/backend/jena/GenericJenaBackend.java
new file mode 100644
index 0000000..7d3e09e
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-jena/src/main/java/org/apache/marmotta/ldpath/backend/jena/GenericJenaBackend.java
@@ -0,0 +1,469 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.jena;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterators;
+import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.rdf.model.Literal;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Locale;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.apache.marmotta.ldpath.api.backend.RDFBackend;
+import org.apache.marmotta.ldpath.util.FormatUtils;
+
+/**
+ * Add file description here!
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class GenericJenaBackend implements RDFBackend<RDFNode> {
+
+
+ private Model model;
+
+ public GenericJenaBackend(Model model) {
+ this.model = model;
+ }
+
+
+ /**
+ * Return true if the underlying backend supports the parallel execution of queries.
+ *
+ * @return
+ */
+ @Override
+ public boolean supportsThreading() {
+ return false;
+ }
+
+
+ /**
+ * In case the backend supports threading, this method should return the ExecutorService representing the
+ * thread pool. LDPath lets the backend manage the thread pool to avoid excessive threading.
+ *
+ * @return
+ */
+ @Override
+ public ThreadPoolExecutor getThreadPool() {
+ return null;
+ }
+
+ /**
+ * Test whether the node passed as argument is a literal
+ *
+ * @param n the node to check
+ * @return true if the node is a literal
+ */
+ @Override
+ public boolean isLiteral(RDFNode n) {
+ return n.isLiteral();
+ }
+
+ /**
+ * Test whether the node passed as argument is a URI
+ *
+ * @param n the node to check
+ * @return true if the node is a URI
+ */
+ @Override
+ public boolean isURI(RDFNode n) {
+ return n.isURIResource();
+ }
+
+ /**
+ * Test whether the node passed as argument is a blank node
+ *
+ * @param n the node to check
+ * @return true if the node is a blank node
+ */
+ @Override
+ public boolean isBlank(RDFNode n) {
+ return n.isAnon();
+ }
+
+ /**
+ * Return the language of the literal node passed as argument.
+ *
+ * @param n the literal node for which to return the language
+ * @return a Locale representing the language of the literal, or null if the literal node has no language
+ * @throws IllegalArgumentException in case the node is no literal
+ */
+ @Override
+ public Locale getLiteralLanguage(RDFNode n) {
+ if(n.isLiteral()) {
+ if (((Literal)n).getLanguage() != null) {
+ return new Locale(((Literal)n).getLanguage());
+ } else {
+ return null;
+ }
+ } else {
+ throw new IllegalArgumentException("the node "+n+" is not a literal, cannot return language");
+ }
+ }
+
+ /**
+ * Return the URI of the type of the literal node passed as argument.
+ *
+ * @param n the literal node for which to return the typer
+ * @return a URI representing the type of the literal content, or null if the literal is untyped
+ * @throws IllegalArgumentException in case the node is no literal
+ */
+ @Override
+ public URI getLiteralType(RDFNode n) {
+ if(n.isLiteral()) {
+ if (((Literal)n).getLanguage() != null) {
+ try {
+ return new URI(((Literal)n).getDatatypeURI());
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException("the type of node "+n+" was not a valid URI");
+ }
+ } else {
+ return null;
+ }
+ } else {
+ throw new IllegalArgumentException("the node "+n+" is not a literal, cannot return literal type");
+ }
+ }
+
+ /**
+ * Create a literal node with the content passed as argument
+ *
+ * @param content string content to represent inside the literal
+ * @return a literal node in using the model used by this backend
+ */
+ @Override
+ public RDFNode createLiteral(String content) {
+ return model.createLiteral(content);
+ }
+
+ /**
+ * Create a literal node with the content passed as argument
+ *
+ * @param content string content to represent inside the literal
+ * @return a literal node in using the model used by this backend
+ */
+ @Override
+ public RDFNode createLiteral(String content, Locale language, URI type) {
+ if(language != null && type == null) {
+ return model.createLiteral(content,language.getLanguage());
+ } else if(language == null && type != null) {
+ return model.createTypedLiteral(content, TypeMapper.getInstance().getSafeTypeByName(type.toString()));
+ } else {
+ return model.createLiteral(content);
+ }
+ }
+
+ /**
+ * Create a URI mode with the URI passed as argument
+ *
+ * @param uri URI of the resource to create
+ * @return a URI node using the model used by this backend
+ */
+ @Override
+ public RDFNode createURI(String uri) {
+ return model.createProperty(uri);
+ }
+
+ /**
+ * Return the lexial representation of a node. For a literal, this will be the content, for a URI node it will be the
+ * URI itself, and for a blank node it will be the identifier of the node.
+ *
+ * @param rdfNode
+ * @return
+ */
+ @Override
+ public String stringValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getString();
+ } else if(isURI(rdfNode)) {
+ return ((Resource)rdfNode).getURI();
+ } else if(isBlank(rdfNode)) {
+ return ((Resource)rdfNode).getId().getLabelString();
+ } else {
+ return rdfNode.toString();
+ }
+ }
+
+ /**
+ * Return the double value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as double, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal
+ *
+ * @param rdfNode the literal node for which to return the double value
+ * @return double value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as double value
+ * @throws ArithmeticException in case the literal cannot be represented as double value
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Double doubleValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getDouble();
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the long value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as long, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal
+ *
+ * @param rdfNode the literal node for which to return the long value
+ * @return long value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as long value
+ * @throws ArithmeticException in case the literal cannot be represented as long value
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Long longValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getLong();
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the boolean value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation.
+ * TODO: Define:<ul>
+ * <li> Do we also support '0' '1', 'yes', 'no'; whats about case insensitive
+ * such as TRUE, False
+ * <li> should we throw an RuntimeException of not an boolean value or return
+ * false as {@link Boolean#parseBoolean(String)}
+ * </ul>
+ *
+ * @param rdfNode the literal node for which to return the boolean value
+ * @return long value of the literal node
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Boolean booleanValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getBoolean();
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * TODO
+ *
+ * @param rdfNode the literal node for which to return the dateTime value
+ * @return long value of the literal node
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Date dateTimeValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return FormatUtils.parseDate(((Literal)rdfNode).getString());
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * TODO
+ *
+ * @param rdfNode the literal node for which to return the date value
+ * @return long value of the literal node
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Date dateValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return FormatUtils.parseDate(((Literal)rdfNode).getString());
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * TODO
+ *
+ * @param rdfNode the literal node for which to return the time value
+ * @return long value of the literal node
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Date timeValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return FormatUtils.parseDate(((Literal)rdfNode).getString());
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the float value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as float, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal
+ *
+ * @param rdfNode the literal node for which to return the float value
+ * @return long value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as float value
+ * @throws ArithmeticException in case the literal cannot be represented as float value
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Float floatValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getFloat();
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the 32bit integer value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as integer, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal.
+ * <p/>
+ * Note that this is restricted to 32bit singed integer values as defined by
+ * xsd:int and {@link Integer}. For bigger nuber one might want to use
+ * xsd:integer represented by {@link java.math.BigInteger}.
+ *
+ * @param rdfNode the literal node for which to return the Integer (xsd:int) value
+ * @return long value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as 32 bit integer value
+ * @throws ArithmeticException in case the literal cannot be represented as 32 bit integer value
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public Integer intValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return ((Literal)rdfNode).getInt();
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the arbitrary length integer value of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as integer, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal.
+ *
+ * @param rdfNode the literal node for which to return the {@link java.math.BigInteger xsd:integer} value
+ * @return long value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as integer value
+ * @throws ArithmeticException in case the literal cannot be represented as long value
+ * @throws IllegalArgumentException in case the node passed as argument is integer a literal
+ */
+ @Override
+ public BigInteger integerValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return new BigInteger(((Literal)rdfNode).getString());
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * Return the decimal number of a literal node. Depending on the backend implementing this method,
+ * the value can be retrieved directly or must be parsed from the string representation. The method can throw
+ * a NumberFormatException or ArithmeticException indicating that the value cannot be represented as decimal, and an
+ * IllegalArgumentException, indicating that the passed node is not a literal.
+ *
+ * @param rdfNode the literal node for which to return the xsd:decimal value
+ * @return long value of the literal node
+ * @throws NumberFormatException in case the literal cannot be represented as decimal value
+ * @throws ArithmeticException in case the literal cannot be represented as decimal value
+ * @throws IllegalArgumentException in case the node passed as argument is not a literal
+ */
+ @Override
+ public BigDecimal decimalValue(RDFNode rdfNode) {
+ if(isLiteral(rdfNode)) {
+ return new BigDecimal(((Literal)rdfNode).getString());
+ } else {
+ throw new IllegalArgumentException("the node "+rdfNode+" is not a literal value");
+ }
+ }
+
+ /**
+ * List the objects of triples in the triple store underlying this backend that have the subject and
+ * property given as argument.
+ *
+ * @param subject the subject of the triples to look for
+ * @param property the property of the triples to look for, <code>null</code> is interpreted as wildcard
+ * @return all objects of triples with matching subject and property
+ */
+ @Override
+ public Collection<RDFNode> listObjects(RDFNode subject, RDFNode property) {
+ try {
+ return ImmutableSet.copyOf(
+ Iterators.transform(
+ model.listStatements((Resource)subject,(Property)property,(RDFNode)null),
+ new Function<Statement, RDFNode>() {
+ @Override
+ public RDFNode apply(Statement input) {
+ return input.getObject();
+ }
+ })
+ );
+
+ } catch(ClassCastException ex) {
+ throw new IllegalArgumentException("subject or property where no valid resources in the Jena model",ex);
+ }
+
+ }
+
+ /**
+ * List the subjects of triples in the triple store underlying this backend that have the object and
+ * property given as argument.
+ *
+ * @param object the object of the triples to look for
+ * @param property the property of the triples to look for, <code>null</code> is interpreted as wildcard
+ * @return all subjects of triples with matching object and property
+ * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
+ */
+ @Override
+ public Collection<RDFNode> listSubjects(RDFNode property, RDFNode object) {
+ try {
+ return ImmutableSet.copyOf(
+ Iterators.transform(
+ model.listStatements((Resource)null,(Property)property,object),
+ new Function<Statement, RDFNode>() {
+ @Override
+ public RDFNode apply(Statement input) {
+ return input.getSubject();
+ }
+ })
+ );
+ } catch(ClassCastException ex) {
+ throw new IllegalArgumentException("property was no valid resource in the Jena model",ex);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/AbstractLDBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/AbstractLDBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/AbstractLDBackend.java
deleted file mode 100644
index 372eb98..0000000
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/AbstractLDBackend.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.linkeddata;
-
-import at.newmedialab.ldclient.api.LDCacheProvider;
-import at.newmedialab.ldclient.model.Endpoint;
-import at.newmedialab.ldclient.service.LDCache;
-import at.newmedialab.ldpath.backend.sesame.SesameRepositoryBackend;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.openrdf.model.URI;
-import org.openrdf.model.Value;
-import org.openrdf.repository.Repository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-/**
- * Abstract superclass for Linked Data backends. Implements functionality common to all implementations.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public abstract class AbstractLDBackend extends SesameRepositoryBackend implements LDCacheProvider {
-
- private Logger log = LoggerFactory.getLogger(AbstractLDBackend.class);
-
- private LDCache ldCache;
-
- /**
- * Initialise a new sesame backend. Repository needs to be set using setRepository.
- */
- protected AbstractLDBackend() {
- ldCache = new LDCache(this);
-
- try {
- Configuration config = new PropertiesConfiguration("endpoints.properties");
-
- HashSet<String> endpointNames = new HashSet<String>();
- for(Iterator<String> it = config.getKeys(); it.hasNext(); ) {
- String key = it.next();
- String[] components = key.split("\\.");
- if(components.length > 1) {
- endpointNames.add(components[0]);
- }
- }
- for(String endpointName : endpointNames) {
- String prefix = config.getString(endpointName+".prefix","");
- String kind = config.getString(endpointName+".kind","");
- String endpointUrl = config.getString(endpointName+".endpoint","");
- String mimetype = config.getString(endpointName+".mimetype","");
- long expiry = config.getLong(endpointName+".expiry",(long)86400);
-
- Endpoint.EndpointType type;
- try {
- type = Endpoint.EndpointType.valueOf(kind.toUpperCase());
- } catch (Exception e) {
- type = Endpoint.EndpointType.LINKEDDATA;
- }
-
- if (prefix != null && prefix.startsWith(Endpoint.REGEX_INDICATOR)) {
- // Check for valid Regex
- try {
- Pattern.compile(prefix.substring(Endpoint.REGEX_INDICATOR.length()));
- } catch (PatternSyntaxException pse) {
- log.error("invalid regexp pattern in endpoint '{}' prefix definition: {}",endpointName,prefix);
- }
- }
- if (endpointUrl != null) {
- endpointUrl = endpointUrl.replace('<', '{').replace('>', '}');
- } else {
- endpointUrl = "";
- }
- Endpoint endpoint = new Endpoint(endpointName, type, prefix, endpointUrl, mimetype, expiry);
- log.info("Registering LD Cache Endpoint \"{}\"",endpointName);
- registerEndpoint(endpoint);
- }
-
- } catch (ConfigurationException e) {
- log.warn("could not load configuration file endpoints.properties from current directory, home directory, or classpath");
- }
-
-
- }
-
- /**
- * Return the sesame repository used for storing the triples that are retrieved from the Linked Data Cloud.
- * Triples will always be added to the context http://www.newmedialab.at/ldclient/cache to be able to distinguish
- * them from other triples.
- *
- * @return an initialised Sesame repository that can be used for caching triples
- */
- @Override
- public Repository getTripleRepository() {
- return getRepository();
- }
-
-
- /**
- * List the objects of triples in the triple store underlying this backend that have the subject and
- * property given as argument.
- *
- * @param subject the subject of the triples to look for
- * @param property the property of the triples to look for
- * @return all objects of triples with matching subject and property
- */
- @Override
- public Collection<Value> listObjects(Value subject, Value property) {
- if(isURI(subject)) {
- ldCache.refreshResource((URI)subject);
- }
- return super.listObjects(subject, property);
- }
-
- /**
- * List the subjects of triples in the triple store underlying this backend that have the object and
- * property given as argument.
- *
- * @param object the object of the triples to look for
- * @param property the property of the triples to look for
- * @return all dubjects of triples with matching object and property
- * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
- */
- @Override
- public Collection<Value> listSubjects(Value property, Value object) {
- throw new IllegalArgumentException("reverse navigation not supported by Linked Data backend");
- }
-
-
- /**
- * Register a new Linked Data endpoint with this cache provider.
- *
- * @param endpoint
- */
- @Override
- public void registerEndpoint(Endpoint endpoint) {
- ldCache.getEndpointService().addEndpoint(endpoint);
- }
-
- /**
- * List all endpoints currently registered with the Linked Data cache provider.
- *
- * @return a collection of endpoints
- */
- @Override
- public Collection<Endpoint> listEndpoints() {
- return ldCache.getEndpointService().listEndpoints();
- }
-
- /**
- * Unregister the Linked Data endpoint given as argument.
- *
- * @param endpoint the endpoint to unregister
- */
- @Override
- public void unregisterEndpoint(Endpoint endpoint) {
- ldCache.getEndpointService().removeEndpoint(endpoint);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDMemoryBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDMemoryBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDMemoryBackend.java
deleted file mode 100644
index adf2a0a..0000000
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDMemoryBackend.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.linkeddata;
-
-import at.newmedialab.ldclient.model.CacheEntry;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.memory.MemoryStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A Linked Data backend implementation with no persistent storage. All retrieved data is kept in memory and discarded
- * when the virtual machine exits.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LDMemoryBackend extends AbstractLDBackend {
-
- private static final Logger log = LoggerFactory.getLogger(LDMemoryBackend.class);
-
- private Map<String,CacheEntry> cacheEntries;
-
- public LDMemoryBackend() {
- super();
-
- cacheEntries = new HashMap<String,CacheEntry>();
-
- try {
- Repository repository = new SailRepository(new MemoryStore());
- repository.initialize();
- setRepository(repository);
-
- } catch (RepositoryException e) {
- log.error("error initialising connection to Sesame in-memory repository",e);
- }
-
- }
-
-
-
- /**
- * Return a map that can be used to store caching metadata about resources. The LDCacheProvider should take care
- * of persisting the metadata if desired.
- *
- * @return a map for storing caching metadata
- */
- @Override
- public Map<String,CacheEntry> getMetadataRepository() {
- return cacheEntries;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDPersistentBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDPersistentBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDPersistentBackend.java
deleted file mode 100644
index fdafd1e..0000000
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDPersistentBackend.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.linkeddata;
-
-import at.newmedialab.ldclient.model.CacheEntry;
-import jdbm.RecordManager;
-import jdbm.RecordManagerFactory;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sail.SailRepository;
-import org.openrdf.sail.nativerdf.NativeStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * A Linked Data backend with persistent caching of the retrieved data. All data is read and stored in the directory
- * passed as constructor argument.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LDPersistentBackend extends AbstractLDBackend {
- private static final Logger log = LoggerFactory.getLogger(LDMemoryBackend.class);
-
- private Map<String,CacheEntry> cacheEntries;
-
-
- private RecordManager recordManager;
-
- /**
- * Create a persistent linked data backend storing the cache data in the directory passed as argument.
- * The directory will be created if it does not exist.
- * @param dataDirectory
- */
- public LDPersistentBackend(File dataDirectory) throws IOException {
- super();
-
- if(!dataDirectory.exists()) {
- dataDirectory.mkdirs();
- }
-
- File tripleStore = new File(dataDirectory.getAbsolutePath()+File.separator+"triples");
- if(!tripleStore.exists()) {
- tripleStore.mkdirs();
- }
-
-
- recordManager = RecordManagerFactory.createRecordManager(dataDirectory.getAbsolutePath()+File.separator+"resource_cache.cache");
-
- cacheEntries = recordManager.treeMap("resources");
-
- try {
- Repository repository = new SailRepository(new NativeStore(tripleStore));
- repository.initialize();
- setRepository(repository);
-
- } catch (RepositoryException e) {
- log.error("error initialising connection to Sesame in-memory repository",e);
- }
- }
-
-
- public void shutdown() {
- try {
- recordManager.close();
- getRepository().shutDown();
- } catch (IOException e) {
- log.error("error shutting down record manager for resource cache");
- } catch (RepositoryException e) {
- log.error("error shutting down repository for resource cache");
- }
- }
-
-
- /**
- /**
- * Return a map that can be used to store caching metadata about resources. The LDCacheProvider should take care
- * of persisting the metadata if desired.
- *
- * @return a map for storing caching metadata
- */
- @Override
- public Map<String,CacheEntry> getMetadataRepository() {
- return cacheEntries;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDQuery.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDQuery.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDQuery.java
deleted file mode 100644
index caee246..0000000
--- a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/at/newmedialab/ldpath/backend/linkeddata/LDQuery.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.linkeddata;
-
-import at.newmedialab.ldpath.LDPath;
-import at.newmedialab.ldpath.backend.sesame.SesameRepositoryBackend;
-import at.newmedialab.ldpath.exception.LDPathParseException;
-import ch.qos.logback.classic.Level;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-import org.apache.commons.cli.PosixParser;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Value;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * Command line application for querying input from files.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class LDQuery {
-
- private static final Logger log = LoggerFactory.getLogger(LDQuery.class);
-
- public static void main(String[] args) {
- Options options = buildOptions();
-
- CommandLineParser parser = new PosixParser();
- try {
- CommandLine cmd = parser.parse( options, args);
-
- Level logLevel = Level.WARN;
-
- if(cmd.hasOption("loglevel")) {
- String logLevelName = cmd.getOptionValue("loglevel");
- if("DEBUG".equals(logLevelName.toUpperCase())) {
- logLevel = Level.DEBUG;
- } else if("INFO".equals(logLevelName.toUpperCase())) {
- logLevel = Level.INFO;
- } else if("WARN".equals(logLevelName.toUpperCase())) {
- logLevel = Level.WARN;
- } else if("ERROR".equals(logLevelName.toUpperCase())) {
- logLevel = Level.ERROR;
- } else {
- log.error("unsupported log level: {}",logLevelName);
- }
- }
-
- if(logLevel != null) {
- for(String logname : new String [] {"at","org","net","com"}) {
-
- ch.qos.logback.classic.Logger logger =
- (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(logname);
- logger.setLevel(logLevel);
- }
- }
-
-
- String format = null;
- if(cmd.hasOption("format")) {
- format = cmd.getOptionValue("format");
- }
-
- SesameRepositoryBackend backend;
- if(cmd.hasOption("store")) {
- backend = new LDPersistentBackend(new File(cmd.getOptionValue("store")));
- } else {
- backend = new LDMemoryBackend();
- }
-
- Resource context = null;
- if(cmd.hasOption("context")) {
- context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context"));
- }
-
- if(backend != null && context != null) {
- LDPath<Value> ldpath = new LDPath<Value>(backend);
-
- if(cmd.hasOption("path")) {
- String path = cmd.getOptionValue("path");
-
- for(Value v : ldpath.pathQuery(context,path,null)) {
- System.out.println(v.stringValue());
- }
- } else if(cmd.hasOption("program")) {
- File file = new File(cmd.getOptionValue("program"));
-
- Map<String,Collection<?>> result = ldpath.programQuery(context,new FileReader(file));
-
- for(String field : result.keySet()) {
- StringBuilder line = new StringBuilder();
- line.append(field);
- line.append(" = ");
- line.append("{");
- for (Iterator<?> it = result.get(field).iterator(); it.hasNext();) {
- line.append(it.next().toString());
- if(it.hasNext()) {
- line.append(", ");
- }
- }
- line.append("}");
- System.out.println(line);
-
- }
- }
- }
-
- if(backend instanceof LDPersistentBackend) {
- ((LDPersistentBackend) backend).shutdown();
- }
-
-
- } catch (ParseException e) {
- System.err.println("invalid arguments");
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp( "LDQuery", options, true );
- } catch (LDPathParseException e) {
- System.err.println("path or program could not be parsed");
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- System.err.println("file or program could not be found");
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("LDQuery", options, true);
- } catch (IOException e) {
- System.err.println("could not access cache data directory");
- HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp("LDQuery", options, true);
- }
-
-
- }
-
- @SuppressWarnings("static-access")
- private static Options buildOptions() {
- Options result = new Options();
-
- OptionGroup query = new OptionGroup();
- Option path = OptionBuilder.withArgName("path").hasArg().withDescription("LD Path to evaluate on the file starting from the context").create("path");
- Option program = OptionBuilder.withArgName("file").hasArg().withDescription("LD Path program to evaluate on the file starting from the context").create("program");
- query.addOption(path);
- query.addOption(program);
- query.setRequired(true);
- result.addOptionGroup(query);
-
- Option context = OptionBuilder.withArgName("uri").hasArg().withDescription("URI of the context node to start from").create("context");
- context.setRequired(true);
- result.addOption(context);
-
- Option loglevel = OptionBuilder.withArgName("level").hasArg().withDescription("set the log level; default is 'warn'").create("loglevel");
- result.addOption(loglevel);
-
- Option store = OptionBuilder.withArgName("dir").hasArg().withDescription("cache the retrieved data in this directory").create("store");
- result.addOption(store);
-
-
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/AbstractLDBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/AbstractLDBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/AbstractLDBackend.java
new file mode 100644
index 0000000..a0369e0
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/AbstractLDBackend.java
@@ -0,0 +1,177 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.linkeddata;
+
+import at.newmedialab.ldclient.api.LDCacheProvider;
+import at.newmedialab.ldclient.model.Endpoint;
+import at.newmedialab.ldclient.service.LDCache;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.marmotta.ldpath.backend.sesame.SesameRepositoryBackend;
+import org.openrdf.model.URI;
+import org.openrdf.model.Value;
+import org.openrdf.repository.Repository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * Abstract superclass for Linked Data backends. Implements functionality common to all implementations.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public abstract class AbstractLDBackend extends SesameRepositoryBackend implements LDCacheProvider {
+
+ private Logger log = LoggerFactory.getLogger(AbstractLDBackend.class);
+
+ private LDCache ldCache;
+
+ /**
+ * Initialise a new sesame backend. Repository needs to be set using setRepository.
+ */
+ protected AbstractLDBackend() {
+ ldCache = new LDCache(this);
+
+ try {
+ Configuration config = new PropertiesConfiguration("endpoints.properties");
+
+ HashSet<String> endpointNames = new HashSet<String>();
+ for(Iterator<String> it = config.getKeys(); it.hasNext(); ) {
+ String key = it.next();
+ String[] components = key.split("\\.");
+ if(components.length > 1) {
+ endpointNames.add(components[0]);
+ }
+ }
+ for(String endpointName : endpointNames) {
+ String prefix = config.getString(endpointName+".prefix","");
+ String kind = config.getString(endpointName+".kind","");
+ String endpointUrl = config.getString(endpointName+".endpoint","");
+ String mimetype = config.getString(endpointName+".mimetype","");
+ long expiry = config.getLong(endpointName+".expiry",(long)86400);
+
+ Endpoint.EndpointType type;
+ try {
+ type = Endpoint.EndpointType.valueOf(kind.toUpperCase());
+ } catch (Exception e) {
+ type = Endpoint.EndpointType.LINKEDDATA;
+ }
+
+ if (prefix != null && prefix.startsWith(Endpoint.REGEX_INDICATOR)) {
+ // Check for valid Regex
+ try {
+ Pattern.compile(prefix.substring(Endpoint.REGEX_INDICATOR.length()));
+ } catch (PatternSyntaxException pse) {
+ log.error("invalid regexp pattern in endpoint '{}' prefix definition: {}",endpointName,prefix);
+ }
+ }
+ if (endpointUrl != null) {
+ endpointUrl = endpointUrl.replace('<', '{').replace('>', '}');
+ } else {
+ endpointUrl = "";
+ }
+ Endpoint endpoint = new Endpoint(endpointName, type, prefix, endpointUrl, mimetype, expiry);
+ log.info("Registering LD Cache Endpoint \"{}\"",endpointName);
+ registerEndpoint(endpoint);
+ }
+
+ } catch (ConfigurationException e) {
+ log.warn("could not load configuration file endpoints.properties from current directory, home directory, or classpath");
+ }
+
+
+ }
+
+ /**
+ * Return the sesame repository used for storing the triples that are retrieved from the Linked Data Cloud.
+ * Triples will always be added to the context http://www.newmedialab.at/ldclient/cache to be able to distinguish
+ * them from other triples.
+ *
+ * @return an initialised Sesame repository that can be used for caching triples
+ */
+ @Override
+ public Repository getTripleRepository() {
+ return getRepository();
+ }
+
+
+ /**
+ * List the objects of triples in the triple store underlying this backend that have the subject and
+ * property given as argument.
+ *
+ * @param subject the subject of the triples to look for
+ * @param property the property of the triples to look for
+ * @return all objects of triples with matching subject and property
+ */
+ @Override
+ public Collection<Value> listObjects(Value subject, Value property) {
+ if(isURI(subject)) {
+ ldCache.refreshResource((URI)subject);
+ }
+ return super.listObjects(subject, property);
+ }
+
+ /**
+ * List the subjects of triples in the triple store underlying this backend that have the object and
+ * property given as argument.
+ *
+ * @param object the object of the triples to look for
+ * @param property the property of the triples to look for
+ * @return all dubjects of triples with matching object and property
+ * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
+ */
+ @Override
+ public Collection<Value> listSubjects(Value property, Value object) {
+ throw new IllegalArgumentException("reverse navigation not supported by Linked Data backend");
+ }
+
+
+ /**
+ * Register a new Linked Data endpoint with this cache provider.
+ *
+ * @param endpoint
+ */
+ @Override
+ public void registerEndpoint(Endpoint endpoint) {
+ ldCache.getEndpointService().addEndpoint(endpoint);
+ }
+
+ /**
+ * List all endpoints currently registered with the Linked Data cache provider.
+ *
+ * @return a collection of endpoints
+ */
+ @Override
+ public Collection<Endpoint> listEndpoints() {
+ return ldCache.getEndpointService().listEndpoints();
+ }
+
+ /**
+ * Unregister the Linked Data endpoint given as argument.
+ *
+ * @param endpoint the endpoint to unregister
+ */
+ @Override
+ public void unregisterEndpoint(Endpoint endpoint) {
+ ldCache.getEndpointService().removeEndpoint(endpoint);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDMemoryBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDMemoryBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDMemoryBackend.java
new file mode 100644
index 0000000..438f3bf
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDMemoryBackend.java
@@ -0,0 +1,70 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.linkeddata;
+
+import at.newmedialab.ldclient.model.CacheEntry;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.sail.memory.MemoryStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * A Linked Data backend implementation with no persistent storage. All retrieved data is kept in memory and discarded
+ * when the virtual machine exits.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDMemoryBackend extends AbstractLDBackend {
+
+ private static final Logger log = LoggerFactory.getLogger(LDMemoryBackend.class);
+
+ private Map<String,CacheEntry> cacheEntries;
+
+ public LDMemoryBackend() {
+ super();
+
+ cacheEntries = new HashMap<String,CacheEntry>();
+
+ try {
+ Repository repository = new SailRepository(new MemoryStore());
+ repository.initialize();
+ setRepository(repository);
+
+ } catch (RepositoryException e) {
+ log.error("error initialising connection to Sesame in-memory repository",e);
+ }
+
+ }
+
+
+
+ /**
+ * Return a map that can be used to store caching metadata about resources. The LDCacheProvider should take care
+ * of persisting the metadata if desired.
+ *
+ * @return a map for storing caching metadata
+ */
+ @Override
+ public Map<String,CacheEntry> getMetadataRepository() {
+ return cacheEntries;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
new file mode 100644
index 0000000..91785c9
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDPersistentBackend.java
@@ -0,0 +1,103 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.linkeddata;
+
+import at.newmedialab.ldclient.model.CacheEntry;
+import jdbm.RecordManager;
+import jdbm.RecordManagerFactory;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.sail.SailRepository;
+import org.openrdf.sail.nativerdf.NativeStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * A Linked Data backend with persistent caching of the retrieved data. All data is read and stored in the directory
+ * passed as constructor argument.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDPersistentBackend extends AbstractLDBackend {
+ private static final Logger log = LoggerFactory.getLogger(LDMemoryBackend.class);
+
+ private Map<String,CacheEntry> cacheEntries;
+
+
+ private RecordManager recordManager;
+
+ /**
+ * Create a persistent linked data backend storing the cache data in the directory passed as argument.
+ * The directory will be created if it does not exist.
+ * @param dataDirectory
+ */
+ public LDPersistentBackend(File dataDirectory) throws IOException {
+ super();
+
+ if(!dataDirectory.exists()) {
+ dataDirectory.mkdirs();
+ }
+
+ File tripleStore = new File(dataDirectory.getAbsolutePath()+File.separator+"triples");
+ if(!tripleStore.exists()) {
+ tripleStore.mkdirs();
+ }
+
+
+ recordManager = RecordManagerFactory.createRecordManager(dataDirectory.getAbsolutePath()+File.separator+"resource_cache.cache");
+
+ cacheEntries = recordManager.treeMap("resources");
+
+ try {
+ Repository repository = new SailRepository(new NativeStore(tripleStore));
+ repository.initialize();
+ setRepository(repository);
+
+ } catch (RepositoryException e) {
+ log.error("error initialising connection to Sesame in-memory repository",e);
+ }
+ }
+
+
+ public void shutdown() {
+ try {
+ recordManager.close();
+ getRepository().shutDown();
+ } catch (IOException e) {
+ log.error("error shutting down record manager for resource cache");
+ } catch (RepositoryException e) {
+ log.error("error shutting down repository for resource cache");
+ }
+ }
+
+
+ /**
+ /**
+ * Return a map that can be used to store caching metadata about resources. The LDCacheProvider should take care
+ * of persisting the metadata if desired.
+ *
+ * @return a map for storing caching metadata
+ */
+ @Override
+ public Map<String,CacheEntry> getMetadataRepository() {
+ return cacheEntries;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
new file mode 100644
index 0000000..8019e1e
--- /dev/null
+++ b/libraries/ldpath/ldpath-backend-linkeddata/src/main/java/org/apache/marmotta/ldpath/backend/linkeddata/LDQuery.java
@@ -0,0 +1,187 @@
+/**
+ * Copyright (C) 2013 Salzburg Research.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.marmotta.ldpath.backend.linkeddata;
+
+import ch.qos.logback.classic.Level;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+import org.apache.marmotta.ldpath.LDPath;
+import org.apache.marmotta.ldpath.backend.sesame.SesameRepositoryBackend;
+import org.apache.marmotta.ldpath.exception.LDPathParseException;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Value;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * Command line application for querying input from files.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class LDQuery {
+
+ private static final Logger log = LoggerFactory.getLogger(LDQuery.class);
+
+ public static void main(String[] args) {
+ Options options = buildOptions();
+
+ CommandLineParser parser = new PosixParser();
+ try {
+ CommandLine cmd = parser.parse( options, args);
+
+ Level logLevel = Level.WARN;
+
+ if(cmd.hasOption("loglevel")) {
+ String logLevelName = cmd.getOptionValue("loglevel");
+ if("DEBUG".equals(logLevelName.toUpperCase())) {
+ logLevel = Level.DEBUG;
+ } else if("INFO".equals(logLevelName.toUpperCase())) {
+ logLevel = Level.INFO;
+ } else if("WARN".equals(logLevelName.toUpperCase())) {
+ logLevel = Level.WARN;
+ } else if("ERROR".equals(logLevelName.toUpperCase())) {
+ logLevel = Level.ERROR;
+ } else {
+ log.error("unsupported log level: {}",logLevelName);
+ }
+ }
+
+ if(logLevel != null) {
+ for(String logname : new String [] {"at","org","net","com"}) {
+
+ ch.qos.logback.classic.Logger logger =
+ (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(logname);
+ logger.setLevel(logLevel);
+ }
+ }
+
+
+ String format = null;
+ if(cmd.hasOption("format")) {
+ format = cmd.getOptionValue("format");
+ }
+
+ SesameRepositoryBackend backend;
+ if(cmd.hasOption("store")) {
+ backend = new LDPersistentBackend(new File(cmd.getOptionValue("store")));
+ } else {
+ backend = new LDMemoryBackend();
+ }
+
+ Resource context = null;
+ if(cmd.hasOption("context")) {
+ context = backend.getRepository().getValueFactory().createURI(cmd.getOptionValue("context"));
+ }
+
+ if(backend != null && context != null) {
+ LDPath<Value> ldpath = new LDPath<Value>(backend);
+
+ if(cmd.hasOption("path")) {
+ String path = cmd.getOptionValue("path");
+
+ for(Value v : ldpath.pathQuery(context,path,null)) {
+ System.out.println(v.stringValue());
+ }
+ } else if(cmd.hasOption("program")) {
+ File file = new File(cmd.getOptionValue("program"));
+
+ Map<String,Collection<?>> result = ldpath.programQuery(context,new FileReader(file));
+
+ for(String field : result.keySet()) {
+ StringBuilder line = new StringBuilder();
+ line.append(field);
+ line.append(" = ");
+ line.append("{");
+ for (Iterator<?> it = result.get(field).iterator(); it.hasNext();) {
+ line.append(it.next().toString());
+ if(it.hasNext()) {
+ line.append(", ");
+ }
+ }
+ line.append("}");
+ System.out.println(line);
+
+ }
+ }
+ }
+
+ if(backend instanceof LDPersistentBackend) {
+ ((LDPersistentBackend) backend).shutdown();
+ }
+
+
+ } catch (ParseException e) {
+ System.err.println("invalid arguments");
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp( "LDQuery", options, true );
+ } catch (LDPathParseException e) {
+ System.err.println("path or program could not be parsed");
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ System.err.println("file or program could not be found");
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("LDQuery", options, true);
+ } catch (IOException e) {
+ System.err.println("could not access cache data directory");
+ HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp("LDQuery", options, true);
+ }
+
+
+ }
+
+ @SuppressWarnings("static-access")
+ private static Options buildOptions() {
+ Options result = new Options();
+
+ OptionGroup query = new OptionGroup();
+ Option path = OptionBuilder.withArgName("path").hasArg().withDescription("LD Path to evaluate on the file starting from the context").create("path");
+ Option program = OptionBuilder.withArgName("file").hasArg().withDescription("LD Path program to evaluate on the file starting from the context").create("program");
+ query.addOption(path);
+ query.addOption(program);
+ query.setRequired(true);
+ result.addOptionGroup(query);
+
+ Option context = OptionBuilder.withArgName("uri").hasArg().withDescription("URI of the context node to start from").create("context");
+ context.setRequired(true);
+ result.addOption(context);
+
+ Option loglevel = OptionBuilder.withArgName("level").hasArg().withDescription("set the log level; default is 'warn'").create("loglevel");
+ result.addOption(loglevel);
+
+ Option store = OptionBuilder.withArgName("dir").hasArg().withDescription("cache the retrieved data in this directory").create("store");
+ result.addOption(store);
+
+
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/AbstractSesameBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/AbstractSesameBackend.java b/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/AbstractSesameBackend.java
deleted file mode 100644
index deafa26..0000000
--- a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/AbstractSesameBackend.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.sesame;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashSet;
-import java.util.Locale;
-import java.util.Set;
-import java.util.concurrent.ThreadPoolExecutor;
-
-import javax.xml.datatype.XMLGregorianCalendar;
-
-import org.openrdf.model.BNode;
-import org.openrdf.model.Literal;
-import org.openrdf.model.Resource;
-import org.openrdf.model.Statement;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.RepositoryResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import at.newmedialab.ldpath.api.backend.RDFBackend;
-
-public abstract class AbstractSesameBackend implements RDFBackend<Value> {
-
- private static final Logger log = LoggerFactory.getLogger(AbstractSesameBackend.class);
-
- /**
- * Return true if the underlying backend supports the parallel execution of queries.
- *
- * @return
- */
- @Override
- public boolean supportsThreading() {
- return false;
- }
-
- /**
- * In case the backend supports threading, this method should return the ExecutorService representing the
- * thread pool. LDPath lets the backend manage the thread pool to avoid excessive threading.
- *
- * @return
- */
- @Override
- public ThreadPoolExecutor getThreadPool() {
- return null;
- }
-
- /**
- * Test whether the node passed as argument is a literal
- *
- * @param n the node to check
- * @return true if the node is a literal
- */
- @Override
- public boolean isLiteral(Value n) {
- return n instanceof Literal;
- }
-
- /**
- * Test whether the node passed as argument is a URI
- *
- * @param n the node to check
- * @return true if the node is a URI
- */
- @Override
- public boolean isURI(Value n) {
- return n instanceof org.openrdf.model.URI;
- }
-
- /**
- * Test whether the node passed as argument is a blank node
- *
- * @param n the node to check
- * @return true if the node is a blank node
- */
- @Override
- public boolean isBlank(Value n) {
- return n instanceof BNode;
- }
-
- /**
- * Return the language of the literal node passed as argument.
- *
- * @param n the literal node for which to return the language
- * @return a Locale representing the language of the literal, or null if the literal node has no language
- * @throws IllegalArgumentException in case the node is no literal
- */
- @Override
- public Locale getLiteralLanguage(Value n) {
- try {
- if(((Literal)n).getLanguage() != null) {
- return new Locale( ((Literal)n).getLanguage() );
- } else {
- return null;
- }
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+n.stringValue()+" is not a literal" +
- "but of type "+debugType(n));
- }
- }
-
- /**
- * Return the URI of the type of the literal node passed as argument.
- *
- * @param n the literal node for which to return the typer
- * @return a URI representing the type of the literal content, or null if the literal is untyped
- * @throws IllegalArgumentException in case the node is no literal
- */
- @Override
- public URI getLiteralType(Value n) {
- try {
- if(((Literal)n).getDatatype() != null) {
- try {
- return new URI(((Literal)n).getDatatype().stringValue());
- } catch (URISyntaxException e) {
- log.error("literal datatype was not a valid URI: {}",((Literal) n).getDatatype());
- return null;
- }
- } else {
- return null;
- }
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+n.stringValue()+" is not a literal" +
- "but of type "+debugType(n));
- }
- }
-
- /**
- * Return the string value of a node. For a literal, this will be the content, for a URI node it will be the
- * URI itself, and for a blank node it will be the identifier of the node.
- *
- * @param value
- * @return
- */
- @Override
- public String stringValue(Value value) {
- return value.stringValue();
- }
-
- @Override
- public BigDecimal decimalValue(Value node) {
- try {
- return ((Literal)node).decimalValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public BigInteger integerValue(Value node) {
- try {
- return ((Literal)node).integerValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Boolean booleanValue(Value node) {
- try {
- return ((Literal)node).booleanValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Date dateTimeValue(Value node) {
- try {
- XMLGregorianCalendar cal = ((Literal)node).calendarValue();
- //TODO: check if we need to deal with timezone and Local here
- return cal.toGregorianCalendar().getTime();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Date dateValue(Value node) {
- try {
- XMLGregorianCalendar cal = ((Literal)node).calendarValue();
- return new GregorianCalendar(cal.getYear(), cal.getMonth(), cal.getDay()).getTime();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Date timeValue(Value node) {
- //TODO: Unless someone knwos how to create a Date that only has the time
- // from a XMLGregorianCalendar
- return dateTimeValue(node);
- }
-
- @Override
- public Long longValue(Value node) {
- try {
- return ((Literal)node).longValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Double doubleValue(Value node) {
- try {
- return ((Literal)node).doubleValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Float floatValue(Value node) {
- try {
- return ((Literal)node).floatValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- @Override
- public Integer intValue(Value node) {
- try {
- return ((Literal)node).intValue();
- } catch (ClassCastException e) {
- throw new IllegalArgumentException("Value "+node.stringValue()+" is not a literal" +
- "but of type "+debugType(node));
- }
- }
-
- protected Collection<Value> listObjectsInternal(RepositoryConnection connection, Resource subject, org.openrdf.model.URI property)
- throws RepositoryException {
- Set<Value> result = new HashSet<Value>();
- RepositoryResult<Statement> qResult = connection.getStatements(subject, property, null, true);
- try {
- while(qResult.hasNext()) {
- result.add(qResult.next().getObject());
- }
- } finally {
- qResult.close();
- }
- return result;
- }
-
- protected Collection<Value> listSubjectsInternal(final RepositoryConnection connection, org.openrdf.model.URI property, Value object)
- throws RepositoryException {
- Set<Value> result = new HashSet<Value>();
- RepositoryResult<Statement> qResult = connection.getStatements(null, property, object, true);
- try {
- while(qResult.hasNext()) {
- result.add(qResult.next().getSubject());
- }
- } finally {
- qResult.close();
- }
- return result;
- }
-
- protected Value createURIInternal(final ValueFactory valueFactory, String uri) {
- return valueFactory.createURI(uri);
- }
-
- protected Value createLiteralInternal(final ValueFactory valueFactory, String content) {
- log.debug("creating literal with content \"{}\"",content);
- return valueFactory.createLiteral(content);
- }
-
- protected Value createLiteralInternal(final ValueFactory valueFactory, String content, Locale language, URI type) {
- log.debug("creating literal with content \"{}\", language {}, datatype {}",new Object[]{content,language,type});
- if(language == null && type == null) {
- return valueFactory.createLiteral(content);
- } else if(type == null) {
- return valueFactory.createLiteral(content,language.getLanguage());
- } else {
- return valueFactory.createLiteral(content, valueFactory.createURI(type.toString()));
- }
- }
-
- /**
- * Prints the type (URI,bNode,literal) by inspecting the parsed {@link Value}
- * to improve error messages and other loggings. In case of literals
- * also the {@link #getLiteralType(Value) literal type} is printed
- * @param value the value or <code>null</code>
- * @return the type as string.
- */
- protected String debugType(Value value) {
- return value == null ? "null":isURI(value)?"URI":isBlank(value)?"bNode":
- "literal ("+getLiteralType(value)+")";
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameConnectionBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameConnectionBackend.java b/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameConnectionBackend.java
deleted file mode 100644
index a805594..0000000
--- a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameConnectionBackend.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.sesame;
-
-import java.net.URI;
-import java.util.Collection;
-import java.util.Locale;
-
-import org.openrdf.model.Resource;
-import org.openrdf.model.Value;
-import org.openrdf.model.ValueFactory;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-
-public class SesameConnectionBackend extends AbstractSesameBackend {
-
- private final RepositoryConnection connection;
- private final ValueFactory valueFactory;
-
- public SesameConnectionBackend(RepositoryConnection connection) {
- this.connection = connection;
- valueFactory = connection.getValueFactory();
- }
-
- @Override
- public Value createLiteral(String content) {
- return createLiteralInternal(valueFactory, content);
- }
-
- @Override
- public Value createLiteral(String content, Locale language, URI type) {
- return createLiteralInternal(valueFactory, content, language, type);
- }
-
- @Override
- public Value createURI(String uri) {
- return createURIInternal(valueFactory, uri);
- }
-
- @Override
- public Collection<Value> listObjects(Value subject, Value property) {
- try {
- return listObjectsInternal(connection, (Resource) subject, (org.openrdf.model.URI) property);
- } catch (RepositoryException e) {
- throw new RuntimeException(
- "error while querying Sesame repository!", e);
- } catch (ClassCastException e) {
- throw new IllegalArgumentException(String.format(
- "Subject needs to be a URI or blank node, property a URI node "
- + "(types: [subject: %s, property: %s])",
- debugType(subject), debugType(property)), e);
- }
- }
-
- @Override
- public Collection<Value> listSubjects(Value property, Value object) {
- try {
- return listSubjectsInternal(connection, (org.openrdf.model.URI) property, object);
- } catch (RepositoryException e) {
- throw new RuntimeException("error while querying Sesame repository!",e);
- } catch (ClassCastException e) {
- throw new IllegalArgumentException(String.format(
- "Property needs to be a URI node (property type: %s)",
- isURI(property)?"URI":isBlank(property)?"bNode":"literal"),e);
- }
- }
-
- public static SesameConnectionBackend withConnection(RepositoryConnection connection) {
- return new SesameConnectionBackend(connection);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/5b8766b3/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameRepositoryBackend.java
----------------------------------------------------------------------
diff --git a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameRepositoryBackend.java b/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameRepositoryBackend.java
deleted file mode 100644
index 94eda72..0000000
--- a/libraries/ldpath/ldpath-backend-sesame/src/main/java/at/newmedialab/ldpath/backend/sesame/SesameRepositoryBackend.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (C) 2013 Salzburg Research.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package at.newmedialab.ldpath.backend.sesame;
-
-import java.net.URI;
-import java.util.Collection;
-import java.util.Locale;
-
-import org.openrdf.model.Resource;
-import org.openrdf.model.Value;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-
-/**
- * Generic implementation of a Sesame backend for LDPath. A Sesame repository is passed as argument to the
- * constructor.
- * <p/>
- * Implementatins can either use this class directly or implement their own Sesame-based backend by subclassing
- * and calling the super constructor.
- * <p/>
- * Author: Sebastian Schaffert
- */
-public class SesameRepositoryBackend extends AbstractSesameBackend {
-
- private Repository repository;
-
- /**
- * Initialise a new sesame backend. Repository needs to be set using setRepository.
- */
- protected SesameRepositoryBackend() {
- }
-
- /**
- * Initialise a new sesame backend using the repository passed as argument.
- *
- * @param repository
- */
- public SesameRepositoryBackend(Repository repository) {
- this.repository = repository;
- }
-
- public Repository getRepository() {
- return repository;
- }
-
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
-
- /**
- * Create a literal node with the content passed as argument
- *
- * @param content string content to represent inside the literal
- * @return a literal node in using the model used by this backend
- */
- @Override
- public Value createLiteral(String content) {
- return createLiteralInternal(repository.getValueFactory(), content);
- }
-
-
- /**
- * Create a literal node with the content passed as argument
- *
- * @param content string content to represent inside the literal
- * @return a literal node in using the model used by this backend
- */
- @Override
- public Value createLiteral(String content, Locale language, URI type) {
- return createLiteralInternal(repository.getValueFactory(), content, language, type);
- }
-
-
- /**
- * Create a URI mode with the URI passed as argument
- *
- * @param uri URI of the resource to create
- * @return a URI node using the model used by this backend
- */
- @Override
- public Value createURI(String uri) {
- return createURIInternal(repository.getValueFactory(), uri);
- }
-
- /**
- * List the objects of triples in the triple store underlying this backend that have the subject and
- * property given as argument.
- *
- * @param subject the subject of the triples to look for
- * @param property the property of the triples to look for
- * @return all objects of triples with matching subject and property
- */
- @Override
- public Collection<Value> listObjects(Value subject, Value property) {
- try {
- RepositoryConnection connection = repository.getConnection();
-
- try {
- connection.begin();
- return listObjectsInternal(connection, (Resource) subject, (org.openrdf.model.URI) property);
- } finally {
- connection.commit();
- connection.close();
- }
- } catch (RepositoryException e) {
- throw new RuntimeException("error while querying Sesame repository!",e);
- } catch (ClassCastException e) {
- throw new IllegalArgumentException(String.format(
- "Subject needs to be a URI or blank node, property a URI node " +
- "(types: [subject: %s, property: %s])",
- debugType(subject),debugType(property)),e);
- }
-
- }
-
- /**
- * List the subjects of triples in the triple store underlying this backend that have the object and
- * property given as argument.
- *
- * @param object the object of the triples to look for
- * @param property the property of the triples to look for
- * @return all subjects of triples with matching object and property
- * @throws UnsupportedOperationException in case reverse selection is not supported (e.g. when querying Linked Data)
- */
- @Override
- public Collection<Value> listSubjects(Value property, Value object) {
- try {
- final RepositoryConnection connection = repository.getConnection();
-
- try {
- connection.begin();
- return listSubjectsInternal(connection, (org.openrdf.model.URI) property, object);
- } finally {
- connection.commit();
- connection.close();
- }
- } catch (RepositoryException e) {
- throw new RuntimeException("error while querying Sesame repository!",e);
- } catch (ClassCastException e) {
- throw new IllegalArgumentException(String.format(
- "Property needs to be a URI node (property type: %s)",
- isURI(property)?"URI":isBlank(property)?"bNode":"literal"),e);
- }
-
- }
-}