Skip to content

Commit

Permalink
Use namespaces as namespaces and do not compare as string
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastiaan Bijl committed Feb 17, 2017
1 parent b0a4eb3 commit 24e0dbb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@
package nl.coinsweb.sdk.cli.generate;


import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.tdb.TDB;
import nl.coinsweb.sdk.Namespace;
import nl.coinsweb.sdk.cli.Run;
import nl.coinsweb.sdk.cli.validate.ValidateOptions;
import nl.coinsweb.sdk.jena.JenaCoinsContainer;
import nl.coinsweb.sdk.jena.InMemGraphSet;
import nl.coinsweb.sdk.jena.JenaCoinsContainer;
import nl.coinsweb.sdk.owlgenerator.ClassGenerateEngine;
import org.apache.commons.cli.ParseException;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.tdb.TDB;
import org.codehaus.plexus.util.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -278,7 +280,7 @@ public void go(String[] args) {


engine.setTargetFolder(generatedFolder.toString());
Map<String, String> mapping = engine.process(model, sourceFileNames);
Map<Namespace, String> mapping = engine.process(model, sourceFileNames);

if(!doCompile) {
return;
Expand All @@ -288,7 +290,7 @@ public void go(String[] args) {
// Compile the java code

String fileList = "";
for(String namespace : mapping.keySet()) {
for(Namespace namespace : mapping.keySet()) {
String packageFolder = mapping.get(namespace).replace(".", "//");
fileList += files(generatedFolder.resolve(packageFolder), ".java", " ");
}
Expand All @@ -305,12 +307,29 @@ public void go(String[] args) {


List<String> producedDllFiles = new ArrayList<>();
List<String> pickList = new ArrayList(mapping.keySet());
List<Namespace> pickList = new ArrayList(mapping.keySet());
if(options.hasOrderOption()) {
log.info("Use specified order.");
pickList = options.getOrderOptions();

// Add all from list
List<Namespace> reOrderedPickList = new ArrayList();
for(String fromPriorityList : options.getOrderOptions()) {
Namespace fromPriorityListNs = new Namespace(fromPriorityList);
if(mapping.containsKey(fromPriorityListNs)) {
reOrderedPickList.add(fromPriorityListNs);
}
}

// Add all remaining
for(Namespace fromOriginalListNs : pickList) {
if(!reOrderedPickList.contains(fromOriginalListNs)) {
reOrderedPickList.add(fromOriginalListNs);
}
}

pickList = reOrderedPickList;
}
for(String namespace : pickList) {
for(Namespace namespace : pickList) {

log.info("Deal with "+namespace);
if(!mapping.containsKey(namespace)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void setTargetFolder(String folder) {

HashMap<String, String> preRunClassList = new HashMap<>();

Map<String, String> namespaceToPackage = new HashMap<>();
Map<Namespace, String> namespaceToPackage = new HashMap<>();

Set<String> fullyQualifiedJavaClasses = new HashSet<>();

Expand All @@ -68,7 +68,7 @@ private String simplify(String objectKey) {
return objectKey;
}

public void addNamespace(String rdfNamespace, String javaPackageName) {
public void addNamespace(Namespace rdfNamespace, String javaPackageName) {
log.info("Adding to namespaceToPackage map "+rdfNamespace+" / "+javaPackageName);
if(!subjectIgnoreList.contains(rdfNamespace)) {
namespaceToPackage.put(rdfNamespace, javaPackageName);
Expand Down Expand Up @@ -115,7 +115,7 @@ public ClassGenerateEngine() {


// The main function that calls all the above
public Map<String, String> process(ExpertCoinsModel model, List<String> sourceFileNames) {
public Map<Namespace, String> process(ExpertCoinsModel model, List<String> sourceFileNames) {


this.sourceFileNames = sourceFileNames;
Expand All @@ -131,10 +131,10 @@ public Map<String, String> process(ExpertCoinsModel model, List<String> sourceFi

preRunClassList.put(clazz.getURI(), Language.getLabel(clazz));

if(!namespaceToPackage.containsKey(clazz.asResource().getNameSpace())) {
if(!namespaceToPackage.containsKey(new Namespace(clazz.asResource().getNameSpace()))) {
String javaPackageName = Utils.namespaceUriToPackage(clazz.asResource().getNameSpace());
if(javaPackageName != null) {
addNamespace(clazz.asResource().getNameSpace(), javaPackageName);
addNamespace(new Namespace(clazz.asResource().getNameSpace()), javaPackageName);
} else {
log.warn("Failed to process class "+clazz.getURI());
}
Expand Down Expand Up @@ -217,7 +217,7 @@ public boolean processClass(ExpertCoinsModel model, OntClass clazz) {
return false;
}

if(!namespaceToPackage.containsKey(clazz.asResource().getNameSpace())) {
if(!namespaceToPackage.containsKey(new Namespace(clazz.asResource().getNameSpace()))) {

log.warn("Class should have been in namespaceToPackage list: "+clazz.getURI());
return false;
Expand All @@ -226,7 +226,7 @@ public boolean processClass(ExpertCoinsModel model, OntClass clazz) {

currentClass = new HashMap<>();

currentPackage = namespaceToPackage.get(clazz.asResource().getNameSpace());
currentPackage = namespaceToPackage.get(new Namespace(clazz.asResource().getNameSpace()));

initTemplateFields();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package nl.coinsweb.sdk.integration.d.owlgenerator;

import com.hp.hpl.jena.ontology.OntModelSpec;

import nl.coinsweb.sdk.jena.JenaCoinsContainer;
import nl.coinsweb.sdk.Namespace;
import nl.coinsweb.sdk.jena.InMemGraphSet;
import nl.coinsweb.sdk.jena.JenaCoinsContainer;
import nl.coinsweb.sdk.owlgenerator.ClassGenerateEngine;
import org.junit.Test;

Expand Down Expand Up @@ -46,7 +46,7 @@ public void listing() {
// sourceFileNames.add(modelPath.getFileName().toString());
// }

Map<String, String> mapping = engine.process(model, sourceFileNames);
Map<Namespace, String> mapping = engine.process(model, sourceFileNames);

}

Expand Down

0 comments on commit 24e0dbb

Please sign in to comment.