From: Marko Luukkainen Date: Fri, 4 Feb 2022 15:09:50 +0000 (+0200) Subject: Make it possible to customise element parsers before imports X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=268cc26d9b8c79c4a30b746bf22e1bde9e179e00;p=simantics%2Finterop.git Make it possible to customise element parsers before imports gitlab #32 Change-Id: Ibb2a55fcb972c3b7baeb9084eec3935dde622ecb --- diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java index 3493631..9a17650 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/AbstractImporter.java @@ -120,4 +120,13 @@ public abstract class AbstractImporter { throw new DatabaseException(e); } } + + public XMLElementParser getParser(String elementId) { + return parser.getParser(elementId); + } + + public void setParser(String elementId, XMLElementParser p) { + parser.setParser(elementId, p); + } + } 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 index 0000000..ce9a6f0 --- /dev/null +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLElementParserWrapper.java @@ -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 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(); + } + +} diff --git a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java index 44530c0..efea418 100644 --- a/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java +++ b/org.simantics.xml.sax.base/src/org/simantics/xml/sax/base/XMLParser.java @@ -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