]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.graph/src/org/simantics/graph/representation/TransferableGraph1.java
Fixing PrettyPrintTG to not concatenate strings in logging
[simantics/platform.git] / bundles / org.simantics.graph / src / org / simantics / graph / representation / TransferableGraph1.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.graph.representation;
13
14 import java.util.TreeMap;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.binding.Binding;
18 import org.simantics.databoard.binding.mutable.Variant;
19 import org.simantics.databoard.serialization.Serializer;
20
21
22 /**
23  * Transferable graph datatype. 
24  * See <a href="http://dev.simantics.org/index.php/Transferable_Graph">specification</a>. 
25  * @author Hannu Niemist&ouml;
26  */
27 public class TransferableGraph1 {
28         public static Binding BINDING = Bindings.getBindingUnchecked(TransferableGraph1.class);
29         public static Serializer SERIALIZER = Bindings.getSerializerUnchecked(BINDING);
30         
31         public int resourceCount;
32         public TreeMap<String, Variant> extensions;
33         public Identity[] identities;   
34         public int[] statements;
35         public Value[] values;  
36         
37         public TransferableGraph1() {     
38     }
39         
40         public TransferableGraph1(int resourceCount, Identity[] identities,
41                         int[] statements, Value[] values) {
42                 this(resourceCount, identities, statements, values,
43                                 new TreeMap<String, Variant>());
44         }
45         
46         public TransferableGraph1(int resourceCount, Identity[] identities,
47                         int[] statements, Value[] values, TreeMap<String, Variant> extensions) {
48                 this.resourceCount = resourceCount;
49                 this.identities = identities;
50                 this.statements = statements;
51                 this.values = values;
52                 this.extensions = extensions;
53         }
54
55         public void print() {
56                 System.out.println("Identities");
57                 for(Identity id : identities) {
58                         System.out.print("    " + id.resource + " = ");
59                         if(id.definition instanceof Root) {
60                                 Root def = (Root)id.definition;
61                                 System.out.println("ROOT(" + def.name + ")");
62                         }
63                         else if(id.definition instanceof External) {
64                                 External def = (External)id.definition;
65                                 System.out.println("EXTERNAL(" + def.parent + ", " + def.name + ")");
66                         }
67                         else if(id.definition instanceof Internal) {
68                                 Internal def = (Internal)id.definition;
69                                 System.out.println("INTERNAL(" + def.parent + ", " + def.name + ")");
70                         }
71                 }
72                 System.out.println("Statements:");
73                 for(int i=0;i<statements.length;i+=4)
74                         System.out.println("    " + 
75                                         statements[i] + " " +
76                                         statements[i+1] + " " +
77                                         statements[i+2] + " " +
78                                         statements[i+3]
79                                         );
80         }
81 }