Difference between revisions of "JavaCodeGenerationUsingAPI"

From Protege Wiki
Jump to: navigation, search
(categorizing page)
Line 14: Line 14:
 
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.setOutputFolder(new File("C:\\test"));
options.setPackage("protege.codegenerator.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");
+
            //the following 2 lines have no effect because the specified  
options.setAbstractMode(false);
+
            //values are the default values for those properties
//new option since Protege 3.4 Beta Build 130
+
    options.setFactoryClassName("MyFactory");
options.setPrefixMode(true);
+
    options.setAbstractMode(false);
//for the options not specified (e.g. setSetMode(boolean value)) the default value will be used  
+
 
+
    //new option since Protege 3.4 Beta Build 130
//create and run Java Code Generator
+
    options.setPrefixMode(true);
JavaCodeGenerator code_generator = new JavaCodeGenerator(owlModel, options);
+
 
code_generator.createAll();
+
    //for the options not specified (e.g. setSetMode(boolean value)) the default value will be used  
 
 
} catch (Exception e) {
+
    //create and run Java Code Generator
e.printStackTrace();
+
    JavaCodeGenerator code_generator = new JavaCodeGenerator(owlModel, options);
}
+
    code_generator.createAll();
 +
} catch (Exception e) {
 +
    e.printStackTrace();
 
}
 
}
 
+
    }
 
}
 
}
 
 
</pre>
 
</pre>
 
</code>
 
</code>
  
[[Category:Protege Developer Documentation]]
+
[[Category:Protege developer documentation]]
[[Category:Protege 3 Documentation]]
 
[[Category:Protege-OWL Documentation]]
 

Revision as of 15:01, May 27, 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();
	}
    }
}