]> gerrit.simantics Code Review - simantics/platform.git/blob
f316cbfc7cb49aa837a27ec1cef03ed497607da2
[simantics/platform.git] /
1 package org.simantics.structural.synchronization.utils;
2
3 import java.util.Collection;
4
5 import org.simantics.structural.synchronization.protocol.ChildInfo;
6 import org.simantics.structural.synchronization.protocol.Connection;
7 import org.simantics.structural.synchronization.protocol.SerializedVariable;
8 import org.simantics.structural.synchronization.protocol.SynchronizationEventHandler;
9 import org.simantics.structural.synchronization.protocol.SynchronizationException;
10
11 public class DiagnosticSynchronizationEventHandler implements SynchronizationEventHandler {
12
13     int indentation;
14
15     @Override
16     public void beginSynchronization() {
17     }
18
19     @Override
20     public void endSynchronization() {
21     }
22
23     @Override
24     public void beginComponent(String name, String typeId,
25             Collection<SerializedVariable> properties,
26             Collection<Connection> connections, Collection<ChildInfo> children)
27                     throws SynchronizationException {
28         for(int i=0;i<indentation;++i)
29             System.out.print("  ");
30         System.out.print(name);
31         if(typeId != null)
32             System.out.print(" :: " + typeId);
33         System.out.println();
34         for(SerializedVariable var : properties) {
35             for(int i=0;i<=indentation;++i)
36                 System.out.print("  ");
37             System.out.println(SerializedVariable.print(var, indentation*2+2));
38         }
39         for(Connection connection : connections) {
40             for(int i=0;i<=indentation;++i)
41                 System.out.print("  ");
42             System.out.println(connection);
43         }
44         if(!children.isEmpty()) {
45             for(int i=0;i<=indentation;++i)
46                 System.out.print("  ");
47             System.out.print("Children ");
48             if(children != null)
49                 System.out.println(children);
50         }
51         ++indentation;
52     }
53
54     @Override
55     public void endComponent() {
56         --indentation;
57     }
58
59     @Override
60     public void beginType(String id, Collection<SerializedVariable> properties) {
61         System.out.println("--- Type " + id + " --------------------------------");
62         for(SerializedVariable var : properties)
63             System.out.println(SerializedVariable.print(var, 2));
64     }
65
66     @Override
67     public void endType() {
68         System.out.println("----------------------------------------------------");
69     }
70
71     @Override
72     public void reportProblem(String description) {
73         System.err.println(description);
74     }
75
76     @Override
77     public void reportProblem(String description, Exception e) {
78         System.err.println(description);
79         e.printStackTrace();
80     }
81
82 }