]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Make it possible to customise element parsers before imports 85/4885/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 4 Feb 2022 15:09:50 +0000 (17:09 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Fri, 4 Feb 2022 15:09:50 +0000 (17:09 +0200)
gitlab #32

Change-Id: Ibb2a55fcb972c3b7baeb9084eec3935dde622ecb

org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParserWrapper.java [new file with mode: 0644]
org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java

index 34936318f3cec738e3fe8b58a7efac3bd3de8065..9a1765083b3dc13b768d28ef86c60c0be19d43f3 100644 (file)
@@ -120,4 +120,13 @@ public abstract class AbstractImporter {
                        throw new DatabaseException(e);\r
                } \r
        }\r
+       \r
+       public XMLElementParser getParser(String elementId) {\r
+               return parser.getParser(elementId);\r
+       }\r
+\r
+       public void setParser(String elementId, XMLElementParser p) {\r
+               parser.setParser(elementId, p);\r
+       }\r
+\r
 }\r
diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParserWrapper.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParserWrapper.java
new file mode 100644 (file)
index 0000000..ce9a6f0
--- /dev/null
@@ -0,0 +1,59 @@
+package org.simantics.xml.sax.base;
+
+import java.util.Deque;
+
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.exception.DatabaseException;
+
+public class XMLElementParserWrapper implements XMLElementParser {
+
+       private XMLElementParser base;
+       
+       public XMLElementParserWrapper(XMLElementParser base) {
+               this.base = base;
+       }
+       
+       @Override
+       public String getElementId() {
+               return base.getElementId();
+       }
+
+       @Override
+       public int idPriority() {
+               return base.idPriority();
+       }
+
+       @Override
+       public Resource create(WriteGraph graph, ParserElement element) throws DatabaseException {
+               return base.create(graph, element);
+       }
+
+       @Override
+       public void configure(WriteGraph graph, Deque<ParserElement> parents, ParserElement element)
+                       throws DatabaseException {
+               base.configure(graph, parents, element);
+       }
+
+       @Override
+       public void configure(WriteGraph graph, ParserElement element, String string) throws DatabaseException {
+               base.configure(graph, element, string);
+       }
+
+       @Override
+       public boolean connectChild(WriteGraph graph, ParserElement element, ParserElement child) throws DatabaseException {
+               return base.connectChild(graph, element, child);
+       }
+
+       @Override
+       public boolean connectParent(WriteGraph graph, ParserElement parent, ParserElement element)
+                       throws DatabaseException {
+               return base.connectParent(graph, parent, element);
+       }
+
+       @Override
+       public String getID() {
+               return base.getID();
+       }
+
+}
index 44530c00c968095ac0f0701e63ef469f085e4d73..efea418576f2fb8b46b904d37b4058d091f1db86 100644 (file)
@@ -331,5 +331,14 @@ public class XMLParser extends DefaultHandler implements Serializable {
                done();
        }
        
+       public XMLElementParser getParser(String elementId) {
+               return parsers.get(elementId);
+       }
+
+       public void setParser(String elementId, XMLElementParser p) {
+               parsers.put(elementId, p);
+       }
+
+       
        
 }
\ No newline at end of file