summaryrefslogtreecommitdiff
path: root/jut/com/sun/star/tools/uno/RegistryKey.java
blob: 136233aceb37c5dc9a38736a7aa23ee28066b343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: RegistryKey.java,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-07 19:20:49 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

package com.sun.star.tools.uno;


import java.util.Enumeration;
import java.util.Hashtable;


import com.sun.star.registry.InvalidRegistryException;
import com.sun.star.registry.InvalidValueException;
import com.sun.star.registry.RegistryKeyType;
import com.sun.star.registry.RegistryValueType;
import com.sun.star.registry.XRegistryKey;


/**
 * This is a dummy registry implementation,
 * which only implmenets the needed methods.
 */
class RegistryKey implements XRegistryKey {
    protected RegistryValueType _registryValueType = RegistryValueType.NOT_DEFINED;

    protected String    _name;
    protected Hashtable _keys = new Hashtable();

    protected int    _long;
    protected int    _long_list[];
    protected String _ascii;
    protected String _ascii_list[];
    protected String _string;
    protected String _string_list[];
    protected byte   _binary[];

    public RegistryKey(String name) {
        _name = name;
    }


    // XRegistryKey Attributes
    public String getKeyName() throws com.sun.star.uno.RuntimeException {
        return _name;
    }

    // XRegistryKey Methods
    public boolean isReadOnly() throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return false;
    }

    public boolean isValid() throws com.sun.star.uno.RuntimeException {
        return true;
    }

    public RegistryKeyType getKeyType( /*IN*/String rKeyName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return RegistryKeyType.KEY;
    }

    public RegistryValueType getValueType() throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return _registryValueType;
    }

    public int getLongValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException {
        if(_registryValueType != RegistryValueType.LONG)
            throw new InvalidValueException("long");

        return _long;
    }

    public void setLongValue( /*IN*/int value ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.LONG;

        _long = value;
    }

    public int[] getLongListValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException {
        if(_registryValueType != RegistryValueType.LONGLIST)
            throw new InvalidValueException("longlist");

        return _long_list;
    }

    public void setLongListValue( /*IN*/int[] seqValue ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.LONGLIST;

        _long_list = seqValue;
    }

    public String getAsciiValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException {
        if(_registryValueType != RegistryValueType.ASCII)
            throw new InvalidValueException("ascii");

        return _ascii;
    }

    public void setAsciiValue( /*IN*/String value ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.ASCII;

        _ascii = value;
    }

    public String[] getAsciiListValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException  {
        if(_registryValueType != RegistryValueType.ASCIILIST)
            throw new InvalidValueException("asciilist");

        return _ascii_list;
    }

    public void setAsciiListValue( /*IN*/String[] seqValue ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.ASCIILIST;

        _ascii_list = seqValue;
    }

    public String getStringValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException  {
        if(_registryValueType != RegistryValueType.STRING)
            throw new InvalidValueException("string");

        return _string;
    }

    public void setStringValue( /*IN*/String value ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.STRING;

        _string = value;
    }

    public String[] getStringListValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException {
        if(_registryValueType != RegistryValueType.STRINGLIST)
            throw new InvalidValueException("string_list");

        return _string_list;
    }

    public void setStringListValue( /*IN*/String[] seqValue ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.STRINGLIST;

        _string_list = seqValue;
    }

    public byte[] getBinaryValue() throws InvalidRegistryException, InvalidValueException, com.sun.star.uno.RuntimeException {
        if(_registryValueType != RegistryValueType.BINARY)
            throw new InvalidValueException("longlist");

        return _binary;
    }

    public void setBinaryValue( /*IN*/byte[] value ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _registryValueType = RegistryValueType.BINARY;

        _binary = value;
    }

    public XRegistryKey openKey( /*IN*/String aKeyName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return (XRegistryKey)_keys.get(aKeyName);
    }

    public XRegistryKey createKey( /*IN*/String aKeyName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        XRegistryKey xRegistryKey = openKey(aKeyName);

        if(xRegistryKey == null) {
            xRegistryKey = new RegistryKey(aKeyName);
            _keys.put(aKeyName, xRegistryKey);
        }

        return xRegistryKey;
    }

    public void closeKey() throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
    }

    public void deleteKey( /*IN*/String rKeyName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        _keys.remove(rKeyName);
    }

    public synchronized XRegistryKey[] openKeys() throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        RegistryKey registryKeys[] = new RegistryKey[_keys.size()];

        Enumeration elements = _keys.elements();
        int i = 0;
        while(elements.hasMoreElements()) {
            registryKeys[i ++] = (RegistryKey)elements.nextElement();
        }

        return registryKeys;
    }

    public synchronized String[] getKeyNames() throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        String strings[] = new String[_keys.size()];

        Enumeration elements = _keys.keys();
        int i = 0;
        while(elements.hasMoreElements()) {
            strings[i ++] = (String)elements.nextElement();
        }

        return strings;
    }

    public boolean createLink( /*IN*/String aLinkName, /*IN*/String aLinkTarget ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return false;
    }

    public void deleteLink( /*IN*/String rLinkName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
    }

    public String getLinkTarget( /*IN*/String rLinkName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return null;
    }

    public String getResolvedName( /*IN*/String aKeyName ) throws InvalidRegistryException, com.sun.star.uno.RuntimeException {
        return null;
    }
}