KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ice > jni > registry > RegistryValue


1 /*
2 ** Java native interface to the Windows Registry API.
3 ** Copyright (c) 1997 by Timothy Gerard Endres
4 **
5 ** This program is free software.
6 **
7 ** You may redistribute it and/or modify it under the terms of the GNU
8 ** General Public License as published by the Free Software Foundation.
9 ** Version 2 of the license should be included with this distribution in
10 ** the file LICENSE, as well as License.html. If the license is not
11 ** included with this distribution, you may find a copy at the FSF web
12 ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
13 ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
14 **
15 ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
16 ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
17 ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
18 ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
19 ** REDISTRIBUTION OF THIS SOFTWARE.
20 **
21 */

22
23 package com.ice.jni.registry;
24
25 import java.io.PrintWriter JavaDoc;
26
27 /**
28  * The RegistryValue class represents a value in the registry.
29  * This class is abstract, so it can not be instantiated. The
30  * class is a superclass to all value classes. The common
31  * abstract methods for getting and setting data must be defined
32  * by the subclass, but subclasses will almost always provide
33  * additional methods that get and set the value using the data
34  * type of the subclass.
35  *
36  * @see com.ice.jni.registry.Registry
37  * @see com.ice.jni.registry.RegistryKey
38  */

39
40 abstract public class
41 RegistryValue
42     {
43     public static final int REG_NONE = 0;
44     public static final int REG_SZ = 1;
45     public static final int REG_EXPAND_SZ = 2;
46     public static final int REG_BINARY = 3;
47     public static final int REG_DWORD = 4;
48     public static final int REG_DWORD_LITTLE_ENDIAN = 4;
49     public static final int REG_DWORD_BIG_ENDIAN = 5;
50     public static final int REG_LINK = 6;
51     public static final int REG_MULTI_SZ = 7;
52     public static final int REG_RESOURCE_LIST = 8;
53     public static final int REG_FULL_RESOURCE_DESCRIPTOR = 9;
54     public static final int REG_RESOURCE_REQUIREMENTS_LIST = 10;
55
56     protected static char[] hexChars;
57
58     int type;
59     String JavaDoc name;
60     RegistryKey key;
61     
62     static
63         {
64         RegistryValue.hexChars = new char[20];
65
66         RegistryValue.hexChars[0] = '0';
67         RegistryValue.hexChars[1] = '1';
68         RegistryValue.hexChars[2] = '2';
69         RegistryValue.hexChars[3] = '3';
70         RegistryValue.hexChars[4] = '4';
71         RegistryValue.hexChars[5] = '5';
72         RegistryValue.hexChars[6] = '6';
73         RegistryValue.hexChars[7] = '7';
74         RegistryValue.hexChars[8] = '8';
75         RegistryValue.hexChars[9] = '9';
76         RegistryValue.hexChars[10] = 'a';
77         RegistryValue.hexChars[11] = 'b';
78         RegistryValue.hexChars[12] = 'c';
79         RegistryValue.hexChars[13] = 'd';
80         RegistryValue.hexChars[14] = 'e';
81         RegistryValue.hexChars[15] = 'f';
82         }
83
84     public
85     RegistryValue( RegistryKey key, String JavaDoc name, int type )
86         {
87         this.key = key;
88         this.name = name;
89         this.type = type;
90         }
91
92     public RegistryKey
93     getKey()
94         {
95         return this.key;
96         }
97
98     public String JavaDoc
99     getName()
100         {
101         return this.name;
102         }
103
104     public int
105     getType()
106         {
107         return this.type;
108         }
109
110     public void
111     export( PrintWriter JavaDoc out )
112         {
113         out.print( "\"" + this.getName() + "\"=" );
114         out.println( "\"ERROR called RegistryValue.export()!\"" );
115         }
116
117     public String JavaDoc
118     toString()
119         {
120         return "[type=" + this.type + ",name=" + this.name + "]";
121         }
122
123     public static void
124     exportHexData( PrintWriter JavaDoc out, byte[] data )
125         {
126         int i, cnt;
127         char ch1, ch2;
128         int len = data.length;
129
130         for ( i = 0, cnt = 0 ; i < len ; ++i )
131             {
132             byte dByte = data[i];
133
134             ch2 = RegistryValue.hexChars[ (dByte & 0x0F) ];
135             ch1 = RegistryValue.hexChars[ ((dByte >> 4) & 0x0F) ];
136
137             if ( cnt == 0 ) out.print( " " );
138             
139             out.print( ch1 );
140             out.print( ch2 );
141
142             if ( i < (len - 1) )
143                 out.print( "," );
144             
145             if ( ++cnt > 15 )
146                 {
147                 cnt = 0;
148                 if ( i < (len-1) )
149                     out.println( "\\" );
150                 }
151             }
152
153         out.println( "" );
154         }
155
156     abstract public byte[]
157         getByteData();
158
159     abstract public int
160         getByteLength();
161
162     abstract public void
163         setByteData( byte[] data );
164
165     }
166
167
168
Popular Tags