You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@clerezza.apache.org by re...@apache.org on 2015/03/19 15:53:45 UTC
[1/3] clerezza git commit: CLEREZZA-961: using rdf-commons from
clerezza-rdf-core repository
Repository: clerezza
Updated Branches:
refs/heads/rdf-commons 9ae0a1bc9 -> e5531d964
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactory.java
new file mode 100644
index 0000000..2799379
--- /dev/null
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactory.java
@@ -0,0 +1,313 @@
+/*
+ * 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.clerezza.rdf.core.impl.util;
+
+import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
+import java.math.BigInteger;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.clerezza.rdf.core.InvalidLiteralTypeException;
+import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.clerezza.rdf.core.NoConvertorException;
+import org.apache.commons.rdf.Iri;
+import org.apache.clerezza.rdf.core.impl.util.Base64;
+import org.apache.clerezza.rdf.core.impl.util.W3CDateFormat;
+import org.apache.commons.rdf.Literal;
+
+/**
+ * An implementation of literal factory currently supporting only
+ * byte[]/base64Binary and Java.util.Date/date
+ *
+ * @author reto
+ */
+
+public class SimpleLiteralFactory extends LiteralFactory {
+
+ private static final String XSD = "http://www.w3.org/2001/XMLSchema#";
+ final private static Iri xsdInteger = xsd("integer");
+ final private static Iri xsdInt = xsd("int");
+ final private static Iri xsdShort = xsd("short");
+ final private static Iri xsdByte = xsd("byte");
+ final private static Iri xsdLong = xsd("long");
+
+
+ final private static Set<Iri> decimalTypes = new HashSet<Iri>();
+
+ final private static Map<Class<?>, TypeConverter<?>> typeConverterMap = new HashMap<Class<?>, TypeConverter<?>>();
+ final static Class<? extends byte[]> byteArrayType;
+
+ static {
+ Collections.addAll(decimalTypes, xsdInteger, xsdInt, xsdByte, xsdShort, xsdLong );
+
+ byte[] byteArray = new byte[0];
+ byteArrayType = byteArray.getClass();
+ typeConverterMap.put(byteArrayType, new ByteArrayConverter());
+ typeConverterMap.put(Date.class, new DateConverter());
+ typeConverterMap.put(Boolean.class, new BooleanConverter());
+ typeConverterMap.put(String.class, new StringConverter());
+ typeConverterMap.put(Integer.class, new IntegerConverter());
+ typeConverterMap.put(BigInteger.class, new BigIntegerConverter());
+ typeConverterMap.put(Long.class, new LongConverter());
+ typeConverterMap.put(Double.class, new DoubleConverter());
+ typeConverterMap.put(Float.class, new FloatConverter());
+ typeConverterMap.put(Iri.class, new UriRefConverter());
+ }
+
+ final private static Iri xsdDouble =xsd("double");
+ final private static Iri xsdFloat =xsd("float");
+ final private static Iri xsdAnyURI =xsd("anyURI");
+
+ final private static Iri xsd(String name) {
+ return new Iri(XSD+name);
+ }
+
+ private static interface TypeConverter<T> {
+ Literal createLiteral(T value);
+ T createObject(Literal literal);
+ }
+
+ private static class ByteArrayConverter implements TypeConverter<byte[]> {
+
+ private static final Iri base64Uri =xsd("base64Binary");
+
+ @Override
+ public Literal createLiteral(byte[] value) {
+ return new TypedLiteralImpl(Base64.encode((byte[]) value), base64Uri);
+ }
+
+ @Override
+ public byte[] createObject(Literal literal) {
+ if (!literal.getDataType().equals(base64Uri)) {
+ throw new InvalidLiteralTypeException(byteArrayType, literal.getDataType());
+ }
+ return (byte[])Base64.decode(literal.getLexicalForm());
+ }
+
+
+ }
+ private static class DateConverter implements TypeConverter<Date> {
+
+ private static final Iri dateTimeUri =xsd("dateTime");
+ private static final DateFormat DATE_FORMAT = new W3CDateFormat();
+
+ @Override
+ public Literal createLiteral(Date value) {
+ return new TypedLiteralImpl(DATE_FORMAT.format(value), dateTimeUri);
+ }
+
+ @Override
+ public Date createObject(Literal literal) {
+ if (!literal.getDataType().equals(dateTimeUri)) {
+ throw new InvalidLiteralTypeException(Date.class, literal.getDataType());
+ }
+ try {
+ return DATE_FORMAT.parse(literal.getLexicalForm());
+ } catch (ParseException ex) {
+ throw new RuntimeException("Exception parsing literal as date", ex);
+ }
+ }
+
+
+ }
+
+ private static class BooleanConverter implements TypeConverter<Boolean> {
+
+ private static final Iri booleanUri =xsd("boolean");
+ public static final TypedLiteralImpl TRUE = new TypedLiteralImpl("true", booleanUri);
+ public static final TypedLiteralImpl FALSE = new TypedLiteralImpl("false", booleanUri);
+
+ @Override
+ public Literal createLiteral(Boolean value) {
+ if (value) return TRUE;
+ else return FALSE;
+ }
+
+ @Override
+ public Boolean createObject(Literal literal) {
+ if (literal == TRUE) return true;
+ else if (literal == FALSE) return false;
+ else if (!literal.getDataType().equals(booleanUri)) {
+ throw new InvalidLiteralTypeException(Boolean.class, literal.getDataType());
+ }
+ return Boolean.valueOf(literal.getLexicalForm());
+ }
+ }
+
+ private static class StringConverter implements TypeConverter<String> {
+
+ private static final Iri stringUri =xsd("string");
+
+ @Override
+ public Literal createLiteral(String value) {
+ return new TypedLiteralImpl(value, stringUri);
+ }
+
+ @Override
+ public String createObject(Literal literal) {
+ if (!literal.getDataType().equals(stringUri)) {
+ throw new InvalidLiteralTypeException(String.class, literal.getDataType());
+ }
+ return literal.getLexicalForm();
+ }
+ }
+
+ private static class IntegerConverter implements TypeConverter<Integer> {
+
+
+ @Override
+ public Literal createLiteral(Integer value) {
+ return new TypedLiteralImpl(value.toString(), xsdInt);
+ }
+
+ @Override
+ public Integer createObject(Literal literal) {
+ if (!decimalTypes.contains(literal.getDataType())) {
+ throw new InvalidLiteralTypeException(Integer.class, literal.getDataType());
+ }
+ return new Integer(literal.getLexicalForm());
+ }
+ }
+
+ private static class LongConverter implements TypeConverter<Long> {
+
+
+
+ @Override
+ public Literal createLiteral(Long value) {
+ return new TypedLiteralImpl(value.toString(), xsdLong);
+ }
+
+ @Override
+ public Long createObject(Literal literal) {
+ if (!decimalTypes.contains(literal.getDataType())) {
+ throw new InvalidLiteralTypeException(Long.class, literal.getDataType());
+ }
+ return new Long(literal.getLexicalForm());
+ }
+ }
+
+
+ private static class FloatConverter implements TypeConverter<Float> {
+
+ @Override
+ public Literal createLiteral(Float value) {
+ return new TypedLiteralImpl(value.toString(), xsdFloat);
+ }
+
+ @Override
+ public Float createObject(Literal literal) {
+ if (!literal.getDataType().equals(xsdFloat)) {
+ throw new InvalidLiteralTypeException(Float.class, literal.getDataType());
+ }
+ return Float.valueOf(literal.getLexicalForm());
+ }
+ }
+
+ private static class DoubleConverter implements TypeConverter<Double> {
+
+
+
+ @Override
+ public Literal createLiteral(Double value) {
+ return new TypedLiteralImpl(value.toString(), xsdDouble);
+ }
+
+ @Override
+ public Double createObject(Literal literal) {
+ if (!literal.getDataType().equals(xsdDouble)) {
+ throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
+ }
+ return new Double(literal.getLexicalForm());
+ }
+ }
+
+ private static class BigIntegerConverter implements TypeConverter<BigInteger> {
+
+
+
+ @Override
+ public Literal createLiteral(BigInteger value) {
+ return new TypedLiteralImpl(value.toString(), xsdInteger);
+ }
+
+ @Override
+ public BigInteger createObject(Literal literal) {
+ if (!literal.getDataType().equals(xsdInteger)) {
+ throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
+ }
+ return new BigInteger(literal.getLexicalForm());
+ }
+ }
+
+ private static class UriRefConverter implements TypeConverter<Iri> {
+
+
+
+ @Override
+ public Literal createLiteral(Iri value) {
+ return new TypedLiteralImpl(value.getUnicodeString(), xsdAnyURI);
+ }
+
+ @Override
+ public Iri createObject(Literal literal) {
+ if (!literal.getDataType().equals(xsdAnyURI)) {
+ throw new InvalidLiteralTypeException(Iri.class, literal.getDataType());
+ }
+ return new Iri(literal.getLexicalForm());
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Literal createTypedLiteral(Object value) throws NoConvertorException {
+ TypeConverter converter = getConverterFor(value.getClass());
+ return converter.createLiteral(value);
+ }
+
+
+
+ @Override
+ public <T> T createObject(Class<T> type, Literal literal)
+ throws NoConvertorException, InvalidLiteralTypeException {
+ final TypeConverter<T> converter = getConverterFor(type);
+ return converter.createObject(literal);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> TypeConverter<T> getConverterFor(Class<T> type) throws NoConvertorException {
+ TypeConverter<T> convertor = (TypeConverter<T>) typeConverterMap.get(type);
+ if (convertor != null) {
+ return convertor;
+ }
+ for (Map.Entry<Class<?>, TypeConverter<?>> converterEntry : typeConverterMap.entrySet()) {
+ if (type.isAssignableFrom(converterEntry.getKey())) {
+ return (TypeConverter<T>) converterEntry.getValue();
+ }
+ }
+ throw new NoConvertorException(type);
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/serializedform/Parser.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/serializedform/Parser.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/serializedform/Parser.java
index d7ef8a8..944fd5d 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/serializedform/Parser.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/serializedform/Parser.java
@@ -35,7 +35,7 @@ import java.util.logging.Level;
import org.apache.commons.rdf.ImmutableGraph;
import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj b/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj
index c56f87c..db5ad01 100644
--- a/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj
+++ b/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedQueryParser.jj
@@ -45,8 +45,8 @@ import org.apache.commons.rdf.Literal;
import org.apache.commons.rdf.RdfTerm;
import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
import org.apache.clerezza.rdf.core.sparql.query.GroupGraphPattern;
import org.apache.clerezza.rdf.core.sparql.query.BinaryOperation;
import org.apache.clerezza.rdf.core.sparql.query.Variable;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj b/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
index e881782..1064cb8 100644
--- a/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
+++ b/rdf.core/src/main/javacc/org/apache/clerezza/rdf/core/sparql/JavaCCGeneratedSparqlPreParser.jj
@@ -44,8 +44,8 @@ import org.apache.commons.rdf.Literal;
import org.apache.commons.rdf.RdfTerm;
import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TypedLiteralImpl;
import org.apache.clerezza.rdf.core.sparql.query.AlternativeGraphPattern;
import org.apache.clerezza.rdf.core.sparql.query.BinaryOperation;
import org.apache.clerezza.rdf.core.sparql.query.BinaryPropertyPathOperation;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
index 42c297c..deb0baf 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/SecurityTest.java
@@ -40,8 +40,8 @@ import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.providers.WeightedA;
import org.apache.clerezza.rdf.core.access.providers.WeightedDummy;
import org.apache.clerezza.rdf.core.access.security.TcPermission;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
/**
*
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
index a4ae80a..59ce257 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/TcManagerTest.java
@@ -32,8 +32,8 @@ import org.apache.clerezza.rdf.core.access.providers.WeightedA;
import org.apache.clerezza.rdf.core.access.providers.WeightedA1;
import org.apache.clerezza.rdf.core.access.providers.WeightedAHeavy;
import org.apache.clerezza.rdf.core.access.providers.WeightedBlight;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.rdf.core.sparql.NoQueryEngineException;
import org.apache.clerezza.rdf.core.sparql.QueryEngine;
import org.apache.clerezza.rdf.core.sparql.query.AskQuery;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
index 2e804fb..f61bd44 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA.java
@@ -29,8 +29,8 @@ import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
import org.apache.clerezza.rdf.core.access.TcManagerTest;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
/**
*
@@ -57,7 +57,7 @@ public class WeightedA implements WeightedTcProvider {
@Override
public Graph getMGraph(Iri name) throws NoSuchEntityException {
- throw new UnsupportedOperationException("Not supported yet.");
+ throw new NoSuchEntityException(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
index f280178..4a9bcf2 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedA1.java
@@ -29,8 +29,8 @@ import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
import org.apache.clerezza.rdf.core.access.TcManagerTest;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
/**
* Same weight as WeightedA, but later in string-ordering
@@ -58,7 +58,7 @@ public class WeightedA1 implements WeightedTcProvider {
@Override
public Graph getMGraph(Iri name) throws NoSuchEntityException {
- throw new UnsupportedOperationException("Not supported yet.");
+ throw new NoSuchEntityException(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
index d5f0ae5..82307ad 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedAHeavy.java
@@ -30,8 +30,9 @@ import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
import org.apache.clerezza.rdf.core.access.TcManagerTest;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
/**
*
@@ -47,7 +48,7 @@ public class WeightedAHeavy implements WeightedTcProvider {
@Override
public ImmutableGraph getGraph(Iri name) throws NoSuchEntityException {
if (name.equals(TcManagerTest.uriRefA)) {
- Graph mResult = new SimpleMGraph();
+ Graph mResult = new SimpleGraph();
mResult.add(new TripleImpl(TcManagerTest.uriRefAHeavy,
TcManagerTest.uriRefAHeavy, TcManagerTest.uriRefAHeavy));
return mResult.getImmutableGraph();
@@ -57,7 +58,7 @@ public class WeightedAHeavy implements WeightedTcProvider {
@Override
public Graph getMGraph(Iri name) throws NoSuchEntityException {
- throw new UnsupportedOperationException("Not supported yet.");
+ throw new NoSuchEntityException(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
index b0e3192..c5023d8 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedBlight.java
@@ -29,8 +29,8 @@ import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
import org.apache.clerezza.rdf.core.access.TcManagerTest;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
/**
*
@@ -60,7 +60,7 @@ public class WeightedBlight implements WeightedTcProvider {
@Override
public Graph getMGraph(Iri name) throws NoSuchEntityException {
- throw new UnsupportedOperationException("Not supported yet.");
+ throw new NoSuchEntityException(name);
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
index cc9bd88..183d1f7 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/access/providers/WeightedDummy.java
@@ -31,8 +31,8 @@ import org.apache.clerezza.rdf.core.access.EntityAlreadyExistsException;
import org.apache.clerezza.rdf.core.access.EntityUndeletableException;
import org.apache.clerezza.rdf.core.access.NoSuchEntityException;
import org.apache.clerezza.rdf.core.access.WeightedTcProvider;
-import org.apache.clerezza.rdf.core.impl.SimpleImmutableGraph;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
+import org.apache.commons.rdf.impl.utils.simple.SimpleMGraph;
/**
*
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/events/NotificationTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/events/NotificationTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/events/NotificationTest.java
deleted file mode 100644
index 09a25e8..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/events/NotificationTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.clerezza.rdf.core.events;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.junit.Assert;
-import org.junit.Test;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.event.FilterTriple;
-import org.apache.commons.rdf.event.GraphEvent;
-import org.apache.commons.rdf.event.GraphListener;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-
-/**
- *
- * @author reto
- */
-public class NotificationTest {
- @Test public void getEventsTogether() throws Exception {
- final Graph tc = new SimpleMGraph();
- final List<List<GraphEvent>> eventChunks = new ArrayList<List<GraphEvent>>();
- GraphListener myGraphListener = new GraphListener() {
- @Override
- public void graphChanged(List<GraphEvent> events) {
- eventChunks.add(events);
- //the following causes an event to be added to events
- //(the List we already got)! This is because it doesn't wait
- //on a synhronized(this) as we are already in an evnet dispatch
- //thread
- //tc.add(generateTriple());
- }
- };
- tc.addGraphListener(myGraphListener, new FilterTriple(null, null, null),
- 500);
- for (int i = 0; i < 100; i++) {
- tc.add(generateTriple());
- }
- Thread.sleep(600);
- Assert.assertEquals(1, eventChunks.size());
- Assert.assertEquals(100, eventChunks.get(0).size());
- tc.add(generateTriple());
- Thread.sleep(600);
- Assert.assertEquals(2, eventChunks.size());
- Assert.assertEquals(1, eventChunks.get(1).size());
- }
-
-
- @Test public void synchroneousEvents() throws Exception {
- final Graph tc = new SimpleMGraph();
- final List<List<GraphEvent>> eventChunks = new ArrayList<List<GraphEvent>>();
- GraphListener myGraphListener = new GraphListener() {
- @Override
- public void graphChanged(List<GraphEvent> events) {
- eventChunks.add(events);
- }
- };
- tc.addGraphListener(myGraphListener, new FilterTriple(null, null, null),
- 0);
- for (int i = 0; i < 100; i++) {
- tc.add(generateTriple());
- }
- Assert.assertEquals(100, eventChunks.size());
- Assert.assertEquals(1, eventChunks.get(97).size());
- tc.add(generateTriple());
- Assert.assertEquals(101, eventChunks.size());
- Assert.assertEquals(1, eventChunks.get(100).size());
- }
-
- private static Triple generateTriple() {
- return new TripleImpl(generateRandomUriRef(), generateRandomUriRef(),
- generateRandomUriRef());
- }
-
- private static Iri generateRandomUriRef() {
- return new Iri("http://example.org/"+Math.random());
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImplTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImplTest.java
deleted file mode 100644
index 381503b..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImplTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import org.junit.Test;
-import junit.framework.Assert;
-
-import org.apache.commons.rdf.Language;
-import org.apache.commons.rdf.Literal;
-/**
- *
- * @author reto
- *
- */
-
-public class PlainLiteralImplTest {
-
-
- @Test public void plainLiteralEquality() {
- String stringValue = "some text";
- Literal literal1 = new PlainLiteralImpl(stringValue);
- Literal literal2 = new PlainLiteralImpl(stringValue);
- Assert.assertEquals(literal1, literal2);
- Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
- Literal literal3 = new PlainLiteralImpl("something else");
- Assert.assertFalse(literal1.equals(literal3));
- }
-
- @Test public void languageLiteralEquality() {
- String stringValue = "some text";
- Language lang = new Language("en-ca");
- Literal literal1 = new PlainLiteralImpl(stringValue, lang);
- Literal literal2 = new PlainLiteralImpl(stringValue, lang);
- Assert.assertEquals(literal1, literal2);
- Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
- Language lang2 = new Language("de");
- Literal literal3 = new PlainLiteralImpl(stringValue, lang2);
- Assert.assertFalse(literal1.equals(literal3));
- Literal literal4 = new PlainLiteralImpl(stringValue, null);
- Assert.assertFalse(literal3.equals(literal4));
- Assert.assertFalse(literal4.equals(literal3));
- }
-
- /**
- * hashCode of the lexical form plus the hashCode of the locale
- */
- @Test public void checkHashCode() {
- String stringValue = "some text";
- Language language = new Language("en");
- Literal literal = new PlainLiteralImpl(stringValue, language);
- Assert.assertEquals(stringValue.hashCode() + language.hashCode(), literal.hashCode());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleGraphTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleGraphTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleGraphTest.java
deleted file mode 100644
index b4f5aa4..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleGraphTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import org.junit.Assert;
-import org.junit.Test;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-
-/**
- *
- * @author mir
- */
-public class SimpleGraphTest {
-
- private Iri uriRef1 = new Iri("http://example.org/foo");
- private Iri uriRef2 = new Iri("http://example.org/bar");
- private Iri uriRef3 = new Iri("http://example.org/test");
- private Triple triple1 = new TripleImpl(uriRef1, uriRef2, uriRef3);
- private Triple triple2 = new TripleImpl(uriRef2, uriRef2, uriRef1);
- private Triple triple3 = new TripleImpl(uriRef3, uriRef1, uriRef3);
- private Triple triple4 = new TripleImpl(uriRef1, uriRef3, uriRef2);
- private Triple triple5 = new TripleImpl(uriRef2, uriRef3, uriRef2);
-
- @Test
- public void iteratorRemove() {
- SimpleGraph stc = new SimpleGraph();
- stc.add(triple1);
- stc.add(triple2);
- stc.add(triple3);
- stc.add(triple4);
- stc.add(triple5);
- Iterator<Triple> iter = stc.iterator();
- while (iter.hasNext()) {
- Triple triple = iter.next();
- iter.remove();
- }
- Assert.assertEquals(0, stc.size());
- }
-
- @Test
- public void removeAll() {
- SimpleGraph stc = new SimpleGraph();
- stc.add(triple1);
- stc.add(triple2);
- stc.add(triple3);
- stc.add(triple4);
- stc.add(triple5);
- SimpleGraph stc2 = new SimpleGraph();
- stc2.add(triple1);
- stc2.add(triple3);
- stc2.add(triple5);
- stc.removeAll(stc2);
- Assert.assertEquals(2, stc.size());
- }
-
- @Test
- public void filterIteratorRemove() {
- SimpleGraph stc = new SimpleGraph();
- stc.add(triple1);
- stc.add(triple2);
- stc.add(triple3);
- stc.add(triple4);
- stc.add(triple5);
- Iterator<Triple> iter = stc.filter(uriRef1, null, null);
- while (iter.hasNext()) {
- Triple triple = iter.next();
- iter.remove();
- }
- Assert.assertEquals(3, stc.size());
- }
-
- @Test(expected=ConcurrentModificationException.class)
- public void remove() {
- SimpleGraph stc = new SimpleGraph();
- stc.setCheckConcurrency(true);
- stc.add(triple1);
- stc.add(triple2);
- stc.add(triple3);
- stc.add(triple4);
- stc.add(triple5);
- Iterator<Triple> iter = stc.filter(uriRef1, null, null);
- while (iter.hasNext()) {
- Triple triple = iter.next();
- stc.remove(triple);
- }
- Assert.assertEquals(3, stc.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactoryTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactoryTest.java
deleted file mode 100644
index 17e25ed..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactoryTest.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import junit.framework.Assert;
-import org.apache.commons.rdf.Literal;
-import org.apache.commons.rdf.Iri;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class SimpleLiteralFactoryTest {
-
- final private static Iri xsdInteger =
- new Iri("http://www.w3.org/2001/XMLSchema#integer");
- final private static Iri xsdInt =
- new Iri("http://www.w3.org/2001/XMLSchema#int");
- final private static Iri xsdLong =
- new Iri("http://www.w3.org/2001/XMLSchema#long");
-
- SimpleLiteralFactory simpleLiteralFactory = new SimpleLiteralFactory();
-
- @Test
- public void longToXsdIntegerAndBackToMany() {
- long value = 14l;
- Literal tl = simpleLiteralFactory.createTypedLiteral(value);
- Assert.assertEquals(xsdLong, tl.getDataType());
- long longValue = simpleLiteralFactory.createObject(Long.class, tl);
- Assert.assertEquals(value, longValue);
- int intValue = simpleLiteralFactory.createObject(Integer.class, tl);
- Assert.assertEquals(value, intValue);
- }
-
- @Test
- public void intToXsdIntAndBackToMany() {
- int value = 14;
- Literal tl = simpleLiteralFactory.createTypedLiteral(value);
- Assert.assertEquals(xsdInt, tl.getDataType());
- long longValue = simpleLiteralFactory.createObject(Long.class, tl);
- Assert.assertEquals(value, longValue);
- int intValue = simpleLiteralFactory.createObject(Integer.class, tl);
- Assert.assertEquals(value, intValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TripleImplTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TripleImplTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TripleImplTest.java
deleted file mode 100644
index b127702..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TripleImplTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-
-package org.apache.clerezza.rdf.core.impl;
-/*
- *
- * 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.
- *
-*/
-
-
-import org.junit.Test;
-import junit.framework.Assert;
-
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-/**
- *
- * @author reto
- *
- */
-
-public class TripleImplTest {
-
-
- @Test public void tripleEquality() {
- BlankNodeOrIri subject = new Iri("http://example.org/");
- Iri predicate = new Iri("http://example.org/property");
- RdfTerm object = new PlainLiteralImpl("property value");
- Triple triple1 = new TripleImpl(subject, predicate, object);
- Triple triple2 = new TripleImpl(subject, predicate, object);
- Assert.assertEquals(triple1.hashCode(), triple2.hashCode());
- Assert.assertEquals(triple1, triple2);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImplTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImplTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImplTest.java
deleted file mode 100644
index 9a3dbed..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImplTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import org.junit.Test;
-import junit.framework.Assert;
-
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.Literal;
-/**
- *
- * @author reto/**
- *
- * @author reto/**
- *
- * @author reto/**
- *
- * @author reto
- *
- */
-
-public class TypedLiteralImplTest {
-
-
- @Test public void typedLiteralEquality() {
- String stringValue = "some text";
- Iri uriRef = new Iri("http://example.org/datatypes/magic");
- Literal literal1 = new TypedLiteralImpl(stringValue, uriRef);
- Literal literal2 = new TypedLiteralImpl(stringValue, uriRef);
- Assert.assertEquals(literal1, literal2);
- Assert.assertEquals(literal1.hashCode(), literal2.hashCode());
- Literal literal3 = new TypedLiteralImpl("something else", uriRef);
- Assert.assertFalse(literal1.equals(literal3));
- Iri uriRef2 = new Iri("http://example.org/datatypes/other");
- Literal literal4 = new TypedLiteralImpl(stringValue, uriRef2);
- Assert.assertFalse(literal1.equals(literal4));
- }
-
-
- /**
- * The hascode is equals to the hascode of the lexical form plus the hashcode of the dataTyp
- */
- @Test public void checkHashCode() {
- String stringValue = "some text";
- Iri uriRef = new Iri("http://example.org/datatypes/magic");
- Literal literal = new TypedLiteralImpl(stringValue, uriRef);
- Assert.assertEquals(stringValue.hashCode() + uriRef.hashCode(), literal.hashCode());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcherTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcherTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcherTest.java
deleted file mode 100644
index 5c7248d..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcherTest.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-import java.util.Map;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class GraphMatcherTest {
-
- final static Iri u1 = new Iri("http://example.org/u1");
-
- @Test
- public void testEmpty() {
- Graph tc1 = new SimpleMGraph();
- Graph tc2 = new SimpleMGraph();
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(0, mapping.size());
- }
-
- @Test
- public void test2() {
- Graph tc1 = new SimpleMGraph();
- tc1.add(new TripleImpl(u1, u1, u1));
- Graph tc2 = new SimpleMGraph();
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNull(mapping);
- }
-
- @Test
- public void test3() {
- Graph tc1 = new SimpleMGraph();
- tc1.add(new TripleImpl(u1, u1, u1));
- Graph tc2 = new SimpleMGraph();
- tc2.add(new TripleImpl(u1, u1, u1));
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(0, mapping.size());
- }
-
- @Test
- public void test4() {
- Graph tc1 = new SimpleMGraph();
- tc1.add(new TripleImpl(u1, u1, new BlankNode()));
- Graph tc2 = new SimpleMGraph();
- tc2.add(new TripleImpl(u1, u1, new BlankNode()));
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(1, mapping.size());
- }
-
- @Test
- public void test5() {
- Graph tc1 = new SimpleMGraph();
- tc1.add(new TripleImpl(new BlankNode(), u1, new BlankNode()));
- Graph tc2 = new SimpleMGraph();
- tc2.add(new TripleImpl(new BlankNode(), u1, new BlankNode()));
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(2, mapping.size());
- }
-
- @Test
- public void test6() {
- Graph tc1 = new SimpleMGraph();
- final BlankNode b11 = new BlankNode();
- tc1.add(new TripleImpl(new BlankNode(), u1,b11));
- tc1.add(new TripleImpl(new BlankNode(), u1,b11));
- Graph tc2 = new SimpleMGraph();
- tc2.add(new TripleImpl(new BlankNode(), u1, new BlankNode()));
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNull(mapping);
- }
-
- private Graph generateCircle(int size) {
- return generateCircle(size, new BlankNode());
- }
-
- private Graph generateCircle(int size, final BlankNodeOrIri firstNode) {
- if (size < 1) {
- throw new IllegalArgumentException();
- }
- Graph result = new SimpleMGraph();
- BlankNodeOrIri lastNode = firstNode;
- for (int i = 0; i < (size-1); i++) {
- final BlankNode newNode = new BlankNode();
- result.add(new TripleImpl(lastNode, u1, newNode));
- lastNode = newNode;
- }
- result.add(new TripleImpl(lastNode, u1, firstNode));
- return result;
- }
-
- @Test
- public void test7() {
- Graph tc1 = generateCircle(2);
- Graph tc2 = generateCircle(2);
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(2, mapping.size());
- }
-
- @Test
- public void test8() {
- Graph tc1 = generateCircle(5);
- Graph tc2 = generateCircle(5);
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(5, mapping.size());
- }
-
- @Test
- public void test9() {
- BlankNodeOrIri crossing = new Iri("http://example.org/");
- Graph tc1 = generateCircle(2,crossing);
- tc1.addAll(generateCircle(3,crossing));
- Graph tc2 = generateCircle(2,crossing);
- tc2.addAll(generateCircle(3,crossing));
- Assert.assertEquals(5, tc1.size());
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- //a circle of 2 with 1 bnode and one of 2 bnodes
- Assert.assertEquals(3, mapping.size());
- }
-
- @Test
- public void test10() {
- BlankNodeOrIri crossing1 = new BlankNode();
- Graph tc1 = generateCircle(2,crossing1);
- tc1.addAll(generateCircle(3,crossing1));
- BlankNodeOrIri crossing2 = new BlankNode();
- Graph tc2 = generateCircle(2,crossing2);
- tc2.addAll(generateCircle(3,crossing2));
- Assert.assertEquals(5, tc1.size());
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- //a circle of 2 and one of 3 with one common node
- Assert.assertEquals(4, mapping.size());
- }
-
- @Test
- public void test11() {
- BlankNodeOrIri crossing1 = new BlankNode();
- Graph tc1 = generateCircle(2,crossing1);
- tc1.addAll(generateCircle(4,crossing1));
- BlankNodeOrIri crossing2 = new BlankNode();
- Graph tc2 = generateCircle(3,crossing2);
- tc2.addAll(generateCircle(3,crossing2));
- Assert.assertEquals(6, tc1.size());
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNull(mapping);
- }
-
- @Test
- public void test12() {
- BlankNodeOrIri start1 = new BlankNode();
- Graph tc1 = Utils4Testing.generateLine(4,start1);
- tc1.addAll(Utils4Testing.generateLine(5,start1));
- BlankNodeOrIri start2 = new BlankNode();
- Graph tc2 = Utils4Testing.generateLine(5,start2);
- tc2.addAll(Utils4Testing.generateLine(4,start2));
- Assert.assertEquals(9, tc1.size());
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNotNull(mapping);
- Assert.assertEquals(10, mapping.size());
- }
-
- @Test
- public void test13() {
- BlankNodeOrIri start1 = new BlankNode();
- Graph tc1 = Utils4Testing.generateLine(4,start1);
- tc1.addAll(Utils4Testing.generateLine(5,start1));
- BlankNodeOrIri start2 = new BlankNode();
- Graph tc2 = Utils4Testing.generateLine(3,start2);
- tc2.addAll(Utils4Testing.generateLine(3,start2));
- Assert.assertEquals(9, tc1.size());
- final Map<BlankNode, BlankNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
- Assert.assertNull(mapping);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatchingTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatchingTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatchingTest.java
deleted file mode 100644
index 075d38b..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatchingTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-import java.util.Map;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class HashMatchingTest {
-
- @Test
- public void twoLine() throws GraphNotIsomorphicException {
- BlankNodeOrIri start1 = new BlankNode();
- Graph tc1 = Utils4Testing.generateLine(4,start1);
- tc1.addAll(Utils4Testing.generateLine(5,start1));
- BlankNodeOrIri start2 = new BlankNode();
- Graph tc2 = Utils4Testing.generateLine(5,start2);
- tc2.addAll(Utils4Testing.generateLine(4,start2));
- Assert.assertEquals(9, tc1.size());
- final Map<BlankNode, BlankNode> mapping = new HashMatching(tc1, tc2).getMatchings();
- Assert.assertNotNull(mapping);
- Assert.assertEquals(10, mapping.size());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIteratorTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIteratorTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIteratorTest.java
deleted file mode 100644
index db6cf71..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIteratorTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- * @author reto
- */
-public class PermutationIteratorTest {
-
- @Test
- public void simple() {
- List<String> list = new ArrayList<String>();
- PermutationIterator<String> pi = new PermutationIterator<String>(list);
- Assert.assertFalse(pi.hasNext());
- }
-
- @Test
- public void lessSimple() {
- List<String> list = new ArrayList<String>();
- list.add("Hasan");
- PermutationIterator<String> pi = new PermutationIterator<String>(list);
- Assert.assertTrue(pi.hasNext());
- }
-
- @Test
- public void regular() {
- List<String> list = new ArrayList<String>();
- list.add("Hasan");
- list.add("Tsuy");
- PermutationIterator<String> pi = new PermutationIterator<String>(list);
- Set<List<String>> permutations = new HashSet<List<String>>();
- while (pi.hasNext()) {
- permutations.add(pi.next());
- }
- Assert.assertEquals(2, permutations.size());
- }
-
- @Test
- public void extended() {
- List<String> list = new ArrayList<String>();
- list.add("Hasan");
- list.add("Tsuy");
- list.add("Llena");
- PermutationIterator<String> pi = new PermutationIterator<String>(list);
- Set<List<String>> permutations = new HashSet<List<String>>();
- while (pi.hasNext()) {
- permutations.add(pi.next());
- }
- Assert.assertEquals(6, permutations.size());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils4Testing.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils4Testing.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils4Testing.java
deleted file mode 100644
index d5ef512..0000000
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils4Testing.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-
-/**
- *
- * @author reto
- */
-public class Utils4Testing {
-
- static Graph generateLine(int size, final BlankNodeOrIri firstNode) {
- if (size < 1) {
- throw new IllegalArgumentException();
- }
- Graph result = new SimpleMGraph();
- BlankNodeOrIri lastNode = firstNode;
- for (int i = 0; i < size; i++) {
- final BlankNode newNode = new BlankNode();
- result.add(new TripleImpl(lastNode, u1, newNode));
- lastNode = newNode;
- }
- return result;
- }
-
- final static Iri u1 = new Iri("http://example.org/u1");
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactoryTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactoryTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactoryTest.java
new file mode 100644
index 0000000..886648b
--- /dev/null
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/impl/util/SimpleLiteralFactoryTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.clerezza.rdf.core.impl.util;
+
+import junit.framework.Assert;
+import org.apache.clerezza.rdf.core.impl.util.SimpleLiteralFactory;
+import org.apache.commons.rdf.Literal;
+import org.apache.commons.rdf.Iri;
+import org.junit.Test;
+
+/**
+ *
+ * @author reto
+ */
+public class SimpleLiteralFactoryTest {
+
+ final private static Iri xsdInteger =
+ new Iri("http://www.w3.org/2001/XMLSchema#integer");
+ final private static Iri xsdInt =
+ new Iri("http://www.w3.org/2001/XMLSchema#int");
+ final private static Iri xsdLong =
+ new Iri("http://www.w3.org/2001/XMLSchema#long");
+
+ SimpleLiteralFactory simpleLiteralFactory = new SimpleLiteralFactory();
+
+ @Test
+ public void longToXsdIntegerAndBackToMany() {
+ long value = 14l;
+ Literal tl = simpleLiteralFactory.createTypedLiteral(value);
+ Assert.assertEquals(xsdLong, tl.getDataType());
+ long longValue = simpleLiteralFactory.createObject(Long.class, tl);
+ Assert.assertEquals(value, longValue);
+ int intValue = simpleLiteralFactory.createObject(Integer.class, tl);
+ Assert.assertEquals(value, intValue);
+ }
+
+ @Test
+ public void intToXsdIntAndBackToMany() {
+ int value = 14;
+ Literal tl = simpleLiteralFactory.createTypedLiteral(value);
+ Assert.assertEquals(xsdInt, tl.getDataType());
+ long longValue = simpleLiteralFactory.createObject(Long.class, tl);
+ Assert.assertEquals(value, longValue);
+ int intValue = simpleLiteralFactory.createObject(Integer.class, tl);
+ Assert.assertEquals(value, intValue);
+ }
+}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java
index 0c30926..a923f8a 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QueryParserTest.java
@@ -25,7 +25,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.apache.commons.rdf.Language;
import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.commons.rdf.impl.utils.PlainLiteralImpl;
import org.apache.clerezza.rdf.core.sparql.query.AskQuery;
import org.apache.clerezza.rdf.core.sparql.query.BasicGraphPattern;
import org.apache.clerezza.rdf.core.sparql.query.BuiltInCall;
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java
index e536493..d088dc1 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/QuerySerializerTest.java
@@ -43,6 +43,7 @@ import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleOrderCondition;
import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleSelectQuery;
import org.apache.clerezza.rdf.core.sparql.query.impl.SimpleTriplePattern;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
/**
@@ -149,6 +150,11 @@ public class QuerySerializerTest {
.replaceAll("( |\n)+", " ").trim().equals(queryString));
}
+ /**
+ * Ignoring: given that triplePatterns is a Set I don't see what is supposed
+ * to guarantee the expected ordering.
+ */
+ @Ignore
@Test
public void testFilter() {
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
index c03c2d0..490d296 100644
--- a/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
+++ b/rdf.core/src/test/java/org/apache/clerezza/rdf/core/sparql/SparqlPreParserTest.java
@@ -31,9 +31,9 @@ import org.junit.Test;
*/
public class SparqlPreParserTest {
- private final static Iri DEFAULT_GRAPH = new Iri("http://example.org/default.ImmutableGraph");
- private final static Iri NAMED_GRAPH = new Iri("http://example.org/dummy.ImmutableGraph");
- private final static Iri TEST_GRAPH = new Iri("http://example.org/test.ImmutableGraph");
+ private final static Iri DEFAULT_GRAPH = new Iri("http://example.org/default.graph");
+ private final static Iri NAMED_GRAPH = new Iri("http://example.org/dummy.graph");
+ private final static Iri TEST_GRAPH = new Iri("http://example.org/test.graph");
class MyTcManager extends TcManager {
@Override
@@ -65,7 +65,7 @@ public class SparqlPreParserTest {
public void testAllGraphReferenceInSelectQuery() throws ParseException {
StringBuilder queryStrBuilder = new StringBuilder();
- queryStrBuilder.append("SELECT DISTINCT ?g { ImmutableGraph ?g { ?s ?p ?o } }\n");
+ queryStrBuilder.append("SELECT DISTINCT ?g { GRAPH ?g { ?s ?p ?o } }\n");
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -116,7 +116,7 @@ public class SparqlPreParserTest {
@Test
public void testLoadingToGraph() throws ParseException {
- String queryStr = "LOAD SILENT <http://example.org/mydata> INTO ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "LOAD SILENT <http://example.org/mydata> INTO GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -149,7 +149,7 @@ public class SparqlPreParserTest {
@Test
public void testClearingGraph() throws ParseException {
- String queryStr = "CLEAR SILENT ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "CLEAR SILENT GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -182,7 +182,7 @@ public class SparqlPreParserTest {
@Test
public void testDroppingGraph() throws ParseException {
- String queryStr = "DROP SILENT ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "DROP SILENT GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -193,7 +193,7 @@ public class SparqlPreParserTest {
@Test
public void testCreatingGraph() throws ParseException {
- String queryStr = "CREATE SILENT ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "CREATE SILENT GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -204,7 +204,7 @@ public class SparqlPreParserTest {
@Test
public void testAddingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
- String queryStr = "ADD SILENT DEFAULT TO ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "ADD SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -218,7 +218,7 @@ public class SparqlPreParserTest {
@Test
public void testAddingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
- String queryStr = "ADD SILENT ImmutableGraph " + TEST_GRAPH.toString() + " TO DEFAULT";
+ String queryStr = "ADD SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -232,7 +232,7 @@ public class SparqlPreParserTest {
@Test
public void testMovingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
- String queryStr = "MOVE SILENT DEFAULT TO ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "MOVE SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -246,7 +246,7 @@ public class SparqlPreParserTest {
@Test
public void testMovingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
- String queryStr = "MOVE SILENT ImmutableGraph " + TEST_GRAPH.toString() + " TO DEFAULT";
+ String queryStr = "MOVE SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -260,7 +260,7 @@ public class SparqlPreParserTest {
@Test
public void testCopyingTriplesFromDefaultGraphToNamedGraph() throws ParseException {
- String queryStr = "COPY SILENT DEFAULT TO ImmutableGraph " + TEST_GRAPH.toString();
+ String queryStr = "COPY SILENT DEFAULT TO GRAPH " + TEST_GRAPH.toString();
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -274,7 +274,7 @@ public class SparqlPreParserTest {
@Test
public void testCopyingTriplesFromNamedGraphToDefaultGraph() throws ParseException {
- String queryStr = "COPY SILENT ImmutableGraph " + TEST_GRAPH.toString() + " TO DEFAULT";
+ String queryStr = "COPY SILENT GRAPH " + TEST_GRAPH.toString() + " TO DEFAULT";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -301,7 +301,7 @@ public class SparqlPreParserTest {
public void testInsertDataToNamedGraph() throws ParseException {
String queryStr = "PREFIX ns: <http://example.org/ns#>\n" +
- "INSERT DATA { ImmutableGraph " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
+ "INSERT DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
Set<Iri> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
@@ -324,7 +324,7 @@ public class SparqlPreParserTest {
public void testDeleteDataInNamedGraph() throws ParseException {
String queryStr = "PREFIX ns: <http://example.org/ns#>\n" +
- "DELETE DATA { ImmutableGraph " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
+ "DELETE DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
Set<Iri> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
@@ -336,7 +336,7 @@ public class SparqlPreParserTest {
String queryStr = "PREFIX ns: <http://example.org/ns#> " +
"INSERT DATA { <http://example/book1> ns:price 42 }; " +
- "DELETE DATA { ImmutableGraph " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
+ "DELETE DATA { GRAPH " + TEST_GRAPH.toString() + " { <http://example/book1> ns:price 42 } }";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
Set<Iri> referredGraphs = parser.getReferredGraphs(queryStr, DEFAULT_GRAPH);
@@ -364,8 +364,8 @@ public class SparqlPreParserTest {
public void testDeleteWhereInNamedGraphs() throws ParseException {
String queryStr = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> DELETE WHERE " +
- "{ ImmutableGraph <http://example.com/names> { ?person foaf:givenName 'Fred' ; ?property1 ?value1 } " +
- " ImmutableGraph <http://example.com/addresses> { ?person ?property2 ?value2 } }";
+ "{ GRAPH <http://example.com/names> { ?person foaf:givenName 'Fred' ; ?property1 ?value1 } " +
+ " GRAPH <http://example.com/addresses> { ?person ?property2 ?value2 } }";
SparqlPreParser parser;
parser = new SparqlPreParser(TcManager.getInstance());
@@ -404,8 +404,8 @@ public class SparqlPreParserTest {
@Test
public void testInsertOperationToNamedGraph() throws ParseException {
String queryStr = "PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> " +
- "INSERT { ImmutableGraph <http://example/bookStore2> { ?book ?p ?v } } " +
- "WHERE { ImmutableGraph <http://example/bookStore> { ?book dc:date ?date . " +
+ "INSERT { GRAPH <http://example/bookStore2> { ?book ?p ?v } } " +
+ "WHERE { GRAPH <http://example/bookStore> { ?book dc:date ?date . " +
"FILTER ( ?date > \"1970-01-01T00:00:00-02:00\"^^xsd:dateTime ) ?book ?p ?v } }";
SparqlPreParser parser;
@@ -424,9 +424,9 @@ public class SparqlPreParserTest {
"PREFIX dcmitype: <http://purl.org/dc/dcmitype/>\n" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n" +
"INSERT\n" +
- " { ImmutableGraph <http://example/bookStore2> { ?book ?p ?v } }\n" +
+ " { GRAPH <http://example/bookStore2> { ?book ?p ?v } }\n" +
"WHERE\n" +
- " { ImmutableGraph <http://example/bookStore>\n" +
+ " { GRAPH <http://example/bookStore>\n" +
" { ?book dc:date ?date . \n" +
" FILTER ( ?date < \"2000-01-01T00:00:00-02:00\"^^xsd:dateTime )\n" +
" ?book ?p ?v\n" +
[3/3] clerezza git commit: CLEREZZA-961: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
CLEREZZA-961: using rdf-commons from clerezza-rdf-core repository
Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/e5531d96
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/e5531d96
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/e5531d96
Branch: refs/heads/rdf-commons
Commit: e5531d9645632eff5b0ee897828ae6b57e3fbf9f
Parents: 9ae0a1b
Author: Reto Gmuer <re...@apache.org>
Authored: Thu Mar 19 14:52:41 2015 +0000
Committer: Reto Gmuer <re...@apache.org>
Committed: Thu Mar 19 14:52:41 2015 +0000
----------------------------------------------------------------------
rdf.core/pom.xml | 9 +-
.../clerezza/rdf/core/LiteralFactory.java | 2 +-
.../access/ImmutableGraphServiceFactory.java | 3 +-
.../rdf/core/access/LockableMGraph.java | 41 --
.../rdf/core/access/LockableMGraphWrapper.java | 274 --------------
.../rdf/core/access/LockingIterator.java | 73 ----
.../rdf/core/access/MGraphServiceFactory.java | 2 +-
.../clerezza/rdf/core/access/SecuredGraph.java | 25 +-
.../clerezza/rdf/core/access/SecuredMGraph.java | 72 ----
.../clerezza/rdf/core/access/TcManager.java | 19 +-
.../rdf/core/access/TcProviderMultiplexer.java | 56 ++-
.../rdf/core/access/debug/ReadLockDebug.java | 85 -----
.../debug/ReentrantReadWriteLockTracker.java | 133 -------
.../rdf/core/access/debug/WriteLockDebug.java | 89 -----
.../access/security/TcAccessController.java | 22 +-
.../clerezza/rdf/core/impl/AbstractGraph.java | 251 ------------
.../rdf/core/impl/AbstractImmutableGraph.java | 112 ------
.../clerezza/rdf/core/impl/AbstractMGraph.java | 36 --
.../rdf/core/impl/DelayedNotificator.java | 112 ------
.../rdf/core/impl/PlainLiteralImpl.java | 103 -----
.../clerezza/rdf/core/impl/SimpleGraph.java | 220 -----------
.../rdf/core/impl/SimpleImmutableGraph.java | 78 ----
.../rdf/core/impl/SimpleLiteralFactory.java | 312 ---------------
.../clerezza/rdf/core/impl/SimpleMGraph.java | 55 ---
.../clerezza/rdf/core/impl/TripleImpl.java | 100 -----
.../rdf/core/impl/TypedLiteralImpl.java | 97 -----
.../rdf/core/impl/WriteBlockedGraph.java | 24 +-
.../rdf/core/impl/WriteBlockedMGraph.java | 52 ---
.../core/impl/graphmatching/GraphMatcher.java | 143 -------
.../GraphNotIsomorphicException.java | 28 --
.../graphmatching/GroupMappingIterator.java | 102 -----
.../core/impl/graphmatching/HashMatching.java | 268 -------------
.../impl/graphmatching/MappingIterator.java | 76 ----
.../impl/graphmatching/PermutationIterator.java | 107 ------
.../rdf/core/impl/graphmatching/Utils.java | 82 ----
.../graphmatching/collections/IntHashMap.java | 377 -------------------
.../graphmatching/collections/IntHashSet.java | 62 ---
.../graphmatching/collections/IntIterator.java | 30 --
.../impl/graphmatching/collections/IntSet.java | 35 --
.../core/impl/util/PrivilegedGraphWrapper.java | 17 +-
.../core/impl/util/SimpleLiteralFactory.java | 313 +++++++++++++++
.../rdf/core/serializedform/Parser.java | 2 +-
.../core/sparql/JavaCCGeneratedQueryParser.jj | 4 +-
.../sparql/JavaCCGeneratedSparqlPreParser.jj | 4 +-
.../clerezza/rdf/core/access/SecurityTest.java | 4 +-
.../clerezza/rdf/core/access/TcManagerTest.java | 4 +-
.../rdf/core/access/providers/WeightedA.java | 6 +-
.../rdf/core/access/providers/WeightedA1.java | 6 +-
.../core/access/providers/WeightedAHeavy.java | 9 +-
.../core/access/providers/WeightedBlight.java | 6 +-
.../core/access/providers/WeightedDummy.java | 4 +-
.../rdf/core/events/NotificationTest.java | 99 -----
.../rdf/core/impl/PlainLiteralImplTest.java | 70 ----
.../clerezza/rdf/core/impl/SimpleGraphTest.java | 107 ------
.../rdf/core/impl/SimpleLiteralFactoryTest.java | 62 ---
.../clerezza/rdf/core/impl/TripleImplTest.java | 57 ---
.../rdf/core/impl/TypedLiteralImplTest.java | 66 ----
.../impl/graphmatching/GraphMatcherTest.java | 210 -----------
.../impl/graphmatching/HashMatchingTest.java | 50 ---
.../graphmatching/PermutationIteratorTest.java | 77 ----
.../core/impl/graphmatching/Utils4Testing.java | 51 ---
.../impl/util/SimpleLiteralFactoryTest.java | 63 ++++
.../rdf/core/sparql/QueryParserTest.java | 2 +-
.../rdf/core/sparql/QuerySerializerTest.java | 6 +
.../rdf/core/sparql/SparqlPreParserTest.java | 46 +--
65 files changed, 498 insertions(+), 4614 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/pom.xml
----------------------------------------------------------------------
diff --git a/rdf.core/pom.xml b/rdf.core/pom.xml
index f150df9..134f93f 100644
--- a/rdf.core/pom.xml
+++ b/rdf.core/pom.xml
@@ -33,8 +33,13 @@
<description>Interfaces and utilities to access RDF Graphs</description>
<dependencies>
<dependency>
- <groupId>commons-rdf</groupId>
- <artifactId>commons-rdf</artifactId>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-api</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.clerezza.commons-rdf</groupId>
+ <artifactId>commons-rdf-impl-utils</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/LiteralFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/LiteralFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/LiteralFactory.java
index a7c6104..fafb854 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/LiteralFactory.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/LiteralFactory.java
@@ -18,7 +18,7 @@
*/
package org.apache.clerezza.rdf.core;
-import org.apache.clerezza.rdf.core.impl.SimpleLiteralFactory;
+import org.apache.clerezza.rdf.core.impl.util.SimpleLiteralFactory;
import org.apache.commons.rdf.Literal;
/**
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
index 23ba3f2..900c8d8 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/ImmutableGraphServiceFactory.java
@@ -24,7 +24,6 @@ import org.osgi.framework.ServiceRegistration;
import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.security.TcAccessController;
-import org.apache.clerezza.rdf.core.impl.SimpleImmutableGraph;
/**
* @see <a href="http://www.osgi.org/javadoc/r4v41/org/osgi/framework/ServiceFactory.html">
@@ -50,7 +49,7 @@ public class ImmutableGraphServiceFactory implements ServiceFactory {
Graph tc =
new SecuredGraph(tcManager.getGraph(name), name,
tcAccessController);
- return new SimpleImmutableGraph(tc);
+ return tc.getImmutableGraph();
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraph.java
deleted file mode 100644
index 64b6fdf..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraph.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access;
-
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.Graph;
-
-/**
- *
- * Represents an <code>Graph</code> that can be locked for reading/writing.
- *
- * @author rbn
- */
-public interface LockableMGraph extends Graph {
-
- /**
- * The lock provided by this methods allows to create read- and write-locks
- * that span individual method calls. Having a read locks prevents other
- * threads from writing to this Graph, having a write-lock prevents other
- * threads from reading and writing.
- *
- * @return the lock of this Graph
- */
- ReadWriteLock getLock();
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraphWrapper.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraphWrapper.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraphWrapper.java
deleted file mode 100644
index 59d97fa..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockableMGraphWrapper.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.access.debug.ReentrantReadWriteLockTracker;
-import org.apache.commons.rdf.event.FilterTriple;
-import org.apache.commons.rdf.event.GraphListener;
-
-/**
- * Wrappes an Graph as a LockableMGraph, this class is used by TcManager to
- * support TcProviders that do not privide <code>LockableMGraph</code>.
- *
- * @author rbn
- */
-public class LockableMGraphWrapper implements LockableMGraph {
-
- private static final String DEBUG_MODE = "rdfLocksDebugging";
- private final ReadWriteLock lock;
-
- private final Lock readLock;
- private final Lock writeLock;
- private final Graph wrapped;
-
- /**
- * Constructs a LocalbleMGraph for an Graph.
- *
- * @param providedMGraph a non-lockable graph
- */
- public LockableMGraphWrapper(final Graph providedMGraph) {
- this.wrapped = providedMGraph;
- {
- String debugMode = System.getProperty(DEBUG_MODE);
- if (debugMode != null && debugMode.toLowerCase().equals("true")) {
- lock = new ReentrantReadWriteLockTracker();
- } else {
- lock = new ReentrantReadWriteLock();
- }
- }
- readLock = lock.readLock();
- writeLock = lock.writeLock();
- }
-
- public LockableMGraphWrapper(final Graph providedMGraph, final ReadWriteLock lock) {
- this.wrapped = providedMGraph;
- this.lock = lock;
- readLock = lock.readLock();
- writeLock = lock.writeLock();
- }
-
- @Override
- public ReadWriteLock getLock() {
- return lock;
- }
-
- @Override
- public ImmutableGraph getImmutableGraph() {
- readLock.lock();
- try {
- return wrapped.getImmutableGraph();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
- readLock.lock();
- try {
- return new LockingIterator(wrapped.filter(subject, predicate, object), lock);
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public int size() {
- readLock.lock();
- try {
- return wrapped.size();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public boolean isEmpty() {
- readLock.lock();
- try {
- return wrapped.isEmpty();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- @SuppressWarnings("element-type-mismatch")
- public boolean contains(Object o) {
- readLock.lock();
- try {
- return wrapped.contains(o);
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public Iterator<Triple> iterator() {
- readLock.lock();
- try {
- return new LockingIterator(wrapped.iterator(), lock);
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public Object[] toArray() {
- readLock.lock();
- try {
- return wrapped.toArray();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public <T> T[] toArray(T[] a) {
- readLock.lock();
- try {
- return wrapped.toArray(a);
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public boolean containsAll(Collection<?> c) {
- readLock.lock();
- try {
- return wrapped.containsAll(c);
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public boolean add(Triple e) {
- writeLock.lock();
- try {
- return wrapped.add(e);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean remove(Object o) {
- writeLock.lock();
- try {
- return wrapped.remove(o);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean addAll(Collection<? extends Triple> c) {
- writeLock.lock();
- try {
- return wrapped.addAll(c);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- writeLock.lock();
- try {
- return wrapped.removeAll(c);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean retainAll(Collection<?> c) {
- writeLock.lock();
- try {
- return wrapped.retainAll(c);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public void clear() {
- writeLock.lock();
- try {
- wrapped.clear();
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- wrapped.addGraphListener(listener, filter, delay);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- wrapped.addGraphListener(listener, filter);
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- wrapped.removeGraphListener(listener);
- }
-
- @Override
- public int hashCode() {
- return wrapped.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (obj == this) {
- return true;
- }
- if (obj.getClass() != getClass()) {
- return false;
- }
-
- LockableMGraphWrapper other = (LockableMGraphWrapper) obj;
- return wrapped.equals(other.wrapped);
- }
-
- @Override
- public String toString() {
- return wrapped.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockingIterator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockingIterator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockingIterator.java
deleted file mode 100644
index defb966..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/LockingIterator.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access;
-
-import java.util.Iterator;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.Triple;
-
-/**
- * Wrapps an iterator<Triple> reading entering a read-lock on every invocation
- * of hasNext and next
- * @author reto
- */
-class LockingIterator implements Iterator<Triple> {
-
- private Iterator<Triple> base;
- private Lock readLock;
- private Lock writeLock;
-
- public LockingIterator(Iterator<Triple> iterator, ReadWriteLock lock) {
- base = iterator;
- readLock = lock.readLock();
- writeLock = lock.writeLock();
- }
-
- @Override
- public boolean hasNext() {
- readLock.lock();
- try {
- return base.hasNext();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public Triple next() {
- readLock.lock();
- try {
- return base.next();
- } finally {
- readLock.unlock();
- }
- }
-
- @Override
- public void remove() {
- writeLock.lock();
- try {
- base.remove();
- } finally {
- writeLock.unlock();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/MGraphServiceFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/MGraphServiceFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/MGraphServiceFactory.java
index 7774177..a231733 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/MGraphServiceFactory.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/MGraphServiceFactory.java
@@ -45,7 +45,7 @@ public class MGraphServiceFactory implements ServiceFactory {
@Override
public Object getService(Bundle arg0, ServiceRegistration arg1) {
- return new SecuredMGraph(tcManager.getMGraph(name), name, tcAccessController);
+ return new SecuredGraph(tcManager.getMGraph(name), name, tcAccessController);
}
@Override
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredGraph.java
index 3c35497..8620563 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredGraph.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredGraph.java
@@ -20,14 +20,16 @@ package org.apache.clerezza.rdf.core.access;
import java.util.Collection;
import java.util.Iterator;
+import java.util.concurrent.locks.ReadWriteLock;
import org.apache.commons.rdf.BlankNodeOrIri;
import org.apache.commons.rdf.RdfTerm;
import org.apache.commons.rdf.Triple;
import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.security.TcAccessController;
-import org.apache.clerezza.rdf.core.impl.SimpleImmutableGraph;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
import org.apache.commons.rdf.ImmutableGraph;
+import org.apache.commons.rdf.WatchableGraph;
import org.apache.commons.rdf.event.FilterTriple;
import org.apache.commons.rdf.event.GraphListener;
@@ -150,22 +152,6 @@ public class SecuredGraph implements Graph {
return wrapped.contains((Triple) o);
}
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- checkRead();
- wrapped.addGraphListener(listener, filter, delay);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- checkRead();
- wrapped.addGraphListener(listener, filter);
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- wrapped.removeGraphListener(listener);
- }
@Override
public Iterator<Triple> iterator() {
@@ -182,4 +168,9 @@ public class SecuredGraph implements Graph {
public ImmutableGraph getImmutableGraph() {
return new SimpleImmutableGraph(this);
}
+
+ @Override
+ public ReadWriteLock getLock() {
+ return wrapped.getLock();
+ }
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredMGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredMGraph.java
deleted file mode 100644
index 77b6d6a..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/SecuredMGraph.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access;
-
-import java.security.AccessControlException;
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.access.security.TcAccessController;
-import org.apache.clerezza.rdf.core.impl.SimpleImmutableGraph;
-import org.apache.clerezza.rdf.core.impl.WriteBlockedMGraph;
-
-/**
- * A SecuredMGraph is a LockableMGraph that wraps a LockableMGraph checking each
- * access for the rights on a the ImmutableGraph for which the uri is passed to the
- * constructor.
- *
- * @author mir
- */
-public class SecuredMGraph extends SecuredGraph implements LockableMGraph {
-
- private LockableMGraph wrapped;
-
- public SecuredMGraph(LockableMGraph wrapped, Iri name,
- TcAccessController tcAccessController) {
- super(wrapped, name, tcAccessController);
- this.wrapped = wrapped;
- }
-
-
- @Override
- public ReadWriteLock getLock() {
- return wrapped.getLock();
- }
-
- /**
- * Returns the wrapped LockableMGraph if the caller has all access rights.
- * If the caller has only the read access right, then a write-blocked
- * LockableMGraph is returned. If the caller has neither the read nor the write
- * access right then an AccessControlException is thrown.
- *
- * @return the wrapped LockableMGraph or a write-block LockableMGraph depending
- * on the access rights of the caller.
- */
- public LockableMGraph getUnsecuredMGraph() {
- try {
- checkWrite();
- return wrapped;
- } catch (AccessControlException ex) {
- checkRead();
- return new WriteBlockedMGraph(wrapped);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
index 4a977d8..6e56479 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcManager.java
@@ -19,7 +19,6 @@
package org.apache.clerezza.rdf.core.access;
import java.security.AccessControlException;
-import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
@@ -34,11 +33,9 @@ import java.util.TreeSet;
import org.apache.commons.rdf.ImmutableGraph;
import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Iri;
import org.apache.clerezza.rdf.core.access.security.TcAccessController;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.WriteBlockedMGraph;
+import org.apache.commons.rdf.impl.utils.simple.SimpleGraph;
import org.apache.clerezza.rdf.core.impl.WriteBlockedGraph;
import org.apache.clerezza.rdf.core.sparql.NoQueryEngineException;
import org.apache.clerezza.rdf.core.sparql.ParseException;
@@ -53,8 +50,6 @@ import org.apache.clerezza.rdf.core.sparql.query.SelectQuery;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Component;
@@ -84,7 +79,7 @@ import org.osgi.service.component.annotations.ReferencePolicy;
* injects them the instance.
*
* This class returns
- * <code>LockableMGraph</code>s a subtype of
+ * <code>Graph</code>s a subtype of
* <code>Graph</code> that allows read/write locks.
*
* This class also registers all Graphs as services with the property
@@ -217,12 +212,12 @@ public class TcManager extends TcProviderMultiplexer {
}
@Override
- public LockableMGraph getMGraph(Iri name) {
+ public Graph getMGraph(Iri name) {
try {
tcAccessController.checkReadWritePermission(name);
} catch (AccessControlException e) {
tcAccessController.checkReadPermission(name);
- return new WriteBlockedMGraph(super.getMGraph(name));
+ return new WriteBlockedGraph(super.getMGraph(name));
}
return super.getMGraph(name);
}
@@ -240,7 +235,7 @@ public class TcManager extends TcProviderMultiplexer {
}
@Override
- public LockableMGraph createMGraph(Iri name)
+ public Graph createMGraph(Iri name)
throws UnsupportedOperationException {
tcAccessController.checkReadWritePermission(name);
return super.createMGraph(name);
@@ -355,7 +350,7 @@ public class TcManager extends TcProviderMultiplexer {
}
final QueryEngine queryEngine = this.queryEngine;
if (queryEngine != null) {
- return queryEngine.execute(this, new SimpleMGraph(), query);
+ return queryEngine.execute(this, new SimpleGraph(), query);
} else {
throw new NoQueryEngineException();
}
@@ -586,7 +581,7 @@ public class TcManager extends TcProviderMultiplexer {
if (isMGraph) {
interfaceNames = new String[]{
Graph.class.getName(),
- LockableMGraph.class.getName()
+ Graph.class.getName()
};
service = new MGraphServiceFactory(this, name, tcAccessController);
} else {
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
index a8e4da6..2d2ca96 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/TcProviderMultiplexer.java
@@ -47,9 +47,9 @@ public class TcProviderMultiplexer implements TcProvider {
protected SortedSet<WeightedTcProvider> providerList = new TreeSet<WeightedTcProvider>(
new WeightedProviderComparator());
/**
- * Mapping to LockableMGraph's and ServiceRegistration using their URI's as key.
- * Makes sure that per URI only one instance of the LockableMGraph is used,
- * otherwise the locks in the <code>LockableMGraph</code>s would have no effect
+ * Mapping to Graph's and ServiceRegistration using their URI's as key.
+ * Makes sure that per URI only one instance of the Graph is used,
+ * otherwise the locks in the <code>Graph</code>s would have no effect
* between different instances and concurrency issues could occur.
*/
private Map<Iri, MGraphHolder> mGraphCache = Collections.synchronizedMap(new HashMap<Iri, MGraphHolder>());
@@ -68,7 +68,7 @@ public class TcProviderMultiplexer implements TcProvider {
*/
public void addWeightedTcProvider(WeightedTcProvider provider) {
providerList.add(provider);
- updateLockableMGraphCache(provider, true);
+ updateGraphCache(provider, true);
}
/**
@@ -80,7 +80,7 @@ public class TcProviderMultiplexer implements TcProvider {
public void removeWeightedTcProvider(
WeightedTcProvider provider) {
providerList.remove(provider);
- updateLockableMGraphCache(provider, false);
+ updateGraphCache(provider, false);
}
/**
@@ -133,7 +133,7 @@ public class TcProviderMultiplexer implements TcProvider {
* <code>org.apache.clerezza.rdf.core.TcManager.providerList</code>
* otherwise <code>false</code>
*/
- private void updateLockableMGraphCache(WeightedTcProvider provider,
+ private void updateGraphCache(WeightedTcProvider provider,
boolean providerAdded) {
Set<Iri> uriSet = provider.listGraphs();
if (!(uriSet == null || uriSet.isEmpty())) {
@@ -232,9 +232,9 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public LockableMGraph getMGraph(Iri name)
+ public Graph getMGraph(Iri name)
throws NoSuchEntityException {
- LockableMGraph result = getMGraphFromCache(name);
+ Graph result = getMGraphFromCache(name);
if (result == null) {
synchronized (this) {
result = getMGraphFromCache(name);
@@ -246,7 +246,7 @@ public class TcProviderMultiplexer implements TcProvider {
return result;
}
- private LockableMGraph getMGraphFromCache(Iri name) {
+ private Graph getMGraphFromCache(Iri name) {
MGraphHolder holder = mGraphCache.get(name);
if (holder == null) {
return null;
@@ -254,12 +254,12 @@ public class TcProviderMultiplexer implements TcProvider {
return holder.getMGraph();
}
- private LockableMGraph getUnsecuredMGraphAndAddToCache(Iri name)
+ private Graph getUnsecuredMGraphAndAddToCache(Iri name)
throws NoSuchEntityException {
for (WeightedTcProvider provider : providerList) {
try {
Graph providedMGraph = provider.getMGraph(name);
- LockableMGraph result = ensureLockable(providedMGraph);
+ Graph result = ensureLockable(providedMGraph);
if (isCachingEnabled()) {
mGraphCache.put(name, new MGraphHolder(
@@ -282,7 +282,7 @@ public class TcProviderMultiplexer implements TcProvider {
for (WeightedTcProvider provider : providerList) {
try {
result = provider.getTriples(name);
- if (!(result instanceof Graph)) {
+ if (result instanceof ImmutableGraph) {
return result;
} else {
// This is to ensure the Graph gets added to the cache
@@ -298,19 +298,12 @@ public class TcProviderMultiplexer implements TcProvider {
}
@Override
- public LockableMGraph createMGraph(Iri name)
+ public Graph createMGraph(Iri name)
throws UnsupportedOperationException {
for (WeightedTcProvider provider : providerList) {
try {
- Graph providedMGraph = provider.createMGraph(name);
- LockableMGraph result;
- if (providedMGraph instanceof LockableMGraph) {
- result = (LockableMGraph) providedMGraph;
- } else {
- result = new LockableMGraphWrapper(providedMGraph);
- }
-
+ Graph result = provider.createMGraph(name);
// unregisters a possible ImmutableGraph or Graph service under this name
// provided by a WeightedTcProvider with a lower weight.
tcDisappears(name);
@@ -417,31 +410,26 @@ public class TcProviderMultiplexer implements TcProvider {
return result;
}
- private LockableMGraph ensureLockable(Graph providedMGraph) {
- LockableMGraph result;
- if (providedMGraph instanceof LockableMGraph) {
- result = (LockableMGraph) providedMGraph;
- } else {
- result = new LockableMGraphWrapper(providedMGraph);
- }
- return result;
+ private Graph ensureLockable(Graph providedMGraph) {
+ //Graphs are alway locable now
+ return providedMGraph;
}
/**
- * Contains an unsecured LockableMGraph, a ServiceRegistration and
+ * Contains an unsecured Graph, a ServiceRegistration and
* the WeightedTcProvider that generated the ImmutableGraph
*/
private static class MGraphHolder {
private WeightedTcProvider tcProvider;
- private WeakReference<LockableMGraph> mGraphReference;
+ private WeakReference<Graph> mGraphReference;
- MGraphHolder(WeightedTcProvider tcProvider, LockableMGraph graph) {
+ MGraphHolder(WeightedTcProvider tcProvider, Graph graph) {
this.tcProvider = tcProvider;
- this.mGraphReference = new WeakReference<LockableMGraph>(graph);
+ this.mGraphReference = new WeakReference<Graph>(graph);
}
- LockableMGraph getMGraph() {
+ Graph getMGraph() {
return this.mGraphReference.get();
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReadLockDebug.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReadLockDebug.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReadLockDebug.java
deleted file mode 100644
index 80cb6d0..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReadLockDebug.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access.debug;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
-
-/**
- *
- * @author mir
- */
-public class ReadLockDebug extends ReadLock {
-
- ReentrantReadWriteLockTracker lock;
- StackTraceElement[] stackTrace;
-
- ReadLock readLock;
- public ReadLockDebug(ReentrantReadWriteLockTracker lock) {
- super(lock);
- this.lock = lock;
- this.readLock = lock.realReadLock();
- }
-
- @Override
- public void lock() {
- readLock.lock();
- lock.addLockedReadLock(this);
- stackTrace = Thread.currentThread().getStackTrace();
- }
-
- @Override
- public void lockInterruptibly() throws InterruptedException {
- readLock.lockInterruptibly();
- }
-
- @Override
- public Condition newCondition() {
- return readLock.newCondition();
- }
-
- @Override
- public String toString() {
- return readLock.toString();
- }
-
- @Override
- public boolean tryLock() {
- return readLock.tryLock();
- }
-
- @Override
- public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
- return readLock.tryLock(timeout, unit);
- }
-
- @Override
- public void unlock() {
- readLock.unlock();
- lock.removeReadLock(this);
- stackTrace = null;
- }
-
- public StackTraceElement[] getStackTrace() {
- return stackTrace;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReentrantReadWriteLockTracker.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReentrantReadWriteLockTracker.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReentrantReadWriteLockTracker.java
deleted file mode 100644
index 75b06d8..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/ReentrantReadWriteLockTracker.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access.debug;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-/**
- *
- * @author mir
- */
-public class ReentrantReadWriteLockTracker extends ReentrantReadWriteLock {
-
-
- private Set<ReadLockDebug> lockedReadLocks = Collections.synchronizedSet(new HashSet<ReadLockDebug>());
- private final WriteLockDebug writeLock = new WriteLockDebug(this);
- @Override
- protected Thread getOwner() {
- return super.getOwner();
- }
-
- @Override
- protected Collection<Thread> getQueuedReaderThreads() {
- return super.getQueuedReaderThreads();
- }
-
- @Override
- protected Collection<Thread> getQueuedThreads() {
- return super.getQueuedThreads();
- }
-
- @Override
- protected Collection<Thread> getQueuedWriterThreads() {
- return super.getQueuedWriterThreads();
- }
-
- @Override
- public int getReadHoldCount() {
- return super.getReadHoldCount();
- }
-
- @Override
- public int getReadLockCount() {
- return super.getReadLockCount();
- }
-
- @Override
- public int getWaitQueueLength(Condition condition) {
- return super.getWaitQueueLength(condition);
- }
-
- @Override
- protected Collection<Thread> getWaitingThreads(Condition condition) {
- return super.getWaitingThreads(condition);
- }
-
- @Override
- public int getWriteHoldCount() {
- return super.getWriteHoldCount();
- }
-
- @Override
- public boolean hasWaiters(Condition condition) {
- return super.hasWaiters(condition);
- }
-
- @Override
- public boolean isWriteLocked() {
- return super.isWriteLocked();
- }
-
- @Override
- public boolean isWriteLockedByCurrentThread() {
- return super.isWriteLockedByCurrentThread();
- }
-
- @Override
- public ReadLock readLock() {
- return new ReadLockDebug(this);
- }
-
- ReadLock realReadLock() {
- return super.readLock();
- }
-
- WriteLock realWriteLock() {
- return super.writeLock();
- }
-
- @Override
- public String toString() {
- return super.toString();
- }
-
- @Override
- public WriteLockDebug writeLock() {
- return writeLock;
- }
-
- void addLockedReadLock(ReadLockDebug lock) {
- lockedReadLocks.add(lock);
- }
-
- void removeReadLock(ReadLockDebug lock) {
- lockedReadLocks.remove(lock);
- }
-
- public Set<ReadLockDebug> getLockedReadLocks() {
- return lockedReadLocks;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/WriteLockDebug.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/WriteLockDebug.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/WriteLockDebug.java
deleted file mode 100644
index 5bbbfeb..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/debug/WriteLockDebug.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.clerezza.rdf.core.access.debug;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
-
-/**
- *
- * @author mir
- */
-public class WriteLockDebug extends WriteLock {
-
- private ReentrantReadWriteLockTracker lock;
- private WriteLock writeLock;
- private StackTraceElement[] stackTrace;
-
- public WriteLockDebug(ReentrantReadWriteLockTracker lock) {
- super(lock);
- this.lock = lock;
- this.writeLock = lock.realWriteLock();
- }
-
- @Override
- public int getHoldCount() {
- return writeLock.getHoldCount();
- }
-
- @Override
- public boolean isHeldByCurrentThread() {
- return writeLock.isHeldByCurrentThread();
- }
-
- @Override
- public void lock() {
- writeLock.lock();
- stackTrace = Thread.currentThread().getStackTrace();
- }
-
- @Override
- public void lockInterruptibly() throws InterruptedException {
- writeLock.lockInterruptibly();
- }
-
- @Override
- public Condition newCondition() {
- return writeLock.newCondition();
- }
-
- @Override
- public boolean tryLock() {
- return writeLock.tryLock();
- }
-
- @Override
- public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
- return writeLock.tryLock(timeout, unit);
- }
-
- @Override
- public void unlock() {
- writeLock.unlock();
- stackTrace = null;
- }
-
- public StackTraceElement[] getStackTrace() {
- return stackTrace;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
index 405cfbd..155cccb 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/access/security/TcAccessController.java
@@ -31,17 +31,17 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.locks.Lock;
-import org.apache.commons.rdf.BlankNode;
import org.apache.clerezza.rdf.core.LiteralFactory;
+import org.apache.commons.rdf.BlankNode;
import org.apache.commons.rdf.BlankNodeOrIri;
import org.apache.commons.rdf.RdfTerm;
import org.apache.commons.rdf.Triple;
import org.apache.commons.rdf.Iri;
-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.clerezza.rdf.core.impl.TripleImpl;
+import org.apache.commons.rdf.impl.utils.TripleImpl;
import org.apache.clerezza.utils.security.PermissionParser;
+import org.apache.commons.rdf.Graph;
import org.apache.commons.rdf.Literal;
/**
@@ -146,7 +146,7 @@ public abstract class TcAccessController {
public void setRequiredReadPermissionStrings(Iri GraphUri,
Collection<String> permissionDescriptions) {
readPermissionCache.remove(GraphUri);
- final LockableMGraph permissionMGraph = getOrCreatePermisionGraph();
+ final Graph permissionMGraph = getOrCreatePermisionGraph();
Lock l = permissionMGraph.getLock().writeLock();
l.lock();
try {
@@ -186,7 +186,7 @@ public abstract class TcAccessController {
public void setRequiredReadWritePermissionStrings(Iri GraphUri,
Collection<String> permissionDescriptions) {
readWritePermissionCache.remove(GraphUri);
- final LockableMGraph permissionMGraph = getOrCreatePermisionGraph();
+ final Graph permissionMGraph = getOrCreatePermisionGraph();
Lock l = permissionMGraph.getLock().writeLock();
l.lock();
try {
@@ -258,7 +258,7 @@ public abstract class TcAccessController {
return result;
}
- private BlankNodeOrIri createList(Iterator<String> iterator, LockableMGraph permissionMGraph) {
+ private BlankNodeOrIri createList(Iterator<String> iterator, Graph permissionMGraph) {
if (!iterator.hasNext()) {
return rdfNil;
}
@@ -273,7 +273,7 @@ public abstract class TcAccessController {
//called withiong write-lock
private void removeExistingRequiredReadPermissions(Iri GraphUri,
- LockableMGraph permissionMGraph) {
+ Graph permissionMGraph) {
try {
Triple t = permissionMGraph.filter(GraphUri, readPermissionListProperty, null).next();
RdfTerm list = t.getObject();
@@ -284,7 +284,7 @@ public abstract class TcAccessController {
}
}
- private void removeList(BlankNodeOrIri list, LockableMGraph permissionMGraph) {
+ private void removeList(BlankNodeOrIri list, Graph permissionMGraph) {
try {
Triple t = permissionMGraph.filter(list, rest, null).next();
RdfTerm restList = t.getObject();
@@ -306,7 +306,7 @@ public abstract class TcAccessController {
}
private Collection<String> getRequiredPermissionStrings(final Iri GraphUri, Iri property) {
try {
- final LockableMGraph permissionMGraph = tcManager.getMGraph(permissionGraphName);
+ final Graph permissionMGraph = tcManager.getMGraph(permissionGraphName);
Lock l = permissionMGraph.getLock().readLock();
l.lock();
try {
@@ -325,7 +325,7 @@ public abstract class TcAccessController {
}
}
- private void readList(BlankNodeOrIri list, LockableMGraph permissionMGraph, LinkedList<String> target) {
+ private void readList(BlankNodeOrIri list, Graph permissionMGraph, LinkedList<String> target) {
if (list.equals(rdfNil)) {
return;
}
@@ -338,7 +338,7 @@ public abstract class TcAccessController {
target.addFirst(value);
}
- private LockableMGraph getOrCreatePermisionGraph() {
+ private Graph getOrCreatePermisionGraph() {
try {
return tcManager.getMGraph(permissionGraphName);
} catch (NoSuchEntityException e) {
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractGraph.java
deleted file mode 100644
index 86f000b..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractGraph.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.lang.ref.WeakReference;
-import java.util.AbstractCollection;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import java.util.Set;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.event.AddEvent;
-import org.apache.commons.rdf.event.FilterTriple;
-import org.apache.commons.rdf.event.GraphEvent;
-import org.apache.commons.rdf.event.GraphListener;
-import org.apache.commons.rdf.event.RemoveEvent;
-
-/**
- * An abstract implementation of <code>Graph</code> implementing
- * <code>iterator</code> and <code>contains</code> calling <code>filter</code>.
- *
- * @author reto
- */
-public abstract class AbstractGraph extends AbstractCollection<Triple>
- implements Graph {
-
- //all listeners
- private final Set<ListenerConfiguration> listenerConfigs = Collections.synchronizedSet(
- new HashSet<ListenerConfiguration>());
- private DelayedNotificator delayedNotificator = new DelayedNotificator();
-
- @Override
- public Iterator<Triple> iterator() {
- return filter(null, null, null);
- }
-
- @Override
- public boolean contains(Object o) {
- if (!(o instanceof Triple)) {
- return false;
- }
- Triple t = (Triple) o;
- return filter(t.getSubject(), t.getPredicate(), t.getObject()).hasNext();
- }
-
- @Override
- public Iterator<Triple> filter(BlankNodeOrIri subject, Iri predicate,
- RdfTerm object) {
- final Iterator<Triple> baseIter = performFilter(subject, predicate, object);
- return new Iterator<Triple>() {
-
- Triple currentTriple = null;
-
- @Override
- public boolean hasNext() {
- return baseIter.hasNext();
- }
-
- @Override
- public Triple next() {
- currentTriple = baseIter.next();
- return currentTriple;
- }
-
- @Override
- public void remove() {
- baseIter.remove();
- dispatchEvent(new RemoveEvent(AbstractGraph.this, currentTriple));
- }
- };
- }
-
- /**
- * A subclass of <code>AbstractGraph</code> should override
- * this method instead of <code>filter</code> for ImmutableGraph event support to be
- * added. The Iterator returned by <code>filter</code> will dispatch a
- * GraphEvent after invoking the remove method of the iterator returned by
- * this method.
- *
- * @param subject
- * @param predicate
- * @param object
- * @return
- */
- protected abstract Iterator<Triple> performFilter(BlankNodeOrIri subject, Iri predicate,
- RdfTerm object);
-
- @Override
- public boolean add(Triple triple) {
- boolean success = performAdd(triple);
- if (success) {
- dispatchEvent(new AddEvent(this, triple));
- }
- return success;
- }
-
- /**
- * A subclass of <code>AbstractGraph</code> should override
- * this method instead of <code>add</code> for ImmutableGraph event support to be
- * added.
- *
- * @param e The triple to be added to the triple collection
- * @return
- */
- protected boolean performAdd(Triple e) {
- return super.add(e);
- }
-
- @Override
- public boolean remove(Object o) {
- Triple triple = (Triple) o;
- boolean success = performRemove(triple);
- if (success) {
- dispatchEvent(new RemoveEvent(this, triple));
- }
- return success;
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- boolean modified = false;
- for (Iterator<? extends Object> it = c.iterator(); it.hasNext();) {
- Object object = it.next();
- if (remove(object)) {
- modified = true;
- }
- }
- return modified;
- }
-
- /**
- * A subclass of <code>AbstractGraph</code> should override
- * this method instead of <code>remove</code> for ImmutableGraph event support to be
- * added.
- *
- * @param o The triple to be removed from the triple collection
- * @return
- */
- protected boolean performRemove(Triple triple) {
- Iterator<Triple> e = performFilter(null, null, null);
- while (e.hasNext()) {
- if (triple.equals(e.next())) {
- e.remove();
- return true;
- }
- }
- return false;
- }
-
- /**
- * Dispatches a <code>GraphEvent</code> to all registered listeners for which
- * the specified <code>Triple</code> matches the <code>FilterTriple</code>s
- * of the listeners.
- *
- * @param triple The Triple that was modified
- * @param type The type of modification
- */
- protected void dispatchEvent(GraphEvent event) {
- synchronized(listenerConfigs) {
- Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
- while (iter.hasNext()) {
- ListenerConfiguration config = iter.next();
- GraphListener registeredListener = config.getListener();
- if (registeredListener == null) {
- iter.remove();
- continue;
- }
- if (config.getFilter().match(event.getTriple())) {
- delayedNotificator.sendEventToListener(registeredListener, event);
- }
- }
- }
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- addGraphListener(listener, filter, 0);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter,
- long delay) {
- listenerConfigs.add(new ListenerConfiguration(listener, filter));
- if (delay > 0) {
- delayedNotificator.addDelayedListener(listener, delay);
- }
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- synchronized(listenerConfigs) {
- Iterator<ListenerConfiguration> iter = listenerConfigs.iterator();
- while (iter.hasNext()) {
- ListenerConfiguration listenerConfig = iter.next();
- GraphListener registeredListener = listenerConfig.getListener();
- if ((registeredListener == null) || (registeredListener.equals(listener))) {
- iter.remove();
- }
- }
- }
- delayedNotificator.removeDelayedListener(listener);
- }
-
- private static class ListenerConfiguration {
-
- private WeakReference<GraphListener> listenerRef;
- private FilterTriple filter;
-
- private ListenerConfiguration(GraphListener listener, FilterTriple filter) {
- this.listenerRef = new WeakReference<GraphListener>(listener);
- this.filter = filter;
- }
-
- /**
- * @return the listener
- */
- GraphListener getListener() {
- GraphListener listener = listenerRef.get();
- return listener;
- }
-
- /**
- * @return the filter
- */
- FilterTriple getFilter() {
- return filter;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractImmutableGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractImmutableGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractImmutableGraph.java
deleted file mode 100644
index 9a52c88..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractImmutableGraph.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.clerezza.rdf.core.impl.graphmatching.GraphMatcher;
-
-/**
- * <code>AbstractGraph</code> is an abstract implementation of <code>ImmutableGraph</code>
- * implementing the <code>equals</code> and the <code>hashCode</code> methods.
- *
- * @author reto
- *
- */
-public abstract class AbstractImmutableGraph extends AbstractGraph
- implements ImmutableGraph {
-
- public final synchronized int hashCode() {
- int result = 0;
- for (Iterator<Triple> iter = iterator(); iter.hasNext();) {
- result += getBlankNodeBlindHash(iter.next());
- }
- return result;
- }
-
- /**
- * @param triple
- * @return hash without BNode hashes
- */
- private int getBlankNodeBlindHash(Triple triple) {
- int hash = triple.getPredicate().hashCode();
- RdfTerm subject = triple.getSubject();
-
- if (!(subject instanceof BlankNode)) {
- hash ^= subject.hashCode() >> 1;
- }
- RdfTerm object = triple.getObject();
- if (!(object instanceof BlankNode)) {
- hash ^= object.hashCode() << 1;
- }
-
- return hash;
- }
-
- @Override
- public boolean add(Triple e) {
- throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
-
- }
-
- @Override
- public boolean addAll(Collection<? extends Triple> c) {
- throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
- }
-
- @Override
- public boolean remove(Object o) {
- throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
- }
-
- @Override
- public boolean removeAll(Collection<?> c) {
- throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("Graphs are not mutable, use Graph");
- }
-
-
- @Override
- public ImmutableGraph getImmutableGraph() {
- return this;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof ImmutableGraph)) {
- return false;
- }
- if (hashCode() != obj.hashCode()) {
- return false;
- }
- return GraphMatcher.getValidMapping(this, (ImmutableGraph) obj) != null;
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractMGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractMGraph.java
deleted file mode 100644
index 55bb2c3..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/AbstractMGraph.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Graph;
-
-/**
- * <code>AbstractMGraph</code> is an abstract implementation of <code>Graph</code>
- * implementing the <code>getGraph</code> method.
- *
- * @author reto
- */
-public abstract class AbstractMGraph extends AbstractGraph implements Graph {
-
- @Override
- public ImmutableGraph getImmutableGraph() {
- return new SimpleImmutableGraph(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/DelayedNotificator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/DelayedNotificator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/DelayedNotificator.java
deleted file mode 100644
index bc49042..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/DelayedNotificator.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.lang.ref.WeakReference;
-import java.util.*;
-
-import org.apache.commons.rdf.event.GraphEvent;
-import org.apache.commons.rdf.event.GraphListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- * @author reto
- */
-class DelayedNotificator {
-
- private static final Logger log = LoggerFactory.getLogger(DelayedNotificator.class);
- private static Timer timer = new Timer("Event delivery timer",true);
-
- static class ListenerHolder {
-
- long delay;
- List<GraphEvent> events = null;
- WeakReference<GraphListener> listenerRef;
-
- public ListenerHolder(GraphListener listener, long delay) {
- this.listenerRef = new WeakReference<GraphListener>(listener);
- this.delay = delay;
- }
-
- private void registerEvent(GraphEvent event) {
- synchronized (this) {
- if (events == null) {
- events = new ArrayList<GraphEvent>();
- events.add(event);
- timer.schedule(new TimerTask() {
-
- @Override
- public void run() {
- List<GraphEvent> eventsLocal;
- synchronized (ListenerHolder.this) {
- eventsLocal = events;
- events = null;
- }
- GraphListener listener = listenerRef.get();
- if (listener == null) {
- log.debug("Ignoring garbage collected listener");
- } else {
- try {
- listener.graphChanged(eventsLocal);
- } catch (Exception e) {
- log.warn("Exception delivering ImmutableGraph event", e);
- }
- }
- }
- }, delay);
- } else {
- events.add(event);
- }
- }
- }
- }
-
- private final Map<GraphListener, ListenerHolder> map = Collections.synchronizedMap(
- new WeakHashMap<GraphListener, ListenerHolder>());
-
- void addDelayedListener(GraphListener listener, long delay) {
- map.put(listener, new ListenerHolder(listener, delay));
- }
-
- /**
- * removes a Listener, this doesn't prevent the listenerRef from receiving
- * events alreay scheduled.
- *
- * @param listenerRef
- */
- void removeDelayedListener(GraphListener listener) {
- map.remove(listener);
- }
-
- /**
- * if the listenerRef has not been registered as delayed listenerRef te events is
- * forwarded synchroneously
- * @param event
- */
- void sendEventToListener(GraphListener listener, GraphEvent event) {
- ListenerHolder holder = map.get(listener);
- if (holder == null) {
- listener.graphChanged(Collections.singletonList(event));
- } else {
- holder.registerEvent(event);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImpl.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImpl.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImpl.java
deleted file mode 100644
index 9ba5495..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/PlainLiteralImpl.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.io.Serializable;
-import org.apache.commons.rdf.Iri;
-
-import org.apache.commons.rdf.Language;
-import org.apache.commons.rdf.Literal;
-
-/**
- *
- * @author reto
- */
-public class PlainLiteralImpl implements Literal, Serializable {
-
- private String lexicalForm;
- private Language language = null;
-
- public PlainLiteralImpl(String value) {
- if (value == null) {
- throw new IllegalArgumentException("The literal string cannot be null");
- }
- this.lexicalForm = value;
- }
-
- public PlainLiteralImpl(String value, Language language) {
- if (value == null) {
- throw new IllegalArgumentException("The literal string cannot be null");
- }
- this.lexicalForm = value;
- this.language = language;
- }
-
- @Override
- public String getLexicalForm() {
- return lexicalForm;
- }
-
- @Override
- public boolean equals(Object otherObj) {
- if (!(otherObj instanceof Literal)) {
- return false;
- }
- Literal other = (Literal) otherObj;
- if (!lexicalForm.equals(other.getLexicalForm())) {
- return false;
- }
- if (language != null) {
- return language.equals(other.getLanguage());
- }
- if (other.getLanguage() != null) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- int hash = lexicalForm.hashCode();
- if (language != null) {
- hash += language.hashCode();
- }
- return hash;
- }
-
- @Override
- public Language getLanguage() {
- return language;
- }
-
- @Override
- public String toString() {
- StringBuffer result = new StringBuffer();
- result.append('\"').append(lexicalForm).append('\"');
- if (language != null) {
- result.append("@").append(language.toString());
- }
- return result.toString();
- }
-
- @Override
- public Iri getDataType() {
- return XSD_STRING;
- }
- private static final Iri XSD_STRING = new Iri("http://www.w3.org/2001/XMLSchema#string");
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleGraph.java
deleted file mode 100644
index 334a7d9..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleGraph.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.lang.ref.SoftReference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-
-/**
- * For now this is a minimalistic implementation, without any indexes or other
- * optimizations.
- *
- * This class is not public, implementations should use {@link SimpleGraph} or
- * {@link SimpleMGraph}.
- *
- * @author reto
- */
-class SimpleGraph extends AbstractGraph {
-
- final Set<Triple> triples;
-
- private boolean checkConcurrency = false;
-
- class SimpleIterator implements Iterator<Triple> {
-
- private Iterator<Triple> listIter;
- private boolean isValid = true;
-
- public SimpleIterator(Iterator<Triple> listIter) {
- this.listIter = listIter;
- }
- private Triple currentNext;
-
- @Override
- public boolean hasNext() {
- checkValidity();
- return listIter.hasNext();
- }
-
- @Override
- public Triple next() {
- checkValidity();
- currentNext = listIter.next();
- return currentNext;
- }
-
- @Override
- public void remove() {
- checkValidity();
- listIter.remove();
- triples.remove(currentNext);
- invalidateIterators(this);
- }
-
- private void checkValidity() throws ConcurrentModificationException {
- if (checkConcurrency && !isValid) {
- throw new ConcurrentModificationException();
- }
- }
-
- private void invalidate() {
- isValid = false;
- }
- }
-
- private final Set<SoftReference<SimpleIterator>> iterators =
- Collections.synchronizedSet(new HashSet<SoftReference<SimpleIterator>>());
-
- /**
- * Creates an empty SimpleGraph
- */
- public SimpleGraph() {
- triples = Collections.synchronizedSet(new HashSet<Triple>());
- }
-
- /**
- * Creates a SimpleGraph using the passed iterator, the iterator
- * is consumed before the constructor returns
- *
- * @param iterator
- */
- public SimpleGraph(Iterator<Triple> iterator) {
- triples = new HashSet<Triple>();
- while (iterator.hasNext()) {
- Triple triple = iterator.next();
- triples.add(triple);
- }
- }
-
- /**
- * Creates a SimpleGraph for the specified set of triples,
- * subsequent modification of baseSet do affect the created instance.
- *
- * @param baseSet
- */
- public SimpleGraph(Set<Triple> baseSet) {
- this.triples = baseSet;
- }
-
- /**
- * Creates a SimpleGraph for the specified collection of triples,
- * subsequent modification of baseSet do not affect the created instance.
- *
- * @param baseSet
- */
- public SimpleGraph(Collection<Triple> baseCollection) {
- this.triples = new HashSet<Triple>(baseCollection);
- }
-
- @Override
- public int size() {
- return triples.size();
- }
-
- @Override
- public Iterator<Triple> performFilter(final BlankNodeOrIri subject, final Iri predicate, final RdfTerm object) {
- final List<Triple> tripleList = new ArrayList<Triple>();
- synchronized (triples) {
- Iterator<Triple> baseIter = triples.iterator();
- while (baseIter.hasNext()) {
- Triple triple = baseIter.next();
- if ((subject != null)
- && (!triple.getSubject().equals(subject))) {
- continue;
- }
- if ((predicate != null)
- && (!triple.getPredicate().equals(predicate))) {
- continue;
- }
- if ((object != null)
- && (!triple.getObject().equals(object))) {
- continue;
- }
- tripleList.add(triple);
- }
-
- final Iterator<Triple> listIter = tripleList.iterator();
- SimpleIterator resultIter = new SimpleIterator(listIter);
- if (checkConcurrency) {
- iterators.add(new SoftReference<SimpleIterator>(resultIter));
- }
- return resultIter;
- }
- }
-
-
- @Override
- public boolean performAdd(Triple e) {
- boolean modified = triples.add(e);
- if (modified) {
- invalidateIterators(null);
- }
- return modified;
- }
-
- private void invalidateIterators(SimpleIterator caller) {
- if (!checkConcurrency) {
- return;
- }
- Set<SoftReference> oldReferences = new HashSet<SoftReference>();
- synchronized(iterators) {
- for (SoftReference<SimpleGraph.SimpleIterator> softReference : iterators) {
- SimpleIterator simpleIterator = softReference.get();
- if (simpleIterator == null) {
- oldReferences.add(softReference);
- continue;
- }
- if (simpleIterator != caller) {
- simpleIterator.invalidate();
- }
- }
- }
- iterators.removeAll(oldReferences);
- }
-
- /**
- * Specifies whether or not to throw <code>ConcurrentModificationException</code>s,
- * if this simple triple collection is modified concurrently. Concurrency
- * check is set to false by default.
- *
- * @param bool Specifies whether or not to check concurrent modifications.
- */
- public void setCheckConcurrency(boolean bool) {
- checkConcurrency = bool;
- }
-
-
- @Override
- public ImmutableGraph getImmutableGraph() {
- return new SimpleImmutableGraph(this);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleImmutableGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleImmutableGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleImmutableGraph.java
deleted file mode 100644
index d0c6a61..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleImmutableGraph.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.util.Iterator;
-
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-
-/**
- *
- * @author reto
- */
-public class SimpleImmutableGraph extends AbstractImmutableGraph {
-
- private Graph graph;
-
- /**
- * Creates a ImmutableGraph with the triples in Graph
- *
- * @param Graph the collection of triples this ImmutableGraph shall consist of
- */
- public SimpleImmutableGraph(Graph Graph) {
- this.graph = new SimpleGraph(Graph.iterator());
- }
-
- /**
- * Creates a ImmutableGraph with the triples in Graph.
- *
- * This construction allows to specify if the Graph might change
- * in future. If GraphWillNeverChange is set to true it will
- * assume that the collection never changes, in this case the collection
- * isn't copied making things more efficient.
- *
- * @param Graph the collection of triples this ImmutableGraph shall consist of
- * @param GraphWillNeverChange true if the caller promises Graph will never change
- */
- public SimpleImmutableGraph(Graph Graph, boolean GraphWillNeverChange) {
- if (!GraphWillNeverChange) {
- this.graph = new SimpleGraph(Graph.iterator());
- } else {
- this.graph = Graph;
- }
- }
-
- public SimpleImmutableGraph(Iterator<Triple> tripleIter) {
- this.graph = new SimpleGraph(tripleIter);
- }
-
- @Override
- public int size() {
- return graph.size();
- }
-
- @Override
- public Iterator<Triple> performFilter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
- return graph.filter(subject, predicate, object);
- }
-}
[2/3] clerezza git commit: CLEREZZA-961: using rdf-commons from
clerezza-rdf-core repository
Posted by re...@apache.org.
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactory.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactory.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactory.java
deleted file mode 100644
index 4a19132..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleLiteralFactory.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.math.BigInteger;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.apache.clerezza.rdf.core.InvalidLiteralTypeException;
-import org.apache.clerezza.rdf.core.LiteralFactory;
-import org.apache.clerezza.rdf.core.NoConvertorException;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.util.Base64;
-import org.apache.clerezza.rdf.core.impl.util.W3CDateFormat;
-import org.apache.commons.rdf.Literal;
-
-/**
- * An implementation of literal factory currently supporting only
- * byte[]/base64Binary and Java.util.Date/date
- *
- * @author reto
- */
-
-public class SimpleLiteralFactory extends LiteralFactory {
-
- private static final String XSD = "http://www.w3.org/2001/XMLSchema#";
- final private static Iri xsdInteger = xsd("integer");
- final private static Iri xsdInt = xsd("int");
- final private static Iri xsdShort = xsd("short");
- final private static Iri xsdByte = xsd("byte");
- final private static Iri xsdLong = xsd("long");
-
-
- final private static Set<Iri> decimalTypes = new HashSet<Iri>();
-
- final private static Map<Class<?>, TypeConverter<?>> typeConverterMap = new HashMap<Class<?>, TypeConverter<?>>();
- final static Class<? extends byte[]> byteArrayType;
-
- static {
- Collections.addAll(decimalTypes, xsdInteger, xsdInt, xsdByte, xsdShort, xsdLong );
-
- byte[] byteArray = new byte[0];
- byteArrayType = byteArray.getClass();
- typeConverterMap.put(byteArrayType, new ByteArrayConverter());
- typeConverterMap.put(Date.class, new DateConverter());
- typeConverterMap.put(Boolean.class, new BooleanConverter());
- typeConverterMap.put(String.class, new StringConverter());
- typeConverterMap.put(Integer.class, new IntegerConverter());
- typeConverterMap.put(BigInteger.class, new BigIntegerConverter());
- typeConverterMap.put(Long.class, new LongConverter());
- typeConverterMap.put(Double.class, new DoubleConverter());
- typeConverterMap.put(Float.class, new FloatConverter());
- typeConverterMap.put(Iri.class, new UriRefConverter());
- }
-
- final private static Iri xsdDouble =xsd("double");
- final private static Iri xsdFloat =xsd("float");
- final private static Iri xsdAnyURI =xsd("anyURI");
-
- final private static Iri xsd(String name) {
- return new Iri(XSD+name);
- }
-
- private static interface TypeConverter<T> {
- Literal createLiteral(T value);
- T createObject(Literal literal);
- }
-
- private static class ByteArrayConverter implements TypeConverter<byte[]> {
-
- private static final Iri base64Uri =xsd("base64Binary");
-
- @Override
- public Literal createLiteral(byte[] value) {
- return new TypedLiteralImpl(Base64.encode((byte[]) value), base64Uri);
- }
-
- @Override
- public byte[] createObject(Literal literal) {
- if (!literal.getDataType().equals(base64Uri)) {
- throw new InvalidLiteralTypeException(byteArrayType, literal.getDataType());
- }
- return (byte[])Base64.decode(literal.getLexicalForm());
- }
-
-
- }
- private static class DateConverter implements TypeConverter<Date> {
-
- private static final Iri dateTimeUri =xsd("dateTime");
- private static final DateFormat DATE_FORMAT = new W3CDateFormat();
-
- @Override
- public Literal createLiteral(Date value) {
- return new TypedLiteralImpl(DATE_FORMAT.format(value), dateTimeUri);
- }
-
- @Override
- public Date createObject(Literal literal) {
- if (!literal.getDataType().equals(dateTimeUri)) {
- throw new InvalidLiteralTypeException(Date.class, literal.getDataType());
- }
- try {
- return DATE_FORMAT.parse(literal.getLexicalForm());
- } catch (ParseException ex) {
- throw new RuntimeException("Exception parsing literal as date", ex);
- }
- }
-
-
- }
-
- private static class BooleanConverter implements TypeConverter<Boolean> {
-
- private static final Iri booleanUri =xsd("boolean");
- public static final TypedLiteralImpl TRUE = new TypedLiteralImpl("true", booleanUri);
- public static final TypedLiteralImpl FALSE = new TypedLiteralImpl("false", booleanUri);
-
- @Override
- public Literal createLiteral(Boolean value) {
- if (value) return TRUE;
- else return FALSE;
- }
-
- @Override
- public Boolean createObject(Literal literal) {
- if (literal == TRUE) return true;
- else if (literal == FALSE) return false;
- else if (!literal.getDataType().equals(booleanUri)) {
- throw new InvalidLiteralTypeException(Boolean.class, literal.getDataType());
- }
- return Boolean.valueOf(literal.getLexicalForm());
- }
- }
-
- private static class StringConverter implements TypeConverter<String> {
-
- private static final Iri stringUri =xsd("string");
-
- @Override
- public Literal createLiteral(String value) {
- return new TypedLiteralImpl(value, stringUri);
- }
-
- @Override
- public String createObject(Literal literal) {
- if (!literal.getDataType().equals(stringUri)) {
- throw new InvalidLiteralTypeException(String.class, literal.getDataType());
- }
- return literal.getLexicalForm();
- }
- }
-
- private static class IntegerConverter implements TypeConverter<Integer> {
-
-
- @Override
- public Literal createLiteral(Integer value) {
- return new TypedLiteralImpl(value.toString(), xsdInt);
- }
-
- @Override
- public Integer createObject(Literal literal) {
- if (!decimalTypes.contains(literal.getDataType())) {
- throw new InvalidLiteralTypeException(Integer.class, literal.getDataType());
- }
- return new Integer(literal.getLexicalForm());
- }
- }
-
- private static class LongConverter implements TypeConverter<Long> {
-
-
-
- @Override
- public Literal createLiteral(Long value) {
- return new TypedLiteralImpl(value.toString(), xsdLong);
- }
-
- @Override
- public Long createObject(Literal literal) {
- if (!decimalTypes.contains(literal.getDataType())) {
- throw new InvalidLiteralTypeException(Long.class, literal.getDataType());
- }
- return new Long(literal.getLexicalForm());
- }
- }
-
-
- private static class FloatConverter implements TypeConverter<Float> {
-
- @Override
- public Literal createLiteral(Float value) {
- return new TypedLiteralImpl(value.toString(), xsdFloat);
- }
-
- @Override
- public Float createObject(Literal literal) {
- if (!literal.getDataType().equals(xsdFloat)) {
- throw new InvalidLiteralTypeException(Float.class, literal.getDataType());
- }
- return Float.valueOf(literal.getLexicalForm());
- }
- }
-
- private static class DoubleConverter implements TypeConverter<Double> {
-
-
-
- @Override
- public Literal createLiteral(Double value) {
- return new TypedLiteralImpl(value.toString(), xsdDouble);
- }
-
- @Override
- public Double createObject(Literal literal) {
- if (!literal.getDataType().equals(xsdDouble)) {
- throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
- }
- return new Double(literal.getLexicalForm());
- }
- }
-
- private static class BigIntegerConverter implements TypeConverter<BigInteger> {
-
-
-
- @Override
- public Literal createLiteral(BigInteger value) {
- return new TypedLiteralImpl(value.toString(), xsdInteger);
- }
-
- @Override
- public BigInteger createObject(Literal literal) {
- if (!literal.getDataType().equals(xsdInteger)) {
- throw new InvalidLiteralTypeException(Double.class, literal.getDataType());
- }
- return new BigInteger(literal.getLexicalForm());
- }
- }
-
- private static class UriRefConverter implements TypeConverter<Iri> {
-
-
-
- @Override
- public Literal createLiteral(Iri value) {
- return new TypedLiteralImpl(value.getUnicodeString(), xsdAnyURI);
- }
-
- @Override
- public Iri createObject(Literal literal) {
- if (!literal.getDataType().equals(xsdAnyURI)) {
- throw new InvalidLiteralTypeException(Iri.class, literal.getDataType());
- }
- return new Iri(literal.getLexicalForm());
- }
- }
-
-
- @SuppressWarnings("unchecked")
- @Override
- public Literal createTypedLiteral(Object value) throws NoConvertorException {
- TypeConverter converter = getConverterFor(value.getClass());
- return converter.createLiteral(value);
- }
-
-
-
- @Override
- public <T> T createObject(Class<T> type, Literal literal)
- throws NoConvertorException, InvalidLiteralTypeException {
- final TypeConverter<T> converter = getConverterFor(type);
- return converter.createObject(literal);
-
- }
-
- @SuppressWarnings("unchecked")
- private <T> TypeConverter<T> getConverterFor(Class<T> type) throws NoConvertorException {
- TypeConverter<T> convertor = (TypeConverter<T>) typeConverterMap.get(type);
- if (convertor != null) {
- return convertor;
- }
- for (Map.Entry<Class<?>, TypeConverter<?>> converterEntry : typeConverterMap.entrySet()) {
- if (type.isAssignableFrom(converterEntry.getKey())) {
- return (TypeConverter<T>) converterEntry.getValue();
- }
- }
- throw new NoConvertorException(type);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleMGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleMGraph.java
deleted file mode 100644
index 19a4b72..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/SimpleMGraph.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Triple;
-
-/**
- *
- * @author reto
- */
-public class SimpleMGraph extends SimpleGraph implements Graph {
-
- /**
- * Creates an empty SimpleMGraph
- */
- public SimpleMGraph() {
- }
-
- public SimpleMGraph(Set<Triple> baseSet) {
- super(baseSet);
- }
-
- public SimpleMGraph(Collection<Triple> baseCollection) {
- super(baseCollection);
- }
-
- public SimpleMGraph(Iterator<Triple> iterator) {
- super(iterator);
- }
-
-}
-
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TripleImpl.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TripleImpl.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TripleImpl.java
deleted file mode 100644
index e41bbd0..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TripleImpl.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Iri;
-
-/**
- *
- * @author reto
- */
-public class TripleImpl implements Triple {
-
- private final BlankNodeOrIri subject;
- private final Iri predicate;
- private final RdfTerm object;
-
- /**
- * Creates a new <code>TripleImpl</code>.
- *
- * @param subject the subject.
- * @param predicate the predicate.
- * @param object the object.
- * @throws IllegalArgumentException if an attribute is <code>null</code>.
- */
- public TripleImpl(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
- if (subject == null) {
- throw new IllegalArgumentException("Invalid subject: null");
- } else if (predicate == null) {
- throw new IllegalArgumentException("Invalid predicate: null");
- } else if (object == null) {
- throw new IllegalArgumentException("Invalid object: null");
- }
- this.subject = subject;
- this.predicate = predicate;
- this.object = object;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof Triple)) {
- return false;
- }
- final Triple other = (Triple) obj;
- if (!this.subject.equals(other.getSubject())) {
- return false;
- }
- if (!this.predicate.equals(other.getPredicate())) {
- return false;
- }
- if (!this.object.equals(other.getObject())) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- return (subject.hashCode() >> 1) ^ predicate.hashCode() ^ (object.hashCode() << 1);
- }
-
- @Override
- public BlankNodeOrIri getSubject() {
- return subject;
- }
-
- public Iri getPredicate() {
- return predicate;
- }
-
- public RdfTerm getObject() {
- return object;
- }
-
- @Override
- public String toString() {
- return subject + " " + predicate + " " + object + ".";
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImpl.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImpl.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImpl.java
deleted file mode 100644
index ded5097..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/TypedLiteralImpl.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.io.Serializable;
-
-import org.apache.commons.rdf.Iri;
-import org.apache.commons.rdf.Language;
-import org.apache.commons.rdf.Literal;
-
-/**
- *
- * @author reto
- */
-public class TypedLiteralImpl implements Literal, Serializable {
- private String lexicalForm;
- private Iri dataType;
- private int hashCode;
-
- /**
- * @param lexicalForm
- * @param dataType
- */
- public TypedLiteralImpl(String lexicalForm, Iri dataType) {
- this.lexicalForm = lexicalForm;
- this.dataType = dataType;
- this.hashCode = lexicalForm.hashCode()+dataType.hashCode();
- }
-
- public Iri getDataType() {
- return dataType;
- }
-
- /* (non-Javadoc)
- * @see org.apache.clerezza.rdf.core.LiteralNode#getLexicalForm()
- */
- @Override
- public String getLexicalForm() {
- return lexicalForm;
- }
-
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj instanceof Literal) {
- Literal other = (Literal) obj;
- if (other.getLanguage() != null) {
- return false;
- }
- boolean res = getDataType().equals(other.getDataType())
- && getLexicalForm().equals(other.getLexicalForm());
- return res;
- } else {
- return false;
- }
- }
-
- @Override
- public String toString() {
- StringBuffer result = new StringBuffer();
- result.append('\"');
- result.append(getLexicalForm());
- result.append('\"');
- result.append("^^");
- result.append(getDataType());
- return result.toString();
- }
-
- @Override
- public Language getLanguage() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedGraph.java
index 7812a76..f89ba89 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedGraph.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedGraph.java
@@ -31,6 +31,7 @@ import org.apache.clerezza.rdf.core.access.ReadOnlyException;
import org.apache.commons.rdf.ImmutableGraph;
import org.apache.commons.rdf.event.FilterTriple;
import org.apache.commons.rdf.event.GraphListener;
+import org.apache.commons.rdf.impl.utils.AbstractGraph;
/**
*
@@ -41,7 +42,7 @@ import org.apache.commons.rdf.event.GraphListener;
*
* @author tsuy
*/
-public class WriteBlockedGraph extends AbstractCollection<Triple>
+public class WriteBlockedGraph extends AbstractGraph
implements Graph {
private Graph triples;
@@ -51,12 +52,12 @@ public class WriteBlockedGraph extends AbstractCollection<Triple>
}
@Override
- public int size() {
+ protected int performSize() {
return triples.size();
}
@Override
- public Iterator<Triple> filter(final BlankNodeOrIri subject, final Iri predicate, final RdfTerm object) {
+ protected Iterator<Triple> performFilter(BlankNodeOrIri subject, Iri predicate, RdfTerm object) {
final Iterator<Triple> baseIter = triples.filter(subject, predicate, object);
return new Iterator<Triple>() {
@@ -110,22 +111,6 @@ public class WriteBlockedGraph extends AbstractCollection<Triple>
}
@Override
- public void addGraphListener(GraphListener listener, FilterTriple filter,
- long delay) {
- triples.addGraphListener(listener, filter, delay);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- triples.addGraphListener(listener, filter);
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- triples.removeGraphListener(listener);
- }
-
- @Override
public Iterator iterator() {
return filter(null, null, null);
}
@@ -134,4 +119,5 @@ public class WriteBlockedGraph extends AbstractCollection<Triple>
public ImmutableGraph getImmutableGraph() {
return this.triples.getImmutableGraph();
}
+
}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedMGraph.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedMGraph.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedMGraph.java
deleted file mode 100644
index 129a803..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/WriteBlockedMGraph.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl;
-
-import java.util.concurrent.locks.ReadWriteLock;
-import org.apache.commons.rdf.ImmutableGraph;
-import org.apache.clerezza.rdf.core.access.LockableMGraph;
-
-
-/**
-*
-* This is a wrapper object for <code>Graph</code>. If <code>SecurityManger</code>
-* is not <code>null</code> <code>TcManager</code> checks the <code>TcPermission</code>.
-* If read-only permissions are set this wrapper is used instead of <code>Graph</code>.
-*
-* @author tsuy
-*/
-public class WriteBlockedMGraph extends WriteBlockedGraph
- implements LockableMGraph {
-
- private LockableMGraph graph;
- /**
- * Creates a wrapper of <code>SimpleMGraph</code>
- */
- public WriteBlockedMGraph(LockableMGraph graph) {
- super(graph);
- this.graph = graph;
- }
-
- @Override
- public ReadWriteLock getLock() {
- return graph.getLock();
- }
-}
-
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcher.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcher.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcher.java
deleted file mode 100644
index 2ea5389..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphMatcher.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author reto
- *
- */
-public class GraphMatcher {
-
-
- private final static Logger log = LoggerFactory.getLogger(GraphMatcher.class);
-
- /**
- * get a mapping from g1 to g2 or null if the graphs are not isomorphic. The
- * returned map maps each <code>BNode</code>s from g1 to one
- * of g2. If the graphs are ground graphs the method return an empty map if
- * the ImmutableGraph are equals and null otherwise.
- * <p/>
- * NOTE: This method does not returned mapping from blank nodes to grounded
- * nodes, a bnode in g1 is not a vraiable that may match any node, but must
- * match a bnode in g2.
- * <p/>
- *
- * On the algorithm:<br/>
- * - In a first step it checked if every grounded triple in g1 matches one
- * in g2<br/>
- * - [optional] blank node blind matching</br>
- * - in a map mbng1 bnode of g1 is mapped to a set of of its
- * properties and inverse properties, this is the predicate and the object
- * or subject respectively, analoguosly in mbgn2 every bnode of g2<br/>
- * - based on the incoming and outgoing properties a hash is calculated for
- * each bnode, in the first step when calculating the hash aconstant value
- * is taken for the bnodes that might be subject or object in the (inverse properties)
- * - hash-classes:
- *
- * @param g1
- * @param g2
- * @return a Set of NodePairs
- */
- public static Map<BlankNode, BlankNode> getValidMapping(Graph og1, Graph og2) {
- Graph g1 = new SimpleMGraph(og1);
- Graph g2 = new SimpleMGraph(og2);
- if (!Utils.removeGrounded(g1,g2)) {
- return null;
- }
- final HashMatching hashMatching;
- try {
- hashMatching = new HashMatching(g1, g2);
- } catch (GraphNotIsomorphicException ex) {
- return null;
- }
- Map<BlankNode, BlankNode> matchings = hashMatching.getMatchings();
- if (g1.size() > 0) {
- //start trial an error matching
- //TODO (CLEREZZA-81) at least in the situation where one matching
- //group is big (approx > 5) we should switch back to hash-based matching
- //after a first guessed matching, rather than try all permutations
- Map<BlankNode, BlankNode> remainingMappings = trialAndErrorMatching(g1, g2, hashMatching.getMatchingGroups());
- if (remainingMappings == null) {
- return null;
- } else {
- matchings.putAll(remainingMappings);
- }
- }
- return matchings;
- }
-
- private static Map<BlankNode, BlankNode> trialAndErrorMatching(Graph g1, Graph g2,
- Map<Set<BlankNode>, Set<BlankNode>> matchingGroups) {
- if (log.isDebugEnabled()) {
- Set<BlankNode> bn1 = Utils.getBNodes(g1);
- log.debug("doing trial and error matching for {} bnodes, " +
- "in graphs of size: {}.", bn1.size(), g1.size());
- }
- Iterator<Map<BlankNode, BlankNode>> mappingIter
- = GroupMappingIterator.create(matchingGroups);
- while (mappingIter.hasNext()) {
- Map<BlankNode, BlankNode> map = mappingIter.next();
- if (checkMapping(g1, g2, map)) {
- return map;
- }
- }
- return null;
- }
-
- private static boolean checkMapping(Graph g1, Graph g2, Map<BlankNode, BlankNode> map) {
- for (Triple triple : g1) {
- if (!g2.contains(map(triple, map))) {
- return false;
- }
- }
- return true;
- }
-
- private static Triple map(Triple triple, Map<BlankNode, BlankNode> map) {
- final BlankNodeOrIri oSubject = triple.getSubject();
-
- BlankNodeOrIri subject = oSubject instanceof BlankNode ?
- map.get((BlankNode)oSubject) : oSubject;
-
- RdfTerm oObject = triple.getObject();
- RdfTerm object = oObject instanceof BlankNode ?
- map.get((BlankNode)oObject) : oObject;
- return new TripleImpl(subject, triple.getPredicate(), object);
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphNotIsomorphicException.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphNotIsomorphicException.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphNotIsomorphicException.java
deleted file mode 100644
index 99ae230..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GraphNotIsomorphicException.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-/**
- *
- * @author reto
- */
-class GraphNotIsomorphicException extends Exception {
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java
deleted file mode 100644
index a032963..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/GroupMappingIterator.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2010 reto.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * under the License.
- */
-
-package org.apache.clerezza.rdf.core.impl.graphmatching;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-/**
- * Iterates over all mappings from each element of every Set<T> to each
- * elemenent of their corresponding Set<U>.
- *
- * @author reto
- */
-class GroupMappingIterator<T,U> implements Iterator<Map<T, U>> {
-
- private Iterator<Map<T, U>> firstPartIter;
- private Map<T, U> currentFirstPart;
- final private Map<Set<T>, Set<U>> restMap;
- private Iterator<Map<T, U>> currentRestPartIter;
-
- static <T,U> Iterator<Map<T, U>> create(Map<Set<T>, Set<U>> matchingGroups) {
- if (matchingGroups.size() > 1) {
- return new GroupMappingIterator<T, U>(matchingGroups);
- } else {
- if (matchingGroups.size() == 0) {
- return new ArrayList<Map<T, U>>(0).iterator();
- }
- Map.Entry<Set<T>, Set<U>> entry = matchingGroups.entrySet().iterator().next();
- return new MappingIterator<T,U>(entry.getKey(),
- entry.getValue());
- }
- }
-
- private GroupMappingIterator(Map<Set<T>, Set<U>> matchingGroups) {
- if (matchingGroups.size() == 0) {
- throw new IllegalArgumentException("matchingGroups must not be empty");
- }
- restMap = new HashMap<Set<T>, Set<U>>();
- boolean first = true;
- for (Map.Entry<Set<T>, Set<U>> entry : matchingGroups.entrySet()) {
- if (first) {
- firstPartIter = new MappingIterator<T,U>(entry.getKey(),
- entry.getValue());
- first = false;
- } else {
- restMap.put(entry.getKey(), entry.getValue());
- }
- }
- currentRestPartIter = create(restMap);
- currentFirstPart = firstPartIter.next();
- }
-
- @Override
- public boolean hasNext() {
- return firstPartIter.hasNext() || currentRestPartIter.hasNext();
- }
-
- @Override
- public Map<T, U> next() {
- Map<T, U> restPart;
- if (currentRestPartIter.hasNext()) {
- restPart = currentRestPartIter.next();
- } else {
- if (firstPartIter.hasNext()) {
- currentFirstPart = firstPartIter.next();
- currentRestPartIter = create(restMap);
- restPart = currentRestPartIter.next();
- } else {
- throw new NoSuchElementException();
- }
- }
- Map<T, U> result = new HashMap<T, U>(restPart);
- result.putAll(currentFirstPart);
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Not supported.");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatching.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatching.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatching.java
deleted file mode 100644
index 7b3d540..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/HashMatching.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-
-import org.apache.clerezza.rdf.core.impl.graphmatching.collections.IntHashMap;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.BlankNodeOrIri;
-import org.apache.commons.rdf.RdfTerm;
-import org.apache.commons.rdf.Triple;
-import org.apache.commons.rdf.Graph;
-import org.apache.commons.rdf.Iri;
-import org.apache.clerezza.rdf.core.impl.TripleImpl;
-import org.apache.clerezza.rdf.core.impl.graphmatching.collections.IntIterator;
-
-/**
- *
- * @author reto
- */
-public class HashMatching {
-
- private Map<BlankNode, BlankNode> matchings = new HashMap<BlankNode, BlankNode>();
- private Map<Set<BlankNode>, Set<BlankNode>> matchingGroups;
-
- /**
- * tc1 and tc2 will be modified: the triples containing no unmatched bnode
- * will be removed
- *
- * @param tc1
- * @param tc2
- * @throws GraphNotIsomorphicException
- */
- HashMatching(Graph tc1, Graph tc2) throws GraphNotIsomorphicException {
- int foundMatchings = 0;
- int foundMatchingGroups = 0;
- Map<BlankNode, Integer> bNodeHashMap = new HashMap<BlankNode, Integer>();
- while (true) {
- bNodeHashMap = matchByHashes(tc1, tc2, bNodeHashMap);
- if (bNodeHashMap == null) {
- throw new GraphNotIsomorphicException();
- }
- if (matchings.size() == foundMatchings) {
- if (!(matchingGroups.size() > foundMatchingGroups)) {
- break;
- }
- }
- foundMatchings = matchings.size();
- foundMatchingGroups = matchingGroups.size();
- }
- }
-
- /**
- *
- * @return a map containing set of which each bnodes mappes one of the other set
- */
- public Map<Set<BlankNode>, Set<BlankNode>> getMatchingGroups() {
- return matchingGroups;
- }
-
- public Map<BlankNode, BlankNode> getMatchings() {
- return matchings;
- }
-
-
- private static IntHashMap<Set<BlankNode>> getHashNodes(Map<BlankNode,
- Set<Property>> bNodePropMap, Map<BlankNode, Integer> bNodeHashMap) {
- IntHashMap<Set<BlankNode>> result = new IntHashMap<Set<BlankNode>>();
- for (Map.Entry<BlankNode, Set<Property>> entry : bNodePropMap.entrySet()) {
- int hash = computeHash(entry.getValue(), bNodeHashMap);
- Set<BlankNode> bNodeSet = result.get(hash);
- if (bNodeSet == null) {
- bNodeSet = new HashSet<BlankNode>();
- result.put(hash,bNodeSet);
- }
- bNodeSet.add(entry.getKey());
- }
- return result;
- }
- /*
- * returns a Map from bnodes to hash that can be used for future
- * refinements, this could be separate for each ImmutableGraph.
- *
- * triples no longer containing an unmatched bnodes ae removed.
- *
- * Note that the matched node are not guaranteed to be equals, but only to
- * be the correct if the graphs are isomorphic.
- */
- private Map<BlankNode, Integer> matchByHashes(Graph g1, Graph g2,
- Map<BlankNode, Integer> bNodeHashMap) {
- Map<BlankNode, Set<Property>> bNodePropMap1 = getBNodePropMap(g1);
- Map<BlankNode, Set<Property>> bNodePropMap2 = getBNodePropMap(g2);
- IntHashMap<Set<BlankNode>> hashNodeMap1 = getHashNodes(bNodePropMap1, bNodeHashMap);
- IntHashMap<Set<BlankNode>> hashNodeMap2 = getHashNodes(bNodePropMap2, bNodeHashMap);
- if (!hashNodeMap1.keySet().equals(hashNodeMap2.keySet())) {
- return null;
- }
-
- matchingGroups = new HashMap<Set<BlankNode>, Set<BlankNode>>();
- IntIterator hashIter = hashNodeMap1.keySet().intIterator();
- while (hashIter.hasNext()) {
- int hash = hashIter.next();
- Set<BlankNode> nodes1 = hashNodeMap1.get(hash);
- Set<BlankNode> nodes2 = hashNodeMap2.get(hash);
- if (nodes1.size() != nodes2.size()) {
- return null;
- }
- if (nodes1.size() != 1) {
- matchingGroups.put(nodes1, nodes2);
- continue;
- }
- final BlankNode bNode1 = nodes1.iterator().next();
- final BlankNode bNode2 = nodes2.iterator().next();
- matchings.put(bNode1,bNode2);
- //in the graphs replace node occurences with grounded node,
- BlankNodeOrIri mappedNode = new MappedNode(bNode1, bNode2);
- replaceNode(g1,bNode1, mappedNode);
- replaceNode(g2, bNode2, mappedNode);
- //remove grounded triples
- if (!Utils.removeGrounded(g1,g2)) {
- return null;
- }
- }
- Map<BlankNode, Integer> result = new HashMap<BlankNode, Integer>();
- addInverted(result, hashNodeMap1);
- addInverted(result, hashNodeMap2);
- return result;
- }
- private static int computeHash(Set<Property> propertySet, Map<BlankNode, Integer> bNodeHashMap) {
- int result = 0;
- for (Property property : propertySet) {
- result += property.hashCode(bNodeHashMap);
- }
- return result;
- }
- private static Map<BlankNode, Set<Property>> getBNodePropMap(Graph g) {
- Set<BlankNode> bNodes = Utils.getBNodes(g);
- Map<BlankNode, Set<Property>> result = new HashMap<BlankNode, Set<Property>>();
- for (BlankNode bNode : bNodes) {
- result.put(bNode, getProperties(bNode, g));
- }
- return result;
- }
- private static Set<Property> getProperties(BlankNode bNode, Graph g) {
- Set<Property> result = new HashSet<Property>();
- Iterator<Triple> ti = g.filter(bNode, null, null);
- while (ti.hasNext()) {
- Triple triple = ti.next();
- result.add(new ForwardProperty(triple.getPredicate(), triple.getObject()));
- }
- ti = g.filter(null, null, bNode);
- while (ti.hasNext()) {
- Triple triple = ti.next();
- result.add(new BackwardProperty(triple.getSubject(), triple.getPredicate()));
- }
- return result;
- }
- private static int nodeHash(RdfTerm resource, Map<BlankNode, Integer> bNodeHashMap) {
- if (resource instanceof BlankNode) {
- Integer mapValue = bNodeHashMap.get((BlankNode)resource);
- if (mapValue == null) {
- return 0;
- } else {
- return mapValue;
- }
- } else {
- return resource.hashCode();
- }
- }
- private static void replaceNode(Graph graph, BlankNode bNode, BlankNodeOrIri replacementNode) {
- Set<Triple> triplesToRemove = new HashSet<Triple>();
- for (Triple triple : graph) {
- Triple replacementTriple = getReplacement(triple, bNode, replacementNode);
- if (replacementTriple != null) {
- triplesToRemove.add(triple);
- graph.add(replacementTriple);
- }
- }
- graph.removeAll(triplesToRemove);
- }
- private static Triple getReplacement(Triple triple, BlankNode bNode, BlankNodeOrIri replacementNode) {
- if (triple.getSubject().equals(bNode)) {
- if (triple.getObject().equals(bNode)) {
- return new TripleImpl(replacementNode, triple.getPredicate(), replacementNode);
- } else {
- return new TripleImpl(replacementNode, triple.getPredicate(), triple.getObject());
- }
- } else {
- if (triple.getObject().equals(bNode)) {
- return new TripleImpl(triple.getSubject(), triple.getPredicate(), replacementNode);
- } else {
- return null;
- }
- }
- }
- private static void addInverted(Map<BlankNode, Integer> result, IntHashMap<Set<BlankNode>> hashNodeMap) {
- for (int hash : hashNodeMap.keySet()) {
- Set<BlankNode> bNodes = hashNodeMap.get(hash);
- for (BlankNode bNode : bNodes) {
- result.put(bNode, hash);
- }
- }
- }
-
- private static class BackwardProperty implements Property {
- private BlankNodeOrIri subject;
- private Iri predicate;
-
- public BackwardProperty(BlankNodeOrIri subject, Iri predicate) {
- this.subject = subject;
- this.predicate = predicate;
- }
-
- @Override
- public int hashCode(Map<BlankNode, Integer> bNodeHashMap) {
- return 0xFF ^ predicate.hashCode() ^ nodeHash(subject, bNodeHashMap);
- }
-
- }
- private static class ForwardProperty implements Property {
- private Iri predicate;
- private RdfTerm object;
-
- public ForwardProperty(Iri predicate, RdfTerm object) {
- this.predicate = predicate;
- this.object = object;
- }
-
- @Override
- public int hashCode(Map<BlankNode, Integer> bNodeHashMap) {
- return predicate.hashCode() ^ nodeHash(object, bNodeHashMap);
- }
- }
- private static class MappedNode implements BlankNodeOrIri {
- private BlankNode bNode1, bNode2;
-
- public MappedNode(BlankNode bNode1, BlankNode bNode2) {
- this.bNode1 = bNode1;
- this.bNode2 = bNode2;
- }
-
- }
- private static interface Property {
- public int hashCode(Map<BlankNode, Integer> bNodeHashMap);
- }
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/MappingIterator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/MappingIterator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/MappingIterator.java
deleted file mode 100644
index 3027f27..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/MappingIterator.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package org.apache.clerezza.rdf.core.impl.graphmatching;
-
-/*
- * 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.
- */
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * An iterator over all possible mapping beetween the elemnets of two sets of
- * the same size, each mapping maps each element from set1 to a disctinct one of
- * set2.
- *
- *
- *
- * @author reto
- */
-class MappingIterator<T,U> implements Iterator<Map<T, U>> {
-
- private List<T> list1;
- private Iterator<List<U>> permutationList2Iterator;
-
-
- public MappingIterator(Set<T> set1, Set<U> set2) {
- if (set1.size() != set2.size()) {
- throw new IllegalArgumentException();
- }
- this.list1 = new ArrayList<T>(set1);
- permutationList2Iterator = new PermutationIterator<U>(
- new ArrayList<U>(set2));
- }
-
- @Override
- public boolean hasNext() {
- return permutationList2Iterator.hasNext();
- }
-
- @Override
- public Map<T, U> next() {
- List<U> list2 = permutationList2Iterator.next();
- Map<T, U> result = new HashMap<T, U>(list1.size());
- for (int i = 0; i < list1.size(); i++) {
- result.put(list1.get(i), list2.get(i));
- }
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Not supported.");
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java
deleted file mode 100644
index 92dffca..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/PermutationIterator.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.clerezza.rdf.core.impl.graphmatching;
-
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- *
- * An Iterator over all permuations of a list.
- *
- * @author reto
- */
-class PermutationIterator<T> implements Iterator<List<T>> {
-
- private Iterator<List<T>> restIterator;
- private List<T> list;
- private List<T> next;
- int posInList = 0; //the position of the last element of next returned list
- //with list, this is the one excluded from restIterator
-
- PermutationIterator(List<T> list) {
- this.list = Collections.unmodifiableList(list);
- if (list.size() > 1) {
- createRestList();
- }
- prepareNext();
- }
-
- @Override
- public boolean hasNext() {
- return next != null;
- }
-
- @Override
- public List<T> next() {
- List<T> result = next;
- if (result == null) {
- throw new NoSuchElementException();
- }
- prepareNext();
- return result;
- }
-
- @Override
- public void remove() {
- throw new UnsupportedOperationException("Not supported");
- }
-
- private void createRestList() {
- List<T> restList = new ArrayList<T>(list);
- restList.remove(posInList);
- restIterator = new PermutationIterator<T>(restList);
- }
-
- private void prepareNext() {
- next = getNext();
-
- }
- private List<T> getNext() {
- if (list.size() == 0) {
- return null;
- }
- if (list.size() == 1) {
- if (posInList++ == 0) {
- return new ArrayList<T>(list);
- } else {
- return null;
- }
- } else {
- if (!restIterator.hasNext()) {
- if (posInList < (list.size()-1)) {
- posInList++;
- createRestList();
- } else {
- return null;
- }
- }
- List<T> result = restIterator.next();
- result.add(list.get(posInList));
- return result;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils.java
deleted file mode 100644
index f8400fd..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/Utils.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package org.apache.clerezza.rdf.core.impl.graphmatching;
-/*
- *
- * 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.
- *
-*/
-
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.commons.rdf.BlankNode;
-import org.apache.commons.rdf.Triple;
-
-public class Utils {
-
- static Set<BlankNode> getBNodes(Collection<Triple> s) {
- Set<BlankNode> result = new HashSet<BlankNode>();
- for (Triple triple : s) {
- if (triple.getSubject() instanceof BlankNode) {
- result.add((BlankNode) triple.getSubject());
- }
- if (triple.getObject() instanceof BlankNode) {
- result.add((BlankNode) triple.getObject());
- }
- }
- return result;
- }
-
- /**
- * removes the common grounded triples from s1 and s2. returns false if
- * a grounded triple is not in both sets, true otherwise
- */
- static boolean removeGrounded(Collection<Triple> s1, Collection<Triple> s2) {
- Iterator<Triple> triplesIter = s1.iterator();
- while (triplesIter.hasNext()) {
- Triple triple = triplesIter.next();
- if (!isGrounded(triple)) {
- continue;
- }
- if (!s2.remove(triple)) {
- return false;
- }
- triplesIter.remove();
- }
- //for efficiency we might skip this (redefine method)
- for (Triple triple : s2) {
- if (isGrounded(triple)) {
- return false;
- }
- }
- return true;
- }
-
- private static boolean isGrounded(Triple triple) {
- if (triple.getSubject() instanceof BlankNode) {
- return false;
- }
- if (triple.getObject() instanceof BlankNode) {
- return false;
- }
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashMap.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashMap.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashMap.java
deleted file mode 100644
index 474627e..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashMap.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Note: originally released under the GNU LGPL v2.1,
- * but rereleased by the original author under the ASF license (above).
- */
-
-package org.apache.clerezza.rdf.core.impl.graphmatching.collections;
-
-
-
-/**
- * <p>A hash map that uses primitive ints for the key rather than objects.</p>
- *
- * <p>Note that this class is for internal optimization purposes only, and may
- * not be supported in future releases of Jakarta Commons Lang. Utilities of
- * this sort may be included in future releases of Jakarta Commons Collections.</p>
- *
- * @author Justin Couch
- * @author Alex Chaffee (alex@apache.org)
- * @author Stephen Colebourne
- * @since 2.0
- * @version $Revision: 1.2 $
- * @see java.util.HashMap
- */
-public class IntHashMap<T> {
-
-
- private IntSet keySet = new IntHashSet();
-
- /**
- * The hash table data.
- */
- private transient Entry<T> table[];
-
- /**
- * The total number of entries in the hash table.
- */
- private transient int count;
-
- /**
- * The table is rehashed when its size exceeds this threshold. (The
- * value of this field is (int)(capacity * loadFactor).)
- *
- * @serial
- */
- private int threshold;
-
- /**
- * The load factor for the hashtable.
- *
- * @serial
- */
- private float loadFactor;
-
- /**
- * <p>Innerclass that acts as a datastructure to create a new entry in the
- * table.</p>
- */
- private static class Entry<T> {
- int hash;
- int key;
- T value;
- Entry<T> next;
-
- /**
- * <p>Create a new entry with the given values.</p>
- *
- * @param hash The code used to hash the object with
- * @param key The key used to enter this in the table
- * @param value The value for this key
- * @param next A reference to the next entry in the table
- */
- protected Entry(int hash, int key, T value, Entry<T> next) {
- this.hash = hash;
- this.key = key;
- this.value = value;
- this.next = next;
- }
- }
-
- /**
- * <p>Constructs a new, empty hashtable with a default capacity and load
- * factor, which is <code>20</code> and <code>0.75</code> respectively.</p>
- */
- public IntHashMap() {
- this(20, 0.75f);
- }
-
- /**
- * <p>Constructs a new, empty hashtable with the specified initial capacity
- * and default load factor, which is <code>0.75</code>.</p>
- *
- * @param initialCapacity the initial capacity of the hashtable.
- * @throws IllegalArgumentException if the initial capacity is less
- * than zero.
- */
- public IntHashMap(int initialCapacity) {
- this(initialCapacity, 0.75f);
- }
-
- /**
- * <p>Constructs a new, empty hashtable with the specified initial
- * capacity and the specified load factor.</p>
- *
- * @param initialCapacity the initial capacity of the hashtable.
- * @param loadFactor the load factor of the hashtable.
- * @throws IllegalArgumentException if the initial capacity is less
- * than zero, or if the load factor is nonpositive.
- */
- public IntHashMap(int initialCapacity, float loadFactor) {
- super();
- if (initialCapacity < 0) {
- throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
- }
- if (loadFactor <= 0) {
- throw new IllegalArgumentException("Illegal Load: " + loadFactor);
- }
- if (initialCapacity == 0) {
- initialCapacity = 1;
- }
-
- this.loadFactor = loadFactor;
- table = new Entry[initialCapacity];
- threshold = (int) (initialCapacity * loadFactor);
- }
-
- /**
- * <p>Returns the number of keys in this hashtable.</p>
- *
- * @return the number of keys in this hashtable.
- */
- public int size() {
- return count;
- }
-
- /**
- * <p>Tests if this hashtable maps no keys to values.</p>
- *
- * @return <code>true</code> if this hashtable maps no keys to values;
- * <code>false</code> otherwise.
- */
- public boolean isEmpty() {
- return count == 0;
- }
-
- /**
- * <p>Tests if some key maps into the specified value in this hashtable.
- * This operation is more expensive than the <code>containsKey</code>
- * method.</p>
- *
- * <p>Note that this method is identical in functionality to containsValue,
- * (which is part of the Map interface in the collections framework).</p>
- *
- * @param value a value to search for.
- * @return <code>true</code> if and only if some key maps to the
- * <code>value</code> argument in this hashtable as
- * determined by the <tt>equals</tt> method;
- * <code>false</code> otherwise.
- * @throws NullPointerException if the value is <code>null</code>.
- * @see #containsKey(int)
- * @see #containsValue(Object)
- * @see java.util.Map
- */
- public boolean contains(Object value) {
- if (value == null) {
- throw new NullPointerException();
- }
-
- Entry tab[] = table;
- for (int i = tab.length; i-- > 0;) {
- for (Entry e = tab[i]; e != null; e = e.next) {
- if (e.value.equals(value)) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * <p>Returns <code>true</code> if this HashMap maps one or more keys
- * to this value.</p>
- *
- * <p>Note that this method is identical in functionality to contains
- * (which predates the Map interface).</p>
- *
- * @param value value whose presence in this HashMap is to be tested.
- * @see java.util.Map
- * @since JDK1.2
- */
- public boolean containsValue(Object value) {
- return contains(value);
- }
-
- /**
- * <p>Tests if the specified object is a key in this hashtable.</p>
- *
- * @param key possible key.
- * @return <code>true</code> if and only if the specified object is a
- * key in this hashtable, as determined by the <tt>equals</tt>
- * method; <code>false</code> otherwise.
- * @see #contains(Object)
- */
- public boolean containsKey(int key) {
- Entry tab[] = table;
- int hash = key;
- int index = (hash & 0x7FFFFFFF) % tab.length;
- for (Entry e = tab[index]; e != null; e = e.next) {
- if (e.hash == hash) {
- return true;
- }
- }
- return false;
- }
-
- /**
- * <p>Returns the value to which the specified key is mapped in this map.</p>
- *
- * @param key a key in the hashtable.
- * @return the value to which the key is mapped in this hashtable;
- * <code>null</code> if the key is not mapped to any value in
- * this hashtable.
- * @see #put(int, Object)
- */
- public T get(int key) {
- Entry<T> tab[] = table;
- int hash = key;
- int index = (hash & 0x7FFFFFFF) % tab.length;
- for (Entry<T> e = tab[index]; e != null; e = e.next) {
- if (e.hash == hash) {
- return e.value;
- }
- }
- return null;
- }
-
- /**
- * <p>Increases the capacity of and internally reorganizes this
- * hashtable, in order to accommodate and access its entries more
- * efficiently.</p>
- *
- * <p>This method is called automatically when the number of keys
- * in the hashtable exceeds this hashtable's capacity and load
- * factor.</p>
- */
- protected void rehash() {
- int oldCapacity = table.length;
- Entry<T> oldMap[] = table;
-
- int newCapacity = oldCapacity * 2 + 1;
- Entry<T> newMap[] = new Entry[newCapacity];
-
- threshold = (int) (newCapacity * loadFactor);
- table = newMap;
-
- for (int i = oldCapacity; i-- > 0;) {
- for (Entry<T> old = oldMap[i]; old != null;) {
- Entry<T> e = old;
- old = old.next;
-
- int index = (e.hash & 0x7FFFFFFF) % newCapacity;
- e.next = newMap[index];
- newMap[index] = e;
- }
- }
- }
-
- /**
- * <p>Maps the specified <code>key</code> to the specified
- * <code>value</code> in this hashtable. The key cannot be
- * <code>null</code>. </p>
- *
- * <p>The value can be retrieved by calling the <code>get</code> method
- * with a key that is equal to the original key.</p>
- *
- * @param key the hashtable key.
- * @param value the value.
- * @return the previous value of the specified key in this hashtable,
- * or <code>null</code> if it did not have one.
- * @throws NullPointerException if the key is <code>null</code>.
- * @see #get(int)
- */
- public Object put(int key, T value) {
- keySet.add(key);
- // Makes sure the key is not already in the hashtable.
- Entry<T> tab[] = table;
- int hash = key;
- int index = (hash & 0x7FFFFFFF) % tab.length;
- for (Entry<T> e = tab[index]; e != null; e = e.next) {
- if (e.hash == hash) {
- T old = e.value;
- e.value = value;
- return old;
- }
- }
-
- if (count >= threshold) {
- // Rehash the table if the threshold is exceeded
- rehash();
-
- tab = table;
- index = (hash & 0x7FFFFFFF) % tab.length;
- }
-
- // Creates the new entry.
- Entry<T> e = new Entry<T>(hash, key, value, tab[index]);
- tab[index] = e;
- count++;
- return null;
- }
-
- /**
- * <p>Removes the key (and its corresponding value) from this
- * hashtable.</p>
- *
- * <p>This method does nothing if the key is not present in the
- * hashtable.</p>
- *
- * @param key the key that needs to be removed.
- * @return the value to which the key had been mapped in this hashtable,
- * or <code>null</code> if the key did not have a mapping.
- */
- /*public Object remove(int key) {
- Entry tab[] = table;
- int hash = key;
- int index = (hash & 0x7FFFFFFF) % tab.length;
- for (Entry e = tab[index], prev = null; e != null; prev = e, e = e.next) {
- if (e.hash == hash) {
- if (prev != null) {
- prev.next = e.next;
- } else {
- tab[index] = e.next;
- }
- count--;
- Object oldValue = e.value;
- e.value = null;
- return oldValue;
- }
- }
- return null;
- }*/
-
- /**
- * <p>Clears this hashtable so that it contains no keys.</p>
- */
- public synchronized void clear() {
- keySet.clear();
- Entry tab[] = table;
- for (int index = tab.length; --index >= 0;) {
- tab[index] = null;
- }
- count = 0;
- }
-
- public IntSet keySet() {
- return keySet;
- }
-
-
-
-}
-
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashSet.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashSet.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashSet.java
deleted file mode 100644
index 00e8517..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntHashSet.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.clerezza.rdf.core.impl.graphmatching.collections;
-
-import java.util.HashSet;
-import java.util.Iterator;
-
-/**
- * This is currently just a placeholder implementation based onm HashSet<Integer>
- * an efficient implementation is to store the primitives directly.
- *
- * @author reto
- */
-public class IntHashSet extends HashSet<Integer> implements IntSet {
-
- @Override
- public IntIterator intIterator() {
- final Iterator<Integer> base = iterator();
- return new IntIterator() {
-
- @Override
- public int nextInt() {
- return base.next();
- }
-
- @Override
- public boolean hasNext() {
- return base.hasNext();
- }
-
- @Override
- public Integer next() {
- return base.next();
- }
-
- @Override
- public void remove() {
- base.remove();
- }
- };
- }
-
- @Override
- public void add(int i) {
- super.add((Integer)i);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntIterator.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntIterator.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntIterator.java
deleted file mode 100644
index a2f189a..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntIterator.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.clerezza.rdf.core.impl.graphmatching.collections;
-
-import java.util.Iterator;
-
-
-/**
- * An iterator allowing to iterate over ints, Iterator<Integer> is extended for
- * compatibility, however accessing nextInt allows faster implementations.
- *
- * @author reto
- */
-public interface IntIterator extends Iterator<Integer> {
- public int nextInt();
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntSet.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntSet.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntSet.java
deleted file mode 100644
index 115f15d..0000000
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/graphmatching/collections/IntSet.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.clerezza.rdf.core.impl.graphmatching.collections;
-
-import java.util.Set;
-
-/**
- * A IntSet allows directly adding primitive ints to a set, Set<Integer> is
- * extended, but accessingt he respective methods is less efficient.
- *
- * @author reto
- */
-public interface IntSet extends Set<Integer> {
- /**
- *
- * @return an iterator over the primitive int
- */
- public IntIterator intIterator();
-
- public void add(int i);
-}
http://git-wip-us.apache.org/repos/asf/clerezza/blob/e5531d96/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/PrivilegedGraphWrapper.java
----------------------------------------------------------------------
diff --git a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/PrivilegedGraphWrapper.java b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/PrivilegedGraphWrapper.java
index 97547c0..bde1f16 100644
--- a/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/PrivilegedGraphWrapper.java
+++ b/rdf.core/src/main/java/org/apache/clerezza/rdf/core/impl/util/PrivilegedGraphWrapper.java
@@ -22,7 +22,8 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
import java.util.Iterator;
-import org.apache.clerezza.rdf.core.impl.SimpleImmutableGraph;
+import java.util.concurrent.locks.ReadWriteLock;
+import org.apache.commons.rdf.impl.utils.simple.SimpleImmutableGraph;
import org.apache.commons.rdf.BlankNodeOrIri;
import org.apache.commons.rdf.RdfTerm;
import org.apache.commons.rdf.Triple;
@@ -204,18 +205,8 @@ public class PrivilegedGraphWrapper implements Graph {
}
@Override
- public void addGraphListener(GraphListener listener, FilterTriple filter, long delay) {
- graph.addGraphListener(listener, filter, delay);
- }
-
- @Override
- public void addGraphListener(GraphListener listener, FilterTriple filter) {
- graph.addGraphListener(listener, filter);
- }
-
- @Override
- public void removeGraphListener(GraphListener listener) {
- graph.removeGraphListener(listener);
+ public ReadWriteLock getLock() {
+ return graph.getLock();
}
private static class PriviledgedTripleIterator implements Iterator<Triple> {