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 =")
public interface IPerson {
    String getId();
    String getName();
    void setName(String name);
    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();;        
RDFBeanManager manager = new RDFBeanManager(model);
IPerson person = manager.create("", IPerson.class)

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

person.setName("John Doe");

will cause adding the statements to the model:

<> a <> ;
	<> "John Doe" ;
	<> "" ;

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:

	"foaf =",
	"persons =" 
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