001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.tomcat.jni;
019:
020: /** Windows Registy support
021: *
022: * @author Mladen Turk
023: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
024: */
025:
026: public class Registry {
027:
028: /* Registry Enums */
029: public static final int HKEY_CLASSES_ROOT = 1;
030: public static final int HKEY_CURRENT_CONFIG = 2;
031: public static final int HKEY_CURRENT_USER = 3;
032: public static final int HKEY_LOCAL_MACHINE = 4;
033: public static final int HKEY_USERS = 5;
034:
035: public static final int KEY_ALL_ACCESS = 0x0001;
036: public static final int KEY_CREATE_LINK = 0x0002;
037: public static final int KEY_CREATE_SUB_KEY = 0x0004;
038: public static final int KEY_ENUMERATE_SUB_KEYS = 0x0008;
039: public static final int KEY_EXECUTE = 0x0010;
040: public static final int KEY_NOTIFY = 0x0020;
041: public static final int KEY_QUERY_VALUE = 0x0040;
042: public static final int KEY_READ = 0x0080;
043: public static final int KEY_SET_VALUE = 0x0100;
044: public static final int KEY_WOW64_64KEY = 0x0200;
045: public static final int KEY_WOW64_32KEY = 0x0400;
046: public static final int KEY_WRITE = 0x0800;
047:
048: public static final int REG_BINARY = 1;
049: public static final int REG_DWORD = 2;
050: public static final int REG_EXPAND_SZ = 3;
051: public static final int REG_MULTI_SZ = 4;
052: public static final int REG_QWORD = 5;
053: public static final int REG_SZ = 6;
054:
055: /**
056: * Create or open a Registry Key.
057: * @param name Registry Subkey to open
058: * @param root Root key, one of HKEY_*
059: * @param som Access mask that specifies the access rights for the key.
060: * @return Opened Registry key
061: */
062: public static native long create(int root, String name, int sam,
063: long pool) throws Error;
064:
065: /**
066: * Opens the specified Registry Key.
067: * @param name Registry Subkey to open
068: * @param root Root key, one of HKEY_*
069: * @param som Access mask that specifies the access rights for the key.
070: * @return Opened Registry key
071: */
072: public static native long open(int root, String name, int sam,
073: long pool) throws Error;
074:
075: /**
076: * Close the specified Registry key.
077: * @param key The Registry key descriptor to close.
078: */
079: public static native int close(long key);
080:
081: /**
082: * Get the Registry key type.
083: * @param key The Registry key descriptor to use.
084: * @param name The name of the value to query
085: * @return Value type or negative error value
086: */
087: public static native int getType(long key, String name);
088:
089: /**
090: * Get the Registry value for REG_DWORD
091: * @param key The Registry key descriptor to use.
092: * @param name The name of the value to query
093: * @return Registry key value
094: */
095: public static native int getValueI(long key, String name)
096: throws Error;
097:
098: /**
099: * Get the Registry value for REG_QWORD or REG_DWORD
100: * @param key The Registry key descriptor to use.
101: * @param name The name of the value to query
102: * @return Registry key value
103: */
104: public static native long getValueJ(long key, String name)
105: throws Error;
106:
107: /**
108: * Get the Registry key length.
109: * @param key The Registry key descriptor to use.
110: * @param name The name of the value to query
111: * @return Value size or negative error value
112: */
113: public static native int getSize(long key, String name);
114:
115: /**
116: * Get the Registry value for REG_SZ or REG_EXPAND_SZ
117: * @param key The Registry key descriptor to use.
118: * @param name The name of the value to query
119: * @return Registry key value
120: */
121: public static native String getValueS(long key, String name)
122: throws Error;
123:
124: /**
125: * Get the Registry value for REG_MULTI_SZ
126: * @param key The Registry key descriptor to use.
127: * @param name The name of the value to query
128: * @return Registry key value
129: */
130: public static native String[] getValueA(long key, String name)
131: throws Error;
132:
133: /**
134: * Get the Registry value for REG_BINARY
135: * @param key The Registry key descriptor to use.
136: * @param name The name of the value to query
137: * @return Registry key value
138: */
139: public static native byte[] getValueB(long key, String name)
140: throws Error;
141:
142: /**
143: * Set the Registry value for REG_DWORD
144: * @param key The Registry key descriptor to use.
145: * @param name The name of the value to set
146: * @param val The the value to set
147: * @return If the function succeeds, the return value is 0
148: */
149: public static native int setValueI(long key, String name, int val);
150:
151: /**
152: * Set the Registry value for REG_QWORD
153: * @param key The Registry key descriptor to use.
154: * @param name The name of the value to set
155: * @param val The the value to set
156: * @return If the function succeeds, the return value is 0
157: */
158: public static native int setValueJ(long key, String name, int val);
159:
160: /**
161: * Set the Registry value for REG_SZ
162: * @param key The Registry key descriptor to use.
163: * @param name The name of the value to set
164: * @param val The the value to set
165: * @return If the function succeeds, the return value is 0
166: */
167: public static native int setValueS(long key, String name, String val);
168:
169: /**
170: * Set the Registry value for REG_EXPAND_SZ
171: * @param key The Registry key descriptor to use.
172: * @param name The name of the value to set
173: * @param val The the value to set
174: * @return If the function succeeds, the return value is 0
175: */
176: public static native int setValueE(long key, String name, String val);
177:
178: /**
179: * Set the Registry value for REG_MULTI_SZ
180: * @param key The Registry key descriptor to use.
181: * @param name The name of the value to set
182: * @param val The the value to set
183: * @return If the function succeeds, the return value is 0
184: */
185: public static native int setValueA(long key, String name,
186: String[] val);
187:
188: /**
189: * Set the Registry value for REG_BINARY
190: * @param key The Registry key descriptor to use.
191: * @param name The name of the value to set
192: * @param val The the value to set
193: * @return If the function succeeds, the return value is 0
194: */
195: public static native int setValueB(long key, String name, byte[] val);
196:
197: /**
198: * Enumerate the Registry subkeys
199: * @param key The Registry key descriptor to use.
200: * @param name The name of the value to query
201: * @return Array of all subkey names
202: */
203: public static native String[] enumKeys(long key) throws Error;
204:
205: /**
206: * Enumerate the Registry values
207: * @param key The Registry key descriptor to use.
208: * @param name The name of the value to query
209: * @return Array of all value names
210: */
211: public static native String[] enumValues(long key) throws Error;
212:
213: /**
214: * Delete the Registry value
215: * @param key The Registry key descriptor to use.
216: * @param name The name of the value to delete
217: * @return If the function succeeds, the return value is 0
218: */
219: public static native int deleteValue(long key, String name);
220:
221: /**
222: * Delete the Registry subkey
223: * @param root Root key, one of HKEY_*
224: * @param name Subkey to delete
225: * @param onlyIfEmpty If true will not delete a key if
226: * it contains any subkeys or values
227: * @return If the function succeeds, the return value is 0
228: */
229: public static native int deleteKey(int root, String name,
230: boolean onlyIfEmpty);
231:
232: }
|