Configuration
Primitive Type Mapping
Owl datatype properties are mapped to the corresponding java class (where applicable). The mapping table can be configured via the static xsd2javaName map in the class XsdMapConfig. For each java type a getXYZ method must be supplied as shown in the static javaName2Method map.
Namespaces
Namespaces with a given prefix are transfered to java packages. For classes and interfaces of namespaces without a prefix a new namespace of the notation “p1”, “p2″… is created.
Naming Conventions
By default all properties, classes and instances are named PropertynamePrefix, ClassnamePrefix and IInterfacenamePrefix respectively. This can be configured via static variables in de.incunabulum.owl2java.model.jmodel.utils.NamingUtils.
Running the API generator
The main generator class for running the generator is de.incunabulum.owl2java.JenaGenerator. To run the generator, execute one of the three generate methods. A base directory for the generated java classes as well as a java base package must be supplied.
Also, the following configuration options are avaibale via setter methods:
- setToolsPackage: Defines the package name for the tools package. In this package the merge code class are generated
- setGenerateMergeCode: If set to true (default), a class to merge any existing instance data of a corresponding ontology to a db4o model is generated.
- setInstanceClassName: The name of the merge class.
- setReassignDomainlessProperties: If set to true (default) for all properties without a range the range is changed to the classes highest up in the class hierarchy with a retriction on the property.
Using the API
Basically, the generator generates db4o compliant class definitions with support for transparent persistence. The API can be used as plain old java objects.
For each class listClassName and countClassName methods are provided to get access to the objects stored in the db4o database. These require the ObjectContainer instance as argument.
A new instance is created via:
MyClass myObject = new MyClass();
and persisted to the database via:
objectContainer.store(myObject)
Requirements
Currently, the gnerator depends on the following libraries
- Jena 2.5.5
- Apache Commons Logging 1.1.1
- Apache Commons Collections 3.2
- Apache Commons Codec 1.3
- Apache Log4J 1.2.15
- Apache Velocity 1.5
- JGraphT 0.7.3
The runtime, i. e. the generated API depends on db4o and Apache Commons Logging only. Apache Commons Codec is required for the mapping from Hex to Ascii-encoded strings etc.