]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural.synchronization/src/org/simantics/structural/synchronization/utils/DiagnosticSynchronizationEventHandler.java
Replace System.err and System.out with SLF4J Logging
[simantics/platform.git] / bundles / org.simantics.structural.synchronization / src / org / simantics / structural / synchronization / utils / DiagnosticSynchronizationEventHandler.java
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 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 public class DiagnosticSynchronizationEventHandler implements SynchronizationEventHandler {
14
15     private static final Logger LOGGER = LoggerFactory.getLogger(DiagnosticSynchronizationEventHandler.class);
16     int indentation;
17
18     @Override
19     public void beginSynchronization() {
20     }
21
22     @Override
23     public void endSynchronization() {
24     }
25
26     @Override
27     public void beginComponent(String name, String typeId,
28             Collection<SerializedVariable> properties,
29             Collection<Connection> connections, Collection<ChildInfo> children)
30                     throws SynchronizationException {
31         StringBuilder indent = new StringBuilder();
32         for(int i=0;i<indentation;++i)
33             indent.append("  ");
34         indent.append(name);
35         if(typeId != null)
36             indent.append(" :: " + typeId);
37         LOGGER.info(indent.toString());
38         for(SerializedVariable var : properties) {
39             indent = new StringBuilder();
40             for(int i=0;i<=indentation;++i)
41                 indent.append("  ");
42             indent.append(SerializedVariable.print(var, indentation*2+2));
43             LOGGER.info(indent.toString());
44         }
45         for(Connection connection : connections) {
46             indent = new StringBuilder();
47             for(int i=0;i<=indentation;++i)
48                 indent.append("  ");
49             indent.append(connection);
50             LOGGER.info(indent.toString());
51         }
52         if(!children.isEmpty()) {
53             indent = new StringBuilder();
54             for(int i=0;i<=indentation;++i)
55                 indent.append("  ");
56             indent.append("Children ");
57             if(children != null)
58                 indent.append(children);
59             LOGGER.info(indent.toString());
60         }
61         ++indentation;
62     }
63
64     @Override
65     public void endComponent() {
66         --indentation;
67     }
68
69     @Override
70     public void beginType(String id, Collection<SerializedVariable> properties) {
71         LOGGER.info("--- Type " + id + " --------------------------------");
72         for(SerializedVariable var : properties)
73             LOGGER.info(SerializedVariable.print(var, 2));
74     }
75
76     @Override
77     public void endType() {
78         LOGGER.info("----------------------------------------------------");
79     }
80
81     @Override
82     public void reportProblem(String description) {
83         LOGGER.error(description);
84     }
85
86     @Override
87     public void reportProblem(String description, Exception e) {
88         LOGGER.error(description, e);
89     }
90
91 }