1 package org.simantics.export.core.manager;
4 import java.io.IOException;
5 import java.util.TreeMap;
7 import org.simantics.databoard.binding.Binding;
8 import org.simantics.databoard.binding.mutable.Variant;
9 import org.simantics.databoard.container.DataContainer;
10 import org.simantics.databoard.container.DataContainers;
11 import org.simantics.db.RequestProcessor;
12 import org.simantics.export.core.error.ExportException;
13 import org.simantics.graph.db.TransferableGraphSource;
14 import org.simantics.graph.db.TransferableGraphs;
16 public class TransferableGraphWriter {
18 public final File file;
19 public final String format;
20 public final int version;
22 public TransferableGraphWriter(File file, String format, int version) {
25 this.version = version;
29 * Write TG to the file that is associated with this writer.
33 * @throws ExportException
35 public void writeFile(Binding tgBinding, Object tg) throws ExportException {
37 Variant variant = new Variant(tgBinding, tg);
38 DataContainer dataContainer = new DataContainer(format, version, variant);
39 DataContainers.writeFile(file, dataContainer);
40 } catch (IOException e) {
41 throw new ExportException( "I/O Error occured: "+e.getMessage() );
46 * Write from TG Source to the file that is associated with this writer.
48 * @param session request processor to be used for reading the source
49 * @param source TG source
50 * @throws ExportException
52 public void writeFile(RequestProcessor session, TransferableGraphSource source) throws ExportException
54 writeFile(session, source, new TreeMap<String, Variant>());
58 * Write from TG Source to the file that is associated with this writer.
60 * @param session request processor to be used for reading the source
61 * @param source TG source
62 * @throws ExportException
64 public void writeFile(RequestProcessor session, TransferableGraphSource source, TreeMap<String,Variant> metadata) throws ExportException
67 TransferableGraphs.writeTransferableGraph(
74 } catch (Exception e) {
75 throw new ExportException(e);