This document covers fundamental aspects of using the Java API of OntoBroker 6. Its goal is to acquaint developers with the concepts of the API via useful examples and is to be seen as a supplement to the OntoBroker API javadoc, which remains the main source of reference.
OntoBroker 6 introduced numerous innovations compared to the last major release, amongst others, ObjectLogic replaced F-Logic as the main ontology language and will therefore be the language used in our examples. As the OntoBroker Java API has also seen a number of changes and improvements, even developers with previous OntoBroker experience will benefit from reviewing the document.
The code snippets presented throughout the document are kept concise, however, complete source code for working demo applications is attached to the respective chapters.
The preferred way of accessing the OntoBroker Java API is via the 'Remote API' (for our purposes equivalent to the 'Collaboration Server' mode and further referred to as 'remote API'); only the remote API is guaranteed to support the complete API feature set.
Using the remote API means running OntoBroker independently from the application being developed, potentially on a different computer.
In order to start using the remote API, OntoBroker has to be configured to allow connections via the 'Remote API' or 'Collaboration Server'. If you plan on running OntoBroker on a different computer for development purposes, enabling the Web Console will let you control the server easily from your development workstation. To try out the examples and demo applications presented, remember to configure OntoBroker to use ObjectLogic. Refer to the OntoBroker documentation for further information on configuration.
If you run OntoBroker on a different machine, adjust the hostname or IP address in the example code. In case of connection problems, make sure that OntoBroker is really running and check the firewall settings.
Development Environment Setup
Using the OntoBroker Java API requires a number of Ontoprise and third party libraries, which come packaged within the OntoBroker installation. The subdirectory interfaces\development\Code Examples of your OntoBroker installation contains an Eclipse project, that will 'compile' the required libraries into a subdirectory. Follow the instructions in ReadMe.txt (in the project directory). Upon completing the steps, you will also have configured a 'User library collection' that can be added to your own projects with a few clicks making sure you don't miss any remote API library dependency.
Having touched on connecting to an OntoBroker instance, let us now see how this can be programmed. The central point for establishing a connection to OntoBroker and managing ontologies is the so-called Ontology Manager. OntologyManager is parameterized by a Properties object, that holds any relevant connection settings and specifies the ontology language of choice.
This code snippet below instantiates an OntologyManager for the ObjectLogic language. The variable url in the fourth line must hold the hostname or IP of the OntoBroker instance, in our examples, this will be "localhost". Also note the two commented out lines for setting the username and password, unless you change the default security OntoBroker settings, these will not be needed.
// create a new ontology manager for ObjectLogic
Properties properties = new Properties();
properties.setProperty("CollaborationServer.Url", url); // IP or hostname of OntoBroker
// properties.setProperty("CollaborationServer.User", "username"); // if applicable
// properties.setProperty("CollaborationServer.Password", "psswd"); // if applicable
OntologyManager manager = KAON2Manager.newOntologyManager(properties)
NOTE: Ignoring security settings might be acceptable for development, however, make sure to secure OntoBroker properly for production use. For more information, see the OntoBroker documentation.
NOTE: The examples mentioned in the API documentation can be downloaded at http://otc.ontoprise.com -> Downloads (registration is free).