X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.xml.sax.base%2Fsrc%2Forg%2Fsimantics%2Fxml%2Fsax%2Fbase%2FAbstractImporter.java;h=f47dd9395c90e2338236fb0508ac9572a856327c;hb=c8ead11dcd815dc26885b2b8e866e4ac4e563ae5;hp=af5c2c3da0fc43c1da6ea4f42e53129aa0fd43c3;hpb=ada38ab0a1a98dcb413bef3273064da36ce2d273;p=simantics%2Finterop.git 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 af5c2c3..f47dd93 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 @@ -2,8 +2,6 @@ package org.simantics.xml.sax.base; import java.io.File; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.simantics.db.Resource; import org.simantics.db.Session; import org.simantics.db.WriteGraph; @@ -21,6 +19,7 @@ public abstract class AbstractImporter { private Session session; private File file; private ILogger logger; + private XMLParser parser; private static final boolean USE_DELAYED = false; @@ -28,6 +27,12 @@ public abstract class AbstractImporter { this.session = session; this.file = file; } + + public AbstractImporter(Session session, File file, XMLParser parser) { + this.session = session; + this.file = file; + this.parser = parser; + } public Resource doImport() throws DatabaseException { return doImport(MessageService.getDefault()); } @@ -49,7 +54,8 @@ public abstract class AbstractImporter { return file; } - public abstract void configure(XMLParser parser); + public void configure(XMLParser parser){}; + private class ImportRequest extends WriteRequest { private Resource result; @@ -59,6 +65,8 @@ public abstract class AbstractImporter { @Override public void perform(WriteGraph graph) throws DatabaseException { + Layer0Utils.addCommentMetadata(graph, "Import file " + file.getName()); + graph.markUndoPoint(); result = doImport(graph); } @@ -86,8 +94,15 @@ public abstract class AbstractImporter { private Resource doImport(WriteGraph graph) throws DatabaseException { Layer0Utils.setDependenciesIndexingDisabled(graph, true); try { - XMLParser parser = new XMLParser(graph); - configure(parser); + + if (parser == null) { + parser = new XMLParser(); + parser.setGraph(graph); + configure(parser); + } else { + parser.setGraph(graph); + } + parser.parse(file, logger); System.out.println(file.getAbsolutePath() + " imported"); Resource root = parser.getRoot();