Jastor    Typesafe, Ontology Driven RDF Access from Java


Jastor 1.0.4 Java Source and Binaries


Jastor is a open source Java code generator that emits Java Beans from Web Ontologies (OWL) enabling convenient, type safe access and eventing of RDF stored in a Jena Semantic Web Framework model. Jastor generates Java interfaces, implementations, factories, and listeners based on the properties and class hierarchies in the Web Ontologies. Jastor is based on several ideas from Automatic Mapping of OWL Ontologies to Java (PDF).

Jastor is licensed under the Common Public License.



Mailing List:


What's new

Jastor 1.0.4 Changes/Features/Fixes

- Jena 2.4 Compatibility

- Individuals with rdf:type that matches a class in the ontology are given constants in the interface for that class

- owl:oneOf Enumerated Classes assure that the members are generated as individuals in the class and are checked during creation of objects. Anonymous enumerated classes specified as property ranges generate a dummy class with individuals to use.

- previously, rdf:type statements for every class in the type hierarchy would be added to new individuals created through the factory. Now, by request, this behavior is configurable via the generation flag addAllRDFTypesInHierarchy. The default behavior remains to add all the types.

- Open domain properties (null domain, rdfs:Resource, owl:Thing) are now added to every class in the ontology in which it was defined. The previous behavior was to ignore such open domain properties unless a class had a restriction on that property.

- Literal fixes - configuration of typed vs. plain literals - in typedLiteral mode, the getters of propertie return null unless the literal value is typed properly. This may be a bit less convenient in some cases, however, it is semantically more correct.

- If a class has two properties with the same local name (different NS), Jastor 1.0.4 will create a prefix for the conflicting names. Optionally, these prefixes may be manually configured in the JastorContext or in the Ant build.xml

- Generation time performance has been improved by caching the results of OntologyClass.listProperties(...).

- Various other bug fixes and tweaks that I was not dilligent enough to record.

Jastor 1.0.3 Changes

The only major feature change is that factory getters return null if resouce is not of correct type and if strict typing is enabled

Jastor 1.0.2 Changes

Jastor 1.0.2 improves upon the efficiency of the property caches by registering fewer listeners on the model. We also added support for owl:functionalProperty so that function properties have single-valued getters/setters. In addition, properties that are subProperties inherit the domain/range of their parent properties. We also added a method to the factory getAll(Model model) that returns all instances of that exist in the model.

Finally, the getters and iterators returned by properties with alternate ranges (allValuesFrom, union range definitions) only return instances for objects with the proper rdf:Type. For example, if we have class A with property “foo” and class B subclassof A, and B (foo allValuesFrom C) and we call myB.getFoo_AsC(), the resulting Iterator will skip over any objects that do not have rdf:type C. In the single valued property case, the method will return null.


  • Jena Semantic Web Framework version 2.3 or later is required. Jena 2.4 is recommended.
  • Ant version 1.6 or later is optional. Ant may be used to generate Jastor classes using an Ant build file instead of a Java application.

Generating Java Classes

To Generate Jastor classes, a JastorContext must be defined either directly via Jastor's Java API or via the "jastor" Ant Task (com.ibm.adtech.jastor.JastorTask). JastorContext generation options provide flexibility in terms of what code is generated and how Java identifier names are chosen. Some users may wish to have the generated classes extend some custom base class. This may be done according to the example in com.ibm.adtech.jastor.test/src/com/ibm/adtech/jastor/customthing/test.

For example, given our ski.owl ontology, the following Java snippet will generate Jastor classes and save them to the "gensrc" directory:

Example 1: Java to generate Jastor classes
JastorContext ctx = new JastorContext();
ctx.addOntologyToGenerate(new FileInputStream("ski.owl"),
JastorGenerator gen = new JastorGenerator(
                          new File("gensrc").getCanonicalFile(),

The following Ant snippet (from build.xml) generates the same classes:

Example 2: Jastor Ant Build Task
  description="builds ski ontology">
	   usePackageNamesForRestrictedRanges="false" >
		  javaPackage="com.ibm.adtech.jastor.test.ski" />

After Jastor classes are generated, they can be used to access RDF in a clean, type-safe manner:

Example 3: Using Jastor classes
static final String PREFIX = "http://test.ibm.com/jastor/skiing/";
static final String POCKET_ROCKETS_URI = PREFIX + "pocketRockets";

Model model = ModelFactory.createDefaultModel();

// factories get or create resources as needed
Ski pocketRockets = SkiFactory.createFatTwin(POCKET_ROCKETS_URI, model);

// setters add or replace statements approperately
pocketRockets.setModel("Pocket Rockets");

// getters to read statements from the model
System.out.println("These skis have " + pocketRockets.getCoreConstruction() + " core construction.");

// take advantage of interface based multiple inheritence
// NOTE: PowederSki and TwinTip, are siblings of the parent class Ski
if (pocketRockets instanceof PowderSki) {
	System.out.println("These skis can handle deep powder.");
if (pocketRockets instanceof TwinTip) {
	System.out.println("You can ride backwards on these skis.");

// conviently registers listener
pocketRockets.registerListener(new SkiListener() {
	public void manufacturerChanged(Ski source) {
    	System.out.println("Pocket Rocket Manufacturer changed to: " + source.getManufacturer());

// switch between Jastor Classes and Jena
StmtIterator iter = pocketRockets.resource().listProperties();
System.out.println("Lets look at all statements about these skis, even ones that are not part of our ontology: ");
while(iter.hasNext()) {
	System.out.println("\t" + iter.nextStatement());

For more examples of using Jastor to generate classes see com.ibm.adtech.jastor.test/src/com/ibm/adtech/jastor/jet/test in Jastor's test source in CVS. and com.ibm.adtech.jastor.test/build.xml. In particular, the OWL-S tests demonstrate numerious complex OWL DL features.

Jastor source in in CVS under the "com.ibm.adtech.jastor" module.

Jastor's test source in in CVS under the "com.ibm.adtech.jastor.test" module.

OWL Compatibility Notes

Jastor supports most features of OWL Lite and OWL DL in terms of generating interfaces and hierarchies that capture the correct class descriptions and properties. In this version, Jastor does not perform restriction checking beyond those restrictions that can be implemented with first order Java constructs. For example, type restrictions are implemented with setter methods that take specific parameters.


Jastor binaries and source are available for download on the SourceForge files page: Download Page.

For anonymous cvs access to Jastor see the SourceForge CVS page: CVS Page.

Example Generated APIs

To demonstrate the utility of Jastor, we have generated and packaged code for several popular ontologies. The packages are available for download on the SourceForge files page: Download Page. We now present a brief description of each package.

OWL-S 1.1

OWL-S is a set of ontologies for describing workflow and Web Services. The generated package contains code for OWL-S and all of its dependencies (ObjectList, SWRL, time-entry, etc...).


FOAF is a popular system for describing people and relationships on the Web. Recently, RDF has become a popular data format for FOAF. This package contains code generated from the FOAF RDFS ontology.


Biopax is a collaborative effort to create a data exchange format for biological pathway data. Users of biopax should find the generated Jastor classes useful.


The Collections ontology is designed to provide a way to express ordered and unordered lists of objects and literals that can be subclassed. Unlike ObjectList, collections can contain mixtures of literals and objects. CollectionWrapper is a java.util.Collection implementation based on the generated code.

Design by Plain Black. Used with permission from the WebGUI open source content management project.