Skip to content

Commit

Permalink
XSD type handling rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zimmermann committed Jul 30, 2008
1 parent aa1d678 commit 7d487a8
Show file tree
Hide file tree
Showing 45 changed files with 798 additions and 1,784 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.incunabulum.owl4java.exceptions;
package de.incunabulum.jakuzi.exceptions;

public class CarindinalityException extends O4JException {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.incunabulum.owl4java.exceptions;
package de.incunabulum.jakuzi.exceptions;

public class O4JException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.incunabulum.owl4java.generator;
package de.incunabulum.jakuzi.generator;

import java.util.Date;

Expand All @@ -10,9 +10,9 @@
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.ModelFactory;

import de.incunabulum.owl4java.jmodel.JModel;
import de.incunabulum.owl4java.utils.IReporting;
import de.incunabulum.owl4java.utils.IStatistics;
import de.incunabulum.jakuzi.jmodel.JModel;
import de.incunabulum.jakuzi.utils.IReporting;
import de.incunabulum.jakuzi.utils.IStatistics;

public class Generator implements IStatistics, IReporting {

Expand All @@ -26,18 +26,24 @@ public class Generator implements IStatistics, IReporting {
private JModel jmodel;

// config options
private String anonClassBase = "AnonClass";
private String vocabularyName = "Vocabulary";
private String factoryName = "Factory";
private String toolsPackage = "owl4java";
private String toolsPackage = "jakuzi";
private String testClassName = "JakuziTest";

private boolean reasignDomainlessProperties = true;
private boolean createTestClass = true;

public void generate(String uri, String baseDir, String basePackage) {
startDate = new Date();

OntModel owlModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
OntDocumentManager owlDocMgr = owlModel.getDocumentManager();
owlDocMgr.setProcessImports(true);
owlModel.read(uri);

modelReadDate = new Date();

generate(owlModel, baseDir, basePackage);
}

Expand All @@ -47,18 +53,25 @@ public void generate(OntModel model, String baseDir, String basePackage) {
if (startDate == null) {
startDate = new Date();
}
// analyze the model
Owl2JModelReader mAnalyzer = new Owl2JModelReader();
mAnalyzer.setAnonClassBase(anonClassBase);
mAnalyzer.setBasePackage(basePackage);
mAnalyzer.addForbiddenPrefix(toolsPackage);
this.jmodel = mAnalyzer.generateJModel(model);


// read the model
OwlReader mReader = new OwlReader();
mReader.setBasePackage(basePackage);
mReader.addForbiddenPrefix(toolsPackage);
this.jmodel = mReader.generateJModel(model);

// prepare the model
JModelPreparation mPrep = new JModelPreparation();
mPrep.setReasignDomainlessProperties(reasignDomainlessProperties);
this.jmodel = mPrep.prepareModel(jmodel);

// write the model
JModel2JavaWriter mWriter = new JModel2JavaWriter();
JavaWriter mWriter = new JavaWriter();
mWriter.setVocabularyName(vocabularyName);
mWriter.setToolsPackage(toolsPackage);
mWriter.setFactoryName(factoryName);
mWriter.setCreateTestClass(createTestClass);
mWriter.setTestClassName(testClassName);
mWriter.generate(jmodel, baseDir, basePackage);

stopDate = new Date();
Expand All @@ -83,10 +96,6 @@ public String getReport() {
return new String();
}

public void setAnonClassBase(String anonClassBase) {
this.anonClassBase = anonClassBase;
}

public void setVocabularyName(String vocabularyName) {
this.vocabularyName = vocabularyName;
}
Expand All @@ -103,4 +112,16 @@ public OntModel getModel() {
return model;
}

public void setCreateTestClass(boolean createTestClass) {
this.createTestClass = createTestClass;
}

public void setTestcaseName(String testcaseName) {
this.testClassName = testcaseName;
}

public void setReasignDomainlessProperties(boolean reasignDomainlessProperties) {
this.reasignDomainlessProperties = reasignDomainlessProperties;
}

}
56 changes: 56 additions & 0 deletions src/java/de/incunabulum/jakuzi/generator/JModelPreparation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package de.incunabulum.jakuzi.generator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.incunabulum.jakuzi.jmodel.JModel;

public class JModelPreparation {

private static Log log = LogFactory.getLog(JModelPreparation.class);

private boolean reasignDomainlessProperties;
private JModel jmodel;

public JModel prepareModel(JModel model) {
this.jmodel = model;
log.info("Prepaing model for class writer");

// assign properties without domain to restrictions
if (reasignDomainlessProperties)
reasignProperties();

// add all parent properties to a class
aggregateProperties();

// dito for the restrictions
aggregateRestrictions();

// remove duplicate restrictions; cleanup
cleanupRestrictions();

return this.jmodel;
}

protected void reasignProperties() {

}

protected void aggregateProperties() {

}

protected void aggregateRestrictions() {

}

protected void cleanupRestrictions() {

}



public void setReasignDomainlessProperties(boolean reasignDomainlessProperties) {
this.reasignDomainlessProperties = reasignDomainlessProperties;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package de.incunabulum.owl4java.generator;
package de.incunabulum.jakuzi.generator;

import java.io.File;
import java.text.SimpleDateFormat;
Expand All @@ -10,18 +10,19 @@
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

import de.incunabulum.owl4java.generator.writer.ClassWriter;
import de.incunabulum.owl4java.generator.writer.FactoryWriter;
import de.incunabulum.owl4java.generator.writer.InterfaceWriter;
import de.incunabulum.owl4java.generator.writer.VocabularyWriter;
import de.incunabulum.owl4java.jmodel.JClass;
import de.incunabulum.owl4java.jmodel.JModel;
import de.incunabulum.owl4java.jmodel.utils.NamingUtils;
import de.incunabulum.owl4java.utils.JavaUtils;
import de.incunabulum.jakuzi.generator.writer.ClassWriter;
import de.incunabulum.jakuzi.generator.writer.FactoryWriter;
import de.incunabulum.jakuzi.generator.writer.InterfaceWriter;
import de.incunabulum.jakuzi.generator.writer.TestWriter;
import de.incunabulum.jakuzi.generator.writer.VocabularyWriter;
import de.incunabulum.jakuzi.jmodel.JClass;
import de.incunabulum.jakuzi.jmodel.JModel;
import de.incunabulum.jakuzi.jmodel.utils.NamingUtils;
import de.incunabulum.jakuzi.utils.JavaUtils;

public class JModel2JavaWriter {
public class JavaWriter {

private static Log log = LogFactory.getLog(JModel2JavaWriter.class);
private static Log log = LogFactory.getLog(JavaWriter.class);

VelocityEngine vEngine;

Expand All @@ -30,6 +31,8 @@ public class JModel2JavaWriter {
private String vocabularyName;
private String factoryName;
private String toolsPackage;
private String testClassName;
private boolean generateTestClass;

private JModel jmodel;

Expand Down Expand Up @@ -58,9 +61,21 @@ public void generate(JModel model, String baseDir, String basePackage) {

// write factory
createFactory();

// create test cases
if (generateTestClass) {
createTestClass();
}
}

protected void createTestClass() {
log.info("Creating Testclass");
TestWriter tWriter = new TestWriter(vEngine, getBaseVelocityContext());
tWriter.setTestClassName(testClassName);
tWriter.setToolsPackage(toolsPackage);
tWriter.writeTestCases(jmodel, baseDir, basePackage);
}

@SuppressWarnings("unchecked")
protected void createFactory() {
log.info("Creating Factory");
FactoryWriter fWriter = new FactoryWriter(vEngine, getBaseVelocityContext());
Expand All @@ -69,7 +84,6 @@ protected void createFactory() {
fWriter.writeFactory(jmodel, baseDir, basePackage);
}

@SuppressWarnings("unchecked")
protected void createVocabulary() {
log.info("Creating vocabulary");
VocabularyWriter vWriter = new VocabularyWriter(vEngine, getBaseVelocityContext());
Expand All @@ -95,7 +109,7 @@ protected void initVelocityEngine() {

}

private VelocityContext getBaseVelocityContext() {
protected VelocityContext getBaseVelocityContext() {
// add some default stuff to our context. These are reused over all writers
VelocityContext vContext = new VelocityContext();
Calendar c = Calendar.getInstance();
Expand All @@ -107,7 +121,8 @@ private VelocityContext getBaseVelocityContext() {
vContext.put("factoryPkg", NamingUtils.getJavaPackageName(basePackage, toolsPackage));
vContext.put("vocabName", vocabularyName);
vContext.put("vocabPkg", NamingUtils.getJavaPackageName(basePackage, toolsPackage));

vContext.put("testcaseName", testClassName);
vContext.put("testcasePkg", NamingUtils.getJavaPackageName(basePackage, toolsPackage));
return vContext;
}

Expand Down Expand Up @@ -176,4 +191,13 @@ public void setFactoryName(String factoryName) {
this.factoryName = factoryName;
}


public void setCreateTestClass(boolean createTestClass) {
this.generateTestClass = createTestClass;
}

public void setTestClassName(String testClassName) {
this.testClassName = testClassName;
}

}
Loading

0 comments on commit 7d487a8

Please sign in to comment.