You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/07/30 10:50:29 UTC

svn commit: r1367037 - in /incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store: ./ clerezza/ clerezza/src/ clerezza/src/main/ clerezza/src/main/java/ clerezza/src/main/java/org/ clerezza/src/main/java/org/apache/ clerezza/src/ma...

Author: rwesten
Date: Mon Jul 30 08:50:27 2012
New Revision: 1367037

URL: http://svn.apache.org/viewvc?rev=1367037&view=rev
Log:
STANBOL-704: First commit for the Entityhub Store implementations for Clerezza and JenaTDB (native). Revision and Chante management is still missing. Also this was not yet tested. So try not to use this for now.

Added:
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/test/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/test/java/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties   (with props)
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/test/
    incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/test/java/

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 30 08:50:27 2012
@@ -0,0 +1,7 @@
+target
+
+.project
+
+.settings
+
+.classpath

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml Mon Jul 30 08:50:27 2012
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>org.apache.stanbol.entityhub.parent</artifactId>
+    <version>0.11.0-incubating-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
+  </parent>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>org.apache.stanbol.entityhub.store.clerezza</artifactId>
+  <version>0.11.0-incubating-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Stanbol Entityhub Store based on Clerezza</name>
+  <description>This bundle provides implementation of the Entityhub Yard interface(s)
+    based on a RDF Triple store by using the Clerezza framework.
+  </description>
+
+  <inceptionYear>2010</inceptionYear>
+  <licenses>
+    <license>
+      <name>Apache Software License, Version 2.0</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+      <comments>A business-friendly OSS license</comments>
+    </license>
+  </licenses>
+  
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/entityhub/yard/clerezza
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/entityhub/yard/clerezza
+    </developerConnection>
+    <url>http://incubator.apache.org/stanbol</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              org.apache.stanbol.entityhub.yard.clerezza;version=${project.version},
+            </Export-Package>
+            <Private-Package>
+              org.apache.stanbol.entityhub.yard.clerezza.impl;version=${project.version},
+              org.apache.stanbol.entityhub.yard.clerezza.impl.adapter;version=${project.version}
+            </Private-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+
+    </plugins>
+  </build>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.semanticindex.servicesapi</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.semanticindex.core</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.servicesapi</artifactId>
+      <version>0.11.0-incubating-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.core</artifactId>
+      <version>0.9.0-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.model.clerezza</artifactId>
+      <version>0.9.0-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.query.clerezza</artifactId>
+      <version>0.9.0-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.indexedgraph</artifactId>
+      <version>0.9.0-incubating</version>
+    </dependency>
+	<dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.ldpath.clerezza</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+	</dependency>
+    <dependency>
+      <groupId>org.apache.clerezza</groupId>
+      <artifactId>rdf.core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.clerezza</groupId>
+      <artifactId>rdf.utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+
+    <!-- for tests -->
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.test</artifactId>
+      <version>0.11.0-incubating-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <!-- A TC Provider is needed to run the Unit Tests of the Yard Interface.
+         Currently the Simple Storage Provider (in memory) is used.
+         As alternative one could also run the tests against Jena TDB but that
+         would require a lot of additional bundles to be added as test
+         dependencies -->
+    <dependency>
+      <groupId>org.apache.clerezza</groupId>
+      <artifactId>rdf.simple.storage</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java Mon Jul 30 08:50:27 2012
@@ -0,0 +1,523 @@
+package org.apache.stanbol.entityhub.store.clerezza.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.clerezza.rdf.core.BNode;
+import org.apache.clerezza.rdf.core.Graph;
+import org.apache.clerezza.rdf.core.MGraph;
+import org.apache.clerezza.rdf.core.Resource;
+import org.apache.clerezza.rdf.core.Triple;
+import org.apache.clerezza.rdf.core.TripleCollection;
+import org.apache.clerezza.rdf.core.UriRef;
+import org.apache.clerezza.rdf.core.access.LockableMGraph;
+import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
+import org.apache.clerezza.rdf.core.access.TcManager;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.stanbol.commons.indexedgraph.IndexedMGraph;
+import org.apache.stanbol.commons.ldpath.clerezza.ClerezzaBackend;
+import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
+import org.apache.stanbol.commons.semanticindex.store.EpochException;
+import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
+import org.apache.stanbol.commons.semanticindex.store.Store;
+import org.apache.stanbol.commons.semanticindex.store.StoreException;
+import org.apache.stanbol.entityhub.model.clerezza.RdfRepresentation;
+import org.apache.stanbol.entityhub.model.clerezza.RdfValueFactory;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.newmedialab.ldpath.LDPath;
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+
+/**
+ * {@link Store} implementation for Clerezza {@link TripleCollection}. In case
+ * the configured graph URI points to a {@link Graph} the Store will be
+ * read-only (basically only support the {@link IndexingSource} part of the
+ * {@link Store} interface. This also implements {@link RDFBackend} for
+ * {@link Resource} over the configured Graph. The Data of this Store can 
+ * therefore be used with {@link LDPath}.<p>
+ * This implementation internally supports {@link BNode}s. Internally a
+ * {@link Representation} is defined as all outgoing triples including 
+ * recursively all outgoing triples of {@link BNode} used as 
+ * {@link Triple#getObject() object}. This Store also adds Triples with
+ * {@link BNode}s to the {@link RdfRepresentation#getRdfGraph() rdf graph} of
+ * {@link RdfRepresentation}s returned by {@link #get(String)}. However via
+ * the {@link Representation} interface Users will have no direct access to
+ * those information.<p>
+ * 
+ * <b>TODO</b>s:<ul>
+ * <li> This dies not yet support {@link #changes(long, long, int)} and Epochs.
+ * I need to discuss with SUAT if it is possible to make the FileRevisionManager
+ * useable by any {@link Store} implementation. This would dramatically 
+ * reduce the coding requirements for Store Implementations!
+ * <li> No unit tests for now ...
+ * </ul>
+ * 
+ * @author Rupert Westenthaler
+ *
+ */
+@Component(immediate=true,configurationFactory=true,
+		   policy=ConfigurationPolicy.REQUIRE)
+@Properties({
+	@Property(name=Store.PROPERTY_NAME,value="changeMe"),
+	@Property(name=Store.PROPERTY_DESCRIPTION,value="<Optional Description>")
+})
+public class ClerezzaStore extends ClerezzaBackend implements Store<Representation>, RDFBackend<Resource> {
+	private static final Logger log = LoggerFactory.getLogger(ClerezzaStore.class);
+	/**
+	 * Allows to configure the Graph URI used to store the data
+	 */
+	@Property
+	public static final String PROPERTY_GRAPH_URI = "org.apache.stanbol.entityhub.store.clerezza.graphuri";
+    @Reference
+    private TcManager tcManager;
+
+    private TripleCollection graph;
+    
+    private ServiceRegistration graphRegistration;
+    
+    private final RdfValueFactory valueFactory = RdfValueFactory.getInstance();
+
+	private String name;
+	private String description;
+	/**
+	 * Unmodifiable properties as set in the {@link #activate(ComponentContext)}
+	 * method
+	 */
+	private Map<String,Object> properties;
+	
+	@Activate
+	protected final void activate(ComponentContext context) throws ConfigurationException {
+		Object value = context.getProperties().get(PROPERTY_NAME);
+		Map<String,Object> properties = new HashMap<String,Object>();
+		if(value == null || value.toString().isEmpty()){
+			throw new ConfigurationException(PROPERTY_NAME, "The parsed name of the Store MUST NOT be NULL nor empty!");
+		} else if(value.getClass().isArray() || value instanceof Collection<?>){
+			throw new ConfigurationException(PROPERTY_NAME, "Only a single name for the Store MUST BE parsed (type: '"
+					+ value.getClass() +"', values: "+value+")!");
+		} else {
+			this.name = value.toString();
+			properties.put(PROPERTY_NAME, name);
+		}
+		value = context.getProperties().get(Store.PROPERTY_DESCRIPTION);
+		this.description = value != null ? value.toString() : null;
+		if(this.description != null){
+			properties.put(PROPERTY_DESCRIPTION, description);
+		}
+		value = context.getProperties().get(PROPERTY_GRAPH_URI);
+		UriRef graphUri;
+		if(value == null || value.toString().isEmpty()){
+			graphUri = new UriRef(String.format("urn:org.apache:entityhub.store.clerezza:%s",
+					name));
+		} else if(value.getClass().isArray() || value instanceof Collection<?>){
+			throw new ConfigurationException(PROPERTY_GRAPH_URI, "Only a single PROPERTY_GRAPH_URI MUST BE parsed (type: '"
+					+ value.getClass() +"', values: "+value+")!");
+		} else {
+			try {
+				new URI(value.toString());
+			} catch (URISyntaxException e) {
+				throw new ConfigurationException(PROPERTY_GRAPH_URI, "The parsed grph URI is invalid (message: "
+						+ e.getMessage()+")",e);
+			}
+			graphUri = new UriRef(value.toString());
+		}
+		properties.put(PROPERTY_GRAPH_URI, graphUri);
+        try {
+            this.graph = tcManager.getTriples(graphUri);
+            log.info("  ... (re)use existing Graph {} for Yard {}",
+            		graphUri,name);
+            if(!(graph instanceof LockableMGraph)){
+                log.info("        > NOTE: this ClerezzaStore is read-only");
+            }
+        } catch (NoSuchEntityException e) {
+            log.info("   ... create new Graph {} for ClerezzaStore {}",graphUri,name);
+            this.graph =  tcManager.createMGraph(graphUri);
+        }
+        //set the graph also to the parent ClerezzaRepository
+        setGraph(graph);
+        //register the store with the Stanbol SPARQL endpoint
+        Dictionary<String,Object> graphRegProp = new Hashtable<String,Object>();
+        graphRegProp.put("graph.uri", graphUri.getUnicodeString());
+        graphRegProp.put(Constants.SERVICE_RANKING, new Integer(-100));
+        graphRegProp.put("graph.name", name);
+        if(description != null){
+            graphRegProp.put("graph.description", description);
+        }
+        graphRegistration = context.getBundleContext().registerService(
+            TripleCollection.class.getName(), graph, graphRegProp);
+
+        
+		log.info("Activate {} '{}' with grpah URI {}");
+		properties.put(PROPERTY_ITEM_TYPE, Representation.class);
+		this.properties = Collections.unmodifiableMap(properties);
+	}
+	
+	@Deactivate
+	protected final void deactivate(ComponentContext context){
+		if(graphRegistration != null){
+			graphRegistration.unregister();
+		}
+		this.graph = null;
+		setGraph(null);//remove the graph also form the parent ClerezzaRepository
+		this.name = null;
+		this.description = null;
+		this.properties = null;
+	}
+	
+	@Override
+	public String getName() {
+		return name;
+	}
+
+	@Override
+	public String getDescription() {
+		return description;
+	}
+
+	@Override
+	public Class<Representation> getItemType() {
+		return Representation.class;
+	}
+
+	@Override
+	public Map<String, Object> getProperties() {
+		return properties;
+	}
+
+	@Override
+	public Representation get(String uri) throws StoreException {
+        final Lock readLock = readLockGraph();
+        try {
+        	return getRepresentation(new UriRef(uri), null);
+        } finally {
+        	if(readLock != null){ //on read-only Graphs this will be null
+        		readLock.unlock();
+        	}
+        }
+        
+    }
+
+	@Override
+	public long getEpoch() {
+		// TODO implement
+		throw new UnsupportedOperationException("TODO: implement!!");
+	}
+
+	@Override
+	public ChangeSet<Representation> changes(long epoch, long revision,
+			int batchSize) throws StoreException, EpochException {
+		// TODO implement
+		throw new UnsupportedOperationException("TODO: implement!!");
+	}
+
+	@Override
+	public Representation remove(String uri) throws StoreException {
+        final Lock writeLock = writeLockGraph();
+        try {
+        	Representation resource = get(uri);
+        	if(resource != null){
+        		removeResource(new UriRef(uri));
+        	}
+        	return resource;
+        } finally {
+            writeLock.unlock();
+        }
+	}
+
+	@Override
+	public String put(Representation representation) throws StoreException {
+        log.debug("put Representation " + representation.getId());
+        final Lock writeLock = writeLockGraph();
+        try {
+            return add(representation);
+        } finally {
+            writeLock.unlock();
+        }
+    }
+
+	@Override
+	public Iterable<String> put(Iterable<Representation> items)
+			throws StoreException {
+		List<String> processed = new ArrayList<String>();
+        final Lock writeLock = writeLockGraph();
+        try {
+        	//remove all existing
+			for(Representation item : items){
+				removeResource(new UriRef(item.getId()));
+			}
+			//add all parsed
+			for(Representation item : items){
+				add(item);
+				processed.add(item.getId());
+			}
+        } finally {
+            writeLock.unlock();
+        }
+		return processed;
+	}
+
+	@Override
+	public void remove(Iterable<String> uris) throws StoreException {
+        final Lock writeLock = writeLockGraph();
+        try {
+	    	//remove all existing
+			for(String uri : uris){
+				removeResource(new UriRef(uri));
+			}
+        } finally {
+            writeLock.unlock();
+        }
+	}
+
+	@Override
+	public void removeAll() throws StoreException {
+        final Lock writeLock = writeLockGraph();
+        try {
+        	graph.clear();
+        } finally {
+            writeLock.unlock();
+        }
+	}
+
+	
+	/* -----------------------------------------------------------------------
+	 * Utility methods for getting/adding/removing Resources 
+	 * (including support for BNodes)
+	 * -----------------------------------------------------------------------
+	 */
+	/**
+	 * Adds the representation (without deleting). Assumes a writeLock
+	 * @param representation
+	 * @return
+	 */
+	protected final String add(Representation representation) {
+		//get the graph for the Representation and add it to the store
+		RdfRepresentation toAdd = ((RdfValueFactory)valueFactory).toRdfRepresentation(representation);
+		//log.info("  > add "+toAdd.size()+" triples to Yard "+getId());
+
+		addResource(toAdd.getRdfGraph(),toAdd.getNode());
+		return representation.getId();
+	}
+	
+	/**
+	 * Removes the {@link Representation#getId() resource} and also recursively 
+	 * all {@link BNode}s referenced by outgoing triples. This ensures that
+	 * BNodes added to the graph are also deleted of the {@link Representation}
+	 * is deleted.
+     * <p>
+     * This method assumes a read lock on {@link #graph}
+	 * @param resource
+	 * @return
+	 */
+	private boolean removeResource(UriRef resource) {
+		Iterator<Triple> current = graph.filter(resource, null, null);
+		Set<BNode> bNodes = new HashSet<BNode>();
+		boolean contains = current.hasNext();
+		while(current.hasNext()){ //delete current
+		    Triple t = current.next();
+		    current.remove();
+		    if(t.getObject() instanceof BNode){
+		    	BNode node = (BNode)t.getObject();
+		    	if(!graph.filter(null, null, node).hasNext()){
+		    		bNodes.add(node);
+		    	} //other resources to refer the same BNode ... do not delete
+		    }
+		}
+		//remove all outgoing references with BNodes as object
+		while(!bNodes.isEmpty()){
+			Iterator<BNode> it = bNodes.iterator();
+			boolean modified = false;
+			while(it.hasNext() && //still more BNodes to remove
+					!modified){ // if the bNodes set is modified we need a new Iterator!
+				BNode node = it.next();
+				it.remove(); //remove the BNode before processing as afterwards
+				//the Set might already be modified!
+				modified = removeBNode(node,bNodes);
+			}
+		}
+		return contains;
+	}
+	
+	
+	/**
+	 * Removes all triples for this {@link BNode} and adds all other
+	 * {@link BNode}s referenced by {@link Triple#getObject()}.<p>
+	 * This allows to recursively remove all BNodes of outgoing triples without
+	 * recursively calling this method
+	 * @param resource the BNode to remove
+	 * @param set other BNodes
+	 * @return if the parsed set was modified by this method
+	 */
+	private boolean removeBNode(BNode resource, Set<BNode> set){
+		Iterator<Triple> current = graph.filter(resource, null, null);
+		boolean modified = false;
+		while(current.hasNext()){ //delete current
+		    Resource obj = current.next().getObject();
+		    current.remove();
+		    if(obj instanceof BNode && !obj.equals(resource)){
+		    	BNode node = (BNode)obj;
+		    	if(!node.equals(resource) && !graph.filter(null, null, node).hasNext()){
+		    		modified = set.add(node) || modified;
+		    	} //else ignore because
+		    	// the Bnode of the object is the same as the subject or
+		    	// an other resources to refer the same BNode
+		    }
+		}
+		return modified;
+	}
+
+	/**
+	 * Adds all outgoing triples for the parsed resource. In addition it also
+	 * adds triples for {@link BNode}s that are {@link Triple#getObject()}s of
+	 * added triples.
+     * <p>
+     * This method assumes a read lock on {@link #graph}
+	 * @param source the source graph
+	 * @param resource the resource to add
+	 */
+	private void addResource(TripleCollection source, UriRef resource) {
+		Iterator<Triple> triples = source.filter(resource, null, null);
+		Set<BNode> bNodes = new HashSet<BNode>();
+		while(triples.hasNext()){
+			Triple t = triples.next();
+			if(t.getObject() instanceof BNode){
+				bNodes.add((BNode)t.getObject());
+			}
+		    graph.add(t);
+		}
+		while(!bNodes.isEmpty()){
+			boolean modified = false;
+			Iterator<BNode> it = bNodes.iterator();
+			while(!modified && it.hasNext()){
+				BNode node = it.next();
+				it.remove();
+				modified = addBNode(source, node, bNodes);
+			}
+		}
+	}
+	private boolean addBNode(TripleCollection source, BNode node, Set<BNode> set) {
+		boolean modified = false;
+		Iterator<Triple> triples = source.filter(node, null, null);
+		while(triples.hasNext()){
+			Triple t = triples.next();
+		    graph.add(t);
+			if(t.getObject() instanceof BNode){
+				modified = set.add((BNode)t.getObject());
+			}
+		}
+		return modified;
+	}
+    /**
+     * Creates a {@link RdfRepresentation} for the parsed resource. If target
+     * is not <code>null</code> it will be used to create the representation.
+     * This follows all outgoing {@link Triple} as well as recursively 
+     * outgoing triples of {@link BNode}s used as {@link Triple#getObject()}.
+     * <p>
+     * This method assumes a read lock on {@link #graph}
+     */
+    private RdfRepresentation getRepresentation(UriRef resource, MGraph target){
+        //we need all the outgoing relations and also want to follow bNodes until
+        //the next UriRef. However we are not interested in incoming relations!
+    	if(target == null){
+    		target = new IndexedMGraph();
+    	}
+    	Set<BNode> bNodes = new HashSet<BNode>();
+        Iterator<Triple> triples = graph.filter(resource, null, null);
+        if(!triples.hasNext()){
+        	return null;
+        }
+        while (triples.hasNext()) {
+            Triple triple = triples.next();
+            target.add(triple);
+            Resource object = triple.getObject();
+            if(object instanceof BNode){
+            	//collect BNodes to process them later
+            	bNodes.add((BNode)object);
+            }
+        }
+        Set<BNode> visited = new HashSet<BNode>();
+        while(!bNodes.isEmpty()){
+        	Iterator<BNode> it = bNodes.iterator();
+        	boolean modified = false;
+        	while(!modified && it.hasNext()){
+        		BNode node = it.next();
+        		it.remove();
+        		modified = collectTriples(target, node, visited, bNodes);
+        	}
+        }
+        return valueFactory.createRdfRepresentation(resource, target);
+    }
+    private boolean collectTriples(MGraph target, BNode node, Set<BNode> visited, Set<BNode> set){
+    	visited.add(node);
+        Iterator<Triple> triples = graph.filter(node, null, null);
+        boolean modified = false;
+        while (triples.hasNext()) {
+            Triple triple = triples.next();
+            target.add(triple);
+            Resource object = triple.getObject();
+            if(object instanceof BNode && !visited.contains(object)){
+            	//an other BNode we need to follow
+            	modified = set.add((BNode)object) || modified;
+            }
+        }
+        return modified;
+    }
+
+	/* -----------------------------------------------------------------------
+	 * Utils for read/write locks on the TripleCollection
+	 * -----------------------------------------------------------------------
+	 */
+
+    /**
+     * @return
+     * @throws StoreException in case this store is read-only
+     */
+    private Lock writeLockGraph() throws StoreException {
+        final Lock writeLock;
+        if(graph instanceof LockableMGraph){
+            writeLock = ((LockableMGraph)graph).getLock().writeLock();
+            writeLock.lock();
+        } else {
+            throw new StoreException("Unable modify data in ClerezzaStore '"+name
+                + "' because the backing RDF graph '"+properties.get(PROPERTY_GRAPH_URI)
+                + "' is read-only!");
+        }
+        return writeLock;
+    }
+    /**
+     * @return the readLock or <code>null</code>if no read lock is needed
+     */
+    private Lock readLockGraph() {
+        final Lock readLock;
+        if(graph instanceof LockableMGraph){
+            readLock = ((LockableMGraph)graph).getLock().readLock();
+            readLock.lock();
+        } else {
+            readLock = null;
+        }
+        return readLock;
+    }
+}

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/java/org/apache/stanbol/entityhub/store/clerezza/impl/ClerezzaStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties Mon Jul 30 08:50:27 2012
@@ -0,0 +1,14 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/clerezza/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul 30 08:50:27 2012
@@ -0,0 +1,7 @@
+.settings
+
+target
+
+.classpath
+
+.project

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml Mon Jul 30 08:50:27 2012
@@ -0,0 +1,186 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.stanbol</groupId>
+    <artifactId>org.apache.stanbol.entityhub.parent</artifactId>
+    <version>0.11.0-incubating-SNAPSHOT</version>
+    <relativePath>../../parent</relativePath>
+  </parent>
+
+  <groupId>org.apache.stanbol</groupId>
+  <artifactId>org.apache.stanbol.entityhub.store.jenatdb</artifactId>
+  <version>0.11.0-incubating-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <name>Apache Stanbol Entityhub Store based on Jena TDB</name>
+  <description>Store implementation based on Jena TDB for Representations
+  </description>
+
+  <inceptionYear>2012</inceptionYear>
+  <licenses>
+    <license>
+      <name>Apache Software License, Version 2.0</name>
+      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+      <distribution>repo</distribution>
+      <comments>A business-friendly OSS license</comments>
+    </license>
+  </licenses>
+  
+  <scm>
+    <connection>
+      scm:svn:http://svn.apache.org/repos/asf/incubator/stanbol/trunk/entityhub/store/jenatdb
+    </connection>
+    <developerConnection>
+      scm:svn:https://svn.apache.org/repos/asf/incubator/stanbol/trunk/entityhub/store/jenatdb
+    </developerConnection>
+    <url>http://incubator.apache.org/stanbol</url>
+  </scm>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+              org.apache.stanbol.entityhub.store.jenatdb;version=${project.version}
+            </Export-Package>
+            <!-- NOTE: The exclusion of javax.xml.stream assumes that only serialised
+                 java objects are used as serialisation to and from the SolrServer
+                 and therefore no XML API is needed -->
+            <Import-Package>
+              *
+            </Import-Package>
+            <Private-Package>
+              org.apache.stanbol.entityhub.store.jenatdb.impl;version=${project.version}
+            </Private-Package>
+            <Embed-Dependency>
+            </Embed-Dependency>
+            <!-- 
+              We need to provide the default SolrYard indexConfigurations to
+              the DataFileProvider infrastructure
+            <Data-Files>
+            </Data-Files>
+             -->
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-scr-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+    <!-- Stanbol Commomns dependencies -->
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.semanticindex.servicesapi</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+    </dependency>
+    <dependency> <!-- provides Solr and OSGI utilities for Solr -->
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.commons.semanticindex.core</artifactId>
+      <version>0.10.0-incubating-SNAPSHOT</version>
+    </dependency>
+
+    <!-- Stanbol Entityhub internal dependencies -->
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.core</artifactId>
+      <version>0.11.0-incubating-SNAPSHOT</version>
+    </dependency>
+
+   <!--  other dependencies -->
+    <dependency>
+      <groupId>joda-time</groupId>
+      <artifactId>joda-time</artifactId>
+    </dependency>
+     <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-compress</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency> 
+
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.compendium</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.scr.annotations</artifactId>
+    </dependency>
+    <!-- Jena -->
+    <dependency>
+      <groupId>com.hp.hpl.jena</groupId>
+      <artifactId>tdb</artifactId>
+    </dependency>
+
+    <!-- LD-Path -->
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>at.newmedialab.ldpath</groupId>
+      <artifactId>ldpath-core-bundle</artifactId>
+    </dependency>
+
+    <!-- Logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+
+    <!-- for tests -->
+    <dependency>
+      <groupId>org.apache.stanbol</groupId>
+      <artifactId>org.apache.stanbol.entityhub.test</artifactId>
+      <version>0.11.0-incubating-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <scope>test</scope>
+    </dependency>
+   
+  </dependencies>
+
+</project>

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java Mon Jul 30 08:50:27 2012
@@ -0,0 +1,297 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.stanbol.entityhub.store.jenatdb.impl;
+
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
+import com.hp.hpl.jena.graph.Node;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.model.backend.AbstractBackend;
+
+/**
+ * <hr>
+ * <b>NOTE</b>: This class is copy/pasted from 
+ * <code>org.apache.stanbol.entityhub.indexing.source.jenatdb.AbstractTdbBackend</code>
+ * with the intension that the old package will be replace by this one.
+ * <hr>
+ * Implements all the value converter methods of {@link RDFBackend}.
+ * @author Rupert Westenthaler
+ *
+ */
+public abstract class AbstractTdbBackend extends AbstractBackend<Node> implements RDFBackend<Node> {
+
+    /**
+     * Avoids massive instance creation for language literal
+     */
+    private Map<String,Locale> localeCache = new TreeMap<String,Locale>();
+    /**
+     * Avoids massive instance creation for typed literal URIs
+     */
+    private Map<String,URI> xsdTypeCache = new TreeMap<String,URI>();
+    /**
+     * Provides the jena type for a type URI
+     */
+    private TypeMapper typeMapper = TypeMapper.getInstance();
+    
+    private Locale toLocale(String lang){
+        if(lang == null){ 
+            return null;
+        }
+        Locale locale = localeCache.get(lang);
+        if(locale == null){
+            locale = new Locale(lang);
+            localeCache.put(lang, locale);
+        }
+        return locale;
+    }
+    private URI toLiteralTypeURI(String type){
+        if(type == null){ 
+            return null;
+        }
+        URI uri = xsdTypeCache.get(type);
+        if(uri == null){
+            uri = URI.create(type);
+            xsdTypeCache.put(type, uri);
+        }
+        return uri;
+    }    
+    
+    @Override
+    public boolean supportsThreading() {
+        //threading is supposed to be used in cases where LDpath needs to
+        //use remote services. No advantage of having multiple threads on a
+        //triple store limited by local File access.
+        return false;
+    }
+
+    @Override
+    public ThreadPoolExecutor getThreadPool() {
+        return null;
+    }
+
+    @Override
+    public boolean isLiteral(Node n) {
+        return n.isLiteral();
+    }
+
+    @Override
+    public boolean isURI(Node n) {
+        return n.isURI();
+    }
+
+    @Override
+    public boolean isBlank(Node n) {
+        return n.isBlank();
+    }
+
+
+    @Override
+    public Locale getLiteralLanguage(Node n) {
+        if(n.isLiteral()){
+            return toLocale(n.getLiteralLanguage());
+        } else {
+            throw new IllegalArgumentException("The parsed Node is not a Literal");
+        }
+    }
+
+
+    @Override
+    public URI getLiteralType(Node n) {
+        if(n.isLiteral()){
+            return toLiteralTypeURI(n.getLiteralDatatypeURI());
+        } else {
+            throw new IllegalArgumentException("The parsed Node is not a Literal");
+        }
+    }
+
+    @Override
+    public Node createLiteral(String content) {
+        return Node.createLiteral(content);
+    }
+    @Override
+    public Node createLiteral(String content, Locale language, URI type) {
+        return Node.createLiteral(content, 
+            language == null ? null : language.getLanguage(), 
+            typeMapper.getSafeTypeByName(
+                type == null ? null : type.toString()));
+    }
+
+    @Override
+    public Node createURI(String uri) {
+        return Node.createURI(uri);
+    }
+
+    @Override
+    public String stringValue(Node node) {
+        if(node.isLiteral()){
+            //we do not want '"example"@en' but 'example'
+            return node.getLiteralLexicalForm();
+        } else {
+            return node.toString();
+        }
+    }
+
+    @Override
+    public Double doubleValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            if(value instanceof Double){
+                return (Double)value;
+            } else {
+                return super.doubleValue(node);
+            }
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Long longValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            if(value instanceof Long){
+                return (Long)value;
+            } else {
+                return super.longValue(node);
+            }
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Boolean booleanValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            if(value instanceof Boolean){
+                return (Boolean)value;
+            } else {
+                return super.booleanValue(node);
+            }
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Date dateTimeValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            try {
+                if(value instanceof XSDDateTime){
+                    return ((XSDDateTime)value).asCalendar().getTime();
+                }
+            } catch (RuntimeException e) { /*ignore*/}
+            return super.dateTimeValue(node);
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Date dateValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            try {
+                if(value instanceof XSDDateTime){
+                    return new GregorianCalendar(
+                        ((XSDDateTime)value).getYears(), 
+                        ((XSDDateTime)value).getMonths() -1, 
+                        ((XSDDateTime)value).getDays()).getTime();
+                }
+            } catch (RuntimeException e) { /*ignore*/}
+            return super.dateValue(node);
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Date timeValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            try {
+                if(value instanceof XSDDateTime){
+                    Calendar cal = ((XSDDateTime)value).asCalendar();
+                    cal.set(1900, 0, 1); //we need only the time
+                    return cal.getTime();
+                }
+            } catch (RuntimeException e) { /*ignore*/}
+            return super.timeValue(node);
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Float floatValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            if(value instanceof Float){
+                return (Float)value;
+            } else {
+                return super.floatValue(node);
+            }
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+    @Override
+    public Integer intValue(Node node) {
+        if(node.isLiteral()){
+            Object value = node.getLiteral().getValue();
+            if(value instanceof Integer){
+                return (Integer)value;
+            } else {
+                return super.intValue(node);
+            }
+        } else {
+            throw new IllegalArgumentException("parsed node is not an Literal");
+        }
+    }
+
+//    @Override
+//    public BigInteger integerValue(Node node) {
+//        // TODO Auto-generated method stub
+//        return null;
+//    }
+
+//    @Override
+//    public BigDecimal decimalValue(Node node) {
+//        // TODO Auto-generated method stub
+//        return null;
+//    }
+
+    @Override
+    public abstract Collection<Node> listObjects(Node subject, Node property);
+
+    @Override
+    public abstract Collection<Node> listSubjects(Node property, Node object);
+
+}

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/AbstractTdbBackend.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java Mon Jul 30 08:50:27 2012
@@ -0,0 +1,604 @@
+package org.apache.stanbol.entityhub.store.jenatdb.impl;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.io.FilenameUtils;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.stanbol.commons.semanticindex.store.ChangeSet;
+import org.apache.stanbol.commons.semanticindex.store.EpochException;
+import org.apache.stanbol.commons.semanticindex.store.IndexingSource;
+import org.apache.stanbol.commons.semanticindex.store.Store;
+import org.apache.stanbol.commons.semanticindex.store.StoreException;
+import org.apache.stanbol.entityhub.core.model.InMemoryValueFactory;
+import org.apache.stanbol.entityhub.core.utils.TimeUtils;
+import org.apache.stanbol.entityhub.servicesapi.defaults.DataTypeEnum;
+import org.apache.stanbol.entityhub.servicesapi.model.Reference;
+import org.apache.stanbol.entityhub.servicesapi.model.Representation;
+import org.apache.stanbol.entityhub.servicesapi.model.Text;
+import org.apache.stanbol.entityhub.servicesapi.model.ValueFactory;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hp.hpl.jena.datatypes.BaseDatatype;
+import com.hp.hpl.jena.datatypes.DatatypeFormatException;
+import com.hp.hpl.jena.datatypes.RDFDatatype;
+import com.hp.hpl.jena.datatypes.TypeMapper;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
+import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
+import com.hp.hpl.jena.datatypes.xsd.XSDDuration;
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.graph.Triple;
+import com.hp.hpl.jena.graph.impl.LiteralLabel;
+import com.hp.hpl.jena.graph.impl.LiteralLabelFactory;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.tdb.TDB;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+
+import at.newmedialab.ldpath.api.backend.RDFBackend;
+
+@Component(immediate=true,configurationFactory=true,
+           policy=ConfigurationPolicy.REQUIRE)
+@Properties({
+    @Property(name=Store.PROPERTY_NAME,value="changeMe"),
+    @Property(name=Store.PROPERTY_DESCRIPTION,value="<Optional Description>")
+})
+public class JenaTdbStore extends AbstractTdbBackend implements Store<Representation>, RDFBackend<Node> {
+
+	private static final Logger log = LoggerFactory.getLogger(JenaTdbStore.class);
+	
+	/**
+	 * The name of the Jena TDB model (the directory holding the data). 
+	 * If {@link #PROPERTY_NAMED_GRAPH_STATE NamedGraph}s are enabled this will 
+	 * be the default Jena TDB model of this Store implementation. Otherwise the
+	 * configured {@link IndexingSource#PROPERTY_NAME name} is used as default. 
+	 */
+	@Property
+	public static final String PROPERTY_JENA_TDB_MODEL = "org.apache.stanbol.entityhub.store.jenatdb.model";
+	/**
+	 * Allows to enable/disable the use of named graphs. For small and medium
+	 * sized data sources one would typically like to use named graphs. For 
+	 * big RDF graphs only using the default graph (deactivating named graphs)
+	 * will reduce the size of the data on the disc as only SPO need to be
+	 * stored.
+	 */
+	@Property(boolValue=JenaTdbStore.DEFAULT_NAMED_GRAPH_STATE)
+	public static final String PROPERTY_NAMED_GRAPH_STATE = "org.apache.stanbol.entityhub.store.jenatdb.namedgraph.state";
+	/**
+	 * As a default {@link #PROPERTY_NAMED_GRAPH_STATE} is enabled
+	 */
+	private static final boolean DEFAULT_NAMED_GRAPH_STATE = true;
+	/**
+	 * The URI used for the named graph. Ignored if {@link #PROPERTY_NAMED_GRAPH_STATE}
+	 * is deactivated.
+	 */
+	@Property
+	public static final String PROPERTY_NAMED_GRAPH_URI = "org.apache.stanbol.entityhub.store.jenatdb.namedgraph.uri";
+	/**
+	 * Property that can not be configured, but provides the location of the
+	 * TDB directory. Users can receive this by using {@link #getProperties()}
+	 */
+	public static final String PROPERTY_TDB_MODEL_LOCATION = "org.apache.stanbol.entityhub.store.jenatdb.modellocation";
+	/**
+	 * The name of the main Jena TDB model.
+	 */
+	protected static final String ROOT_PATH = "entityhub/store/jenatdb/";
+	/**
+	 * The name of the main Jena TDB model.
+	 */
+	public static final String MAIN_JENA_TDB_MODEL = "_main";
+	
+    /**
+     * The valueFactory used to create {@link Representation}s, {@link Reference}s
+     * and {@link Text} instances. This uses the {@link InMemoryValueFactory}
+     */
+    private ValueFactory valueFactory = InMemoryValueFactory.getInstance();
+    /**
+     * The Jena TypeMapper allows to convert Java Classes to {@link RDFDatatype}s.
+     * RDFDatatypes can than be used to create {@link Node} instances representing
+     * typed literals.
+     */
+    private TypeMapper typeMapper = TypeMapper.getInstance();
+	private Dataset dataset;
+	private String name;
+	private String description;
+	private Map<String,Object> properties;
+	private Graph graph;
+	/**
+	 * The {@link Node} of the named graph. Will be <code>null</code> if no
+	 * named graphs are used.
+	 */
+	private Node namedGraphNode;
+
+	@Activate
+	protected final void activate(ComponentContext context) throws ConfigurationException {
+		Object value = context.getProperties().get(PROPERTY_NAME);
+		Map<String,Object> properties = new HashMap<String,Object>();
+		if(value == null || value.toString().isEmpty()){
+			throw new ConfigurationException(PROPERTY_NAME, "The parsed name of the Store MUST NOT be NULL nor empty!");
+		} else if(value.getClass().isArray() || value instanceof Collection<?>){
+			throw new ConfigurationException(PROPERTY_NAME, "Only a single name for the Store MUST BE parsed (type: '"
+					+ value.getClass() +"', values: "+value+")!");
+		} else {
+			this.name = value.toString();
+			properties.put(PROPERTY_NAME, name);
+		}
+		value = context.getProperties().get(Store.PROPERTY_DESCRIPTION);
+		this.description = value != null ? value.toString() : null;
+		if(this.description != null){
+			properties.put(PROPERTY_DESCRIPTION, description);
+		}
+		boolean namedGraphState;
+		value = context.getProperties().get(PROPERTY_NAMED_GRAPH_STATE);
+		if(value == null ||value.toString().isEmpty()){
+			namedGraphState = DEFAULT_NAMED_GRAPH_STATE;
+		} else if(value.getClass().isArray() || value instanceof Collection<?>){
+			throw new ConfigurationException(PROPERTY_NAMED_GRAPH_STATE, "Only a single PROPERTY_NAMED_GRAPH_STATE MUST BE parsed (type: '"
+					+ value.getClass() +"', values: "+value+")!");
+		} else if(value instanceof Boolean){
+			namedGraphState = (Boolean)value;
+		} else {
+			namedGraphState = Boolean.parseBoolean(value.toString());
+		}
+		String jenaTdbModelName;
+		//parse the TDB model name
+		value = context.getProperties().get(PROPERTY_JENA_TDB_MODEL);
+		if(value == null ||value.toString().isEmpty()){
+			jenaTdbModelName = name;
+		} else if(value.getClass().isArray() || value instanceof Collection<?>){
+			throw new ConfigurationException(PROPERTY_NAMED_GRAPH_STATE, "Only a single PROPERTY_NAMED_GRAPH_STATE MUST BE parsed (type: '"
+					+ value.getClass() +"', values: "+value+")!");
+		} else {
+			jenaTdbModelName = value.toString();
+		}
+		if(jenaTdbModelName.equalsIgnoreCase(MAIN_JENA_TDB_MODEL)){
+			throw new ConfigurationException(PROPERTY_JENA_TDB_MODEL, 
+					"The configured Jena TDB model name MUST NOT be the same as the default '"
+					+ MAIN_JENA_TDB_MODEL+"' (Note the name of the store is used as default if "
+					+ "no specific model name is configured!");
+		}
+		Node namedGraphUri;
+		if(namedGraphState){ //parse the URI for the named grpah
+			value = context.getProperties().get(PROPERTY_NAMED_GRAPH_URI);
+			if(value == null || value.toString().isEmpty()){
+				namedGraphUri = Node.createURI(String.format("urn:org.apache:entityhub.store.jenatdb:%s",
+						name));
+			} else if(value.getClass().isArray() || value instanceof Collection<?>){
+				throw new ConfigurationException(PROPERTY_NAMED_GRAPH_URI, "Only a single PROPERTY_NAMED_GRAPH_URI MUST BE parsed (type: '"
+						+ value.getClass() +"', values: "+value+")!");
+			} else {
+				try {
+					new URI(value.toString());
+				} catch (URISyntaxException e) {
+					throw new ConfigurationException(PROPERTY_NAMED_GRAPH_URI, "The parsed grph URI is invalid (message: "
+							+ e.getMessage()+")",e);
+				}
+				namedGraphUri = Node.createURI(value.toString());
+			}
+			properties.put(PROPERTY_NAMED_GRAPH_URI, namedGraphUri.toString());
+		} else {// else no named graph uri if named graphs are deactivated
+			namedGraphUri = null;
+		}
+		
+		//initialise the Jena TDB dataset/graph
+		String modelRoot = FilenameUtils.concat(
+				context.getBundleContext().getProperty("sling.home"),
+				ROOT_PATH);
+		String modelLocation;
+		if(namedGraphState){
+			modelLocation = FilenameUtils.concat(modelRoot, 
+					jenaTdbModelName == null ? name : jenaTdbModelName);
+			this.namedGraphNode = namedGraphUri; //set the node of the named graph
+		} else {
+			modelLocation = FilenameUtils.concat(modelRoot, 
+					jenaTdbModelName == null ? MAIN_JENA_TDB_MODEL : jenaTdbModelName);
+			this.namedGraphNode = null; //no named graph
+		}
+		properties.put(PROPERTY_TDB_MODEL_LOCATION, modelLocation);
+		//init the TDB dataset
+		dataset = Utils.initTDBDataset(new File(modelLocation));
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			graph = Utils.initGraph(dataset,namedGraphNode);
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+		this.properties = Collections.unmodifiableMap(properties);
+	}
+	
+	@Deactivate
+	protected final void deactivate(ComponentContext context){
+		TDB.sync(graph);
+		graph.close();
+		graph = null;
+		if(namedGraphNode == null){
+			TDB.sync(dataset);
+			dataset.close();
+		} //else ... other graphs might still be open ... do not close
+		dataset = null;
+		namedGraphNode = null;
+		properties = null;
+		description = null;
+		name = null;
+	}
+	
+	@Override
+	public String getName() {
+		return name;
+	}
+
+	@Override
+	public String getDescription() {
+		return description;
+	}
+
+	@Override
+	public Class<Representation> getItemType() {
+		return Representation.class;
+	}
+
+	@Override
+	public Map<String, Object> getProperties() {
+		return properties;
+	}
+
+	@Override
+	public Representation get(String uri) throws StoreException {
+        Node resource = Node.createURI(uri);
+        Representation source = valueFactory.createRepresentation(uri);
+		dataset.getLock().enterCriticalSection(true);
+		try {
+	        ExtendedIterator<Triple> outgoing = graph.find(resource, null, null);
+	        boolean found = outgoing.hasNext();
+	        while(outgoing.hasNext()){ //iterate over the statements for that resource
+	            Triple statement = outgoing.next();
+	            Node predicate = statement.getPredicate();
+	            if(predicate == null || !predicate.isURI()){
+	                log.warn("Ignore field {} for resource {} because it is null or not an URI!",
+	                    predicate,resource);
+	            } else {
+	                String field = predicate.getURI();
+	                Node value = statement.getObject();
+	                processValue(value, source, field);
+	            } //end else predicate != null
+	        } //end iteration over resource triple
+	        if(found) {
+	            return source;
+	            //log.info("Resource: \n"+ModelUtils.getRepresentationInfo(source));
+	        } else {
+	            log.debug("No Statements found for Entity {}!",uri);
+	            return null;
+	        }
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+	}
+
+	@Override
+	public long getEpoch() {
+		// TODO not yet implemented
+		throw new UnsupportedOperationException("TODO: implement!!");
+	}
+
+	@Override
+	public ChangeSet<Representation> changes(long epoch, long revision, int batchSize)
+			throws StoreException, EpochException {
+		// TODO not yet implemented
+		throw new UnsupportedOperationException("TODO: implement!!");
+	}
+
+	@Override
+	public String put(Representation item) throws StoreException {
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			Node node = Node.createURI(item.getId());
+			removeResource(node); //remove the old data
+			addResource(item); //add the new data
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+		return item.getId();
+	}
+
+	/**
+	 * Adds an Resource based on the data of the parsed Representation. Does
+	 * NOT delete any present information. Assumes a Write Lock.
+	 * @param item
+	 */
+	private void addResource(Representation item) {
+		Node subject = Node.createURI(item.getId());
+		for(Iterator<String> fields =item.getFieldNames(); fields.hasNext();){
+			String field = fields.next();
+			Node property = Node.createURI(field);
+			for(Iterator<Object> values = item.get(field);values.hasNext();){
+				Object value = values.next();
+				Node object = getNode(value);
+				graph.add(new Triple(subject,property,object));
+			}
+		}
+	}
+	
+	@Override
+	public Iterable<String> put(Iterable<Representation> items) throws StoreException {
+		List<String> added = new ArrayList<String>(); 
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			for(Representation item : items){
+				try {
+					Node node = Node.createURI(item.getId());
+					removeResource(node); //remove the old data
+					addResource(item); //add the new data
+					added.add(item.getId());
+				}catch (RuntimeException e) {
+					log.warn("Unable to add Representation '"+item.getId()
+							+"' Message: "+e.getMessage(),e);
+				}
+			}
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+		return added;
+	}
+
+	@Override
+	public Representation remove(String uri) throws StoreException {
+		Representation removed;
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			removed = get(uri);
+			if(removed != null){
+				removeResource(Node.createURI(uri));
+			}
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+		return removed;
+	}
+
+	@Override
+	public void remove(Iterable<String> uris) throws StoreException {
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			for(String uri : uris){
+				removeResource(Node.createURI(uri));
+			}
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+		
+	}
+
+	@Override
+	public void removeAll() throws StoreException {
+		dataset.getLock().enterCriticalSection(false);
+		try {
+			graph = Utils.cleanGraph(dataset, namedGraphNode);
+		} finally {
+			dataset.getLock().leaveCriticalSection();
+		}
+	}
+
+    /* ----------------------------------------------------------------------
+     *     RDF Backend implementation
+     * ----------------------------------------------------------------------
+     */
+    @Override
+	public Collection<Node> listObjects(Node subject, Node property) {
+        Collection<Node> nodes = new ArrayList<Node>();
+		dataset.getLock().enterCriticalSection(true);
+		ExtendedIterator<Triple> it = null;
+		try {
+	        it = graph.find(subject, property, null);
+	        while(it.hasNext()){
+	            nodes.add(it.next().getObject());
+	        }
+		} finally {
+			if(it != null){
+				it.close();
+			}
+			dataset.getLock().leaveCriticalSection();
+		}
+		return nodes;
+	}
+
+	@Override
+	public Collection<Node> listSubjects(Node property, Node object) {
+        Collection<Node> nodes = new ArrayList<Node>();
+		dataset.getLock().enterCriticalSection(true);
+		ExtendedIterator<Triple> it = null;
+		try {
+	        it = graph.find(null, property, object);
+	        while(it.hasNext()){
+	            nodes.add(it.next().getSubject());
+	        }
+		} finally {
+			if(it != null) {
+				it.close();
+			}
+			dataset.getLock().leaveCriticalSection();
+		}
+        return nodes;
+	}
+
+	/* ------------------------------------------------------------------------
+	 * Methods for converting TDB values to Representation Objects
+	 * ------------------------------------------------------------------------
+	 */
+    /**
+     * Processes a {@link Node} and adds the according value to the parsed
+     * Representation.
+     * @param value The node to convert to an value for the Representation
+     * @param source the representation (MUST NOT be <code>null</code>
+     * @param field the field (MUST NOT be <code>null</code>)
+     */
+    private void processValue(Node value, Representation source, String field) {
+        if(value == null){
+            log.warn("Encountered NULL value for field {} and entity {}",
+                    field,source.getId());
+        } else if(value.isURI()){ //add a reference
+            source.addReference(field, value.getURI());
+        } else if(value.isLiteral()){ //add a value or a text depending on the dataType
+            LiteralLabel ll = value.getLiteral();
+//            log.debug("LL: lexical {} | value {} | dataType {} | language {}",
+//                new Object[]{ll.getLexicalForm(),ll.getValue(),ll.getDatatype(),ll.language()});
+            //if the dataType == null , than we can expect a plain literal
+            RDFDatatype dataType = ll.getDatatype();
+            if(dataType != null){ //add a value
+                Object literalValue;
+                try {
+                    literalValue = ll.getValue();
+                    if(literalValue instanceof BaseDatatype.TypedValue){
+                        //used for unknown data types
+                        // -> in such cases just use the lexical type
+                        String lexicalValue = ((BaseDatatype.TypedValue)literalValue).lexicalValue;
+                        if(lexicalValue != null && !lexicalValue.isEmpty()){
+                            source.add(field,lexicalValue);
+                        }
+                    } else if(literalValue instanceof XSDDateTime) {
+                        source.add(field, ((XSDDateTime)literalValue).asCalendar().getTime()); //Entityhub uses the time
+                    } else if(literalValue instanceof XSDDuration) {
+                        String duration = literalValue.toString();
+                        if(duration != null && !duration.isEmpty()) {
+                            source.add(field, literalValue.toString());
+                        }
+                    } else {
+                        source.add(field, literalValue);
+                    }
+                } catch (DatatypeFormatException e) {
+                    log.warn(" Unable to convert {} to {} -> use lecicalForm",
+                        ll.getLexicalForm(),ll.getDatatype());
+                    literalValue = ll.getLexicalForm();
+                }
+            } else { //add a text
+                String lexicalForm = ll.getLexicalForm();
+                if(lexicalForm != null && !lexicalForm.isEmpty()){
+                    String language = ll.language();
+                    if(language!=null && language.length()<1){
+                        language = null;
+                    }
+                    source.addNaturalText(field, lexicalForm, language);
+                } //else ignore empty literals
+            }
+            // "" is parsed if there is no language
+        } else {
+            if(value.isBlank()){
+                log.info("ignoreing blank node value {} for field {} and Resource {}!",
+                        new Object[]{value,field,source.getId()});
+            } else {
+                log.warn("ignoreing value {} for field {} and Resource {} because it is of an unsupported type!",
+                        new Object[]{value,field,source.getId()});
+            }
+        } //end different value node type
+    }
+    /**
+     * Creates Jena {@link Node} instances for {@link Representation} values
+     * @param value the value
+     * @return the Node
+     * TODO: Error Handling
+     */
+	private Node getNode(Object value) {
+		if(value instanceof Reference){
+			return Node.createURI(((Reference)value).getReference());
+		} else if(value instanceof Text){
+			return Node.createLiteral(LiteralLabelFactory.create(
+					((Text)value).getText(), ((Text)value).getLanguage()));
+		} else if(value instanceof Date){
+			//TODO: looks like we can only handle xsd:dateTime ...
+			return Node.createLiteral(
+					TimeUtils.toString(DataTypeEnum.DateTime, (Date)value),
+					null,XSDDatatype.XSDdateTime);
+		} else {//other typed Literal
+			RDFDatatype dataType = typeMapper.getTypeByClass(value.getClass());
+			if(dataType == null){
+				dataType = XSDDatatype.XSDstring;
+			}
+			return Node.createLiteral(value.toString(), null, dataType);
+		}
+	}    
+
+	/* -------------------------------------------------------------------------
+	 * Code for removing Resources following recursively referenced BNodes.
+	 * -------------------------------------------------------------------------
+	 */
+    
+	/**
+	 * Removes the {@link Representation#getId() resource} and also recursively 
+	 * all blank {@link Node}s referenced by outgoing triples. This ensures that
+	 * BNodes added to the graph are also deleted of the {@link Representation}
+	 * is deleted.
+     * <p>
+     * This method assumes a read lock on {@link #graph}
+	 * @param resource
+	 * @return
+	 */
+	private boolean removeResource(Node resource) {
+		ExtendedIterator<Triple> current = graph.find(resource, null, null);
+		Set<Node> bNodes = new HashSet<Node>();
+		boolean contains = current.hasNext();
+		while(current.hasNext()){ //delete current
+		    Node obj = current.removeNext().getObject();
+		    if(obj.isBlank()){
+		    	if(!graph.contains(null, null, obj)){
+		    		bNodes.add(obj);
+		    	} //other resources to refer the same BNode ... do not delete
+		    }
+		}
+		//remove all outgoing references with BNodes as object
+		while(!bNodes.isEmpty()){
+			Iterator<Node> it = bNodes.iterator();
+			boolean modified = false;
+			while(it.hasNext() && //still more BNodes to remove
+					!modified){ // if the bNodes set is modified we need a new Iterator!
+				Node node = it.next();
+				it.remove(); //remove the BNode before processing as afterwards
+				//the Set might already be modified!
+				modified = removeBNode(node,bNodes);
+			}
+		}
+		return contains;
+	}
+	
+	/**
+	 * Removes all triples for the parsed bNode and adds all other
+	 * {@link BNode}s referenced by {@link Triple#getObject()}.<p>
+	 * This allows to recursively remove all BNodes of outgoing triples without
+	 * recursively calling this method
+	 * @param bNode the Node to be removed. It is expected to be a blank node
+	 * @param set other blank {@link Node}s
+	 * @return if the parsed set was modified by this method
+	 */
+	private boolean removeBNode(Node bNode, Set<Node> set){
+		ExtendedIterator<Triple> current = graph.find(bNode, null, null);
+		boolean modified = false;
+		while(current.hasNext()){ //delete current
+		    Node obj = current.removeNext().getObject();
+		    if(obj.isBlank() && !obj.equals(bNode)){
+		    	if(graph.contains(null, null, obj)){
+		    		modified = set.add(obj) || modified;
+		    	} //else ignore because
+		    	// the Bnode of the object is the same as the subject or
+		    	// an other resources to refer the same BNode
+		    }
+		}
+		return modified;
+	}
+}

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/JenaTdbStore.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java Mon Jul 30 08:50:27 2012
@@ -0,0 +1,81 @@
+package org.apache.stanbol.entityhub.store.jenatdb.impl;
+
+import java.io.File;
+
+import com.hp.hpl.jena.graph.Graph;
+import com.hp.hpl.jena.graph.Node;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.sparql.core.DatasetGraph;
+import com.hp.hpl.jena.tdb.TDBFactory;
+import com.hp.hpl.jena.tdb.base.file.Location;
+import com.hp.hpl.jena.tdb.store.DatasetGraphTDB;
+
+public class Utils {
+    /**
+     * @param modelLocation The directory with the Jena TDB model. Will be created
+     * if not existent.
+     * @return
+     * @throws IllegalArgumentException if <code>null</code> is parsed; 
+     * if the parsed {@link File} exists but is not a directory; if the parsed 
+     * File does NOT exists AND can not be created.
+     */
+    public static Dataset initTDBDataset(File modelLocation) {
+        if(modelLocation == null){
+            throw new IllegalArgumentException("The parsed Jena TDB directory" +
+            		"MUST NOT be NULL!");
+        }
+        if(modelLocation.exists() && !modelLocation.isDirectory()){
+            throw new IllegalArgumentException("The configured RDF model directory "+
+                modelLocation+"exists but is not a Directory");
+        } else if(!modelLocation.exists()){
+            if(!modelLocation.mkdirs()){
+                throw new IllegalArgumentException("Unable to create the configured RDF model directory "+
+                    modelLocation+"!");
+            }
+        }
+        Location location = new Location(modelLocation.getAbsolutePath());
+        return TDBFactory.createDataset(location);
+    }
+	/**
+	 * Initializes the {@link Graph} for based on the parsed parameter. If
+	 * namedGraphName is <code>null</code> the default graph of the parsed
+	 * dataset is returned. Otherwise the named graph for the parsed node
+	 * is created/opened. 
+	 * @param dataset
+	 * @param namedGraphNode
+	 * @return
+	 */
+	public static Graph initGraph(Dataset dataset, Node namedGraphNode) {
+		DatasetGraph dsGraph = dataset.asDatasetGraph();
+		if(namedGraphNode != null){
+			if(!dsGraph.containsGraph(namedGraphNode)){
+				dsGraph.addGraph(namedGraphNode, Graph.emptyGraph);
+			}
+			return dsGraph.getGraph(namedGraphNode);
+		} else {
+			return dsGraph.getDefaultGraph();
+		}
+	}
+	/**
+	 * Removes all data from the parsed named graph. IF the parsed namedGraphNode
+	 * is <code>null</code> than all data from the default graph are deleted.
+	 * @param dataset the {@link Dataset}. <p>
+	 * <i>NOTE</i> that Jena API requires to call 'set' with an empty grpah. 
+	 * Therefore the graph instance is being replaced.
+	 * Because of this callers need to replace their current reference to the
+	 * Graph with the one returned by this method. 
+	 * @param namedGraphNode the named graph node or <code>null</code> for the
+	 * default graph
+	 * @return the emptied graph. 
+	 */
+	public static Graph cleanGraph(Dataset dataset, Node namedGraphNode){
+		DatasetGraph dsGraph = dataset.asDatasetGraph();
+		if(namedGraphNode != null){
+			dsGraph.addGraph(namedGraphNode, Graph.emptyGraph);
+			return dsGraph.getGraph(namedGraphNode);
+		} else {
+			dsGraph.setDefaultGraph(Graph.emptyGraph);
+			return dsGraph.getDefaultGraph();
+		}
+	}
+}

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/java/org/apache/stanbol/entityhub/store/jenatdb/impl/Utils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=1367037&view=auto
==============================================================================
--- incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties (added)
+++ incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties Mon Jul 30 08:50:27 2012
@@ -0,0 +1,14 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.

Propchange: incubator/stanbol/branches/contenthub-two-layered-structure/entityhub/store/jenatdb/src/main/resources/OSGI-INF/metatype/metatype.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain