X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FGraphPrinter.java;h=db22a77e7b34664c5a8a8e97889bf51469c41d39;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=f679c9f26f7adac1bf26b934321c98d3470a7a29;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/GraphPrinter.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/GraphPrinter.java index f679c9f26..db22a77e7 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/GraphPrinter.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/GraphPrinter.java @@ -1,102 +1,102 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.impl; - -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; - -public class GraphPrinter { - - public static String LOG_FILE = "d:\\graph.dot"; - - public static boolean LOG = true; - - static Object loggerCreationLock = new Object(); - static GraphPrinter logger = null; - - DataOutput log; - - public GraphPrinter() { - if(LOG) { - try { - FileOutputStream stream = new FileOutputStream(LOG_FILE); - log = new DataOutputStream(stream); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - } - - public static GraphPrinter getInstance() { - if(logger == null) { - synchronized (loggerCreationLock) { - if(logger == null) - logger = new GraphPrinter(); - } - } - return logger; - } - - public void begin(String filename) { - if(LOG) { - try { - FileOutputStream stream = new FileOutputStream(LOG_FILE); - log = new DataOutputStream(stream); - try { - synchronized(log) { - log.writeBytes("digraph test {\n"); - } - } catch(IOException e) { - e.printStackTrace(); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - } - - public void finish() { - if(LOG) { - try { - synchronized(log) { - log.writeBytes("}\n"); - } - } catch(IOException e) { - e.printStackTrace(); - } - log = null; - } - } - - private String escape(String input) { - return input.replace("[", "_").replace("]", "_").replace(":", "_").replace("/", "_").replace("@", "_").replace(".", "_").replace(" ", "_").replace("#", "_").replace("-", "_"); - } - - public void log(String start, String end) { - - try { - synchronized(log) { - log.writeBytes(escape(start.toString())); - log.writeBytes(" -> "); - log.writeBytes(escape(end.toString())); - log.writeBytes("\n"); - } - } catch(IOException e) { - e.printStackTrace(); - } - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.impl; + +import java.io.DataOutput; +import java.io.DataOutputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +public class GraphPrinter { + + public static String LOG_FILE = "d:\\graph.dot"; + + public static boolean LOG = true; + + static Object loggerCreationLock = new Object(); + static GraphPrinter logger = null; + + DataOutput log; + + public GraphPrinter() { + if(LOG) { + try { + FileOutputStream stream = new FileOutputStream(LOG_FILE); + log = new DataOutputStream(stream); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } + + public static GraphPrinter getInstance() { + if(logger == null) { + synchronized (loggerCreationLock) { + if(logger == null) + logger = new GraphPrinter(); + } + } + return logger; + } + + public void begin(String filename) { + if(LOG) { + try { + FileOutputStream stream = new FileOutputStream(LOG_FILE); + log = new DataOutputStream(stream); + try { + synchronized(log) { + log.writeBytes("digraph test {\n"); + } + } catch(IOException e) { + e.printStackTrace(); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } + + public void finish() { + if(LOG) { + try { + synchronized(log) { + log.writeBytes("}\n"); + } + } catch(IOException e) { + e.printStackTrace(); + } + log = null; + } + } + + private String escape(String input) { + return input.replace("[", "_").replace("]", "_").replace(":", "_").replace("/", "_").replace("@", "_").replace(".", "_").replace(" ", "_").replace("#", "_").replace("-", "_"); + } + + public void log(String start, String end) { + + try { + synchronized(log) { + log.writeBytes(escape(start.toString())); + log.writeBytes(" -> "); + log.writeBytes(escape(end.toString())); + log.writeBytes("\n"); + } + } catch(IOException e) { + e.printStackTrace(); + } + + } + +}