]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.export.core/src/org/simantics/export/core/manager/TransferableGraphWriter.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.export.core / src / org / simantics / export / core / manager / TransferableGraphWriter.java
1 package org.simantics.export.core.manager;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.TreeMap;
6
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;
15
16 public class TransferableGraphWriter {
17
18         public final File file;         
19         public final String format;
20         public final int version;
21         
22         public TransferableGraphWriter(File file, String format, int version) {
23                 this.file = file;
24                 this.format = format;
25                 this.version = version;
26         }
27         
28         /**
29          * Write TG to the file that is associated with this writer.
30          * 
31          * @param tgBinding
32          * @param tg
33          * @throws ExportException
34          */
35         public void writeFile(Binding tgBinding, Object tg) throws ExportException {
36         try {
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() );
42                 }                               
43         }
44         
45         /**
46          * Write from TG Source to the file that is associated with this writer.
47          *  
48          * @param session request processor to be used for reading the source
49          * @param source TG source
50          * @throws ExportException
51          */
52         public void writeFile(RequestProcessor session, TransferableGraphSource source) throws ExportException
53         {
54                 writeFile(session, source, new TreeMap<String, Variant>());
55         }
56
57         /**
58          * Write from TG Source to the file that is associated with this writer.
59          *  
60          * @param session request processor to be used for reading the source
61          * @param source TG source
62          * @throws ExportException
63          */
64         public void writeFile(RequestProcessor session, TransferableGraphSource source, TreeMap<String,Variant> metadata) throws ExportException
65         {
66                 try {
67                         TransferableGraphs.writeTransferableGraph(
68                                         session, 
69                                         format, 
70                                         version, 
71                                         metadata, 
72                                         source, 
73                                         file);
74                 } catch (Exception e) {
75                         throw new ExportException(e);
76                 }
77         }
78
79 }