KickJava   Java API By Example, From Geeks To Geeks.

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


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 import com.ice.text.HexNumberFormat;
27
28
29 /**
30  * The RegDWordValue class represents a double word, or
31  * integer, value in the registry (REG_DWORD).
32  *
33  * @see com.ice.jni.registry.Registry
34  * @see com.ice.jni.registry.RegistryKey
35  */

36
37 public class
38 RegDWordValue extends RegistryValue
39     {
40     int data;
41     int dataLen;
42
43     public
44     RegDWordValue( RegistryKey key, String JavaDoc name )
45         {
46         super( key, name, RegistryValue.REG_DWORD );
47         this.data = 0;
48         this.dataLen = 0;
49         }
50
51     public
52     RegDWordValue( RegistryKey key, String JavaDoc name, int type )
53         {
54         super( key, name, type );
55         this.data = 0;
56         this.dataLen = 0;
57         }
58
59     public
60     RegDWordValue( RegistryKey key, String JavaDoc name, int type, int data )
61         {
62         super( key, name, RegistryValue.REG_DWORD );
63         this.setData( data );
64         }
65
66     public int
67     getData()
68         {
69         return this.data;
70         }
71
72     public int
73     getLength()
74         {
75         return this.dataLen;
76         }
77
78     public void
79     setData( int data )
80         {
81         this.data = data;
82         this.dataLen = 1;
83         }
84
85     public byte[]
86     getByteData()
87         {
88         byte[] result = new byte[4];
89
90         result[0] = (byte) ( (this.data >> 24) & 255 );
91         result[1] = (byte) ( (this.data >> 16) & 255 );
92         result[2] = (byte) ( (this.data >> 8) & 255 );
93         result[3] = (byte) ( this.data & 255 );
94
95         return result;
96         }
97
98     public int
99     getByteLength()
100         {
101         return 4;
102         }
103
104     public void
105     setByteData( byte[] data )
106         {
107         int newValue =
108               ( (((int) data[0]) << 24) & 0xFF000000 )
109             | ( (((int) data[1]) << 16) & 0x00FF0000 )
110             | ( (((int) data[2]) << 8) & 0x0000FF00 )
111             | ( ((int) data[3]) & 0x000000FF );
112
113         this.setData( newValue );
114         }
115
116     public void
117     export( PrintWriter JavaDoc out )
118         {
119         out.print( "\"" + this.getName() + "\"=" );
120
121         HexNumberFormat nFmt =
122             new HexNumberFormat( "xxxxxxxx" );
123
124         out.println( "dword:" + nFmt.format( this.getData() ) );
125         }
126
127     }
128
129
130
131
132
Popular Tags