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 2014/01/08 16:25:26 UTC
[10/51] [abbrv] [partial] MARMOTTA-397: Reorganized and renamed
Marmotta Sesame Tools
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/ConcurrentFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/ConcurrentFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/ConcurrentFacadingTest.java
new file mode 100644
index 0000000..241f5f3
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/ConcurrentFacadingTest.java
@@ -0,0 +1,198 @@
+/*
+ * 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.marmotta.commons.sesame.facading.concurrent;
+
+import java.util.ConcurrentModificationException;
+import java.util.UUID;
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.concurrent.model.FooFacade;
+import org.apache.marmotta.commons.sesame.facading.concurrent.model.TypeFacade;
+import org.apache.marmotta.commons.sesame.repository.ResourceUtils;
+import org.apache.marmotta.commons.vocabulary.DCTERMS;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.model.vocabulary.RDF;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+
+public class ConcurrentFacadingTest extends AbstractFacadingTest {
+
+ private URI subject;
+
+ @Before
+ public void init() {
+ subject = repositoryRDF.getValueFactory().createURI("http://example.com/rdf/" + UUID.randomUUID().toString());
+ }
+
+ @Test
+ public void testParallelConnections() throws RepositoryException {
+ final URI type = repositoryRDF.getValueFactory().createURI(DCTERMS.Agent.stringValue()+"#", UUID.randomUUID().toString());
+ final RepositoryConnection cX = repositoryRDF.getConnection(),
+ cO = repositoryRDF.getConnection();
+ try {
+ cX.begin();
+ cO.begin();
+
+ cX.add(subject, RDF.TYPE, type);
+ Assert.assertTrue (cX.hasStatement(subject, RDF.TYPE, type, false));
+ Assert.assertFalse(cO.hasStatement(subject, RDF.TYPE, type, false));
+
+ cX.commit();
+ Assert.assertTrue(cO.hasStatement(subject, RDF.TYPE, type, false));
+
+ cO.commit();
+ } finally {
+ if (cX.isActive()) cX.rollback();
+ if (cO.isActive()) cO.rollback();
+ cX.close();
+ cO.close();
+ }
+ }
+
+ @Test
+ @Ignore("currently fails for H2 database because of transaction locking")
+ public void testParallelFacading() throws RepositoryException {
+ final RepositoryConnection fc = repositoryRDF.getConnection();
+ try {
+ fc.begin();
+ final Facading facading = FacadingFactory.createFacading(fc);
+
+ final FooFacade ff = facading.createFacade(subject, FooFacade.class);
+
+ Assert.assertNull(ff.getString());
+ final String v = UUID.randomUUID().toString();
+ ff.setString(v);
+ Assert.assertEquals(v, ff.getString());
+
+ final RepositoryConnection fc2 = repositoryRDF.getConnection();
+ try {
+ fc2.begin();
+
+ final Facading f2 = FacadingFactory.createFacading(fc2);
+ Assert.assertNull(f2.createFacade(subject, FooFacade.class).getString());
+
+ fc2.commit();
+ } finally {
+ if (fc2.isActive()) fc2.rollback();
+ fc2.close();
+ }
+
+ fc.commit();
+
+ final RepositoryConnection fc3 = repositoryRDF.getConnection();
+ try {
+ fc3.begin();
+
+ final Facading f3 = FacadingFactory.createFacading(fc3);
+ Assert.assertEquals(v, f3.createFacade(subject, FooFacade.class).getString());
+
+ fc3.commit();
+ } finally {
+ if (fc3.isActive()) fc3.rollback();
+ fc3.close();
+ }
+ } finally {
+ if (fc.isActive()) fc.rollback();
+ fc.close();
+ }
+ }
+
+ /**
+ * Test for MARMOTTA-236
+ * @throws RepositoryException
+ */
+ @Test
+ public void testParallelFacadingType() throws RepositoryException {
+ final RepositoryConnection mainCon = repositoryRDF.getConnection();
+ try {
+ mainCon.begin();
+ Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
+
+ final Facading facading = FacadingFactory.createFacading(mainCon);
+ Assert.assertFalse(facading.isFacadeable(subject, TypeFacade.class));
+ Assert.assertFalse(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
+
+
+ final TypeFacade ff = facading.createFacade(subject, TypeFacade.class);
+ Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));
+ Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
+
+ Assert.assertNull(ff.getTitle());
+ final String v = UUID.randomUUID().toString();
+ ff.setTitle(v);
+ Assert.assertEquals(v, ff.getTitle());
+ Assert.assertTrue(ResourceUtils.hasType(mainCon, subject, TypeFacade.TYPE));
+ Assert.assertTrue(facading.isFacadeable(subject, TypeFacade.class));
+
+ { // before-commit
+ final RepositoryConnection subCon_1 = repositoryRDF.getConnection();
+ try {
+ subCon_1.begin();
+ Assert.assertFalse(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));
+
+ final Facading f_1 = FacadingFactory.createFacading(subCon_1);
+ Assert.assertFalse(f_1.isFacadeable(subject, TypeFacade.class));
+
+ final TypeFacade tf_1 = f_1.createFacade(subject, TypeFacade.class);
+ Assert.assertNull(tf_1.getTitle());
+ Assert.assertTrue(f_1.isFacadeable(subject, TypeFacade.class));
+ Assert.assertTrue(ResourceUtils.hasType(subCon_1, subject, TypeFacade.TYPE));
+
+ subCon_1.rollback();
+ } finally {
+ if (subCon_1.isActive()) subCon_1.rollback();
+ subCon_1.close();
+ }
+ }
+
+ mainCon.commit();
+
+ { // after-commit
+ final RepositoryConnection subCon_2 = repositoryRDF.getConnection();
+ try {
+ subCon_2.begin();
+ Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));
+
+ final Facading f_2 = FacadingFactory.createFacading(subCon_2);
+ Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));
+
+ Assert.assertEquals(v, f_2.createFacade(subject, TypeFacade.class).getTitle());
+ Assert.assertTrue(ResourceUtils.hasType(subCon_2, subject, TypeFacade.TYPE));
+ Assert.assertTrue(f_2.isFacadeable(subject, TypeFacade.class));
+
+ subCon_2.commit();
+ } finally {
+ if (subCon_2.isActive()) subCon_2.rollback();
+ subCon_2.close();
+ }
+ }
+ } catch (ConcurrentModificationException ex) {
+ // do nothing, H2 locking
+ } finally {
+ if (mainCon.isActive()) mainCon.rollback();
+ mainCon.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/FooFacade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/FooFacade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/FooFacade.java
new file mode 100644
index 0000000..095f6fe
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/FooFacade.java
@@ -0,0 +1,30 @@
+/*
+ * 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.marmotta.commons.sesame.facading.concurrent.model;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.openrdf.model.vocabulary.DCTERMS;
+
+public interface FooFacade extends Facade {
+
+ @RDF(DCTERMS.NAMESPACE + "string")
+ public void setString(String string);
+ public String getString();
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/TypeFacade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/TypeFacade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/TypeFacade.java
new file mode 100644
index 0000000..d08404a
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/concurrent/model/TypeFacade.java
@@ -0,0 +1,34 @@
+/*
+ * 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.marmotta.commons.sesame.facading.concurrent.model;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFType;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+
+@RDFType(TypeFacade.TYPE)
+public interface TypeFacade extends Facade {
+
+ public static final String TITLE = "http://foo.bar/title";
+ public static final String TYPE = "http://foo.bar/Type";
+
+ @RDF(TITLE)
+ String getTitle();
+ void setTitle(String title);
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/FacadingFoafTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/FacadingFoafTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/FacadingFoafTest.java
new file mode 100644
index 0000000..9d1442e
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/FacadingFoafTest.java
@@ -0,0 +1,273 @@
+/*
+ * 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.marmotta.commons.sesame.facading.foaf;
+
+import static org.hamcrest.CoreMatchers.allOf;
+import static org.hamcrest.CoreMatchers.hasItem;
+import static org.hamcrest.CoreMatchers.hasItems;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.Matchers.hasProperty;
+import static org.junit.Assume.assumeThat;
+
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.foaf.model.OnlineAccount;
+import org.apache.marmotta.commons.sesame.facading.foaf.model.Person;
+import org.apache.marmotta.commons.sesame.model.Namespaces;
+import org.hamcrest.CoreMatchers;
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.Resource;
+import org.openrdf.model.Statement;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.repository.RepositoryResult;
+import org.openrdf.rio.RDFFormat;
+import org.openrdf.rio.RDFParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Test if facading works for the FOAF examples
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class FacadingFoafTest extends AbstractFacadingTest {
+ private static Logger log = LoggerFactory.getLogger(FacadingFoafTest.class);
+
+ @Before
+ public void loadData() throws RepositoryException, IOException, RDFParseException {
+
+ // load demo data
+ InputStream rdfXML = this.getClass().getResourceAsStream("demo-data.foaf");
+ assumeThat("Could not load test-data: demo-data.foaf", rdfXML, notNullValue(InputStream.class));
+
+ RepositoryConnection connectionRDF = repositoryRDF.getConnection();
+ try {
+ connectionRDF.add(rdfXML, "http://localhost/foaf/", RDFFormat.RDFXML);
+ connectionRDF.commit();
+ } finally {
+ connectionRDF.close();
+ }
+ }
+
+ /**
+ * Test if we can access the data contained in a FOAF file via the facading
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testAccessData() throws Exception {
+
+ RepositoryConnection connectionRDF = repositoryRDF.getConnection();
+ try {
+
+ // list all resources contained in the repository and create facades over them
+ Set<Resource> resources = new HashSet<Resource>();
+ RepositoryResult<Statement> triples = connectionRDF.getStatements(null,null,null,true);
+ while(triples.hasNext()) {
+ resources.add(triples.next().getSubject());
+ }
+ triples.close();
+
+ Facading facading = FacadingFactory.createFacading(connectionRDF);
+
+ // test individual resource
+ URI u_hans_meier = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+ URI u_anna_schmidt = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/anna_schmidt");
+ Person hans_meier = facading.createFacade(u_hans_meier,Person.class);
+
+ Assert.assertEquals("Hans Meier",hans_meier.getName());
+ Assert.assertEquals(2,hans_meier.getFriends().size());
+ Assert.assertThat(hans_meier.getOnlineAccounts(),
+ CoreMatchers.<OnlineAccount> hasItem(hasProperty("accountName", is("Example"))));
+
+ Assert.assertThat(hans_meier.getFriends(), allOf(
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Anna Schmidt"))),
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Sepp Huber")))
+ ));
+
+ // test collection
+ Collection<Person> persons = facading.createFacade(resources,Person.class);
+ Assert.assertEquals(3, persons.size());
+ Assert.assertThat(persons,allOf(
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Hans Meier"))),
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Anna Schmidt"))),
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Sepp Huber")))
+ )
+ );
+
+ connectionRDF.commit();
+ } finally {
+ connectionRDF.close();
+ }
+ }
+
+ /**
+ * Test if we can access the data contained in a FOAF file via the facading
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testModifyData() throws Exception {
+ RepositoryConnection connectionRDF = repositoryRDF.getConnection();
+ try {
+ // list all resources contained in the repository and create facades over them
+ Set<Resource> resources = new HashSet<Resource>();
+ RepositoryResult<Statement> triples = connectionRDF.getStatements(null,null,null,true);
+ while(triples.hasNext()) {
+ resources.add(triples.next().getSubject());
+ }
+ triples.close();
+
+ Facading facading = FacadingFactory.createFacading(connectionRDF);
+
+ // test individual resource
+ URI u_hans_meier = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+ Person hans_meier = facading.createFacade(u_hans_meier,Person.class);
+
+ Assert.assertNull(hans_meier.getNick());
+
+ // set nick name and check if it is now set
+ hans_meier.setNick("hansi");
+ Assert.assertNotNull(hans_meier.getNick());
+ Assert.assertEquals("hansi",hans_meier.getNick());
+
+ // check in triple store if the triple is there
+ URI p_foaf_nick = connectionRDF.getValueFactory().createURI(Namespaces.NS_FOAF + "nick");
+ RepositoryResult<Statement> nicknames = connectionRDF.getStatements(u_hans_meier,p_foaf_nick,null,true);
+ Assert.assertTrue(nicknames.hasNext());
+ Assert.assertEquals("hansi",nicknames.next().getObject().stringValue());
+ nicknames.close();
+
+ // test creating a completely new resource
+ URI u_fritz_fischer = connectionRDF.getValueFactory().createURI("http://localhost:8080/LMF/resource/fritz_fischer");
+ Person fritz_fischer = facading.createFacade(u_fritz_fischer,Person.class);
+ fritz_fischer.setName("Fritz Fischer");
+
+ Assert.assertEquals("Fritz Fischer", fritz_fischer.getName());
+
+ // test if it is now there
+ URI p_foaf_name = connectionRDF.getValueFactory().createURI(Namespaces.NS_FOAF + "name");
+ RepositoryResult<Statement> names = connectionRDF.getStatements(u_fritz_fischer,p_foaf_name,null,true);
+ Assert.assertTrue(names.hasNext());
+ Assert.assertEquals("Fritz Fischer",names.next().getObject().stringValue());
+ names.close();
+
+ // test extending a collection
+ Set<Person> hans_friends = hans_meier.getFriends();
+ hans_friends.add(fritz_fischer);
+ hans_meier.setFriends(hans_friends);
+
+ Assert.assertEquals(3,hans_meier.getFriends().size());
+ Assert.assertThat(hans_meier.getFriends(), allOf(
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Anna Schmidt"))),
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Fritz Fischer"))),
+ CoreMatchers.<Person> hasItem(hasProperty("name", is("Sepp Huber")))
+ ));
+
+ Assert.assertTrue(hans_meier.hasFriends());
+
+ connectionRDF.commit();
+ } finally {
+ connectionRDF.close();
+ }
+ }
+
+ @Test
+ public void testReadInverseRDF() throws RepositoryException {
+
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+ try {
+ final Facading facading = FacadingFactory.createFacading(connection);
+
+ URI u_hans_meier = connection.getValueFactory().createURI("http://localhost:8080/LMF/resource/hans_meier");
+ Person hans_meier = facading.createFacade(u_hans_meier, Person.class);
+ Assume.assumeThat("Could not load test-person", hans_meier, notNullValue(Person.class));
+
+ for (OnlineAccount account : hans_meier.getOnlineAccounts()) {
+ Assert.assertNotNull(account);
+ final Resource accountRSC = account.getDelegate();
+ Assert.assertNotNull(accountRSC);
+
+ final OnlineAccount oa = facading.createFacade(accountRSC, OnlineAccount.class);
+ Assert.assertNotNull(oa);
+
+ Assert.assertEquals(hans_meier, oa.getHolder());
+ }
+
+ } finally {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void testWriteInverserRDF() throws RepositoryException {
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+ try {
+ final Facading facading = FacadingFactory.createFacading(connection);
+
+ URI p = connection.getValueFactory().createURI("http://localhost/person");
+ Person person = facading.createFacade(p, Person.class);
+
+ URI a = connection.getValueFactory().createURI("http://localhost/account");
+ OnlineAccount account = facading.createFacade(a, OnlineAccount.class);
+
+ account.setHolder(person);
+
+ connection.commit();
+
+ Assert.assertThat(person.getOnlineAccounts(), CoreMatchers.hasItem(account));
+
+ } finally {
+ connection.close();
+ }
+ }
+
+ @Test
+ public void testAdd() throws RepositoryException {
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+ try {
+ final Facading facading = FacadingFactory.createFacading(connection);
+
+ URI a = connection.getValueFactory().createURI("http://localhost/account");
+ OnlineAccount account = facading.createFacade(a, OnlineAccount.class);
+
+ account.addChatId("foo");
+ Assert.assertThat(account.getChatId(), hasItem("foo"));
+ account.addChatId("bar");
+ Assert.assertThat(account.getChatId(), hasItems("foo", "bar"));
+ Assert.assertThat(account.getChatId(), hasItems("bar", "foo"));
+ } finally {
+ connection.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/OnlineAccount.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/OnlineAccount.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/OnlineAccount.java
new file mode 100644
index 0000000..12cd744
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/OnlineAccount.java
@@ -0,0 +1,61 @@
+/*
+ * 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.marmotta.commons.sesame.facading.foaf.model;
+
+
+
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFInverse;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFType;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.apache.marmotta.commons.sesame.model.Namespaces;
+
+/**
+ * @author Stephanie Stroka
+ * User: Stephanie Stroka
+ * Date: 18.05.2011
+ * Time: 11:29:17
+ */
+@RDFType(Namespaces.NS_FOAF + "OnlineAccount")
+public interface OnlineAccount extends Facade {
+
+ @RDF(Namespaces.NS_FOAF + "accountServiceHomepage")
+ public String getAccountServiceHomepage();
+ public void setAccountServiceHomepage(String accountServiceHomepage);
+
+ @RDF(Namespaces.NS_FOAF + "accountName")
+ public String getAccountName();
+ public void setAccountName(String accountName);
+
+ @RDFInverse(Namespaces.NS_FOAF + "account")
+ public Person getHolder();
+ public void setHolder(Person holder);
+
+ @RDF(Namespaces.NS_FOAF + "chatId")
+ public Set<String> getChatId();
+ public void addChatId(String chatId);
+
+ @RDF("http://www.example.com/rdf/vocab/login")
+ public List<Date> getLoginDate();
+ public void addLoginDate(Date login);
+ public void setLoginDate(List<Date> logins);
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/Person.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/Person.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/Person.java
new file mode 100644
index 0000000..9328f75
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/foaf/model/Person.java
@@ -0,0 +1,68 @@
+/*
+ * 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.marmotta.commons.sesame.facading.foaf.model;
+
+
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFFilter;
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFType;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.apache.marmotta.commons.sesame.model.Namespaces;
+import org.openrdf.model.URI;
+
+import java.util.Set;
+
+/**
+ * Sample facade to describe a foaf:Person
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+@RDFType(Namespaces.NS_FOAF + "Person")
+@RDFFilter(Namespaces.NS_FOAF + "Person")
+public interface Person extends Facade {
+
+ @RDF(Namespaces.NS_FOAF + "nick")
+ public String getNick();
+ public void setNick(String nick);
+
+ /**
+ * The name of the user; mapped to the foaf:name RDF property
+ */
+ @RDF(Namespaces.NS_FOAF + "name")
+ public String getName();
+ public void setName(String firstName);
+
+
+ @RDF(Namespaces.NS_FOAF + "mbox")
+ public String getMbox();
+ public void setMbox(String mbox);
+
+ @RDF(Namespaces.NS_FOAF + "depiction")
+ public URI getDepiciton();
+ public void setDepiction(URI depiction);
+
+ @RDF(Namespaces.NS_FOAF + "account")
+ public Set<OnlineAccount> getOnlineAccounts();
+ public void setOnlineAccounts(Set<OnlineAccount> onlineAccounts);
+
+ @RDF(Namespaces.NS_FOAF + "knows")
+ public Set<Person> getFriends();
+ public void setFriends(Set<Person> friends);
+ public boolean hasFriends();
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/LocaleFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/LocaleFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/LocaleFacadingTest.java
new file mode 100644
index 0000000..6dc860e
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/LocaleFacadingTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.marmotta.commons.sesame.facading.locale;
+
+import java.util.Locale;
+
+import static org.hamcrest.CoreMatchers.anyOf;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.locale.model.LocaleFacade;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+
+public class LocaleFacadingTest extends AbstractFacadingTest {
+
+ @Test
+ public void testWithLocale() throws RepositoryException {
+ final Locale de = Locale.GERMAN, en = Locale.ENGLISH, fr = Locale.FRENCH, none = new Locale("xx", "none");
+
+ final String lbl = "Label",
+ lbl_de = lbl + ": " + de.toString(),
+ lbl_en = lbl + ": " + en.toString(),
+ lbl_fr = lbl + ": " + fr.toString(),
+ lbl_none = lbl + ": " + none.toString();
+
+ final RepositoryConnection connection = repositoryRDF.getConnection();
+ try {
+ connection.begin();
+ final Facading facading = FacadingFactory.createFacading(connection);
+
+ final URI uri = connection.getValueFactory().createURI("http://www.example.com/rdf/test/locale");
+ final LocaleFacade f = facading.createFacade(uri, LocaleFacade.class);
+
+ f.setLabel(lbl);
+ assertEquals(lbl, f.getLabel());
+ assertNull(f.getLabel(none));
+
+ f.setLabel(lbl_de, de);
+ f.setLabel(lbl_en, en);
+ assertEquals(lbl_de, f.getLabel(de));
+ assertEquals(lbl_en, f.getLabel(en));
+ assertNull(f.getLabel(none));
+
+ f.setLabel(null);
+ assertNull(f.getLabel());
+ assertNull(f.getLabel(de));
+ assertNull(f.getLabel(en));
+ assertNull(f.getLabel(fr));
+ assertNull(f.getLabel(none));
+
+ f.setLabel(lbl_de, de);
+ f.setLabel(lbl_en, en);
+ f.setLabel(lbl_fr, fr);
+ f.setLabel(lbl_none, none);
+ assertEquals(lbl_de, f.getLabel(de));
+ assertEquals(lbl_en, f.getLabel(en));
+ assertEquals(lbl_fr, f.getLabel(fr));
+ assertEquals(lbl_none, f.getLabel(none));
+
+ assertThat(f.getLabel(), anyOf(is(lbl_de), is(lbl_en), is(lbl_fr), is(lbl_none)));
+
+ f.deleteLabel(en);
+ assertEquals(lbl_de, f.getLabel(de));
+ assertNull(f.getLabel(en));
+ assertEquals(lbl_fr, f.getLabel(fr));
+ assertEquals(lbl_none, f.getLabel(none));
+
+ f.setLabel(null, fr);
+ assertEquals(lbl_de, f.getLabel(de));
+ assertNull(f.getLabel(en));
+ assertNull(f.getLabel(fr));
+ assertEquals(lbl_none, f.getLabel(none));
+
+ f.setLabel(lbl);
+ assertEquals(lbl, f.getLabel());
+ assertNull(f.getLabel(de));
+ assertNull(f.getLabel(en));
+ assertNull(f.getLabel(fr));
+ assertNull(f.getLabel(none));
+
+ connection.commit();
+ } finally {
+ connection.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/model/LocaleFacade.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/model/LocaleFacade.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/model/LocaleFacade.java
new file mode 100644
index 0000000..953fb02
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/locale/model/LocaleFacade.java
@@ -0,0 +1,37 @@
+/*
+ * 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.marmotta.commons.sesame.facading.locale.model;
+
+
+import java.util.Locale;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDF;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+import org.apache.marmotta.commons.sesame.model.Namespaces;
+
+public interface LocaleFacade extends Facade {
+
+ @RDF(Namespaces.NS_RDFS + "label")
+ public String getLabel();
+ public String getLabel(Locale loc);
+ public void setLabel(String label);
+ public void setLabel(String label, Locale loc);
+ public void deleteLabel();
+ public void deleteLabel(Locale loc);
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java
new file mode 100644
index 0000000..5efc18a
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/BoxedFacadingTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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.marmotta.commons.sesame.facading.primitive;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.primitive.model.Boxed;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+
+public class BoxedFacadingTest extends AbstractFacadingTest {
+
+ private URI subject;
+ private Random random;
+ private RepositoryConnection facadingConnection;
+ private Boxed boxed;
+
+ @Before
+ public void before() throws Exception {
+ subject = repositoryRDF.getValueFactory().createURI("urn:", UUID.randomUUID().toString());
+ random = new Random();
+
+ facadingConnection = repositoryRDF.getConnection();
+ facadingConnection.begin();
+ final Facading factory = FacadingFactory.createFacading(facadingConnection);
+ boxed = factory.createFacade(subject, Boxed.class);
+ }
+
+ @After
+ public void after() throws Exception {
+ if (facadingConnection != null) {
+ if (facadingConnection.isActive()) facadingConnection.rollback();
+ facadingConnection.close();
+ }
+ }
+
+ @Test
+ public void testString() throws RepositoryException {
+ final String string = UUID.randomUUID().toString();
+
+ Assert.assertNull(boxed.getString());
+ boxed.setString(string);
+ Assert.assertEquals(string, boxed.getString());
+ }
+
+ @Test
+ public void testInteger() {
+ final Integer i = new Integer(random.nextInt());
+
+ Assert.assertEquals(new Integer(0), boxed.getInteger());
+ boxed.setInteger(i);
+ Assert.assertEquals(i, boxed.getInteger());
+ }
+
+ @Test
+ public void testLong() {
+ final Long l = new Long(random.nextLong());
+
+ Assert.assertEquals(new Long(0), boxed.getLong());
+ boxed.setLong(l);
+ Assert.assertEquals(l, boxed.getLong());
+ }
+
+ @Test
+ public void testFloat() {
+ final Float f = new Float(random.nextFloat());
+
+ Assert.assertEquals(0f, boxed.getFloat().floatValue(), 10e-9);
+ boxed.setFloat(f);
+ Assert.assertEquals(f, boxed.getFloat().floatValue(), 10e-9);
+ }
+
+ @Test
+ public void testDouble() {
+ final Double d = new Double(random.nextDouble());
+
+ Assert.assertEquals(0d, boxed.getDouble().doubleValue(), 10e-12);
+ boxed.setDouble(d);
+ Assert.assertEquals(d, boxed.getDouble().doubleValue(), 10e-12);
+ }
+
+ @Test
+ public void testCharacter() {
+ final Character c = new Character((char) random.nextInt(255));
+
+ Assert.assertNull(boxed.getCharacter());
+ boxed.setCharacter(c);
+ Assert.assertEquals(c, boxed.getCharacter());
+ }
+
+ @Test
+ public void testByte() {
+ final Byte b = new Byte((byte) random.nextInt(Byte.MAX_VALUE));
+
+ Assert.assertEquals(new Byte((byte)0), boxed.getByte());
+ boxed.setByte(b);
+ Assert.assertEquals(b, boxed.getByte());
+ }
+
+ @Test
+ public void testBoolean() {
+ Assert.assertFalse(boxed.getBoolean());
+ boxed.setBoolean(Boolean.FALSE);
+ Assert.assertFalse(boxed.getBoolean());
+ boxed.setBoolean(Boolean.TRUE);
+ Assert.assertTrue(boxed.getBoolean());
+ }
+
+ @Test
+ public void testLocale() {
+ Assert.assertNull(boxed.getLocale());
+
+ for (Locale l: Locale.getAvailableLocales()) {
+ boxed.setLocale(l);
+ //Assert.assertEquals(l, boxed.getLocale());
+ Assert.assertEquals(l.getDisplayLanguage(), boxed.getLocale().getDisplayLanguage());
+ }
+ }
+
+ @Test
+ public void testGetDate() {
+ /* Dates are stored with seconds-precision */
+ final Date d = new Date(1000*((random.nextLong()%System.currentTimeMillis())/1000));
+
+ Assert.assertNull(boxed.getDate());
+ boxed.setDate(d);
+ Assert.assertEquals(d, boxed.getDate());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/PrimitiveFacadingTest.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/PrimitiveFacadingTest.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/PrimitiveFacadingTest.java
new file mode 100644
index 0000000..1d1d060
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/PrimitiveFacadingTest.java
@@ -0,0 +1,130 @@
+/*
+ * 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.marmotta.commons.sesame.facading.primitive;
+
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.marmotta.commons.sesame.facading.AbstractFacadingTest;
+import org.apache.marmotta.commons.sesame.facading.FacadingFactory;
+import org.apache.marmotta.commons.sesame.facading.api.Facading;
+import org.apache.marmotta.commons.sesame.facading.primitive.model.Primitive;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openrdf.model.URI;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+
+public class PrimitiveFacadingTest extends AbstractFacadingTest {
+
+ private static final int ITERATIONS = 2500;
+
+ private URI subject;
+ private Random random;
+ private RepositoryConnection facadingConnection;
+ private Primitive primitive;
+
+ @Before
+ public void before() throws Exception {
+ subject = repositoryRDF.getValueFactory().createURI("urn:", UUID.randomUUID().toString());
+ random = new Random();
+
+ facadingConnection = repositoryRDF.getConnection();
+ facadingConnection.begin();
+ final Facading factory = FacadingFactory.createFacading(facadingConnection);
+ primitive = factory.createFacade(subject, Primitive.class);
+
+ }
+
+ @After
+ public void after() throws RepositoryException {
+ if (facadingConnection != null) {
+ if (facadingConnection.isActive()) facadingConnection.rollback();
+ facadingConnection.close();
+ }
+ }
+
+ @Test
+ public void testInt() {
+
+ for (int j =0; j < ITERATIONS; j++) {
+ Assert.assertEquals(0, primitive.getInt());
+ }
+ final int i = random.nextInt();
+ primitive.setInt(i);
+ Assert.assertEquals(i, primitive.getInt());
+ }
+
+ @Test
+ public void testByte() {
+ final byte b = (byte) random.nextInt(Byte.MAX_VALUE);
+
+ Assert.assertEquals(0, primitive.getByte());
+ primitive.setByte(b);
+ Assert.assertEquals(b, primitive.getByte());
+ }
+
+ @Test
+ public void testFloat() {
+ final float f = random.nextFloat();
+
+ Assert.assertEquals(0f, primitive.getFloat(), 10e-9);
+ primitive.setFloat(f);
+ Assert.assertEquals(f, primitive.getFloat(), 10e-9);
+ }
+
+ @Test
+ public void testDouble() {
+ final double d = random.nextDouble();
+
+ Assert.assertEquals(0d, primitive.getDouble(), 10e-12);
+ primitive.setDouble(d);
+ Assert.assertEquals(d, primitive.getDouble(), 10e-12);
+ }
+
+ @Test
+ public void testLong() {
+ final long l = random.nextLong();
+
+ Assert.assertEquals(0l, primitive.getLong());
+ primitive.setLong(l);
+ Assert.assertEquals(l, primitive.getLong());
+ }
+
+
+ @Test
+ public void testGetBoolean() {
+ Assert.assertFalse(primitive.getBoolean());
+ primitive.setBoolean(false);
+ Assert.assertFalse(primitive.getBoolean());
+ primitive.setBoolean(true);
+ Assert.assertTrue(primitive.getBoolean());
+ }
+
+ @Test
+ public void testGetChar() {
+ final char c = (char) random.nextInt(255);
+
+ Assert.assertEquals(0, primitive.getChar());
+ primitive.setChar(c);
+ Assert.assertEquals(c, primitive.getChar());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Boxed.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Boxed.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Boxed.java
new file mode 100644
index 0000000..f540689
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Boxed.java
@@ -0,0 +1,51 @@
+/*
+ * 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.marmotta.commons.sesame.facading.primitive.model;
+
+import java.util.Date;
+import java.util.Locale;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFPropertyBuilder;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+
+@RDFPropertyBuilder(PropBuilder.class)
+public interface Boxed extends Facade {
+
+ public Integer getInteger();
+ public void setInteger(Integer integer);
+ public Long getLong();
+ public void setLong(Long l);
+ public Float getFloat();
+ public void setFloat(Float f);
+ public Double getDouble();
+ public void setDouble(Double d);
+ public Character getCharacter();
+ public void setCharacter(Character character);
+ public Byte getByte();
+ public void setByte(Byte b);
+ public Boolean getBoolean();
+ public void setBoolean(Boolean b);
+ public Locale getLocale();
+ public void setLocale(Locale locale);
+ public String getString();
+ public void setString(String string);
+ public Date getDate();
+ public void setDate(Date date);
+
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Primitive.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Primitive.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Primitive.java
new file mode 100644
index 0000000..05647c9
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/Primitive.java
@@ -0,0 +1,47 @@
+/*
+ * 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.marmotta.commons.sesame.facading.primitive.model;
+
+import org.apache.marmotta.commons.sesame.facading.annotations.RDFPropertyBuilder;
+import org.apache.marmotta.commons.sesame.facading.model.Facade;
+
+@RDFPropertyBuilder(PropBuilder.class)
+public interface Primitive extends Facade {
+
+ public int getInt();
+ public void setInt(int i);
+
+ public float getFloat();
+ public void setFloat(float f);
+
+ public double getDouble();
+ public void setDouble(double d);
+
+ public long getLong();
+ public void setLong(long l);
+
+ public boolean getBoolean();
+ public void setBoolean(boolean b);
+
+ public char getChar();
+ public void setChar(char c);
+
+ public byte getByte();
+ public void setByte(byte b);
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/PropBuilder.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/PropBuilder.java b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/PropBuilder.java
new file mode 100644
index 0000000..98bfc3e
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/java/org/apache/marmotta/commons/sesame/facading/primitive/model/PropBuilder.java
@@ -0,0 +1,29 @@
+/*
+ * 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.marmotta.commons.sesame.facading.primitive.model;
+
+import org.apache.marmotta.commons.sesame.facading.model.AbstractNamespacePropBuilder;
+
+public class PropBuilder extends AbstractNamespacePropBuilder {
+
+ @Override
+ protected String getNamespace() {
+ return "http://persistence.text/prop#";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/logback.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/logback.xml b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/logback.xml
new file mode 100644
index 0000000..864df3a
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/logback.xml
@@ -0,0 +1,28 @@
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} %highlight(%level) %cyan(%logger{15}) - %m%n</pattern>
+ </encoder>
+ </appender>
+ <logger name="org.apache.marmotta.commons.sesame.facading.concurrent.model" level="TRACE" />
+ <root level="${root-level:-INFO}">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+</configuration>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/org/apache/marmotta/commons/sesame/facading/demo-data.foaf
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/org/apache/marmotta/commons/sesame/facading/demo-data.foaf b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/org/apache/marmotta/commons/sesame/facading/demo-data.foaf
new file mode 100644
index 0000000..c2d786b
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-facading/src/test/resources/org/apache/marmotta/commons/sesame/facading/demo-data.foaf
@@ -0,0 +1,70 @@
+<!--
+ ~ 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.
+ -->
+
+<rdf:RDF
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/">
+
+ <foaf:Person rdf:about="http://localhost:8080/LMF/resource/hans_meier" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <foaf:name>Hans Meier</foaf:name>
+ <dc:description>Hans Meier is a software engineer living in Salzburg</dc:description>
+ <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.software_engineering"/>
+ <foaf:interest rdf:resource="http://rdf.freebase.com/ns/en.linux"/>
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Java" />
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+ <foaf:based_near rdf:resource="http://sws.geonames.org/2766824/"/>
+ <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/hans_meier.jpg"/>
+
+ <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+ <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt"/>
+
+ <foaf:account>
+ <foaf:OnlineAccount>
+ <foaf:accountName>Example</foaf:accountName>
+ <foaf:accountServiceHomepage>http://www.example.com</foaf:accountServiceHomepage>
+ </foaf:OnlineAccount>
+ </foaf:account>
+ </foaf:Person>
+
+ <foaf:Person rdf:about="http://localhost:8080/LMF/resource/sepp_huber" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <foaf:name>Sepp Huber</foaf:name>
+ <dc:description>Sepp Huber is an alpinist living in Traunstein. He is a good climber, but not as famous as his cousin Alexander Huber.</dc:description>
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Climbing"/>
+ <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+ <foaf:based_near rdf:resource="http://dbpedia.org/resource/Traunstein"/>
+
+ <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+ <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/hans_meier" />
+ </foaf:Person>
+
+ <foaf:Person rdf:about="http://localhost:8080/LMF/resource/anna_schmidt" xmlns:foaf="http://xmlns.com/foaf/0.1/">
+ <foaf:name>Anna Schmidt</foaf:name>
+ <dc:description>Anna Schmidt is working as PR manager for mountaineers coming from Garmisch-Partenkirchen. She likes mountaineering and is also a Linux enthusiast.</dc:description>
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Mountaineering"/>
+ <foaf:interest rdf:resource="http://dbpedia.org/resource/Linux"/>
+ <foaf:interest rdf:resource="http://localhost:8080/LMF/resource/Chess" />
+ <foaf:based_near rdf:resource="http://dbpedia.org/resource/Garmisch-Partenkirchen"/>
+ <foaf:depiction rdf:resource="http://localhost:8080/LMF/resource/anna_schmidt.jpg"/>
+
+ <foaf:knows rdf:resource="http://dbpedia.org/resource/Alexander_Huber" />
+ <foaf:knows rdf:resource="http://localhost:8080/LMF/resource/sepp_huber" />
+ </foaf:Person>
+
+
+</rdf:RDF>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/pom.xml
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/pom.xml b/commons/marmotta-sesame-tools/marmotta-util-filter/pom.xml
new file mode 100644
index 0000000..f35b827
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/pom.xml
@@ -0,0 +1,110 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.marmotta</groupId>
+ <artifactId>marmotta-parent</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <relativePath>../../../parent</relativePath>
+ </parent>
+
+ <artifactId>marmotta-util-filter</artifactId>
+ <name>Marmotta Sesame Tools: Resource Filters</name>
+
+ <description>
+ This module provides generic components for composite resource filtering, e.g. checking if
+ a resource conforms to a certain pattern.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-repository-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-sail-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-repository-sail</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-sail-memory</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.openrdf.sesame</groupId>
+ <artifactId>sesame-rio-rdfxml</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AllOfFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AllOfFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AllOfFilter.java
new file mode 100644
index 0000000..570981d
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AllOfFilter.java
@@ -0,0 +1,62 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A filter combining several filters and requiring that all filters match.
+ * <p/>
+ * Author: Sebastian Schaffert
+ *
+ * @param <T> the type of object to filter
+ */
+public class AllOfFilter<T> implements SesameFilter<T> {
+
+ private Set<SesameFilter<T>> children;
+
+
+ public AllOfFilter(SesameFilter<T>... children) {
+ this(new HashSet<SesameFilter<T>>(Arrays.asList(children)));
+ }
+
+ public AllOfFilter(Set<SesameFilter<T>> children) {
+ this.children = children;
+ }
+
+ /**
+ * Return false in case the filter does not accept the resource passed as argument, true otherwise.
+ *
+ *
+ * @param resource
+ * @return
+ */
+ @Override
+ public boolean accept(T resource) {
+
+ for(SesameFilter<T> filter : children) {
+ if(!filter.accept(resource)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysFalseFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysFalseFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysFalseFilter.java
new file mode 100644
index 0000000..67e5a7a
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysFalseFilter.java
@@ -0,0 +1,39 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+/**
+ * A filter that always returns false.
+ * <p/>
+ * Author: Sebastian Schaffert (sschaffert@apache.org)
+ *
+ * @param <T> the type of object to filter
+ */
+public class AlwaysFalseFilter<T> implements SesameFilter<T> {
+
+ /**
+ * Return false in case the filter does not accept the object passed as argument, true otherwise.
+ *
+ * @param object the object to check
+ * @return true in case the object is accepted, false otherwise
+ */
+ @Override
+ public boolean accept(T object) {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysTrueFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysTrueFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysTrueFilter.java
new file mode 100644
index 0000000..9f8520c
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/AlwaysTrueFilter.java
@@ -0,0 +1,39 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+/**
+ * A filter that accepts everything.
+ * <p/>
+ * Author: Sebastian Schaffert (sschaffert@apache.org)
+ *
+ * @param <T> the type of object to filter
+ */
+public class AlwaysTrueFilter<T> implements SesameFilter<T> {
+
+ /**
+ * Return false in case the filter does not accept the object passed as argument, true otherwise.
+ *
+ * @param object the object to check
+ * @return true in case the object is accepted, false otherwise
+ */
+ @Override
+ public boolean accept(T object) {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/NotFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/NotFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/NotFilter.java
new file mode 100644
index 0000000..08c1a38
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/NotFilter.java
@@ -0,0 +1,43 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+/**
+ * Negates a wrapped filter
+ * <p/>
+ * Author: Sebastian Schaffert (sschaffert@apache.org)
+ */
+public class NotFilter<T> implements SesameFilter<T> {
+
+ SesameFilter<T> wrapped;
+
+ public NotFilter(SesameFilter<T> wrapped) {
+ this.wrapped = wrapped;
+ }
+
+ /**
+ * Return false in case the filter does not accept the resource passed as argument, true otherwise.
+ *
+ * @param resource
+ * @return
+ */
+ @Override
+ public boolean accept(T resource) {
+ return !wrapped.accept(resource);
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/OneOfFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/OneOfFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/OneOfFilter.java
new file mode 100644
index 0000000..9d9a926
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/OneOfFilter.java
@@ -0,0 +1,60 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A filter combining several other filters with a disjunction, i.e. it is sufficient that one of the other filters
+ * matches.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class OneOfFilter<T> implements SesameFilter<T> {
+
+ private Set<SesameFilter<T>> children;
+
+
+ public OneOfFilter(SesameFilter<T>... children) {
+ this(new HashSet<SesameFilter<T>>(Arrays.asList(children)));
+ }
+
+ public OneOfFilter(Set<SesameFilter<T>> children) {
+ this.children = children;
+ }
+
+ /**
+ * Return false in case the filter does not accept the resource passed as argument, true otherwise.
+ *
+ *
+ * @param resource
+ * @return
+ */
+ @Override
+ public boolean accept(T resource) {
+ for(SesameFilter<T> filter : children) {
+ if(filter.accept(resource)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/SesameFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/SesameFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/SesameFilter.java
new file mode 100644
index 0000000..09b24af
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/SesameFilter.java
@@ -0,0 +1,36 @@
+/**
+ * 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.marmotta.commons.sesame.filter;
+
+/**
+ * Generic superinterface for all filters. Only defines an accept() method.
+ * <p/>
+ * Author: Sebastian Schaffert (sschaffert@apache.org)
+ */
+public interface SesameFilter<T> {
+
+ /**
+ * Return false in case the filter does not accept the object passed as argument, true otherwise.
+ *
+ *
+ * @param object the object to check
+ * @return true in case the object is accepted, false otherwise
+ */
+ public boolean accept(T object);
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/ResourceFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/ResourceFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/ResourceFilter.java
new file mode 100644
index 0000000..eacadcf
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/ResourceFilter.java
@@ -0,0 +1,34 @@
+/**
+ * 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.marmotta.commons.sesame.filter.resource;
+
+import org.apache.marmotta.commons.sesame.filter.SesameFilter;
+import org.openrdf.model.Resource;
+
+/**
+ * A common interface for enhancement filters on resources. Specifies a single method, "accept", which should
+ * return false in case the filter does not accept the resource passed as argument.
+ * <p/>
+ * Note that enhancement filters should only implement methods that are not expensive to compute, since they will be
+ * evaluated when the transaction commits and before adding a resource to the enhancement queue.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public interface ResourceFilter extends SesameFilter<Resource> {
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/00c22e7c/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/UriPrefixFilter.java
----------------------------------------------------------------------
diff --git a/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/UriPrefixFilter.java b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/UriPrefixFilter.java
new file mode 100644
index 0000000..fb54a8d
--- /dev/null
+++ b/commons/marmotta-sesame-tools/marmotta-util-filter/src/main/java/org/apache/marmotta/commons/sesame/filter/resource/UriPrefixFilter.java
@@ -0,0 +1,74 @@
+/**
+ * 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.marmotta.commons.sesame.filter.resource;
+
+import org.openrdf.model.Resource;
+import org.openrdf.model.URI;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * A filter only accepting resources starting with a given prefix.
+ * <p/>
+ * Author: Sebastian Schaffert
+ */
+public class UriPrefixFilter implements ResourceFilter {
+
+
+ private Set<String> prefixes;
+
+ public UriPrefixFilter(String... prefixes) {
+ this(new HashSet<String>(Arrays.asList(prefixes)));
+ }
+
+ public UriPrefixFilter(Set<String> prefixes) {
+ this.prefixes = prefixes;
+ }
+
+ public Set<String> getPrefixes() {
+ return prefixes;
+ }
+
+ /**
+ * Return false in case the filter does not accept the resource passed as argument, true otherwise.
+ *
+ *
+ * @param resource
+ * @return
+ */
+ @Override
+ public boolean accept(Resource resource) {
+ if(! (resource instanceof URI)) {
+ return false;
+ }
+
+ URI uri = (URI) resource;
+
+ for(String prefix : prefixes) {
+ if(uri.stringValue().startsWith(prefix)) {
+ return true;
+ }
+ }
+
+
+ return false;
+ }
+
+}