1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl;
14 import java.io.DataOutput;
15 import java.io.DataOutputStream;
16 import java.io.FileNotFoundException;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
20 public class GraphPrinter {
22 public static String LOG_FILE = "d:\\graph.dot";
24 public static boolean LOG = true;
26 static Object loggerCreationLock = new Object();
27 static GraphPrinter logger = null;
31 public GraphPrinter() {
34 FileOutputStream stream = new FileOutputStream(LOG_FILE);
35 log = new DataOutputStream(stream);
36 } catch (FileNotFoundException e) {
42 public static GraphPrinter getInstance() {
44 synchronized (loggerCreationLock) {
46 logger = new GraphPrinter();
52 public void begin(String filename) {
55 FileOutputStream stream = new FileOutputStream(LOG_FILE);
56 log = new DataOutputStream(stream);
59 log.writeBytes("digraph test {\n");
61 } catch(IOException e) {
64 } catch (FileNotFoundException e) {
70 public void finish() {
74 log.writeBytes("}\n");
76 } catch(IOException e) {
83 private String escape(String input) {
84 return input.replace("[", "_").replace("]", "_").replace(":", "_").replace("/", "_").replace("@", "_").replace(".", "_").replace(" ", "_").replace("#", "_").replace("-", "_");
87 public void log(String start, String end) {
91 log.writeBytes(escape(start.toString()));
92 log.writeBytes(" -> ");
93 log.writeBytes(escape(end.toString()));
96 } catch(IOException e) {