Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <osl/mutex.hxx>
21 : #include <osl/diagnose.h>
22 : #include <cppuhelper/queryinterface.hxx>
23 : #include <cppuhelper/weak.hxx>
24 : #include <cppuhelper/implbase1.hxx>
25 : #include <cppuhelper/implbase4.hxx>
26 : #include <cppuhelper/implbase3.hxx>
27 : #include <cppuhelper/implementationentry.hxx>
28 : #include <cppuhelper/supportsservice.hxx>
29 : #include <registry/registry.hxx>
30 : #include <rtl/ref.hxx>
31 :
32 : #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 : #include <com/sun/star/lang/XServiceInfo.hpp>
35 : #include <com/sun/star/lang/XTypeProvider.hpp>
36 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
37 : #include <com/sun/star/lang/XInitialization.hpp>
38 : #include <com/sun/star/container/XEnumerationAccess.hpp>
39 :
40 : using namespace css::uno;
41 : using namespace css::registry;
42 : using namespace css::lang;
43 : using namespace css::container;
44 : using namespace cppu;
45 : using namespace osl;
46 :
47 : namespace {
48 :
49 : class NestedKeyImpl;
50 :
51 : class NestedRegistryImpl : public WeakAggImplHelper4 < XSimpleRegistry, XInitialization, XServiceInfo, XEnumerationAccess >
52 : {
53 : public:
54 : NestedRegistryImpl( );
55 :
56 : virtual ~NestedRegistryImpl();
57 :
58 : // XServiceInfo
59 : virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
60 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
61 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
62 :
63 : // XInitialization
64 : virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
65 : throw(Exception, RuntimeException, std::exception) SAL_OVERRIDE;
66 :
67 : // XSimpleRegistry
68 : virtual OUString SAL_CALL getURL() throw(RuntimeException, std::exception) SAL_OVERRIDE;
69 : virtual void SAL_CALL open( const OUString& rURL, sal_Bool bReadOnly, sal_Bool bCreate ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
70 : virtual sal_Bool SAL_CALL isValid( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
71 : virtual void SAL_CALL close( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
72 : virtual void SAL_CALL destroy( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
73 : virtual Reference< XRegistryKey > SAL_CALL getRootKey( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
74 : virtual sal_Bool SAL_CALL isReadOnly( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
75 : virtual void SAL_CALL mergeKey( const OUString& aKeyName, const OUString& aUrl ) throw(InvalidRegistryException, MergeConflictException, RuntimeException, std::exception) SAL_OVERRIDE;
76 :
77 : // XEnumerationAccess
78 : virtual Reference< XEnumeration > SAL_CALL createEnumeration( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
79 : virtual Type SAL_CALL getElementType( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
80 : virtual sal_Bool SAL_CALL hasElements( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
81 :
82 : friend class NestedKeyImpl;
83 : protected:
84 : Mutex m_mutex;
85 : sal_uInt32 m_state;
86 : Reference<XSimpleRegistry> m_localReg;
87 : Reference<XSimpleRegistry> m_defaultReg;
88 :
89 : };
90 :
91 :
92 : // class NestedKeyImpl the implenetation of interface XRegistryKey
93 :
94 : class NestedKeyImpl : public WeakImplHelper1< XRegistryKey >
95 : {
96 : public:
97 : NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
98 : Reference<XRegistryKey>& localKey,
99 : Reference<XRegistryKey>& defaultKey);
100 :
101 : NestedKeyImpl( const OUString& aKeyName,
102 : NestedKeyImpl* pKey);
103 :
104 : virtual ~NestedKeyImpl();
105 :
106 : // XRegistryKey
107 : virtual OUString SAL_CALL getKeyName() throw(RuntimeException, std::exception) SAL_OVERRIDE;
108 : virtual sal_Bool SAL_CALL isReadOnly( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
109 : virtual sal_Bool SAL_CALL isValid( ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
110 : virtual RegistryKeyType SAL_CALL getKeyType( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
111 : virtual RegistryValueType SAL_CALL getValueType( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
112 : virtual sal_Int32 SAL_CALL getLongValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
113 : virtual void SAL_CALL setLongValue( sal_Int32 value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
114 : virtual Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
115 : virtual void SAL_CALL setLongListValue( const css::uno::Sequence< sal_Int32 >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
116 : virtual OUString SAL_CALL getAsciiValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
117 : virtual void SAL_CALL setAsciiValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
118 : virtual Sequence< OUString > SAL_CALL getAsciiListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
119 : virtual void SAL_CALL setAsciiListValue( const css::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
120 : virtual OUString SAL_CALL getStringValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
121 : virtual void SAL_CALL setStringValue( const OUString& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
122 : virtual Sequence< OUString > SAL_CALL getStringListValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
123 : virtual void SAL_CALL setStringListValue( const css::uno::Sequence< OUString >& seqValue ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
124 : virtual Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception) SAL_OVERRIDE;
125 : virtual void SAL_CALL setBinaryValue( const css::uno::Sequence< sal_Int8 >& value ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
126 : virtual Reference< XRegistryKey > SAL_CALL openKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
127 : virtual Reference< XRegistryKey > SAL_CALL createKey( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
128 : virtual void SAL_CALL closeKey( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
129 : virtual void SAL_CALL deleteKey( const OUString& rKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
130 : virtual Sequence< Reference< XRegistryKey > > SAL_CALL openKeys( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
131 : virtual Sequence< OUString > SAL_CALL getKeyNames( ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
132 : virtual sal_Bool SAL_CALL createLink( const OUString& aLinkName, const OUString& aLinkTarget ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
133 : virtual void SAL_CALL deleteLink( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
134 : virtual OUString SAL_CALL getLinkTarget( const OUString& rLinkName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
135 : virtual OUString SAL_CALL getResolvedName( const OUString& aKeyName ) throw(InvalidRegistryException, RuntimeException, std::exception) SAL_OVERRIDE;
136 :
137 : protected:
138 : void computeChanges();
139 : OUString computeName(const OUString& name);
140 :
141 : OUString m_name;
142 : sal_uInt32 m_state;
143 : NestedRegistryImpl* m_pRegistry;
144 : Reference<XRegistryKey> m_localKey;
145 : Reference<XRegistryKey> m_defaultKey;
146 : };
147 :
148 :
149 :
150 0 : NestedKeyImpl::NestedKeyImpl( NestedRegistryImpl* pDefaultRegistry,
151 : Reference<XRegistryKey>& localKey,
152 : Reference<XRegistryKey>& defaultKey )
153 0 : : m_pRegistry(pDefaultRegistry)
154 : {
155 0 : m_pRegistry->acquire();
156 :
157 0 : m_localKey = localKey;
158 0 : m_defaultKey = defaultKey;
159 :
160 0 : if (m_localKey.is())
161 : {
162 0 : m_name = m_localKey->getKeyName();
163 : }
164 0 : else if (m_defaultKey.is())
165 : {
166 0 : m_name = m_defaultKey->getKeyName();
167 : }
168 :
169 0 : m_state = m_pRegistry->m_state;
170 0 : }
171 :
172 :
173 0 : NestedKeyImpl::NestedKeyImpl( const OUString& rKeyName,
174 : NestedKeyImpl* pKey)
175 0 : : m_pRegistry(pKey->m_pRegistry)
176 : {
177 0 : m_pRegistry->acquire();
178 :
179 0 : if (pKey->m_localKey.is() && pKey->m_localKey->isValid())
180 : {
181 0 : m_localKey = pKey->m_localKey->openKey(rKeyName);
182 : }
183 0 : if (pKey->m_defaultKey.is() && pKey->m_defaultKey->isValid())
184 : {
185 0 : m_defaultKey = pKey->m_defaultKey->openKey(rKeyName);
186 : }
187 :
188 0 : if (m_localKey.is())
189 : {
190 0 : m_name = m_localKey->getKeyName();
191 : }
192 0 : else if (m_defaultKey.is())
193 : {
194 0 : m_name = m_defaultKey->getKeyName();
195 : }
196 :
197 0 : m_state = m_pRegistry->m_state;
198 0 : }
199 :
200 :
201 0 : NestedKeyImpl::~NestedKeyImpl()
202 : {
203 0 : if ( m_pRegistry )
204 0 : m_pRegistry->release();
205 0 : }
206 :
207 :
208 0 : void NestedKeyImpl::computeChanges()
209 : {
210 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
211 0 : if ( m_state != m_pRegistry->m_state )
212 : {
213 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
214 :
215 0 : Reference<XRegistryKey> tmpKey = rootKey->openKey(m_name);
216 :
217 0 : if ( tmpKey.is() )
218 : {
219 0 : m_localKey = rootKey->openKey(m_name);
220 : }
221 :
222 0 : m_state = m_pRegistry->m_state;
223 0 : }
224 0 : }
225 :
226 :
227 : // NestedKey_Impl::computeName()
228 :
229 0 : OUString NestedKeyImpl::computeName(const OUString& name)
230 : {
231 0 : OUString resLocalName, resDefaultName;
232 :
233 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
234 : try
235 : {
236 0 : if ( m_localKey.is() && m_localKey->isValid() )
237 : {
238 0 : resLocalName = m_localKey->getResolvedName(name);
239 : }
240 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
241 : {
242 0 : return m_defaultKey->getResolvedName(name);
243 : }
244 :
245 0 : if ( !resLocalName.isEmpty() && m_pRegistry->m_defaultReg->isValid() )
246 : {
247 0 : Reference<XRegistryKey> localRoot(m_pRegistry->m_localReg->getRootKey());
248 0 : Reference<XRegistryKey> defaultRoot(m_pRegistry->m_defaultReg->getRootKey());
249 :
250 0 : resDefaultName = defaultRoot->getResolvedName(resLocalName);
251 :
252 0 : sal_uInt32 count = 100;
253 :
254 0 : while (resLocalName != resDefaultName && count > 0)
255 : {
256 0 : count--;
257 :
258 0 : if (resLocalName.isEmpty() || resDefaultName.isEmpty())
259 0 : throw InvalidRegistryException();
260 :
261 0 : resLocalName = localRoot->getResolvedName(resDefaultName);
262 0 : resDefaultName = defaultRoot->getResolvedName(resLocalName);
263 0 : }
264 : }
265 : }
266 0 : catch(InvalidRegistryException& )
267 : {
268 : }
269 :
270 0 : return resLocalName;
271 : }
272 :
273 :
274 0 : OUString SAL_CALL NestedKeyImpl::getKeyName() throw(RuntimeException, std::exception)
275 : {
276 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
277 0 : return m_name;
278 : }
279 :
280 :
281 0 : sal_Bool SAL_CALL NestedKeyImpl::isReadOnly( )
282 : throw(InvalidRegistryException, RuntimeException, std::exception)
283 : {
284 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
285 0 : computeChanges();
286 :
287 0 : if ( m_localKey.is() && m_localKey->isValid() )
288 0 : return m_localKey->isReadOnly();
289 : else
290 0 : throw InvalidRegistryException();
291 : }
292 :
293 :
294 0 : sal_Bool SAL_CALL NestedKeyImpl::isValid( ) throw(RuntimeException, std::exception)
295 : {
296 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
297 0 : return ((m_localKey.is() && m_localKey->isValid()) ||
298 0 : (m_defaultKey.is() && m_defaultKey->isValid()) );
299 : }
300 :
301 :
302 0 : RegistryKeyType SAL_CALL NestedKeyImpl::getKeyType( const OUString& rKeyName )
303 : throw(InvalidRegistryException, RuntimeException, std::exception)
304 : {
305 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
306 0 : computeChanges();
307 :
308 0 : if ( m_localKey.is() && m_localKey->isValid() )
309 : {
310 0 : return m_localKey->getKeyType(rKeyName);
311 : }
312 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
313 : {
314 0 : return m_defaultKey->getKeyType(rKeyName);
315 : }
316 :
317 0 : return RegistryKeyType_KEY;
318 : }
319 :
320 :
321 0 : RegistryValueType SAL_CALL NestedKeyImpl::getValueType( )
322 : throw(InvalidRegistryException, RuntimeException, std::exception)
323 : {
324 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
325 0 : computeChanges();
326 :
327 0 : if ( m_localKey.is() && m_localKey->isValid() )
328 : {
329 0 : return m_localKey->getValueType();
330 : }
331 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
332 : {
333 0 : return m_defaultKey->getValueType();
334 : }
335 :
336 0 : return RegistryValueType_NOT_DEFINED;
337 : }
338 :
339 :
340 0 : sal_Int32 SAL_CALL NestedKeyImpl::getLongValue( )
341 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
342 : {
343 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
344 0 : computeChanges();
345 :
346 0 : if ( m_localKey.is() && m_localKey->isValid() )
347 : {
348 0 : return m_localKey->getLongValue();
349 : }
350 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
351 : {
352 0 : return m_defaultKey->getLongValue();
353 : }
354 : else
355 : {
356 0 : throw InvalidRegistryException();
357 0 : }
358 : }
359 :
360 :
361 0 : void SAL_CALL NestedKeyImpl::setLongValue( sal_Int32 value )
362 : throw(InvalidRegistryException, RuntimeException, std::exception)
363 : {
364 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
365 0 : computeChanges();
366 :
367 0 : if ( m_localKey.is() && m_localKey->isValid() )
368 : {
369 0 : m_localKey->setLongValue(value);
370 : }
371 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
372 : {
373 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
374 0 : m_localKey = rootKey->createKey(m_name);
375 0 : m_localKey->setLongValue(value);
376 0 : m_state = m_pRegistry->m_state++;
377 : }
378 : else
379 : {
380 0 : throw InvalidRegistryException();
381 0 : }
382 0 : }
383 :
384 :
385 0 : Sequence< sal_Int32 > SAL_CALL NestedKeyImpl::getLongListValue( )
386 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
387 : {
388 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
389 0 : computeChanges();
390 :
391 0 : if ( m_localKey.is() && m_localKey->isValid() )
392 : {
393 0 : return m_localKey->getLongListValue();
394 : }
395 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
396 : {
397 0 : return m_defaultKey->getLongListValue();
398 : }
399 : else
400 : {
401 0 : throw InvalidRegistryException();
402 0 : }
403 : }
404 :
405 :
406 0 : void SAL_CALL NestedKeyImpl::setLongListValue( const Sequence< sal_Int32 >& seqValue )
407 : throw(InvalidRegistryException, RuntimeException, std::exception)
408 : {
409 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
410 0 : computeChanges();
411 :
412 0 : if ( m_localKey.is() && m_localKey->isValid() )
413 : {
414 0 : m_localKey->setLongListValue(seqValue);
415 : }
416 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
417 : {
418 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
419 0 : m_localKey = rootKey->createKey(m_name);
420 0 : m_localKey->setLongListValue(seqValue);
421 0 : m_state = m_pRegistry->m_state++;
422 : }
423 : else
424 : {
425 0 : throw InvalidRegistryException();
426 0 : }
427 0 : }
428 :
429 :
430 0 : OUString SAL_CALL NestedKeyImpl::getAsciiValue( )
431 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
432 : {
433 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
434 0 : computeChanges();
435 :
436 0 : if ( m_localKey.is() && m_localKey->isValid() )
437 : {
438 0 : return m_localKey->getAsciiValue();
439 : }
440 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
441 : {
442 0 : return m_defaultKey->getAsciiValue();
443 : }
444 : else
445 : {
446 0 : throw InvalidRegistryException();
447 0 : }
448 : }
449 :
450 :
451 0 : void SAL_CALL NestedKeyImpl::setAsciiValue( const OUString& value )
452 : throw(InvalidRegistryException, RuntimeException, std::exception)
453 : {
454 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
455 0 : computeChanges();
456 :
457 0 : if ( m_localKey.is() && m_localKey->isValid() )
458 : {
459 0 : m_localKey->setAsciiValue(value);
460 : }
461 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
462 : {
463 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
464 0 : m_localKey = rootKey->createKey(m_name);
465 0 : m_localKey->setAsciiValue(value);
466 0 : m_state = m_pRegistry->m_state++;
467 : }
468 : else
469 : {
470 0 : throw InvalidRegistryException();
471 0 : }
472 0 : }
473 :
474 :
475 0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getAsciiListValue( )
476 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
477 : {
478 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
479 0 : computeChanges();
480 :
481 0 : if ( m_localKey.is() && m_localKey->isValid() )
482 : {
483 0 : return m_localKey->getAsciiListValue();
484 : }
485 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
486 : {
487 0 : return m_defaultKey->getAsciiListValue();
488 : }
489 : else
490 : {
491 0 : throw InvalidRegistryException();
492 0 : }
493 : }
494 :
495 :
496 0 : void SAL_CALL NestedKeyImpl::setAsciiListValue( const Sequence< OUString >& seqValue )
497 : throw(InvalidRegistryException, RuntimeException, std::exception)
498 : {
499 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
500 0 : computeChanges();
501 :
502 0 : if ( m_localKey.is() && m_localKey->isValid() )
503 : {
504 0 : m_localKey->setAsciiListValue(seqValue);
505 : }
506 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
507 : {
508 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
509 0 : m_localKey = rootKey->createKey(m_name);
510 0 : m_localKey->setAsciiListValue(seqValue);
511 0 : m_state = m_pRegistry->m_state++;
512 : }
513 : else
514 : {
515 0 : throw InvalidRegistryException();
516 0 : }
517 0 : }
518 :
519 :
520 0 : OUString SAL_CALL NestedKeyImpl::getStringValue( )
521 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
522 : {
523 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
524 0 : computeChanges();
525 :
526 0 : if ( m_localKey.is() && m_localKey->isValid() )
527 : {
528 0 : return m_localKey->getStringValue();
529 : }
530 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
531 : {
532 0 : return m_defaultKey->getStringValue();
533 : }
534 : else
535 : {
536 0 : throw InvalidRegistryException();
537 0 : }
538 : }
539 :
540 :
541 0 : void SAL_CALL NestedKeyImpl::setStringValue( const OUString& value )
542 : throw(InvalidRegistryException, RuntimeException, std::exception)
543 : {
544 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
545 0 : computeChanges();
546 :
547 0 : if ( m_localKey.is() && m_localKey->isValid() )
548 : {
549 0 : m_localKey->setStringValue(value);
550 : }
551 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
552 : {
553 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
554 0 : m_localKey = rootKey->createKey(m_name);
555 0 : m_localKey->setStringValue(value);
556 0 : m_state = m_pRegistry->m_state++;
557 : }
558 : else
559 : {
560 0 : throw InvalidRegistryException();
561 0 : }
562 0 : }
563 :
564 :
565 0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getStringListValue( )
566 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
567 : {
568 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
569 0 : computeChanges();
570 :
571 0 : if ( m_localKey.is() && m_localKey->isValid() )
572 : {
573 0 : return m_localKey->getStringListValue();
574 : }
575 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
576 : {
577 0 : return m_defaultKey->getStringListValue();
578 : }
579 : else
580 : {
581 0 : throw InvalidRegistryException();
582 0 : }
583 : }
584 :
585 :
586 0 : void SAL_CALL NestedKeyImpl::setStringListValue( const Sequence< OUString >& seqValue )
587 : throw(InvalidRegistryException, RuntimeException, std::exception)
588 : {
589 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
590 0 : computeChanges();
591 :
592 0 : if ( m_localKey.is() && m_localKey->isValid() )
593 : {
594 0 : m_localKey->setStringListValue(seqValue);
595 : }
596 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
597 : {
598 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
599 0 : m_localKey = rootKey->createKey(m_name);
600 0 : m_localKey->setStringListValue(seqValue);
601 0 : m_state = m_pRegistry->m_state++;
602 : }
603 : else
604 : {
605 0 : throw InvalidRegistryException();
606 0 : }
607 0 : }
608 :
609 :
610 0 : Sequence< sal_Int8 > SAL_CALL NestedKeyImpl::getBinaryValue( )
611 : throw(InvalidRegistryException, InvalidValueException, RuntimeException, std::exception)
612 : {
613 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
614 0 : computeChanges();
615 :
616 0 : if ( m_localKey.is() && m_localKey->isValid() )
617 : {
618 0 : return m_localKey->getBinaryValue();
619 : }
620 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
621 : {
622 0 : return m_defaultKey->getBinaryValue();
623 : }
624 : else
625 : {
626 0 : throw InvalidRegistryException();
627 0 : }
628 : }
629 :
630 :
631 0 : void SAL_CALL NestedKeyImpl::setBinaryValue( const Sequence< sal_Int8 >& value )
632 : throw(InvalidRegistryException, RuntimeException, std::exception)
633 : {
634 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
635 0 : computeChanges();
636 :
637 0 : if ( m_localKey.is() && m_localKey->isValid() )
638 : {
639 0 : m_localKey->setBinaryValue(value);
640 : }
641 0 : else if ( m_defaultKey.is() && m_defaultKey->isValid() )
642 : {
643 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
644 0 : m_localKey = rootKey->createKey(m_name);
645 0 : m_localKey->setBinaryValue(value);
646 0 : m_state = m_pRegistry->m_state++;
647 : }
648 : else
649 : {
650 0 : throw InvalidRegistryException();
651 0 : }
652 0 : }
653 :
654 :
655 0 : Reference< XRegistryKey > SAL_CALL NestedKeyImpl::openKey( const OUString& aKeyName )
656 : throw(InvalidRegistryException, RuntimeException, std::exception)
657 : {
658 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
659 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
660 : {
661 0 : throw InvalidRegistryException();
662 : }
663 :
664 0 : OUString resolvedName = computeName(aKeyName);
665 :
666 0 : if ( resolvedName.isEmpty() )
667 0 : throw InvalidRegistryException();
668 :
669 0 : Reference<XRegistryKey> localKey, defaultKey;
670 :
671 0 : if ( m_localKey.is() && m_localKey->isValid() )
672 : {
673 0 : localKey = m_pRegistry->m_localReg->getRootKey()->openKey(resolvedName);
674 : }
675 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
676 : {
677 0 : defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
678 : }
679 :
680 0 : if ( localKey.is() || defaultKey.is() )
681 : {
682 0 : return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
683 : }
684 : else
685 : {
686 0 : return Reference<XRegistryKey>();
687 0 : }
688 : }
689 :
690 :
691 0 : Reference< XRegistryKey > SAL_CALL NestedKeyImpl::createKey( const OUString& aKeyName )
692 : throw(InvalidRegistryException, RuntimeException, std::exception)
693 : {
694 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
695 0 : if ( (!m_localKey.is() && !m_defaultKey.is()) ||
696 0 : (m_localKey.is() && m_localKey->isReadOnly()) )
697 : {
698 0 : throw InvalidRegistryException();
699 : }
700 :
701 0 : OUString resolvedName = computeName(aKeyName);
702 :
703 0 : if ( resolvedName.isEmpty() )
704 0 : throw InvalidRegistryException();
705 :
706 0 : if ( m_localKey.is() && m_localKey->isValid() )
707 : {
708 0 : Reference<XRegistryKey> localKey, defaultKey;
709 :
710 0 : localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
711 0 : if ( localKey.is() )
712 : {
713 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
714 : {
715 0 : defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
716 : }
717 :
718 0 : m_state = m_pRegistry->m_state++;
719 :
720 0 : return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
721 0 : }
722 : }
723 : else
724 : {
725 0 : Reference<XRegistryKey> localKey, defaultKey;
726 :
727 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
728 : {
729 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
730 0 : m_localKey = rootKey->createKey(m_name);
731 :
732 0 : localKey = m_pRegistry->m_localReg->getRootKey()->createKey(resolvedName);
733 :
734 0 : if ( localKey.is() )
735 : {
736 0 : defaultKey = m_pRegistry->m_defaultReg->getRootKey()->openKey(resolvedName);
737 :
738 0 : m_state = m_pRegistry->m_state++;
739 :
740 0 : return ((XRegistryKey*)new NestedKeyImpl(m_pRegistry, localKey, defaultKey));
741 0 : }
742 0 : }
743 : }
744 :
745 0 : return Reference<XRegistryKey>();
746 : }
747 :
748 :
749 0 : void SAL_CALL NestedKeyImpl::closeKey( )
750 : throw(InvalidRegistryException, RuntimeException, std::exception)
751 : {
752 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
753 0 : if ( m_localKey.is() && m_localKey->isValid() )
754 : {
755 0 : m_localKey->closeKey();
756 : }
757 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
758 : {
759 0 : m_defaultKey->closeKey();
760 0 : }
761 0 : }
762 :
763 :
764 0 : void SAL_CALL NestedKeyImpl::deleteKey( const OUString& rKeyName )
765 : throw(InvalidRegistryException, RuntimeException, std::exception)
766 : {
767 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
768 0 : if ( m_localKey.is() && m_localKey->isValid() &&
769 0 : !m_localKey->isReadOnly() )
770 : {
771 0 : OUString resolvedName = computeName(rKeyName);
772 :
773 0 : if ( resolvedName.isEmpty() )
774 : {
775 0 : throw InvalidRegistryException();
776 : }
777 :
778 0 : m_pRegistry->m_localReg->getRootKey()->deleteKey(resolvedName);
779 : }
780 : else
781 : {
782 0 : throw InvalidRegistryException();
783 0 : }
784 0 : }
785 :
786 :
787 0 : Sequence< Reference< XRegistryKey > > SAL_CALL NestedKeyImpl::openKeys( )
788 : throw(InvalidRegistryException, RuntimeException, std::exception)
789 : {
790 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
791 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
792 : {
793 0 : throw InvalidRegistryException();
794 : }
795 :
796 0 : Sequence<OUString> localSeq, defaultSeq;
797 :
798 0 : if ( m_localKey.is() && m_localKey->isValid() )
799 : {
800 0 : localSeq = m_localKey->getKeyNames();
801 : }
802 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
803 : {
804 0 : defaultSeq = m_defaultKey->getKeyNames();
805 : }
806 :
807 0 : sal_uInt32 local = localSeq.getLength();
808 0 : sal_uInt32 def = defaultSeq.getLength();
809 0 : sal_uInt32 len = 0;
810 :
811 : sal_uInt32 i, j;
812 0 : for (i=0; i < local; i++)
813 : {
814 0 : for (j=0 ; j < def; j++)
815 : {
816 0 : if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
817 : {
818 0 : len++;
819 0 : break;
820 : }
821 : }
822 : }
823 :
824 0 : Sequence< Reference<XRegistryKey> > retSeq(local + def - len);
825 0 : bool insert = true;
826 0 : OUString name;
827 : sal_Int32 lastIndex;
828 :
829 0 : for (i=0; i < local; i++)
830 : {
831 0 : name = localSeq.getConstArray()[i];
832 0 : lastIndex = name.lastIndexOf('/');
833 0 : name = name.copy(lastIndex);
834 0 : retSeq.getArray()[i] =
835 0 : (XRegistryKey*)new NestedKeyImpl(name, this);
836 : }
837 :
838 0 : sal_uInt32 k = local;
839 0 : for (i=0; i < def; i++)
840 : {
841 0 : insert = true;
842 :
843 0 : for (j=0 ; j < local; j++)
844 : {
845 0 : if ( retSeq.getConstArray()[j]->getKeyName()
846 0 : == defaultSeq.getConstArray()[i] )
847 : {
848 0 : insert = false;
849 0 : break;
850 : }
851 : }
852 :
853 0 : if ( insert )
854 : {
855 0 : name = defaultSeq.getConstArray()[i];
856 0 : lastIndex = name.lastIndexOf('/');
857 0 : name = name.copy(lastIndex);
858 0 : retSeq.getArray()[k++] =
859 0 : (XRegistryKey*)new NestedKeyImpl(name, this);
860 : }
861 : }
862 :
863 0 : return retSeq;
864 : }
865 :
866 :
867 0 : Sequence< OUString > SAL_CALL NestedKeyImpl::getKeyNames( )
868 : throw(InvalidRegistryException, RuntimeException, std::exception)
869 : {
870 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
871 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
872 : {
873 0 : throw InvalidRegistryException();
874 : }
875 :
876 0 : Sequence<OUString> localSeq, defaultSeq;
877 :
878 0 : if ( m_localKey.is() && m_localKey->isValid() )
879 : {
880 0 : localSeq = m_localKey->getKeyNames();
881 : }
882 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
883 : {
884 0 : defaultSeq = m_defaultKey->getKeyNames();
885 : }
886 :
887 0 : sal_uInt32 local = localSeq.getLength();
888 0 : sal_uInt32 def = defaultSeq.getLength();
889 0 : sal_uInt32 len = 0;
890 :
891 : sal_uInt32 i, j;
892 0 : for (i=0; i < local; i++)
893 : {
894 0 : for (j=0 ; j < def; j++)
895 : {
896 0 : if ( localSeq.getConstArray()[i] == defaultSeq.getConstArray()[j] )
897 : {
898 0 : len++;
899 0 : break;
900 : }
901 : }
902 : }
903 :
904 0 : Sequence<OUString> retSeq(local + def - len);
905 0 : bool insert = true;
906 :
907 0 : for (i=0; i < local; i++)
908 : {
909 0 : retSeq.getArray()[i] = localSeq.getConstArray()[i];
910 : }
911 :
912 0 : sal_uInt32 k = local;
913 0 : for (i=0; i < def; i++)
914 : {
915 0 : insert = true;
916 :
917 0 : for (j=0 ; j < local; j++)
918 : {
919 0 : if ( retSeq.getConstArray()[j] == defaultSeq.getConstArray()[i] )
920 : {
921 0 : insert = false;
922 0 : break;
923 : }
924 : }
925 :
926 0 : if ( insert )
927 0 : retSeq.getArray()[k++] = defaultSeq.getConstArray()[i];
928 : }
929 :
930 0 : return retSeq;
931 : }
932 :
933 :
934 0 : sal_Bool SAL_CALL NestedKeyImpl::createLink( const OUString& aLinkName, const OUString& aLinkTarget )
935 : throw(InvalidRegistryException, RuntimeException, std::exception)
936 : {
937 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
938 :
939 0 : bool isCreated = false;
940 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
941 : {
942 0 : throw InvalidRegistryException();
943 : }
944 :
945 0 : OUString linkName;
946 0 : OUString resolvedName;
947 0 : sal_Int32 lastIndex = aLinkName.lastIndexOf('/');
948 :
949 0 : if ( lastIndex > 0 )
950 : {
951 0 : linkName = aLinkName.copy(0, lastIndex);
952 :
953 0 : resolvedName = computeName(linkName);
954 :
955 0 : if ( resolvedName.isEmpty() )
956 : {
957 0 : throw InvalidRegistryException();
958 : }
959 :
960 0 : resolvedName = resolvedName + aLinkName.copy(lastIndex);
961 : }
962 : else
963 : {
964 0 : if ( lastIndex == 0 )
965 0 : resolvedName = m_name + aLinkName;
966 : else
967 0 : resolvedName = m_name + "/" + aLinkName;
968 : }
969 :
970 0 : if ( m_localKey.is() && m_localKey->isValid() )
971 : {
972 0 : isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
973 : }
974 : else
975 : {
976 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
977 : {
978 0 : Reference<XRegistryKey> rootKey(m_pRegistry->m_localReg->getRootKey());
979 0 : m_localKey = rootKey->createKey(m_name);
980 :
981 0 : isCreated = m_pRegistry->m_localReg->getRootKey()->createLink(resolvedName, aLinkTarget);
982 : }
983 : }
984 :
985 0 : if ( isCreated )
986 0 : m_state = m_pRegistry->m_state++;
987 :
988 0 : return isCreated;
989 : }
990 :
991 :
992 0 : void SAL_CALL NestedKeyImpl::deleteLink( const OUString& rLinkName )
993 : throw(InvalidRegistryException, RuntimeException, std::exception)
994 : {
995 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
996 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
997 : {
998 0 : throw InvalidRegistryException();
999 : }
1000 :
1001 0 : OUString linkName;
1002 0 : OUString resolvedName;
1003 0 : sal_Int32 lastIndex = rLinkName.lastIndexOf('/');
1004 :
1005 0 : if ( lastIndex > 0 )
1006 : {
1007 0 : linkName = rLinkName.copy(0, lastIndex);
1008 :
1009 0 : resolvedName = computeName(linkName);
1010 :
1011 0 : if ( resolvedName.isEmpty() )
1012 : {
1013 0 : throw InvalidRegistryException();
1014 : }
1015 :
1016 0 : resolvedName = resolvedName + rLinkName.copy(lastIndex);
1017 : }
1018 : else
1019 : {
1020 0 : if ( lastIndex == 0 )
1021 0 : resolvedName = m_name + rLinkName;
1022 : else
1023 0 : resolvedName = m_name + "/" + rLinkName;
1024 : }
1025 :
1026 0 : if ( m_localKey.is() && m_localKey->isValid() &&
1027 0 : !m_localKey->isReadOnly() )
1028 : {
1029 0 : m_pRegistry->m_localReg->getRootKey()->deleteLink(resolvedName);
1030 : }
1031 : else
1032 : {
1033 0 : throw InvalidRegistryException();
1034 0 : }
1035 0 : }
1036 :
1037 :
1038 0 : OUString SAL_CALL NestedKeyImpl::getLinkTarget( const OUString& rLinkName )
1039 : throw(InvalidRegistryException, RuntimeException, std::exception)
1040 : {
1041 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1042 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
1043 : {
1044 0 : throw InvalidRegistryException();
1045 : }
1046 :
1047 0 : OUString linkName;
1048 0 : OUString resolvedName;
1049 0 : sal_Int32 lastIndex = rLinkName.lastIndexOf('/');
1050 :
1051 0 : if ( lastIndex > 0 )
1052 : {
1053 0 : linkName = rLinkName.copy(0, lastIndex);
1054 :
1055 0 : resolvedName = computeName(linkName);
1056 :
1057 0 : if ( resolvedName.isEmpty() )
1058 : {
1059 0 : throw InvalidRegistryException();
1060 : }
1061 :
1062 0 : resolvedName = resolvedName + rLinkName.copy(lastIndex);
1063 : }
1064 : else
1065 : {
1066 0 : if ( lastIndex == 0 )
1067 0 : resolvedName = m_name + rLinkName;
1068 : else
1069 0 : resolvedName = m_name + "/" + rLinkName;
1070 : }
1071 :
1072 0 : OUString linkTarget;
1073 0 : if ( m_localKey.is() && m_localKey->isValid() )
1074 : {
1075 : try
1076 : {
1077 0 : linkTarget = m_pRegistry->m_localReg->getRootKey()->getLinkTarget(resolvedName);
1078 0 : return linkTarget;
1079 : }
1080 0 : catch(InvalidRegistryException& )
1081 : {
1082 : }
1083 : }
1084 :
1085 0 : if ( m_defaultKey.is() && m_defaultKey->isValid() )
1086 0 : linkTarget = m_pRegistry->m_defaultReg->getRootKey()->getLinkTarget(resolvedName);
1087 :
1088 0 : return linkTarget;
1089 : }
1090 :
1091 :
1092 0 : OUString SAL_CALL NestedKeyImpl::getResolvedName( const OUString& aKeyName )
1093 : throw(InvalidRegistryException, RuntimeException, std::exception)
1094 : {
1095 0 : Guard< Mutex > aGuard( m_pRegistry->m_mutex );
1096 0 : if ( !m_localKey.is() && !m_defaultKey.is() )
1097 : {
1098 0 : throw InvalidRegistryException();
1099 : }
1100 :
1101 0 : OUString resolvedName = computeName(aKeyName);
1102 :
1103 0 : if ( resolvedName.isEmpty() )
1104 : {
1105 0 : throw InvalidRegistryException();
1106 : }
1107 :
1108 0 : return resolvedName;
1109 : }
1110 :
1111 :
1112 :
1113 : // DefaultRegistry Implementation
1114 :
1115 :
1116 0 : NestedRegistryImpl::NestedRegistryImpl( )
1117 0 : : m_state(0)
1118 0 : {}
1119 :
1120 :
1121 0 : NestedRegistryImpl::~NestedRegistryImpl() {}
1122 :
1123 0 : class RegistryEnumueration : public WeakImplHelper1< XEnumeration >
1124 : {
1125 : public:
1126 0 : RegistryEnumueration(
1127 : const Reference< XSimpleRegistry > &r1,
1128 : const Reference< XSimpleRegistry > &r2 )
1129 0 : : m_xReg1( r1 ) , m_xReg2( r2 )
1130 0 : {}
1131 : public:
1132 : virtual sal_Bool SAL_CALL hasMoreElements( ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
1133 : virtual Any SAL_CALL nextElement( ) throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception) SAL_OVERRIDE;
1134 :
1135 : private:
1136 : Reference< XSimpleRegistry > m_xReg1;
1137 : Reference< XSimpleRegistry > m_xReg2;
1138 : };
1139 :
1140 0 : sal_Bool RegistryEnumueration::hasMoreElements( ) throw (RuntimeException, std::exception)
1141 : {
1142 0 : return m_xReg1.is() || m_xReg2.is();
1143 : }
1144 :
1145 0 : Any RegistryEnumueration::nextElement( )
1146 : throw (NoSuchElementException, WrappedTargetException, RuntimeException, std::exception)
1147 : {
1148 0 : Any a;
1149 0 : if( m_xReg1.is() )
1150 : {
1151 0 : a <<= m_xReg1;
1152 0 : m_xReg1.clear();
1153 : }
1154 0 : else if( m_xReg2.is() )
1155 : {
1156 0 : a <<= m_xReg2;
1157 0 : m_xReg2.clear();
1158 : }
1159 : else
1160 : {
1161 0 : throw NoSuchElementException( "NestedRegistry: no nextElement() !" );
1162 : }
1163 0 : return a;
1164 : }
1165 :
1166 :
1167 0 : Reference< XEnumeration > NestedRegistryImpl::createEnumeration( ) throw (RuntimeException, std::exception)
1168 : {
1169 0 : MutexGuard guard( m_mutex );
1170 0 : return new RegistryEnumueration( m_localReg, m_defaultReg );
1171 : }
1172 :
1173 0 : Type NestedRegistryImpl::getElementType( ) throw (RuntimeException, std::exception)
1174 : {
1175 0 : return getCppuType( &m_localReg );
1176 : }
1177 :
1178 0 : sal_Bool SAL_CALL NestedRegistryImpl::hasElements( ) throw (RuntimeException, std::exception)
1179 : {
1180 0 : MutexGuard guard( m_mutex );
1181 0 : return m_localReg.is() || m_defaultReg.is();
1182 : }
1183 :
1184 :
1185 :
1186 :
1187 0 : OUString SAL_CALL NestedRegistryImpl::getImplementationName( )
1188 : throw(RuntimeException, std::exception)
1189 : {
1190 0 : return OUString("com.sun.star.comp.stoc.NestedRegistry");
1191 : }
1192 :
1193 0 : sal_Bool SAL_CALL NestedRegistryImpl::supportsService( const OUString& ServiceName )
1194 : throw(RuntimeException, std::exception)
1195 : {
1196 0 : return cppu::supportsService(this, ServiceName);
1197 : }
1198 :
1199 0 : Sequence<OUString> SAL_CALL NestedRegistryImpl::getSupportedServiceNames( )
1200 : throw(RuntimeException, std::exception)
1201 : {
1202 0 : Sequence< OUString > seqNames(1);
1203 0 : seqNames[0] = "com.sun.star.registry.NestedRegistry";
1204 0 : return seqNames;
1205 : }
1206 :
1207 :
1208 0 : void SAL_CALL NestedRegistryImpl::initialize( const Sequence< Any >& aArguments )
1209 : throw( Exception, RuntimeException, std::exception )
1210 : {
1211 0 : Guard< Mutex > aGuard( m_mutex );
1212 0 : if ( (aArguments.getLength() == 2) &&
1213 0 : (aArguments[0].getValueType().getTypeClass() == TypeClass_INTERFACE) &&
1214 0 : (aArguments[1].getValueType().getTypeClass() == TypeClass_INTERFACE) )
1215 : {
1216 0 : aArguments[0] >>= m_localReg;
1217 0 : aArguments[1] >>= m_defaultReg;
1218 0 : if ( m_localReg == m_defaultReg )
1219 0 : m_defaultReg.clear();
1220 0 : }
1221 0 : }
1222 :
1223 :
1224 0 : OUString SAL_CALL NestedRegistryImpl::getURL() throw(RuntimeException, std::exception)
1225 : {
1226 0 : Guard< Mutex > aGuard( m_mutex );
1227 : try
1228 : {
1229 0 : if ( m_localReg.is() && m_localReg->isValid() )
1230 0 : return m_localReg->getURL();
1231 : }
1232 0 : catch(InvalidRegistryException& )
1233 : {
1234 : }
1235 :
1236 0 : return OUString();
1237 : }
1238 :
1239 :
1240 0 : void SAL_CALL NestedRegistryImpl::open( const OUString&, sal_Bool, sal_Bool )
1241 : throw(InvalidRegistryException, RuntimeException, std::exception)
1242 : {
1243 : throw InvalidRegistryException(
1244 0 : "the 'open' method is not specified for a nested registry" );
1245 : }
1246 :
1247 :
1248 0 : sal_Bool SAL_CALL NestedRegistryImpl::isValid( ) throw(RuntimeException, std::exception)
1249 : {
1250 0 : Guard< Mutex > aGuard( m_mutex );
1251 : try
1252 : {
1253 0 : if ( (m_localReg.is() && m_localReg->isValid()) ||
1254 0 : (m_defaultReg.is() && m_defaultReg->isValid()) )
1255 0 : return sal_True;
1256 : }
1257 0 : catch(InvalidRegistryException& )
1258 : {
1259 : }
1260 :
1261 0 : return sal_False;
1262 : }
1263 :
1264 :
1265 0 : void SAL_CALL NestedRegistryImpl::close( )
1266 : throw(InvalidRegistryException, RuntimeException, std::exception)
1267 : {
1268 0 : Guard< Mutex > aGuard( m_mutex );
1269 0 : if ( m_localReg.is() && m_localReg->isValid() )
1270 : {
1271 0 : m_localReg->close();
1272 : }
1273 0 : if ( m_defaultReg.is() && m_defaultReg->isValid() )
1274 : {
1275 0 : m_defaultReg->close();
1276 0 : }
1277 0 : }
1278 :
1279 :
1280 0 : void SAL_CALL NestedRegistryImpl::destroy( )
1281 : throw(InvalidRegistryException, RuntimeException, std::exception)
1282 : {
1283 : throw InvalidRegistryException(
1284 0 : "the 'destroy' method is not specified for a nested registry" );
1285 : }
1286 :
1287 :
1288 0 : Reference< XRegistryKey > SAL_CALL NestedRegistryImpl::getRootKey( )
1289 : throw(InvalidRegistryException, RuntimeException, std::exception)
1290 : {
1291 0 : Reference<XRegistryKey> tmpKey;
1292 :
1293 0 : Guard< Mutex > aGuard( m_mutex );
1294 0 : if ( m_localReg.is() && m_localReg->isValid() )
1295 : {
1296 0 : Reference<XRegistryKey> localKey, defaultKey;
1297 :
1298 0 : localKey = m_localReg->getRootKey();
1299 :
1300 0 : if ( localKey.is() )
1301 : {
1302 0 : if ( m_defaultReg.is() && m_defaultReg->isValid() )
1303 : {
1304 0 : defaultKey = m_defaultReg->getRootKey();
1305 : }
1306 :
1307 0 : return ((XRegistryKey*)new NestedKeyImpl(this, localKey, defaultKey));
1308 0 : }
1309 : }
1310 : else
1311 : {
1312 0 : throw InvalidRegistryException();
1313 : }
1314 :
1315 0 : return Reference<XRegistryKey>();
1316 : }
1317 :
1318 :
1319 0 : sal_Bool SAL_CALL NestedRegistryImpl::isReadOnly( )
1320 : throw(InvalidRegistryException, RuntimeException, std::exception)
1321 : {
1322 0 : Guard< Mutex > aGuard( m_mutex );
1323 : try
1324 : {
1325 0 : if ( m_localReg.is() && m_localReg->isValid() )
1326 0 : return m_localReg->isReadOnly();
1327 : }
1328 0 : catch(InvalidRegistryException& )
1329 : {
1330 : }
1331 :
1332 0 : return sal_False;
1333 : }
1334 :
1335 :
1336 0 : void SAL_CALL NestedRegistryImpl::mergeKey( const OUString& aKeyName, const OUString& aUrl )
1337 : throw(InvalidRegistryException, MergeConflictException, RuntimeException, std::exception)
1338 : {
1339 0 : Guard< Mutex > aGuard( m_mutex );
1340 0 : if ( m_localReg.is() && m_localReg->isValid() )
1341 : {
1342 0 : m_localReg->mergeKey(aKeyName, aUrl);
1343 :
1344 0 : m_state++;
1345 0 : }
1346 0 : }
1347 :
1348 : } // namespace
1349 :
1350 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
1351 0 : com_sun_star_comp_stoc_NestedRegistry_get_implementation(
1352 : SAL_UNUSED_PARAMETER css::uno::XComponentContext *,
1353 : css::uno::Sequence<css::uno::Any> const &)
1354 : {
1355 0 : return cppu::acquire(new NestedRegistryImpl);
1356 : }
1357 :
1358 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|