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:
027: /**
028: * The RegistryValue class represents a value in the registry.
029: * This class is abstract, so it can not be instantiated. The
030: * class is a superclass to all value classes. The common
031: * abstract methods for getting and setting data must be defined
032: * by the subclass, but subclasses will almost always provide
033: * additional methods that get and set the value using the data
034: * type of the subclass.
035: *
036: * @see com.ice.jni.registry.Registry
037: * @see com.ice.jni.registry.RegistryKey
038: */
039:
040: abstract public class RegistryValue {
041: public static final int REG_NONE = 0;
042: public static final int REG_SZ = 1;
043: public static final int REG_EXPAND_SZ = 2;
044: public static final int REG_BINARY = 3;
045: public static final int REG_DWORD = 4;
046: public static final int REG_DWORD_LITTLE_ENDIAN = 4;
047: public static final int REG_DWORD_BIG_ENDIAN = 5;
048: public static final int REG_LINK = 6;
049: public static final int REG_MULTI_SZ = 7;
050: public static final int REG_RESOURCE_LIST = 8;
051: public static final int REG_FULL_RESOURCE_DESCRIPTOR = 9;
052: public static final int REG_RESOURCE_REQUIREMENTS_LIST = 10;
053:
054: protected static char[] hexChars;
055:
056: int type;
057: String name;
058: RegistryKey key;
059:
060: static {
061: RegistryValue.hexChars = new char[20];
062:
063: RegistryValue.hexChars[0] = '0';
064: RegistryValue.hexChars[1] = '1';
065: RegistryValue.hexChars[2] = '2';
066: RegistryValue.hexChars[3] = '3';
067: RegistryValue.hexChars[4] = '4';
068: RegistryValue.hexChars[5] = '5';
069: RegistryValue.hexChars[6] = '6';
070: RegistryValue.hexChars[7] = '7';
071: RegistryValue.hexChars[8] = '8';
072: RegistryValue.hexChars[9] = '9';
073: RegistryValue.hexChars[10] = 'a';
074: RegistryValue.hexChars[11] = 'b';
075: RegistryValue.hexChars[12] = 'c';
076: RegistryValue.hexChars[13] = 'd';
077: RegistryValue.hexChars[14] = 'e';
078: RegistryValue.hexChars[15] = 'f';
079: }
080:
081: public RegistryValue(RegistryKey key, String name, int type) {
082: this .key = key;
083: this .name = name;
084: this .type = type;
085: }
086:
087: public RegistryKey getKey() {
088: return this .key;
089: }
090:
091: public String getName() {
092: return this .name;
093: }
094:
095: public int getType() {
096: return this .type;
097: }
098:
099: public void export(PrintWriter out) {
100: out.print("\"" + this .getName() + "\"=");
101: out.println("\"ERROR called RegistryValue.export()!\"");
102: }
103:
104: public String toString() {
105: return "[type=" + this .type + ",name=" + this .name + "]";
106: }
107:
108: public static void exportHexData(PrintWriter out, byte[] data) {
109: int i, cnt;
110: char ch1, ch2;
111: int len = data.length;
112:
113: for (i = 0, cnt = 0; i < len; ++i) {
114: byte dByte = data[i];
115:
116: ch2 = RegistryValue.hexChars[(dByte & 0x0F)];
117: ch1 = RegistryValue.hexChars[((dByte >> 4) & 0x0F)];
118:
119: if (cnt == 0)
120: out.print(" ");
121:
122: out.print(ch1);
123: out.print(ch2);
124:
125: if (i < (len - 1))
126: out.print(",");
127:
128: if (++cnt > 15) {
129: cnt = 0;
130: if (i < (len - 1))
131: out.println("\\");
132: }
133: }
134:
135: out.println("");
136: }
137:
138: abstract public byte[] getByteData();
139:
140: abstract public int getByteLength();
141:
142: abstract public void setByteData(byte[] data);
143:
144: }
|