Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
</distributionManagement>

<properties>
<rdf4j.version>2.5.2</rdf4j.version>
<slf4j.version>1.7.9</slf4j.version>
<rdf4j.version>5.0.2</rdf4j.version>
<slf4j.version>2.0.16</slf4j.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand Down Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -144,15 +144,15 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<version>3.10.1</version>
<configuration>
<failOnError>true</failOnError>
<doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
<!-- doclet>ch.raffael.doclets.pegdown.PegdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.pegdown-doclet</groupId>
<artifactId>pegdown-doclet</artifactId>
<version>1.3</version>
</docletArtifact>
</docletArtifact -->
<useStandardDocletOptions>true</useStandardDocletOptions>
</configuration>
</plugin>
Expand Down Expand Up @@ -196,10 +196,10 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -209,7 +209,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
Expand Down Expand Up @@ -306,7 +305,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.9</version>
<version>3.10.1</version>
<reportSets>
<reportSet>
<reports>
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/org/cyberborean/rdfbeans/RDFBeanManagerContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.cyberborean.rdfbeans.reflect.RDFBeanInfo;
import org.cyberborean.rdfbeans.reflect.SubjectProperty;
import org.cyberborean.rdfbeans.util.LockKeeper;
import org.eclipse.rdf4j.RDF4JException;
import org.eclipse.rdf4j.common.exception.RDF4JException;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
Expand Down Expand Up @@ -238,57 +238,63 @@ public <T> T get(String stringId, Class<T> rdfBeanClass) throws RDFBeanException
* If the class is not a valid RDFBean class
* @throws RepositoryException
*/
public <T> CloseableIteration<T, Exception> getAll(final Class<T> rdfBeanClass)
public <T> CloseableIteration<T> getAll(final Class<T> rdfBeanClass)
throws RDFBeanException, RepositoryException {
//public <T> CloseableIteration<T, Exception> getAll(final Class<T> rdfBeanClass)
// throws RDFBeanException, RepositoryException {
RDFBeanInfo rbi = RDFBeanInfo.get(rdfBeanClass);
IRI type = rbi.getRDFType();
if (type == null) {
return new CloseableIteration<T, Exception>() {
//return new CloseableIteration<T, Exception>() {
return new CloseableIteration<T>() {

@Override
public boolean hasNext() throws Exception {
public boolean hasNext() {
return false;
}

@Override
public T next() throws Exception {
public T next() {
return null;
}

@Override
public void remove() throws Exception {
public void remove() {
throw new UnsupportedOperationException();
}

@Override
public void close() throws Exception {
public void close() {
}

};
}

final CloseableIteration<Statement, RepositoryException> sts = connectionPool.getConnection()
final CloseableIteration<Statement> sts = connectionPool.getConnection()
.getStatements(null, RDF.TYPE, type, false, (IRI)context);
//final CloseableIteration<Statement, RepositoryException> sts = connectionPool.getConnection()
// .getStatements(null, RDF.TYPE, type, false, (IRI)context);

return new CloseableIteration<T, Exception>() {
//return new CloseableIteration<T, Exception>() {
return new CloseableIteration<T>() {

@Override
public boolean hasNext() throws Exception {
public boolean hasNext() {
return sts.hasNext();
}

@Override
public T next() throws Exception {
public T next() {
return _get(sts.next().getSubject(), rdfBeanClass);
}

@Override
public void remove() throws Exception {
public void remove() {
throw new UnsupportedOperationException();
}

@Override
public void close() throws Exception {
public void close() {
sts.close();
}
};
Expand Down Expand Up @@ -316,8 +322,6 @@ public boolean isResourceExist(Resource r) throws RepositoryException {
*
* @param r
* Resource IRI or BNode
* @param context
* RDF4J context
* @return true, if the model contains the statements with the given
* resource subject and RDF type of that resource matches one
* specified in {@link RDFBean} annotation of the given class.
Expand Down Expand Up @@ -680,7 +684,7 @@ private void fireObjectCreated(Object object, Class<?> cls, Resource resource) {
*
* @return the current ClassLoader instance
*
* @see setClassLoader(ClassLoader)
* see setClassLoader(ClassLoader)
*/
public ClassLoader getClassLoader() {
return unmarshaller.getClassLoader();
Expand All @@ -691,7 +695,7 @@ public ClassLoader getClassLoader() {
*
* @return the datatypeMapper
*
* @see setDatatypeMapper(DatatypeMapper)
* see setDatatypeMapper(DatatypeMapper)
*/
public DatatypeMapper getDatatypeMapper() {
return marshaller.getDatatypeMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
*
* Applied to: Class or interface declaration <br>
* Value: String or String array (required)
*
*
* `@RDFNamespaces` annotation specifies one or more RDF namespace prefixes in
* the format `<prefix> = <uri>`
*
* Examples:
* ---------
* ```
* {@literal @}RDFNamespaces("owl = http://www.w3.org/2002/07/owl#");
* ```
*
* ```
* {@literal @}RDFNamespaces({
* "foaf = http://xmlns.com/foaf/0.1/",
* "persons = http://rdfbeans.viceversatech.com/test-ontology/persons/"
* });
* ```
*
*/
///
///
/// Applied to: Class or interface declaration <br>
/// Value: String or String array (required)
///
///
/// `@RDFNamespaces` annotation specifies one or more RDF namespace prefixes in
/// the format `<prefix> = <uri>`
///
/// Examples:
/// ---------
/// ```
/// {@literal @}RDFNamespaces("owl = http://www.w3.org/2002/07/owl#");
/// ```
///
/// ```
/// {@literal @}RDFNamespaces({
/// "foaf = http://xmlns.com/foaf/0.1/",
/// "persons = http://rdfbeans.viceversatech.com/test-ontology/persons/"
/// });
/// ```
///
///
@Target({ElementType.TYPE, ElementType.PACKAGE})
@Retention(RetentionPolicy.RUNTIME)
public @interface RDFNamespaces {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class DateUtils {
static final SimpleDateFormat ISO8601DateFormat;
static final SimpleDateFormat ISO8601DateFormat2;
static final SimpleDateFormat ISO8601DateFormat3;
static final SimpleDateFormat ISO8601DateOnlyFormat;

static final DateFormat[] dateformats;

Expand All @@ -31,10 +32,15 @@ public class DateUtils {
.getDateTimeInstance();
ISO8601DateFormat3.applyPattern("yyyy-MM-dd'T'HH:mmX");

ISO8601DateOnlyFormat = (SimpleDateFormat) DateFormat
.getDateTimeInstance();
ISO8601DateOnlyFormat.applyPattern("yyyy-MM-dd");

dateformats = new DateFormat[] {
ISO8601DateFormat,
ISO8601DateFormat2,
ISO8601DateFormat3,
ISO8601DateOnlyFormat,
DateFormat.getInstance(),
DateFormat.getDateInstance()
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.cyberborean.rdfbeans.datatype;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.ValueFactory;
import org.eclipse.rdf4j.model.vocabulary.XMLSchema;
import org.eclipse.rdf4j.model.vocabulary.XSD;


/**
Expand All @@ -34,17 +35,19 @@ public class DefaultDatatypeMapper implements DatatypeMapper {
static {

// standard XML-Schema datatypes
DATATYPE_MAP.put(String.class, XMLSchema.STRING);
DATATYPE_MAP.put(Integer.class, XMLSchema.INT);
DATATYPE_MAP.put(Date.class, XMLSchema.DATETIME);
DATATYPE_MAP.put(Boolean.class, XMLSchema.BOOLEAN);
DATATYPE_MAP.put(Float.class, XMLSchema.FLOAT);
DATATYPE_MAP.put(Double.class, XMLSchema.DOUBLE);
DATATYPE_MAP.put(Byte.class, XMLSchema.BYTE);
DATATYPE_MAP.put(Long.class, XMLSchema.LONG);
DATATYPE_MAP.put(Short.class, XMLSchema.SHORT);
DATATYPE_MAP.put(BigDecimal.class, XMLSchema.DECIMAL);
DATATYPE_MAP.put(java.net.URI.class, XMLSchema.ANYURI);
DATATYPE_MAP.put(String.class, XSD.STRING);
DATATYPE_MAP.put(Integer.class, XSD.INT);
DATATYPE_MAP.put(Date.class, XSD.DATETIME);
DATATYPE_MAP.put(LocalDate.class, XSD.DATE);
DATATYPE_MAP.put(Boolean.class, XSD.BOOLEAN);
DATATYPE_MAP.put(Float.class, XSD.FLOAT);
DATATYPE_MAP.put(Double.class, XSD.DOUBLE);
DATATYPE_MAP.put(Byte.class, XSD.BYTE);
DATATYPE_MAP.put(Long.class, XSD.LONG);
DATATYPE_MAP.put(Short.class, XSD.SHORT);
DATATYPE_MAP.put(BigDecimal.class, XSD.DECIMAL);
DATATYPE_MAP.put(java.net.URI.class, XSD.ANYURI);
DATATYPE_MAP.put(java.time.LocalDate.class, XSD.DATE);

// custom datatypes
DATATYPE_MAP.put(Character.class, Java.CHAR);
Expand All @@ -66,39 +69,42 @@ public static IRI getDatatypeURI(Class<?> c) {

public Object getJavaObject(Literal l) {
IRI dt = l.getDatatype();
if ((dt == null) || XMLSchema.STRING.equals(dt)) {
if ((dt == null) || XSD.STRING.equals(dt)) {
return l.stringValue();
}
else if (XMLSchema.BOOLEAN.equals(dt)) {
else if (XSD.BOOLEAN.equals(dt)) {
return l.booleanValue();
}
else if (XMLSchema.INT.equals(dt)) {
else if (XSD.INT.equals(dt)) {
return l.intValue(); //Integer.valueOf(l.intValue());
}
else if (XMLSchema.BYTE.equals(dt)) {
else if (XSD.BYTE.equals(dt)) {
return l.byteValue(); //Byte.valueOf(l.byteValue());
}
else if (XMLSchema.LONG.equals(dt)) {
else if (XSD.LONG.equals(dt)) {
return l.longValue();//Long.valueOf(l.longValue());
}
else if (XMLSchema.SHORT.equals(dt)) {
else if (XSD.SHORT.equals(dt)) {
return l.shortValue(); //Short.valueOf(l.shortValue());
}
else if (XMLSchema.FLOAT.equals(dt)) {
else if (XSD.FLOAT.equals(dt)) {
return l.floatValue(); //Float.valueOf(l.floatValue());
}
else if (XMLSchema.DOUBLE.equals(dt)) {
else if (XSD.DOUBLE.equals(dt)) {
return l.doubleValue();//Double.valueOf(l.doubleValue());
}
else if (XMLSchema.DECIMAL.equals(dt)) {
else if (XSD.DECIMAL.equals(dt)) {
return l.decimalValue();
}
else if (XMLSchema.ANYURI.equals(dt)) {
else if (XSD.ANYURI.equals(dt)) {
return java.net.URI.create(l.stringValue());
}
else if (XMLSchema.DATETIME.equals(dt)) {
else if (XSD.DATETIME.equals(dt)) {
return l.calendarValue().toGregorianCalendar().getTime();
}
else if (XSD.DATE.equals(dt)) {
return LocalDate.from(l.temporalAccessorValue());
}
else if (Java.CHAR.equals(dt)) {
String s = l.stringValue();
return s.length() > 0? l.stringValue().charAt(0) : '\u0000';
Expand All @@ -113,7 +119,7 @@ public Literal getRDFValue(Object value, ValueFactory vf) {
}
IRI dtUri = getDatatypeURI(value.getClass());
if (dtUri != null) {
if (dtUri.equals(XMLSchema.STRING)) {
if (dtUri.equals(XSD.STRING)) {
return vf.createLiteral(value.toString());
}
return vf.createLiteral(value.toString(), dtUri);
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/cyberborean/rdfbeans/impl/Unmarshaller.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.cyberborean.rdfbeans.reflect.RDFProperty;
import org.cyberborean.rdfbeans.reflect.SubjectProperty;
import org.cyberborean.rdfbeans.util.LockKeeper;
import org.eclipse.rdf4j.RDF4JException;
import org.eclipse.rdf4j.common.exception.RDF4JException;
import org.eclipse.rdf4j.common.iteration.CloseableIteration;
import org.eclipse.rdf4j.model.BNode;
import org.eclipse.rdf4j.model.IRI;
Expand Down Expand Up @@ -89,7 +89,8 @@ private <T> T unmarshal(RepositoryConnection conn, Resource resource, Class<T> c
for (RDFProperty p : rbi.getProperties()) {
// Get values
IRI predicate = p.getUri();
CloseableIteration<Statement, ? extends RDF4JException> statements;
// CloseableIteration<Statement, ? extends RDF4JException> statements;
CloseableIteration<Statement> statements;
if (p.isInversionOfProperty()) {
statements = conn.getStatements(null, predicate, resource, false, (IRI)context);
if (!statements.hasNext()) {
Expand Down Expand Up @@ -254,7 +255,8 @@ private void addList(RepositoryConnection conn, List<Object> list, final Resourc
private Class<?> getBindingClass(RepositoryConnection conn, Resource r, Resource... contexts)
throws RDFBeanException, RepositoryException {
Class<?> cls = null;
try (CloseableIteration<Statement, RepositoryException> ts = conn.getStatements(r, RDF.TYPE, null, false, contexts)) {
//try (CloseableIteration<Statement, RepositoryException> ts = conn.getStatements(r, RDF.TYPE, null, false, contexts)) {
try (CloseableIteration<Statement> ts = conn.getStatements(r, RDF.TYPE, null, false, contexts)) {
while (cls == null && ts.hasNext()) {
Value type = ts.next().getObject();
if (type instanceof IRI) {
Expand Down
Loading