Simple example for using SemRest with Sommer.

Getting a Bookmark (Resource) object of the GroupMe! system, which is provided in RDF.
Our Client application wants to receive bookmarks from the GroupMe! system. Bookmarks in GroupMe! have several properties such as name and description of the bookmark, tags assigned to the bookmark, relations to other resources, or resource collections the bookmark is contained in.
Let us consider a client application that is just interested in the name and the description of bookmarks (both strings, only simple types and existing class-types are allowed, in case of need you have to implement the used types before). With SemREST, this client
application can define an interface IResource and with the right RDF tag annotations the classes are generated automatically.

The SemRest properties file:
#The base directory, where SemRest tries to store the generated *.class Files
#If this property is set there is no need to pass the ClassGenDist when calling
#getAllInstancesFromRdfString(...) method
#Important! You have to add this folder as a class folder to the build path of
#of your project!

#URI Mapper to use if none specified we use the UriDefault Mapper
#which has to be configured separately  

#Implementation Factory to use if none specified we use the JavassistImplFactory

#Instace Factory to use if none specified we use the SommerInstanceFactory

#RdfaReader to use if none specified we use the JenaRdfaReaders
Define Interfaces for the classes which should be generated, annotate the Interface and the methods with the right RDF tags. Used namespaces:
package de.l3s.sr.example.core;

public class NameSpaces {
	public static final String dc = "http://purl.org/dc/elements/1.1/";
	public static final String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
	public static final String foaf = "http://xmlns.com/foaf/0.1/";
The IResource interface with RDF tag annotations:
package de.l3s.sr.example.interfaces;

import static de.l3s.sr.example.core.NameSpaces.*;
import net.java.rdf.annotations.rdf;

@rdf(foaf + "Document")
public interface IResource {
	@rdf(dc + "title")
	public String getTitle();

	@rdf(dc + "description")
	public String getDescription();
Using SemRest and the defined Interface for generating classes from RDF:
package de.l3s.sr.example.core;
import java.io.IOException;
import java.util.Collection;
import org.restlet.data.Reference;
import de.l3s.sr.example.interfaces.IResource;
import de.l3s.sr.ws.RestletSommerWsHandler;

public class GroupMeResourceExample {
//URL of the RESTlet Service, which provides RDF
private static String resourceRESTletURL = 
	public static void main(String args[]){
		//the Interface you have defined for the RDF data
		IResource resource = null;
		//instantiate the URL as Reference
		Reference resourceURI = new Reference(resourceRESTletURL);
		try {
			//getting Java objects from the RDF data
			Collection resources = RestletSommerWsHandler.createHTTPhandler()
				.getObjectsFromWs(resourceURI, IResource.class);
			//here we have only one object
			for (IResource res : resources) {
				resource = res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
		System.out.println("Resource title: " + resource.getTitle());
		System.out.println("Resource description: " + resource.getDescription());


The SemREST Javadoc (Public APIs)

Resource Description Framework
Hosted by: sourceforge.net