Difference between revisions of "JavaCodeGenerationUsingAPI"

From Protege Wiki
Jump to: navigation, search
(categorizing page)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
This is an example code of a Test class using the Protege OWL API to invoke the OWL Java Code Generator.
+
This is example code for a test class that uses the Protege-OWL API to invoke the OWL Java Code Generator.
 
 
  
 
<code>
 
<code>
Line 14: Line 13:
 
public class JavaCodeGenerationTest {
 
public class JavaCodeGenerationTest {
  
public static void main(String[] args) {
+
    public static void main(String[] args) {
try {
+
        try {
//create OWL Model
+
    //create OWL Model
OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///C:/Program%20Files/Protege_3.4_beta/examples/pizza/pizza.owl");
+
            OWLModel owlModel =  
 +
                ProtegeOWL.createJenaOWLModelFromURI("file:///C:/Program%20Files/Protege_3.4_beta/examples/pizza/pizza.owl");
 
 
//create and set options for the Java Code Generator  
+
            //create and set options for the Java Code Generator  
ProjectBasedJavaCodeGeneratorOptions options = new ProjectBasedJavaCodeGeneratorOptions(owlModel);
+
    ProjectBasedJavaCodeGeneratorOptions options = new ProjectBasedJavaCodeGeneratorOptions(owlModel);
 +
 
 +
    options.setOutputFolder(new File("C:\\test"));
 +
    options.setPackage("protege.codegenerator.test");
 +
 
 +
            //the following 2 lines have no effect because the specified
 +
            //values are the default values for those properties
 +
    options.setFactoryClassName("MyFactory");
 +
    options.setAbstractMode(false);
  
options.setOutputFolder(new File("C:\\test"));
+
    //new option since Protege 3.4 Beta Build 130
options.setPackage("protege.codegenerator.test");
+
    options.setPrefixMode(true);
//the following 2 lines have no effect because the specified values are the default values for those properties
+
 
options.setFactoryClassName("MyFactory");
+
    //for the options not specified (e.g. setSetMode(boolean value)) the default value will be used  
options.setAbstractMode(false);
 
//new option since Protege 3.4 Beta Build 130
 
options.setPrefixMode(true);
 
//for the options not specified (e.g. setSetMode(boolean value)) the default value will be used  
 
 
 
//create and run Java Code Generator
+
    //create and run Java Code Generator
JavaCodeGenerator code_generator = new JavaCodeGenerator(owlModel, options);
+
    JavaCodeGenerator code_generator = new JavaCodeGenerator(owlModel, options);
code_generator.createAll();
+
    code_generator.createAll();
+
} catch (Exception e) {
} catch (Exception e) {
+
    e.printStackTrace();
e.printStackTrace();
 
}
 
 
}
 
}
 
+
    }
 
}
 
}
 
 
</pre>
 
</pre>
 
</code>
 
</code>
  
[[Category:Protege Developer Documentation]]
+
[[Category:Protege developer documentation]]
[[Category:Protege 3 Documentation]]
 
[[Category:Protege-OWL Documentation]]
 

Latest revision as of 15:02, May 27, 2008

This is example code for a test class that uses the Protege-OWL API to invoke the OWL Java Code Generator.

import java.io.File;

import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.javacode.JavaCodeGenerator;
import edu.stanford.smi.protegex.owl.javacode.ProjectBasedJavaCodeGeneratorOptions;
import edu.stanford.smi.protegex.owl.model.OWLModel;


public class JavaCodeGenerationTest {

    public static void main(String[] args) {
        try {
	    //create OWL Model
            OWLModel owlModel = 
                ProtegeOWL.createJenaOWLModelFromURI("file:///C:/Program%20Files/Protege_3.4_beta/examples/pizza/pizza.owl");
			
            //create and set options for the Java Code Generator 
	    ProjectBasedJavaCodeGeneratorOptions options = new ProjectBasedJavaCodeGeneratorOptions(owlModel);

	    options.setOutputFolder(new File("C:\\test"));
	    options.setPackage("protege.codegenerator.test");

            //the following 2 lines have no effect because the specified 
            //values are the default values for those properties
	    options.setFactoryClassName("MyFactory");
	    options.setAbstractMode(false);

	    //new option since Protege 3.4 Beta Build 130
	    options.setPrefixMode(true);

	    //for the options not specified (e.g. setSetMode(boolean value)) the default value will be used 
			
	    //create and run Java Code Generator
	    JavaCodeGenerator code_generator = new JavaCodeGenerator(owlModel, options);
	    code_generator.createAll();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    }
}