Cyberborean Chronicles

RDFBeans 2.0

The second edition of RDFBeans Java-to-RDF databinding framework is finally out. In 2.0 version the library underwent major refactoring to clean and enhance the API and provide new databinding techniques.

RDFBeans is an open-source object-RDF databinding and persistence library for the Semantic Web development with Java language. It provides a framework for mapping an object-oriented domain model to RDF resource descriptions.

For more information, see:

RDFBean interfaces and dynamic proxying

Along with traditional JavaBean-like persisting technique using RDFBean classes, the version 2.0 introduces new approach to object-RDF mapping: RDFBean interfaces.

It works simply: you define an interface of your domain model object and annotate it just like an RDFBean class:

@RDFNamespaces("foaf = http://xmlns.com/foaf/0.1/")
@RDFBean("foaf:Person")
public interface IPerson {
 
    @RDFSubject
    String getId();
 
    @RDF("foaf:name")
    String getName();
 
    void setName(String name);
 
    @RDF("foaf:mbox")
    String getEmail();
 
    void setEmail(String email);
}

Then you instantiate the RDFBeanManager (was RDFBinding in RDFBeans 1.x) upon an RDF2Go Model and create a dynamic proxy object with your interface:

ModelFactory modelFactory = RDF2Go.getModelFactory();
Model model = modelFactory.createModel();
model.open();        
RDFBeanManager manager = new RDFBeanManager(model);
IPerson person = manager.create("http://example.com/persons/jdoe", IPerson.class)

The methods of this proxy object are directed immediately to the underlying RDF triples, so that

person.setName("John Doe");
person.setEmail("john@example.com");

will cause adding the statements to the model:

<http://example.com/persons/jdoe> a <http://xmlns.com/foaf/0.1/Person> ;
	<http://xmlns.com/foaf/0.1/name> "John Doe" ;
	<http://xmlns.com/foaf/0.1/mbox> "john@example.com" ;

Similarly, the getter methods will return values retrieved directly from these statements.

RDFBean annotations

The annotations scheme has changed, so the old classes will be incompatible with RDFBeans 2.0. As you can see in the example above, @RDF annotation is now applied to the getter methods but not to the field declaration like in the previous versions.

You also can notice new annotation, @RDFNamespaces, which defines a list of URI prefixes to be used in other RDFBean annotations declared in a given class or interface. This includes class and property URIs, as well as RDFBean identifiers:

@RDFNamespaces({ 
	"foaf = http://xmlns.com/foaf/0.1/",
	"persons = http://example.com/persons/" 
})
@RDFBean("foaf:Person")
public interface IPerson {
 
	@RDFSubject(prefix = "persons:")
	String getId();
...

Annotations are now inherited from superclasses and interfaces that makes the RDFBeans markup compatible with complex domain-specific object models. See how the Thing, Agent and Person classes of the FOAF example are organized to mimic the owl:Thing → foaf:Agent → foaf:Person subclassing in RDF-Schema.

Leave a Reply