You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by rw...@apache.org on 2012/02/24 14:27:36 UTC
svn commit: r1293242 - in /incubator/stanbol/trunk/commons/ldpath/clerezza:
pom.xml
src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java
Author: rwesten
Date: Fri Feb 24 13:27:35 2012
New Revision: 1293242
URL: http://svn.apache.org/viewvc?rev=1293242&view=rev
Log:
The Clerezza RDFBackend now supports type conversions for the **value() methods. e.g. it now returns an integer for a plain literal with a value such as "1.0"
This is the expected behaviour of the RDFBackend interface.
Implementation is done by extending AbstractBackend of the ldpath-core module und forwaring all calls with Resources that are not instanceof TypedLiteral.
Modified:
incubator/stanbol/trunk/commons/ldpath/clerezza/pom.xml
incubator/stanbol/trunk/commons/ldpath/clerezza/src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java
Modified: incubator/stanbol/trunk/commons/ldpath/clerezza/pom.xml
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/ldpath/clerezza/pom.xml?rev=1293242&r1=1293241&r2=1293242&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/ldpath/clerezza/pom.xml (original)
+++ incubator/stanbol/trunk/commons/ldpath/clerezza/pom.xml Fri Feb 24 13:27:35 2012
@@ -76,6 +76,10 @@
<groupId>at.newmedialab.ldpath</groupId>
<artifactId>ldpath-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>at.newmedialab.ldpath</groupId>
+ <artifactId>ldpath-core-bundle</artifactId>
+ </dependency>
<!-- Commons -->
<dependency>
<groupId>commons-collections</groupId>
@@ -104,11 +108,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>at.newmedialab.ldpath</groupId>
- <artifactId>ldpath-core-bundle</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.apache.stanbol</groupId>
<artifactId>org.apache.stanbol.commons.indexedgraph</artifactId>
<scope>test</scope>
Modified: incubator/stanbol/trunk/commons/ldpath/clerezza/src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/commons/ldpath/clerezza/src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java?rev=1293242&r1=1293241&r2=1293242&view=diff
==============================================================================
--- incubator/stanbol/trunk/commons/ldpath/clerezza/src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java (original)
+++ incubator/stanbol/trunk/commons/ldpath/clerezza/src/main/java/org/apache/stanbol/commons/ldpath/clerezza/ClerezzaBackend.java Fri Feb 24 13:27:35 2012
@@ -45,6 +45,7 @@ import org.apache.clerezza.rdf.core.Trip
import org.apache.clerezza.rdf.core.TypedLiteral;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.PlainLiteralImpl;
+import org.apache.clerezza.rdf.core.impl.SimpleLiteralFactory;
import org.apache.clerezza.rdf.core.impl.TypedLiteralImpl;
import org.apache.clerezza.rdf.core.impl.util.W3CDateFormat;
import org.apache.commons.collections.BidiMap;
@@ -53,15 +54,21 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.newmedialab.ldpath.api.backend.RDFBackend;
+import at.newmedialab.ldpath.model.backend.AbstractBackend;
/**
* Clerezza based implementation of {@link RDFBackend} interface. This implementation uses the
- * {@link Resource} objects of Clerezza as processing unit RDFBackend.
+ * {@link Resource} objects of Clerezza as processing unit RDFBackend.<p>
*
- * @author anil.sinaci
+ * For type conversions of {@link TypedLiteral}s the {@link LiteralFactory}
+ * of Clerezza is used. In case parsed nodes are not {@link TypedLiteral} the
+ * super implementations of {@link AbstractBackend} are called as such also
+ * support converting values based on the string representation.
*
+ * @author anil.sinaci
+ * @author Rupert Westenthaler
*/
-public class ClerezzaBackend implements RDFBackend<Resource> {
+public class ClerezzaBackend extends AbstractBackend<Resource> implements RDFBackend<Resource> {
private static final Logger logger = LoggerFactory.getLogger(ClerezzaBackend.class);
@@ -172,7 +179,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return LiteralFactory.getInstance().createObject(Double.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.doubleValue(resource);
}
}
@@ -247,7 +254,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Long.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.longValue(resource);
}
}
@@ -267,7 +274,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Boolean.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.booleanValue(resource);
}
}
@@ -276,7 +283,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Date.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.dateTimeValue(resource);
}
}
@@ -285,7 +292,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Date.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.dateValue(resource);
}
}
@@ -294,7 +301,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Date.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.timeValue(resource);
}
}
@@ -303,7 +310,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Float.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.floatValue(resource);
}
}
@@ -312,7 +319,7 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(Integer.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.intValue(resource);
}
}
@@ -321,23 +328,16 @@ public class ClerezzaBackend implements
if (resource instanceof TypedLiteral) {
return lf.createObject(BigInteger.class, (TypedLiteral) resource);
} else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
+ return super.integerValue(resource);
}
}
@Override
public BigDecimal decimalValue(Resource resource) {
- if (resource instanceof TypedLiteral) {
- try {
- return lf.createObject(BigDecimal.class, (TypedLiteral) resource);
- } catch (NoConvertorException e) {
- //currently there is no converter for BigDecimal in clerezza
- //so as a workaround use the lexical form
- return new BigDecimal(((TypedLiteral)resource).getLexicalForm());
- }
- } else {
- throw new IllegalArgumentException("Resource " + resource.toString() + " is not a TypedLiteral");
- }
+ //currently there is no converter for BigDecimal in clerezza
+ //so as a workaround use the lexical form (as provided by the super
+ //implementation
+ return super.decimalValue(resource);
}
@Override