\r
public abstract class XMLElementNamedChildWriterBase implements XMLElementNamedChildWriter{\r
\r
- private Map<Resource,Class<? extends XMLElementWriter>> typeWriters = new HashMap<Resource, Class<? extends XMLElementWriter>>();\r
- private Map<Resource,Class<? extends XMLElementWriter>> relationWriters = new HashMap<Resource, Class<? extends XMLElementWriter>>();\r
+ private Map<Resource,Class<? extends XMLElementWriter>> typeWriters = new HashMap<>();\r
+ private Map<Resource,Class<? extends XMLElementWriter>> relationWriters = new HashMap<>();\r
+ private Map<Resource,Map<Resource,Class<? extends XMLElementWriter>>> relationTypeWriters = new HashMap<>();\r
private Set<Class<? extends XMLElementWriter>> writers = new HashSet<Class<? extends XMLElementWriter>>();\r
\r
\r
if (writerClass != null)\r
return writerClass;\r
if (child.statement != null) {\r
+ Map<Resource,Class<? extends XMLElementWriter>> typeWriters = relationTypeWriters.get(child.statement.getPredicate());\r
+ if (typeWriters != null) {\r
+ writerClass = typeWriters.get(type);\r
+ if (writerClass != null)\r
+ return writerClass;\r
+ }\r
writerClass = relationWriters.get(child.statement.getPredicate());\r
if (writerClass != null)\r
return writerClass;\r
relationWriters.put(relation, writer);\r
}\r
\r
+ public void addRelationTypeWriter(Resource relation, Resource type, Class<? extends XMLElementWriter> writer) {\r
+ Map<Resource,Class<? extends XMLElementWriter>> typeWriters = relationTypeWriters.get(relation);\r
+ if (typeWriters == null) {\r
+ typeWriters = new HashMap<>();\r
+ relationTypeWriters.put(relation, typeWriters);\r
+ }\r
+ typeWriters.put(type, writer);\r
+ }\r
+ \r
+ \r
public void addWriter(Class<? extends XMLElementWriter> writer) {\r
writers.add(writer);\r
}\r
import javax.xml.namespace.QName;\r
\r
import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.xml.sax.SchemaConversionBase.RefType;\r
import org.simantics.xml.sax.SchemaObject.ObjectType;\r
import org.simantics.xml.sax.configuration.AttributeComposition;\r
import org.simantics.xml.sax.configuration.Configuration;\r
protected void createReferenceIndicator(SchemaObject parent, RefType referenceType, String refName, String objectName,\r
String primaryClassName, String secondaryClassName, boolean useElementList, boolean useOriginalList) {\r
FileWriter fw = getWriter(parent);\r
+ if ("TextOrField".equals(refName))\r
+ System.out.println();\r
if (referenceType == RefType.Type) {\r
// create internal class for handling the element and child attachment\r
secondaryClassName = getName(parent) +"_" +objectName;\r
- fw.writer.println(" addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);");\r
+ if (objectName.equals(refName))\r
+ fw.writer.println(" addRelationWriter("+ontShort+ getName(parent)+"_has"+refName +", "+secondaryClassName+".class);");\r
+ else // FIXME : type name may not be correct\r
+ fw.writer.println(" addRelationTypeWriter("+ontShort+ getName(parent)+"_has"+refName +", " +ontShort+primaryClassName +", "+secondaryClassName+".class);");\r
fw.delayedWriter2.println(" public static class " + secondaryClassName +" extends " + primaryClassName +"{");\r
fw.delayedWriter2.println(" public "+ secondaryClassName +"(ReadGraph graph){");\r
fw.delayedWriter2.println(" super(graph);");\r
if (useElementList) {\r
\r
// element type specific list\r
- fw.delayedWriter.println(" {");\r
- fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
- fw.delayedWriter.println(" if (list != null) {");\r
- fw.delayedWriter.println(" java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
- fw.delayedWriter.println(" result.addAll(l);");\r
- fw.delayedWriter.println(" } else {");\r
- fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
- fw.delayedWriter.println(" }");\r
- fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" {");\r
+ fw.delayedWriter.println(" org.simantics.db.Resource list = graph.getPossibleObject(instance.getResource(),"+ontShort+getName(parent)+"_has"+refName + "List);");\r
+ fw.delayedWriter.println(" if (list != null) {");\r
+ fw.delayedWriter.println(" java.util.List<org.simantics.db.Resource> l = org.simantics.db.common.utils.ListUtils.toList(graph, list);");\r
+ fw.delayedWriter.println(" result.addAll(l);");\r
+ fw.delayedWriter.println(" } else {");\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ fw.delayedWriter.println(" }");\r
+ fw.delayedWriter.println(" }");\r
} else {\r
- fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
+ fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
}\r
// if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
// // generic list\r
} else {\r
fw.delayedWriter.println(" result.addAll(graph.getObjects(instance.getResource(), "+ontShort+getName(parent)+"_has"+refName + "));");\r
}\r
-// // element type specific list\r
-// fw.delayedWriter.println(" {");\r
-// fw.delayedWriter.println(" Resource list = graph.getPossibleObject(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List);");\r
-// fw.delayedWriter.println(" if (list == null) {");\r
-// fw.delayedWriter.println(" list = org.simantics.db.common.utils.ListUtils.create(graph, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" graph.claim(element.getData(),"+ontShort+getName(parent)+"_has"+ref + "List,list);");\r
-// fw.delayedWriter.println(" } else {");\r
-// fw.delayedWriter.println(" org.simantics.db.common.utils.ListUtils.insertBack(graph, list, java.util.Collections.singletonList(child.getData()));");\r
-// fw.delayedWriter.println(" }");\r
-// fw.delayedWriter.println(" }");\r
-// }\r
// if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
// // generic list\r
// fw.delayedWriter.println(" {");\r