--- /dev/null
+package org.simantics.export.core.manager;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.TreeMap;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.databoard.binding.mutable.Variant;\r
+import org.simantics.databoard.container.DataContainer;\r
+import org.simantics.databoard.container.DataContainers;\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.export.core.error.ExportException;\r
+import org.simantics.graph.db.TransferableGraphSource;\r
+import org.simantics.graph.db.TransferableGraphs;\r
+\r
+public class TransferableGraphWriter {\r
+\r
+ public final File file; \r
+ public final String format;\r
+ public final int version;\r
+ \r
+ public TransferableGraphWriter(File file, String format, int version) {\r
+ this.file = file;\r
+ this.format = format;\r
+ this.version = version;\r
+ }\r
+ \r
+ /**\r
+ * Write TG to the file that is associated with this writer.\r
+ * \r
+ * @param tgBinding\r
+ * @param tg\r
+ * @throws ExportException\r
+ */\r
+ public void writeFile(Binding tgBinding, Object tg) throws ExportException {\r
+ try {\r
+ Variant variant = new Variant(tgBinding, tg);\r
+ DataContainer dataContainer = new DataContainer(format, version, variant);\r
+ DataContainers.writeFile(file, dataContainer);\r
+ } catch (IOException e) {\r
+ throw new ExportException( "I/O Error occured: "+e.getMessage() );\r
+ } \r
+ }\r
+ \r
+ /**\r
+ * Write from TG Source to the file that is associated with this writer.\r
+ * \r
+ * @param session request processor to be used for reading the source\r
+ * @param source TG source\r
+ * @throws ExportException\r
+ */\r
+ public void writeFile(RequestProcessor session, TransferableGraphSource source) throws ExportException\r
+ {\r
+ writeFile(session, source, new TreeMap<String, Variant>());\r
+ }\r
+\r
+ /**\r
+ * Write from TG Source to the file that is associated with this writer.\r
+ * \r
+ * @param session request processor to be used for reading the source\r
+ * @param source TG source\r
+ * @throws ExportException\r
+ */\r
+ public void writeFile(RequestProcessor session, TransferableGraphSource source, TreeMap<String,Variant> metadata) throws ExportException\r
+ {\r
+ try {\r
+ TransferableGraphs.writeTransferableGraph(\r
+ session, \r
+ format, \r
+ version, \r
+ metadata, \r
+ source, \r
+ file);\r
+ } catch (Exception e) {\r
+ throw new ExportException(e);\r
+ }\r
+ }\r
+\r
+}\r