001: /*
002: * $Id: Win_RegistryHandler.java 2062 2008-02-25 20:22:45Z jponge $
003: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
004: *
005: * http://izpack.org/
006: * http://izpack.codehaus.org/
007: *
008: * Copyright 2005 Klaus Bartz
009: *
010: * Licensed under the Apache License, Version 2.0 (the "License");
011: * you may not use this file except in compliance with the License.
012: * You may obtain a copy of the License at
013: *
014: * http://www.apache.org/licenses/LICENSE-2.0
015: *
016: * Unless required by applicable law or agreed to in writing, software
017: * distributed under the License is distributed on an "AS IS" BASIS,
018: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019: * See the License for the specific language governing permissions and
020: * limitations under the License.
021: */
022:
023: package com.izforge.izpack.util.os;
024:
025: import java.util.List;
026:
027: import com.coi.tools.os.izpack.Registry;
028: import com.coi.tools.os.win.NativeLibException;
029: import com.coi.tools.os.win.RegDataContainer;
030:
031: /**
032: * This is the Microsoft Windows specific implementation of <code>RegistryHandler</code>.
033: *
034: * @author bartzkau
035: *
036: */
037: public class Win_RegistryHandler extends RegistryHandler {
038:
039: Registry regWorker = null;
040:
041: /**
042: * Default constructor.
043: */
044: public Win_RegistryHandler() {
045: super ("com.coi.tools.os.izpack.Registry");
046: if (good())
047: regWorker = (Registry) worker;
048: }
049:
050: /**
051: * Sets the given contents to the given registry value. If a sub key or the registry value does
052: * not exist, it will be created. The return value is a String array which contains the names of
053: * the keys and values which are created. REG_SZ is used as registry value type.
054: *
055: * @param key the registry key which should be used or created
056: * @param value the registry value into which the contents should be set
057: * @param contents the contents for the value
058: * @throws NativeLibException
059: * @throws NativeLibException
060: */
061: public void setValue(String key, String value, String contents)
062: throws NativeLibException {
063: if (!good())
064: return;
065: regWorker.setValue(key, value, contents);
066: }
067:
068: /**
069: * Sets the given contents to the given registry value. If a sub key or the registry value does
070: * not exist, it will be created. The return value is a String array which contains the names of
071: * the keys and values which are created. REG_MULTI_SZ is used as registry value type.
072: *
073: * @param key the registry key which should be used or created
074: * @param value the registry value into which the contents should be set
075: * @param contents the contents for the value
076: * @throws NativeLibException
077: */
078: public void setValue(String key, String value, String[] contents)
079: throws NativeLibException {
080: if (!good())
081: return;
082: regWorker.setValue(key, value, contents);
083: }
084:
085: /**
086: * Sets the given contents to the given registry value. If a sub key or the registry value does
087: * not exist, it will be created. The return value is a String array which contains the names of
088: * the keys and values which are created. REG_BINARY is used as registry value type.
089: *
090: * @param key the registry key which should be used or created
091: * @param value the registry value into which the contents should be set
092: * @param contents the contents for the value
093: * @throws NativeLibException
094: */
095: public void setValue(String key, String value, byte[] contents)
096: throws NativeLibException {
097: if (!good())
098: return;
099: regWorker.setValue(key, value, contents);
100: }
101:
102: /**
103: * Sets the given contents to the given registry value. If a sub key or the registry value does
104: * not exist, it will be created. The return value is a String array which contains the names of
105: * the keys and values which are created. REG_DWORD is used as registry value type.
106: *
107: * @param key the registry key which should be used or created
108: * @param value the registry value into which the contents should be set
109: * @param contents the contents for the value
110: * @throws NativeLibException
111: */
112: public void setValue(String key, String value, long contents)
113: throws NativeLibException {
114: if (!good())
115: return;
116: regWorker.setValue(key, value, contents);
117: }
118:
119: /**
120: * Returns the contents of the key/value pair if value exist, else the given default value.
121: *
122: * @param key the registry key which should be used
123: * @param value the registry value from which the contents should be requested
124: * @param defaultVal value to be used if no value exist in the registry
125: * @return requested value if exist, else the default value
126: * @throws NativeLibException
127: */
128: public RegDataContainer getValue(String key, String value,
129: RegDataContainer defaultVal) throws NativeLibException {
130: if (!good())
131: return (null);
132: if (valueExist(key, value))
133: return (getValue(key, value));
134: return (defaultVal);
135: }
136:
137: /**
138: * Returns whether a key exist or not.
139: *
140: * @param key key to be evaluated
141: * @return whether a key exist or not
142: * @throws NativeLibException
143: */
144: public boolean keyExist(String key) throws NativeLibException {
145: if (!good())
146: return (false);
147: return (regWorker.keyExist(key));
148: }
149:
150: /**
151: * Returns whether a the given value under the given key exist or not.
152: *
153: * @param key key to be used as path for the value
154: * @param value value name to be evaluated
155: * @return whether a the given value under the given key exist or not
156: * @throws NativeLibException
157: */
158: public boolean valueExist(String key, String value)
159: throws NativeLibException {
160: if (!good())
161: return (false);
162: return (regWorker.valueExist(key, value));
163: }
164:
165: /**
166: * Returns all keys which are defined under the given key.
167: *
168: * @param key key to be used as path for the sub keys
169: * @return all keys which are defined under the given key
170: * @throws NativeLibException
171: */
172: public String[] getSubkeys(String key) throws NativeLibException {
173: if (!good())
174: return (null);
175: return (regWorker.getSubkeys(key));
176: }
177:
178: /**
179: * Returns all value names which are defined under the given key.
180: *
181: * @param key key to be used as path for the value names
182: * @return all value names which are defined under the given key
183: * @throws NativeLibException
184: */
185: public String[] getValueNames(String key) throws NativeLibException {
186: if (!good())
187: return (null);
188: return (regWorker.getValueNames(key));
189: }
190:
191: /**
192: * Returns the contents of the key/value pair if value exist, else an exception is raised.
193: *
194: * @param key the registry key which should be used
195: * @param value the registry value from which the contents should be requested
196: * @return requested value if exist, else an exception
197: * @throws NativeLibException
198: */
199: public RegDataContainer getValue(String key, String value)
200: throws NativeLibException {
201: if (!good())
202: return (null);
203: return (regWorker.getValue(key, value));
204: }
205:
206: /**
207: * Creates the given key in the registry.
208: *
209: * @param key key to be created
210: * @throws NativeLibException
211: */
212: public void createKey(String key) throws NativeLibException {
213: if (!good())
214: return;
215: regWorker.createKey(key);
216: }
217:
218: /**
219: * Deletes the given key if exist, else throws an exception.
220: * @param key key to be deleted
221: * @throws NativeLibException
222: */
223: public void deleteKey(String key) throws NativeLibException {
224: if (!good())
225: return;
226: regWorker.deleteKey(key);
227: }
228:
229: /**
230: * Deletes a key under the current root if it is empty, else do nothing.
231: *
232: * @param key key to be deleted
233: * @throws NativeLibException
234: */
235: public void deleteKeyIfEmpty(String key) throws NativeLibException {
236: if (!good())
237: return;
238: regWorker.deleteKeyIfEmpty(key);
239: }
240:
241: /**
242: * Deletes a value.
243: *
244: * @param key key of the value which should be deleted
245: * @param value value name to be deleted
246: * @throws NativeLibException
247: */
248: public void deleteValue(String key, String value)
249: throws NativeLibException {
250: if (!good())
251: return;
252: regWorker.deleteValue(key, value);
253: }
254:
255: /**
256: * Sets the root for the next registry access.
257: *
258: * @param i an integer which refers to a HKEY
259: * @throws NativeLibException
260: */
261: public void setRoot(int i) throws NativeLibException {
262: if (!good())
263: return;
264: regWorker.setRoot(i);
265: }
266:
267: /**
268: * Return the root as integer (HKEY_xxx).
269: *
270: * @return the root as integer
271: * @throws NativeLibException
272: */
273: public int getRoot() throws NativeLibException {
274: if (!good())
275: return (0);
276: return (regWorker.getRoot());
277: }
278:
279: /**
280: * Activates logging of registry changes.
281: *
282: * @throws NativeLibException
283: */
284: public void activateLogging() throws NativeLibException {
285: if (!good())
286: return;
287: regWorker.activateLogging();
288: }
289:
290: /**
291: * Suspends logging of registry changes.
292: *
293: * @throws NativeLibException
294: */
295: public void suspendLogging() throws NativeLibException {
296: if (!good())
297: return;
298: regWorker.suspendLogging();
299: }
300:
301: /**
302: * Resets logging of registry changes.
303: *
304: * @throws NativeLibException
305: */
306: public void resetLogging() throws NativeLibException {
307: if (!good())
308: return;
309: regWorker.resetLogging();
310: }
311:
312: public List<Object> getLoggingInfo() throws NativeLibException {
313: if (!good())
314: return (null);
315: return (regWorker.getLoggingInfo());
316: }
317:
318: public void setLoggingInfo(List info) throws NativeLibException {
319: if (!good())
320: return;
321: regWorker.setLoggingInfo(info);
322: }
323:
324: public void addLoggingInfo(List info) throws NativeLibException {
325: if (!good())
326: return;
327: regWorker.addLoggingInfo(info);
328: }
329:
330: public void rewind() throws NativeLibException {
331: if (!good())
332: return;
333: regWorker.rewind();
334: }
335:
336: }
|