]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * 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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.history;\r
13 \r
14 import java.io.File;\r
15 import java.io.IOException;\r
16 import java.io.InputStream;\r
17 import java.io.OutputStream;\r
18 \r
19 import org.simantics.databoard.binding.Binding;\r
20 import org.simantics.history.impl.CollectorImpl;\r
21 import org.simantics.history.impl.FileHistory;\r
22 import org.simantics.history.impl.FlushPolicy;\r
23 import org.simantics.history.impl.MemoryHistory;\r
24 import org.simantics.history.util.HistoryExportUtil;\r
25 \r
26 /**\r
27  * Facade-class for History Services.\r
28  * \r
29  * There are two main services HistoryManager and Collector.\r
30  * There are two main implementations file and memory.\r
31  * \r
32  * @author toni.kalajainen\r
33  */\r
34 public class History {\r
35 \r
36         /**\r
37          * Open a file based history manager.\r
38          * (Note, Trend does not need flush policy)\r
39          * \r
40          * @param workarea\r
41          * @return history manager\r
42          */\r
43         public static HistoryManager openFileHistory(File workarea)\r
44         {\r
45                 return new FileHistory(workarea);\r
46         }\r
47         \r
48         /**\r
49          * Create a transient memory history\r
50          * \r
51          * @return no history\r
52          */\r
53         public static HistoryManager createMemoryHistory()\r
54         {\r
55                 return new MemoryHistory();\r
56         }\r
57         \r
58         /**\r
59          * Create collector\r
60          * \r
61          * @param historyManager\r
62          * @return collector\r
63          */\r
64         public static Collector createCollector(HistoryManager historyManager)\r
65         {\r
66                 CollectorImpl result = new CollectorImpl(historyManager);\r
67                 return result;\r
68         }\r
69         \r
70         /**\r
71          * Create collector\r
72          * \r
73          * @param historyManager\r
74          * @param flushPolicy\r
75          * @return collector\r
76          */\r
77         public static Collector createCollector(HistoryManager historyManager, FlushPolicy flushPolicy)\r
78         {\r
79                 CollectorImpl result = new CollectorImpl(historyManager);\r
80                 result.setFlushPolicy(flushPolicy);\r
81                 return result;\r
82         }\r
83 \r
84         /**\r
85          * Export whole history manager to an output stream.\r
86          * \r
87          * @param history\r
88          * @param timeBinding\r
89          * @param from\r
90          * @param end\r
91          * @param os\r
92          * @throws IOException\r
93          * @throws HistoryException\r
94          */\r
95         public static void exportHistory( HistoryManager history, Binding timeBinding, Double from, Double end, OutputStream os )\r
96         throws IOException, HistoryException\r
97         {\r
98                 HistoryExportUtil eu = new HistoryExportUtil();\r
99                 eu.exportHistory(history, timeBinding, from, end, os);\r
100         }\r
101         \r
102         /**\r
103          * Import a history manager from an input stream \r
104          * \r
105          * @param history\r
106          * @param is\r
107          * @throws IOException\r
108          * @throws HistoryException\r
109          */\r
110         public static void importHistory( HistoryManager history, InputStream is )\r
111         throws IOException, HistoryException\r
112         {\r
113                 HistoryExportUtil eu = new HistoryExportUtil();\r
114                 eu.importHistory(history, is);\r
115         }\r
116 \r
117 }\r