From: luukkainen Date: Fri, 27 Jan 2017 14:22:41 +0000 (+0000) Subject: Handling choice exporting properly by checking exported resource type X-Git-Tag: v1.31.0~44 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=5a2849a5e792c9821201d320cb30b3dc41a586bf;p=simantics%2Finterop.git Handling choice exporting properly by checking exported resource type refs #6985 git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@33439 ac1ea38d-2e2b-0410-8846-a27921b304fc --- diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriterBase.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriterBase.java index 9c4ceb6..8e6a678 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriterBase.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriterBase.java @@ -14,8 +14,9 @@ import org.simantics.db.exception.DatabaseException; public abstract class XMLElementNamedChildWriterBase implements XMLElementNamedChildWriter{ - private Map> typeWriters = new HashMap>(); - private Map> relationWriters = new HashMap>(); + private Map> typeWriters = new HashMap<>(); + private Map> relationWriters = new HashMap<>(); + private Map>> relationTypeWriters = new HashMap<>(); private Set> writers = new HashSet>(); @@ -61,6 +62,12 @@ public abstract class XMLElementNamedChildWriterBase implements XMLElementNamedC if (writerClass != null) return writerClass; if (child.statement != null) { + Map> typeWriters = relationTypeWriters.get(child.statement.getPredicate()); + if (typeWriters != null) { + writerClass = typeWriters.get(type); + if (writerClass != null) + return writerClass; + } writerClass = relationWriters.get(child.statement.getPredicate()); if (writerClass != null) return writerClass; @@ -85,6 +92,16 @@ public abstract class XMLElementNamedChildWriterBase implements XMLElementNamedC relationWriters.put(relation, writer); } + public void addRelationTypeWriter(Resource relation, Resource type, Class writer) { + Map> typeWriters = relationTypeWriters.get(relation); + if (typeWriters == null) { + typeWriters = new HashMap<>(); + relationTypeWriters.put(relation, typeWriters); + } + typeWriters.put(type, writer); + } + + public void addWriter(Class writer) { writers.add(writer); } diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java index 74538ea..243a1c2 100644 --- a/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java +++ b/org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java @@ -11,7 +11,6 @@ import java.util.Map; import javax.xml.namespace.QName; import org.simantics.utils.datastructures.BijectionMap; -import org.simantics.xml.sax.SchemaConversionBase.RefType; import org.simantics.xml.sax.SchemaObject.ObjectType; import org.simantics.xml.sax.configuration.AttributeComposition; import org.simantics.xml.sax.configuration.Configuration; @@ -280,10 +279,15 @@ public class ExporterGenerator extends JavaGenerator{ protected void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName, String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) { FileWriter fw = getWriter(parent); + if ("TextOrField".equals(refName)) + System.out.println(); if (referenceType == RefType.Type) { // create internal class for handling the element and child attachment secondaryClassName = getName(parent) +"_" +objectName; - fw.writer.println(" addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);"); + if (objectName.equals(refName)) + fw.writer.println(" addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);"); + else // FIXME : type name may not be correct + fw.writer.println(" addRelationTypeWriter("+ontShort+ getName(parent)+"_has"+refName +", " +ontShort+primaryClassName +", "+secondaryClassName+".class);"); fw.delayedWriter2.println(" public static class " + secondaryClassName +" extends " + primaryClassName +"{"); fw.delayedWriter2.println(" public "+ secondaryClassName +"(ReadGraph graph){"); fw.delayedWriter2.println(" super(graph);"); @@ -304,17 +308,17 @@ public class ExporterGenerator extends JavaGenerator{ if (useElementList) { // element type specific list - fw.delayedWriter.println(" {"); - fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);"); - fw.delayedWriter.println(" if (list != null) {"); - fw.delayedWriter.println(" java.util.List l = org.simantics.db.common.utils.ListUtils.toList(graph, list);"); - fw.delayedWriter.println(" result.addAll(l);"); - fw.delayedWriter.println(" } else {"); - fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));"); - fw.delayedWriter.println(" }"); - fw.delayedWriter.println(" }"); + fw.delayedWriter.println(" {"); + fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);"); + fw.delayedWriter.println(" if (list != null) {"); + fw.delayedWriter.println(" java.util.List l = org.simantics.db.common.utils.ListUtils.toList(graph, list);"); + fw.delayedWriter.println(" result.addAll(l);"); + fw.delayedWriter.println(" } else {"); + fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));"); + fw.delayedWriter.println(" }"); + fw.delayedWriter.println(" }"); } else { - fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));"); + fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));"); } // if (useOriginalList(parent, indicator,element, reference, ref, refType)) { // // generic list @@ -376,17 +380,6 @@ public class ExporterGenerator extends JavaGenerator{ } else { fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));"); } -// // element type specific list -// fw.delayedWriter.println(" {"); -// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);"); -// fw.delayedWriter.println(" if (list == null) {"); -// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));"); -// fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List,list);"); -// fw.delayedWriter.println(" } else {"); -// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));"); -// fw.delayedWriter.println(" }"); -// fw.delayedWriter.println(" }"); -// } // if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) { // // generic list // fw.delayedWriter.println(" {");