Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "dp_component.hrc"
31 : : #include "dp_backend.h"
32 : : #include "dp_platform.hxx"
33 : : #include "dp_ucb.h"
34 : : #include "rtl/string.hxx"
35 : : #include "rtl/strbuf.hxx"
36 : : #include "rtl/ustrbuf.hxx"
37 : : #include "rtl/uri.hxx"
38 : : #include "cppuhelper/exc_hlp.hxx"
39 : : #include "ucbhelper/content.hxx"
40 : : #include "comphelper/anytostring.hxx"
41 : : #include "comphelper/servicedecl.hxx"
42 : : #include "comphelper/sequence.hxx"
43 : : #include "xmlscript/xml_helper.hxx"
44 : : #include "svl/inettype.hxx"
45 : : #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
46 : : #include "com/sun/star/container/XNameContainer.hpp"
47 : : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
48 : : #include "com/sun/star/container/XSet.hpp"
49 : : #include "com/sun/star/registry/XSimpleRegistry.hpp"
50 : : #include "com/sun/star/registry/XImplementationRegistration.hpp"
51 : : #include "com/sun/star/loader/XImplementationLoader.hpp"
52 : : #include "com/sun/star/io/XInputStream.hpp"
53 : : #include "com/sun/star/ucb/NameClash.hpp"
54 : : #include "com/sun/star/util/XMacroExpander.hpp"
55 : : #include <list>
56 : : #include <boost/unordered_map.hpp>
57 : : #include <vector>
58 : : #include <memory>
59 : : #include <algorithm>
60 : : #include "dp_compbackenddb.hxx"
61 : :
62 : : using namespace ::dp_misc;
63 : : using namespace ::com::sun::star;
64 : : using namespace ::com::sun::star::uno;
65 : : using namespace ::com::sun::star::ucb;
66 : : using ::rtl::OUString;
67 : : namespace css = com::sun::star;
68 : :
69 : : namespace dp_registry {
70 : : namespace backend {
71 : : namespace component {
72 : : namespace {
73 : :
74 : : typedef ::std::list<OUString> t_stringlist;
75 : : typedef ::std::vector< ::std::pair<OUString, OUString> > t_stringpairvec;
76 : :
77 : : #define IMPLEMENTATION_NAME "com.sun.star.comp.deployment.component.PackageRegistryBackend"
78 : :
79 : : /** return a vector of bootstrap variables which have been provided
80 : : as command arguments.
81 : : */
82 : 2 : ::std::vector<OUString> getCmdBootstrapVariables()
83 : : {
84 : 2 : ::std::vector<OUString> ret;
85 [ + - ]: 2 : sal_uInt32 count = osl_getCommandArgCount();
86 [ + + ]: 20 : for (sal_uInt32 i = 0; i < count; i++)
87 : : {
88 : 18 : OUString arg;
89 [ + - ]: 18 : osl_getCommandArg(i, &arg.pData);
90 [ + + ]: 18 : if (arg.matchAsciiL("-env:", 5))
91 [ + - ]: 6 : ret.push_back(arg);
92 : 18 : }
93 : 2 : return ret;
94 : : }
95 : :
96 : 2 : bool jarManifestHeaderPresent(
97 : : OUString const & url, OUString const & name,
98 : : Reference<XCommandEnvironment> const & xCmdEnv )
99 : : {
100 : 2 : ::rtl::OUStringBuffer buf;
101 [ + - ]: 2 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip://") );
102 : : buf.append(
103 : : ::rtl::Uri::encode(
104 : : url, rtl_UriCharClassRegName, rtl_UriEncodeIgnoreEscapes,
105 [ + - ]: 2 : RTL_TEXTENCODING_UTF8 ) );
106 [ + - ]: 2 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/META-INF/MANIFEST.MF") );
107 [ + - ]: 2 : ::ucbhelper::Content manifestContent;
108 : 2 : OUString line;
109 : : return
110 : : create_ucb_content(
111 : : &manifestContent, buf.makeStringAndClear(), xCmdEnv,
112 [ + - ][ + - ]: 4 : false /* no throw */ )
[ # # ][ + - ]
113 [ + - ][ + - ]: 4 : && readLine( &line, name, manifestContent, RTL_TEXTENCODING_ASCII_US );
[ - + ][ + - ]
114 : : }
115 : :
116 : : //==============================================================================
117 [ + - ][ + - ]: 380 : class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
[ + - ][ - + ]
118 : : {
119 [ - + ]: 252 : class ComponentPackageImpl : public ::dp_registry::backend::Package
120 : : {
121 : : BackendImpl * getMyBackend() const;
122 : :
123 : : const OUString m_loader;
124 : :
125 : : enum reg {
126 : : REG_UNINIT, REG_VOID, REG_REGISTERED, REG_NOT_REGISTERED, REG_MAYBE_REGISTERED
127 : : } m_registered;
128 : :
129 : : void getComponentInfo(
130 : : ComponentBackendDb::Data * data,
131 : : std::vector< css::uno::Reference< css::uno::XInterface > > *
132 : : factories,
133 : : Reference<XComponentContext> const & xContext );
134 : :
135 : : void componentLiveInsertion(
136 : : ComponentBackendDb::Data const & data,
137 : : std::vector< css::uno::Reference< css::uno::XInterface > > const &
138 : : factories);
139 : :
140 : : void componentLiveRemoval(ComponentBackendDb::Data const & data);
141 : :
142 : : virtual void SAL_CALL disposing();
143 : :
144 : : // Package
145 : : virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
146 : : ::osl::ResettableMutexGuard & guard,
147 : : ::rtl::Reference<AbortChannel> const & abortChannel,
148 : : Reference<XCommandEnvironment> const & xCmdEnv );
149 : : virtual void processPackage_(
150 : : ::osl::ResettableMutexGuard & guard,
151 : : bool registerPackage,
152 : : bool startup,
153 : : ::rtl::Reference<AbortChannel> const & abortChannel,
154 : : Reference<XCommandEnvironment> const & xCmdEnv );
155 : :
156 : : const Reference<registry::XSimpleRegistry> getRDB() const;
157 : :
158 : : public:
159 : : ComponentPackageImpl(
160 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
161 : : OUString const & url, OUString const & name,
162 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
163 : : OUString const & loader, bool bRemoved,
164 : : OUString const & identifier);
165 : : };
166 : : friend class ComponentPackageImpl;
167 : :
168 [ - + ]: 1240 : class ComponentsPackageImpl : public ::dp_registry::backend::Package
169 : : {
170 : : BackendImpl * getMyBackend() const;
171 : :
172 : : // Package
173 : : virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
174 : : ::osl::ResettableMutexGuard & guard,
175 : : ::rtl::Reference<AbortChannel> const & abortChannel,
176 : : Reference<XCommandEnvironment> const & xCmdEnv );
177 : : virtual void processPackage_(
178 : : ::osl::ResettableMutexGuard & guard,
179 : : bool registerPackage,
180 : : bool startup,
181 : : ::rtl::Reference<AbortChannel> const & abortChannel,
182 : : Reference<XCommandEnvironment> const & xCmdEnv );
183 : : public:
184 : : ComponentsPackageImpl(
185 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
186 : : OUString const & url, OUString const & name,
187 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
188 : : bool bRemoved, OUString const & identifier);
189 : : };
190 : : friend class ComponentsPackageImpl;
191 : :
192 [ # # ]: 0 : class TypelibraryPackageImpl : public ::dp_registry::backend::Package
193 : : {
194 : : BackendImpl * getMyBackend() const;
195 : :
196 : : const bool m_jarFile;
197 : : Reference<container::XHierarchicalNameAccess> m_xTDprov;
198 : :
199 : : virtual void SAL_CALL disposing();
200 : :
201 : : // Package
202 : : virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
203 : : ::osl::ResettableMutexGuard & guard,
204 : : ::rtl::Reference<AbortChannel> const & abortChannel,
205 : : Reference<XCommandEnvironment> const & xCmdEnv );
206 : : virtual void processPackage_(
207 : : ::osl::ResettableMutexGuard & guard,
208 : : bool registerPackage,
209 : : bool startup,
210 : : ::rtl::Reference<AbortChannel> const & abortChannel,
211 : : Reference<XCommandEnvironment> const & xCmdEnv );
212 : :
213 : : public:
214 : : TypelibraryPackageImpl(
215 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
216 : : OUString const & url, OUString const & name,
217 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
218 : : bool jarFile, bool bRemoved,
219 : : OUString const & identifier);
220 : : };
221 : : friend class TypelibraryPackageImpl;
222 : :
223 : : /** Serves for unregistering packages that were registered on a
224 : : different platform. This can happen if one has remotely mounted
225 : : /home, for example.
226 : : */
227 [ # # ]: 0 : class OtherPlatformPackageImpl : public ::dp_registry::backend::Package
228 : : {
229 : : public:
230 : : OtherPlatformPackageImpl(
231 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
232 : : OUString const & url, OUString const & name,
233 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
234 : : bool bRemoved, OUString const & identifier, OUString const& rPlatform);
235 : :
236 : : private:
237 : : BackendImpl * getMyBackend() const;
238 : :
239 : : const Reference<registry::XSimpleRegistry> impl_openRDB() const;
240 : : const Reference<XInterface> impl_createInstance(OUString const& rService) const;
241 : :
242 : : // Package
243 : : virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
244 : : ::osl::ResettableMutexGuard & guard,
245 : : ::rtl::Reference<AbortChannel> const & abortChannel,
246 : : Reference<XCommandEnvironment> const & xCmdEnv );
247 : : virtual void processPackage_(
248 : : ::osl::ResettableMutexGuard & guard,
249 : : bool registerPackage,
250 : : bool startup,
251 : : ::rtl::Reference<AbortChannel> const & abortChannel,
252 : : Reference<XCommandEnvironment> const & xCmdEnv );
253 : :
254 : : private:
255 : : OUString const m_aPlatform;
256 : : };
257 : : friend class OtherPlatformPackageImpl;
258 : :
259 : : t_stringlist m_jar_typelibs;
260 : : t_stringlist m_rdb_typelibs;
261 : : t_stringlist m_components;
262 : :
263 : : enum RcItem { RCITEM_JAR_TYPELIB, RCITEM_RDB_TYPELIB, RCITEM_COMPONENTS };
264 : :
265 : 1980 : t_stringlist & getRcItemList( RcItem kind ) {
266 [ + - + ]: 1980 : switch (kind)
267 : : {
268 : : case RCITEM_JAR_TYPELIB:
269 : 4 : return m_jar_typelibs;
270 : : case RCITEM_RDB_TYPELIB:
271 : 0 : return m_rdb_typelibs;
272 : : default: // case RCITEM_COMPONENTS
273 : 1980 : return m_components;
274 : : }
275 : : }
276 : :
277 : : bool m_unorc_inited;
278 : : bool m_unorc_modified;
279 : : bool bSwitchedRdbFiles;
280 : :
281 : : typedef ::boost::unordered_map< OUString, Reference<XInterface>,
282 : : ::rtl::OUStringHash > t_string2object;
283 : : t_string2object m_backendObjects;
284 : :
285 : : // PackageRegistryBackend
286 : : virtual Reference<deployment::XPackage> bindPackage_(
287 : : OUString const & url, OUString const & mediaType,
288 : : sal_Bool bRemoved, OUString const & identifier,
289 : : Reference<XCommandEnvironment> const & xCmdEnv );
290 : :
291 : : virtual void SAL_CALL disposing();
292 : :
293 : : const Reference<deployment::XPackageTypeInfo> m_xDynComponentTypeInfo;
294 : : const Reference<deployment::XPackageTypeInfo> m_xJavaComponentTypeInfo;
295 : : const Reference<deployment::XPackageTypeInfo> m_xPythonComponentTypeInfo;
296 : : const Reference<deployment::XPackageTypeInfo> m_xComponentsTypeInfo;
297 : : const Reference<deployment::XPackageTypeInfo> m_xRDBTypelibTypeInfo;
298 : : const Reference<deployment::XPackageTypeInfo> m_xJavaTypelibTypeInfo;
299 : : Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
300 : :
301 : : OUString m_commonRDB;
302 : : OUString m_nativeRDB;
303 : :
304 : : //URLs of the original rdbs (before any switching):
305 : : OUString m_commonRDB_orig;
306 : : OUString m_nativeRDB_orig;
307 : :
308 : : std::auto_ptr<ComponentBackendDb> m_backendDb;
309 : :
310 : : void addDataToDb(OUString const & url, ComponentBackendDb::Data const & data);
311 : : ComponentBackendDb::Data readDataFromDb(OUString const & url);
312 : : void revokeEntryFromDb(OUString const & url);
313 : :
314 : : Reference<registry::XSimpleRegistry> m_xCommonRDB;
315 : : Reference<registry::XSimpleRegistry> m_xNativeRDB;
316 : :
317 : : void unorc_verify_init( Reference<XCommandEnvironment> const & xCmdEnv );
318 : : void unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv );
319 : :
320 : : Reference<XInterface> getObject( OUString const & id );
321 : : Reference<XInterface> insertObject(
322 : : OUString const & id, Reference<XInterface> const & xObject );
323 : : void releaseObject( OUString const & id );
324 : :
325 : : bool addToUnoRc( RcItem kind, OUString const & url,
326 : : Reference<XCommandEnvironment> const & xCmdEnv );
327 : : bool removeFromUnoRc( RcItem kind, OUString const & url,
328 : : Reference<XCommandEnvironment> const & xCmdEnv );
329 : : bool hasInUnoRc( RcItem kind, OUString const & url );
330 : :
331 : : css::uno::Reference< css::uno::XComponentContext > getRootContext() const;
332 : :
333 : : public:
334 : : BackendImpl( Sequence<Any> const & args,
335 : : Reference<XComponentContext> const & xComponentContext );
336 : :
337 : : // XPackageRegistry
338 : : virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
339 : : getSupportedPackageTypes() throw (RuntimeException);
340 : :
341 : : virtual void SAL_CALL packageRemoved(OUString const & url, OUString const & mediaType)
342 : : throw (deployment::DeploymentException,
343 : : uno::RuntimeException);
344 : :
345 : : using PackageRegistryBackend::disposing;
346 : :
347 : : //Will be called from ComponentPackageImpl
348 : : void initServiceRdbFiles();
349 : : };
350 : :
351 : : //______________________________________________________________________________
352 : :
353 : 126 : BackendImpl::ComponentPackageImpl::ComponentPackageImpl(
354 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
355 : : OUString const & url, OUString const & name,
356 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
357 : : OUString const & loader, bool bRemoved,
358 : : OUString const & identifier)
359 : : : Package( myBackend, url, name, name /* display-name */,
360 : : xPackageType, bRemoved, identifier),
361 : : m_loader( loader ),
362 : 126 : m_registered( REG_UNINIT )
363 : 126 : {}
364 : :
365 : : const Reference<registry::XSimpleRegistry>
366 : 192 : BackendImpl::ComponentPackageImpl::getRDB() const
367 : : {
368 : 192 : BackendImpl * that = getMyBackend();
369 : :
370 : : //Late "initialization" of the services rdb files
371 : : //This is to prevent problems when running several
372 : : //instances of OOo with root rights in parallel. This
373 : : //would otherwise cause problems when copying the rdbs.
374 : : //See http://qa.openoffice.org/issues/show_bug.cgi?id=99257
375 : : {
376 [ + - ]: 192 : const ::osl::MutexGuard guard( getMutex() );
377 [ + + ]: 192 : if (!that->bSwitchedRdbFiles)
378 : : {
379 : 126 : that->bSwitchedRdbFiles = true;
380 [ + - ]: 126 : that->initServiceRdbFiles();
381 [ + - ]: 192 : }
382 : : }
383 [ - + ]: 192 : if ( m_loader == "com.sun.star.loader.SharedLibrary" )
384 : 0 : return that->m_xNativeRDB;
385 : : else
386 : 192 : return that->m_xCommonRDB;
387 : : }
388 : :
389 : 264 : BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend() const
390 : : {
391 : 264 : BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
392 [ - + ]: 264 : if (NULL == pBackend)
393 : : {
394 : : //Throws a DisposedException
395 : 0 : check();
396 : : //We should never get here...
397 : : throw RuntimeException(
398 : : OUSTR("Failed to get the BackendImpl"),
399 [ # # ][ # # ]: 0 : static_cast<OWeakObject*>(const_cast<ComponentPackageImpl *>(this)));
[ # # ]
400 : : }
401 : 264 : return pBackend;
402 : : }
403 : :
404 : :
405 : : //______________________________________________________________________________
406 : 126 : void BackendImpl::ComponentPackageImpl::disposing()
407 : : {
408 : 126 : Package::disposing();
409 : 126 : }
410 : :
411 : : //______________________________________________________________________________
412 : 0 : void BackendImpl::TypelibraryPackageImpl::disposing()
413 : : {
414 : 0 : m_xTDprov.clear();
415 : 0 : Package::disposing();
416 : 0 : }
417 : :
418 : : //______________________________________________________________________________
419 : 380 : void BackendImpl::disposing()
420 : : {
421 : : try {
422 [ + - ][ + - ]: 380 : m_backendObjects = t_string2object();
[ + - ]
423 [ + + ]: 380 : if (m_xNativeRDB.is()) {
424 [ + - ][ + - ]: 126 : m_xNativeRDB->close();
425 : 126 : m_xNativeRDB.clear();
426 : : }
427 [ + + ]: 380 : if (m_xCommonRDB.is()) {
428 [ + - ][ + - ]: 126 : m_xCommonRDB->close();
429 : 126 : m_xCommonRDB.clear();
430 : : }
431 [ + - ]: 380 : unorc_flush( Reference<XCommandEnvironment>() );
432 : :
433 [ + - ]: 380 : PackageRegistryBackend::disposing();
434 : : }
435 : 0 : catch (const RuntimeException &) {
436 : 0 : throw;
437 : : }
438 [ # # # ]: 0 : catch (const Exception &) {
439 [ # # ]: 0 : Any exc( ::cppu::getCaughtException() );
440 : : throw lang::WrappedTargetRuntimeException(
441 : : OUSTR("caught unexpected exception while disposing..."),
442 [ # # # # : 0 : static_cast<OWeakObject *>(this), exc );
# # ]
443 : : }
444 : 380 : }
445 : :
446 : :
447 : 126 : void BackendImpl::initServiceRdbFiles()
448 : : {
449 : 126 : const Reference<XCommandEnvironment> xCmdEnv;
450 : :
451 [ + - ]: 126 : ::ucbhelper::Content cacheDir( getCachePath(), xCmdEnv );
452 [ + - ]: 126 : ::ucbhelper::Content oldRDB;
453 : : // switch common rdb:
454 [ + + ]: 126 : if (!m_commonRDB_orig.isEmpty())
455 : : {
456 : : create_ucb_content(
457 : 62 : &oldRDB, makeURL( getCachePath(), m_commonRDB_orig),
458 [ + - ][ + - ]: 62 : xCmdEnv, false /* no throw */ );
459 : : }
460 [ + + ][ + - ]: 126 : m_commonRDB = m_commonRDB_orig == "common.rdb" ? OUSTR("common_.rdb") : OUSTR("common.rdb");
[ + - ]
461 [ + + ][ + - ]: 126 : if (oldRDB.get().is())
462 : : {
463 [ - + ]: 62 : if (! cacheDir.transferContent(
464 : : oldRDB, ::ucbhelper::InsertOperation_COPY,
465 [ + - ]: 62 : m_commonRDB, NameClash::OVERWRITE ))
466 : : {
467 : :
468 : : throw RuntimeException(
469 [ # # ][ # # ]: 0 : OUSTR("UCB transferContent() failed!"), 0 );
[ # # ]
470 : : }
471 [ + - ][ + - ]: 62 : oldRDB = ::ucbhelper::Content();
[ + - ]
472 : : }
473 : : // switch native rdb:
474 [ + + ]: 126 : if (!m_nativeRDB_orig.isEmpty())
475 : : {
476 : : create_ucb_content(
477 : 62 : &oldRDB, makeURL(getCachePath(), m_nativeRDB_orig),
478 [ + - ][ + - ]: 62 : xCmdEnv, false /* no throw */ );
479 : : }
480 [ + - ][ + - ]: 126 : const OUString plt_rdb( getPlatformString() + OUSTR(".rdb") );
481 [ + - ][ + - ]: 126 : const OUString plt_rdb_( getPlatformString() + OUSTR("_.rdb") );
482 [ + + ]: 126 : m_nativeRDB = m_nativeRDB_orig.equals( plt_rdb ) ? plt_rdb_ : plt_rdb;
483 [ + + ][ + - ]: 126 : if (oldRDB.get().is())
484 : : {
485 [ - + ]: 62 : if (! cacheDir.transferContent(
486 : : oldRDB, ::ucbhelper::InsertOperation_COPY,
487 [ + - ]: 62 : m_nativeRDB, NameClash::OVERWRITE ))
488 : : throw RuntimeException(
489 [ # # ][ # # ]: 0 : OUSTR("UCB transferContent() failed!"), 0 );
[ # # ]
490 : : }
491 : :
492 : : // UNO is bootstrapped, flush for next process start:
493 : 126 : m_unorc_modified = true;
494 [ + - ]: 126 : unorc_flush( Reference<XCommandEnvironment>() );
495 : :
496 : :
497 : : // common rdb for java, native rdb for shared lib components
498 [ + - ]: 126 : if (!m_commonRDB.isEmpty()) {
499 : : m_xCommonRDB.set(
500 [ + - ]: 126 : m_xComponentContext->getServiceManager()
501 [ + - ][ + - ]: 252 : ->createInstanceWithContext(
502 : : OUSTR("com.sun.star.registry.SimpleRegistry"),
503 [ + - ][ + - ]: 126 : m_xComponentContext ), UNO_QUERY_THROW );
[ + - ]
504 [ + - ]: 126 : m_xCommonRDB->open(
505 : 126 : makeURL( expandUnoRcUrl(getCachePath()), m_commonRDB ),
506 [ + - ][ + - ]: 126 : false, true);
[ + - ]
507 : : }
508 [ + - ]: 126 : if (!m_nativeRDB.isEmpty()) {
509 : : m_xNativeRDB.set(
510 [ + - ]: 126 : m_xComponentContext->getServiceManager()
511 [ + - ][ + - ]: 252 : ->createInstanceWithContext(
512 : : OUSTR("com.sun.star.registry.SimpleRegistry"),
513 [ + - ][ + - ]: 126 : m_xComponentContext ), UNO_QUERY_THROW );
[ + - ]
514 [ + - ]: 126 : m_xNativeRDB->open(
515 : 126 : makeURL( expandUnoRcUrl(getCachePath()), m_nativeRDB ),
516 [ + - ][ + - ]: 126 : false, true);
[ + - ]
517 [ + - ][ + - ]: 126 : }
518 : 126 : }
519 : :
520 : 380 : BackendImpl::BackendImpl(
521 : : Sequence<Any> const & args,
522 : : Reference<XComponentContext> const & xComponentContext )
523 : : : PackageRegistryBackend( args, xComponentContext ),
524 : : m_unorc_inited( false ),
525 : : m_unorc_modified( false ),
526 : : bSwitchedRdbFiles(false),
527 : : m_xDynComponentTypeInfo( new Package::TypeInfo(
528 : : OUSTR("application/"
529 : : "vnd.sun.star.uno-component;"
530 : : "type=native;platform=") +
531 [ + - ]: 380 : getPlatformString(),
532 : : OUSTR("*" SAL_DLLEXTENSION),
533 : : getResourceString(RID_STR_DYN_COMPONENT),
534 [ + - ]: 380 : RID_IMG_COMPONENT) ),
535 : : m_xJavaComponentTypeInfo( new Package::TypeInfo(
536 : : OUSTR("application/"
537 : : "vnd.sun.star.uno-component;"
538 : : "type=Java"),
539 : : OUSTR("*.jar"),
540 : : getResourceString(RID_STR_JAVA_COMPONENT),
541 [ + - ]: 380 : RID_IMG_JAVA_COMPONENT) ),
542 : : m_xPythonComponentTypeInfo( new Package::TypeInfo(
543 : : OUSTR("application/"
544 : : "vnd.sun.star.uno-component;"
545 : : "type=Python"),
546 : : OUSTR("*.py"),
547 : : getResourceString(
548 : : RID_STR_PYTHON_COMPONENT),
549 [ + - ]: 380 : RID_IMG_COMPONENT ) ),
550 : : m_xComponentsTypeInfo( new Package::TypeInfo(
551 : : OUSTR("application/"
552 : : "vnd.sun.star.uno-components"),
553 : : OUSTR("*.components"),
554 : : getResourceString(RID_STR_COMPONENTS),
555 [ + - ]: 380 : RID_IMG_COMPONENT ) ),
556 : : m_xRDBTypelibTypeInfo( new Package::TypeInfo(
557 : : OUSTR("application/"
558 : : "vnd.sun.star.uno-typelibrary;"
559 : : "type=RDB"),
560 : : OUSTR("*.rdb"),
561 : : getResourceString(RID_STR_RDB_TYPELIB),
562 [ + - ]: 380 : RID_IMG_TYPELIB ) ),
563 : : m_xJavaTypelibTypeInfo( new Package::TypeInfo(
564 : : OUSTR("application/"
565 : : "vnd.sun.star.uno-typelibrary;"
566 : : "type=Java"),
567 : : OUSTR("*.jar"),
568 : : getResourceString(RID_STR_JAVA_TYPELIB),
569 [ + - ]: 380 : RID_IMG_JAVA_TYPELIB ) ),
570 [ + - ][ + - ]: 3040 : m_typeInfos( 6 )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
571 : : {
572 [ + - ][ + - ]: 380 : m_typeInfos[ 0 ] = m_xDynComponentTypeInfo;
573 [ + - ][ + - ]: 380 : m_typeInfos[ 1 ] = m_xJavaComponentTypeInfo;
574 [ + - ][ + - ]: 380 : m_typeInfos[ 2 ] = m_xPythonComponentTypeInfo;
575 [ + - ][ + - ]: 380 : m_typeInfos[ 3 ] = m_xComponentsTypeInfo;
576 [ + - ][ + - ]: 380 : m_typeInfos[ 4 ] = m_xRDBTypelibTypeInfo;
577 [ + - ][ + - ]: 380 : m_typeInfos[ 5 ] = m_xJavaTypelibTypeInfo;
578 : :
579 : 380 : const Reference<XCommandEnvironment> xCmdEnv;
580 : :
581 [ - + ]: 380 : if (transientMode())
582 : : {
583 : : // in-mem rdbs:
584 : : // common rdb for java, native rdb for shared lib components
585 : : m_xCommonRDB.set(
586 [ # # ][ # # ]: 0 : xComponentContext->getServiceManager()->createInstanceWithContext(
[ # # ]
587 : : OUSTR("com.sun.star.registry.SimpleRegistry"),
588 [ # # ][ # # ]: 0 : xComponentContext ), UNO_QUERY_THROW );
[ # # ]
589 [ # # ]: 0 : m_xCommonRDB->open( OUString() /* in-mem */,
590 [ # # ]: 0 : false /* ! read-only */, true /* create */ );
591 : : m_xNativeRDB.set(
592 [ # # ][ # # ]: 0 : xComponentContext->getServiceManager()->createInstanceWithContext(
[ # # ]
593 : : OUSTR("com.sun.star.registry.SimpleRegistry"),
594 [ # # ][ # # ]: 0 : xComponentContext ), UNO_QUERY_THROW );
[ # # ]
595 [ # # ]: 0 : m_xNativeRDB->open( OUString() /* in-mem */,
596 [ # # ]: 0 : false /* ! read-only */, true /* create */ );
597 : : }
598 : : else
599 : : {
600 [ + - ]: 380 : unorc_verify_init( xCmdEnv );
601 [ + - ][ + - ]: 380 : OUString dbFile = makeURL(getCachePath(), OUSTR("backenddb.xml"));
602 : : m_backendDb.reset(
603 [ + - ][ + - ]: 380 : new ComponentBackendDb(getComponentContext(), dbFile));
604 : 380 : }
605 : 380 : }
606 : :
607 : 64 : void BackendImpl::addDataToDb(
608 : : OUString const & url, ComponentBackendDb::Data const & data)
609 : : {
610 [ + - ]: 64 : if (m_backendDb.get())
611 : 64 : m_backendDb->addEntry(url, data);
612 : 64 : }
613 : :
614 : 2 : ComponentBackendDb::Data BackendImpl::readDataFromDb(OUString const & url)
615 : : {
616 : 2 : ComponentBackendDb::Data data;
617 [ + - ]: 2 : if (m_backendDb.get())
618 [ + - ][ + - ]: 2 : data = m_backendDb->getEntry(url);
619 : 2 : return data;
620 : : }
621 : :
622 : 2 : void BackendImpl::revokeEntryFromDb(OUString const & url)
623 : : {
624 [ + - ]: 2 : if (m_backendDb.get())
625 : 2 : m_backendDb->revokeEntry(url);
626 : 2 : }
627 : :
628 : : // XPackageRegistry
629 : : //______________________________________________________________________________
630 : : Sequence< Reference<deployment::XPackageTypeInfo> >
631 : 380 : BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
632 : : {
633 : 380 : return m_typeInfos;
634 : : }
635 : :
636 : 2 : void BackendImpl::packageRemoved(OUString const & url, OUString const & /*mediaType*/)
637 : : throw (deployment::DeploymentException,
638 : : uno::RuntimeException)
639 : : {
640 [ + - ]: 2 : if (m_backendDb.get())
641 : 2 : m_backendDb->removeEntry(url);
642 : 2 : }
643 : :
644 : : // PackageRegistryBackend
645 : : //______________________________________________________________________________
646 : 1246 : Reference<deployment::XPackage> BackendImpl::bindPackage_(
647 : : OUString const & url, OUString const & mediaType_,
648 : : sal_Bool bRemoved, OUString const & identifier,
649 : : Reference<XCommandEnvironment> const & xCmdEnv )
650 : : {
651 : 1246 : OUString mediaType(mediaType_);
652 [ + - ][ - + ]: 1246 : if ( mediaType.isEmpty() || mediaType == "application/vnd.sun.star.uno-component" || mediaType == "application/vnd.sun.star.uno-typelibrary" )
[ + + ][ + + ]
653 : : {
654 : : // detect exact media-type:
655 [ + - ]: 500 : ::ucbhelper::Content ucbContent;
656 [ + - ][ + - ]: 500 : if (create_ucb_content( &ucbContent, url, xCmdEnv )) {
657 [ + - ]: 500 : const OUString title( StrTitle::getTitle( ucbContent ) );
658 [ - + ]: 500 : if (title.endsWithIgnoreAsciiCaseAsciiL(
659 : : RTL_CONSTASCII_STRINGPARAM(SAL_DLLEXTENSION) ))
660 : : {
661 : : mediaType = OUSTR("application/vnd.sun.star.uno-component;"
662 : : "type=native;platform=") +
663 [ # # ][ # # ]: 0 : getPlatformString();
664 : : }
665 [ - + ]: 500 : else if (title.endsWithIgnoreAsciiCaseAsciiL(
666 : : RTL_CONSTASCII_STRINGPARAM(".jar") ))
667 : : {
668 [ # # # # ]: 0 : if (jarManifestHeaderPresent(
669 [ # # ]: 0 : url, OUSTR("RegistrationClassName"), xCmdEnv ))
670 [ # # ]: 0 : mediaType = OUSTR(
671 : 0 : "application/vnd.sun.star.uno-component;type=Java");
672 [ # # ]: 0 : if (mediaType.isEmpty())
673 [ # # ]: 0 : mediaType = OUSTR(
674 : 0 : "application/vnd.sun.star.uno-typelibrary;type=Java");
675 : : }
676 [ - + ]: 500 : else if (title.endsWithIgnoreAsciiCaseAsciiL(
677 : : RTL_CONSTASCII_STRINGPARAM(".py") ))
678 : : mediaType =
679 [ # # ]: 0 : OUSTR("application/vnd.sun.star.uno-component;type=Python");
680 [ - + ]: 500 : else if (title.endsWithIgnoreAsciiCaseAsciiL(
681 : : RTL_CONSTASCII_STRINGPARAM(".rdb") ))
682 : : mediaType =
683 [ # # ]: 500 : OUSTR("application/vnd.sun.star.uno-typelibrary;type=RDB");
684 : : }
685 [ + - ]: 500 : if (mediaType.isEmpty())
686 : : throw lang::IllegalArgumentException(
687 [ + - ]: 500 : StrCannotDetectMediaType::get() + url,
688 [ + - ][ + - ]: 1000 : static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
[ # # ]
689 : : }
690 : :
691 [ + - ][ + - ]: 746 : String type, subType;
692 [ + - ]: 746 : INetContentTypeParameterList params;
693 [ + - ][ + - ]: 746 : if (INetContentTypes::parse( mediaType, type, subType, ¶ms ))
[ + - ][ + - ]
694 : : {
695 [ + - ][ + - ]: 746 : if (type.EqualsIgnoreCaseAscii("application"))
696 : : {
697 : 746 : OUString name;
698 [ + - ]: 746 : if (!bRemoved)
699 : : {
700 [ + - ]: 746 : ::ucbhelper::Content ucbContent( url, xCmdEnv );
701 [ + - ][ + - ]: 746 : name = StrTitle::getTitle( ucbContent );
702 : : }
703 : :
704 [ + - ][ + + ]: 746 : if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.uno-component"))
705 : : {
706 : : // xxx todo: probe and evaluate component xml description
707 : :
708 : : INetContentTypeParameter const * param = params.find(
709 [ + - ]: 126 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("platform")));
710 : 126 : bool bPlatformFits(param == 0);
711 [ + - ]: 126 : String aPlatform;
712 [ - + ]: 126 : if (!bPlatformFits) // platform is specified, we have to check
713 : : {
714 [ # # ]: 0 : aPlatform = param->m_sValue;
715 [ # # ][ # # ]: 0 : bPlatformFits = platform_fits(aPlatform);
716 : : }
717 : : // If the package is being removed, do not care whether
718 : : // platform fits. We won't be using it anyway.
719 [ - + ][ # # ]: 126 : if (bPlatformFits || bRemoved) {
720 [ + - ]: 126 : param = params.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("type")));
721 [ + - ]: 126 : if (param != 0)
722 : : {
723 [ + - ]: 126 : String const & value = param->m_sValue;
724 [ + - ][ - + ]: 126 : if (value.EqualsIgnoreCaseAscii("native")) {
725 [ # # ]: 0 : if (bPlatformFits)
726 : : return new BackendImpl::ComponentPackageImpl(
727 : : this, url, name, m_xDynComponentTypeInfo,
728 : : OUSTR("com.sun.star.loader.SharedLibrary"),
729 [ # # ][ # # ]: 0 : bRemoved, identifier);
[ # # ][ # # ]
730 : : else
731 : : return new BackendImpl::OtherPlatformPackageImpl(
732 : : this, url, name, m_xDynComponentTypeInfo,
733 [ # # ][ # # ]: 0 : bRemoved, identifier, aPlatform);
[ # # ][ # # ]
734 : : }
735 [ + - ][ + + ]: 126 : if (value.EqualsIgnoreCaseAscii("Java")) {
736 : : return new BackendImpl::ComponentPackageImpl(
737 : : this, url, name, m_xJavaComponentTypeInfo,
738 : : OUSTR("com.sun.star.loader.Java2"),
739 [ + - ][ + - ]: 2 : bRemoved, identifier);
[ + - ][ + - ]
740 : : }
741 [ + - ][ + - ]: 124 : if (value.EqualsIgnoreCaseAscii("Python")) {
742 : : return new BackendImpl::ComponentPackageImpl(
743 : : this, url, name, m_xPythonComponentTypeInfo,
744 : : OUSTR("com.sun.star.loader.Python"),
745 [ + - ][ + - ]: 124 : bRemoved, identifier);
[ + - ][ + - ]
746 [ + - ][ + - ]: 126 : }
747 : : }
748 [ + - ][ - + ]: 126 : }
749 : : }
750 [ + - ]: 620 : else if (subType.EqualsIgnoreCaseAscii(
751 [ + - ]: 620 : "vnd.sun.star.uno-components"))
752 : : {
753 : : INetContentTypeParameter const * param = params.find(
754 [ + - ]: 620 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("platform")));
755 [ + - ][ + - ]: 620 : if (param == 0 || platform_fits( param->m_sValue )) {
[ + - ][ + + ]
756 : : return new BackendImpl::ComponentsPackageImpl(
757 : : this, url, name, m_xComponentsTypeInfo, bRemoved,
758 [ + - ][ + - ]: 620 : identifier);
[ + - ]
759 : : }
760 : : }
761 [ # # ]: 0 : else if (subType.EqualsIgnoreCaseAscii(
762 [ # # ]: 0 : "vnd.sun.star.uno-typelibrary"))
763 : : {
764 : : INetContentTypeParameter const * param = params.find(
765 [ # # ]: 0 : rtl::OString(RTL_CONSTASCII_STRINGPARAM("type")));
766 [ # # ]: 0 : if (param != 0) {
767 [ # # ]: 0 : String const & value = param->m_sValue;
768 [ # # ][ # # ]: 0 : if (value.EqualsIgnoreCaseAscii("RDB"))
769 : : {
770 : : return new BackendImpl::TypelibraryPackageImpl(
771 : : this, url, name, m_xRDBTypelibTypeInfo,
772 [ # # ][ # # ]: 0 : false /* rdb */, bRemoved, identifier);
[ # # ]
773 : : }
774 [ # # ][ # # ]: 0 : if (value.EqualsIgnoreCaseAscii("Java")) {
775 : : return new BackendImpl::TypelibraryPackageImpl(
776 : : this, url, name, m_xJavaTypelibTypeInfo,
777 [ # # ][ # # ]: 0 : true /* jar */, bRemoved, identifier);
[ # # ]
778 [ # # ][ # # ]: 0 : }
779 : : }
780 [ - + ]: 746 : }
781 : : }
782 : : }
783 : : throw lang::IllegalArgumentException(
784 [ # # ]: 0 : StrUnsupportedMediaType::get() + mediaType,
785 : : static_cast<OWeakObject *>(this),
786 [ + - ][ # # ]: 1246 : static_cast<sal_Int16>(-1) );
[ # # ][ + - ]
[ + - ]
787 : : }
788 : :
789 : :
790 : : //______________________________________________________________________________
791 : 694 : void BackendImpl::unorc_verify_init(
792 : : Reference<XCommandEnvironment> const & xCmdEnv )
793 : : {
794 [ + - ]: 694 : if (transientMode())
795 : 694 : return;
796 [ + - ]: 694 : const ::osl::MutexGuard guard( getMutex() );
797 [ + + ]: 694 : if (! m_unorc_inited)
798 : : {
799 : : // common rc:
800 [ + - ]: 380 : ::ucbhelper::Content ucb_content;
801 [ + - + + ]: 760 : if (create_ucb_content(
802 : : &ucb_content,
803 : 380 : makeURL( getCachePath(), OUSTR("unorc") ),
804 [ + - + - ]: 1140 : xCmdEnv, false /* no throw */ ))
805 : : {
806 : 62 : OUString line;
807 [ + - - + ]: 124 : if (readLine( &line, OUSTR("UNO_JAVA_CLASSPATH="), ucb_content,
808 [ + - ]: 124 : RTL_TEXTENCODING_UTF8 ))
809 : : {
810 : 0 : sal_Int32 index = sizeof ("UNO_JAVA_CLASSPATH=") - 1;
811 [ # # ]: 0 : do {
812 : 0 : OUString token( line.getToken( 0, ' ', index ).trim() );
813 [ # # ]: 0 : if (!token.isEmpty())
814 : : {
815 [ # # # # ]: 0 : if (create_ucb_content(
816 : : 0, expandUnoRcTerm(token), xCmdEnv,
817 [ # # ]: 0 : false /* no throw */ ))
818 : : {
819 : : //The jar file may not exist anymore if a shared or bundled
820 : : //extension was removed, but it can still be in the unorc
821 : : //After running XExtensionManager::synchronize, the unorc is
822 : : //cleaned up
823 [ # # ]: 0 : m_jar_typelibs.push_back( token );
824 : : }
825 : 0 : }
826 : : }
827 : : while (index >= 0);
828 : : }
829 [ + - - + ]: 124 : if (readLine( &line, OUSTR("UNO_TYPES="), ucb_content,
830 [ + - ]: 124 : RTL_TEXTENCODING_UTF8 )) {
831 : 0 : sal_Int32 index = sizeof ("UNO_TYPES=") - 1;
832 [ # # ]: 0 : do {
833 : 0 : OUString token( line.getToken( 0, ' ', index ).trim() );
834 [ # # ]: 0 : if (!token.isEmpty())
835 : : {
836 [ # # ]: 0 : if (token[ 0 ] == '?')
837 : 0 : token = token.copy( 1 );
838 [ # # # # ]: 0 : if (create_ucb_content(
839 : : 0, expandUnoRcTerm(token), xCmdEnv,
840 [ # # ]: 0 : false /* no throw */ ))
841 : : {
842 : : //The RDB file may not exist anymore if a shared or bundled
843 : : //extension was removed, but it can still be in the unorc.
844 : : //After running XExtensionManager::synchronize, the unorc is
845 : : //cleaned up
846 [ # # ]: 0 : m_rdb_typelibs.push_back( token );
847 : : }
848 : 0 : }
849 : : }
850 : : while (index >= 0);
851 : : }
852 [ + - + - ]: 124 : if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
853 [ + - ]: 124 : RTL_TEXTENCODING_UTF8 ))
854 : : {
855 : : // The UNO_SERVICES line always has the BNF form
856 : : // "UNO_SERVICES="
857 : : // ("?$ORIGIN/" <common-rdb>)? -- first
858 : : // "${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}"? -- second
859 : : // ("?" ("BUNDLED_EXTENSIONS" | -- third
860 : : // "UNO_SHARED_PACKAGES_CACHE" | "UNO_USER_PACKAGES_CACHE")
861 : : // ...)*
862 : : // so can unambiguously be split into its thre parts:
863 : 62 : int state = 1;
864 [ + + ]: 496 : for (sal_Int32 i = RTL_CONSTASCII_LENGTH("UNO_SERVICES=");
865 : : i >= 0;)
866 : : {
867 : 434 : rtl::OUString token(line.getToken(0, ' ', i));
868 [ + - ]: 434 : if (!token.isEmpty())
869 : : {
870 [ + + + - ]: 496 : if (state == 1 &&
[ + + ]
871 : : token.matchAsciiL(
872 : 62 : RTL_CONSTASCII_STRINGPARAM("?$ORIGIN/")))
873 : : {
874 : : m_commonRDB_orig = token.copy(
875 : 62 : RTL_CONSTASCII_LENGTH("?$ORIGIN/"));
876 : 62 : state = 2;
877 : : }
878 [ + + ][ + - ]: 372 : else if ( state <= 2 && token == "${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}" )
[ + + ]
879 : : {
880 : 62 : state = 3;
881 : : }
882 : : else
883 : : {
884 [ + - ]: 310 : if (token[0] == '?')
885 : : {
886 : 310 : token = token.copy(1);
887 : : }
888 [ + - ]: 310 : m_components.push_back(token);
889 : 310 : state = 3;
890 : : }
891 : : }
892 : 434 : }
893 : : }
894 : :
895 : : // native rc:
896 [ + - + - ]: 124 : if (create_ucb_content(
897 : : &ucb_content,
898 [ + - ]: 124 : makeURL( getCachePath(), getPlatformString() + OUSTR("rc")),
899 [ + - ][ + - ]: 248 : xCmdEnv, false /* no throw */ )) {
900 [ + - + - ]: 124 : if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
901 [ + - ]: 124 : RTL_TEXTENCODING_UTF8 )) {
902 : : m_nativeRDB_orig = line.copy(
903 : 62 : sizeof ("UNO_SERVICES=?$ORIGIN/") - 1 );
904 : : }
905 : 62 : }
906 : : }
907 : 380 : m_unorc_modified = false;
908 [ + - ]: 380 : m_unorc_inited = true;
909 [ + - ]: 694 : }
910 : : }
911 : :
912 : : //______________________________________________________________________________
913 : 820 : void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv )
914 : : {
915 [ + - ]: 820 : if (transientMode())
916 : : return;
917 [ + - ][ + + ]: 820 : if (!m_unorc_inited || !m_unorc_modified)
918 : : return;
919 : :
920 : 440 : ::rtl::OStringBuffer buf;
921 : :
922 [ + - ]: 440 : buf.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN="));
923 [ + - ]: 440 : OUString sOrigin = dp_misc::makeRcTerm(m_cachePath);
924 [ + - ]: 440 : ::rtl::OString osOrigin = ::rtl::OUStringToOString(sOrigin, RTL_TEXTENCODING_UTF8);
925 [ + - ]: 440 : buf.append(osOrigin);
926 [ + - ]: 440 : buf.append(LF);
927 : :
928 [ + + ]: 440 : if (! m_jar_typelibs.empty())
929 : : {
930 : 2 : t_stringlist::const_iterator iPos( m_jar_typelibs.begin() );
931 : 2 : t_stringlist::const_iterator const iEnd( m_jar_typelibs.end() );
932 [ + - ]: 2 : buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_JAVA_CLASSPATH=") );
933 [ + + ]: 4 : while (iPos != iEnd) {
934 : : // encoded ASCII file-urls:
935 : : const ::rtl::OString item(
936 [ + - ]: 2 : ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
937 [ + - ]: 2 : buf.append( item );
938 : 2 : ++iPos;
939 [ - + ]: 2 : if (iPos != iEnd)
940 [ # # ]: 0 : buf.append( ' ' );
941 : 2 : }
942 [ + - ]: 2 : buf.append(LF);
943 : : }
944 [ - + ]: 440 : if (! m_rdb_typelibs.empty())
945 : : {
946 : 0 : t_stringlist::const_iterator iPos( m_rdb_typelibs.begin() );
947 : 0 : t_stringlist::const_iterator const iEnd( m_rdb_typelibs.end() );
948 [ # # ]: 0 : buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_TYPES=") );
949 [ # # ]: 0 : while (iPos != iEnd) {
950 [ # # ]: 0 : buf.append( '?' );
951 : : // encoded ASCII file-urls:
952 : : const ::rtl::OString item(
953 [ # # ]: 0 : ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
954 [ # # ]: 0 : buf.append( item );
955 : 0 : ++iPos;
956 [ # # ]: 0 : if (iPos != iEnd)
957 [ # # ]: 0 : buf.append( ' ' );
958 : 0 : }
959 [ # # ]: 0 : buf.append(LF);
960 : : }
961 : :
962 : : // If we duplicated the common or native rdb then we must use those urls
963 : : //otherwise we use those of the original files. That is, m_commonRDB_orig
964 : : //and m_nativeRDB_orig;
965 [ - + ]: 440 : OUString sCommonRDB(m_commonRDB.isEmpty() ? m_commonRDB_orig : m_commonRDB );
966 [ - + ]: 440 : OUString sNativeRDB(m_nativeRDB.isEmpty() ? m_nativeRDB_orig : m_nativeRDB );
967 : :
968 [ # # # # ]: 440 : if (!sCommonRDB.isEmpty() || !sNativeRDB.isEmpty() ||
[ + - ][ - + ]
969 : 0 : !m_components.empty())
970 : : {
971 [ + - ]: 440 : buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=") );
972 : 440 : bool space = false;
973 [ + - ]: 440 : if (!sCommonRDB.isEmpty())
974 : : {
975 [ + - ]: 440 : buf.append( RTL_CONSTASCII_STRINGPARAM("?$ORIGIN/") );
976 : : buf.append( ::rtl::OUStringToOString(
977 [ + - ][ + - ]: 440 : sCommonRDB, RTL_TEXTENCODING_ASCII_US ) );
978 : 440 : space = true;
979 : : }
980 [ + - ]: 440 : if (!sNativeRDB.isEmpty())
981 : : {
982 [ + - ]: 440 : if (space)
983 : : {
984 [ + - ]: 440 : buf.append(' ');
985 : : }
986 : : buf.append( RTL_CONSTASCII_STRINGPARAM(
987 [ + - ]: 440 : "${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}") );
988 : 440 : space = true;
989 : :
990 : : // write native rc:
991 : 440 : ::rtl::OStringBuffer buf2;
992 [ + - ]: 440 : buf2.append(RTL_CONSTASCII_STRINGPARAM("ORIGIN="));
993 [ + - ]: 440 : buf2.append(osOrigin);
994 [ + - ]: 440 : buf2.append(LF);
995 [ + - ]: 440 : buf2.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=?$ORIGIN/") );
996 : : buf2.append( ::rtl::OUStringToOString(
997 [ + - ][ + - ]: 440 : sNativeRDB, RTL_TEXTENCODING_ASCII_US ) );
998 [ + - ]: 440 : buf2.append(LF);
999 : :
1000 : : const Reference<io::XInputStream> xData(
1001 : : ::xmlscript::createInputStream(
1002 : : ::rtl::ByteSequence(
1003 : 440 : reinterpret_cast<sal_Int8 const *>(buf2.getStr()),
1004 [ + - ][ + - ]: 880 : buf2.getLength() ) ) );
1005 : : ::ucbhelper::Content ucb_content(
1006 [ + - ]: 880 : makeURL( getCachePath(), getPlatformString() + OUSTR("rc") ),
1007 [ + - ][ + - ]: 1320 : xCmdEnv );
[ + - ]
1008 [ + - ][ + - ]: 440 : ucb_content.writeStream( xData, true /* replace existing */ );
1009 : : }
1010 [ + + ]: 3360 : for (t_stringlist::iterator i(m_components.begin());
1011 : 1680 : i != m_components.end(); ++i)
1012 : : {
1013 [ + - ]: 1240 : if (space)
1014 : : {
1015 [ + - ]: 1240 : buf.append(' ');
1016 : : }
1017 [ + - ]: 1240 : buf.append('?');
1018 [ + - ][ + - ]: 1240 : buf.append(rtl::OUStringToOString(*i, RTL_TEXTENCODING_UTF8));
1019 : 1240 : space = true;
1020 : : }
1021 [ + - ]: 440 : buf.append(LF);
1022 : : }
1023 : :
1024 : : // See refreshBundledExtensionsDir (desktop/source/app/app.cxx):
1025 [ + + ]: 440 : if (m_eContext == CONTEXT_BUNDLED)
1026 : : {
1027 [ + - ]: 434 : buf.append("LIBO_NON_PREREG_BUNDLED_EXTENSIONS=TRUE");
1028 [ + - ]: 434 : buf.append(LF);
1029 : : }
1030 : :
1031 : : // write unorc:
1032 : : const Reference<io::XInputStream> xData(
1033 : : ::xmlscript::createInputStream(
1034 : : ::rtl::ByteSequence(
1035 : 440 : reinterpret_cast<sal_Int8 const *>(buf.getStr()),
1036 [ + - ][ + - ]: 880 : buf.getLength() ) ) );
1037 : : ::ucbhelper::Content ucb_content(
1038 [ + - ][ + - ]: 440 : makeURL( getCachePath(), OUSTR("unorc") ), xCmdEnv );
[ + - ]
1039 [ + - ]: 440 : ucb_content.writeStream( xData, true /* replace existing */ );
1040 : :
1041 [ + - ]: 820 : m_unorc_modified = false;
1042 : : }
1043 : :
1044 : : //______________________________________________________________________________
1045 : 312 : bool BackendImpl::addToUnoRc( RcItem kind, OUString const & url_,
1046 : : Reference<XCommandEnvironment> const & xCmdEnv )
1047 : : {
1048 [ + - ]: 312 : const OUString rcterm( dp_misc::makeRcTerm(url_) );
1049 [ + - ]: 312 : const ::osl::MutexGuard guard( getMutex() );
1050 [ + - ]: 312 : unorc_verify_init( xCmdEnv );
1051 : 312 : t_stringlist & rSet = getRcItemList(kind);
1052 [ + - ][ + - ]: 312 : if (::std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
1053 [ + - ]: 312 : rSet.push_front( rcterm ); // prepend to list, thus overriding
1054 : : // write immediately:
1055 : 312 : m_unorc_modified = true;
1056 [ + - ]: 312 : unorc_flush( xCmdEnv );
1057 : 312 : return true;
1058 : : }
1059 : : else
1060 [ + - ]: 312 : return false;
1061 : : }
1062 : :
1063 : : //______________________________________________________________________________
1064 : 2 : bool BackendImpl::removeFromUnoRc(
1065 : : RcItem kind, OUString const & url_,
1066 : : Reference<XCommandEnvironment> const & xCmdEnv )
1067 : : {
1068 [ + - ]: 2 : const OUString rcterm( dp_misc::makeRcTerm(url_) );
1069 [ + - ]: 2 : const ::osl::MutexGuard guard( getMutex() );
1070 [ + - ]: 2 : unorc_verify_init( xCmdEnv );
1071 [ + - ]: 2 : getRcItemList(kind).remove( rcterm );
1072 : : // write immediately:
1073 : 2 : m_unorc_modified = true;
1074 [ + - ]: 2 : unorc_flush( xCmdEnv );
1075 [ + - ]: 2 : return true;
1076 : : }
1077 : :
1078 : : //______________________________________________________________________________
1079 : 1666 : bool BackendImpl::hasInUnoRc(
1080 : : RcItem kind, OUString const & url_ )
1081 : : {
1082 [ + - ]: 1666 : const OUString rcterm( dp_misc::makeRcTerm(url_) );
1083 [ + - ]: 1666 : const ::osl::MutexGuard guard( getMutex() );
1084 : 1666 : t_stringlist const & rSet = getRcItemList(kind);
1085 [ + - ][ + - ]: 1666 : return ::std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end();
1086 : : }
1087 : :
1088 : 4 : css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
1089 : : const
1090 : : {
1091 : : css::uno::Reference< css::uno::XComponentContext > rootContext(
1092 [ + - ]: 4 : getComponentContext()->getValueByName(
1093 : 4 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
1094 [ + - ][ + - ]: 4 : css::uno::UNO_QUERY);
[ + - ]
1095 [ + - ]: 4 : return rootContext.is() ? rootContext : getComponentContext();
1096 : : }
1097 : :
1098 : : //______________________________________________________________________________
1099 : 2 : void BackendImpl::releaseObject( OUString const & id )
1100 : : {
1101 [ + - ]: 2 : const ::osl::MutexGuard guard( getMutex() );
1102 [ + - ][ + - ]: 2 : m_backendObjects.erase( id );
1103 : 2 : }
1104 : :
1105 : : //______________________________________________________________________________
1106 : 4 : Reference<XInterface> BackendImpl::getObject( OUString const & id )
1107 : : {
1108 [ + - ]: 4 : const ::osl::MutexGuard guard( getMutex() );
1109 [ + - ]: 4 : const t_string2object::const_iterator iFind( m_backendObjects.find( id ) );
1110 [ + + ][ + - ]: 4 : if (iFind == m_backendObjects.end())
1111 : 2 : return Reference<XInterface>();
1112 : : else
1113 [ + - ][ + - ]: 4 : return iFind->second;
1114 : : }
1115 : :
1116 : : //______________________________________________________________________________
1117 : 2 : Reference<XInterface> BackendImpl::insertObject(
1118 : : OUString const & id, Reference<XInterface> const & xObject )
1119 : : {
1120 [ + - ]: 2 : const ::osl::MutexGuard guard( getMutex() );
1121 : : const ::std::pair<t_string2object::iterator, bool> insertion(
1122 : : m_backendObjects.insert( t_string2object::value_type(
1123 [ + - ][ + - ]: 2 : id, xObject ) ) );
[ + - ]
1124 [ + - ][ + - ]: 2 : return insertion.first->second;
1125 : : }
1126 : :
1127 : : //------------------------------------------------------------------------------
1128 : 2 : Reference<XComponentContext> raise_uno_process(
1129 : : Reference<XComponentContext> const & xContext,
1130 : : ::rtl::Reference<AbortChannel> const & abortChannel )
1131 : : {
1132 : : OSL_ASSERT( xContext.is() );
1133 : :
1134 : : ::rtl::OUString url(
1135 : : Reference<util::XMacroExpander>(
1136 [ + - ]: 2 : xContext->getValueByName(
1137 : 2 : OUSTR("/singletons/com.sun.star.util.theMacroExpander") ),
1138 [ + - ][ + - ]: 4 : UNO_QUERY_THROW )->
[ + - ][ + - ]
1139 [ + - ][ + - ]: 2 : expandMacros( OUSTR("$URE_BIN_DIR/uno") ) );
1140 : :
1141 : 2 : ::rtl::OUStringBuffer buf;
1142 [ + - ]: 2 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno:pipe,name=") );
1143 [ + - ]: 2 : OUString pipeId( generateRandomPipeId() );
1144 [ + - ]: 2 : buf.append( pipeId );
1145 : : buf.appendAscii(
1146 [ + - ]: 2 : RTL_CONSTASCII_STRINGPARAM(";urp;uno.ComponentContext") );
1147 [ + - ]: 2 : const OUString connectStr( buf.makeStringAndClear() );
1148 : :
1149 : : // raise core UNO process to register/run a component,
1150 : : // javavm service uses unorc next to executable to retrieve deployed
1151 : : // jar typelibs
1152 : :
1153 [ + - ]: 2 : ::std::vector<OUString> args;
1154 : : #if OSL_DEBUG_LEVEL == 0
1155 [ + - ][ + - ]: 2 : args.push_back( OUSTR("--quiet") );
1156 : : #endif
1157 [ + - ][ + - ]: 2 : args.push_back( OUSTR("--singleaccept") );
1158 [ + - ][ + - ]: 2 : args.push_back( OUSTR("-u") );
1159 [ + - ]: 2 : args.push_back( connectStr );
1160 : : // don't inherit from unorc:
1161 [ + - ][ + - ]: 2 : args.push_back( OUSTR("-env:INIFILENAME=") );
1162 : :
1163 : : //now add the bootstrap variables which were supplied on the command line
1164 [ + - ]: 2 : ::std::vector<OUString> bootvars = getCmdBootstrapVariables();
1165 [ + - ]: 2 : args.insert(args.end(), bootvars.begin(), bootvars.end());
1166 : :
1167 : : oslProcess hProcess = raiseProcess(
1168 [ + - ][ + - ]: 2 : url, comphelper::containerToSequence(args) );
[ + - ]
1169 : : try {
1170 : : return Reference<XComponentContext>(
1171 : : resolveUnoURL( connectStr, xContext, abortChannel.get() ),
1172 [ + - ][ + - ]: 4 : UNO_QUERY_THROW );
1173 : : }
1174 : 0 : catch (...) {
1175 : : // try to terminate process:
1176 [ # # ]: 0 : if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
1177 : : {
1178 : : OSL_ASSERT( false );
1179 : : }
1180 : 0 : throw;
1181 : 2 : }
1182 : : }
1183 : :
1184 : : //------------------------------------------------------------------------------
1185 : : namespace {
1186 : :
1187 : 64 : void extractComponentData(
1188 : : css::uno::Reference< css::uno::XComponentContext > const & context,
1189 : : css::uno::Reference< css::registry::XRegistryKey > const & registry,
1190 : : ComponentBackendDb::Data * data,
1191 : : std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1192 : : css::uno::Reference< css::loader::XImplementationLoader > const &
1193 : : componentLoader,
1194 : : rtl::OUString const & componentUrl)
1195 : : {
1196 : : OSL_ASSERT(
1197 : : context.is() && registry.is() && data != 0 && componentLoader.is());
1198 [ + - ][ + - ]: 64 : rtl::OUString registryName(registry->getKeyName());
1199 : 64 : sal_Int32 prefix = registryName.getLength();
1200 [ - + ]: 64 : if (!registryName.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("/"))) {
1201 : 0 : prefix += RTL_CONSTASCII_LENGTH("/");
1202 : : }
1203 : : css::uno::Sequence< css::uno::Reference< css::registry::XRegistryKey > >
1204 [ + - ][ + - ]: 64 : keys(registry->openKeys());
1205 : : css::uno::Reference< css::lang::XMultiComponentFactory > smgr(
1206 [ + - ][ + - ]: 64 : context->getServiceManager(), css::uno::UNO_QUERY_THROW);
[ + - ]
1207 [ + + ]: 190 : for (sal_Int32 i = 0; i < keys.getLength(); ++i) {
1208 [ + - ][ + - ]: 126 : rtl::OUString name(keys[i]->getKeyName().copy(prefix));
[ + - ]
1209 [ + - ]: 126 : data->implementationNames.push_back(name);
1210 : : css::uno::Reference< css::registry::XRegistryKey > singletons(
1211 [ + - ][ + - ]: 126 : keys[i]->openKey(
1212 [ + - ][ + - ]: 126 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UNO/SINGLETONS"))));
1213 [ - + ]: 126 : if (singletons.is()) {
1214 [ # # ][ # # ]: 0 : sal_Int32 prefix2 = keys[i]->getKeyName().getLength() +
[ # # ]
1215 : 0 : RTL_CONSTASCII_LENGTH("/UNO/SINGLETONS/");
1216 : : css::uno::Sequence<
1217 : : css::uno::Reference< css::registry::XRegistryKey > >
1218 [ # # ][ # # ]: 0 : singletonKeys(singletons->openKeys());
1219 [ # # ]: 0 : for (sal_Int32 j = 0; j < singletonKeys.getLength(); ++j) {
1220 : : data->singletons.push_back(
1221 : : std::pair< rtl::OUString, rtl::OUString >(
1222 [ # # ][ # # ]: 0 : singletonKeys[j]->getKeyName().copy(prefix2), name));
[ # # ][ # # ]
1223 [ # # ]: 0 : }
1224 : : }
1225 [ + + ]: 126 : if (factories != 0) {
1226 : : factories->push_back(
1227 [ + - ]: 2 : componentLoader->activate(
1228 [ + - ][ + - ]: 2 : name, rtl::OUString(), componentUrl, keys[i]));
[ + - ]
1229 : : }
1230 [ + - ]: 190 : }
1231 : 64 : }
1232 : :
1233 : : }
1234 : :
1235 : 64 : void BackendImpl::ComponentPackageImpl::getComponentInfo(
1236 : : ComponentBackendDb::Data * data,
1237 : : std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
1238 : : Reference<XComponentContext> const & xContext )
1239 : : {
1240 : : const Reference<loader::XImplementationLoader> xLoader(
1241 [ + - ][ + - ]: 128 : xContext->getServiceManager()->createInstanceWithContext(
[ + - ]
1242 [ + - ][ + - ]: 64 : m_loader, xContext ), UNO_QUERY );
1243 [ - + ]: 64 : if (! xLoader.is())
1244 : : {
1245 : : throw css::deployment::DeploymentException(
1246 : : (rtl::OUString(
1247 : : RTL_CONSTASCII_USTRINGPARAM("cannot instantiate loader ")) +
1248 : : m_loader),
1249 [ # # ][ # # ]: 0 : static_cast< OWeakObject * >(this), Any());
[ # # ]
1250 : : }
1251 : :
1252 : : // HACK: highly dependent on stoc/source/servicemanager
1253 : : // and stoc/source/implreg implementation which rely on the same
1254 : : // services.rdb format!
1255 : : // .../UNO/LOCATION and .../UNO/ACTIVATOR appear not to be written by
1256 : : // writeRegistryInfo, however, but are knwon, fixed values here, so
1257 : : // can be passed into extractComponentData
1258 [ + - ]: 64 : rtl::OUString url(getURL());
1259 : : const Reference<registry::XSimpleRegistry> xMemReg(
1260 [ + - ][ + - ]: 128 : xContext->getServiceManager()->createInstanceWithContext(
[ + - ]
1261 : 64 : OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
1262 [ + - ][ + - ]: 64 : UNO_QUERY_THROW );
[ + - ]
1263 [ + - ][ + - ]: 64 : xMemReg->open( OUString() /* in mem */, false, true );
1264 [ + - ][ + - ]: 64 : xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
[ + - ][ + - ]
1265 : : extractComponentData(
1266 [ + - ][ + - ]: 64 : xContext, xMemReg->getRootKey(), data, factories, xLoader, url);
[ + - ]
1267 : 64 : }
1268 : :
1269 : 2 : void BackendImpl::ComponentPackageImpl::componentLiveInsertion(
1270 : : ComponentBackendDb::Data const & data,
1271 : : std::vector< css::uno::Reference< css::uno::XInterface > > const &
1272 : : factories)
1273 : : {
1274 : : css::uno::Reference< css::uno::XComponentContext > rootContext(
1275 [ + - ][ + - ]: 2 : getMyBackend()->getRootContext());
1276 : : css::uno::Reference< css::container::XSet > set(
1277 [ + - ][ + - ]: 2 : rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
[ + - ]
1278 : : std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
1279 : 2 : factory(factories.begin());
1280 [ + + ]: 8 : for (t_stringlist::const_iterator i(data.implementationNames.begin());
1281 : 4 : i != data.implementationNames.end(); ++i)
1282 : : {
1283 : : try {
1284 [ + - ][ + - ]: 2 : set->insert(css::uno::Any(*factory++));
[ + - ][ + - ]
[ # # ]
1285 [ # # ]: 0 : } catch (const container::ElementExistException &) {
1286 : : OSL_TRACE(
1287 : : "implementation %s already registered",
1288 : : rtl::OUStringToOString(*i, RTL_TEXTENCODING_UTF8).getStr());
1289 : : }
1290 : : }
1291 [ - + ]: 2 : if (!data.singletons.empty()) {
1292 : : css::uno::Reference< css::container::XNameContainer > cont(
1293 [ # # ]: 0 : rootContext, css::uno::UNO_QUERY_THROW);
1294 [ # # ][ # # ]: 0 : for (t_stringpairvec::const_iterator i(data.singletons.begin());
1295 : 0 : i != data.singletons.end(); ++i)
1296 : : {
1297 : : rtl::OUString name(
1298 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
1299 [ # # ]: 0 : i->first);
1300 : : //TODO: Update should be atomic:
1301 : : try {
1302 [ # # ]: 0 : cont->removeByName(
1303 : : name +
1304 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/arguments")));
[ # # ]
1305 [ # # ]: 0 : } catch (const container::NoSuchElementException &) {}
1306 : : try {
1307 [ # # ]: 0 : cont->insertByName(
1308 : : (name +
1309 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service"))),
1310 [ # # ][ # # ]: 0 : css::uno::Any(i->second));
[ # # ]
1311 [ # # # # ]: 0 : } catch (const container::ElementExistException &) {
1312 [ # # ]: 0 : cont->replaceByName(
1313 : : (name +
1314 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service"))),
1315 [ # # # # : 0 : css::uno::Any(i->second));
# # ]
1316 : : }
1317 : : try {
1318 [ # # ][ # # ]: 0 : cont->insertByName(name, css::uno::Any());
1319 [ # # # # ]: 0 : } catch (const container::ElementExistException &) {
1320 : : OSL_TRACE(
1321 : : "singleton %s already registered",
1322 : : rtl::OUStringToOString(
1323 : : i->first, RTL_TEXTENCODING_UTF8).getStr());
1324 [ # # # # ]: 0 : cont->replaceByName(name, css::uno::Any());
1325 : : }
1326 : 0 : }
1327 : 2 : }
1328 : 2 : }
1329 : :
1330 : 2 : void BackendImpl::ComponentPackageImpl::componentLiveRemoval(
1331 : : ComponentBackendDb::Data const & data)
1332 : : {
1333 : : css::uno::Reference< css::uno::XComponentContext > rootContext(
1334 [ + - ][ + - ]: 2 : getMyBackend()->getRootContext());
1335 : : css::uno::Reference< css::container::XSet > set(
1336 [ + - ][ + - ]: 2 : rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
[ + - ]
1337 [ + + ]: 8 : for (t_stringlist::const_iterator i(data.implementationNames.begin());
1338 : 4 : i != data.implementationNames.end(); ++i)
1339 : : {
1340 : : try {
1341 [ + - ][ + - ]: 2 : set->remove(css::uno::Any(*i));
[ + - ][ # # ]
1342 [ # # # # ]: 0 : } catch (const css::container::NoSuchElementException &) {
1343 : : // ignore if factory has not been live deployed
1344 : : }
1345 : : }
1346 [ - + ]: 2 : if (!data.singletons.empty()) {
1347 : : css::uno::Reference< css::container::XNameContainer > cont(
1348 [ # # ]: 0 : rootContext, css::uno::UNO_QUERY_THROW);
1349 [ # # ][ # # ]: 0 : for (t_stringpairvec::const_iterator i(data.singletons.begin());
1350 : 0 : i != data.singletons.end(); ++i)
1351 : : {
1352 : : rtl::OUString name(
1353 : : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
1354 [ # # ]: 0 : i->first);
1355 : : //TODO: Removal should be atomic:
1356 : : try {
1357 [ # # ][ # # ]: 0 : cont->removeByName(name);
1358 [ # # ]: 0 : } catch (const container::NoSuchElementException &) {}
1359 : : try {
1360 [ # # ]: 0 : cont->removeByName(
1361 : : name +
1362 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service")));
[ # # ]
1363 [ # # ]: 0 : } catch (const container::NoSuchElementException &) {}
1364 : : try {
1365 [ # # ]: 0 : cont->removeByName(
1366 : : name +
1367 [ # # ][ # # ]: 0 : rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/arguments")));
[ # # ]
1368 [ # # ]: 0 : } catch (const container::NoSuchElementException &) {}
1369 : 0 : }
1370 : 2 : }
1371 : 2 : }
1372 : :
1373 : : // Package
1374 : : //______________________________________________________________________________
1375 : : //We could use here BackendImpl::hasActiveEntry. However, this check is just as well.
1376 : : //And it also shows the problem if another extension has overwritten an implementation
1377 : : //entry, because it contains the same service implementation
1378 : : beans::Optional< beans::Ambiguous<sal_Bool> >
1379 : 324 : BackendImpl::ComponentPackageImpl::isRegistered_(
1380 : : ::osl::ResettableMutexGuard &,
1381 : : ::rtl::Reference<AbortChannel> const & abortChannel,
1382 : : Reference<XCommandEnvironment> const & )
1383 : : {
1384 [ + + ]: 324 : if (m_registered == REG_UNINIT)
1385 : : {
1386 : 126 : m_registered = REG_NOT_REGISTERED;
1387 : 126 : bool bAmbiguousComponentName = false;
1388 [ + - ]: 126 : const Reference<registry::XSimpleRegistry> xRDB( getRDB() );
1389 [ + - ]: 126 : if (xRDB.is())
1390 : : {
1391 : : // lookup rdb for location URL:
1392 : : const Reference<registry::XRegistryKey> xRootKey(
1393 [ + - ][ + - ]: 126 : xRDB->getRootKey() );
1394 : : const Reference<registry::XRegistryKey> xImplKey(
1395 [ + - ][ + - ]: 126 : xRootKey->openKey( OUSTR("IMPLEMENTATIONS") ) );
[ + - ]
1396 [ + - ]: 126 : Sequence<OUString> implNames;
1397 [ + + ][ + - ]: 126 : if (xImplKey.is() && xImplKey->isValid())
[ + - ][ + - ]
[ + + ]
1398 [ + - ][ + - ]: 62 : implNames = xImplKey->getKeyNames();
[ + - ][ + - ]
1399 : 126 : OUString const * pImplNames = implNames.getConstArray();
1400 : 126 : sal_Int32 pos = implNames.getLength();
1401 [ + + ]: 126 : for ( ; pos--; )
1402 : : {
1403 [ + - ]: 62 : checkAborted( abortChannel );
1404 : : const OUString key(
1405 [ + - ]: 62 : pImplNames[ pos ] + OUSTR("/UNO/LOCATION") );
1406 : : const Reference<registry::XRegistryKey> xKey(
1407 [ + - ][ + - ]: 62 : xRootKey->openKey(key) );
1408 [ + - ][ + - ]: 62 : if (xKey.is() && xKey->isValid())
[ + - ][ + - ]
[ + - ]
1409 : : {
1410 [ + - ][ + - ]: 62 : const OUString location( xKey->getAsciiValue() );
1411 [ + - ][ + - ]: 62 : if (location.equalsIgnoreAsciiCase( getURL() ))
1412 : : {
1413 : : break;
1414 : : }
1415 : : else
1416 : : {
1417 : : //try to match only the file name
1418 [ # # ]: 0 : OUString thisUrl(getURL());
1419 : 0 : OUString thisFileName(thisUrl.copy(thisUrl.lastIndexOf('/')));
1420 : :
1421 : 0 : OUString locationFileName(location.copy(location.lastIndexOf('/')));
1422 [ # # ]: 0 : if (locationFileName.equalsIgnoreAsciiCase(thisFileName))
1423 : 0 : bAmbiguousComponentName = true;
1424 [ - + ]: 62 : }
1425 : : }
1426 [ + - ][ - + ]: 62 : }
1427 [ + + ]: 126 : if (pos >= 0)
1428 : 62 : m_registered = REG_REGISTERED;
1429 [ - + ]: 64 : else if (bAmbiguousComponentName)
1430 [ + - ]: 126 : m_registered = REG_MAYBE_REGISTERED;
1431 : 126 : }
1432 : : }
1433 : :
1434 : : //Different extensions can use the same service implementations. Then the extensions
1435 : : //which was installed last will overwrite the one from the other extension. That is
1436 : : //the registry will contain the path (the location) of the library or jar of the
1437 : : //second extension. In this case isRegistered called for the lib of the first extension
1438 : : //would return "not registered". That would mean that during uninstallation
1439 : : //XPackage::registerPackage is not called, because it just was not registered. This is,
1440 : : //however, necessary for jar files. Registering and unregistering update
1441 : : //uno_packages/cache/registry/com.sun.star.comp.deployment.component.PackageRegistryBackend/unorc
1442 : : //Therefore, we will return always "is ambiguous" if the path of this component cannot
1443 : : //be found in the registry and if there is another path and both have the same file name (but
1444 : : //the rest of the path is different).
1445 : : //If the caller cannot precisely determine that this package was registered, then it must
1446 : : //call registerPackage.
1447 : : sal_Bool bAmbiguous = m_registered == REG_VOID // REG_VOID == we are in the progress of unregistration
1448 [ + - ][ - + ]: 324 : || m_registered == REG_MAYBE_REGISTERED;
1449 : : return beans::Optional< beans::Ambiguous<sal_Bool> >(
1450 : : true /* IsPresent */,
1451 : : beans::Ambiguous<sal_Bool>(
1452 : 324 : m_registered == REG_REGISTERED, bAmbiguous) );
1453 : : }
1454 : :
1455 : : //______________________________________________________________________________
1456 : 66 : void BackendImpl::ComponentPackageImpl::processPackage_(
1457 : : ::osl::ResettableMutexGuard &,
1458 : : bool doRegisterPackage,
1459 : : bool startup,
1460 : : ::rtl::Reference<AbortChannel> const & abortChannel,
1461 : : Reference<XCommandEnvironment> const & xCmdEnv )
1462 : : {
1463 [ + - ]: 66 : BackendImpl * that = getMyBackend();
1464 [ + - ]: 66 : rtl::OUString url(getURL());
1465 [ + + ]: 66 : if (doRegisterPackage) {
1466 [ + - ]: 64 : ComponentBackendDb::Data data;
1467 : 64 : css::uno::Reference< css::uno::XComponentContext > context;
1468 [ + + ]: 64 : if (startup) {
1469 [ + - ]: 62 : context = that->getComponentContext();
1470 : : } else {
1471 [ + - ][ + - ]: 2 : context.set(that->getObject(url), css::uno::UNO_QUERY);
1472 [ + - ]: 2 : if (!context.is()) {
1473 : : context.set(
1474 : : that->insertObject(
1475 : : url,
1476 : : raise_uno_process(
1477 [ + - ]: 4 : that->getComponentContext(), abortChannel)),
1478 [ + - ][ + - ]: 2 : css::uno::UNO_QUERY_THROW);
1479 : : }
1480 : : }
1481 : : css::uno::Reference< css::registry::XImplementationRegistration>(
1482 [ + - ][ + - ]: 128 : context->getServiceManager()->createInstanceWithContext(
[ + - ]
1483 : : rtl::OUString(
1484 : : RTL_CONSTASCII_USTRINGPARAM(
1485 : : "com.sun.star.registry.ImplementationRegistration")),
1486 : 64 : context),
1487 [ + - ][ + - ]: 128 : css::uno::UNO_QUERY_THROW)->registerImplementation(
[ + - ][ + - ]
1488 [ + - ][ + - ]: 64 : m_loader, url, getRDB());
1489 : : // Only write to unorc after successful registration; it may fail if
1490 : : // there is no suitable java
1491 [ + - ][ + - ]: 64 : if (m_loader == "com.sun.star.loader.Java2" && !jarManifestHeaderPresent(url, OUSTR("UNO-Type-Path"), xCmdEnv))
[ + - ][ + + ]
[ + + # # ]
[ + + ]
1492 : : {
1493 [ + - ]: 2 : that->addToUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1494 : 2 : data.javaTypeLibrary = true;
1495 : : }
1496 [ + - ]: 64 : std::vector< css::uno::Reference< css::uno::XInterface > > factories;
1497 [ + + ][ + - ]: 64 : getComponentInfo(&data, startup ? 0 : &factories, context);
1498 [ + + ]: 64 : if (!startup) {
1499 [ + - ]: 2 : componentLiveInsertion(data, factories);
1500 : : }
1501 : 64 : m_registered = REG_REGISTERED;
1502 [ + - ]: 64 : that->addDataToDb(url, data);
1503 : : } else { // revoke
1504 : 2 : m_registered = REG_VOID;
1505 [ + - ]: 2 : ComponentBackendDb::Data data(that->readDataFromDb(url));
1506 : : css::uno::Reference< css::uno::XComponentContext > context(
1507 [ + - ][ + - ]: 2 : that->getObject(url), css::uno::UNO_QUERY);
1508 : 2 : bool remoteContext = context.is();
1509 [ - + ]: 2 : if (!remoteContext) {
1510 [ # # ]: 0 : context = that->getComponentContext();
1511 : : }
1512 [ + - ]: 2 : if (!startup) {
1513 [ + - ]: 2 : componentLiveRemoval(data);
1514 : : }
1515 : : css::uno::Reference< css::registry::XImplementationRegistration >(
1516 [ + - ][ + - ]: 4 : context->getServiceManager()->createInstanceWithContext(
[ + - ]
1517 : : rtl::OUString(
1518 : : RTL_CONSTASCII_USTRINGPARAM(
1519 : : "com.sun.star.registry.ImplementationRegistration")),
1520 : 2 : context),
1521 [ + - ][ + - ]: 2 : css::uno::UNO_QUERY_THROW)->revokeImplementation(url, getRDB());
[ + - ][ + - ]
[ + - ][ + - ]
1522 [ + - ]: 2 : if (data.javaTypeLibrary) {
1523 [ + - ]: 2 : that->removeFromUnoRc(RCITEM_JAR_TYPELIB, url, xCmdEnv);
1524 : : }
1525 [ + - ]: 2 : if (remoteContext) {
1526 [ + - ]: 2 : that->releaseObject(url);
1527 : : }
1528 : 2 : m_registered = REG_NOT_REGISTERED;
1529 [ + - ][ + - ]: 2 : getMyBackend()->revokeEntryFromDb(url);
1530 : 66 : }
1531 : 66 : }
1532 : :
1533 : 0 : BackendImpl::TypelibraryPackageImpl::TypelibraryPackageImpl(
1534 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
1535 : : OUString const & url, OUString const & name,
1536 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
1537 : : bool jarFile, bool bRemoved, OUString const & identifier)
1538 : : : Package( myBackend, url, name, name /* display-name */,
1539 : : xPackageType, bRemoved, identifier),
1540 : 0 : m_jarFile( jarFile )
1541 : : {
1542 : 0 : }
1543 : :
1544 : : // Package
1545 : 0 : BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend() const
1546 : : {
1547 : 0 : BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1548 [ # # ]: 0 : if (NULL == pBackend)
1549 : : {
1550 : : //May throw a DisposedException
1551 : 0 : check();
1552 : : //We should never get here...
1553 : : throw RuntimeException(
1554 : : OUSTR("Failed to get the BackendImpl"),
1555 [ # # ][ # # ]: 0 : static_cast<OWeakObject*>(const_cast<TypelibraryPackageImpl *>(this)));
[ # # ]
1556 : : }
1557 : 0 : return pBackend;
1558 : : }
1559 : : //______________________________________________________________________________
1560 : : beans::Optional< beans::Ambiguous<sal_Bool> >
1561 : 0 : BackendImpl::TypelibraryPackageImpl::isRegistered_(
1562 : : ::osl::ResettableMutexGuard &,
1563 : : ::rtl::Reference<AbortChannel> const &,
1564 : : Reference<XCommandEnvironment> const & )
1565 : : {
1566 : 0 : BackendImpl * that = getMyBackend();
1567 : : return beans::Optional< beans::Ambiguous<sal_Bool> >(
1568 : : true /* IsPresent */,
1569 : : beans::Ambiguous<sal_Bool>(
1570 : : that->hasInUnoRc(
1571 [ # # ][ # # ]: 0 : m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, getURL() ),
[ # # ]
1572 : 0 : false /* IsAmbiguous */ ) );
1573 : : }
1574 : :
1575 : : //______________________________________________________________________________
1576 : 0 : void BackendImpl::TypelibraryPackageImpl::processPackage_(
1577 : : ::osl::ResettableMutexGuard &,
1578 : : bool doRegisterPackage,
1579 : : bool /*startup*/,
1580 : : ::rtl::Reference<AbortChannel> const &,
1581 : : Reference<XCommandEnvironment> const & xCmdEnv )
1582 : : {
1583 [ # # ]: 0 : BackendImpl * that = getMyBackend();
1584 [ # # ]: 0 : const OUString url( getURL() );
1585 : :
1586 [ # # ]: 0 : if (doRegisterPackage)
1587 : : {
1588 : : // live insertion:
1589 [ # # ]: 0 : if (m_jarFile) {
1590 : : // xxx todo add to classpath at runtime: ???
1591 : : //SB: It is probably not worth it to add the live inserted type
1592 : : // library JAR to the UnoClassLoader in the soffice process. Any
1593 : : // live inserted component JAR that might reference this type
1594 : : // library JAR runs in its own uno process, so there is probably no
1595 : : // Java code in the soffice process that would see any UNO types
1596 : : // introduced by this type library JAR.
1597 : : }
1598 : : else // RDB:
1599 : : {
1600 : : Reference<XComponentContext> const & xContext =
1601 : 0 : that->getComponentContext();
1602 [ # # ]: 0 : if (! m_xTDprov.is())
1603 : : {
1604 [ # # ][ # # ]: 0 : m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1605 [ # # ]: 0 : if (! m_xTDprov.is())
1606 : : {
1607 : : const Reference<registry::XSimpleRegistry> xReg(
1608 [ # # ]: 0 : xContext->getServiceManager()
1609 [ # # ][ # # ]: 0 : ->createInstanceWithContext(
1610 : : OUSTR("com.sun.star.registry.SimpleRegistry"),
1611 [ # # ][ # # ]: 0 : xContext ), UNO_QUERY_THROW );
[ # # ]
1612 [ # # ]: 0 : xReg->open( expandUnoRcUrl(url),
1613 [ # # ][ # # ]: 0 : true /* read-only */, false /* ! create */ );
1614 [ # # ]: 0 : const Any arg(xReg);
1615 : : Reference<container::XHierarchicalNameAccess> xTDprov(
1616 [ # # ]: 0 : xContext->getServiceManager()
1617 [ # # ][ # # ]: 0 : ->createInstanceWithArgumentsAndContext(
1618 : : OUSTR("com.sun.star.comp.stoc."
1619 : : "RegistryTypeDescriptionProvider"),
1620 [ # # ][ # # ]: 0 : Sequence<Any>( &arg, 1 ), xContext ), UNO_QUERY );
[ # # ][ # # ]
[ # # ]
1621 : : OSL_ASSERT( xTDprov.is() );
1622 [ # # ]: 0 : if (xTDprov.is())
1623 : 0 : m_xTDprov.set( that->insertObject( url, xTDprov ),
1624 [ # # ][ # # ]: 0 : UNO_QUERY_THROW );
1625 : : }
1626 : : }
1627 [ # # ]: 0 : if (m_xTDprov.is()) {
1628 : : Reference<container::XSet> xSet(
1629 [ # # ]: 0 : xContext->getValueByName(
1630 : : OUSTR("/singletons/com.sun.star."
1631 : 0 : "reflection.theTypeDescriptionManager") ),
1632 [ # # ][ # # ]: 0 : UNO_QUERY_THROW );
[ # # ]
1633 [ # # ][ # # ]: 0 : xSet->insert( Any(m_xTDprov) );
[ # # ]
1634 : : }
1635 : : }
1636 : :
1637 : : that->addToUnoRc( m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB,
1638 [ # # ][ # # ]: 0 : url, xCmdEnv );
1639 : : }
1640 : : else // revokePackage()
1641 : : {
1642 : : that->removeFromUnoRc(
1643 [ # # ][ # # ]: 0 : m_jarFile ? RCITEM_JAR_TYPELIB : RCITEM_RDB_TYPELIB, url, xCmdEnv );
1644 : :
1645 : : // revoking types at runtime, possible, sensible?
1646 [ # # ]: 0 : if (!m_xTDprov.is())
1647 [ # # ][ # # ]: 0 : m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1648 [ # # ]: 0 : if (m_xTDprov.is()) {
1649 : : // remove live:
1650 : : const Reference<container::XSet> xSet(
1651 [ # # ]: 0 : that->getComponentContext()->getValueByName(
1652 : : OUSTR("/singletons/com.sun.star."
1653 : 0 : "reflection.theTypeDescriptionManager") ),
1654 [ # # ][ # # ]: 0 : UNO_QUERY_THROW );
[ # # ]
1655 [ # # ][ # # ]: 0 : xSet->remove( Any(m_xTDprov) );
[ # # ]
1656 : :
1657 [ # # ]: 0 : that->releaseObject( url );
1658 : 0 : m_xTDprov.clear();
1659 : : }
1660 : 0 : }
1661 : 0 : }
1662 : :
1663 : 0 : BackendImpl::OtherPlatformPackageImpl::OtherPlatformPackageImpl(
1664 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
1665 : : OUString const & url, OUString const & name,
1666 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
1667 : : bool bRemoved, OUString const & identifier, OUString const& rPlatform)
1668 : : : Package(myBackend, url, name, name, xPackageType, bRemoved, identifier)
1669 : 0 : , m_aPlatform(rPlatform)
1670 : : {
1671 : : OSL_PRECOND(bRemoved, "this class can only be used for removing packages!");
1672 : 0 : }
1673 : :
1674 : : BackendImpl *
1675 : 0 : BackendImpl::OtherPlatformPackageImpl::getMyBackend() const
1676 : : {
1677 : 0 : BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1678 [ # # ]: 0 : if (NULL == pBackend)
1679 : : {
1680 : : //Throws a DisposedException
1681 : 0 : check();
1682 : : //We should never get here...
1683 : : throw RuntimeException(
1684 : : OUSTR("Failed to get the BackendImpl"),
1685 [ # # ][ # # ]: 0 : static_cast<OWeakObject*>(const_cast<OtherPlatformPackageImpl*>(this)));
[ # # ]
1686 : : }
1687 : 0 : return pBackend;
1688 : : }
1689 : :
1690 : : Reference<registry::XSimpleRegistry> const
1691 : 0 : BackendImpl::OtherPlatformPackageImpl::impl_openRDB() const
1692 : : {
1693 [ # # ]: 0 : OUString const aRDB(m_aPlatform + OUString(RTL_CONSTASCII_USTRINGPARAM(".rdb")));
1694 [ # # ][ # # ]: 0 : OUString const aRDBPath(makeURL(getMyBackend()->getCachePath(), aRDB));
1695 : :
1696 : 0 : Reference<registry::XSimpleRegistry> xRegistry;
1697 : :
1698 : : try
1699 : : {
1700 : : xRegistry.set(
1701 : : impl_createInstance(
1702 : : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.SimpleRegistry"))),
1703 [ # # ][ # # ]: 0 : UNO_QUERY)
1704 [ # # ]: 0 : ;
1705 [ # # ]: 0 : if (xRegistry.is())
1706 [ # # ][ # # ]: 0 : xRegistry->open(expandUnoRcUrl(aRDBPath), false, false);
[ # # ]
1707 : : }
1708 [ # # # # ]: 0 : catch (registry::InvalidRegistryException const&)
1709 : : {
1710 : : // If the registry does not exist, we do not need to bother at all
1711 [ # # ]: 0 : xRegistry.set(0);
1712 : : }
1713 : :
1714 : : OSL_POSTCOND(xRegistry.is(), "could not create registry for the package's platform");
1715 : 0 : return xRegistry;
1716 : : }
1717 : :
1718 : : Reference<XInterface> const
1719 : 0 : BackendImpl::OtherPlatformPackageImpl::impl_createInstance(OUString const& rService)
1720 : : const
1721 : : {
1722 [ # # ]: 0 : Reference<XComponentContext> const xContext(getMyBackend()->getComponentContext());
1723 : : OSL_ASSERT(xContext.is());
1724 : 0 : Reference<XInterface> xService;
1725 [ # # ]: 0 : if (xContext.is())
1726 [ # # ][ # # ]: 0 : xService.set(xContext->getServiceManager()->createInstanceWithContext(rService, xContext));
[ # # ][ # # ]
[ # # ]
1727 : 0 : return xService;
1728 : : }
1729 : :
1730 : : beans::Optional<beans::Ambiguous<sal_Bool> >
1731 : 0 : BackendImpl::OtherPlatformPackageImpl::isRegistered_(
1732 : : ::osl::ResettableMutexGuard& /* guard */,
1733 : : ::rtl::Reference<AbortChannel> const& /* abortChannel */,
1734 : : Reference<XCommandEnvironment> const& /* xCmdEnv */ )
1735 : : {
1736 : : return beans::Optional<beans::Ambiguous<sal_Bool> >(sal_True,
1737 : 0 : beans::Ambiguous<sal_Bool>(sal_True, sal_False));
1738 : : }
1739 : :
1740 : : void
1741 : 0 : BackendImpl::OtherPlatformPackageImpl::processPackage_(
1742 : : ::osl::ResettableMutexGuard& /* guard */,
1743 : : bool bRegisterPackage,
1744 : : bool /* bStartup */,
1745 : : ::rtl::Reference<AbortChannel> const& /* abortChannel */,
1746 : : Reference<XCommandEnvironment> const& /* xCmdEnv */)
1747 : : {
1748 : : OSL_PRECOND(!bRegisterPackage, "this class can only be used for removing packages!");
1749 : : (void) bRegisterPackage;
1750 : :
1751 [ # # ]: 0 : OUString const aURL(getURL());
1752 : :
1753 [ # # ]: 0 : Reference<registry::XSimpleRegistry> const xServicesRDB(impl_openRDB());
1754 : : Reference<registry::XImplementationRegistration> const xImplReg(
1755 : : impl_createInstance(
1756 : : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.ImplementationRegistration"))),
1757 [ # # ][ # # ]: 0 : UNO_QUERY)
[ # # ]
1758 : : ;
1759 [ # # ][ # # ]: 0 : if (xImplReg.is() && xServicesRDB.is())
[ # # ]
1760 [ # # ][ # # ]: 0 : xImplReg->revokeImplementation(aURL, xServicesRDB);
1761 [ # # ]: 0 : if (xServicesRDB.is())
1762 [ # # ][ # # ]: 0 : xServicesRDB->close();
1763 : :
1764 [ # # ][ # # ]: 0 : getMyBackend()->revokeEntryFromDb(aURL);
1765 : 0 : }
1766 : :
1767 : 1976 : BackendImpl * BackendImpl::ComponentsPackageImpl::getMyBackend() const
1768 : : {
1769 : 1976 : BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1770 [ - + ]: 1976 : if (NULL == pBackend)
1771 : : {
1772 : : //Throws a DisposedException
1773 : 0 : check();
1774 : : //We should never get here...
1775 : : throw RuntimeException(
1776 : : OUSTR("Failed to get the BackendImpl"),
1777 [ # # ][ # # ]: 0 : static_cast<OWeakObject*>(const_cast<ComponentsPackageImpl *>(this)));
[ # # ]
1778 : : }
1779 : 1976 : return pBackend;
1780 : : }
1781 : :
1782 : : beans::Optional< beans::Ambiguous<sal_Bool> >
1783 : 1666 : BackendImpl::ComponentsPackageImpl::isRegistered_(
1784 : : ::osl::ResettableMutexGuard &,
1785 : : ::rtl::Reference<AbortChannel> const &,
1786 : : Reference<XCommandEnvironment> const & )
1787 : : {
1788 : : return beans::Optional< beans::Ambiguous<sal_Bool> >(
1789 : : true,
1790 : : beans::Ambiguous<sal_Bool>(
1791 [ + - ][ + - ]: 1666 : getMyBackend()->hasInUnoRc(RCITEM_COMPONENTS, getURL()), false));
[ + - ]
1792 : : }
1793 : :
1794 : 310 : void BackendImpl::ComponentsPackageImpl::processPackage_(
1795 : : ::osl::ResettableMutexGuard &,
1796 : : bool doRegisterPackage,
1797 : : bool startup,
1798 : : ::rtl::Reference<AbortChannel> const & abortChannel,
1799 : : Reference<XCommandEnvironment> const & xCmdEnv )
1800 : : {
1801 [ + - ]: 310 : BackendImpl * that = getMyBackend();
1802 [ + - ]: 310 : rtl::OUString url(getURL());
1803 [ + - ]: 310 : if (doRegisterPackage) {
1804 [ - + ]: 310 : if (!startup) {
1805 : : css::uno::Reference< css::uno::XComponentContext > context(
1806 [ # # ][ # # ]: 0 : that->getObject(url), css::uno::UNO_QUERY);
1807 [ # # ]: 0 : if (!context.is()) {
1808 : : context.set(
1809 : : that->insertObject(
1810 : : url,
1811 : : raise_uno_process(
1812 [ # # ]: 0 : that->getComponentContext(), abortChannel)),
1813 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY_THROW);
1814 : : }
1815 : : // This relies on the root component context's service manager
1816 : : // supporting the extended XSet semantics:
1817 [ # # ]: 0 : css::uno::Sequence< css::beans::NamedValue > args(2);
1818 [ # # ][ # # ]: 0 : args[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uri"));
1819 [ # # ][ # # ]: 0 : args[0].Value <<= expandUnoRcUrl(url);
[ # # ]
1820 [ # # ]: 0 : args[1].Name = rtl::OUString(
1821 [ # # ]: 0 : RTL_CONSTASCII_USTRINGPARAM("component-context"));
1822 [ # # ][ # # ]: 0 : args[1].Value <<= context;
1823 : : css::uno::Reference< css::container::XSet > smgr(
1824 [ # # ][ # # ]: 0 : that->getRootContext()->getServiceManager(),
1825 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY_THROW);
1826 [ # # ][ # # ]: 0 : smgr->insert(css::uno::makeAny(args));
[ # # ][ # # ]
1827 : : }
1828 [ + - ]: 310 : that->addToUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1829 : : } else { // revoke
1830 [ # # ]: 0 : that->removeFromUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
1831 [ # # ]: 0 : if (!startup) {
1832 : : // This relies on the root component context's service manager
1833 : : // supporting the extended XSet semantics:
1834 [ # # ]: 0 : css::uno::Sequence< css::beans::NamedValue > args(1);
1835 [ # # ][ # # ]: 0 : args[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uri"));
1836 [ # # ][ # # ]: 0 : args[0].Value <<= expandUnoRcUrl(url);
[ # # ]
1837 : : css::uno::Reference< css::container::XSet > smgr(
1838 [ # # ][ # # ]: 0 : that->getRootContext()->getServiceManager(),
1839 [ # # ][ # # ]: 0 : css::uno::UNO_QUERY_THROW);
1840 [ # # ][ # # ]: 0 : smgr->remove(css::uno::makeAny(args));
[ # # ][ # # ]
1841 : : }
1842 [ # # ]: 0 : that->releaseObject(url);
1843 [ # # ]: 0 : that->revokeEntryFromDb(url); // in case it got added with old code
1844 : 310 : }
1845 : 310 : }
1846 : :
1847 : 620 : BackendImpl::ComponentsPackageImpl::ComponentsPackageImpl(
1848 : : ::rtl::Reference<PackageRegistryBackend> const & myBackend,
1849 : : OUString const & url, OUString const & name,
1850 : : Reference<deployment::XPackageTypeInfo> const & xPackageType,
1851 : : bool bRemoved, OUString const & identifier)
1852 : : : Package( myBackend, url, name, name /* display-name */,
1853 : 620 : xPackageType, bRemoved, identifier)
1854 : 620 : {}
1855 : :
1856 : : } // anon namespace
1857 : :
1858 : : namespace sdecl = comphelper::service_decl;
1859 : 124 : sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
1860 : 124 : extern sdecl::ServiceDecl const serviceDecl(
1861 : : serviceBI,
1862 : : IMPLEMENTATION_NAME,
1863 : : BACKEND_SERVICE_NAME );
1864 : :
1865 : : } // namespace component
1866 : : } // namespace backend
1867 [ + - ][ + - ]: 372 : } // namespace dp_registry
1868 : :
1869 : :
1870 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|