]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.impl/src/org/simantics/db/impl/GraphPrinter.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / GraphPrinter.java
index f679c9f26f7adac1bf26b934321c98d3470a7a29..db22a77e7b34664c5a8a8e97889bf51469c41d39 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.impl;\r
-\r
-import java.io.DataOutput;\r
-import java.io.DataOutputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-\r
-public class GraphPrinter {\r
-\r
-    public static String LOG_FILE = "d:\\graph.dot";\r
-    \r
-    public static boolean LOG = true;\r
-\r
-    static Object loggerCreationLock = new Object();\r
-    static GraphPrinter logger = null; \r
-\r
-    DataOutput log;\r
-\r
-    public GraphPrinter() {\r
-        if(LOG) {\r
-            try {\r
-                FileOutputStream stream = new FileOutputStream(LOG_FILE);\r
-                log = new DataOutputStream(stream);\r
-            } catch (FileNotFoundException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-    }\r
-\r
-    public static GraphPrinter getInstance() {\r
-        if(logger == null) {\r
-            synchronized (loggerCreationLock) {\r
-                if(logger == null)\r
-                    logger = new GraphPrinter();       \r
-            }                   \r
-        }\r
-        return logger;\r
-    }\r
-\r
-    public void begin(String filename) {\r
-        if(LOG) {\r
-            try {\r
-                FileOutputStream stream = new FileOutputStream(LOG_FILE);\r
-                log = new DataOutputStream(stream);\r
-                try {\r
-                    synchronized(log) {\r
-                        log.writeBytes("digraph test {\n");\r
-                    }\r
-                } catch(IOException e) {\r
-                    e.printStackTrace();\r
-                }\r
-            } catch (FileNotFoundException e) {\r
-                e.printStackTrace();\r
-            }\r
-        }\r
-    }\r
-\r
-    public void finish() {\r
-        if(LOG) {\r
-            try {\r
-                synchronized(log) {\r
-                    log.writeBytes("}\n");\r
-                }\r
-            } catch(IOException e) {\r
-                e.printStackTrace();\r
-            }\r
-            log = null;\r
-        }\r
-    }\r
-\r
-    private String escape(String input) {\r
-        return input.replace("[", "_").replace("]", "_").replace(":", "_").replace("/", "_").replace("@", "_").replace(".", "_").replace(" ", "_").replace("#", "_").replace("-", "_");\r
-    }\r
-    \r
-    public void log(String start, String end) {\r
-\r
-        try {\r
-            synchronized(log) {\r
-                log.writeBytes(escape(start.toString()));\r
-                log.writeBytes(" -> ");\r
-                log.writeBytes(escape(end.toString()));\r
-                log.writeBytes("\n");\r
-            }\r
-        } catch(IOException e) {\r
-            e.printStackTrace();\r
-        }\r
-        \r
-    }\r
-    \r
-}\r
+/*******************************************************************************
+ * 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();
+        }
+        
+    }
+    
+}