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