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