Bug Summary

File:stoc/source/implementationregistration/implreg.cxx
Location:line 1716, column 29
Description:Called C++ object pointer is null

Annotated 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 <stdlib.h>
21#include <string.h>
22#include <list>
23
24#include <unistd.h>
25#include <cppuhelper/queryinterface.hxx>
26#include <cppuhelper/factory.hxx>
27#include <cppuhelper/weak.hxx>
28#include <cppuhelper/servicefactory.hxx>
29#include <cppuhelper/implbase3.hxx>
30#include <cppuhelper/implementationentry.hxx>
31
32#include <uno/mapping.hxx>
33#include <osl/thread.h>
34
35#include <rtl/ustring.hxx>
36#include <rtl/ustrbuf.hxx>
37#include <rtl/strbuf.hxx>
38#include <osl/process.h>
39
40#include <com/sun/star/lang/XServiceInfo.hpp>
41#include <com/sun/star/lang/XInitialization.hpp>
42#include <com/sun/star/loader/XImplementationLoader.hpp>
43#include <com/sun/star/registry/XImplementationRegistration2.hpp>
44#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
45#include <com/sun/star/reflection/XServiceTypeDescription.hpp>
46#include <com/sun/star/beans/XPropertySet.hpp>
47#include "com/sun/star/uno/RuntimeException.hpp"
48
49#include "mergekeys.hxx"
50
51#if defined(SAL_W32)
52#include <io.h>
53#endif
54
55#define OUSTR(x)::rtl::OUString( (&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof
((x)[0]))-1)), (((rtl_TextEncoding) 11)) )
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x)(&(x)[0]), ((sal_Int32)((sizeof (x) / sizeof ((x)[0]))-1)
), (((rtl_TextEncoding) 11))
)
56
57
58using namespace com::sun::star;
59using namespace com::sun::star::uno;
60using namespace com::sun::star::loader;
61using namespace com::sun::star::beans;
62using namespace com::sun::star::lang;
63using namespace com::sun::star::registry;
64using namespace cppu;
65using namespace osl;
66
67using ::rtl::OUString;
68using ::rtl::OUStringBuffer;
69#define IMPLNAME"com.sun.star.comp.stoc.ImplementationRegistration" "com.sun.star.comp.stoc.ImplementationRegistration"
70#define SERVICENAME"com.sun.star.registry.ImplementationRegistration" "com.sun.star.registry.ImplementationRegistration"
71namespace stoc_impreg
72{
73struct StringPool
74{
75 OUString sImplementationName;
76 OUString sServiceName;
77 OUString TMP;
78 OUString TEMP;
79 OUString slash_UNO_slash_REGISTRY_LINKS;
80 OUString slash_IMPLEMENTATIONS;
81 OUString slash_UNO;
82 OUString slash_UNO_slash_SERVICES;
83 OUString slash_UNO_slash_SINGLETONS;
84 OUString slash_SERVICES;
85 OUString slash_UNO_slash_LOCATION;
86 OUString slash_UNO_slash_ACTIVATOR;
87 OUString colon_old;
88 OUString com_sun_star_registry_SimpleRegistry;
89 OUString Registry;
90 StringPool()
91 : sImplementationName( RTL_CONSTASCII_USTRINGPARAM( IMPLNAME )(&("com.sun.star.comp.stoc.ImplementationRegistration")[0
]), ((sal_Int32)((sizeof ("com.sun.star.comp.stoc.ImplementationRegistration"
) / sizeof (("com.sun.star.comp.stoc.ImplementationRegistration"
)[0]))-1)), (((rtl_TextEncoding) 11))
)
92 , sServiceName( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME )(&("com.sun.star.registry.ImplementationRegistration")[0]
), ((sal_Int32)((sizeof ("com.sun.star.registry.ImplementationRegistration"
) / sizeof (("com.sun.star.registry.ImplementationRegistration"
)[0]))-1)), (((rtl_TextEncoding) 11))
)
93 , TMP( RTL_CONSTASCII_USTRINGPARAM( "TMP" )(&("TMP")[0]), ((sal_Int32)((sizeof ("TMP") / sizeof (("TMP"
)[0]))-1)), (((rtl_TextEncoding) 11))
)
94 , TEMP( RTL_CONSTASCII_USTRINGPARAM( "TEMP" )(&("TEMP")[0]), ((sal_Int32)((sizeof ("TEMP") / sizeof ((
"TEMP")[0]))-1)), (((rtl_TextEncoding) 11))
)
95 , slash_UNO_slash_REGISTRY_LINKS( RTL_CONSTASCII_USTRINGPARAM("/UNO/REGISTRY_LINKS")(&("/UNO/REGISTRY_LINKS")[0]), ((sal_Int32)((sizeof ("/UNO/REGISTRY_LINKS"
) / sizeof (("/UNO/REGISTRY_LINKS")[0]))-1)), (((rtl_TextEncoding
) 11))
)
96 , slash_IMPLEMENTATIONS( RTL_CONSTASCII_USTRINGPARAM( "/IMPLEMENTATIONS" )(&("/IMPLEMENTATIONS")[0]), ((sal_Int32)((sizeof ("/IMPLEMENTATIONS"
) / sizeof (("/IMPLEMENTATIONS")[0]))-1)), (((rtl_TextEncoding
) 11))
)
97 , slash_UNO( RTL_CONSTASCII_USTRINGPARAM("/UNO")(&("/UNO")[0]), ((sal_Int32)((sizeof ("/UNO") / sizeof ((
"/UNO")[0]))-1)), (((rtl_TextEncoding) 11))
)
98 , slash_UNO_slash_SERVICES( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES")(&("/UNO/SERVICES")[0]), ((sal_Int32)((sizeof ("/UNO/SERVICES"
) / sizeof (("/UNO/SERVICES")[0]))-1)), (((rtl_TextEncoding) 11
))
)
99 , slash_UNO_slash_SINGLETONS( RTL_CONSTASCII_USTRINGPARAM("/UNO/SINGLETONS")(&("/UNO/SINGLETONS")[0]), ((sal_Int32)((sizeof ("/UNO/SINGLETONS"
) / sizeof (("/UNO/SINGLETONS")[0]))-1)), (((rtl_TextEncoding
) 11))
)
100 , slash_SERVICES( RTL_CONSTASCII_USTRINGPARAM("/SERVICES/")(&("/SERVICES/")[0]), ((sal_Int32)((sizeof ("/SERVICES/")
/ sizeof (("/SERVICES/")[0]))-1)), (((rtl_TextEncoding) 11))
)
101 , slash_UNO_slash_LOCATION( RTL_CONSTASCII_USTRINGPARAM("/UNO/LOCATION")(&("/UNO/LOCATION")[0]), ((sal_Int32)((sizeof ("/UNO/LOCATION"
) / sizeof (("/UNO/LOCATION")[0]))-1)), (((rtl_TextEncoding) 11
))
)
102 , slash_UNO_slash_ACTIVATOR( RTL_CONSTASCII_USTRINGPARAM("/UNO/ACTIVATOR")(&("/UNO/ACTIVATOR")[0]), ((sal_Int32)((sizeof ("/UNO/ACTIVATOR"
) / sizeof (("/UNO/ACTIVATOR")[0]))-1)), (((rtl_TextEncoding)
11))
)
103 , colon_old( RTL_CONSTASCII_USTRINGPARAM(":old")(&(":old")[0]), ((sal_Int32)((sizeof (":old") / sizeof ((
":old")[0]))-1)), (((rtl_TextEncoding) 11))
)
104 , com_sun_star_registry_SimpleRegistry(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry")(&("com.sun.star.registry.SimpleRegistry")[0]), ((sal_Int32
)((sizeof ("com.sun.star.registry.SimpleRegistry") / sizeof (
("com.sun.star.registry.SimpleRegistry")[0]))-1)), (((rtl_TextEncoding
) 11))
)
105 , Registry( RTL_CONSTASCII_USTRINGPARAM("Registry")(&("Registry")[0]), ((sal_Int32)((sizeof ("Registry") / sizeof
(("Registry")[0]))-1)), (((rtl_TextEncoding) 11))
)
106 {}
107private:
108 StringPool( const StringPool & );
109};
110
111const StringPool &spool()
112{
113 static StringPool *pPool = 0;
114 if( ! pPool )
115 {
116 MutexGuard guard( Mutex::getGlobalMutex() );
117 if( ! pPool )
118 {
119 static StringPool pool;
120 pPool = &pool;
121 }
122 }
123 return *pPool;
124}
125}
126
127extern rtl_StandardModuleCount g_moduleCount;
128
129namespace stoc_bootstrap
130{
131Sequence< OUString > impreg_getSupportedServiceNames()
132{
133 Sequence< OUString > seqNames(1);
134 seqNames.getArray()[0] = stoc_impreg::spool().sServiceName;
135 return seqNames;
136}
137
138OUString impreg_getImplementationName()
139{
140 return stoc_impreg::spool().sImplementationName;
141}
142}
143
144namespace stoc_impreg
145{
146//*************************************************************************
147// static deleteAllLinkReferences()
148//
149static void deleteAllLinkReferences(const Reference < XSimpleRegistry >& xReg,
150 const Reference < XRegistryKey >& xSource)
151 // throw ( InvalidRegistryException, RuntimeException )
152{
153 Reference < XRegistryKey > xKey = xSource->openKey(
154 spool().slash_UNO_slash_REGISTRY_LINKS );
155
156 if (xKey.is() && (xKey->getValueType() == RegistryValueType_ASCIILIST))
157 {
158 Sequence<OUString> linkNames = xKey->getAsciiListValue();
159
160 if (linkNames.getLength())
161 {
162 const OUString* pLinkNames = linkNames.getConstArray();
163
164 OUString aLinkName;
165 OUString aLinkParent;
166 Reference < XRegistryKey > xLinkParent;
167 const sal_Unicode* pTmpName = NULL__null;
168 const sal_Unicode* pShortName = NULL__null;
169 sal_Int32 sEnd = 0;
170
171 for (sal_Int32 i = 0; i < linkNames.getLength(); i++)
172 {
173 aLinkName = pLinkNames[i];
174
175 pTmpName = aLinkName.getStr();
176
177 if (pTmpName[0] != L'/')
178 continue;
179
180 sal_Int32 nIndex = rtl_ustr_indexOfChar( pTmpName, '%' );
181 if ( nIndex == -1 )
182 pShortName = 0;
183 else
184 pShortName = pTmpName+nIndex;
185
186 while (pShortName && pShortName[1] == L'%')
187 {
188 nIndex = rtl_ustr_indexOfChar( pShortName+2, '%' );
189 if ( nIndex == -1 )
190 pShortName = 0;
191 else
192 pShortName += nIndex+2;
193 }
194
195 if (pShortName)
196 {
197 aLinkName = aLinkName.copy(0, pShortName - pTmpName);
198 }
199
200 xReg->getRootKey()->deleteLink(aLinkName);
201
202 sEnd = rtl_ustr_lastIndexOfChar( aLinkName.getStr(), '/' );
203
204 aLinkParent = aLinkName.copy(0, sEnd);
205
206 while(!aLinkParent.isEmpty())
207 {
208 xLinkParent = xReg->getRootKey()->openKey(aLinkParent);
209
210 if (xLinkParent.is() && (xLinkParent->getKeyNames().getLength() == 0))
211 {
212 aLinkName = aLinkParent;
213
214 xReg->getRootKey()->deleteKey(aLinkParent);
215
216 sEnd = rtl_ustr_lastIndexOfChar( aLinkName.getStr(), '/' );
217
218 aLinkParent = aLinkName.copy(0, sEnd);
219 } else
220 {
221 break;
222 }
223 }
224 }
225 }
226 }
227}
228
229//*************************************************************************
230// static prepareLink
231//
232static void prepareLink( const Reference < XSimpleRegistry > & xDest,
233 const Reference < XRegistryKey > & xSource,
234 const OUString& link)
235 // throw ( InvalidRegistryException, RuntimeException )
236{
237 OUString linkRefName = xSource->getKeyName();
238 OUString linkName(link);
239 sal_Bool isRelativ = sal_False((sal_Bool)0);
240
241 const sal_Unicode* pTmpName = link.getStr();
242 const sal_Unicode* pShortName;
243 sal_Int32 nIndex = rtl_ustr_indexOfChar( pTmpName, '%' );
244 if ( nIndex == -1 )
245 pShortName = 0;
246 else
247 pShortName = pTmpName+nIndex;
248
249 if (pTmpName[0] != L'/')
250 isRelativ = sal_True((sal_Bool)1);
251
252 while (pShortName && pShortName[1] == L'%')
253 {
254 nIndex = rtl_ustr_indexOfChar( pShortName+2, '%' );
255 if ( nIndex == -1 )
256 pShortName = 0;
257 else
258 pShortName += nIndex+2;
259 }
260
261 if (pShortName)
262 {
263 linkRefName = linkRefName + link.copy(pShortName - pTmpName + 1);
264 linkName = link.copy(0, pShortName - pTmpName);
265 }
266
267 if (isRelativ)
268 xSource->createLink(linkName, linkRefName);
269 else
270 xDest->getRootKey()->createLink(linkName, linkRefName);
271}
272
273//*************************************************************************
274// static searchImplForLink
275//
276static OUString searchImplForLink(
277 const Reference < XRegistryKey > & xRootKey,
278 const OUString& linkName,
279 const OUString& implName )
280 // throw ( InvalidRegistryException, RuntimeException )
281{
282 const StringPool & pool = spool();
283 Reference < XRegistryKey > xKey = xRootKey->openKey( pool.slash_IMPLEMENTATIONS );
284 if (xKey.is())
285 {
286 Sequence< Reference < XRegistryKey > > subKeys( xKey->openKeys() );
287 const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
288 OUString key_name( pool.slash_UNO + linkName );
289
290 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
291 {
292 try
293 {
294 Reference < XRegistryKey > xImplKey( pSubKeys[i] );
295 if (xImplKey->getKeyType( key_name ) == RegistryKeyType_LINK)
296 {
297 OUString oldImplName = xImplKey->getKeyName().copy(strlen("/IMPLEMENTATIONS/"));
298 if (implName != oldImplName)
299 {
300 return oldImplName;
301 }
302 }
303 }
304 catch(InvalidRegistryException&)
305 {
306 }
307 }
308 }
309
310 return OUString();
311}
312
313//*************************************************************************
314// static searchLinkTargetForImpl
315//
316static OUString searchLinkTargetForImpl(const Reference < XRegistryKey >& xRootKey,
317 const OUString& linkName,
318 const OUString& implName)
319 // throw ( InvalidRegistryException, RuntimeException )
320{
321 OUString ret;
322
323// try
324// {
325 const StringPool & pool = spool();
326 Reference < XRegistryKey > xKey = xRootKey->openKey( pool.slash_IMPLEMENTATIONS );
327
328 if (xKey.is())
329 {
330 Sequence< Reference < XRegistryKey > > subKeys = xKey->openKeys();
331
332 const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
333 Reference < XRegistryKey > xImplKey;
334
335 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
336 {
337 xImplKey = pSubKeys[i];
338
339 OUString tmpImplName = xImplKey->getKeyName().copy(strlen("/IMPLEMENTATIONS/"));
340 OUString qualifiedLinkName( pool.slash_UNO );
341 qualifiedLinkName += linkName;
342 if (tmpImplName == implName &&
343 xImplKey->getKeyType( qualifiedLinkName ) == RegistryKeyType_LINK)
344 {
345 return xImplKey->getLinkTarget( qualifiedLinkName );
346 }
347 }
348 }
349// }
350// catch(InvalidRegistryException&)
351// {
352// }
353
354 return ret;
355}
356
357//*************************************************************************
358// static createUniqueSubEntry
359//
360static void createUniqueSubEntry(const Reference < XRegistryKey > & xSuperKey,
361 const OUString& value)
362 // throw ( InvalidRegistryException, RuntimeException )
363{
364 if (xSuperKey.is())
365 {
366// try
367// {
368 if (xSuperKey->getValueType() == RegistryValueType_ASCIILIST)
369 {
370 sal_Int32 length = 0;
371 sal_Bool bReady = sal_False((sal_Bool)0);
372
373 Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
374 length = implEntries.getLength();
375
376 for (sal_Int32 i = 0; !bReady && (i < length); i++)
377 {
378 bReady = (implEntries.getConstArray()[i] == value);
379 }
380
381 if (bReady)
382 {
383 Sequence<OUString> implEntriesNew(length);
384 implEntriesNew.getArray()[0] = value;
385
386 for (sal_Int32 i=0, j=1; i < length; i++)
387 {
388 if (implEntries.getConstArray()[i] != value)
389 implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
390 }
391 xSuperKey->setAsciiListValue(implEntriesNew);
392 } else
393 {
394 Sequence<OUString> implEntriesNew(length+1);
395 implEntriesNew.getArray()[0] = value;
396
397 for (sal_Int32 i = 0; i < length; i++)
398 {
399 implEntriesNew.getArray()[i+1] = implEntries.getConstArray()[i];
400 }
401 xSuperKey->setAsciiListValue(implEntriesNew);
402 }
403 } else
404 {
405 Sequence<OUString> implEntriesNew(1);
406
407 implEntriesNew.getArray()[0] = value;
408
409 xSuperKey->setAsciiListValue(implEntriesNew);
410 }
411// }
412// catch(InvalidRegistryException&)
413// {
414// }
415 }
416}
417
418//*************************************************************************
419// static deleteSubEntry
420//
421static sal_Bool deleteSubEntry(const Reference < XRegistryKey >& xSuperKey, const OUString& value)
422 // throw ( InvalidRegistryException, RuntimeException )
423{
424 if (xSuperKey->getValueType() == RegistryValueType_ASCIILIST)
425 {
426 Sequence<OUString> implEntries = xSuperKey->getAsciiListValue();
427 sal_Int32 length = implEntries.getLength();
428 sal_Int32 equals = 0;
429 sal_Bool hasNoImplementations = sal_False((sal_Bool)0);
430
431 for (sal_Int32 i = 0; i < length; i++)
432 {
433 if (implEntries.getConstArray()[i] == value)
434 equals++;
435 }
436
437 if (equals == length)
438 {
439 hasNoImplementations = sal_True((sal_Bool)1);
440 } else
441 {
442 Sequence<OUString> implEntriesNew(length - equals);
443
444 sal_Int32 j = 0;
445 for (sal_Int32 i = 0; i < length; i++)
446 {
447 if (implEntries.getConstArray()[i] != value)
448 {
449 implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
450 }
451 }
452 xSuperKey->setAsciiListValue(implEntriesNew);
453 }
454
455 if (hasNoImplementations)
456 {
457 return sal_True((sal_Bool)1);
458 }
459 }
460 return sal_False((sal_Bool)0);
461}
462
463//*************************************************************************
464// static prepareUserLink
465//
466static void prepareUserLink(const Reference < XSimpleRegistry >& xDest,
467 const OUString& linkName,
468 const OUString& linkTarget,
469 const OUString& implName)
470{
471 Reference < XRegistryKey > xRootKey;
472
473 xRootKey = xDest->getRootKey();
474
475 if (xRootKey->getKeyType(linkName) == RegistryKeyType_LINK)
476 {
477 OUString oldImplName(searchImplForLink(xRootKey, linkName, implName));
478
479 if (!oldImplName.isEmpty())
480 {
481 createUniqueSubEntry(xDest->getRootKey()->createKey(
482 linkName + spool().colon_old ), oldImplName);
483 }
484 }
485
486 if (xRootKey->isValid())
487 xRootKey->createLink(linkName, linkTarget);
488}
489
490//*************************************************************************
491// static deleteUserLink
492//
493static void deletePathIfPossible(const Reference < XRegistryKey >& xRootKey,
494 const OUString& path)
495{
496 try
497 {
498 Sequence<OUString> keyNames(xRootKey->openKey(path)->getKeyNames());
499
500 if (keyNames.getLength() == 0 &&
501 xRootKey->openKey(path)->getValueType() == RegistryValueType_NOT_DEFINED)
502 {
503 xRootKey->deleteKey(path);
504
505 OUString tmpPath(path);
506 OUString newPath = tmpPath.copy(0, tmpPath.lastIndexOf('/'));
507
508 if (newPath.getLength() > 1)
509 deletePathIfPossible(xRootKey, newPath);
510 }
511 }
512 catch(InvalidRegistryException&)
513 {
514 }
515}
516
517
518//*************************************************************************
519// static deleteUserLink
520//
521static void deleteUserLink(const Reference < XRegistryKey >& xRootKey,
522 const OUString& linkName,
523 const OUString& linkTarget,
524 const OUString& implName)
525 // throw ( InvalidRegistryException, RuntimeException )
526{
527 sal_Bool bClean = sal_False((sal_Bool)0);
528
529 if (xRootKey->getKeyType(linkName) == RegistryKeyType_LINK)
530 {
531 OUString tmpTarget = xRootKey->getLinkTarget(linkName);
532
533 if (tmpTarget == linkTarget)
534 {
535 xRootKey->deleteLink(linkName);
536 }
537 }
538
539 Reference < XRegistryKey > xOldKey = xRootKey->openKey(
540 linkName + spool().colon_old );
541 if (xOldKey.is())
542 {
543 sal_Bool hasNoImplementations = sal_False((sal_Bool)0);
544
545 if (xOldKey->getValueType() == RegistryValueType_ASCIILIST)
546 {
547 Sequence<OUString> implEntries = xOldKey->getAsciiListValue();
548 sal_Int32 length = implEntries.getLength();
549 sal_Int32 equals = 0;
550
551 for (sal_Int32 i = 0; i < length; i++)
552 {
553 if (implEntries.getConstArray()[i] == implName)
554 equals++;
555 }
556
557 if (equals == length)
558 {
559 hasNoImplementations = sal_True((sal_Bool)1);
560 } else
561 {
562 OUString oldImpl;
563
564 if (length > equals + 1)
565 {
566 Sequence<OUString> implEntriesNew(length - equals - 1);
567
568 sal_Int32 j = 0;
569 sal_Bool first = sal_True((sal_Bool)1);
570 for (sal_Int32 i = 0; i < length; i++)
571 {
572 if (implEntries.getConstArray()[i] != implName)
573 {
574 if (first)
575 {
576 oldImpl = implEntries.getConstArray()[i];
577 first = sal_False((sal_Bool)0);
578 } else
579 {
580 implEntriesNew.getArray()[j++] = implEntries.getConstArray()[i];
581 }
582 }
583 }
584
585 xOldKey->setAsciiListValue(implEntriesNew);
586 } else
587 {
588 oldImpl = implEntries.getConstArray()[0];
589 rtl::OUString path(xOldKey->getKeyName());
590 xOldKey->closeKey();
591 xRootKey->deleteKey(path);
592 }
593
594 OUString oldTarget = searchLinkTargetForImpl(xRootKey, linkName, oldImpl);
595 if (!oldTarget.isEmpty())
596 {
597 xRootKey->createLink(linkName, oldTarget);
598 }
599 }
600
601 if (hasNoImplementations)
602 {
603 bClean = sal_True((sal_Bool)1);
604 hasNoImplementations = sal_False((sal_Bool)0);
605 rtl::OUString path(xOldKey->getKeyName());
606 xOldKey->closeKey();
607 xRootKey->deleteKey(path);
608 }
609 }
610 } else
611 {
612 bClean = sal_True((sal_Bool)1);
613 }
614
615 if (bClean)
616 {
617 OUString tmpName(linkName);
618 OUString path = tmpName.copy(0, tmpName.lastIndexOf('/'));
619 deletePathIfPossible(xRootKey, path);
620 }
621}
622
623//*************************************************************************
624// static prepareUserKeys
625//
626static void prepareUserKeys(const Reference < XSimpleRegistry >& xDest,
627 const Reference < XRegistryKey >& xUnoKey,
628 const Reference < XRegistryKey >& xKey,
629 const OUString& implName,
630 sal_Bool bRegister)
631{
632 sal_Bool hasSubKeys = sal_False((sal_Bool)0);
633
634 Sequence<OUString> keyNames = xKey->getKeyNames();
635
636 OUString relativKey;
637 if (keyNames.getLength())
638 relativKey = keyNames.getConstArray()[0].copy(xKey->getKeyName().getLength()+1);
639
640 if (keyNames.getLength() == 1 &&
641 xKey->getKeyType(relativKey) == RegistryKeyType_LINK)
642 {
643 hasSubKeys = sal_True((sal_Bool)1);
644
645 OUString linkTarget = xKey->getLinkTarget(relativKey);
646 OUString linkName(xKey->getKeyName().copy(xUnoKey->getKeyName().getLength()));
647
648 linkName = linkName + OUString( RTL_CONSTASCII_USTRINGPARAM("/")(&("/")[0]), ((sal_Int32)((sizeof ("/") / sizeof (("/")[0
]))-1)), (((rtl_TextEncoding) 11))
) + relativKey;
649
650 if (bRegister)
651 {
652 prepareUserLink(xDest, linkName, linkTarget, implName);
653 } else
654 {
655 deleteUserLink(xDest->getRootKey(), linkName, linkTarget, implName);
656 }
657 } else
658 {
659 Sequence< Reference < XRegistryKey> > subKeys = xKey->openKeys();
660
661 if (subKeys.getLength())
662 {
663 hasSubKeys = sal_True((sal_Bool)1);
664 const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
665
666 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
667 {
668 prepareUserKeys(xDest, xUnoKey, pSubKeys[i], implName, bRegister);
669 }
670 }
671 }
672
673 if (! hasSubKeys)
674 {
675 OUString keyName(xKey->getKeyName().copy(xUnoKey->getKeyName().getLength()));
676
677 Reference < XRegistryKey > xRootKey = xDest->getRootKey();
678 if (bRegister)
679 {
680 createUniqueSubEntry(xRootKey->createKey(keyName), implName);
681 }
682 else
683 {
684 Reference< XRegistryKey > rKey = xRootKey->openKey(keyName);
685 if( rKey.is() )
686 {
687 deleteSubEntry(rKey, implName);
688 xRootKey->deleteKey(keyName);
689 }
690
691 OUString path = keyName.copy(0, keyName.lastIndexOf('/'));
692 if( !path.isEmpty() )
693 {
694 deletePathIfPossible(xRootKey, path);
695 }
696 }
697 }
698}
699
700//*************************************************************************
701// static deleteAllImplementations
702//
703static void deleteAllImplementations( const Reference < XSimpleRegistry >& xReg,
704 const Reference < XRegistryKey >& xSource,
705 const OUString& locationUrl,
706 std::list<OUString> & implNames)
707 // throw (InvalidRegistryException, RuntimeException)
708{
709 Sequence < Reference < XRegistryKey > > subKeys = xSource->openKeys();
710
711 if (subKeys.getLength() > 0)
712 {
713 const Reference < XRegistryKey> * pSubKeys = subKeys.getConstArray();
714 Reference < XRegistryKey > xImplKey;
715 sal_Bool hasLocationUrl = sal_False((sal_Bool)0);
716
717 const StringPool &pool = spool();
718 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
719 {
720 xImplKey = pSubKeys[i];
721 Reference < XRegistryKey > xKey = xImplKey->openKey(
722 pool.slash_UNO_slash_LOCATION );
723
724 if (xKey.is() && (xKey->getValueType() == RegistryValueType_ASCII))
725 {
726 if (xKey->getAsciiValue() == locationUrl)
727 {
728 hasLocationUrl = sal_True((sal_Bool)1);
729
730 OUString implName(xImplKey->getKeyName().getStr() + 1);
731 sal_Int32 firstDot = implName.indexOf('/');
732
733 if (firstDot >= 0)
734 implName = implName.copy(firstDot + 1);
735
736 implNames.push_back(implName);
737
738 deleteAllLinkReferences(xReg, xImplKey);
739
740 xKey = xImplKey->openKey( pool.slash_UNO );
741 if (xKey.is())
742 {
743 Sequence< Reference < XRegistryKey > > subKeys2 = xKey->openKeys();
744
745 if (subKeys2.getLength())
746 {
747 const Reference < XRegistryKey > * pSubKeys2 = subKeys2.getConstArray();
748
749 for (sal_Int32 j = 0; j < subKeys2.getLength(); j++)
750 {
751 if (pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_SERVICES ) &&
752 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_REGISTRY_LINKS ) &&
753 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_ACTIVATOR ) &&
754 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_SINGLETONS ) &&
755 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_LOCATION) )
756 {
757 prepareUserKeys(xReg, xKey, pSubKeys2[j], implName, sal_False((sal_Bool)0));
758 }
759 }
760 }
761 }
762 }
763 }
764
765 if (hasLocationUrl)
766 {
767 hasLocationUrl = sal_False((sal_Bool)0);
768 rtl::OUString path(xImplKey->getKeyName());
769 xImplKey->closeKey();
770 xReg->getRootKey()->deleteKey(path);
771 }
772 }
773
774 subKeys = xSource->openKeys();
775 if (subKeys.getLength() == 0)
776 {
777 rtl::OUString path(xSource->getKeyName());
778 xSource->closeKey();
779 xReg->getRootKey()->deleteKey(path);
780 }
781 } else
782 {
783 rtl::OUString path(xSource->getKeyName());
784 xSource->closeKey();
785 xReg->getRootKey()->deleteKey(path);
786 }
787}
788
789//==================================================================================================
790static void delete_all_singleton_entries(
791 Reference < registry::XRegistryKey > const & xSingletons_section,
792 ::std::list< OUString > const & impl_names )
793 // throw (InvalidRegistryException, RuntimeException)
794{
795 Sequence< Reference< registry::XRegistryKey > > singletons( xSingletons_section->openKeys() );
796 Reference< registry::XRegistryKey > const * subkeys = singletons.getConstArray();
797 for ( sal_Int32 nPos = singletons.getLength(); nPos--; )
798 {
799 Reference< registry::XRegistryKey > const & xSingleton = subkeys[ nPos ];
800 Reference< registry::XRegistryKey > xRegisteredImplNames(
801 xSingleton->openKey( OUSTR("REGISTERED_BY")::rtl::OUString( (&("REGISTERED_BY")[0]), ((sal_Int32)((sizeof
("REGISTERED_BY") / sizeof (("REGISTERED_BY")[0]))-1)), (((rtl_TextEncoding
) 11)) )
) );
802 if (xRegisteredImplNames.is() && xRegisteredImplNames->isValid())
803 {
804 Sequence< OUString > registered_implnames;
805 try
806 {
807 registered_implnames = xRegisteredImplNames->getAsciiListValue();
808 }
809 catch (registry::InvalidValueException &)
810 {
811 }
812 OUString const * p = registered_implnames.getConstArray();
813 sal_Int32 nOrigRegLength = registered_implnames.getLength();
814 sal_Int32 nNewLength = nOrigRegLength;
815 for ( sal_Int32 n = nOrigRegLength; n--; )
816 {
817 OUString const & registered_implname = p[ n ];
818
819 ::std::list< OUString >::const_iterator iPos( impl_names.begin() );
820 ::std::list< OUString >::const_iterator const iEnd( impl_names.end() );
821 for ( ; iPos != iEnd; ++iPos )
822 {
823 if (iPos->equals( registered_implname ))
824 {
825 registered_implnames[ n ] = p[ nNewLength -1 ];
826 --nNewLength;
827 }
828 }
829 }
830
831 if (nNewLength != nOrigRegLength)
832 {
833 if (0 == nNewLength)
834 {
835 // remove whole entry
836 xRegisteredImplNames->closeKey();
837 xSingleton->deleteKey( OUSTR("REGISTERED_BY")::rtl::OUString( (&("REGISTERED_BY")[0]), ((sal_Int32)((sizeof
("REGISTERED_BY") / sizeof (("REGISTERED_BY")[0]))-1)), (((rtl_TextEncoding
) 11)) )
);
838 // registry key cannot provide its relative name, only absolute :(
839 OUString abs( xSingleton->getKeyName() );
840 xSingletons_section->deleteKey( abs.copy( abs.lastIndexOf( '/' ) +1 ) );
841 }
842 else
843 {
844 registered_implnames.realloc( nNewLength );
845 xRegisteredImplNames->setAsciiListValue( registered_implnames );
846 }
847 }
848 }
849 }
850}
851
852//*************************************************************************
853// static deleteAllServiceEntries
854//
855static void deleteAllServiceEntries( const Reference < XSimpleRegistry >& xReg,
856 const Reference < XRegistryKey >& xSource,
857 const OUString& implName)
858 // throw ( InvalidRegistryException, RuntimeException )
859{
860 Sequence< Reference < XRegistryKey > > subKeys = xSource->openKeys();
861
862 if (subKeys.getLength() > 0)
863 {
864 const Reference < XRegistryKey > * pSubKeys = subKeys.getConstArray();
865 Reference < XRegistryKey > xServiceKey;
866 sal_Bool hasNoImplementations = sal_False((sal_Bool)0);
867
868 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
869 {
870 xServiceKey = pSubKeys[i];
871
872 if (xServiceKey->getValueType() == RegistryValueType_ASCIILIST)
873 {
874 Sequence<OUString> implEntries = xServiceKey->getAsciiListValue();
875 sal_Int32 length = implEntries.getLength();
876 sal_Int32 equals = 0;
877
878 for (sal_Int32 j = 0; j < length; j++)
879 {
880 if (implEntries.getConstArray()[j] == implName)
881 equals++;
882 }
883
884 if (equals == length)
885 {
886 hasNoImplementations = sal_True((sal_Bool)1);
887 } else
888 {
889 if (equals > 0)
890 {
891 Sequence<OUString> implEntriesNew(length-equals);
892
893 sal_Int32 j = 0;
894 for (sal_Int32 k = 0; k < length; k++)
895 {
896 if (implEntries.getConstArray()[k] != implName)
897 {
898 implEntriesNew.getArray()[j++] = implEntries.getConstArray()[k];
899 }
900 }
901
902 xServiceKey->setAsciiListValue(implEntriesNew);
903 }
904 }
905 }
906
907 if (hasNoImplementations)
908 {
909 hasNoImplementations = sal_False((sal_Bool)0);
910 rtl::OUString path(xServiceKey->getKeyName());
911 xServiceKey->closeKey();
912 xReg->getRootKey()->deleteKey(path);
913 }
914 }
915
916 subKeys = xSource->openKeys();
917 if (subKeys.getLength() == 0)
918 {
919 rtl::OUString path(xSource->getKeyName());
920 xSource->closeKey();
921 xReg->getRootKey()->deleteKey(path);
922 }
923 } else
924 {
925 rtl::OUString path(xSource->getKeyName());
926 xSource->closeKey();
927 xReg->getRootKey()->deleteKey(path);
928 }
929}
930
931//--------------------------------------------------------------------------------------------------
932static bool is_supported_service(
933 OUString const & service_name,
934 Reference< reflection::XServiceTypeDescription > const & xService_td )
935{
936 if (xService_td->getName().equals( service_name ))
937 return true;
938 Sequence< Reference< reflection::XServiceTypeDescription > > seq(
939 xService_td->getMandatoryServices() );
940 Reference< reflection::XServiceTypeDescription > const * p = seq.getConstArray();
941 for ( sal_Int32 nPos = seq.getLength(); nPos--; )
942 {
943 if (is_supported_service( service_name, p[ nPos ] ))
944 return true;
945 }
946 return false;
947}
948
949//--------------------------------------------------------------------------------------------------
950static void insert_singletons(
951 Reference< registry::XSimpleRegistry > const & xDest,
952 Reference< registry::XRegistryKey > const & xImplKey,
953 Reference< XComponentContext > const & xContext )
954 // throw( registry::InvalidRegistryException, registry::CannotRegisterImplementationException, RuntimeException )
955{
956 // singletons
957 Reference< registry::XRegistryKey > xKey( xImplKey->openKey( OUSTR("UNO/SINGLETONS")::rtl::OUString( (&("UNO/SINGLETONS")[0]), ((sal_Int32)((
sizeof ("UNO/SINGLETONS") / sizeof (("UNO/SINGLETONS")[0]))-1
)), (((rtl_TextEncoding) 11)) )
) );
958 if (xKey.is() && xKey->isValid())
959 {
960 OUString implname( xImplKey->getKeyName().copy( sizeof ("/IMPLEMENTATIONS/") -1 ) );
961 // singleton entries
962 Sequence< Reference< registry::XRegistryKey > > xSingletons_section( xKey->openKeys() );
963 Reference< registry::XRegistryKey > const * p = xSingletons_section.getConstArray();
964 for ( sal_Int32 nPos = xSingletons_section.getLength(); nPos--; )
965 {
966 Reference< registry::XRegistryKey > const & xSingleton = p[ nPos ];
967 OUString singleton_name(
968 xSingleton->getKeyName().copy(
969 implname.getLength() + sizeof ("/IMPLEMENTATIONS//UNO/SINGLETONS/") -1 ) );
970 OUString service_name( xSingleton->getStringValue() );
971
972 OUString keyname( OUSTR("/SINGLETONS/")::rtl::OUString( (&("/SINGLETONS/")[0]), ((sal_Int32)((sizeof
("/SINGLETONS/") / sizeof (("/SINGLETONS/")[0]))-1)), (((rtl_TextEncoding
) 11)) )
+ singleton_name );
973 Reference< registry::XRegistryKey > xKey2( xDest->getRootKey()->openKey( keyname ) );
974 if (xKey2.is() && xKey2->isValid())
975 {
976 try
977 {
978 OUString existing_name( xKey2->getStringValue() );
979 if (! existing_name.equals( service_name ))
980 {
981 Reference< container::XHierarchicalNameAccess > xTDMgr;
982 OUString the_tdmgr =
983 OUSTR("/singletons/com.sun.star.reflection.theTypeDescriptionManager")::rtl::OUString( (&("/singletons/com.sun.star.reflection.theTypeDescriptionManager"
)[0]), ((sal_Int32)((sizeof ("/singletons/com.sun.star.reflection.theTypeDescriptionManager"
) / sizeof (("/singletons/com.sun.star.reflection.theTypeDescriptionManager"
)[0]))-1)), (((rtl_TextEncoding) 11)) )
;
984 xContext->getValueByName( the_tdmgr ) >>= xTDMgr;
985 if (! xTDMgr.is())
986 {
987 throw RuntimeException(
988 OUSTR("cannot get singleton ")::rtl::OUString( (&("cannot get singleton ")[0]), ((sal_Int32
)((sizeof ("cannot get singleton ") / sizeof (("cannot get singleton "
)[0]))-1)), (((rtl_TextEncoding) 11)) )
+ the_tdmgr,
989 Reference< XInterface >() );
990 }
991 try
992 {
993 Reference< reflection::XServiceTypeDescription > xExistingService_td;
994 xTDMgr->getByHierarchicalName( existing_name ) >>= xExistingService_td;
995 if (! xExistingService_td.is())
996 {
997 throw RuntimeException(
998 OUSTR("cannot get service type description: ")::rtl::OUString( (&("cannot get service type description: "
)[0]), ((sal_Int32)((sizeof ("cannot get service type description: "
) / sizeof (("cannot get service type description: ")[0]))-1)
), (((rtl_TextEncoding) 11)) )
+ existing_name,
999 Reference< XInterface >() );
1000 }
1001
1002 // everything's fine if existing service entry supports the one
1003 // to be registered
1004 if (! is_supported_service( service_name, xExistingService_td ))
1005 {
1006 OUStringBuffer buf( 64 );
1007 buf.appendAscii(
1008 RTL_CONSTASCII_STRINGPARAM("existing singleton service (")(&("existing singleton service (")[0]), ((sal_Int32)(sizeof
("existing singleton service (") / sizeof (("existing singleton service ("
)[0]))-1)
);
1009 buf.append( singleton_name );
1010 buf.append( (sal_Unicode)'=' );
1011 buf.append( existing_name );
1012 buf.appendAscii(
1013 RTL_CONSTASCII_STRINGPARAM(") does not support given one: ")(&(") does not support given one: ")[0]), ((sal_Int32)(sizeof
(") does not support given one: ") / sizeof ((") does not support given one: "
)[0]))-1)
);
1014 buf.append( service_name );
1015 throw registry::CannotRegisterImplementationException(
1016 buf.makeStringAndClear(), Reference< XInterface >() );
1017 }
1018 }
1019 catch (const container::NoSuchElementException & exc)
1020 {
1021 throw RuntimeException(
1022 OUSTR("cannot get service type description: ")::rtl::OUString( (&("cannot get service type description: "
)[0]), ((sal_Int32)((sizeof ("cannot get service type description: "
) / sizeof (("cannot get service type description: ")[0]))-1)
), (((rtl_TextEncoding) 11)) )
+ exc.Message,
1023 Reference< XInterface >() );
1024 }
1025 }
1026 }
1027 catch (registry::InvalidValueException &)
1028 {
1029 // repair
1030 xKey2->setStringValue( service_name );
1031 }
1032 }
1033 else
1034 {
1035 // insert singleton entry
1036 xKey2 = xDest->getRootKey()->createKey( keyname );
1037 xKey2->setStringValue( service_name );
1038 }
1039
1040 Reference< registry::XRegistryKey > xRegisteredImplNames(
1041 xKey2->openKey( OUSTR("REGISTERED_BY")::rtl::OUString( (&("REGISTERED_BY")[0]), ((sal_Int32)((sizeof
("REGISTERED_BY") / sizeof (("REGISTERED_BY")[0]))-1)), (((rtl_TextEncoding
) 11)) )
) );
1042 if (!xRegisteredImplNames.is() || !xRegisteredImplNames->isValid())
1043 {
1044 // create
1045 xRegisteredImplNames = xKey2->createKey( OUSTR("REGISTERED_BY")::rtl::OUString( (&("REGISTERED_BY")[0]), ((sal_Int32)((sizeof
("REGISTERED_BY") / sizeof (("REGISTERED_BY")[0]))-1)), (((rtl_TextEncoding
) 11)) )
);
1046 }
1047
1048 Sequence< OUString > implnames;
1049 try
1050 {
1051 implnames = xRegisteredImplNames->getAsciiListValue();
1052 }
1053 catch (registry::InvalidValueException &)
1054 {
1055 }
1056 // check implname is already in
1057 sal_Int32 nPos_implnames = implnames.getLength();
1058 OUString const * pImplnames = implnames.getConstArray();
1059 while (nPos_implnames--)
1060 {
1061 if (implname.equals( pImplnames[ nPos_implnames ] ))
1062 break;
1063 }
1064 if (nPos_implnames < 0)
1065 {
1066 // append and write back
1067 implnames.realloc( implnames.getLength() +1 );
1068 implnames[ implnames.getLength() -1 ] = implname;
1069 xRegisteredImplNames->setAsciiListValue( implnames );
1070 }
1071 }
1072 }
1073}
1074
1075
1076//*************************************************************************
1077// static prepareRegistry
1078//
1079static void prepareRegistry(
1080 const Reference < XSimpleRegistry >& xDest,
1081 const Reference < XRegistryKey >& xSource,
1082 const OUString& implementationLoaderUrl,
1083 const OUString& locationUrl,
1084 Reference< XComponentContext > const & xContext )
1085 // throw ( InvalidRegistryException, CannotRegisterImplementationException, RuntimeException )
1086{
1087 Sequence< Reference < XRegistryKey > > subKeys = xSource->openKeys();
1088
1089 if (!subKeys.getLength())
1090 {
1091 throw InvalidRegistryException(
1092 OUString( RTL_CONSTASCII_USTRINGPARAM( "prepareRegistry(): source registry is empty" )(&("prepareRegistry(): source registry is empty")[0]), ((
sal_Int32)((sizeof ("prepareRegistry(): source registry is empty"
) / sizeof (("prepareRegistry(): source registry is empty")[0
]))-1)), (((rtl_TextEncoding) 11))
),
1093 Reference< XInterface > () );
1094 }
1095
1096 const StringPool & pool = spool();
1097
1098 const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
1099 Reference < XRegistryKey > xImplKey;
1100
1101 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
1102 {
1103 xImplKey = pSubKeys[i];
1104
1105 Reference < XRegistryKey > xKey = xImplKey->openKey(
1106 pool.slash_UNO_slash_SERVICES );
1107
1108 if (xKey.is())
1109 {
1110 // update entries in SERVICES section
1111 Sequence< Reference < XRegistryKey > > serviceKeys = xKey->openKeys();
1112 const Reference < XRegistryKey > * pServiceKeys = serviceKeys.getConstArray();
1113
1114 OUString implName = OUString(xImplKey->getKeyName().getStr() + 1);
1115 sal_Int32 firstDot = implName.indexOf('/');
1116
1117 if (firstDot >= 0)
1118 implName = implName.copy(firstDot + 1);
1119
1120 sal_Int32 offset = xKey->getKeyName().getLength() + 1;
1121
1122 for (sal_Int32 j = 0; j < serviceKeys.getLength(); j++)
1123 {
1124 OUString serviceName = pServiceKeys[j]->getKeyName().copy(offset);
1125
1126 createUniqueSubEntry(
1127 xDest->getRootKey()->createKey(
1128 pool.slash_SERVICES + serviceName ),
1129 implName);
1130 }
1131
1132 xKey = xImplKey->openKey( pool.slash_UNO );
1133 if (xKey.is())
1134 {
1135 Sequence< Reference < XRegistryKey > > subKeys2 = xKey->openKeys();
1136
1137 if (subKeys2.getLength())
1138 {
1139 const Reference < XRegistryKey > * pSubKeys2 = subKeys2.getConstArray();
1140
1141 for (sal_Int32 j = 0; j < subKeys2.getLength(); j++)
1142 {
1143 if (pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_SERVICES) &&
1144 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_REGISTRY_LINKS ) &&
1145 pSubKeys2[j]->getKeyName() != (xImplKey->getKeyName() + pool.slash_UNO_slash_SINGLETONS ))
1146 {
1147 prepareUserKeys(xDest, xKey, pSubKeys2[j], implName, sal_True((sal_Bool)1));
1148 }
1149 }
1150 }
1151 }
1152 }
1153
1154 // update LOCATION entry
1155 xKey = xImplKey->createKey( pool.slash_UNO_slash_LOCATION );
1156
1157 if (xKey.is())
1158 {
1159 xKey->setAsciiValue(locationUrl);
1160 }
1161
1162 // update ACTIVATOR entry
1163 xKey = xImplKey->createKey( pool.slash_UNO_slash_ACTIVATOR );
1164
1165 if (xKey.is())
1166 {
1167 xKey->setAsciiValue(implementationLoaderUrl);
1168 }
1169
1170 xKey = xImplKey->openKey( pool.slash_UNO_slash_SERVICES );
1171
1172 if (xKey.is() && (xKey->getValueType() == RegistryValueType_ASCIILIST))
1173 {
1174 // update link entries in REGISTRY_LINKS section
1175 Sequence<OUString> linkNames = xKey->getAsciiListValue();
1176
1177 if (linkNames.getLength())
1178 {
1179 const OUString* pLinkNames = linkNames.getConstArray();
1180
1181 for (sal_Int32 j = 0; j < linkNames.getLength(); j++)
1182 {
1183 prepareLink(xDest, xImplKey, pLinkNames[j]);
1184 }
1185 }
1186 }
1187
1188 insert_singletons( xDest, xImplKey, xContext );
1189 }
1190}
1191
1192
1193static void findImplementations( const Reference < XRegistryKey > & xSource,
1194 std::list <OUString>& implNames)
1195{
1196 sal_Bool isImplKey = sal_False((sal_Bool)0);
1197
1198 try
1199 {
1200 Reference < XRegistryKey > xKey = xSource->openKey(
1201 spool().slash_UNO_slash_SERVICES );
1202
1203 if (xKey.is() && (xKey->getKeyNames().getLength() > 0))
1204 {
1205 isImplKey = sal_True((sal_Bool)1);
1206
1207 OUString implName = OUString(xSource->getKeyName().getStr() + 1).replace('/', '.').getStr();
1208 sal_Int32 firstDot = implName.indexOf('.');
1209
1210 if (firstDot >= 0)
1211 implName = implName.copy(firstDot + 1);
1212
1213 implNames.push_back(implName);
1214 }
1215 }
1216 catch(InvalidRegistryException&)
1217 {
1218 }
1219
1220 if (isImplKey) return;
1221
1222 try
1223 {
1224 Sequence< Reference < XRegistryKey > > subKeys = xSource->openKeys();
1225
1226 if (subKeys.getLength() > 0)
1227 {
1228 const Reference < XRegistryKey >* pSubKeys = subKeys.getConstArray();
1229
1230 for (sal_Int32 i = 0; i < subKeys.getLength(); i++)
1231 {
1232 findImplementations(pSubKeys[i], implNames);
1233 }
1234
1235 }
1236 }
1237 catch(InvalidRegistryException&)
1238 {
1239 }
1240}
1241
1242
1243class ImplementationRegistration
1244 : public WeakImplHelper3< XImplementationRegistration2, XServiceInfo, XInitialization >
1245{
1246public:
1247 ImplementationRegistration( const Reference < XComponentContext > & rSMgr );
1248 ~ImplementationRegistration();
1249
1250 // XServiceInfo
1251 OUString SAL_CALL getImplementationName() throw(RuntimeException);
1252 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw(RuntimeException);
1253 Sequence< OUString > SAL_CALL getSupportedServiceNames(void) throw(RuntimeException);
1254
1255 // XImplementationRegistration
1256 virtual void SAL_CALL registerImplementation(
1257 const OUString& implementationLoader,
1258 const OUString& location,
1259 const Reference < XSimpleRegistry > & xReg)
1260 throw( CannotRegisterImplementationException, RuntimeException );
1261
1262 virtual sal_Bool SAL_CALL revokeImplementation(
1263 const OUString& location,
1264 const Reference < XSimpleRegistry >& xReg)
1265 throw( RuntimeException );
1266
1267 virtual Sequence< OUString > SAL_CALL getImplementations(
1268 const OUString& implementationLoader,
1269 const OUString& location)
1270 throw( RuntimeException );
1271 virtual Sequence< OUString > SAL_CALL checkInstantiation(
1272 const OUString& implementationName)
1273 throw( RuntimeException );
1274
1275 // XImplementationRegistration2
1276 virtual void SAL_CALL registerImplementationWithLocation(
1277 const OUString& implementationLoader,
1278 const OUString& location,
1279 const OUString& registeredLocation,
1280 const Reference < XSimpleRegistry > & xReg)
1281 throw( CannotRegisterImplementationException, RuntimeException );
1282
1283 // XInitialization
1284 virtual void SAL_CALL initialize(
1285 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
1286 throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
1287
1288private: // helper methods
1289 void prepareRegister(
1290 const OUString& implementationLoader,
1291 const OUString& location,
1292 const OUString& registeredLocation,
1293 const Reference < XSimpleRegistry > & xReg);
1294 // throw( CannotRegisterImplementationException, RuntimeException )
1295
1296 static void doRegister( const Reference < XMultiComponentFactory >& xSMgr,
1297 const Reference < XComponentContext > &xCtx,
1298 const Reference < XImplementationLoader >& xAct,
1299 const Reference < XSimpleRegistry >& xDest,
1300 const OUString& implementationLoaderUrl,
1301 const OUString& locationUrl,
1302 const OUString& registeredLocationUrl);
1303 /* throw ( InvalidRegistryException,
1304 MergeConflictException,
1305 CannotRegisterImplementationException, RuntimeException ) */
1306
1307 static void doRevoke( const Reference < XSimpleRegistry >& xDest,
1308 const OUString& locationUrl );
1309 // throw( InvalidRegistryException, RuntimeException )
1310 Reference< XSimpleRegistry > getRegistryFromServiceManager();
1311
1312 static Reference< XSimpleRegistry > createTemporarySimpleRegistry(
1313 const Reference< XMultiComponentFactory > &rSMgr,
1314 const Reference < XComponentContext > & rCtx );
1315
1316private: // members
1317 Reference < XMultiComponentFactory > m_xSMgr;
1318 Reference < XComponentContext > m_xCtx;
1319};
1320
1321//*************************************************************************
1322// ImplementationRegistration()
1323//
1324ImplementationRegistration::ImplementationRegistration( const Reference < XComponentContext > & xCtx )
1325 : m_xSMgr( xCtx->getServiceManager() )
1326 , m_xCtx( xCtx )
1327{
1328 g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
1329}
1330
1331//*************************************************************************
1332// ~ImplementationRegistration()
1333//
1334ImplementationRegistration::~ImplementationRegistration()
1335{
1336 g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
1337}
1338
1339
1340// XServiceInfo
1341OUString ImplementationRegistration::getImplementationName() throw(RuntimeException)
1342{
1343 return stoc_bootstrap::impreg_getImplementationName();
1344}
1345
1346// XServiceInfo
1347sal_Bool ImplementationRegistration::supportsService(const OUString& ServiceName) throw(RuntimeException)
1348{
1349 Sequence< OUString > aSNL = getSupportedServiceNames();
1350 const OUString * pArray = aSNL.getConstArray();
1351 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1352 if( pArray[i] == ServiceName )
1353 return sal_True((sal_Bool)1);
1354 return sal_False((sal_Bool)0);
1355}
1356
1357// XServiceInfo
1358Sequence< OUString > ImplementationRegistration::getSupportedServiceNames(void) throw(RuntimeException)
1359{
1360 return stoc_bootstrap::impreg_getSupportedServiceNames();
1361}
1362
1363Reference< XSimpleRegistry > ImplementationRegistration::getRegistryFromServiceManager()
1364{
1365 Reference < XPropertySet > xPropSet( m_xSMgr, UNO_QUERY );
1366 Reference < XSimpleRegistry > xRegistry;
1367
1368 if( xPropSet.is() ) {
1369
1370 try { // the implementation does not support XIntrospectionAccess !
1371
1372 Any aAny = xPropSet->getPropertyValue( spool().Registry );
1373
1374 if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE ) {
1375 aAny >>= xRegistry;
1376 }
1377 }
1378 catch( UnknownPropertyException & ) {
1379 // empty reference is error signal !
1380 }
1381 }
1382
1383 return xRegistry;
1384}
1385
1386
1387//************************************************************************
1388// XInitialization
1389//
1390void ImplementationRegistration::initialize(
1391 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArgs )
1392 throw( ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1393{
1394
1395 if( aArgs.getLength() != 4 ) {
1396 OUStringBuffer buf;
1397 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::initialize() expects 4 parameters, got "
)[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() expects 4 parameters, got "
) / sizeof (("ImplementationRegistration::initialize() expects 4 parameters, got "
)[0]))-1)
1398 "ImplementationRegistration::initialize() expects 4 parameters, got ")(&("ImplementationRegistration::initialize() expects 4 parameters, got "
)[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() expects 4 parameters, got "
) / sizeof (("ImplementationRegistration::initialize() expects 4 parameters, got "
)[0]))-1)
);
1399 buf.append( (sal_Int32) aArgs.getLength() );
1400 throw IllegalArgumentException( buf.makeStringAndClear(),
1401 Reference<XInterface > (),
1402 0 );
1403 }
1404
1405 Reference< XImplementationLoader > rLoader;
1406 OUString loaderServiceName;
1407 OUString locationUrl;
1408 Reference< XSimpleRegistry > rReg;
1409
1410 // 1st argument : An instance of an implementation loader
1411 if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE ) {
1412 aArgs.getConstArray()[0] >>= rLoader;
1413 }
1414 if( !rLoader.is()) {
1415 OUStringBuffer buf;
1416 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid first parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]))-1)
1417 "ImplementationRegistration::initialize() invalid first parameter,"(&("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid first parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]))-1)
1418 "expected " )(&("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid first parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid first parameter,"
"expected ")[0]))-1)
);
1419 buf.append( getCppuType( &rLoader ).getTypeName() );
1420 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ", got " )(&(", got ")[0]), ((sal_Int32)(sizeof (", got ") / sizeof
((", got ")[0]))-1)
);
1421 buf.append( aArgs.getConstArray()[0].getValueTypeName() );
1422 throw IllegalArgumentException( buf.makeStringAndClear(),
1423 Reference< XInterface > (),
1424 0 );
1425 }
1426
1427 // 2nd argument : The service name of the loader. This name is written into the registry
1428 if( aArgs.getConstArray()[1].getValueType().getTypeClass() == TypeClass_STRING ) {
1429 aArgs.getConstArray()[1] >>= loaderServiceName;
1430 }
1431 if( loaderServiceName.isEmpty() ) {
1432 OUStringBuffer buf;
1433 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]))-1)
1434 "ImplementationRegistration::initialize() invalid second parameter,"(&("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]))-1)
1435 "expected string, got " )(&("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid second parameter,"
"expected string, got ")[0]))-1)
);
1436 buf.append( aArgs.getConstArray()[1].getValueTypeName() );
1437 throw IllegalArgumentException( buf.makeStringAndClear(),
1438 Reference< XInterface > (),
1439 0 );
1440 }
1441
1442 // 3rd argument : The file name of the dll, that contains the loader
1443 if( aArgs.getConstArray()[2].getValueType().getTypeClass() == TypeClass_STRING ) {
1444 aArgs.getConstArray()[2] >>= locationUrl;
1445 }
1446 if( locationUrl.isEmpty() ) {
1447 OUStringBuffer buf;
1448 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]))-1)
1449 "ImplementationRegistration::initialize() invalid third parameter,"(&("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]))-1)
1450 "expected string, got " )(&("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ") / sizeof (("ImplementationRegistration::initialize() invalid third parameter,"
"expected string, got ")[0]))-1)
);
1451 buf.append( aArgs.getConstArray()[2].getValueTypeName() );
1452 throw IllegalArgumentException( buf.makeStringAndClear(),
1453 Reference< XInterface > (),
1454 0 );
1455 }
1456
1457 // 4th argument : The registry, the service should be written to
1458 if( aArgs.getConstArray()[3].getValueType().getTypeClass() == TypeClass_INTERFACE ) {
1459 aArgs.getConstArray()[3] >>= rReg;
1460 }
1461
1462 if( !rReg.is() ) {
1463 rReg = getRegistryFromServiceManager();
1464 if( !rReg.is() ) {
1465 OUStringBuffer buf;
1466 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]))-1)
1467 "ImplementationRegistration::initialize() invalid fourth parameter,"(&("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]))-1)
1468 "expected " )(&("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]), ((sal_Int32)(sizeof ("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ") / sizeof (("ImplementationRegistration::initialize() invalid fourth parameter,"
"expected ")[0]))-1)
);
1469 buf.append( getCppuType( &rReg ).getTypeName() );
1470 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(", got " )(&(", got ")[0]), ((sal_Int32)(sizeof (", got ") / sizeof
((", got ")[0]))-1)
);
1471 buf.append( aArgs.getConstArray()[3].getValueTypeName() );
1472 throw IllegalArgumentException( buf.makeStringAndClear(),
1473 Reference< XInterface > (),
1474 0 );
1475 }
1476 }
1477
1478 doRegister(m_xSMgr, m_xCtx, rLoader , rReg, loaderServiceName , locationUrl, locationUrl);
1479}
1480
1481
1482
1483//*************************************************************************
1484// virtual function registerImplementationWithLocation of XImplementationRegistration2
1485//
1486void ImplementationRegistration::registerImplementationWithLocation(
1487 const OUString& implementationLoaderUrl,
1488 const OUString& locationUrl,
1489 const OUString& registeredLocationUrl,
1490 const Reference < XSimpleRegistry > & xReg)
1491 throw( CannotRegisterImplementationException, RuntimeException )
1492{
1493 prepareRegister(
1494 implementationLoaderUrl, locationUrl, registeredLocationUrl, xReg);
1495}
1496
1497// helper function
1498void ImplementationRegistration::prepareRegister(
1499 const OUString& implementationLoaderUrl,
1500 const OUString& locationUrl,
1501 const OUString& registeredLocationUrl,
1502 const Reference < XSimpleRegistry > & xReg)
1503 // throw( CannotRegisterImplementationException, RuntimeException )
1504{
1505 OUString implLoaderUrl(implementationLoaderUrl);
1506 OUString activatorName;
1507
1508 if (!implementationLoaderUrl.isEmpty())
1509 {
1510 OUString tmpActivator(implementationLoaderUrl);
1511 sal_Int32 nIndex = 0;
1512 activatorName = tmpActivator.getToken(0, ':', nIndex );
1513 } else
1514 {
1515 // check locationUrl to find out what kind of loader is needed
1516 // set iimplLoaderUrl
1517 }
1518
1519 if( m_xSMgr.is() ) {
1520 try
1521 {
1522 Reference < XImplementationLoader > xAct(
1523 m_xSMgr->createInstanceWithContext(activatorName, m_xCtx) , UNO_QUERY );
1524 if (xAct.is())
1525 {
1526 Reference < XSimpleRegistry > xRegistry;
1527
1528 if (xReg.is())
1529 {
1530 // registry supplied by user
1531 xRegistry = xReg;
1532 }
1533 else
1534 {
1535 xRegistry = getRegistryFromServiceManager();
1536 }
1537
1538 if ( xRegistry.is())
1539 {
1540 doRegister(m_xSMgr, m_xCtx, xAct, xRegistry, implLoaderUrl,
1541 locationUrl, registeredLocationUrl);
1542 }
1543 }
1544 else
1545 {
1546 OUStringBuffer buf( 128 );
1547 buf.appendAscii( "ImplementationRegistration::registerImplementation() - The service " );
1548 buf.append( activatorName );
1549 buf.appendAscii( " cannot be instantiated\n" );
1550 throw CannotRegisterImplementationException(
1551 buf.makeStringAndClear(), Reference< XInterface > () );
1552 }
1553 }
1554 catch( CannotRegisterImplementationException & )
1555 {
1556 throw;
1557 }
1558 catch( const InvalidRegistryException & e )
1559 {
1560 OUStringBuffer buf;
1561 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (") / sizeof (
("ImplementationRegistration::registerImplementation() " "InvalidRegistryException during registration ("
)[0]))-1)
1562 "ImplementationRegistration::registerImplementation() "(&("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (") / sizeof (
("ImplementationRegistration::registerImplementation() " "InvalidRegistryException during registration ("
)[0]))-1)
1563 "InvalidRegistryException during registration (" )(&("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"InvalidRegistryException during registration (") / sizeof (
("ImplementationRegistration::registerImplementation() " "InvalidRegistryException during registration ("
)[0]))-1)
);
1564 buf.append( e.Message );
1565 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" )(&(")")[0]), ((sal_Int32)(sizeof (")") / sizeof ((")")[0]
))-1)
);
1566 throw CannotRegisterImplementationException(
1567 buf.makeStringAndClear(), Reference< XInterface > () );
1568 }
1569 catch( const MergeConflictException & e )
1570 {
1571 OUStringBuffer buf;
1572 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM((&("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (") / sizeof (("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]))-1)
1573 "ImplementationRegistration::registerImplementation() "(&("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (") / sizeof (("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]))-1)
1574 "MergeConflictException during registration (" )(&("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]), ((sal_Int32
)(sizeof ("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (") / sizeof (("ImplementationRegistration::registerImplementation() "
"MergeConflictException during registration (")[0]))-1)
);
1575 buf.append( e.Message );
1576 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( ")" )(&(")")[0]), ((sal_Int32)(sizeof (")") / sizeof ((")")[0]
))-1)
);
1577 throw CannotRegisterImplementationException(
1578 buf.makeStringAndClear(), Reference< XInterface > () );
1579 }
1580 }
1581 else
1582 {
1583 throw CannotRegisterImplementationException(
1584 OUString(RTL_CONSTASCII_USTRINGPARAM((&("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader")[0]), (
(sal_Int32)((sizeof ("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader") / sizeof
(("ImplementationRegistration::registerImplementation() " "no componentcontext available to instantiate loader"
)[0]))-1)), (((rtl_TextEncoding) 11))
1585 "ImplementationRegistration::registerImplementation() "(&("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader")[0]), (
(sal_Int32)((sizeof ("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader") / sizeof
(("ImplementationRegistration::registerImplementation() " "no componentcontext available to instantiate loader"
)[0]))-1)), (((rtl_TextEncoding) 11))
1586 "no componentcontext available to instantiate loader")(&("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader")[0]), (
(sal_Int32)((sizeof ("ImplementationRegistration::registerImplementation() "
"no componentcontext available to instantiate loader") / sizeof
(("ImplementationRegistration::registerImplementation() " "no componentcontext available to instantiate loader"
)[0]))-1)), (((rtl_TextEncoding) 11))
),
1587 Reference< XInterface > () );
1588 }
1589}
1590
1591//*************************************************************************
1592// virtual function registerImplementation of XImplementationRegistration
1593//
1594void ImplementationRegistration::registerImplementation(
1595 const OUString& implementationLoaderUrl,
1596 const OUString& locationUrl,
1597 const Reference < XSimpleRegistry > & xReg)
1598 throw( CannotRegisterImplementationException, RuntimeException )
1599{
1600 prepareRegister(implementationLoaderUrl, locationUrl, locationUrl, xReg);
1601}
1602
1603
1604//*************************************************************************
1605// virtual function revokeImplementation of XImplementationRegistration
1606//
1607sal_Bool ImplementationRegistration::revokeImplementation(const OUString& location,
1608 const Reference < XSimpleRegistry >& xReg)
1609 throw ( RuntimeException )
1610{
1611 sal_Bool ret = sal_False((sal_Bool)0);
1612
1613 Reference < XSimpleRegistry > xRegistry;
1614
1615 if (xReg.is()) {
1616 xRegistry = xReg;
1617 }
1618 else {
1619 Reference < XPropertySet > xPropSet = Reference< XPropertySet >::query( m_xSMgr );
1620 if( xPropSet.is() ) {
1621 try {
1622 Any aAny = xPropSet->getPropertyValue( spool().Registry );
1623
1624 if( aAny.getValueType().getTypeClass() == TypeClass_INTERFACE )
1625 {
1626 aAny >>= xRegistry;
1627 }
1628 }
1629 catch ( UnknownPropertyException & ) {
1630 }
1631 }
1632 }
1633
1634 if (xRegistry.is())
1635 {
1636 try
1637 {
1638 doRevoke(xRegistry, location);
1639 ret = sal_True((sal_Bool)1);
1640 }
1641 catch( InvalidRegistryException & )
1642 {
1643 // no way to transport the error, as no exception is specified and a runtime
1644 // exception is not appropriate.
1645 OSL_FAIL( "InvalidRegistryException during revokeImplementation" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/implementationregistration/implreg.cxx"
":" "1645" ": "), "%s", "InvalidRegistryException during revokeImplementation"
); } } while (false)
;
1646 }
1647 }
1648
1649 return ret;
1650}
1651
1652//*************************************************************************
1653// virtual function getImplementations of XImplementationRegistration
1654//
1655Sequence< OUString > ImplementationRegistration::getImplementations(
1656 const OUString & implementationLoaderUrl,
1657 const OUString & locationUrl)
1658 throw ( RuntimeException )
1659{
1660 OUString implLoaderUrl(implementationLoaderUrl);
1661 OUString activatorName;
1662
1663 if (!implementationLoaderUrl.isEmpty())
1
Taking false branch
1664 {
1665 OUString tmpActivator(implementationLoaderUrl);
1666 sal_Int32 nIndex = 0;
1667 activatorName = tmpActivator.getToken(0, ':', nIndex );
1668 } else
1669 {
1670 // check locationUrl to find out what kind of loader is needed
1671 // set implLoaderUrl
1672 }
1673
1674 if( m_xSMgr.is() ) {
2
Taking true branch
1675
1676 Reference < XImplementationLoader > xAct(
1677 m_xSMgr->createInstanceWithContext( activatorName, m_xCtx ), UNO_QUERY );
1678
1679 if (xAct.is())
3
Taking true branch
1680 {
1681
1682 Reference < XSimpleRegistry > xReg =
1683 createTemporarySimpleRegistry( m_xSMgr, m_xCtx);
1684
1685 if (xReg.is())
4
Taking true branch
1686 {
1687 try
1688 {
1689 xReg->open(OUString() /* in mem */, sal_False((sal_Bool)0), sal_True((sal_Bool)1));
1690 Reference < XRegistryKey > xImpl;
1691
1692 { // only necessary for deleting the temporary variable of rootkey
1693 xImpl = xReg->getRootKey()->createKey( spool().slash_IMPLEMENTATIONS );
1694 }
1695 if (xAct->writeRegistryInfo(xImpl, implementationLoaderUrl, locationUrl))
5
Taking true branch
1696 {
1697 std::list <OUString> implNames;
1698
1699 findImplementations(xImpl, implNames);
1700
1701 if (!implNames.empty())
6
Taking true branch
1702 {
1703 std::list<OUString>::const_iterator iter = implNames.begin();
1704
1705 Sequence<OUString> seqImpl(implNames.size());
1706 OUString *pImplNames = seqImpl.getArray();
1707
1708 sal_Int32 index = 0;
1709 while (iter != implNames.end())
7
Loop condition is false. Execution continues on line 1716
1710 {
1711 pImplNames[index] = *iter;
1712 index++;
1713 ++iter;
1714 }
1715
1716 xImpl->closeKey();
8
Called C++ object pointer is null
1717 return seqImpl;
1718 }
1719 }
1720
1721 xImpl->closeKey();
1722 }
1723 catch(MergeConflictException&)
1724 {
1725 }
1726 catch(InvalidRegistryException&)
1727 {
1728 }
1729 }
1730 }
1731 }
1732
1733 return Sequence<OUString>();
1734}
1735
1736//*************************************************************************
1737// virtual function checkInstantiation of XImplementationRegistration
1738//
1739Sequence< OUString > ImplementationRegistration::checkInstantiation(const OUString&)
1740 throw ( RuntimeException )
1741{
1742 OSL_FAIL( "ImplementationRegistration::checkInstantiation not implemented" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/implementationregistration/implreg.cxx"
":" "1742" ": "), "%s", "ImplementationRegistration::checkInstantiation not implemented"
); } } while (false)
;
1743 return Sequence<OUString>();
1744}
1745
1746//*************************************************************************
1747// helper function doRegistration
1748//
1749
1750void ImplementationRegistration::doRevoke(
1751 const Reference < XSimpleRegistry >& xDest,
1752 const OUString& locationUrl)
1753 // throw ( InvalidRegistryException, RuntimeException )
1754{
1755 if( xDest.is() )
1756 {
1757 std::list<OUString> aNames;
1758
1759 const StringPool &pool = spool();
1760 Reference < XRegistryKey > xRootKey( xDest->getRootKey() );
1761
1762 Reference < XRegistryKey > xKey =
1763 xRootKey->openKey( pool.slash_IMPLEMENTATIONS );
1764 if (xKey.is() && xKey->isValid())
1765 {
1766 deleteAllImplementations(xDest, xKey, locationUrl, aNames);
1767 }
1768
1769 xKey = xRootKey->openKey( pool.slash_SERVICES );
1770 if (xKey.is())
1771 {
1772 std::list<OUString>::const_iterator iter = aNames.begin();
1773
1774 while (iter != aNames.end())
1775 {
1776 deleteAllServiceEntries(xDest, xKey, *iter);
1777 ++iter;
1778 }
1779 }
1780
1781 xKey = xRootKey->openKey( OUSTR("/SINGLETONS")::rtl::OUString( (&("/SINGLETONS")[0]), ((sal_Int32)((sizeof
("/SINGLETONS") / sizeof (("/SINGLETONS")[0]))-1)), (((rtl_TextEncoding
) 11)) )
);
1782 if (xKey.is() && xKey->isValid())
1783 {
1784 delete_all_singleton_entries( xKey, aNames );
1785 }
1786
1787 if (xRootKey.is())
1788 xRootKey->closeKey();
1789 if (xKey.is() && xKey->isValid() )
1790 xKey->closeKey();
1791 }
1792}
1793
1794void ImplementationRegistration::doRegister(
1795 const Reference< XMultiComponentFactory > & xSMgr,
1796 const Reference< XComponentContext > &xCtx,
1797 const Reference < XImplementationLoader > & xAct,
1798 const Reference < XSimpleRegistry >& xDest,
1799 const OUString& implementationLoaderUrl,
1800 const OUString& locationUrl,
1801 const OUString& registeredLocationUrl)
1802 /* throw ( InvalidRegistryException,
1803 MergeConflictException,
1804 CannotRegisterImplementationException, RuntimeException ) */
1805{
1806 Reference < XSimpleRegistry > xReg =
1807 createTemporarySimpleRegistry( xSMgr, xCtx );
1808 Reference < XRegistryKey > xSourceKey;
1809
1810 if (xAct.is() && xReg.is() && xDest.is())
1811 {
1812 try
1813 {
1814 xReg->open(OUString() /* in mem */, sal_False((sal_Bool)0), sal_True((sal_Bool)1));
1815
1816 { // only necessary for deleting the temporary variable of rootkey
1817 xSourceKey = xReg->getRootKey()->createKey( spool().slash_IMPLEMENTATIONS );
1818 }
1819
1820 sal_Bool bSuccess =
1821 xAct->writeRegistryInfo(xSourceKey, implementationLoaderUrl, locationUrl);
1822 if ( bSuccess )
1823 {
1824 prepareRegistry(xDest, xSourceKey, implementationLoaderUrl, registeredLocationUrl, xCtx);
1825
1826 xSourceKey->closeKey();
1827
1828 xSourceKey = xReg->getRootKey();
1829 Reference < XRegistryKey > xDestKey = xDest->getRootKey();
1830 mergeKeys( xDestKey, xSourceKey );
1831 xDestKey->closeKey();
1832 xSourceKey->closeKey();
1833 }
1834 else
1835 {
1836 throw CannotRegisterImplementationException(
1837 OUString( RTL_CONSTASCII_USTRINGPARAM( "ImplementationRegistration::doRegistration() component registration signaled failure" )(&("ImplementationRegistration::doRegistration() component registration signaled failure"
)[0]), ((sal_Int32)((sizeof ("ImplementationRegistration::doRegistration() component registration signaled failure"
) / sizeof (("ImplementationRegistration::doRegistration() component registration signaled failure"
)[0]))-1)), (((rtl_TextEncoding) 11))
),
1838 Reference< XInterface > () );
1839 }
1840
1841 // Cleanup Source registry.
1842 if ( xSourceKey->isValid() )
1843 xSourceKey->closeKey();
1844 }
1845 catch(CannotRegisterImplementationException&)
1846 {
1847 if ( xSourceKey->isValid() )
1848 xSourceKey->closeKey();
1849 // and throw again
1850 throw;
1851 }
1852 }
1853}
1854
1855
1856
1857Reference< XSimpleRegistry > ImplementationRegistration::createTemporarySimpleRegistry(
1858 const Reference< XMultiComponentFactory > &rSMgr,
1859 const Reference < XComponentContext > & xCtx)
1860{
1861
1862 Reference < XSimpleRegistry > xReg(
1863 rSMgr->createInstanceWithContext(
1864 spool().com_sun_star_registry_SimpleRegistry, xCtx ),
1865 UNO_QUERY);
1866 OSL_ASSERT( xReg.is() )do { if (true && (!(xReg.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/stoc/source/implementationregistration/implreg.cxx"
":" "1866" ": "), "OSL_ASSERT: %s", "xReg.is()"); } } while (
false)
;
1867 return xReg;
1868}
1869}
1870
1871namespace stoc_bootstrap
1872{
1873//*************************************************************************
1874Reference<XInterface> SAL_CALL ImplementationRegistration_CreateInstance(
1875 const Reference<XComponentContext> & xCtx ) // throw(Exception)
1876{
1877 return (XImplementationRegistration *)new stoc_impreg::ImplementationRegistration(xCtx);
1878}
1879
1880}
1881
1882/* vim:set shiftwidth=4 softtabstop=4 expandtab: */