]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/tests/org/simantics/graph/tests/conversion/TG0_TG1.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.graph / tests / org / simantics / graph / tests / conversion / TG0_TG1.java
1 package org.simantics.graph.tests.conversion;
2
3 import java.io.File;
4
5 import org.simantics.databoard.Files;
6 import org.simantics.databoard.binding.mutable.Variant;
7 import org.simantics.databoard.container.DataContainer;
8 import org.simantics.databoard.container.DataContainers;
9 import org.simantics.graph.representation.TransferableGraph1;
10
11 public class TG0_TG1 {
12
13         public static void main(String[] args) throws Exception {
14                 if(args.length != 3) {
15                         System.err.println(TG0_TG1.class.getName() + " formatName input.tg output.tg");
16                         return;
17                 }
18                 String formatName = args[0];
19                 File input = new File(args[1]);
20                 File output = new File(args[2]);
21                 
22                 if(!input.exists()) {
23                         System.err.println(input + " does not exist.");
24                         return;
25                 }
26                 if(output.exists())
27                         output.delete();
28                 
29                 try {
30                         DataContainer header = DataContainers.readHeader(input);
31                         if (formatName.equals(header.format)) {
32                                 System.err.println(input + " already has a data container with the required format, version is " + header.version);
33                                 return;
34                         } else {
35                                 System.err.println(input + " already has a data container with another format '" + header.format + ", version is " + header.version);
36                                 return;
37                         }
38                 } catch (Throwable e) {
39                         // There is no DataContainer in the input file yet.
40                         // Continue conversion.
41                 }
42                 
43                 TransferableGraph0 tg0 = (TransferableGraph0)Files.readFile(input, TransferableGraph0.BINDING);
44                 TransferableGraph1 tg1 = new TransferableGraph1(
45                                 tg0.resourceCount,
46                                 tg0.identities,
47                                 tg0.statements,
48                                 tg0.values,
49                                 tg0.extensions
50                                 );
51                 DataContainers.writeFile(output, 
52                                 new DataContainer(formatName, 1, new Variant(TransferableGraph1.BINDING, tg1)));
53         }
54         
55 }