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.db.impl;
\r
14 import java.io.DataOutput;
\r
15 import java.io.DataOutputStream;
\r
16 import java.io.FileNotFoundException;
\r
17 import java.io.FileOutputStream;
\r
18 import java.io.IOException;
\r
20 public class GraphPrinter {
\r
22 public static String LOG_FILE = "d:\\graph.dot";
\r
24 public static boolean LOG = true;
\r
26 static Object loggerCreationLock = new Object();
\r
27 static GraphPrinter logger = null;
\r
31 public GraphPrinter() {
\r
34 FileOutputStream stream = new FileOutputStream(LOG_FILE);
\r
35 log = new DataOutputStream(stream);
\r
36 } catch (FileNotFoundException e) {
\r
37 e.printStackTrace();
\r
42 public static GraphPrinter getInstance() {
\r
43 if(logger == null) {
\r
44 synchronized (loggerCreationLock) {
\r
46 logger = new GraphPrinter();
\r
52 public void begin(String filename) {
\r
55 FileOutputStream stream = new FileOutputStream(LOG_FILE);
\r
56 log = new DataOutputStream(stream);
\r
59 log.writeBytes("digraph test {\n");
\r
61 } catch(IOException e) {
\r
62 e.printStackTrace();
\r
64 } catch (FileNotFoundException e) {
\r
65 e.printStackTrace();
\r
70 public void finish() {
\r
74 log.writeBytes("}\n");
\r
76 } catch(IOException e) {
\r
77 e.printStackTrace();
\r
83 private String escape(String input) {
\r
84 return input.replace("[", "_").replace("]", "_").replace(":", "_").replace("/", "_").replace("@", "_").replace(".", "_").replace(" ", "_").replace("#", "_").replace("-", "_");
\r
87 public void log(String start, String end) {
\r
91 log.writeBytes(escape(start.toString()));
\r
92 log.writeBytes(" -> ");
\r
93 log.writeBytes(escape(end.toString()));
\r
94 log.writeBytes("\n");
\r
96 } catch(IOException e) {
\r
97 e.printStackTrace();
\r