Difference between revisions of "JavaCodeGenerationUsingAPI"

From Protege Wiki
Jump to: navigation, search
m
(categorizing page)
Line 44: Line 44:
 
</pre>
 
</pre>
 
</code>
 
</code>
 +
 +
[[Category:Protege Developer Documentation]]
 +
[[Category:Protege 3 Documentation]]
 +
[[Category:Protege-OWL Documentation]]

Revision as of 16:42, May 22, 2008

This is an example code of a Test class using 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();
		}
	}

}