]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.history/src/org/simantics/history/History.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / History.java
diff --git a/bundles/org.simantics.history/src/org/simantics/history/History.java b/bundles/org.simantics.history/src/org/simantics/history/History.java
new file mode 100644 (file)
index 0000000..cfcaf66
--- /dev/null
@@ -0,0 +1,117 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * 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.history;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.OutputStream;\r
+\r
+import org.simantics.databoard.binding.Binding;\r
+import org.simantics.history.impl.CollectorImpl;\r
+import org.simantics.history.impl.FileHistory;\r
+import org.simantics.history.impl.FlushPolicy;\r
+import org.simantics.history.impl.MemoryHistory;\r
+import org.simantics.history.util.HistoryExportUtil;\r
+\r
+/**\r
+ * Facade-class for History Services.\r
+ * \r
+ * There are two main services HistoryManager and Collector.\r
+ * There are two main implementations file and memory.\r
+ * \r
+ * @author toni.kalajainen\r
+ */\r
+public class History {\r
+\r
+       /**\r
+        * Open a file based history manager.\r
+        * (Note, Trend does not need flush policy)\r
+        * \r
+        * @param workarea\r
+        * @return history manager\r
+        */\r
+       public static HistoryManager openFileHistory(File workarea)\r
+       {\r
+               return new FileHistory(workarea);\r
+       }\r
+       \r
+       /**\r
+        * Create a transient memory history\r
+        * \r
+        * @return no history\r
+        */\r
+       public static HistoryManager createMemoryHistory()\r
+       {\r
+               return new MemoryHistory();\r
+       }\r
+       \r
+       /**\r
+        * Create collector\r
+        * \r
+        * @param historyManager\r
+        * @return collector\r
+        */\r
+       public static Collector createCollector(HistoryManager historyManager)\r
+       {\r
+               CollectorImpl result = new CollectorImpl(historyManager);\r
+               return result;\r
+       }\r
+       \r
+       /**\r
+        * Create collector\r
+        * \r
+        * @param historyManager\r
+        * @param flushPolicy\r
+        * @return collector\r
+        */\r
+       public static Collector createCollector(HistoryManager historyManager, FlushPolicy flushPolicy)\r
+       {\r
+               CollectorImpl result = new CollectorImpl(historyManager);\r
+               result.setFlushPolicy(flushPolicy);\r
+               return result;\r
+       }\r
+\r
+       /**\r
+        * Export whole history manager to an output stream.\r
+        * \r
+        * @param history\r
+        * @param timeBinding\r
+        * @param from\r
+        * @param end\r
+        * @param os\r
+        * @throws IOException\r
+        * @throws HistoryException\r
+        */\r
+       public static void exportHistory( HistoryManager history, Binding timeBinding, Double from, Double end, OutputStream os )\r
+       throws IOException, HistoryException\r
+       {\r
+               HistoryExportUtil eu = new HistoryExportUtil();\r
+               eu.exportHistory(history, timeBinding, from, end, os);\r
+       }\r
+       \r
+       /**\r
+        * Import a history manager from an input stream \r
+        * \r
+        * @param history\r
+        * @param is\r
+        * @throws IOException\r
+        * @throws HistoryException\r
+        */\r
+       public static void importHistory( HistoryManager history, InputStream is )\r
+       throws IOException, HistoryException\r
+       {\r
+               HistoryExportUtil eu = new HistoryExportUtil();\r
+               eu.importHistory(history, is);\r
+       }\r
+\r
+}\r