Difference between revisions of "JavaCodeGenerationUsingAPI"
From Protege Wiki
(categorizing page) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | This is | + | 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) { | |
− | + | 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(); | |
− | |||
− | |||
} | } | ||
− | + | } | |
} | } | ||
− | |||
</pre> | </pre> | ||
</code> | </code> | ||
− | [[Category:Protege | + | [[Category:Protege developer 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(); } } }