KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hsqldb > util > TransferCommon


1 /* Copyright (c) 1995-2000, The Hypersonic SQL Group.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of the Hypersonic SQL Group nor the names of its
15  * contributors may be used to endorse or promote products derived from this
16  * software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE HYPERSONIC SQL GROUP,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This software consists of voluntary contributions made by many individuals
31  * on behalf of the Hypersonic SQL Group.
32  *
33  *
34  * For work added by the HSQL Development Group:
35  *
36  * Copyright (c) 2001-2005, The HSQL Development Group
37  * All rights reserved.
38  *
39  * Redistribution and use in source and binary forms, with or without
40  * modification, are permitted provided that the following conditions are met:
41  *
42  * Redistributions of source code must retain the above copyright notice, this
43  * list of conditions and the following disclaimer.
44  *
45  * Redistributions in binary form must reproduce the above copyright notice,
46  * this list of conditions and the following disclaimer in the documentation
47  * and/or other materials provided with the distribution.
48  *
49  * Neither the name of the HSQL Development Group nor the names of its
50  * contributors may be used to endorse or promote products derived from this
51  * software without specific prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
54  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
57  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
58  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
59  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
60  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
63  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64  */

65
66
67 package org.hsqldb.util;
68
69 import java.io.FileInputStream JavaDoc;
70 import java.io.FileOutputStream JavaDoc;
71 import java.io.IOException JavaDoc;
72 import java.io.ObjectInputStream JavaDoc;
73 import java.io.ObjectOutputStream JavaDoc;
74 import java.util.Vector JavaDoc;
75
76 // sqlbob@users 20020407 - patch 1.7.0 - reengineering
77

78 /**
79  * Common code in Swing and AWT versions of Tranfer
80  * New class based on Hypersonic code
81  * @author Thomas Mueller (Hypersonic SQL Group)
82  * @version 1.7.2
83  * @since Hypersonic SQL
84  */

85 class TransferCommon {
86
87     static void savePrefs(String JavaDoc f, DataAccessPoint sourceDb,
88                           DataAccessPoint targetDb, Traceable tracer,
89                           Vector JavaDoc tTable) {
90
91         TransferTable t;
92
93         try {
94             FileOutputStream JavaDoc fos = new FileOutputStream JavaDoc(f);
95             ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(fos);
96
97             for (int i = 0; i < tTable.size(); i++) {
98                 t = (TransferTable) tTable.elementAt(i);
99                 t.sourceDb = null;
100                 t.destDb = null;
101                 t.tracer = null;
102             }
103
104             oos.writeObject(tTable);
105
106             for (int i = 0; i < tTable.size(); i++) {
107                 t = (TransferTable) tTable.elementAt(i);
108                 t.tracer = tracer;
109                 t.sourceDb = (TransferDb) sourceDb;
110                 t.destDb = targetDb;
111             }
112         } catch (IOException JavaDoc e) {
113             System.out.println("pb in SavePrefs : " + e.toString());
114             e.printStackTrace();
115         }
116     }
117
118     static Vector JavaDoc loadPrefs(String JavaDoc f, DataAccessPoint sourceDb,
119                             DataAccessPoint targetDb, Traceable tracer) {
120
121         TransferTable t;
122         Vector JavaDoc tTable = null;
123         ObjectInputStream JavaDoc ois = null;
124
125         try {
126             FileInputStream JavaDoc fis = new FileInputStream JavaDoc(f);
127
128             ois = new ObjectInputStream JavaDoc(fis);
129             tTable = (Vector JavaDoc) ois.readObject();
130
131             for (int i = 0; i < tTable.size(); i++) {
132                 t = (TransferTable) tTable.elementAt(i);
133                 t.tracer = tracer;
134                 t.sourceDb = (TransferDb) sourceDb;
135                 t.destDb = targetDb;
136             }
137         } catch (ClassNotFoundException JavaDoc e) {
138             System.out.println("class not found pb in LoadPrefs : "
139                                + e.toString());
140
141             tTable = new Vector JavaDoc();
142         } catch (IOException JavaDoc e) {
143             System.out.println("IO pb in LoadPrefs : actionPerformed"
144                                + e.toString());
145
146             tTable = new Vector JavaDoc();
147         } finally {
148             if (ois != null) {
149                 try {
150                     ois.close();
151                 } catch (IOException JavaDoc ioe) {}
152             }
153         }
154
155         return (tTable);
156     }
157
158     private TransferCommon() {}
159 }
160
Popular Tags