]> gerrit.simantics Code Review - simantics/interop.git/blobdiff - org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java
Adding builtin type for Class in SCL so fix Update.scl
[simantics/interop.git] / org.simantics.xml.sax.base / src / org / simantics / xml / sax / base / XMLWriter.java
index f37e4d8e2ce438094aa224f1099a2e46f8163830..ce5cb90068aa16cedfa7483ae04d00dbeb0c4780 100644 (file)
@@ -26,6 +26,9 @@ import org.simantics.xml.sax.ontology.XMLResource;
 \r
 public class XMLWriter {\r
        \r
+       public static String XML_SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";\r
+       public static String XML_SCHEMA_INSTANCE_URI = "http://www.w3.org/2001/XMLSchema-instance";\r
+       \r
        private ReadGraph graph;\r
        private Map<Resource, XMLWriter> subWriters = new HashMap<Resource, XMLWriter>();\r
        private Map<Class<? extends XMLElementWriter>, XMLElementWriter> namedWriters = new HashMap<Class<? extends XMLElementWriter>, XMLElementWriter>();\r
@@ -95,6 +98,8 @@ public class XMLWriter {
                        if(getSchemaURI() != null) {\r
                                writer.writeDefaultNamespace(getSchemaURI());\r
                        }\r
+                       writer.writeNamespace("xsd", XML_SCHEMA_URI);\r
+                       writer.writeNamespace("xsi", XML_SCHEMA_INSTANCE_URI);\r
                }\r
                elementWriter.attributes(graph, instance, graph.getStatements(instance.instance, XML.hasAttribute), writer);\r
                if (graph.hasValue(instance.instance))\r
@@ -158,8 +163,6 @@ public class XMLWriter {
                                                        c = childWriterClass.getConstructor();\r
                                                        childWriter = c.newInstance();\r
                                                }\r
-                                               //childWriter = childWriterClass.newInstance();\r
-                                               \r
                                                namedWriters.put(childWriterClass, childWriter);\r
                                        } catch (IllegalAccessException|InstantiationException|NoSuchMethodException|SecurityException|InvocationTargetException e) {\r
                                                String err = "Error processing " + childWriterClass.getName() + " : element writers must have accessible constructor with ReadGraph parameter";\r
@@ -172,12 +175,21 @@ public class XMLWriter {
                        childWriter = writers.get(type);\r
                }\r
                if (childWriter == null) {\r
+                       // try child ontology/schema\r
                        Resource type = graph.getSingleType(child.instance);\r
                        Resource ontology = getOntology(type);\r
                        if (ontology != null) {\r
                                XMLWriter xmlWriter = subWriters.get(ontology);\r
                                if (xmlWriter != null) {\r
                                        childWriter = xmlWriter.writers.get(type);\r
+                                       // wrap the child writer with namespace writer\r
+                                       if (childWriter != null) {\r
+                                               if (childWriter instanceof XMLElementNamedChildWriter) {\r
+                                                       childWriter = new XMLNSNamedChildWriter((XMLElementNamedChildWriter)childWriter, xmlWriter.schemaURI);\r
+                                               } else {\r
+                                                       childWriter = new XMLNSElementWriter(childWriter, xmlWriter.schemaURI);\r
+                                               }\r
+                                       }\r
                                }\r
                        }\r
                        if (childWriter == null)\r