001: /*
002: ** Java native interface to the Windows Registry API.
003: ** Copyright (c) 1997 by Timothy Gerard Endres
004: **
005: ** This program is free software.
006: **
007: ** You may redistribute it and/or modify it under the terms of the GNU
008: ** General Public License as published by the Free Software Foundation.
009: ** Version 2 of the license should be included with this distribution in
010: ** the file LICENSE, as well as License.html. If the license is not
011: ** included with this distribution, you may find a copy at the FSF web
012: ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
013: ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
014: **
015: ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
016: ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
017: ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
018: ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
019: ** REDISTRIBUTION OF THIS SOFTWARE.
020: **
021: */
022:
023: package com.ice.jni.registry;
024:
025: import java.io.PrintWriter;
026: import com.ice.text.HexNumberFormat;
027:
028: /**
029: * The RegDWordValue class represents a double word, or
030: * integer, value in the registry (REG_DWORD).
031: *
032: * @see com.ice.jni.registry.Registry
033: * @see com.ice.jni.registry.RegistryKey
034: */
035:
036: public class RegDWordValue extends RegistryValue {
037: int data;
038: int dataLen;
039:
040: public RegDWordValue(RegistryKey key, String name) {
041: super (key, name, RegistryValue.REG_DWORD);
042: this .data = 0;
043: this .dataLen = 0;
044: }
045:
046: public RegDWordValue(RegistryKey key, String name, int type) {
047: super (key, name, type);
048: this .data = 0;
049: this .dataLen = 0;
050: }
051:
052: public RegDWordValue(RegistryKey key, String name, int type,
053: int data) {
054: super (key, name, RegistryValue.REG_DWORD);
055: this .setData(data);
056: }
057:
058: public int getData() {
059: return this .data;
060: }
061:
062: public int getLength() {
063: return this .dataLen;
064: }
065:
066: public void setData(int data) {
067: this .data = data;
068: this .dataLen = 1;
069: }
070:
071: public byte[] getByteData() {
072: byte[] result = new byte[4];
073:
074: result[0] = (byte) ((this .data >> 24) & 255);
075: result[1] = (byte) ((this .data >> 16) & 255);
076: result[2] = (byte) ((this .data >> 8) & 255);
077: result[3] = (byte) (this .data & 255);
078:
079: return result;
080: }
081:
082: public int getByteLength() {
083: return 4;
084: }
085:
086: public void setByteData(byte[] data) {
087: int newValue = ((((int) data[0]) << 24) & 0xFF000000)
088: | ((((int) data[1]) << 16) & 0x00FF0000)
089: | ((((int) data[2]) << 8) & 0x0000FF00)
090: | (((int) data[3]) & 0x000000FF);
091:
092: this .setData(newValue);
093: }
094:
095: public void export(PrintWriter out) {
096: out.print("\"" + this .getName() + "\"=");
097:
098: HexNumberFormat nFmt = new HexNumberFormat("xxxxxxxx");
099:
100: out.println("dword:" + nFmt.format(this.getData()));
101: }
102:
103: }
|