JSave Documentation

Author: Samson Tu (swt at stanford dot edu)
Last Updated: September 12, 2006


Functionality

JSave can be used to generate Java class definition stubs for Protégé classes. The top level classes extend DefaultSimpleInstance, so that instances of the generated Java classes are also Protégé instances and can use Protégé API calls. (More information about the Protégé API is available on the Protégé Web site). A developer can add his or her own methods to the Java class definition. Regenerating Java class stubs will update the stubs while preserving user-supplied code. An option of the package allows generation of Java bean access methods and listeners.

Contents of the jsave directory

After installing Protégé on your system, the JSave application can be found in the directory <protege-install-dir>/applications/jsave. To follow is a description of the contents of the directory.

jsave.html this file
jsave.jar compiled program code
runprotege2java.bat sample invocation script
HL7DataTypes.cfg sample configuration file
/kb directory containing sample Protégé project

Usage

java -Dprotege.dir=%PROTEGEHOME% -cp %CLASSPATH% edu.stanford.smi.protegex.jsave.protege2java %CONFIGURATIONFILE%

Configuration

  1. Configuration file as input to the protege2java program (see HL7DataTypes.cfg for an example):

    /* OUTPUTDIR specifies where the generated stub files will be stored and should be created before running the program. */
    OUTPUTDIR = d:\\projects\\protege\\jsave\\src\\hl7datatypes

    /* The package to which the generated class definition will be assigned, i.e. this parameter determines the "package" statement in a Java class definition. If you want generated files in different packages, run the program multiple times with different configuration files. */
    PACKAGENAME = hl7datatypes

    /* The first line produced by the program is a time stamp, then the HEADERSTRING is added */
    HEADERSTRING = "Copyright Stanford University 2006"

    /* A semi-colon delimited string that specifies the "import" statements to be added to a class definition. */
    IMPORT = import java.util.*;import java.beans.*;import edu.stanford.smi.protege.model.*;import edu.stanford.smi.protege.util.*;

    /* Path to the Protégé project to be loaded */
    KBURL=d:\\projects\\protege\\jsave\\kb\\HL7DataTypes.pprj

    /* A comma delimited list of Protégé classes that should be top level classes */
    TOPCLASS=Expression

    /* Whether to use classes included from other projects (true or false) */
    SAVEINCLUDED = true

    /* How access methods should be formatted. Values can be Regular, Javabean, or NoAccessMethod. In both Regular and Javabean cases "-" in slot names are replaced by "_". With the "Regular" option, suffix "Value" is added to the access methods. In the "Javabean" case the access methods conform to Java Bean convention, and PropertyChangeListeners are added. */
    SAVEFORMAT = Javabean

  2. Annotation to classes with multiple parents:

    Because Protégé allows multiple inheritance and Java classes only have single inheritance, users have to tell JSave which parent class to extend. This is done by annotating the first line of the class documentation slot with the name of the parent class to extend.

  3. Changes to the Protégé PPRJ file to make Protégé aware of the generated classes and create instances appropriately:

    To get Protégé, while loading a project, to create Java instances of the appropriate user-defined Java classes, you need to manually edit the Project instance in the PPRJ file to add a "java_packages" slot (see example below). The Java class files and/or JAR files have to be on the classpath.

    [PROJECT] of Project
    ...
    (default_slot_metaclass ":STANDARD-SLOT")
    (java_packages
    "edu.stanford.smi.eon.Dharma"
    "edu.stanford.smi.eon.time"
    "edu.stanford.smi.eon.criterion"
    "edu.stanford.smi.eon.athenaextensions"
    "edu.stanford.smi.eon.datahandler")
    ...

Limitations

One thing to look out for is that the JSave-generated access methods may clash with Protégé API. For example, if you have a slot called "name", and you use the Javabean save format, you'll get a getName() method, which is also a method in Protégé API. For now, it is probably best to refrain from using slot names that may cause problems or use other formats.