]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Initial support for XML export (order of Elements is not kept)
authorluukkainen <luukkainen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 24 Jan 2017 12:25:59 +0000 (12:25 +0000)
committerMarko Luukkainen <marko.luukkainen@vtt.fi>
Thu, 2 Feb 2017 12:01:35 +0000 (14:01 +0200)
Ability to rename Elements

refs #6985

git-svn-id: https://www.simantics.org/svn/simantics/interoperability/trunk@33434 ac1ea38d-2e2b-0410-8846-a27921b304fc

43 files changed:
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractExporter.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/IDReferenceParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java [moved from org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/Element.java with 83% similarity]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/UnrecognizedElementParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ValueElementParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ValueElementWriter.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/WriterElement.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildParserBase.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriter.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriterBase.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParserBase.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementWriter.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java [new file with mode: 0644]
org.simantics.xml.sax.ontology/graph.tg
org.simantics.xml.sax.ontology/graph/XML.pgraph
org.simantics.xml.sax.ontology/src/org/simantics/xml/sax/ontology/XMLResource.java
org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/InputSelectionPage.java
org.simantics.xml.sax.ui/src/org/simantics/xml/sax/ui/wizard/SchemaConversionWizard.java
org.simantics.xml.sax/schema/configuration.xsd
org.simantics.xml.sax/schema/gen.bat
org.simantics.xml.sax/src/org/simantics/xml/sax/ExporterGenerator.java [new file with mode: 0644]
org.simantics.xml.sax/src/org/simantics/xml/sax/ImporterGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java [new file with mode: 0644]
org.simantics.xml.sax/src/org/simantics/xml/sax/OntologyGenerator.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConversionBase.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaConverter.java
org.simantics.xml.sax/src/org/simantics/xml/sax/SchemaObject.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Attribute.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/AttributeComposition.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/ComplexType.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Configuration.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/ConversionRule.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Element.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/IDProvider.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/IDReference.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/ObjectFactory.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/OrderedChild.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Rename.java [new file with mode: 0644]
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/UnrecognizedChildElement.java
org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/package-info.java

diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractExporter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractExporter.java
new file mode 100644 (file)
index 0000000..14a3fca
--- /dev/null
@@ -0,0 +1,79 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.IOException;\r
+\r
+import javax.xml.stream.XMLOutputFactory;\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.message.ILogger;\r
+import org.simantics.message.MessageService;\r
+\r
+public class AbstractExporter {\r
+       \r
+       private Session session;\r
+       private File file;\r
+       private ILogger logger;\r
+       private Resource root;\r
+       private XMLWriter xmlWriter;\r
+       \r
+       public AbstractExporter(Session session, File file , Resource root, XMLWriter xmlWriter)  {\r
+               this.session = session;\r
+               this.file = file;\r
+               this.root = root;\r
+               this.xmlWriter = xmlWriter;\r
+       }\r
+       \r
+       public AbstractExporter(Session session, File file , Resource root)  {\r
+               this.session = session;\r
+               this.file = file;\r
+               this.root = root;\r
+       }\r
+       \r
+       public void setXmlWriter(XMLWriter xmlWriter) {\r
+               this.xmlWriter = xmlWriter;\r
+       }\r
+       \r
+       public void doExport() throws DatabaseException {\r
+               doExport(MessageService.getDefault());  \r
+       }\r
+       \r
+       public void doExport(ILogger logger) throws DatabaseException {\r
+               ExportRequest req = new ExportRequest();\r
+               session.syncRequest(req);\r
+       }\r
+       \r
+       \r
+       private class ExportRequest extends ReadRequest {\r
+               @Override\r
+               public void run(ReadGraph graph) throws DatabaseException {\r
+                       XMLStreamWriter writer = null;\r
+                       try {\r
+                               XMLOutputFactory output = XMLOutputFactory.newInstance();\r
+                               writer = output.createXMLStreamWriter(new FileOutputStream(file),"UTF-8");\r
+                               writer.writeStartDocument("UTF-8", "1.0");\r
+                               xmlWriter.write(root, writer);\r
+                               \r
+                               writer.writeEndDocument();\r
+                               writer.close();\r
+                       } catch (IOException|XMLStreamException e) {\r
+                               try {\r
+                                       writer.close();\r
+                               } catch (XMLStreamException err) {\r
+                                       \r
+                               }\r
+                               throw new DatabaseException(e);\r
+                       } \r
+                       \r
+                       \r
+               }\r
+       }\r
+\r
+}\r
index fb74fd35c9ca07e631dca965e4d04618ebca27b7..abaf7f27783fb4dcb4301f04800d482fec15998c 100644 (file)
@@ -7,6 +7,6 @@ import org.simantics.db.exception.DatabaseException;
 \r
 public interface IDReferenceParser extends XMLElementParser{\r
        \r
-       public boolean connectReferences(WriteGraph graph, Element element, Map<String,Element> map) throws DatabaseException;\r
+       public boolean connectReferences(WriteGraph graph, ParserElement element, Map<String,ParserElement> map) throws DatabaseException;\r
 \r
 }\r
similarity index 83%
rename from org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/Element.java
rename to org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ParserElement.java
index 62f1597eacd06718976480070cab754e4c5d8277..e3298e3677c8c54916bf4d80cb030f447ea29cac 100644 (file)
@@ -8,7 +8,7 @@ import java.util.Map;
 import org.simantics.db.Resource;\r
 import org.xml.sax.Attributes;\r
 \r
-public class Element implements Serializable {\r
+public class ParserElement implements Serializable {\r
        private static final long serialVersionUID = -5207502156942818875L;\r
        String uri;\r
        String localName;\r
@@ -18,7 +18,7 @@ public class Element implements Serializable {
        XMLElementParser elementParser;\r
        XMLParser xmlParser;\r
        \r
-       public Element(String uri, String localName, String qName, Attributes attributes) {\r
+       public ParserElement(String uri, String localName, String qName, Attributes attributes) {\r
                this.uri = uri;\r
                this.localName = localName;\r
                this.qName = qName;\r
@@ -27,7 +27,7 @@ public class Element implements Serializable {
                }\r
        }\r
        \r
-       public Element(String uri, String localName, String qName, Collection<Attribute> attributes) {\r
+       public ParserElement(String uri, String localName, String qName, Collection<Attribute> attributes) {\r
                this.uri = uri;\r
                this.localName = localName;\r
                this.qName = qName;\r
index d21918bf92c28615eddb6661bb8a732399848237..48c0f8faf4c7fd4f48de503a79e74dbcb655955d 100644 (file)
@@ -7,5 +7,5 @@ import org.simantics.db.exception.DatabaseException;
 \r
 public interface UnrecognizedElementParser {\r
 \r
-       public void configureChild(WriteGraph graph, Deque<Element> parents, Element element, Element child) throws DatabaseException;\r
+       public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException;\r
 }\r
index 718c8b029937b5fcc0222e6b432d6fcf235b5ea9..8a1391888eaca574a8214cd33b2d790dba3e45e6 100644 (file)
@@ -27,29 +27,29 @@ public class ValueElementParser extends XMLElementParserBase{
        }\r
        \r
        @Override\r
-       public Resource create(WriteGraph graph, Element element)\r
+       public Resource create(WriteGraph graph, ParserElement element)\r
                        throws DatabaseException {\r
                Resource res = graph.newResource();\r
                return res;\r
        }\r
        \r
        @Override\r
-       public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {\r
+       public void configure(WriteGraph graph, Deque<ParserElement> parents,   ParserElement element) throws DatabaseException {\r
        }\r
        \r
        @Override\r
-       public boolean connectParent(WriteGraph graph, Element parent, Element element)throws DatabaseException {\r
+       public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element)throws DatabaseException {\r
                graph.claim(parent.getData(), graph.getResource(relationURI), element.getData());\r
                return true;\r
        }\r
        \r
        @Override\r
-       public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException {\r
+       public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException {\r
                return false;\r
        }\r
        \r
        @Override\r
-       public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+       public void configure(WriteGraph graph, ParserElement element, String string)   throws DatabaseException {\r
                Layer0 l0 = Layer0.getInstance(graph);\r
                if (binding == Bindings.STRING) {\r
                        graph.claim(element.getData(), l0.InstanceOf, l0.String);\r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ValueElementWriter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/ValueElementWriter.java
new file mode 100644 (file)
index 0000000..bcc7c95
--- /dev/null
@@ -0,0 +1,95 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.layer0.Layer0;\r
+\r
+public class ValueElementWriter implements XMLElementWriter{\r
+       \r
+       String name;\r
+       Binding binding;\r
+       String typeURI;\r
+       \r
+       public ValueElementWriter(String name, String typeURI,Binding binding) {\r
+               this.name = name;\r
+               this.typeURI = typeURI;\r
+               this.binding = binding;\r
+       }\r
+       \r
+       @Override\r
+       public String getElementId() {\r
+               return name;\r
+       }\r
+       \r
+       @Override\r
+       public Resource getType(ReadGraph graph) throws DatabaseException {\r
+               return graph.getResource(typeURI);\r
+       }\r
+       \r
+       @Override\r
+       public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+               writer.writeStartElement(getElementId());\r
+       }\r
+       \r
+       @Override\r
+       public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+               return Collections.EMPTY_LIST;\r
+       }\r
+       \r
+       @Override\r
+       public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+               writer.writeEndElement();\r
+       }\r
+       \r
+       @Override\r
+       public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes,\r
+                       XMLStreamWriter writer) throws XMLStreamException, DatabaseException {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+                       Layer0 l0 = Layer0.getInstance(graph);\r
+               Object value = graph.getValue(instance.getResource(), binding);\r
+               writer.writeCharacters(value.toString());\r
+//             if (binding == Bindings.STRING) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.String);\r
+//                     graph.claimValue(element.getData(), string, binding);\r
+//             } else if (binding == Bindings.INTEGER) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Integer);\r
+//                     graph.claimValue(element.getData(), Integer.parseInt(string), binding);\r
+//             } else if (binding == Bindings.FLOAT) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Float);\r
+//                     graph.claimValue(element.getData(), Float.parseFloat(string), binding);\r
+//             } else if (binding == Bindings.DOUBLE) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Double);\r
+//                     graph.claimValue(element.getData(), Double.parseDouble(string), binding);\r
+//             } else if (binding == Bindings.BOOLEAN) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Boolean);\r
+//                     graph.claimValue(element.getData(), Boolean.parseBoolean(string), binding);\r
+//             } else if (binding == Bindings.LONG) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Long);\r
+//                     graph.claimValue(element.getData(), Long.parseLong(string), binding);\r
+//             } else if (binding == Bindings.BYTE) {\r
+//                     graph.claim(element.getData(), l0.InstanceOf, l0.Byte);\r
+//                     graph.claimValue(element.getData(), Byte.parseByte(string), binding);\r
+//             } else {\r
+//                     throw new DatabaseException("Unknown datatype " + binding);\r
+//             }\r
+       }\r
+\r
+}\r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/WriterElement.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/WriterElement.java
new file mode 100644 (file)
index 0000000..62a2ded
--- /dev/null
@@ -0,0 +1,33 @@
+package org.simantics.xml.sax.base;\r
+\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+\r
+public class WriterElement {\r
+       public WriterElement parent;\r
+       public Resource instance;\r
+       public Statement statement;\r
+       public XMLElementWriter writer;\r
+       \r
+       public WriterElement(Resource instance) {\r
+               this.instance = instance;\r
+       }\r
+       \r
+       public WriterElement(WriterElement parent, Statement statement) {\r
+               this.statement = statement;\r
+               this.instance = statement.getObject();\r
+               this.parent = parent;\r
+       }\r
+       \r
+       public Resource getResource() {\r
+               return instance;\r
+       }\r
+       \r
+       public XMLElementWriter getWriter() {\r
+               return writer;\r
+       }\r
+       \r
+       public WriterElement getParent() {\r
+               return parent;\r
+       }\r
+}
\ No newline at end of file
index 9085c6bcba05d29b5f2366cf456228069555e3ec..544c906fa56adccc6800965a5f82d6bd7a1ba5f6 100644 (file)
@@ -3,5 +3,5 @@ package org.simantics.xml.sax.base;
 import java.util.Map;\r
 \r
 public interface XMLElementNamedChildParser extends XMLElementParser{\r
-       Class<? extends XMLElementParser> getParser(Map<String,XMLElementParser> parsers, Element element, Element child);\r
+       Class<? extends XMLElementParser> getParser(Map<String,XMLElementParser> parsers, ParserElement element, ParserElement child);\r
 }\r
index c0a217275e31934cea3db77fda5629d0c3ba3159..f1bbdf3f0b0effc34c784b41aad8b1e0977c9bbe 100644 (file)
@@ -14,7 +14,7 @@ public abstract class XMLElementNamedChildParserBase implements XMLElementNamedC
        private Set<Class<? extends XMLElementParser>> parsers = new HashSet<Class<? extends XMLElementParser>>();\r
        \r
        @Override\r
-       public Class<? extends XMLElementParser> getParser(Map<String, XMLElementParser> parsers, Element element, Element child) {\r
+       public Class<? extends XMLElementParser> getParser(Map<String, XMLElementParser> parsers, ParserElement element, ParserElement child) {\r
                Class<? extends XMLElementParser> parserClass =  namedParsers.get(child.qName);\r
                if (parserClass != null)\r
                        return parserClass;\r
@@ -44,7 +44,7 @@ public abstract class XMLElementNamedChildParserBase implements XMLElementNamedC
 //     }\r
        \r
        @Override\r
-       public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+       public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {\r
                \r
        }\r
        \r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementNamedChildWriter.java
new file mode 100644 (file)
index 0000000..97f4d3a
--- /dev/null
@@ -0,0 +1,13 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface XMLElementNamedChildWriter extends XMLElementWriter{\r
+       \r
+       public Class<? extends XMLElementWriter> getWriter(ReadGraph graph, Map<Resource, XMLElementWriter> writers, WriterElement element) throws DatabaseException;\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..69b6c8d
--- /dev/null
@@ -0,0 +1,94 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.scl.compiler.elaboration.errors.ElabNode;\r
+\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 Set<Class<? extends XMLElementWriter>> writers = new HashSet<Class<? extends XMLElementWriter>>();\r
+       \r
+       \r
+       public XMLElementNamedChildWriterBase() {\r
+       \r
+       }\r
+       \r
+       public XMLElementNamedChildWriterBase(ReadGraph graph) {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public Resource getType(ReadGraph graph) throws DatabaseException {\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException {\r
+               writer.writeStartElement(getElementId());\r
+       }\r
+       \r
+       @Override\r
+       public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+               \r
+       }\r
+       \r
+       @Override\r
+       public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException {\r
+               writer.writeEndElement();\r
+       }\r
+       \r
+       @Override\r
+       public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer)\r
+                       throws XMLStreamException, DatabaseException {\r
+               return Collections.EMPTY_LIST;\r
+       }\r
+       \r
+       @Override\r
+       public Class<? extends XMLElementWriter> getWriter(ReadGraph graph, Map<Resource, XMLElementWriter> writers, WriterElement child) throws DatabaseException{\r
+               Resource type = graph.getSingleType(child.instance);\r
+               Class<? extends XMLElementWriter> writerClass =  typeWriters.get(type);\r
+               if (writerClass != null)\r
+                       return writerClass;\r
+               if (child.statement != null) {\r
+                       writerClass = relationWriters.get(child.statement.getPredicate());\r
+                       if (writerClass != null)\r
+                               return writerClass;\r
+               }\r
+               XMLElementWriter writer = writers.get(type);\r
+               if (writer == null)\r
+                       return null;\r
+               writerClass = writer.getClass();\r
+               if (this.writers.contains(writerClass))\r
+                       return writerClass;\r
+               for (Class<?> c : this.writers)\r
+                       if (c.isAssignableFrom(writerClass))\r
+                               return writerClass;\r
+               return null;\r
+       }\r
+       \r
+       public void addTypeWriter(Resource type, Class<? extends XMLElementWriter> writer) {\r
+               typeWriters.put(type, writer);\r
+       }\r
+       \r
+       public void addRelationWriter(Resource relation, Class<? extends XMLElementWriter> writer) {\r
+               relationWriters.put(relation, writer);\r
+       }\r
+       \r
+       public void addWriter(Class<? extends XMLElementWriter> writer) {\r
+               writers.add(writer);\r
+       }\r
+}\r
index c3b380401db4a8744b6d1da5e841923e779990c0..27c0ac79c1de9e56f77054e210e4658cc4097302 100644 (file)
@@ -28,7 +28,7 @@ public interface XMLElementParser {
         * @return\r
         * @throws DatabaseException\r
         */\r
-       public Resource create(WriteGraph graph, Element element) throws DatabaseException;\r
+       public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException;\r
        /**\r
         * Configures the element.\r
         * \r
@@ -38,7 +38,7 @@ public interface XMLElementParser {
         * @param element\r
         * @throws DatabaseException\r
         */\r
-       public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException;\r
+       public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException;\r
        /**\r
         * Configures element with characters content\r
         * \r
@@ -48,7 +48,7 @@ public interface XMLElementParser {
         * @param string\r
         * @throws DatabaseException\r
         */\r
-       public void configure(WriteGraph graph, Element element, String string) throws DatabaseException;\r
+       public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException;\r
        \r
        /**\r
         * Adds child element. Primary method for connecting elements.\r
@@ -58,7 +58,7 @@ public interface XMLElementParser {
         * @return true, if connection was done, otherwise return false.\r
         * @throws DatabaseException\r
         */\r
-       public abstract boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException;\r
+       public abstract boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException;\r
        /**\r
         * Adds element to a parent. Secondary method for connecting elements. Called only if primary method fails.\r
         * @param graph\r
@@ -67,7 +67,7 @@ public interface XMLElementParser {
         * @return true, if connection was done, otherwise return false.\r
         * @throws DatabaseException\r
         */\r
-       public abstract boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException;\r
+       public abstract boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException;\r
        \r
        \r
        //public void configureChild(WriteGraph graph, Stack<Element> parents, Element element, Element child) throws DatabaseException;\r
index 000d25b5a67934815212ffd891176fecf88c6c70..7a5abf500b38dbdc8f91d7b022164dd952a5e59d 100644 (file)
@@ -7,7 +7,7 @@ public abstract class XMLElementParserBase implements XMLElementParser{
        \r
        \r
        @Override\r
-       public void configure(WriteGraph graph, Element element, String string) throws DatabaseException {\r
+       public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {\r
                \r
        }\r
        \r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementWriter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementWriter.java
new file mode 100644 (file)
index 0000000..cde7809
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.util.Collection;\r
+import java.util.List;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface XMLElementWriter {\r
+\r
+       public java.lang.String getElementId();\r
+       public Resource getType(ReadGraph graph) throws DatabaseException;\r
+       //public int idPriority();\r
+       public void start(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+       public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+       public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+       public List<Resource> children(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+       public void end(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException;\r
+       \r
+}\r
index 43a07c560c3e5b86f2eacc1b8540cb25c2f27ea1..992b98ab672f3cd2c39d0314368b158389dc0188 100644 (file)
@@ -28,17 +28,18 @@ import org.xml.sax.helpers.DefaultHandler;
 \r
 public class XMLParser extends DefaultHandler implements Serializable {\r
 \r
+       public static String PLUGIN_ID = "org.simantics.xml.sax.base";\r
+       \r
        private static final long serialVersionUID = 7360740940824360338L;\r
        private static final boolean debug = false;\r
        private static String XML_SCHEMA_REF = "xmlns";\r
        private ILogger logger;\r
+       private WriteGraph graph;\r
        private Resource root;\r
        private String schemaURI;\r
-       private Deque<Element> current = new ArrayDeque<Element>();\r
+       private Deque<ParserElement> current = new ArrayDeque<ParserElement>();\r
        private Map<String, XMLElementParser> parsers = new HashMap<String, XMLElementParser>();\r
-       private WriteGraph graph;\r
        private Map<Class<? extends XMLElementParser>, XMLElementParser> namedParsers = new HashMap<Class<? extends XMLElementParser>, XMLElementParser>();\r
-       \r
        private Map<String, XMLParser> subParsers = new HashMap<String, XMLParser>();\r
        \r
        public XMLParser() {\r
@@ -73,10 +74,10 @@ public class XMLParser extends DefaultHandler implements Serializable {
                subParsers.put(parser.getSchemaURI(), parser);\r
        }\r
        \r
-       private List<Element> idReferenceElements = new ArrayList<Element>();\r
-       private void loadElement(Deque<Element> parents, Element element) throws SAXException{\r
+       private List<ParserElement> idReferenceElements = new ArrayList<ParserElement>();\r
+       private void loadElement(Deque<ParserElement> parents, ParserElement element) throws SAXException{\r
                XMLElementParser parser = null;\r
-               Element parent = null;\r
+               ParserElement parent = null;\r
                if (parents.size() > 0) {\r
                        parent = parents.peek();\r
                        // check for assigned subparser\r
@@ -139,15 +140,15 @@ public class XMLParser extends DefaultHandler implements Serializable {
                }\r
        }\r
        \r
-       private Map<String, Element> idMap = new HashMap<String, Element>();\r
+       private Map<String, ParserElement> idMap = new HashMap<String, ParserElement>();\r
        \r
-       private void handleElement(Deque<Element> parents, Element element) throws SAXException{\r
+       private void handleElement(Deque<ParserElement> parents, ParserElement element) throws SAXException{\r
                XMLElementParser parser = element.getElementParser();\r
                if (parser != null) {\r
                        try {\r
                                parser.configure(graph, parents, element);\r
                                if (parents.size() > 0) {\r
-                                       Element parent = parents.peek();\r
+                                       ParserElement parent = parents.peek();\r
                                        if (parent.getElementParser() != null) {\r
                                                if (!parent.getElementParser().connectChild(graph, parent, element))\r
                                                        if (!parser.connectParent(graph, parent, element)) {\r
@@ -163,7 +164,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
                                }\r
                                String id = parser.getID();\r
                                if (id != null) {\r
-                                       Element existing = idMap.put(id, element);\r
+                                       ParserElement existing = idMap.put(id, element);\r
                                        if (existing != null) {\r
                                                // report error + use id priorities to select the kept element.\r
                                                boolean useExt = existing.elementParser.idPriority() > element.elementParser.idPriority();\r
@@ -178,7 +179,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
                                throw new SAXException(e);\r
                        }\r
                } else {\r
-                       Element parent = parents.peek();\r
+                       ParserElement parent = parents.peek();\r
                        if (parent != null) { \r
                                parser = parent.getElementParser();\r
                                if (parser != null && parser instanceof UnrecognizedElementParser) {\r
@@ -192,7 +193,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
                }\r
        }\r
        \r
-       private void handleCharacters(Element element, String string) throws SAXException{\r
+       private void handleCharacters(ParserElement element, String string) throws SAXException{\r
                XMLElementParser parser = element.getElementParser();\r
                if (parser != null) {\r
                        try {\r
@@ -204,11 +205,11 @@ public class XMLParser extends DefaultHandler implements Serializable {
                }\r
        }\r
        \r
-       private static String PLUGIN_ID = "org.simantics.xml.sax.base";\r
+       \r
        \r
        public void done() throws SAXException{\r
                try {\r
-                       for (Element e : idReferenceElements) {\r
+                       for (ParserElement e : idReferenceElements) {\r
                                IDReferenceParser parser = (IDReferenceParser)parsers.get(e.qName);\r
                                if (!parser.connectReferences(graph, e, idMap)) {\r
                                        String err ="Could not resolve ID references for " + e.getQName() + " " + e.getUri();\r
@@ -229,7 +230,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
        \r
        @Override\r
        public void startElement(String uri, String localName, String name,     Attributes attributes) throws SAXException {\r
-               Element e = new Element(uri,localName,name,attributes);\r
+               ParserElement e = new ParserElement(uri,localName,name,attributes);\r
                \r
                loadElement(current,e);\r
                current.push(e);\r
@@ -240,7 +241,7 @@ public class XMLParser extends DefaultHandler implements Serializable {
        @Override\r
        public void endElement(String uri, String localName, String name)\r
                        throws SAXException {\r
-               Element e = null;\r
+               ParserElement e = null;\r
                if (!current.isEmpty()) {\r
                        e = current.pop();\r
                }\r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLWriter.java
new file mode 100644 (file)
index 0000000..3fd881b
--- /dev/null
@@ -0,0 +1,183 @@
+package org.simantics.xml.sax.base;\r
+\r
+import java.lang.reflect.Constructor;\r
+import java.lang.reflect.InvocationTargetException;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.xml.stream.XMLStreamException;\r
+import javax.xml.stream.XMLStreamWriter;\r
+\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Status;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.Statement;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.common.utils.NameUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.message.ILogger;\r
+import org.simantics.xml.sax.ontology.XMLResource;\r
+\r
+public class XMLWriter {\r
+       \r
+       private ReadGraph graph;\r
+       private Map<String, XMLWriter> subWriters = new HashMap<String, XMLWriter>();\r
+       private Map<Class<? extends XMLElementWriter>, XMLElementWriter> namedWriters = new HashMap<Class<? extends XMLElementWriter>, XMLElementWriter>();\r
+       private Map<Resource,XMLElementWriter> writers = new HashMap<>();\r
+       private String schemaURI;\r
+       \r
+       private ILogger logger;\r
+       \r
+       public ReadGraph getGraph() {\r
+               return graph;\r
+       }\r
+       \r
+       public void setGraph(ReadGraph graph) {\r
+               this.graph = graph;\r
+               for (XMLWriter p : subWriters.values())\r
+                       p.setGraph(graph);\r
+       }\r
+       \r
+       public String getSchemaURI() {\r
+               return schemaURI;\r
+       }\r
+       \r
+       public void setSchemaURI(String schemaURI) {\r
+               this.schemaURI = schemaURI;\r
+       }\r
+       \r
+       public void add(XMLElementWriter writer) throws DatabaseException {\r
+               Resource type = writer.getType(graph);\r
+               if (type != null)\r
+                       writers.put(type, writer);\r
+               namedWriters.put(writer.getClass(), writer);\r
+       }\r
+       \r
+       public void add(XMLWriter writer) {\r
+               subWriters.put(writer.getSchemaURI(), writer);\r
+       }\r
+       \r
+       public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
+               WriterElement element = new WriterElement(root);\r
+               loadElement(element);\r
+               write(element, writer);\r
+       }\r
+       \r
+       \r
+       protected void write(WriterElement instance, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
+               XMLResource XML = XMLResource.getInstance(graph);\r
+\r
+               XMLElementWriter elementWriter = instance.writer;\r
+               elementWriter.start(graph, instance, writer);\r
+               elementWriter.attributes(graph, instance, graph.getStatements(instance.instance, XML.hasAttribute), writer);\r
+               if (graph.hasValue(instance.instance))\r
+                       elementWriter.characters(graph, instance, writer);\r
+               // get all child elements\r
+               Collection<Statement> childElements = graph.getStatements(instance.instance, XML.hasElement);\r
+               // load elements, assign writers\r
+               Map<Resource,WriterElement> elementMap = new HashMap<>();\r
+               for (Statement s : childElements) {\r
+                       WriterElement c = new WriterElement(instance,s);\r
+                       loadElement(c);\r
+                       elementMap.put(s.getObject(), c);\r
+               }\r
+               List<Resource> sorted = elementWriter.children(graph, instance, writer);\r
+                       \r
+               for (Resource r : sorted) {\r
+                       WriterElement child = elementMap.get(r);\r
+                       write(child, writer);\r
+               }\r
+               //write the rest of the elements (in random order) \r
+               for (Statement stm : childElements) {\r
+                       if (sorted.contains(stm.getObject()))\r
+                               continue;\r
+                       WriterElement child = elementMap.get(stm.getObject());\r
+                       write(child, writer);\r
+               }\r
+       \r
+               elementWriter.end(graph, instance, writer);\r
+               \r
+       }\r
+       \r
+//     public void write(Resource root, XMLStreamWriter writer) throws DatabaseException, XMLStreamException {\r
+//             XMLResource XML = XMLResource.getInstance(graph);\r
+//             \r
+//             Deque<Element> stack = new ArrayDeque<>();\r
+//             Element rootElement = new Element(root);\r
+//             loadElement(rootElement);\r
+//             stack.push(rootElement);\r
+//             while (!stack.isEmpty()) {\r
+//                     \r
+//                     Element instance = stack.pop();\r
+//                     XMLElementWriter elementWriter = instance.writer;\r
+//                     elementWriter.start(graph, instance.instance, writer);\r
+//                     elementWriter.attributes(graph, graph.getStatements(instance.instance, XML.hasAttribute), writer);\r
+//                     // get all child elements\r
+//                     Collection<Statement> childElements = graph.getStatements(instance.instance, XML.hasElement);\r
+//                     // get original element order, if available\r
+//                     Resource originalElementList = graph.getPossibleObject(instance.instance, XML.hasOriginalElementList);\r
+//                     List<Resource> originalList = null;\r
+//                     if (originalElementList != null) {\r
+//                             originalList = ListUtils.toList(graph, originalElementList);\r
+//                     }\r
+//                     if (originalList != null) {\r
+//                             // check for elements that are missing form the original list (should be empty).  \r
+//                             for (Statement stm : childElements) {\r
+//                                     if (originalList.contains(stm.getObject()))\r
+//                                             continue;\r
+//                                     Element child = new Element(instance,stm.getObject());\r
+//                                     loadElement(child);\r
+//                                     stack.push(child);\r
+//                             }\r
+//                             // process the list in reverse order so that the stack processing processes the items in correct order.\r
+//                             for (int i = originalList.size()-1; i >= 0; i--) {\r
+//                                     Resource r = originalList.get(i);\r
+//                                     Element child = new Element(instance, r);\r
+//                                     loadElement(child);\r
+//                                     stack.push(child);\r
+//                             }\r
+//                     } else {\r
+//                             for (Statement stm : childElements) {\r
+//                                     Element child = new Element(instance, stm.getObject());\r
+//                                     loadElement(child);\r
+//                                     stack.push(child);\r
+//                             }\r
+//                     }\r
+//             }\r
+//     }\r
+       \r
+       private void loadElement(WriterElement child) throws DatabaseException {\r
+               XMLElementWriter childWriter = null;\r
+               if (child.parent != null && child.parent.writer instanceof XMLElementNamedChildWriter) {\r
+                       XMLElementNamedChildWriter namedParentWriter = (XMLElementNamedChildWriter)child.parent.writer;\r
+                       Class<? extends XMLElementWriter> childWriterClass = namedParentWriter.getWriter(graph, writers, child);\r
+                       if (childWriterClass != null) {\r
+                               childWriter = this.writers.get(childWriterClass);\r
+                               if (childWriter == null) {\r
+                                       try {\r
+                                               Constructor<? extends XMLElementWriter> c = childWriterClass.getConstructor(ReadGraph.class);\r
+                                               //childWriter = childWriterClass.newInstance();\r
+                                               childWriter = c.newInstance(graph);\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
+                                               logger.log(new Status(IStatus.ERROR, XMLParser.PLUGIN_ID, err));\r
+                                       } \r
+                               }\r
+                       }\r
+               } else {\r
+                       Resource type = graph.getSingleType(child.instance);\r
+                       childWriter = writers.get(type);\r
+               }\r
+               if (childWriter == null) {\r
+                       throw new DatabaseException("Cannot locate writer for " + NameUtils.getSafeName(graph, child.instance) + ", " + child.instance);\r
+               }\r
+               child.writer = childWriter;\r
+               \r
+       }\r
+\r
+}\r
index 82dd4f2178135e29415f5e09d262c9d99d7650e7..f19a643af8303f2a21073045636444c33f3a839d 100644 (file)
Binary files a/org.simantics.xml.sax.ontology/graph.tg and b/org.simantics.xml.sax.ontology/graph.tg differ
index 000f2926435380fd6b944a10a00f90ffb9612556..b0526a2ff0d6e74557c1ec1d50a0709b3a990f5a 100644 (file)
@@ -6,14 +6,14 @@ XML = <http://www.simantics.org/XML-1.0> : L0.Ontology
 \r
 \r
 // Built-in types\r
-\r
+XML.Entity <T L0.Entity\r
 XML.hasAttribute <R L0.HasProperty\r
 XML.hasID <R XML.hasAttribute : L0.FunctionalRelation\r
   --> L0.String\r
-XML.ComplexType <T L0.Entity\r
+XML.ComplexType <T XML.Entity\r
 XML.hasComplexType <R L0.IsComposedOf\r
-XML.AttributeGroup  <T L0.Entity\r
-XML.Element <T L0.Entity\r
+XML.AttributeGroup  <T XML.Entity\r
+XML.Element <T XML.Entity\r
 XML.hasElement <R L0.IsComposedOf\r
 XML.ElementList <T L0.List\r
 XML.hasElementList <R L0.IsComposedOf\r
index 48daa5915afd6cc11617f25a419c93ea2c5e32ee..01b5156048a55eee110c6faaf2fd23e9cc06d7f6 100644 (file)
@@ -16,6 +16,7 @@ public class XMLResource {
     public final Resource DateTime;\r
     public final Resource Element;\r
     public final Resource ElementList;\r
+    public final Resource Entity;\r
     public final Resource Time;\r
     public final Resource externalReferenceOf;\r
     public final Resource hasAttribute;\r
@@ -40,6 +41,7 @@ public class XMLResource {
         public static final String DateTime = "http://www.simantics.org/XML-1.0/DateTime";\r
         public static final String Element = "http://www.simantics.org/XML-1.0/Element";\r
         public static final String ElementList = "http://www.simantics.org/XML-1.0/ElementList";\r
+        public static final String Entity = "http://www.simantics.org/XML-1.0/Entity";\r
         public static final String Time = "http://www.simantics.org/XML-1.0/Time";\r
         public static final String externalReferenceOf = "http://www.simantics.org/XML-1.0/externalReferenceOf";\r
         public static final String hasAttribute = "http://www.simantics.org/XML-1.0/hasAttribute";\r
@@ -74,6 +76,7 @@ public class XMLResource {
         DateTime = getResourceOrNull(graph, URIs.DateTime);\r
         Element = getResourceOrNull(graph, URIs.Element);\r
         ElementList = getResourceOrNull(graph, URIs.ElementList);\r
+        Entity = getResourceOrNull(graph, URIs.Entity);\r
         Time = getResourceOrNull(graph, URIs.Time);\r
         externalReferenceOf = getResourceOrNull(graph, URIs.externalReferenceOf);\r
         hasAttribute = getResourceOrNull(graph, URIs.hasAttribute);\r
index 80e0b37c3f019c2dc65af24cdb47d24282d96ca0..e8dce2cefe6c6cd3825b07a9327035289d0e40a6 100644 (file)
@@ -3,7 +3,10 @@ package org.simantics.xml.sax.ui.wizard;
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.wizard.WizardPage;\r
 import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.events.SelectionAdapter;\r
+import org.eclipse.swt.events.SelectionEvent;\r
 import org.eclipse.swt.layout.GridLayout;\r
+import org.eclipse.swt.widgets.Button;\r
 import org.eclipse.swt.widgets.Composite;\r
 import org.simantics.utils.ui.widgets.DirectorySelectionWidget;\r
 import org.simantics.utils.ui.widgets.FileOrDirectorySelectionWidget;\r
@@ -19,6 +22,10 @@ public class InputSelectionPage extends WizardPage implements FileSelectionListe
        private FileSelectionWidget schemaSelection;\r
        private FileSelectionWidget configurationSelection;\r
        private DirectorySelectionWidget pluginSelection;\r
+       \r
+       boolean createPGraph = true;\r
+       boolean createImporter = true;\r
+       boolean createExporter = true;\r
 \r
        @Override\r
        public void createControl(Composite parent) {\r
@@ -39,6 +46,34 @@ public class InputSelectionPage extends WizardPage implements FileSelectionListe
                schemaSelection.addListener(this);\r
                pluginSelection.addListener(this);\r
                \r
+               final Button pGraphButton = new Button(composite, SWT.CHECK);\r
+               final Button importButton = new Button(composite, SWT.CHECK);\r
+               final Button exportButton = new Button(composite, SWT.CHECK);\r
+               pGraphButton.setText("Create Ontology / .pgraph file");\r
+               importButton.setText("Create Importer");\r
+               exportButton.setText("Create Exporter");\r
+               pGraphButton.setSelection(createPGraph);\r
+               importButton.setSelection(createImporter);\r
+               exportButton.setSelection(createExporter);\r
+               pGraphButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               createPGraph = pGraphButton.getSelection();\r
+                       }\r
+               });\r
+               importButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               createImporter = importButton.getSelection();\r
+                       }\r
+               });\r
+               exportButton.addSelectionListener(new SelectionAdapter() {\r
+                       @Override\r
+                       public void widgetSelected(SelectionEvent e) {\r
+                               createExporter = exportButton.getSelection();\r
+                       }\r
+               });\r
+               \r
                setControl(composite);\r
                setPageComplete(false);\r
        }\r
@@ -49,6 +84,18 @@ public class InputSelectionPage extends WizardPage implements FileSelectionListe
                \r
        }\r
        \r
+       public boolean isCreateExporter() {\r
+               return createExporter;\r
+       }\r
+       \r
+       public boolean isCreateImporter() {\r
+               return createImporter;\r
+       }\r
+       \r
+       public boolean isCreatePGraph() {\r
+               return createPGraph;\r
+       }\r
+       \r
        public String getSchemaFilename() {\r
                if (schemaSelection.getFilename() == null ||schemaSelection.getFilename().length == 0)\r
                        return null;\r
index 7512c8adc375cdf78ef1b8ce65051f9ac59319ea..627381bfd84277adc17ad27210106d4c464431fb 100644 (file)
@@ -40,6 +40,9 @@ public class SchemaConversionWizard extends Wizard implements IImportWizard {
        \r
        public void doConversion() throws Exception {\r
                SchemaConverter converter = new SchemaConverter();\r
+               converter.setCreateExporter(inputSelectionPage.createExporter);\r
+               converter.setCreateImporter(inputSelectionPage.createImporter);\r
+               converter.setCreatePGraph(inputSelectionPage.createPGraph);\r
 \r
                File inputFile = new File(inputSelectionPage.getSchemaFilename());\r
                File configurationFile = null;\r
index 81930e6446e44b5d1c76853fe672e14b651673fc..1c1b2d95631b1f765493282a4bd409a5ac268b37 100644 (file)
                        </extension>\r
                </complexContent>\r
        </complexType>\r
+    </element>\r
+    \r
+    <element name="Rename" substitutionGroup="tns:ConversionRule">\r
+       <complexType>\r
+               <complexContent>\r
+                       <extension base="tns:ConversionRule">\r
+                               <sequence maxOccurs="unbounded" minOccurs="1">\r
+                                        <choice>\r
+                                          <element ref="tns:Element"></element>\r
+                                          <element ref="tns:ComplexType"></element>\r
+                                          <element ref="tns:Attribute"></element>\r
+                                       </choice>\r
+                               </sequence>\r
+                               <attribute name="Name" type="string"></attribute>\r
+                       </extension>\r
+               </complexContent>\r
+       </complexType>\r
     </element>
 </schema>
\ No newline at end of file
index ce18e92a6a19b37c0921b76c63b8c52c21e899f3..549d0cc13b5f4163b72c1e9b31cf2a526319342b 100644 (file)
@@ -1 +1 @@
-"c:\Program Files\Java\jdk1.8.0_60\bin\xjc" -d ../src configuration.xsd\r
+"c:\Program Files\Java\jdk1.8.0_112\bin\xjc" -d ../src configuration.xsd\r
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
new file mode 100644 (file)
index 0000000..1d97259
--- /dev/null
@@ -0,0 +1,846 @@
+package org.simantics.xml.sax;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.io.StringWriter;\r
+import java.util.Collections;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.xml.namespace.QName;\r
+\r
+import org.simantics.utils.datastructures.BijectionMap;\r
+import org.simantics.xml.sax.configuration.AttributeComposition;\r
+import org.simantics.xml.sax.configuration.Configuration;\r
+import org.simantics.xml.sax.configuration.IDProvider;\r
+import org.simantics.xml.sax.configuration.IDReference;\r
+import org.simantics.xml.sax.configuration.Rename;\r
+import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
+import org.w3._2001.xmlschema.Annotated;\r
+import org.w3._2001.xmlschema.Attribute;\r
+import org.w3._2001.xmlschema.AttributeGroup;\r
+import org.w3._2001.xmlschema.ComplexType;\r
+import org.w3._2001.xmlschema.Element;\r
+import org.w3._2001.xmlschema.LocalComplexType;\r
+import org.w3._2001.xmlschema.LocalSimpleType;\r
+import org.w3._2001.xmlschema.NamedAttributeGroup;\r
+import org.w3._2001.xmlschema.OpenAttrs;\r
+import org.w3._2001.xmlschema.Restriction;\r
+import org.w3._2001.xmlschema.Schema;\r
+import org.w3._2001.xmlschema.SimpleType;\r
+import org.w3._2001.xmlschema.TopLevelAttribute;\r
+\r
+public class ExporterGenerator extends JavaGenerator{\r
+       \r
+       public ExporterGenerator(Configuration configuration) {\r
+               super(configuration);\r
+       }\r
+\r
+       \r
+       \r
+       public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
+               this.schema = schema;\r
+               this.ontologyClassName = className;\r
+               this.converter = converter;\r
+               \r
+               \r
+               String packageParts[] = className.split("\\.");\r
+               String name = packageParts[packageParts.length-1];\r
+       \r
+               \r
+               ontShort = name.substring(0, 3).toUpperCase();\r
+               ontShort +=".";\r
+               String parserPackagePostfix = "_exp";\r
+               String importerClassPostfix = "Exporter";\r
+               String parserClassPostfix = "Writer";\r
+               elementPackageName = name+parserPackagePostfix;\r
+               \r
+               importParserDir= new File(converter.getParserDir().getAbsolutePath()+"/"+elementPackageName);\r
+               if (!importParserDir.exists())\r
+                       importParserDir.mkdirs();\r
+               \r
+               handle(schema);\r
+               // Create Importer class\r
+               File importerFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+importerClassPostfix+".java");\r
+               PrintWriter mainWriter = createFile(importerFile);\r
+               mainWriter.println("package " + converter.getPluginName() +";");\r
+               mainWriter.println();\r
+               mainWriter.println("import java.io.File;");\r
+               mainWriter.println("import org.simantics.db.Resource;");\r
+               mainWriter.println("import org.simantics.db.Session;");\r
+               mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
+               mainWriter.println("import org.simantics.xml.sax.base.AbstractExporter;");\r
+               mainWriter.println();\r
+               mainWriter.println("public class " + name + importerClassPostfix+" extends AbstractExporter {");\r
+               mainWriter.println();\r
+               mainWriter.println("   public " + name + importerClassPostfix+"(Session session, File file, Resource root) throws DatabaseException {");\r
+               mainWriter.println("      super(session, file, root);");\r
+               mainWriter.println("      setXmlWriter(new "+name + parserClassPostfix+"(session));");\r
+               mainWriter.println("   }");\r
+               mainWriter.println();\r
+               mainWriter.println("}");\r
+               \r
+               mainWriter.println();\r
+               mainWriter.flush();\r
+               mainWriter.close();\r
+               \r
+               // Create Parser class\r
+               File parserFile = new File(converter.getParserDir().getAbsolutePath()+"/"+name+parserClassPostfix+".java");\r
+               mainWriter = createFile(parserFile);\r
+               mainWriter.println("package " + converter.getPluginName() +";");\r
+               mainWriter.println();\r
+               mainWriter.println("import org.simantics.xml.sax.base.XMLWriter;");\r
+               mainWriter.println("import org.simantics.db.ReadGraph;");\r
+               mainWriter.println("import org.simantics.db.Session;");\r
+               mainWriter.println("import org.simantics.db.exception.DatabaseException;");\r
+               mainWriter.println("import org.simantics.db.common.request.ReadRequest;");\r
+               mainWriter.println();\r
+               mainWriter.println("public class " + name + parserClassPostfix+" extends XMLWriter {");\r
+               mainWriter.println();\r
+               mainWriter.println("   public " + name + parserClassPostfix+"(Session session) throws DatabaseException {");\r
+               if (schema.getTargetNamespace() != null)\r
+               mainWriter.println("      setSchemaURI(\""+schema.getTargetNamespace()+"\");");\r
+               mainWriter.println("      session.syncRequest(new ReadRequest() {");\r
+               mainWriter.println("        @Override");\r
+               mainWriter.println("        public void run(ReadGraph graph) throws DatabaseException {");\r
+               mainWriter.println("          setGraph(graph);");\r
+               for (String s : ruleClassNames) {\r
+               mainWriter.println("          add(new "+s+"(graph));");\r
+               }\r
+               mainWriter.println("        }");\r
+               mainWriter.println("      });");\r
+               mainWriter.println("   }");\r
+               mainWriter.println("}");\r
+               \r
+               mainWriter.println();\r
+               mainWriter.flush();\r
+               mainWriter.close();\r
+       }\r
+       \r
+       protected void handle(TopLevelAttribute topLevelAttribute) {\r
+\r
+       }\r
+       \r
+       @Override\r
+       protected String getBaseClass() {\r
+               return "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
+       }\r
+       \r
+\r
+       @Override\r
+       protected void handleComplexType(SchemaObject complexTypeObj) {\r
+               ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
+               \r
+               String name = getName(complexTypeObj);//topLevelComplexType.getName();\r
+               \r
+               String className = name;//"_"+name;\r
+               \r
+               FileWriter fw = new FileWriter();\r
+               try {\r
+                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               writers.put(complexTypeObj, fw);\r
+               \r
+               boolean isList = false;\r
+\r
+               String baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildWriterBase";\r
+               \r
+               boolean inherited = false;\r
+               \r
+               QName type = getComplexTypeBase(topLevelComplexType);\r
+               if (type != null && !type.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema")) {\r
+                       baseClass = getName(complexTypeName.get(type.getLocalPart()));\r
+                       inherited = true;\r
+               }\r
+               \r
+               provider = getIDProvider(topLevelComplexType);\r
+               List<IDReference> references = getIDReferences(topLevelComplexType);\r
+               UnrecognizedChildElement unknownChildElement = getUnknown(topLevelComplexType);\r
+\r
+//             List<String> intrerfaces = new ArrayList<String>();\r
+//             if (references.size() > 0)\r
+//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
+//             if (unknownChildElement != null)\r
+//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
+               \r
+               createClassHeader(fw.writer);\r
+               writeClass(fw.writer,false, null, className, baseClass, Collections.EMPTY_LIST);\r
+                       \r
+//             writeIDProvider(fw.writer);\r
+       \r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");\r
+               fw.writer.println("      "+getOntologyImport());\r
+               fw.writer.println("      return "+ontShort+name+";");\r
+               fw.writer.println("   }");\r
+               fw.writer.println();\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
+//             fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");\r
+//             fw.writer.println("      "+getOntologyImport());\r
+//             if (!isList) {\r
+//             fw.writer.println("      Resource res = graph.newResource();");\r
+//             fw.writer.println("      graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
+//             } else {\r
+//             fw.writer.println("      Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
+//             }\r
+//             fw.writer.println("      return res;");\r
+//             fw.writer.println("   }");\r
+//             fw.writer.println();\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
+//             fw.writer.println("      "+getOntologyImport());\r
+//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");\r
+//             fw.writer.println("      return true;");\r
+//             fw.writer.println("   }");\r
+//             fw.writer.println();\r
+                               \r
+               StringWriter stringWriter = new StringWriter();\r
+               fw.delayedWriter = new PrintWriter(stringWriter);\r
+               StringWriter stringWriter2 = new StringWriter();\r
+               fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
+               \r
+               fw.writer.println("   public " + className + "(ReadGraph graph) {");\r
+               fw.writer.println("      super(graph);");\r
+               fw.writer.println("      "+getOntologyImport());\r
+               \r
+               handleComplexTypeExtension(complexTypeObj);\r
+               \r
+               fw.writer.println("   }");\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
+//             fw.writer.println("      "+getOntologyImport());\r
+//             \r
+//             if (stringWriter.getBuffer().length() > 0) {\r
+//                     fw.writer.write(stringWriter.toString());\r
+//             }\r
+//             \r
+//             \r
+//             fw.writer.println("      return false;");\r
+//             fw.writer.println("   }");\r
+//             fw.writer.println();\r
+               \r
+               if (stringWriter2.getBuffer().length() > 0) {\r
+                       fw.writer.write(stringWriter2.toString());\r
+               }\r
+               \r
+               stringWriter = null;\r
+               fw.delayedWriter.close();\r
+               fw.delayedWriter=null;\r
+               stringWriter2 = null;\r
+               fw.delayedWriter2.close();\r
+               fw.delayedWriter2 = null;\r
+               \r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
+               if (inherited) {\r
+               fw.writer.println("             super.attributes(graph,instance,attributes,writer);");\r
+               }\r
+               fw.writer.println("        "+getOntologyImport());\r
+               fw.writer.println("        for (Statement attribute : attributes) {");\r
+               handleComplexTypeAttributes(complexTypeObj);\r
+               handleExtensionAttributes(complexTypeObj);\r
+               fw.writer.println("        }");\r
+               fw.writer.println("   }");\r
+               \r
+//             writeIDReferences(fw.writer,name, references);\r
+//             writeUnknownChild(fw.writer,name,unknownChildElement);\r
+               \r
+               fw.writer.println("}");\r
+               fw.writer.println();\r
+               fw.writer.flush();\r
+               fw.writer.close();\r
+               fw.writer = null;\r
+               writers.remove(complexTypeObj);\r
+               provider = null;\r
+       }\r
+       \r
+       \r
+       \r
+       @Override\r
+       protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, QName refType) {\r
+               FileWriter fw = getWriter(parent);\r
+               String binding = getBindingFromPrimitiveType(refType);\r
+               if (binding == null) {\r
+                       SchemaObject refElement = elementName.get(refType.getLocalPart());\r
+                       SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
+\r
+                       String className = null;\r
+                       String refClassName = null;\r
+                       if (refElement != null)\r
+                               className = getName(refElement);\r
+                       else\r
+                               className = getName(refComplexType);\r
+                       \r
+                       if (refComplexType != null) {\r
+                               refClassName = getName(refComplexType);\r
+                       } else {\r
+                               refClassName = getName(refElement);\r
+                       }\r
+                       \r
+                       if (!reference)\r
+                       fw.writer.println("        addTypeWriter("+ontShort+ className +", "+className+".class);");\r
+                       else\r
+                       fw.writer.println("        addWriter("+className+".class);");\r
+                       if (!className.equals(refClassName))\r
+                       fw.writer.println("        addWriter("+refClassName+".class);");\r
+                       \r
+//                     fw.delayedWriter.println("         if (child.getElementParser() instanceof "+refClassName+"){");\r
+//                     fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
+//                     if (useElementList(parent, indicator,element, reference, ref, refType)) {\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, refType)) {\r
+//                     // generic list\r
+//                     fw.delayedWriter.println("            {");\r
+//                     fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
+//                     fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\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(), XML.hasOriginalElementList,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
+//                     \r
+//                     fw.delayedWriter.println("            return true;");\r
+//                     fw.delayedWriter.println("         }");\r
+               } else {\r
+                       SchemaObject refElement = elementName.get(refType.getLocalPart());\r
+                       //writer.println(commentTag+ontShort+"."+parent+".has"+ref + " <R " +  ontShort+".hasElement");\r
+                       fw.writer.println("        addRelationWriter("+ ontShort +getName(parent) + "_has"+ref+", "+getName(parent) +"_" +ref+".class);");\r
+                       \r
+                       fw.delayedWriter2.println("   public static class " + getName(parent) +"_" +ref+" extends org.simantics.xml.sax.base.ValueElementWriter {");\r
+                       fw.delayedWriter2.println("      public "+ getName(parent) +"_" +ref +"(){");\r
+                       //fw.delayedWriter2.println("           super(\""+ref+"\"," +this.ontologyClassName+".URIs."+getName(parent) + "_has"+ref+", "+binding+");");\r
+                       fw.delayedWriter2.println("           super(\""+ref+"\",null, "+binding+");");\r
+                       fw.delayedWriter2.println("       }");\r
+                       fw.delayedWriter2.println("   }");\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, OpenAttrs attrs) {\r
+               FileWriter fw = getWriter(parent);\r
+               SchemaObject obj = getWithObj(parent, attrs);\r
+       \r
+               String className = getName(obj);\r
+\r
+               if (!reference)\r
+               fw.writer.println("        addTypeWriter("+ ontShort+getName(obj) +", "+className+".class);");\r
+               else\r
+               fw.writer.println("        addWriter("+className+".class);");\r
+               \r
+               fw.delayedWriter.println("         if (child.getElementParser() instanceof "+className+"){");\r
+               fw.delayedWriter.println("            graph.claim(element.getData(), "+ontShort+getName(parent)+"_has"+ref + ", child.getData());");\r
+//             if (useElementList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\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
+//             fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
+//             fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\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(), XML.hasOriginalElementList,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
+//             \r
+//             fw.delayedWriter.println("            return true;");\r
+//             fw.delayedWriter.println("         }");\r
+               \r
+       }\r
+       \r
+       @Override\r
+       protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {               \r
+               // generates overriding method that allows writing any element\r
+               FileWriter fw = getWriter(parent);\r
+               fw.delayedWriter2.println("   @Override");\r
+               fw.delayedWriter2.println("   public Class<? extends org.simantics.xml.sax.base.XMLElementWriter> getWriter(ReadGraph graph, java.util.Map<Resource, org.simantics.xml.sax.base.XMLElementWriter> writers, WriterElement child) throws DatabaseException{");\r
+               fw.delayedWriter2.println("      Class<? extends org.simantics.xml.sax.base.XMLElementWriter> writerClass = super.getWriter(graph, writers, child);");\r
+               fw.delayedWriter2.println("      if (writerClass != null) return writerClass;");\r
+               fw.delayedWriter2.println("      Resource type = graph.getSingleType(child.instance);");\r
+               fw.delayedWriter2.println("      org.simantics.xml.sax.base.XMLElementWriter writer = writers.get(type);");\r
+               fw.delayedWriter2.println("      if (writer != null) return writer.getClass();");\r
+               fw.delayedWriter2.println("      return null;");\r
+               fw.delayedWriter2.println("   }");\r
+       }\r
+       \r
+       \r
+       \r
+       \r
+       @Override       \r
+       protected void handle(SchemaObject parent, Attribute attribute) {\r
+               String name = attribute.getName();\r
+               QName primitiveType = attribute.getType();\r
+               SimpleType simpleType = attribute.getSimpleType();\r
+               QName ref = attribute.getRef();\r
+               \r
+               String relationName;\r
+               String attrName;\r
+               if (name != null) {\r
+                       attrName = name;\r
+                       relationName = ontShort+"has"+name;\r
+                       if (parent != null)\r
+                               relationName = ontShort+getName(parent)+"_has"+name;\r
+               }\r
+               else if (ref != null && parent != null) {\r
+                       attrName = ref.getLocalPart();\r
+                       relationName = ontShort+getName(parent)+"_has"+ref.getLocalPart();\r
+                       \r
+                       Attribute referred = getRefAttribute(ref);\r
+                       if (referred != null) {\r
+                               primitiveType = referred.getType();\r
+                               simpleType = referred.getSimpleType();\r
+                       }\r
+                       \r
+               } else {\r
+                       throw new RuntimeException();\r
+               }\r
+               boolean isReference = false;\r
+               if (provider!= null && provider.getAttribute().getName().equals(attrName))\r
+                       isReference = true;\r
+               \r
+               FileWriter fw = getWriter(parent);\r
+               if (primitiveType != null) {\r
+                       \r
+                       //String binding = getBindingFromPrimitiveType(primitiveType);\r
+                       TypeEntry binding = getTypeEntry(primitiveType);\r
+                       \r
+                       if (binding != null) {\r
+                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
+                               return;\r
+                   } else {\r
+                       if (simpleType == null) {\r
+                               SchemaObject simpleTypeObj = simpleTypeName.get(primitiveType.getLocalPart());\r
+                               if (simpleTypeObj != null)\r
+                                       simpleType = simpleTypeObj.getSimpleType();\r
+                       }       \r
+                   }\r
+               } \r
+               if (simpleType != null) {\r
+                       org.w3._2001.xmlschema.List list = simpleType.getList();\r
+                       if (list != null) {\r
+                               TypeEntry binding = getTypeEntry(new QName(SCHEMA_NS, "string"));\r
+                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
+                       } else {\r
+                               Restriction restriction = simpleType.getRestriction();\r
+                               if (restriction == null)\r
+                                       throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart()+ ", SimpleType restriction is unset");\r
+                               QName base = restriction.getBase();\r
+                               \r
+                               \r
+                               //String binding = getBindingFromPrimitiveType(base);\r
+                               TypeEntry binding = getTypeEntry(base);\r
+                               writeAttribute(fw, attrName, relationName, binding, isReference);\r
+                       }\r
+               } else {\r
+                       // TODO : using default String attribute should be configured with rules.\r
+                       //throw new RuntimeException("Cannot resolve type for Attribute " + attrName + " -> " + primitiveType.getLocalPart());\r
+                       fw.writer.println("    //FIXME: Cannot resolve type for Attribute " + attrName + " Using default type String");\r
+                       //writeAttribute(fw, attrName, relationName, "STRING", isReference);\r
+                       writeAttribute(fw, attrName, relationName, getTypeEntry("string"), isReference);\r
+               }\r
+       }\r
+       \r
+       //private void writeAttribute(FileWriter fw, String attrName, String relationName, String binding, boolean isReference) {\r
+       private void writeAttribute(FileWriter fw, String attrName, String relationName, TypeEntry binding, boolean isReference) {\r
+               fw.writer.println("      {");\r
+               fw.writer.println("         if (attribute.getPredicate().equals("+relationName+")) {"); \r
+               fw.writer.println("            writer.writeAttribute(\""+attrName+"\", " + binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
+       //      fw.writer.println("            graph.claimLiteral(element.getData(),"+relationName+","+getValueGetterMethod(binding,"a")+", "+binding.binding+");");\r
+       //      if (isReference)\r
+       //      fw.writer.println("            idProviderValue = a.getValue();");       \r
+               fw.writer.println("         }");\r
+               fw.writer.println("      }");\r
+       }\r
+       \r
+       @Override\r
+       protected void handleAttributes(SchemaObject simpleTypeObj) {\r
+               SchemaObject parent = simpleTypeObj.getParent();\r
+               FileWriter fw = getWriter(parent);\r
+               \r
+               SimpleType simpleType = simpleTypeObj.getSimpleType();\r
+               Restriction restriction = simpleType.getRestriction();\r
+               if (restriction == null)\r
+                       throw new RuntimeException("Cannot resolve type for Element " + getName(parent));\r
+               QName base = restriction.getBase();\r
+               \r
+               \r
+               //String binding = getBindingFromPrimitiveType(base);\r
+               TypeEntry binding = getTypeEntry(base);\r
+               \r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
+               fw.writer.println("            writer.writeCharacters("+ binding.getToString("graph.getValue(attribute.getObject(),"+binding.binding+")")+");");\r
+//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
+               fw.writer.println("   }");\r
+       }\r
+       \r
+       @Override\r
+       protected void handle(SchemaObject parent, AttributeGroup attribute) {\r
+               if (parent != null) {\r
+                       FileWriter fw = getWriter(parent);\r
+                       NamedAttributeGroup group = getAttributeGroup(attribute.getRef().getLocalPart());\r
+                       fw.writer.println(commentTag+"    AttributeGroup " + group.getName());\r
+                       SchemaObject obj = new SchemaObject(parent,attribute);\r
+                       for (Annotated annotated : group.getAttributeOrAttributeGroup()) {\r
+                               if (annotated instanceof Attribute) {\r
+                                       //handle("AttributeGroups_"+group.getName(),(Attribute)annotated);\r
+                                       handle(obj,(Attribute)annotated);\r
+                               } else if (annotated instanceof AttributeGroup) {\r
+                                       //handle("AttributeGroups_"+group.getName(),(AttributeGroup)annotated);\r
+                                       handle(obj,(AttributeGroup)annotated);\r
+                               }\r
+                       }\r
+                       fw.writer.println(commentTag+"    End of AttributeGroup " + group.getName());\r
+               }\r
+               \r
+       }\r
+       \r
+       @Override\r
+       protected void handleAttributeComposition(SchemaObject parent, AttributeComposition composition, BijectionMap<org.simantics.xml.sax.configuration.Attribute, Annotated> attributes) {\r
+               FileWriter fw = getWriter(parent);\r
+               QName type = new QName(CONVERSION_NS, composition.getType());\r
+               TypeEntry typeEntry = getTypeEntry(type);\r
+               String arrayBinding = typeEntry.binding;//getBindingFromPrimitiveType(type);\r
+               String javaType = typeEntry.javaType;//getJavaTypeFromPrimitiveType(type);\r
+               String name = composition.getName();\r
+               \r
+               String relationName;\r
+               if (name != null) {\r
+                       relationName = ontShort+"has"+name;\r
+                       if (parent != null)\r
+                               relationName = ontShort+getName(parent)+"_has"+name;\r
+               } else {\r
+                       throw new RuntimeException();\r
+               }\r
+               fw.writer.println("      if (attribute.getPredicate().equals("+relationName+")) {");\r
+               fw.writer.println("            "+javaType+" value = ("+javaType+")graph.getValue(attribute.getObject(),"+arrayBinding+");");\r
+               //fw.writer.println("            writer.writeAttribute("+attrName+", graph.getValue(attribute.getObject(),"+binding.binding+").toString());");\r
+\r
+               int i = 0;\r
+               for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute())\r
+               fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\","+typeEntry.getElementToString("value["+(i++)+"]")+");");\r
+               //fw.writer.println("            writer.writeAttribute(\""+a.getName()+"\",value["+(i++)+"].toString());");\r
+//             fw.writer.println("         Attribute a"+(i++)+" = element.getAttribute(\"" +a.getName()+"\");");\r
+//             fw.writer.print  ("         "+javaType + " value = new "+javaType+"{");\r
+               i = 0;\r
+               // FIXME : handle optional attributes properly.\r
+//             for (org.simantics.xml.sax.configuration.Attribute a : composition.getAttribute()) {\r
+//                     Attribute attribute = ((Attribute)attributes.getRight(a));\r
+//                     //QName atype = getBaseType(attribute);\r
+//                     QName atype = getPrimitiveType(attribute);\r
+//                     String defaultValue = attribute.getDefault();\r
+//                     if (defaultValue == null)\r
+//                         defaultValue = getDefaultValue(atype);\r
+//                             \r
+//                     //String binding = getBindingFromPrimitiveType(atype);\r
+//                     TypeEntry binding = getTypeEntry(atype);\r
+//                     if (i > 0)\r
+//                             fw.writer.print(",");\r
+//                     if (defaultValue != null)\r
+//                             fw.writer.print("a"+(i)+"!= null ? "+ getValueGetterMethod(binding,"a"+(i++)) + " : " +defaultValue);\r
+//                     else\r
+//                             fw.writer.print(getValueGetterMethod(binding,"a"+(i++)));\r
+//             }\r
+//             fw.writer.println("};");\r
+//             fw.writer.println("         graph.claimLiteral(element.getData(),"+relationName+", value, "+arrayBinding+");");\r
+               fw.writer.println("      }");\r
+               \r
+       }\r
+       \r
+       protected String getDefaultValue(QName atype) {\r
+               Map<String,TypeEntry> types = typeMap.get(atype.getNamespaceURI());\r
+               if (types == null)\r
+                       return null;\r
+               TypeEntry entry =  types.get(atype.getLocalPart());\r
+               if (entry == null)\r
+                       return null;\r
+               return entry.defaultValue;\r
+       }\r
+       \r
+       \r
+       @Override\r
+       protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
+\r
+       }\r
+       \r
+       \r
+       \r
+       IDProvider provider;\r
+       @Override\r
+       protected void handleElement(SchemaObject elementObj)  {\r
+               Element element = elementObj.getElement();\r
+               \r
+               String name = getName(elementObj);//topLevelElement.getName();\r
+               String className = name;\r
+               \r
+               FileWriter fw = new FileWriter();\r
+               try {\r
+                       fw.writer = createFile(new File(importParserDir.getAbsolutePath()+"/"+className+".java"));\r
+               } catch (IOException e) {\r
+                       throw new RuntimeException(e);\r
+               }\r
+               writers.put(elementObj, fw);\r
+               boolean isList = false;\r
+               \r
+               Inheritance inhertiance = getElementInheritance(elementObj);    \r
+               \r
+               provider = getIDProvider(element);\r
+               List<IDReference> references = getIDReferences(element);\r
+               UnrecognizedChildElement unknownChildElement = getUnknown(element);\r
+\r
+//             List<String> intrerfaces = new ArrayList<String>();\r
+//             if (references.size() > 0)\r
+//                     intrerfaces.add("org.simantics.xml.sax.base.IDReferenceParser");\r
+//             if (unknownChildElement != null)\r
+//                     intrerfaces.add("org.simantics.xml.sax.base.UnrecognizedElementParser");\r
+\r
+               createClassHeader(fw.writer);\r
+               writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, Collections.EMPTY_LIST);\r
+//             writeIDProvider(fw.writer);\r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public Resource getType(ReadGraph graph) throws DatabaseException {");\r
+               fw.writer.println("      "+getOntologyImport());\r
+               fw.writer.println("      return "+ontShort+name+";");\r
+//             if (!isList) {\r
+//             fw.writer.println("      Resource res = graph.newResource();");\r
+//             fw.writer.println("      graph.claim(res, L0.InstanceOf, "+ontShort+name+");");\r
+//             } else {\r
+//             fw.writer.println("      Resource res = ListUtils.create(graph, "+ontShort+name+", Collections.EMPTY_LIST);");\r
+//             }\r
+//             fw.writer.println("      return res;");\r
+               fw.writer.println("   }");\r
+               fw.writer.println();\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
+//             fw.writer.println("      "+getOntologyImport());\r
+//             fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");\r
+//             fw.writer.println("      return true;");\r
+//             fw.writer.println("   }");\r
+//             fw.writer.println();\r
+               LocalComplexType complexType = element.getComplexType();\r
+               LocalSimpleType simpleType = element.getSimpleType();\r
+               \r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public void attributes(ReadGraph graph, WriterElement instance, Collection<Statement> attributes, XMLStreamWriter writer) throws XMLStreamException, DatabaseException{");\r
+               if (inhertiance.type == InheritanceType.ComplexType) {\r
+               fw.writer.println("        super.attributes(graph,instance,attributes,writer);");\r
+               }\r
+               fw.writer.println("        "+getOntologyImport());\r
+               fw.writer.println("        for (Statement attribute : attributes) {");\r
+               if (complexType != null) {\r
+                       SchemaObject obj = complexTypes.get(complexType);\r
+                       handleElementComplexTypeAttributes(obj);\r
+               } \r
+               fw.writer.println("        }");\r
+               fw.writer.println("   }");\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
+//             if (inhertiance.type == InheritanceType.ComplexType) {\r
+//             fw.writer.println("             super.configure(graph,parents,element);");\r
+//             }\r
+//             fw.writer.println("        "+getOntologyImport());\r
+//             \r
+//             LocalComplexType complexType = element.getComplexType();\r
+//             LocalSimpleType simpleType = element.getSimpleType();\r
+//             \r
+//             if (complexType != null) {\r
+//                     SchemaObject obj = complexTypes.get(complexType);\r
+//                     handleElementComplexTypeAttributes(obj);\r
+//             } \r
+//             fw.writer.println("   }");\r
+               \r
+               if (inhertiance.type == InheritanceType.AtomicType) {\r
+               fw.writer.println();\r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");\r
+//             fw.writer.println("      graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
+//             fw.writer.println("   }");\r
+               fw.writer.println("   @Override");\r
+               fw.writer.println("   public void characters(ReadGraph graph, WriterElement instance, XMLStreamWriter writer) throws XMLStreamException, DatabaseException {");\r
+               fw.writer.println("            writer.writeCharacters("+inhertiance.atomicType.getToString("graph.getValue(instance.getResource(),"+inhertiance.atomicType.binding+")")+");");\r
+//             fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
+               fw.writer.println("   }");\r
+               }\r
+//             if (simpleType != null) {\r
+//                     SchemaObject obj = simpleTypes.get(simpleType);\r
+//                     handleElementSimpleTypeAttributes(obj);\r
+//             }\r
+               \r
+               \r
+               StringWriter stringWriter = new StringWriter();\r
+               fw.delayedWriter = new PrintWriter(stringWriter);\r
+               StringWriter stringWriter2 = new StringWriter();\r
+               fw.delayedWriter2 = new PrintWriter(stringWriter2);\r
+               \r
+               fw.writer.println("   public " + className + "(ReadGraph graph) {");\r
+               fw.writer.println("      super(graph);");\r
+               fw.writer.println("      "+getOntologyImport());\r
+               if (complexType != null) {\r
+                       SchemaObject obj = complexTypes.get(complexType);\r
+                       handleComplexTypeExtension(obj);\r
+               } else if (simpleType != null) {\r
+                       \r
+               }\r
+               \r
+               fw.writer.println("   }");\r
+               \r
+//             fw.writer.println("   @Override");\r
+//             fw.writer.println("   public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
+//             fw.writer.println("      "+getOntologyImport());\r
+//             \r
+//             if (stringWriter.getBuffer().length() > 0) {\r
+//                     fw.writer.write(stringWriter.toString());\r
+//             }\r
+//             if (inhertiance.type == InheritanceType.ComplexType) {\r
+//             fw.writer.println("      return super.connectChild(graph,element,child);");     \r
+//             } else {\r
+//             fw.writer.println("      return false;");\r
+//             }\r
+//             fw.writer.println("   }");\r
+//             fw.writer.println();\r
+               \r
+               if (stringWriter2.getBuffer().length() > 0) {\r
+                       fw.writer.write(stringWriter2.toString());\r
+               }\r
+               \r
+               stringWriter = null;\r
+               fw.delayedWriter.close();\r
+               fw.delayedWriter = null;\r
+               stringWriter2 = null;\r
+               fw.delayedWriter2.close();\r
+               fw.delayedWriter2 = null;\r
+               \r
+//             writeIDReferences(fw.writer,name, references);\r
+//             writeUnknownChild(fw.writer,name,unknownChildElement);\r
+\r
+               fw.writer.println("}");\r
+               fw.writer.println();\r
+               fw.writer.flush();\r
+               fw.writer.close();\r
+               fw.writer = null;\r
+               writers.remove(elementObj);\r
+               provider = null;\r
+               \r
+               ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
+       }\r
+       \r
+       \r
+//     private void writeIDProvider(PrintWriter writer) {\r
+//             if (provider != null) {\r
+//             writer.println("   java.lang.String idProviderValue = null;");\r
+//             writer.println();\r
+//             writer.println("   @Override");\r
+//             writer.println("   public java.lang.String getID() {");\r
+//             writer.println("        java.lang.String s = idProviderValue;");\r
+//             writer.println("        idProviderValue = null;");\r
+//             writer.println("        return s;");\r
+//             writer.println("   }");\r
+//             writer.println();\r
+//             if (provider.getPriority() != null) {\r
+//             writer.println("   @Override");\r
+//             writer.println("   public int idPriority() {");\r
+//             writer.println("        return " + provider.getPriority().intValue()+";");\r
+//             writer.println("   }"); \r
+//             }\r
+//             }\r
+//     }\r
+//     \r
+//     private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {\r
+//             if (references.size() > 0) {\r
+//             writer.println("   @Override");\r
+//             writer.println("   public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");\r
+//             writer.println("      "+getOntologyImport());\r
+//             writer.println("      boolean result = true;");\r
+//             for (IDReference ref : references) {\r
+//             writer.println("      {");\r
+//             writer.println("         Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");\r
+//             writer.println("         if (a != null) {");\r
+//             writer.println("            ParserElement refEle = map.get(a.value);");\r
+//             writer.println("            if (refEle != null) {");\r
+//             writer.println("               Resource ref = refEle.getData();");\r
+//             writer.println("               graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");\r
+//             writer.println("            } else {");\r
+//             writer.println("               result = false;");\r
+//             writer.println("            }");\r
+//             writer.println("         }");\r
+//             writer.println("      }");\r
+//             }\r
+//             writer.println("      return result;");\r
+//             writer.println("   }");\r
+//             writer.println();\r
+//             }\r
+//     }\r
+       \r
+//     private void writeUnknownChild(PrintWriter writer,String name, UnrecognizedChildElement unknownChildElement) {\r
+//             if (unknownChildElement == null)\r
+//                     return;\r
+//             \r
+//             writer.println("   @Override");\r
+//             writer.println("   public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");\r
+//             writer.println("    " + unknownChildElement.getJavaMethod());\r
+//             writer.println("   }");\r
+//             writer.println();\r
+//             \r
+//     }\r
+       \r
+       protected void createClassHeader(PrintWriter writer) {\r
+               writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");\r
+               writer.println();\r
+               writer.println("import org.simantics.databoard.Bindings;");\r
+               writer.println("import org.simantics.db.Resource;");\r
+               writer.println("import org.simantics.db.ReadGraph;");\r
+               writer.println("import org.simantics.db.Statement;");\r
+               writer.println("import org.simantics.db.exception.DatabaseException;");\r
+               writer.println("import org.simantics.xml.sax.base.WriterElement;");\r
+               writer.println("import org.simantics.xml.sax.ontology.XMLResource;");\r
+               writer.println("import java.util.Collection;");\r
+               writer.println("import javax.xml.stream.XMLStreamException;");\r
+               writer.println("import javax.xml.stream.XMLStreamWriter;");\r
+//             if (!isList) {\r
+//             writer.println("import org.simantics.layer0.Layer0;");\r
+//         } else {\r
+//         writer.println("import java.util.Collections;");\r
+//             writer.println("import org.simantics.db.common.utils.ListUtils;");\r
+//             }\r
+               writer.println();\r
+       }\r
+       \r
+\r
+\r
+}\r
index 4245e3e1b4d471cd19e233e757bd0ae977554578..cff6e923c9aa668dc6ae73e467366d9bd0238860 100644 (file)
@@ -16,6 +16,7 @@ import org.simantics.xml.sax.configuration.AttributeComposition;
 import org.simantics.xml.sax.configuration.Configuration;\r
 import org.simantics.xml.sax.configuration.IDProvider;\r
 import org.simantics.xml.sax.configuration.IDReference;\r
+import org.simantics.xml.sax.configuration.Rename;\r
 import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
 import org.w3._2001.xmlschema.Annotated;\r
 import org.w3._2001.xmlschema.Attribute;\r
@@ -32,24 +33,11 @@ import org.w3._2001.xmlschema.Schema;
 import org.w3._2001.xmlschema.SimpleType;\r
 import org.w3._2001.xmlschema.TopLevelAttribute;\r
 \r
-public class ImporterGenerator extends SchemaConversionBase{\r
+public class ImporterGenerator extends JavaGenerator{\r
        \r
        public ImporterGenerator(Configuration configuration) {\r
                super(configuration);\r
        }\r
-\r
-       String commentTag = "//";\r
-       \r
-       Schema schema;\r
-       String ontologyClassName;\r
-       SchemaConverter converter;\r
-       \r
-       List<String> ruleClassNames = new ArrayList<String>();\r
-       \r
-       String ontShort = "ONT"; \r
-       \r
-       File importParserDir;\r
-       String elementPackageName;\r
        \r
        public void createParser(Schema schema,String className, SchemaConverter converter) throws IOException {\r
                this.schema = schema;\r
@@ -88,12 +76,6 @@ public class ImporterGenerator extends SchemaConversionBase{
                mainWriter.println("      super(session, file, new "+name + parserClassPostfix+"());");\r
                mainWriter.println("   }");\r
                mainWriter.println();\r
-//             mainWriter.println("   @Override");\r
-//             mainWriter.println("   public void configure(XMLParser parser) {");\r
-//             for (String s : ruleClassNames) {\r
-//             mainWriter.println("      parser.add(new "+s+"());");\r
-//             }\r
-//             mainWriter.println("   }");\r
                mainWriter.println("}");\r
                \r
                mainWriter.println();\r
@@ -122,80 +104,12 @@ public class ImporterGenerator extends SchemaConversionBase{
                mainWriter.flush();\r
                mainWriter.close();\r
        }\r
-       \r
-       protected PrintWriter createFile(File file) throws IOException {\r
-               if (!file.exists())\r
-                       file.createNewFile();\r
-               PrintWriter writer = new PrintWriter(file);\r
-               for (String s : converter.getHeader()) {\r
-                       writer.println(commentTag + " " + s);   \r
-               }\r
-               writer.println();\r
-               return writer;\r
-       }\r
-       \r
-//     protected String getValueGetter(String binding,String name) {\r
-//             if (binding == null)\r
-//                     return name+".getValue()";\r
-//             if ("STRING".equals(binding))\r
-//                     return name+".getValue()";\r
-//             if ("BOOLEAN".equals(binding))\r
-//                     return "Boolean.parseBoolean("+name+".getValue())";\r
-//             if ("INTEGER".equals(binding))\r
-//                     return "Integer.parseInt("+name+".getValue())";\r
-//             if ("DOUBLE".equals(binding))\r
-//                     return "Double.parseDouble("+name+".getValue())";\r
-//             if ("FLOAT".equals(binding))\r
-//                     return "Float.parseFloat("+name+".getValue())";\r
-//             return name+".getValue()";\r
-//     }\r
-//     protected String getValueGetter(String binding) {\r
-//             if (binding == null)\r
-//                     return "value";\r
-//             if ("STRING".equals(binding))\r
-//                     return "value";\r
-//             if ("BOOLEAN".equals(binding))\r
-//                     return "Boolean.parseBoolean(value)";\r
-//             if ("INTEGER".equals(binding))\r
-//                     return "Integer.parseInt(value)";\r
-//             if ("DOUBLE".equals(binding))\r
-//                     return "Double.parseDouble(value)";\r
-//             if ("FLOAT".equals(binding))\r
-//                     return "Float.parseFloat(value)";\r
-//             return "value";\r
-//     }\r
-       protected String getValueGetterMethod(TypeEntry binding,String name) {\r
-               if (binding == null)\r
-                       return name+".getValue()";\r
-               return binding.getValueGetterMethod(name);\r
-       }\r
-       \r
-       protected String getValueGetter(TypeEntry binding,String name) {\r
-               if (binding == null)\r
-                       return name;\r
-               return binding.getValueGetter(name);\r
-       }\r
-       protected String getValueGetter(TypeEntry binding) {\r
-               if (binding == null)\r
-                       return "value";\r
-               return binding.getValueGetter();\r
-       }\r
-       \r
+\r
        protected void handle(TopLevelAttribute topLevelAttribute) {\r
 \r
        }\r
        \r
-\r
-       \r
-       public static String getComplexTypePrefix() {\r
-               return "ComplexTypes_";\r
-       }       \r
        \r
-       public static String getAttributeGroupPrefix() {\r
-               return "AttributeGroups_";\r
-       }\r
-       \r
-       private Map<SchemaObject, FileWriter> writers = new HashMap<SchemaObject, ImporterGenerator.FileWriter>();\r
        @Override\r
        protected void handleComplexType(SchemaObject complexTypeObj) {\r
                ComplexType topLevelComplexType = complexTypeObj.getComplexType();\r
@@ -240,7 +154,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                writeIDProvider(fw.writer);\r
        \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public Resource create(WriteGraph graph, Element element) throws DatabaseException{");\r
+               fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
                fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");\r
                fw.writer.println("      "+getOntologyImport());\r
                if (!isList) {\r
@@ -254,7 +168,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.writer.println();\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException{");\r
+               fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
                fw.writer.println("      "+getOntologyImport());\r
                fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(complexTypeObj,"has")+", element.getData());");\r
                fw.writer.println("      return true;");\r
@@ -274,7 +188,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.writer.println("   }");\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException{");\r
+               fw.writer.println("   public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
                fw.writer.println("      "+getOntologyImport());\r
                \r
                if (stringWriter.getBuffer().length() > 0) {\r
@@ -298,7 +212,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.delayedWriter2 = null;\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {");\r
+               fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
                if (inherited) {\r
                fw.writer.println("             super.configure(graph,parents,element);");\r
                }\r
@@ -321,30 +235,6 @@ public class ImporterGenerator extends SchemaConversionBase{
                provider = null;\r
        }\r
        \r
-       @Override\r
-       protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
-               if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {\r
-                       for (SchemaElement e : elements) {\r
-                               handle(parent, indicator, e);\r
-                       }\r
-               } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {\r
-                       String name = getChoiceName(elements);\r
-\r
-                       for (SchemaElement e : elements) {\r
-                               Element localElement = e.getElement();\r
-                               if (localElement.getName() != null) {\r
-                                       QName refType = localElement.getType();\r
-                                       if (refType != null)\r
-                                               handleIndicator(parent, indicator, e, false, name, refType);\r
-                               } else if (localElement.getRef() != null) {\r
-                                       QName refType = localElement.getRef();\r
-                                       handleIndicator(parent, indicator, e, true, name, refType);\r
-                               }\r
-                       }\r
-               }\r
-               \r
-       }\r
-       \r
        @Override\r
        protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, QName refType) {\r
                FileWriter fw = getWriter(parent);\r
@@ -352,15 +242,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                if (binding == null) {\r
                        SchemaObject refElement = elementName.get(refType.getLocalPart());\r
                        SchemaObject refComplexType = complexTypeName.get(refType.getLocalPart());\r
-//                     String className = refType.getLocalPart();\r
-//                     if (!isElementRef(refType.getLocalPart())) { \r
-//                             className = "_"+className;\r
-//                     }\r
-//                     \r
-//                     String refClassName = refType.getLocalPart();\r
-//                     if (isComplexTypeRef(refClassName)) {\r
-//                             refClassName = "_"+refClassName;\r
-//                     }\r
+\r
                        String className = null;\r
                        String refClassName = null;\r
                        if (refElement != null)\r
@@ -399,12 +281,10 @@ public class ImporterGenerator extends SchemaConversionBase{
                        if (useOriginalList(parent, indicator,element, reference, ref, refType)) {\r
                        // generic list\r
                        fw.delayedWriter.println("            {");\r
-                       //fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+"XML_hasOriginalElementList);");\r
                        fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
                        fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\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+"XML_hasOriginalElementList,list);");\r
                        fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,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
@@ -431,18 +311,8 @@ public class ImporterGenerator extends SchemaConversionBase{
                FileWriter fw = getWriter(parent);\r
                SchemaObject obj = getWithObj(parent, attrs);\r
        \r
-//             String className = refType.getLocalPart();\r
-//             if (!isElementRef(refType.getLocalPart())) { \r
-//                     className = "_"+className;\r
-//             }\r
-//             \r
-//             String refClassName = refType.getLocalPart();\r
-//             if (isComplexTypeRef(refClassName)) {\r
-//                     refClassName = "_"+refClassName;\r
-//             }\r
                String className = getName(obj);\r
-               \r
-               \r
+\r
                if (!reference)\r
                fw.writer.println("        addParser(\""+ ref +"\", "+className+".class);");\r
                else\r
@@ -466,12 +336,10 @@ public class ImporterGenerator extends SchemaConversionBase{
                if (useOriginalList(parent, indicator,element, reference, ref, new QName(obj.getName()))) {\r
                // generic list\r
                fw.delayedWriter.println("            {");\r
-               //fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(),"+ontShort+"XML_hasOriginalElementList);");\r
                fw.delayedWriter.println("               XMLResource XML = XMLResource.getInstance(graph);");\r
                fw.delayedWriter.println("               Resource list = graph.getPossibleObject(element.getData(), XML.hasOriginalElementList);");\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+"XML_hasOriginalElementList,list);");\r
                fw.delayedWriter.println("                  graph.claim(element.getData(), XML.hasOriginalElementList,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
@@ -486,9 +354,10 @@ public class ImporterGenerator extends SchemaConversionBase{
        \r
        @Override\r
        protected void handleIndicator(SchemaObject parent, SchemaElement indicator, SchemaElement any) {               \r
+               // generates overriding method that allows parsing any element\r
                FileWriter fw = getWriter(parent);\r
                fw.delayedWriter2.println("   @Override");\r
-               fw.delayedWriter2.println("   public Class<? extends org.simantics.xml.sax.base.XMLElementParser> getParser(java.util.Map<java.lang.String,org.simantics.xml.sax.base.XMLElementParser> parsers, Element element, Element child) {");\r
+               fw.delayedWriter2.println("   public Class<? extends org.simantics.xml.sax.base.XMLElementParser> getParser(java.util.Map<java.lang.String,org.simantics.xml.sax.base.XMLElementParser> parsers, ParserElement element, ParserElement child) {");\r
                fw.delayedWriter2.println("      Class<? extends org.simantics.xml.sax.base.XMLElementParser> parserClass = super.getParser(parsers, element, child);");\r
                fw.delayedWriter2.println("      if (parserClass != null) return parserClass;");\r
                fw.delayedWriter2.println("      org.simantics.xml.sax.base.XMLElementParser parser = parsers.get(child.getQName());");\r
@@ -496,19 +365,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.delayedWriter2.println("      return null;");\r
                fw.delayedWriter2.println("   }");\r
        }\r
-       \r
-       private FileWriter getWriter(SchemaObject obj) {\r
-               SchemaObject s = obj;\r
-               while (s != null) {\r
-                       FileWriter fw = writers.get(s);\r
-                       if (fw != null)\r
-                               return fw;\r
-                       s = s.getParent();\r
-               }\r
-               return null;\r
-       }\r
-       \r
-       \r
+\r
        @Override       \r
        protected void handle(SchemaObject parent, Attribute attribute) {\r
                String name = attribute.getName();\r
@@ -610,7 +467,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                //String binding = getBindingFromPrimitiveType(base);\r
                TypeEntry binding = getTypeEntry(base);\r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public void configure(WriteGraph graph, Element element, java.lang.String value) throws DatabaseException {");\r
+               fw.writer.println("   public void configure(WriteGraph graph, ParserElement element, java.lang.String value) throws DatabaseException {");\r
                //fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", Bindings."+binding+");");\r
                fw.writer.println("      graph.claimValue(element.getData(),"+getValueGetter(binding)+", "+binding.binding +");");\r
                fw.writer.println("   }");\r
@@ -700,8 +557,7 @@ public class ImporterGenerator extends SchemaConversionBase{
        protected void handleSimpleType(SchemaObject parent, SchemaObject simpleType) {\r
 \r
        }\r
-       \r
-       \r
+\r
        \r
        IDProvider provider;\r
        @Override\r
@@ -736,7 +592,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                writeClass(fw.writer,false, element.getName(), className, inhertiance.baseClass, intrerfaces);\r
                writeIDProvider(fw.writer);\r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public Resource create(WriteGraph graph, Element element) throws DatabaseException{");\r
+               fw.writer.println("   public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException{");\r
                fw.writer.println("      Layer0 L0 = Layer0.getInstance(graph);");\r
                fw.writer.println("      "+getOntologyImport());\r
                if (!isList) {\r
@@ -750,7 +606,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.writer.println();\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public boolean connectParent(WriteGraph graph, Element parent, Element element) throws DatabaseException{");\r
+               fw.writer.println("   public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element) throws DatabaseException{");\r
                fw.writer.println("      "+getOntologyImport());\r
                fw.writer.println("      graph.claim(parent.getData(), "+this.ontShort+getName(elementObj,"has")+", element.getData());");\r
                fw.writer.println("      return true;");\r
@@ -758,7 +614,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.writer.println();\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public void configure(WriteGraph graph, Deque<Element> parents, Element element) throws DatabaseException {");\r
+               fw.writer.println("   public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element) throws DatabaseException {");\r
                if (inhertiance.type == InheritanceType.ComplexType) {\r
                fw.writer.println("             super.configure(graph,parents,element);");\r
                }\r
@@ -776,14 +632,14 @@ public class ImporterGenerator extends SchemaConversionBase{
                if (inhertiance.type == InheritanceType.AtomicType) {\r
                fw.writer.println();\r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public void configure(WriteGraph graph, Element element, java.lang.String string) throws DatabaseException {");\r
+               fw.writer.println("   public void configure(WriteGraph graph, ParserElement element, java.lang.String string) throws DatabaseException {");\r
                fw.writer.println("      graph.claimValue(element.getData(), "+getValueGetter(inhertiance.atomicType,"string")+", "+inhertiance.atomicType.binding+");");\r
                fw.writer.println("   }");\r
                }\r
-               if (simpleType != null) {\r
-                       SchemaObject obj = simpleTypes.get(simpleType);\r
-                       handleElementSimpleTypeAttributes(obj);\r
-               }\r
+//             if (simpleType != null) {\r
+//                     SchemaObject obj = simpleTypes.get(simpleType);\r
+//                     handleElementSimpleTypeAttributes(obj);\r
+//             }\r
                \r
                \r
                StringWriter stringWriter = new StringWriter();\r
@@ -804,7 +660,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                fw.writer.println("   }");\r
                \r
                fw.writer.println("   @Override");\r
-               fw.writer.println("   public boolean connectChild(WriteGraph graph, Element element, Element child) throws DatabaseException{");\r
+               fw.writer.println("   public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException{");\r
                fw.writer.println("      "+getOntologyImport());\r
                \r
                if (stringWriter.getBuffer().length() > 0) {\r
@@ -842,99 +698,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                \r
                ruleClassNames.add(converter.getPluginName()+"."+elementPackageName+"."+name);\r
        }\r
-       \r
-       private enum InheritanceType{ComplexType,AtomicType,None};\r
-       \r
-       private class Inheritance {\r
-               public String baseClass;\r
-               public InheritanceType type;\r
-               public TypeEntry atomicType;\r
-               \r
-               public Inheritance() {\r
-                       baseClass = "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
-                       type = InheritanceType.None;\r
-               }\r
-       }\r
-       \r
-       private Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
-               Element topLevelElement = topLevelElementObj.getElement();\r
-               Inheritance inheritance = new Inheritance();\r
-               if (topLevelElement.getType() != null) {\r
-                       QName type = topLevelElement.getType();\r
-                       if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                               SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
-//                             if (obj == null)\r
-//                                     obj = simpleTypeName.get(type.getLocalPart());\r
-                               if (obj != null) {\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               }\r
-                       } else {\r
-                               TypeEntry entry = getTypeEntry(type);\r
-                               if (entry != null) {\r
-                                       inheritance.type = InheritanceType.AtomicType;\r
-                                       inheritance.atomicType = entry;\r
-                               }\r
-                       }\r
-               }\r
-               if (inheritance.type == InheritanceType.None) {\r
-                       QName type = getElementBase(topLevelElement);\r
-                       if (type != null) {\r
-                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               } else {\r
-                                       TypeEntry entry = getTypeEntry(type);\r
-                                       if (entry != null) {\r
-                                               inheritance.type = InheritanceType.AtomicType;\r
-                                               inheritance.atomicType = entry;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               if (inheritance.type == InheritanceType.None) {\r
-                       QName type = topLevelElement.getSubstitutionGroup();\r
-                       if (type != null) {\r
-                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
-                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
-                                       inheritance.baseClass = getName(obj);\r
-                                       inheritance.type = InheritanceType.ComplexType;\r
-                               } else {\r
-                                       TypeEntry entry = getTypeEntry(type);\r
-                                       if (entry != null) {\r
-                                               inheritance.type = InheritanceType.AtomicType;\r
-                                               inheritance.atomicType = entry;\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               return inheritance;\r
-       }\r
-       \r
-       private void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
-               writer.println("@SuppressWarnings(\"unused\")");\r
-               writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass);\r
-               if (interfaces.size() > 0) {\r
-                       writer.print(" implements ");\r
-                       for (int i = 0; i < interfaces.size(); i++) {\r
-                               writer.print(interfaces.get(i));\r
-                               if (i < interfaces.size() -1 )\r
-                                       writer.print(",");\r
-                       }\r
-               }\r
-               writer.println("{");\r
-               writer.println();\r
-               writer.println("   @Override");\r
-               writer.println("   public java.lang.String getElementId() {");\r
-               if (name != null)\r
-               writer.println("      return \""+name+"\";");\r
-               else // complex types cannot be parsed directly with name/id reference.\r
-               writer.println("      return null;");\r
-               writer.println("   }");\r
-               writer.println();\r
-       }\r
+\r
        \r
        private void writeIDProvider(PrintWriter writer) {\r
                if (provider != null) {\r
@@ -959,14 +723,14 @@ public class ImporterGenerator extends SchemaConversionBase{
        private void writeIDReferences(PrintWriter writer,String name, List<IDReference> references) {\r
                if (references.size() > 0) {\r
                writer.println("   @Override");\r
-               writer.println("   public boolean connectReferences(WriteGraph graph, Element element, java.util.Map<java.lang.String, Element> map) throws DatabaseException {");\r
+               writer.println("   public boolean connectReferences(WriteGraph graph, ParserElement element, java.util.Map<java.lang.String, ParserElement> map) throws DatabaseException {");\r
                writer.println("      "+getOntologyImport());\r
                writer.println("      boolean result = true;");\r
                for (IDReference ref : references) {\r
                writer.println("      {");\r
                writer.println("         Attribute a = element.getAttribute(\"" + ref.getIDSource().getName() +"\");");\r
                writer.println("         if (a != null) {");\r
-               writer.println("            Element refEle = map.get(a.value);");\r
+               writer.println("            ParserElement refEle = map.get(a.value);");\r
                writer.println("            if (refEle != null) {");\r
                writer.println("               Resource ref = refEle.getData();");\r
                writer.println("               graph.claim(element.getData(), "+ontShort+name+"_"+ref.getReference().getName()+", ref);");\r
@@ -987,13 +751,18 @@ public class ImporterGenerator extends SchemaConversionBase{
                        return;\r
                \r
                writer.println("   @Override");\r
-               writer.println("   public void configureChild(WriteGraph graph, Deque<Element> parents, Element element, Element child) throws DatabaseException {");\r
+               writer.println("   public void configureChild(WriteGraph graph, Deque<ParserElement> parents, ParserElement element, ParserElement child) throws DatabaseException {");\r
                writer.println("    " + unknownChildElement.getJavaMethod());\r
                writer.println("   }");\r
                writer.println();\r
                \r
        }\r
        \r
+       @Override\r
+       protected String getBaseClass() {\r
+               return "org.simantics.xml.sax.base.XMLElementNamedChildParserBase";\r
+       }\r
+       \r
        protected void createClassHeader(PrintWriter writer, boolean isList) {\r
                writer.println("package " + converter.getPluginName() +"."+elementPackageName+";");\r
                writer.println();\r
@@ -1003,7 +772,7 @@ public class ImporterGenerator extends SchemaConversionBase{
                writer.println("import org.simantics.db.WriteGraph;");\r
                writer.println("import org.simantics.db.exception.DatabaseException;");\r
                writer.println("import org.simantics.xml.sax.base.Attribute;");\r
-               writer.println("import org.simantics.xml.sax.base.Element;");\r
+               writer.println("import org.simantics.xml.sax.base.ParserElement;");\r
                writer.println("import org.simantics.xml.sax.ontology.XMLResource;");\r
                if (!isList) {\r
                writer.println("import org.simantics.layer0.Layer0;");\r
@@ -1014,93 +783,4 @@ public class ImporterGenerator extends SchemaConversionBase{
                writer.println();\r
        }\r
        \r
-       private String getOntologyImport() {\r
-               return this.ontologyClassName+" " +ontShort.substring(0, 3)+" = "+this.ontologyClassName+".getInstance(graph);";\r
-       }\r
-       \r
-       \r
-       private static class FileWriter {\r
-               public PrintWriter writer;\r
-               \r
-               public PrintWriter delayedWriter;\r
-               public PrintWriter delayedWriter2;\r
-       }\r
-       \r
-       public static String getName(SchemaObject obj) {\r
-               if (obj.getParent() == null) {\r
-                       switch (obj.getType()) {\r
-                       case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+obj.getName();\r
-                       case ELEMENT:\r
-                               return obj.getName();\r
-                       case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+obj.getName();\r
-                       case SIMPLE_TYPE:\r
-                               return obj.getName();\r
-                       }\r
-               } else {\r
-                       SchemaObject o = obj;\r
-                       SchemaObject prev = null;\r
-                       String name = "";\r
-                       while (o != null){\r
-                               if (o.getName() != null)\r
-                                       name = o.getName()+"_"+name;\r
-                               prev = o;\r
-                               o = o.getParent();\r
-                               if (prev.getObj() instanceof AttributeGroupRef)\r
-                                       o = null;\r
-                       }\r
-                       name = name.substring(0, name.length()-1);\r
-                       switch (prev.getType()) {\r
-                       case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+name;\r
-                       case ELEMENT:\r
-                               return name;\r
-                       case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+name;\r
-                       case SIMPLE_TYPE:\r
-                               return name;\r
-                       }\r
-               }\r
-               throw new RuntimeException();\r
-               \r
-       }\r
-       \r
-       public static String getName(SchemaObject obj, String rel) {\r
-               if (obj.getParent() == null) {\r
-                       switch (obj.getType()) {\r
-                       case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+rel+obj.getName();\r
-                       case ELEMENT:\r
-                               return rel+obj.getName();\r
-                       case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+rel+obj.getName();\r
-                       case SIMPLE_TYPE:\r
-                               return rel+obj.getName();\r
-                       }\r
-               } else {\r
-                       SchemaObject o = obj;\r
-                       SchemaObject prev = null;\r
-                       String name = "";\r
-                       while (o != null){\r
-                               if (o.getName() != null)\r
-                                       name = o.getName()+"_"+name;\r
-                               prev = o;\r
-                               o = o.getParent();\r
-                       }\r
-                       name = name.substring(0, name.length()-1);\r
-                       switch (prev.getType()) {\r
-                       case COMPLEX_TYPE:\r
-                               return getComplexTypePrefix()+rel+name;\r
-                       case ELEMENT:\r
-                               return rel+name;\r
-                       case ATTRIBUTE_GROUP:\r
-                               return getAttributeGroupPrefix()+rel+name;\r
-                       case SIMPLE_TYPE:\r
-                               return rel+name;\r
-                       }\r
-               }\r
-               throw new RuntimeException();\r
-               \r
-       }\r
 }\r
diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/JavaGenerator.java
new file mode 100644 (file)
index 0000000..6467734
--- /dev/null
@@ -0,0 +1,314 @@
+package org.simantics.xml.sax;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.PrintWriter;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.xml.namespace.QName;\r
+\r
+import org.simantics.xml.sax.configuration.Configuration;\r
+import org.w3._2001.xmlschema.AttributeGroupRef;\r
+import org.w3._2001.xmlschema.Element;\r
+import org.w3._2001.xmlschema.Schema;\r
+\r
+public abstract class JavaGenerator extends SchemaConversionBase{\r
+\r
+       String commentTag = "//";\r
+       \r
+       Schema schema;\r
+       String ontologyClassName;\r
+       SchemaConverter converter;\r
+       \r
+       List<String> ruleClassNames = new ArrayList<String>();\r
+       \r
+       String ontShort = "ONT"; \r
+       \r
+       File importParserDir;\r
+       String elementPackageName;\r
+       \r
+       Map<SchemaObject, FileWriter> writers = new HashMap<SchemaObject, ImporterGenerator.FileWriter>();\r
+       \r
+       public JavaGenerator(Configuration configuration) {\r
+               super(configuration);\r
+       }\r
+       \r
+       \r
+       protected PrintWriter createFile(File file) throws IOException {\r
+               if (!file.exists())\r
+                       file.createNewFile();\r
+               PrintWriter writer = new PrintWriter(file);\r
+               for (String s : converter.getHeader()) {\r
+                       writer.println(commentTag + " " + s);   \r
+               }\r
+               writer.println();\r
+               return writer;\r
+       }\r
+       \r
+       protected String getValueGetterMethod(TypeEntry binding,String name) {\r
+               if (binding == null)\r
+                       return name+".getValue()";\r
+               return binding.getValueGetterMethod(name);\r
+       }\r
+       \r
+       protected String getValueGetter(TypeEntry binding,String name) {\r
+               if (binding == null)\r
+                       return name;\r
+               return binding.getValueGetter(name);\r
+       }\r
+       protected String getValueGetter(TypeEntry binding) {\r
+               if (binding == null)\r
+                       return "value";\r
+               return binding.getValueGetter();\r
+       }\r
+       \r
+       public static String getComplexTypePrefix() {\r
+               return "ComplexTypes_";\r
+       }       \r
+       \r
+       public static String getAttributeGroupPrefix() {\r
+               return "AttributeGroups_";\r
+       }\r
+       \r
+       @Override\r
+       protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {\r
+               Element localElement = element.getElement();\r
+               if (localElement.getName() != null) {\r
+                       SchemaObject eObj = elements.get(localElement);\r
+                       String refName = localElement.getName();\r
+                       QName refType = localElement.getType();\r
+                       if (refType != null)\r
+                               handleIndicator(parent, indicator, element, false, refName, refType);\r
+                       else {\r
+                               handleElement(eObj);\r
+                               handleIndicator(parent, indicator, element, false, refName, localElement);\r
+                       }\r
+               } else if (localElement.getRef() != null) {\r
+                       QName refType = localElement.getRef();\r
+                       handleIndicator(parent, indicator,element, true, refType.getLocalPart(), refType);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       protected void handle(SchemaObject parent, SchemaElement indicator, List<SchemaElement> elements) {\r
+               if (indicator.getType() == SchemaElement.ElementType.SEQUENCE || (indicator.getType() == SchemaElement.ElementType.CHOICE && indicator.getRestriction().many())) {\r
+                       for (SchemaElement e : elements) {\r
+                               handle(parent, indicator, e);\r
+                       }\r
+               } else if (indicator.getType() == SchemaElement.ElementType.CHOICE) {\r
+                       String name = getChoiceName(elements);\r
+\r
+                       for (SchemaElement e : elements) {\r
+                               Element localElement = e.getElement();\r
+                               if (localElement.getName() != null) {\r
+                                       QName refType = localElement.getType();\r
+                                       if (refType != null)\r
+                                               handleIndicator(parent, indicator, e, false, name, refType);\r
+                               } else if (localElement.getRef() != null) {\r
+                                       QName refType = localElement.getRef();\r
+                                       handleIndicator(parent, indicator, e, true, name, refType);\r
+                               }\r
+                       }\r
+               }\r
+               \r
+       }\r
+       \r
+       protected String getOntologyImport() {\r
+               return this.ontologyClassName+" " +ontShort.substring(0, 3)+" = "+this.ontologyClassName+".getInstance(graph);";\r
+       }\r
+       \r
+       protected static class FileWriter {\r
+               public PrintWriter writer;\r
+               \r
+               public PrintWriter delayedWriter;\r
+               public PrintWriter delayedWriter2;\r
+       }\r
+       \r
+       protected  FileWriter getWriter(SchemaObject obj) {\r
+               SchemaObject s = obj;\r
+               while (s != null) {\r
+                       FileWriter fw = writers.get(s);\r
+                       if (fw != null)\r
+                               return fw;\r
+                       s = s.getParent();\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       \r
+       public static String getName(SchemaObject obj) {\r
+               if (obj.getParent() == null) {\r
+                       switch (obj.getType()) {\r
+                       case COMPLEX_TYPE:\r
+                               return getComplexTypePrefix()+obj.getName();\r
+                       case ELEMENT:\r
+                               return obj.getName();\r
+                       case ATTRIBUTE_GROUP:\r
+                               return getAttributeGroupPrefix()+obj.getName();\r
+                       case SIMPLE_TYPE:\r
+                               return obj.getName();\r
+                       }\r
+               } else {\r
+                       SchemaObject o = obj;\r
+                       SchemaObject prev = null;\r
+                       String name = "";\r
+                       while (o != null){\r
+                               if (o.getName() != null)\r
+                                       name = o.getName()+"_"+name;\r
+                               prev = o;\r
+                               o = o.getParent();\r
+                               if (prev.getObj() instanceof AttributeGroupRef)\r
+                                       o = null;\r
+                       }\r
+                       name = name.substring(0, name.length()-1);\r
+                       switch (prev.getType()) {\r
+                       case COMPLEX_TYPE:\r
+                               return getComplexTypePrefix()+name;\r
+                       case ELEMENT:\r
+                               return name;\r
+                       case ATTRIBUTE_GROUP:\r
+                               return getAttributeGroupPrefix()+name;\r
+                       case SIMPLE_TYPE:\r
+                               return name;\r
+                       }\r
+               }\r
+               throw new RuntimeException();\r
+               \r
+       }\r
+       \r
+       public static String getName(SchemaObject obj, String rel) {\r
+               if (obj.getParent() == null) {\r
+                       switch (obj.getType()) {\r
+                       case COMPLEX_TYPE:\r
+                               return getComplexTypePrefix()+rel+obj.getName();\r
+                       case ELEMENT:\r
+                               return rel+obj.getName();\r
+                       case ATTRIBUTE_GROUP:\r
+                               return getAttributeGroupPrefix()+rel+obj.getName();\r
+                       case SIMPLE_TYPE:\r
+                               return rel+obj.getName();\r
+                       }\r
+               } else {\r
+                       SchemaObject o = obj;\r
+                       SchemaObject prev = null;\r
+                       String name = "";\r
+                       while (o != null){\r
+                               if (o.getName() != null)\r
+                                       name = o.getName()+"_"+name;\r
+                               prev = o;\r
+                               o = o.getParent();\r
+                       }\r
+                       name = name.substring(0, name.length()-1);\r
+                       switch (prev.getType()) {\r
+                       case COMPLEX_TYPE:\r
+                               return getComplexTypePrefix()+rel+name;\r
+                       case ELEMENT:\r
+                               return rel+name;\r
+                       case ATTRIBUTE_GROUP:\r
+                               return getAttributeGroupPrefix()+rel+name;\r
+                       case SIMPLE_TYPE:\r
+                               return rel+name;\r
+                       }\r
+               }\r
+               throw new RuntimeException();\r
+       }\r
+       \r
+       protected enum InheritanceType{ComplexType,AtomicType,None};\r
+       \r
+       protected class Inheritance {\r
+               public String baseClass;\r
+               public InheritanceType type;\r
+               public TypeEntry atomicType;\r
+               \r
+               public Inheritance(String baseClass) {\r
+                       this.baseClass = baseClass;\r
+                       this.type = InheritanceType.None;\r
+               }\r
+       }\r
+       \r
+       protected void writeClass(PrintWriter writer,boolean abst, String name, String className, String baseClass, List<String> interfaces) {\r
+               writer.println("@SuppressWarnings(\"unused\")");\r
+               writer.print("public " +(abst ? "abstract " : "") + "class " + className + " extends "+baseClass);\r
+               if (interfaces.size() > 0) {\r
+                       writer.print(" implements ");\r
+                       for (int i = 0; i < interfaces.size(); i++) {\r
+                               writer.print(interfaces.get(i));\r
+                               if (i < interfaces.size() -1 )\r
+                                       writer.print(",");\r
+                       }\r
+               }\r
+               writer.println("{");\r
+               writer.println();\r
+               writer.println("   @Override");\r
+               writer.println("   public java.lang.String getElementId() {");\r
+               if (name != null)\r
+               writer.println("      return \""+name+"\";");\r
+               else // complex types cannot be parsed directly with name/id reference.\r
+               writer.println("      return null;");\r
+               writer.println("   }");\r
+               writer.println();\r
+       }\r
+       \r
+       protected abstract String getBaseClass();\r
+       \r
+       protected Inheritance getElementInheritance(SchemaObject topLevelElementObj) {\r
+               Element topLevelElement = topLevelElementObj.getElement();\r
+               Inheritance inheritance = new Inheritance(getBaseClass());\r
+               if (topLevelElement.getType() != null) {\r
+                       QName type = topLevelElement.getType();\r
+                       if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                               SchemaObject obj = complexTypeName.get(type.getLocalPart());\r
+//                             if (obj == null)\r
+//                                     obj = simpleTypeName.get(type.getLocalPart());\r
+                               if (obj != null) {\r
+                                       inheritance.baseClass = getName(obj);\r
+                                       inheritance.type = InheritanceType.ComplexType;\r
+                               }\r
+                       } else {\r
+                               TypeEntry entry = getTypeEntry(type);\r
+                               if (entry != null) {\r
+                                       inheritance.type = InheritanceType.AtomicType;\r
+                                       inheritance.atomicType = entry;\r
+                               }\r
+                       }\r
+               }\r
+               if (inheritance.type == InheritanceType.None) {\r
+                       QName type = getElementBase(topLevelElement);\r
+                       if (type != null) {\r
+                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
+                                       inheritance.baseClass = getName(obj);\r
+                                       inheritance.type = InheritanceType.ComplexType;\r
+                               } else {\r
+                                       TypeEntry entry = getTypeEntry(type);\r
+                                       if (entry != null) {\r
+                                               inheritance.type = InheritanceType.AtomicType;\r
+                                               inheritance.atomicType = entry;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               if (inheritance.type == InheritanceType.None) {\r
+                       QName type = topLevelElement.getSubstitutionGroup();\r
+                       if (type != null) {\r
+                               if (!type.getNamespaceURI().equals(SCHEMA_NS)) {\r
+                                       SchemaObject obj = getWithName(topLevelElementObj, type.getLocalPart());\r
+                                       inheritance.baseClass = getName(obj);\r
+                                       inheritance.type = InheritanceType.ComplexType;\r
+                               } else {\r
+                                       TypeEntry entry = getTypeEntry(type);\r
+                                       if (entry != null) {\r
+                                               inheritance.type = InheritanceType.AtomicType;\r
+                                               inheritance.atomicType = entry;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+               \r
+               return inheritance;\r
+       }       \r
+\r
+}\r
index 095de9d2c20049a9f543fdae21459ebc8ef1dc91..287156299dfe0213ee43f5f858ec44afd29ad04a 100644 (file)
@@ -37,20 +37,22 @@ public class OntologyGenerator extends SchemaConversionBase {
        String commentTag = "//";\r
        \r
        Schema schema;\r
-       \r
+       String ontologyName;\r
        String className;\r
        \r
        SchemaConverter converter;\r
        \r
        PrintWriter writer = null;\r
        \r
-       public String getClassName() {\r
-               return className;\r
-       }\r
        \r
-       public void createOntology(Schema schema, SchemaConverter converter) throws FileNotFoundException {\r
+       \r
+       \r
+       \r
+       public void createOntology(Schema schema, String ontologyName, String className, SchemaConverter converter) throws FileNotFoundException {\r
                this.schema = schema;\r
                this.converter = converter;\r
+               this.ontologyName = ontologyName;\r
+               this.className = className;\r
                \r
 //             for (OpenAttrs attrs : schema.getIncludeOrImportOrRedefine()) {\r
 //                     if (attrs instanceof Annotation) {\r
@@ -83,26 +85,13 @@ public class OntologyGenerator extends SchemaConversionBase {
        }\r
        \r
        protected void handle(Schema schema) {\r
-               String ontologyName = schema.getTargetNamespace();\r
-               if (ontologyName == null) {\r
-                       ontologyName = converter.getSchemaFile().getName();\r
-                       \r
-                       int index = ontologyName.lastIndexOf(".");\r
-                       if (index > 0)\r
-                               ontologyName = ontologyName.substring(0, index);\r
-               } \r
-               if (!ontologyName.startsWith("http"))\r
-                       ontologyName = "http://" + ontologyName;\r
                String parts[] = ontologyName.split("/");\r
                String name = parts[parts.length-1];\r
                ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
                String version = schema.getVersion();\r
                if (version == null)\r
                        version = "1.0";\r
-               \r
-               name = name.replaceAll("\\.", "_");\r
-               name = name.replaceAll(" ", "_");\r
-               className = converter.getPluginName() + "." + name;\r
+\r
                \r
                for (String s : converter.getHeader()) {\r
                        writer.println(commentTag + " " + s);   \r
@@ -467,11 +456,8 @@ public class OntologyGenerator extends SchemaConversionBase {
                Element element = elementObj.getElement();\r
                String name = getName(elementObj);//element.getName();\r
                \r
-//             if ("Presentation".equals(name))\r
-//                     System.out.println();\r
-\r
-//             if (parent != null)\r
-//                     name = parent +"_"+name;\r
+               if ("Text".equals(name))\r
+                       System.out.println();\r
                \r
                String type = "XML.Element";\r
                Set<String> types = new LinkedHashSet<String>();\r
index bcff6982821b680ebf230e9c4840c5a30dea5901..600d13fd7dc91e35989375d8f3df4afe86fb63bb 100644 (file)
@@ -2,7 +2,6 @@ package org.simantics.xml.sax;
 \r
 import java.util.ArrayDeque;\r
 import java.util.ArrayList;\r
-import java.util.Base64;\r
 import java.util.Deque;\r
 import java.util.HashMap;\r
 import java.util.HashSet;\r
@@ -21,6 +20,7 @@ import org.simantics.xml.sax.configuration.Configuration;
 import org.simantics.xml.sax.configuration.IDProvider;\r
 import org.simantics.xml.sax.configuration.IDReference;\r
 import org.simantics.xml.sax.configuration.OrderedChild;\r
+import org.simantics.xml.sax.configuration.Rename;\r
 import org.simantics.xml.sax.configuration.UnrecognizedChildElement;\r
 import org.w3._2001.xmlschema.All;\r
 import org.w3._2001.xmlschema.Annotated;\r
@@ -63,38 +63,38 @@ public abstract class SchemaConversionBase {
                Map<String,TypeEntry> l0Types = new HashMap<String, SchemaConversionBase.TypeEntry>();\r
                typeMap.put(CONVERSION_NS, l0Types);\r
                \r
-               schemaTypes.put("string",               new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","",""));\r
-               schemaTypes.put("NMTOKEN",              new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","",""));\r
-               schemaTypes.put("token",                new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","",""));\r
-               schemaTypes.put("ID",                   new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","",true));\r
-               schemaTypes.put("IDREF",                new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","",""));\r
-               schemaTypes.put("date",                 new TypeEntry("XML.Date",                       "org.simantics.xml.sax.base.datatypes.literal.Date.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Date", "","org.simantics.xml.sax.base.datatypes.literal.Date.parseDate(",")"));\r
-               schemaTypes.put("time",                 new TypeEntry("XML.Time",                       "org.simantics.xml.sax.base.datatypes.literal.Time.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Time", "","org.simantics.xml.sax.base.datatypes.literal.Time.parseTime(",")"));\r
-               schemaTypes.put("dateTime",             new TypeEntry("XML.DateTime",           "org.simantics.xml.sax.base.datatypes.literal.DateTime.BINDING", "org.simantics.xml.sax.base.datatypes.literal.DateTime", "","org.simantics.xml.sax.base.datatypes.literal.DateTime.parseDateTime(",")"));\r
-               schemaTypes.put("anyURI",               new TypeEntry("L0.URI",                         "Bindings.STRING", "java.lang.String", "","",""));\r
-               schemaTypes.put("double",               new TypeEntry("L0.Double",                      "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
-               schemaTypes.put("float",                new TypeEntry("L0.Float",                       "Bindings.FLOAT",  "float",  "java.lang.Float.NaN","java.lang.Float.parseFloat(",")"));\r
-               schemaTypes.put("decimal",              new TypeEntry("L0.Double",                      "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")"));\r
-               schemaTypes.put("boolean",              new TypeEntry("L0.Boolean",                     "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")"));\r
-               schemaTypes.put("integer",              new TypeEntry("L0.Integer",             "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer",          "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer",       "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer",       "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer",          "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("unsignedInt",  new TypeEntry("L0.Integer",             "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("int",                  new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("short",                new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")"));\r
-               schemaTypes.put("byte",                 new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
-               schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")"));\r
-               schemaTypes.put("long",                 new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
-               schemaTypes.put("unsignedLong", new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")"));\r
-               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)"));\r
+               schemaTypes.put("string",               new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","","",""));\r
+               schemaTypes.put("NMTOKEN",              new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","","",""));\r
+               schemaTypes.put("token",                new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","","",""));\r
+               schemaTypes.put("ID",                   new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","","","",true));\r
+               schemaTypes.put("IDREF",                new TypeEntry("L0.String",                      "Bindings.STRING", "java.lang.String", "","","","",""));\r
+               schemaTypes.put("date",                 new TypeEntry("XML.Date",                       "org.simantics.xml.sax.base.datatypes.literal.Date.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Date", "","org.simantics.xml.sax.base.datatypes.literal.Date.parseDate(",")","(",").toString()"));\r
+               schemaTypes.put("time",                 new TypeEntry("XML.Time",                       "org.simantics.xml.sax.base.datatypes.literal.Time.BINDING", "org.simantics.xml.sax.base.datatypes.literal.Time", "","org.simantics.xml.sax.base.datatypes.literal.Time.parseTime(",")","(",").toString()"));\r
+               schemaTypes.put("dateTime",             new TypeEntry("XML.DateTime",           "org.simantics.xml.sax.base.datatypes.literal.DateTime.BINDING", "org.simantics.xml.sax.base.datatypes.literal.DateTime", "","org.simantics.xml.sax.base.datatypes.literal.DateTime.parseDateTime(",")","(",").toString()"));\r
+               schemaTypes.put("anyURI",               new TypeEntry("L0.URI",                         "Bindings.STRING", "java.lang.String", "","","","",""));\r
+               schemaTypes.put("double",               new TypeEntry("L0.Double",                      "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")","java.lang.Double.toString(",")"));\r
+               schemaTypes.put("float",                new TypeEntry("L0.Float",                       "Bindings.FLOAT",  "float",  "java.lang.Float.NaN","java.lang.Float.parseFloat(",")","java.lang.Float.toString(",")"));\r
+               schemaTypes.put("decimal",              new TypeEntry("L0.Double",                      "Bindings.DOUBLE", "double", "java.lang.Double.NaN","java.lang.Double.parseDouble(",")","java.lang.Double.toString(",")"));\r
+               schemaTypes.put("boolean",              new TypeEntry("L0.Boolean",                     "Bindings.BOOLEAN", "boolean", "false","java.lang.Boolean.parseBoolean(",")","java.lang.Boolean.toString(",")"));\r
+               schemaTypes.put("integer",              new TypeEntry("L0.Integer",             "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("positiveInteger", new TypeEntry("L0.Integer",          "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("nonPositiveInteger", new TypeEntry("L0.Integer",       "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("nonNegativeInteger", new TypeEntry("L0.Integer",       "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("negativeInteger", new TypeEntry("L0.Integer",          "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("unsignedInt",  new TypeEntry("L0.Integer",             "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("int",                  new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("short",                new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("unsignedShort",new TypeEntry("L0.Integer",                     "Bindings.INTEGER", "int", "0","java.lang.Integer.parseInt(",")","java.lang.Integer.toString(",")"));\r
+               schemaTypes.put("byte",                 new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));\r
+               schemaTypes.put("unsignedByte", new TypeEntry("L0.Byte",                        "Bindings.BYTE", "byte", "0","java.lang.Byte.parseByte(",")","java.lang.Byte.toString(",")"));\r
+               schemaTypes.put("long",                 new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));\r
+               schemaTypes.put("unsignedLong", new TypeEntry("L0.Long",                        "Bindings.LONG", "long", "0","java.lang.Long.parseLong(",")","java.lang.Long.toString(",")"));\r
+               schemaTypes.put("base64Binary", new TypeEntry("L0.ByteArray",           "Bindings.BYTE_ARRAY", "byte[]", "new byte[0]","",".getBytes(org.simantics.databoard.util.binary.UTF8.CHARSET)","new java.lang.String(",", org.simantics.databoard.util.binary.UTF8.CHARSET)"));\r
                \r
                \r
                \r
-               l0Types.put("doubleArray",              new TypeEntry("L0.DoubleArray",  "Bindings.DOUBLE_ARRAY", "double[]", null,null,null));\r
-               l0Types.put("stringArray",              new TypeEntry("L0.StringArray",  "Bindings.STRING_ARRAY", "string[]", null,null,null));\r
+               l0Types.put("doubleArray",              new TypeEntry("L0.DoubleArray",  "Bindings.DOUBLE_ARRAY", "double[]", null,null,null,"java.lang.Double.toString(",")"));\r
+               l0Types.put("stringArray",              new TypeEntry("L0.StringArray",  "Bindings.STRING_ARRAY", "string[]", null,null,null,"",""));\r
        }\r
        \r
        \r
@@ -216,10 +216,12 @@ public abstract class SchemaConversionBase {
                        if (attrs instanceof Element) {\r
                                Element element = (Element)attrs;\r
                                SchemaObject obj = new SchemaObject(element);\r
+                               obj.setRename(getRename(element));\r
                                stack.push(obj);\r
                        } else if (attrs instanceof ComplexType) {\r
                                ComplexType complexType = (ComplexType)attrs;\r
                                SchemaObject obj = new SchemaObject(complexType);\r
+                               obj.setRename(getRename(complexType));\r
                                stack.push(obj);\r
                        } else if (attrs instanceof SimpleType) {\r
                                SimpleType simpleType = (SimpleType)attrs;\r
@@ -287,7 +289,9 @@ public abstract class SchemaConversionBase {
                                JAXBElement<?> element = (JAXBElement<?>)o;\r
                                Object elemValue = element.getValue();\r
                                if (elemValue instanceof Element) {\r
-                                       stack.add(new SchemaObject(parent,(Element)elemValue));\r
+                                       SchemaObject obj = new SchemaObject(parent,(Element)elemValue);\r
+                                       obj.setRename(getRename((Element)elemValue));\r
+                                       stack.add(obj);\r
                                } else if (elemValue instanceof All) {\r
                                        preload(parent,(All)elemValue, stack);\r
                                } else if (elemValue instanceof ExplicitGroup) {\r
@@ -509,7 +513,6 @@ public abstract class SchemaConversionBase {
                                Object elemValue = element.getValue();\r
                                if (elemValue instanceof LocalElement) {\r
                                        LocalElement localElement = (LocalElement)elemValue;\r
-                                       \r
                                        elements.add(new SchemaElement(indicator,localElement, ElementType.ELEMENT));\r
                                } else if (elemValue instanceof All) {\r
                                        alls.add(new SchemaElement(indicator,(All)elemValue, ElementType.ALL));\r
@@ -603,14 +606,14 @@ public abstract class SchemaConversionBase {
        protected void handle(SchemaObject parent, SchemaElement indicator, SchemaElement element) {\r
                Element localElement = element.getElement();\r
                if (localElement.getName() != null) {\r
-                       String refName = localElement.getName();\r
+                       SchemaObject eObj = elements.get(localElement); // FIXME: handleIndicator should be refactored, not this methdof must be overridden in JavaGenerator to handle renaming of Elements properly\r
+                       String refName = eObj.getName();//localElement.getName();\r
                        QName refType = localElement.getType();\r
                        if (refType != null)\r
                                handleIndicator(parent, indicator, element, false, refName, refType);\r
                        else {\r
-                               handleElement(elements.get(localElement));\r
+                               handleElement(eObj);\r
                                handleIndicator(parent, indicator, element, false, refName, localElement);\r
-                               //FIXME:\r
                        }\r
                } else if (localElement.getRef() != null) {\r
                        QName refType = localElement.getRef();\r
@@ -814,11 +817,11 @@ public abstract class SchemaConversionBase {
        public UnrecognizedChildElement getUnknown(ComplexType complexType) {\r
                for (JAXBElement<?> e : configuration.getConversionRule()) {\r
                        if (e.getValue() instanceof UnrecognizedChildElement) {\r
-                               UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue();\r
-                               org.simantics.xml.sax.configuration.ComplexType complexType2 = ref.getComplexType();\r
+                               UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue();\r
+                               org.simantics.xml.sax.configuration.ComplexType complexType2 = rule.getComplexType();\r
                                if (complexType2 != null) {\r
                                        if (complexType.getName().equals(complexType2.getName()))\r
-                                               return ref;\r
+                                               return rule;\r
                                }\r
                        }\r
                }\r
@@ -828,17 +831,65 @@ public abstract class SchemaConversionBase {
        public UnrecognizedChildElement getUnknown(Element element) {\r
                for (JAXBElement<?> e : configuration.getConversionRule()) {\r
                        if (e.getValue() instanceof UnrecognizedChildElement) {\r
-                               UnrecognizedChildElement ref = (UnrecognizedChildElement)e.getValue();\r
-                               org.simantics.xml.sax.configuration.Element element2 = ref.getElement();\r
+                               UnrecognizedChildElement rule = (UnrecognizedChildElement)e.getValue();\r
+                               org.simantics.xml.sax.configuration.Element element2 = rule.getElement();\r
                                if (element2 != null) {\r
                                        if (element.getName().equals(element2.getName()))\r
-                                               return ref;\r
+                                               return rule;\r
                                }\r
                        }\r
                }\r
                return null;\r
        }\r
        \r
+       public Rename getRename(Attribute element) {\r
+               for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+                       if (e.getValue() instanceof Rename) {\r
+                               Rename rule = (Rename)e.getValue();\r
+                               Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+                               if (!(ref instanceof org.simantics.xml.sax.configuration.Attribute))\r
+                                       continue;\r
+                               org.simantics.xml.sax.configuration.Attribute element2 = (org.simantics.xml.sax.configuration.Attribute)ref;\r
+                               if (element2.getName().equals(element.getName())) {\r
+                                       return rule;\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       public Rename getRename(ComplexType element) {\r
+               for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+                       if (e.getValue() instanceof Rename) {\r
+                               Rename rule = (Rename)e.getValue();\r
+                               Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+                               if (!(ref instanceof org.simantics.xml.sax.configuration.ComplexType))\r
+                                       continue;\r
+                               org.simantics.xml.sax.configuration.ComplexType element2 = (org.simantics.xml.sax.configuration.ComplexType)ref;\r
+                               if (element2.getName().equals(element.getName())) {\r
+                                       return rule;\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       public Rename getRename(Element element) {\r
+               for (JAXBElement<?> e : configuration.getConversionRule()) {\r
+                       if (e.getValue() instanceof Rename) {\r
+                               Rename rule = (Rename)e.getValue();\r
+                               Object ref = rule.getElementOrComplexTypeOrAttribute().get(0);\r
+                               if (!(ref instanceof org.simantics.xml.sax.configuration.Element))\r
+                                       continue;\r
+                               org.simantics.xml.sax.configuration.Element element2 = (org.simantics.xml.sax.configuration.Element)ref;\r
+                               if (element2.getName().equals(element.getName())) {\r
+                                       return rule;\r
+                               }\r
+                       }\r
+               }\r
+               return null;\r
+       }\r
+        \r
        \r
        public boolean useOriginalList(SchemaObject parent, SchemaElement indicator, SchemaElement element,  boolean reference, String ref, QName refType) {\r
                if (parent.getName() == null)\r
@@ -942,7 +993,9 @@ public abstract class SchemaConversionBase {
                boolean id;\r
                String getterPrefix;\r
                String getterPostfix;\r
-               public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix) {\r
+               String stringPrefix;\r
+               String stringPostfix;\r
+               public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix) {\r
                        super();\r
                        this.l0Type = l0Type;\r
                        this.binding = binding;\r
@@ -951,10 +1004,11 @@ public abstract class SchemaConversionBase {
                        this.id = false;\r
                        this.getterPrefix = getterPrefix;\r
                        this.getterPostfix = getterPostfix;\r
-                       \r
+                       this.stringPrefix = stringPrefix;\r
+                       this.stringPostfix = stringPostfix;\r
                }\r
                \r
-               public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, boolean id) {\r
+               public TypeEntry(String l0Type, String binding, String javaType, String defaultValue, String getterPrefix, String getterPostfix, String stringPrefix, String stringPostfix, boolean id) {\r
                        super();\r
                        this.l0Type = l0Type;\r
                        this.binding = binding;\r
@@ -963,6 +1017,8 @@ public abstract class SchemaConversionBase {
                        this.id = id;\r
                        this.getterPrefix = getterPrefix;\r
                        this.getterPostfix = getterPostfix;\r
+                       this.stringPrefix = stringPrefix;\r
+                       this.stringPostfix = stringPostfix;\r
                }\r
                \r
                public String getValueGetterMethod(String name) {\r
@@ -976,6 +1032,14 @@ public abstract class SchemaConversionBase {
                        return getValueGetter("value");\r
                }\r
                \r
+               public String getToString(String name) {\r
+                       return stringPrefix +"("+javaType+")"+name+stringPostfix;\r
+               }\r
+               \r
+               public String getElementToString(String name) {\r
+                       return stringPrefix + name+stringPostfix;\r
+               }\r
+               \r
        }\r
 \r
 }\r
index 523788c8e33971819ed2c709cc79c48c642edb66..32ae1672baa41dc4ff00b588556c3f03ecb6f9a5 100644 (file)
@@ -33,6 +33,12 @@ public class SchemaConverter {
        \r
        private String[] header;\r
        \r
+       boolean createPGraph = true;\r
+       boolean createImporter = true;\r
+       boolean createExporter = true;\r
+       \r
+       \r
+       \r
 \r
        public void convertSchema(File schemaFile, File conversionFile, File outputPlugin) throws JAXBException, IOException {\r
                pluginName = outputPlugin.getName();\r
@@ -61,6 +67,18 @@ public class SchemaConverter {
                \r
        }\r
        \r
+       public void setCreateExporter(boolean createExporter) {\r
+               this.createExporter = createExporter;\r
+       }\r
+       \r
+       public void setCreateImporter(boolean createImporter) {\r
+               this.createImporter = createImporter;\r
+       }\r
+       \r
+       public void setCreatePGraph(boolean createPGraph) {\r
+               this.createPGraph = createPGraph;\r
+       }\r
+       \r
        private void convert() throws JAXBException, IOException {\r
                JAXBContext jc = JAXBContext.newInstance("org.w3._2001.xmlschema");\r
                Unmarshaller u = jc.createUnmarshaller();\r
@@ -84,10 +102,37 @@ public class SchemaConverter {
                header[3] = "Date " + new Date().toString();\r
                \r
                \r
+               String ontologyName = schema.getTargetNamespace();\r
+               if (ontologyName == null) {\r
+                       ontologyName = getSchemaFile().getName();\r
+                       \r
+                       int index = ontologyName.lastIndexOf(".");\r
+                       if (index > 0)\r
+                               ontologyName = ontologyName.substring(0, index);\r
+               } \r
+               if (!ontologyName.startsWith("http"))\r
+                       ontologyName = "http://" + ontologyName;\r
+               String parts[] = ontologyName.split("/");\r
+               String name = parts[parts.length-1];\r
+               //String ontRoot = name.substring(0, Math.min(3, name.length())).toUpperCase();\r
+\r
+               \r
+               name = name.replaceAll("\\.", "_");\r
+               name = name.replaceAll(" ", "_");\r
+               String className = getPluginName() + "." + name;\r
+               \r
+               if (createPGraph) {\r
                OntologyGenerator ontologyGenerator = new OntologyGenerator(configuration);\r
-               ontologyGenerator.createOntology(schema, this);\r
+               ontologyGenerator.createOntology(schema, ontologyName, className, this);\r
+               }\r
+               if (createImporter) {\r
                ImporterGenerator importerGenerator = new ImporterGenerator(configuration);\r
-               importerGenerator.createParser(schema, ontologyGenerator.getClassName(), this);\r
+               importerGenerator.createParser(schema, className, this);\r
+               }\r
+               if (createExporter) {\r
+               ExporterGenerator exporterGenerator = new ExporterGenerator(configuration);\r
+               exporterGenerator.createParser(schema, className, this);\r
+               }\r
        }\r
        \r
        public File getOntologyFile() {\r
index 3b45c7e4d3e5ed54d6df7609a1c344792ee602c4..c081b8188443a6d49adf4d38fac17ccf33f41187 100644 (file)
@@ -1,5 +1,6 @@
 package org.simantics.xml.sax;\r
 \r
+import org.simantics.xml.sax.configuration.Rename;\r
 import org.w3._2001.xmlschema.AttributeGroup;\r
 import org.w3._2001.xmlschema.AttributeGroupRef;\r
 import org.w3._2001.xmlschema.ComplexType;\r
@@ -14,11 +15,16 @@ public class SchemaObject {
        private SchemaObject parent;\r
        private ObjectType type;\r
        private OpenAttrs obj;\r
+       private Rename rename;\r
        \r
        public SchemaObject(Element element) {\r
                this(null,element);\r
        }\r
        \r
+       public void setRename(Rename rename) {\r
+               this.rename = rename;\r
+       }\r
+       \r
        public SchemaObject(ComplexType complexType) {\r
                this(null, complexType);\r
        }\r
@@ -93,8 +99,12 @@ public class SchemaObject {
                        else\r
                                return ((AttributeGroupRef)obj).getRef().getLocalPart();\r
                case COMPLEX_TYPE:\r
+                       if (rename != null)\r
+                               return rename.getName();\r
                        return ((ComplexType)obj).getName();\r
                case ELEMENT:\r
+                       if (rename != null)\r
+                               return rename.getName();\r
                        return ((Element)obj).getName();\r
                case SIMPLE_TYPE:\r
                        return ((SimpleType)obj).getName();\r
index 91b98486f96d099032c5040832c1e514eb35020b..e161573e393f47f2421fcec0b98f950d2144f420 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index b6beb40de9e4a170085d43989b578804781b5a89..2e799dc7d6a85f487b8ca8704d713e5e4c69b26b 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index cd4d3287e81dfee77177d7e266915dae557f33b7..911303d986f43a78b02c51c61b9a62715f9136d9 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index 1ab2be74aee172ac9214fcbb6ec242138c694fda..29be8b629f15c9f1d982d95585f9bd4b3971840f 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
@@ -64,11 +64,12 @@ public class Configuration {
      * <p>\r
      * Objects of the following type(s) are allowed in the list\r
      * {@link JAXBElement }{@code <}{@link OrderedChild }{@code >}\r
-     * {@link JAXBElement }{@code <}{@link IDReference }{@code >}\r
-     * {@link JAXBElement }{@code <}{@link AttributeComposition }{@code >}\r
-     * {@link JAXBElement }{@code <}{@link UnrecognizedChildElement }{@code >}\r
      * {@link JAXBElement }{@code <}{@link ConversionRule }{@code >}\r
+     * {@link JAXBElement }{@code <}{@link AttributeComposition }{@code >}\r
+     * {@link JAXBElement }{@code <}{@link Rename }{@code >}\r
      * {@link JAXBElement }{@code <}{@link IDProvider }{@code >}\r
+     * {@link JAXBElement }{@code <}{@link IDReference }{@code >}\r
+     * {@link JAXBElement }{@code <}{@link UnrecognizedChildElement }{@code >}\r
      * \r
      * \r
      */\r
index 068745f4b2bf0b2188ceb0752bd4d337974222bb..1e7e021426883bf9392919374a974133b8926071 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
@@ -37,7 +37,8 @@ import javax.xml.bind.annotation.XmlType;
     UnrecognizedChildElement.class,\r
     OrderedChild.class,\r
     AttributeComposition.class,\r
-    IDReference.class\r
+    IDReference.class,\r
+    Rename.class\r
 })\r
 public class ConversionRule {\r
 \r
index 00bf583b124923b60fd6428527b5fca120aab115..5b47d79d56b51c78718cd9d427d0338186a3ec33 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index 4031f24ba7fb254ab4292fdb39cf9f952c6d964a..9f3ea82d813900b1953fea49e14225283e721e37 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index e48ca71f62a7e3de2ad29ba8d525ca6d856c3bbc..8640b1c2800f447b3d4433fac8ecd45e525d0d23 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index 2dfe1e4d39fceb8ce6ac22f1abfe509c060e87f1..d005c289ecb149550f8a8200f36ffd96f6712b9e 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
@@ -32,6 +32,7 @@ import javax.xml.namespace.QName;
 public class ObjectFactory {\r
 \r
     private final static QName _ComplexType_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "ComplexType");\r
+    private final static QName _Rename_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "Rename");\r
     private final static QName _IDProvider_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "IDProvider");\r
     private final static QName _ConversionRule_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "ConversionRule");\r
     private final static QName _Attribute_QNAME = new QName("http://www.simantics.org/xml/sax/configuration/", "Attribute");\r
@@ -129,6 +130,14 @@ public class ObjectFactory {
         return new ComplexType();\r
     }\r
 \r
+    /**\r
+     * Create an instance of {@link Rename }\r
+     * \r
+     */\r
+    public Rename createRename() {\r
+        return new Rename();\r
+    }\r
+\r
     /**\r
      * Create an instance of {@link JAXBElement }{@code <}{@link ComplexType }{@code >}}\r
      * \r
@@ -138,6 +147,15 @@ public class ObjectFactory {
         return new JAXBElement<ComplexType>(_ComplexType_QNAME, ComplexType.class, null, value);\r
     }\r
 \r
+    /**\r
+     * Create an instance of {@link JAXBElement }{@code <}{@link Rename }{@code >}}\r
+     * \r
+     */\r
+    @XmlElementDecl(namespace = "http://www.simantics.org/xml/sax/configuration/", name = "Rename", substitutionHeadNamespace = "http://www.simantics.org/xml/sax/configuration/", substitutionHeadName = "ConversionRule")\r
+    public JAXBElement<Rename> createRename(Rename value) {\r
+        return new JAXBElement<Rename>(_Rename_QNAME, Rename.class, null, value);\r
+    }\r
+\r
     /**\r
      * Create an instance of {@link JAXBElement }{@code <}{@link IDProvider }{@code >}}\r
      * \r
index fb9f4988c0e1fbee4dab867b820859726845ef83..726ad9c429c518a45bf0bd18f54a57a98266674a 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
diff --git a/org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Rename.java b/org.simantics.xml.sax/src/org/simantics/xml/sax/configuration/Rename.java
new file mode 100644 (file)
index 0000000..42153d2
--- /dev/null
@@ -0,0 +1,117 @@
+//\r
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
+// Any modifications to this file will be lost upon recompilation of the source schema. \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
+//\r
+\r
+\r
+package org.simantics.xml.sax.configuration;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import javax.xml.bind.annotation.XmlAccessType;\r
+import javax.xml.bind.annotation.XmlAccessorType;\r
+import javax.xml.bind.annotation.XmlAttribute;\r
+import javax.xml.bind.annotation.XmlElement;\r
+import javax.xml.bind.annotation.XmlElements;\r
+import javax.xml.bind.annotation.XmlType;\r
+\r
+\r
+/**\r
+ * <p>Java class for anonymous complex type.\r
+ * \r
+ * <p>The following schema fragment specifies the expected content contained within this class.\r
+ * \r
+ * <pre>\r
+ * &lt;complexType>\r
+ *   &lt;complexContent>\r
+ *     &lt;extension base="{http://www.simantics.org/xml/sax/configuration/}ConversionRule">\r
+ *       &lt;sequence maxOccurs="unbounded">\r
+ *         &lt;choice>\r
+ *           &lt;element ref="{http://www.simantics.org/xml/sax/configuration/}Element"/>\r
+ *           &lt;element ref="{http://www.simantics.org/xml/sax/configuration/}ComplexType"/>\r
+ *           &lt;element ref="{http://www.simantics.org/xml/sax/configuration/}Attribute"/>\r
+ *         &lt;/choice>\r
+ *       &lt;/sequence>\r
+ *       &lt;attribute name="Name" type="{http://www.w3.org/2001/XMLSchema}string" />\r
+ *     &lt;/extension>\r
+ *   &lt;/complexContent>\r
+ * &lt;/complexType>\r
+ * </pre>\r
+ * \r
+ * \r
+ */\r
+@XmlAccessorType(XmlAccessType.FIELD)\r
+@XmlType(name = "", propOrder = {\r
+    "elementOrComplexTypeOrAttribute"\r
+})\r
+public class Rename\r
+    extends ConversionRule\r
+{\r
+\r
+    @XmlElements({\r
+        @XmlElement(name = "Element", type = Element.class),\r
+        @XmlElement(name = "ComplexType", type = ComplexType.class),\r
+        @XmlElement(name = "Attribute", type = Attribute.class)\r
+    })\r
+    protected List<Object> elementOrComplexTypeOrAttribute;\r
+    @XmlAttribute(name = "Name")\r
+    protected String name;\r
+\r
+    /**\r
+     * Gets the value of the elementOrComplexTypeOrAttribute property.\r
+     * \r
+     * <p>\r
+     * This accessor method returns a reference to the live list,\r
+     * not a snapshot. Therefore any modification you make to the\r
+     * returned list will be present inside the JAXB object.\r
+     * This is why there is not a <CODE>set</CODE> method for the elementOrComplexTypeOrAttribute property.\r
+     * \r
+     * <p>\r
+     * For example, to add a new item, do as follows:\r
+     * <pre>\r
+     *    getElementOrComplexTypeOrAttribute().add(newItem);\r
+     * </pre>\r
+     * \r
+     * \r
+     * <p>\r
+     * Objects of the following type(s) are allowed in the list\r
+     * {@link Element }\r
+     * {@link ComplexType }\r
+     * {@link Attribute }\r
+     * \r
+     * \r
+     */\r
+    public List<Object> getElementOrComplexTypeOrAttribute() {\r
+        if (elementOrComplexTypeOrAttribute == null) {\r
+            elementOrComplexTypeOrAttribute = new ArrayList<Object>();\r
+        }\r
+        return this.elementOrComplexTypeOrAttribute;\r
+    }\r
+\r
+    /**\r
+     * Gets the value of the name property.\r
+     * \r
+     * @return\r
+     *     possible object is\r
+     *     {@link String }\r
+     *     \r
+     */\r
+    public String getName() {\r
+        return name;\r
+    }\r
+\r
+    /**\r
+     * Sets the value of the name property.\r
+     * \r
+     * @param value\r
+     *     allowed object is\r
+     *     {@link String }\r
+     *     \r
+     */\r
+    public void setName(String value) {\r
+        this.name = value;\r
+    }\r
+\r
+}\r
index 4874867897e0bbb5bad8bcc30bdba88ecbfb8fa2..d431344a65cca0258de4a895267547c73015a285 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 \r
index dd605beb68e6acc5ef39bdbb294af062200afb98..deb96fc920b2d050de54cc200a6a8250985e6cae 100644 (file)
@@ -2,7 +2,7 @@
 // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.8-b130911.1802 \r
 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> \r
 // Any modifications to this file will be lost upon recompilation of the source schema. \r
-// Generated on: 2015.11.25 at 04:57:27 PM EET \r
+// Generated on: 2017.01.24 at 12:54:40 PM EET \r
 //\r
 \r
 @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.simantics.org/xml/sax/configuration/", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)\r