KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > util > os > Win_RegistryHandler


1 /*
2  * $Id: Win_RegistryHandler.java 1708 2007-01-13 18:31:26Z jponge $
3  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
4  *
5  * http://www.izforge.com/izpack/
6  * http://developer.berlios.de/projects/izpack/
7  *
8  * Copyright 2005 Klaus Bartz
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22
23 package com.izforge.izpack.util.os;
24
25 import java.util.List JavaDoc;
26
27 import com.coi.tools.os.izpack.Registry;
28 import com.coi.tools.os.win.NativeLibException;
29 import com.coi.tools.os.win.RegDataContainer;
30
31 /**
32  * This is the Microsoft Windows specific implementation of <code>RegistryHandler</code>.
33  *
34  * @author bartzkau
35  *
36  */

37 public class Win_RegistryHandler extends RegistryHandler
38 {
39
40     Registry regWorker = null;
41
42     /**
43      * Default constructor.
44      */

45     public Win_RegistryHandler()
46     {
47         super("com.coi.tools.os.izpack.Registry");
48         if (good()) regWorker = (Registry) worker;
49     }
50
51     /**
52      * Sets the given contents to the given registry value. If a sub key or the registry value does
53      * not exist, it will be created. The return value is a String array which contains the names of
54      * the keys and values which are created. REG_SZ is used as registry value type.
55      *
56      * @param key the registry key which should be used or created
57      * @param value the registry value into which the contents should be set
58      * @param contents the contents for the value
59      * @throws NativeLibException
60      * @throws NativeLibException
61      */

62     public void setValue(String JavaDoc key, String JavaDoc value, String JavaDoc contents) throws NativeLibException
63     {
64         if (!good()) return;
65         regWorker.setValue(key, value, contents);
66     }
67
68     /**
69      * Sets the given contents to the given registry value. If a sub key or the registry value does
70      * not exist, it will be created. The return value is a String array which contains the names of
71      * the keys and values which are created. REG_MULTI_SZ is used as registry value type.
72      *
73      * @param key the registry key which should be used or created
74      * @param value the registry value into which the contents should be set
75      * @param contents the contents for the value
76      * @throws NativeLibException
77      */

78     public void setValue(String JavaDoc key, String JavaDoc value, String JavaDoc[] contents) throws NativeLibException
79     {
80         if (!good()) return;
81         regWorker.setValue(key, value, contents);
82     }
83
84     /**
85      * Sets the given contents to the given registry value. If a sub key or the registry value does
86      * not exist, it will be created. The return value is a String array which contains the names of
87      * the keys and values which are created. REG_BINARY is used as registry value type.
88      *
89      * @param key the registry key which should be used or created
90      * @param value the registry value into which the contents should be set
91      * @param contents the contents for the value
92      * @throws NativeLibException
93      */

94     public void setValue(String JavaDoc key, String JavaDoc value, byte[] contents) throws NativeLibException
95     {
96         if (!good()) return;
97         regWorker.setValue(key, value, contents);
98     }
99
100     /**
101      * Sets the given contents to the given registry value. If a sub key or the registry value does
102      * not exist, it will be created. The return value is a String array which contains the names of
103      * the keys and values which are created. REG_DWORD is used as registry value type.
104      *
105      * @param key the registry key which should be used or created
106      * @param value the registry value into which the contents should be set
107      * @param contents the contents for the value
108      * @throws NativeLibException
109      */

110     public void setValue(String JavaDoc key, String JavaDoc value, long contents) throws NativeLibException
111     {
112         if (!good()) return;
113         regWorker.setValue(key, value, contents);
114     }
115
116     /**
117      * Returns the contents of the key/value pair if value exist, else the given default value.
118      *
119      * @param key the registry key which should be used
120      * @param value the registry value from which the contents should be requested
121      * @param defaultVal value to be used if no value exist in the registry
122      * @return requested value if exist, else the default value
123      * @throws NativeLibException
124      */

125     public RegDataContainer getValue(String JavaDoc key, String JavaDoc value, RegDataContainer defaultVal) throws NativeLibException
126     {
127         if (!good()) return (null);
128         if (valueExist(key, value)) return (getValue(key, value));
129         return (defaultVal);
130     }
131
132     /**
133      * Returns whether a key exist or not.
134      *
135      * @param key key to be evaluated
136      * @return whether a key exist or not
137      * @throws NativeLibException
138      */

139     public boolean keyExist(String JavaDoc key) throws NativeLibException
140     {
141         if (!good()) return (false);
142         return (regWorker.keyExist(key));
143     }
144
145     /**
146      * Returns whether a the given value under the given key exist or not.
147      *
148      * @param key key to be used as path for the value
149      * @param value value name to be evaluated
150      * @return whether a the given value under the given key exist or not
151      * @throws NativeLibException
152      */

153     public boolean valueExist(String JavaDoc key, String JavaDoc value) throws NativeLibException
154     {
155         if (!good()) return (false);
156         return (regWorker.valueExist(key, value));
157     }
158
159     /**
160      * Returns all keys which are defined under the given key.
161      *
162      * @param key key to be used as path for the sub keys
163      * @return all keys which are defined under the given key
164      * @throws NativeLibException
165      */

166     public String JavaDoc[] getSubkeys(String JavaDoc key) throws NativeLibException
167     {
168         if (!good()) return (null);
169         return (regWorker.getSubkeys(key));
170     }
171
172     /**
173      * Returns all value names which are defined under the given key.
174      *
175      * @param key key to be used as path for the value names
176      * @return all value names which are defined under the given key
177      * @throws NativeLibException
178      */

179     public String JavaDoc[] getValueNames(String JavaDoc key) throws NativeLibException
180     {
181         if (!good()) return (null);
182         return (regWorker.getValueNames(key));
183     }
184
185     /**
186      * Returns the contents of the key/value pair if value exist, else an exception is raised.
187      *
188      * @param key the registry key which should be used
189      * @param value the registry value from which the contents should be requested
190      * @return requested value if exist, else an exception
191      * @throws NativeLibException
192      */

193     public RegDataContainer getValue(String JavaDoc key, String JavaDoc value) throws NativeLibException
194     {
195         if (!good()) return (null);
196         return (regWorker.getValue(key, value));
197     }
198
199     /**
200      * Creates the given key in the registry.
201      *
202      * @param key key to be created
203      * @throws NativeLibException
204      */

205     public void createKey(String JavaDoc key) throws NativeLibException
206     {
207         if (!good()) return;
208         regWorker.createKey(key);
209     }
210
211     /**
212      * Deletes the given key if exist, else throws an exception.
213      * @param key key to be deleted
214      * @throws NativeLibException
215      */

216     public void deleteKey( String JavaDoc key) throws NativeLibException
217     {
218         if (!good()) return;
219         regWorker.deleteKey(key);
220     }
221     
222     /**
223      * Deletes a key under the current root if it is empty, else do nothing.
224      *
225      * @param key key to be deleted
226      * @throws NativeLibException
227      */

228     public void deleteKeyIfEmpty(String JavaDoc key) throws NativeLibException
229     {
230         if (!good()) return;
231         regWorker.deleteKeyIfEmpty(key);
232     }
233     
234     /**
235      * Deletes a value.
236      *
237      * @param key key of the value which should be deleted
238      * @param value value name to be deleted
239      * @throws NativeLibException
240      */

241     public void deleteValue(String JavaDoc key, String JavaDoc value) throws NativeLibException
242     {
243         if (!good()) return;
244         regWorker.deleteValue(key, value);
245     }
246
247     /**
248      * Sets the root for the next registry access.
249      *
250      * @param i an integer which refers to a HKEY
251      * @throws NativeLibException
252      */

253     public void setRoot(int i) throws NativeLibException
254     {
255         if (!good()) return;
256         regWorker.setRoot(i);
257     }
258
259     /**
260      * Return the root as integer (HKEY_xxx).
261      *
262      * @return the root as integer
263      * @throws NativeLibException
264      */

265     public int getRoot() throws NativeLibException
266     {
267         if (!good()) return (0);
268         return (regWorker.getRoot());
269     }
270
271     /**
272      * Activates logging of registry changes.
273      *
274      * @throws NativeLibException
275      */

276     public void activateLogging() throws NativeLibException
277     {
278         if (!good()) return;
279         regWorker.activateLogging();
280     }
281
282     /**
283      * Suspends logging of registry changes.
284      *
285      * @throws NativeLibException
286      */

287     public void suspendLogging() throws NativeLibException
288     {
289         if (!good()) return;
290         regWorker.suspendLogging();
291     }
292
293     /**
294      * Resets logging of registry changes.
295      *
296      * @throws NativeLibException
297      */

298     public void resetLogging() throws NativeLibException
299     {
300         if (!good()) return;
301         regWorker.resetLogging();
302     }
303
304     public List JavaDoc getLoggingInfo() throws NativeLibException
305     {
306         if (!good()) return (null);
307         return (regWorker.getLoggingInfo());
308     }
309
310     public void setLoggingInfo(List JavaDoc info) throws NativeLibException
311     {
312         if (!good()) return;
313         regWorker.setLoggingInfo(info);
314     }
315
316     public void addLoggingInfo(List JavaDoc info) throws NativeLibException
317     {
318         if (!good()) return;
319         regWorker.addLoggingInfo(info);
320     }
321
322     public void rewind() throws NativeLibException
323     {
324         if (!good()) return;
325         regWorker.rewind();
326     }
327
328 }
329
Popular Tags