Update ooo320-m1
[ooovba.git] / desktop / source / deployment / registry / component / dp_component.cxx
blob3f2def05d71ef11823571511def880ec47239026
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_component.cxx,v $
10 * $Revision: 1.24 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_desktop.hxx"
34 #include "dp_component.hrc"
35 #include "dp_backend.h"
36 #include "dp_platform.hxx"
37 #include "dp_ucb.h"
38 #include "rtl/string.hxx"
39 #include "rtl/strbuf.hxx"
40 #include "rtl/ustrbuf.hxx"
41 #include "rtl/uri.hxx"
42 #include "cppuhelper/exc_hlp.hxx"
43 #include "ucbhelper/content.hxx"
44 #include "comphelper/anytostring.hxx"
45 #include "comphelper/servicedecl.hxx"
46 #include "comphelper/sequence.hxx"
47 #include "xmlscript/xml_helper.hxx"
48 #include "svtools/inettype.hxx"
49 #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
50 #include "com/sun/star/container/XNameContainer.hpp"
51 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
52 #include "com/sun/star/container/XSet.hpp"
53 #include "com/sun/star/registry/XSimpleRegistry.hpp"
54 #include "com/sun/star/registry/XImplementationRegistration.hpp"
55 #include "com/sun/star/loader/XImplementationLoader.hpp"
56 #include "com/sun/star/io/XInputStream.hpp"
57 #include "com/sun/star/ucb/NameClash.hpp"
58 #include "com/sun/star/util/XMacroExpander.hpp"
59 #include <list>
60 #include <hash_map>
61 #include <vector>
62 #include <memory>
63 #include <algorithm>
66 using namespace ::dp_misc;
67 using namespace ::com::sun::star;
68 using namespace ::com::sun::star::uno;
69 using namespace ::com::sun::star::ucb;
70 using ::rtl::OUString;
72 namespace dp_registry {
73 namespace backend {
74 namespace component {
75 namespace {
77 typedef ::std::list<OUString> t_stringlist;
78 typedef ::std::vector< ::std::pair<OUString, OUString> > t_stringpairvec;
80 /** return a vector of bootstrap variables which have been provided
81 as command arguments.
83 ::std::vector<OUString> getCmdBootstrapVariables()
85 ::std::vector<OUString> ret;
86 sal_uInt32 count = osl_getCommandArgCount();
87 for (sal_uInt32 i = 0; i < count; i++)
89 OUString arg;
90 osl_getCommandArg(i, &arg.pData);
91 if (arg.matchAsciiL("-env:", 5))
92 ret.push_back(arg);
94 return ret;
97 bool jarManifestHeaderPresent(
98 OUString const & url, OUString const & name,
99 Reference<XCommandEnvironment> const & xCmdEnv )
101 ::rtl::OUStringBuffer buf;
102 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.zip://") );
103 buf.append(
104 ::rtl::Uri::encode(
105 url, rtl_UriCharClassRegName, rtl_UriEncodeIgnoreEscapes,
106 RTL_TEXTENCODING_UTF8 ) );
107 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("/META-INF/MANIFEST.MF") );
108 ::ucbhelper::Content manifestContent;
109 OUString line;
110 return
111 create_ucb_content(
112 &manifestContent, buf.makeStringAndClear(), xCmdEnv,
113 false /* no throw */ )
114 && readLine( &line, name, manifestContent, RTL_TEXTENCODING_ASCII_US );
117 //==============================================================================
118 class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
120 class ComponentPackageImpl : public ::dp_registry::backend::Package
122 BackendImpl * getMyBackend() const;
124 const OUString m_loader;
125 Reference<XComponentContext> m_xRemoteContext;
127 enum reg {
128 REG_UNINIT, REG_VOID, REG_REGISTERED, REG_NOT_REGISTERED
129 } m_registered;
131 Reference<loader::XImplementationLoader> getComponentInfo(
132 t_stringlist * pImplNames, t_stringpairvec * pSingletons,
133 Reference<XComponentContext> const & xContext );
135 virtual void SAL_CALL disposing();
137 // Package
138 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
139 ::osl::ResettableMutexGuard & guard,
140 ::rtl::Reference<AbortChannel> const & abortChannel,
141 Reference<XCommandEnvironment> const & xCmdEnv );
142 virtual void processPackage_(
143 ::osl::ResettableMutexGuard & guard,
144 bool registerPackage,
145 ::rtl::Reference<AbortChannel> const & abortChannel,
146 Reference<XCommandEnvironment> const & xCmdEnv );
148 const Reference<registry::XSimpleRegistry> getRDB() const;
150 public:
151 inline ComponentPackageImpl(
152 ::rtl::Reference<PackageRegistryBackend> const & myBackend,
153 OUString const & url, OUString const & name,
154 Reference<deployment::XPackageTypeInfo> const & xPackageType,
155 OUString const & loader )
156 : Package( myBackend, url, name, name /* display-name */,
157 xPackageType ),
158 m_loader( loader ),
159 m_registered( REG_UNINIT )
162 friend class ComponentPackageImpl;
164 class TypelibraryPackageImpl : public ::dp_registry::backend::Package
166 BackendImpl * getMyBackend() const;
168 const bool m_jarFile;
169 Reference<container::XHierarchicalNameAccess> m_xTDprov;
171 virtual void SAL_CALL disposing();
173 // Package
174 virtual beans::Optional< beans::Ambiguous<sal_Bool> > isRegistered_(
175 ::osl::ResettableMutexGuard & guard,
176 ::rtl::Reference<AbortChannel> const & abortChannel,
177 Reference<XCommandEnvironment> const & xCmdEnv );
178 virtual void processPackage_(
179 ::osl::ResettableMutexGuard & guard,
180 bool registerPackage,
181 ::rtl::Reference<AbortChannel> const & abortChannel,
182 Reference<XCommandEnvironment> const & xCmdEnv );
184 public:
185 inline TypelibraryPackageImpl(
186 ::rtl::Reference<PackageRegistryBackend> const & myBackend,
187 OUString const & url, OUString const & name,
188 Reference<deployment::XPackageTypeInfo> const & xPackageType,
189 bool jarFile )
190 : Package( myBackend, url, name, name /* display-name */,
191 xPackageType ),
192 m_jarFile( jarFile )
195 friend class TypelibraryPackageImpl;
197 t_stringlist m_jar_typelibs;
198 t_stringlist m_rdb_typelibs;
199 t_stringlist & getTypelibs( bool jar ) {
200 return jar ? m_jar_typelibs : m_rdb_typelibs;
203 bool m_unorc_inited;
204 bool m_unorc_modified;
205 bool bSwitchedRdbFiles;
207 typedef ::std::hash_map< OUString, Reference<XInterface>,
208 ::rtl::OUStringHash > t_string2object;
209 t_string2object m_backendObjects;
211 // PackageRegistryBackend
212 virtual Reference<deployment::XPackage> bindPackage_(
213 OUString const & url, OUString const & mediaType,
214 Reference<XCommandEnvironment> const & xCmdEnv );
216 virtual void SAL_CALL disposing();
218 const Reference<deployment::XPackageTypeInfo> m_xDynComponentTypeInfo;
219 const Reference<deployment::XPackageTypeInfo> m_xJavaComponentTypeInfo;
220 const Reference<deployment::XPackageTypeInfo> m_xPythonComponentTypeInfo;
221 const Reference<deployment::XPackageTypeInfo> m_xRDBTypelibTypeInfo;
222 const Reference<deployment::XPackageTypeInfo> m_xJavaTypelibTypeInfo;
223 Sequence< Reference<deployment::XPackageTypeInfo> > m_typeInfos;
225 OUString m_commonRDB;
226 OUString m_nativeRDB;
227 Reference<registry::XSimpleRegistry> m_xCommonRDB;
228 Reference<registry::XSimpleRegistry> m_xNativeRDB;
230 void unorc_verify_init( Reference<XCommandEnvironment> const & xCmdEnv );
231 void unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv );
233 Reference<XInterface> getObject( OUString const & id );
234 Reference<XInterface> insertObject(
235 OUString const & id, Reference<XInterface> const & xObject );
236 void releaseObject( OUString const & id );
238 bool addToUnoRc( bool jarFile, OUString const & url,
239 Reference<XCommandEnvironment> const & xCmdEnv );
240 bool removeFromUnoRc( bool jarFile, OUString const & url,
241 Reference<XCommandEnvironment> const & xCmdEnv );
242 bool hasInUnoRc( bool jarFile, OUString const & url );
246 public:
247 BackendImpl( Sequence<Any> const & args,
248 Reference<XComponentContext> const & xComponentContext );
250 // XPackageRegistry
251 virtual Sequence< Reference<deployment::XPackageTypeInfo> > SAL_CALL
252 getSupportedPackageTypes() throw (RuntimeException);
254 using PackageRegistryBackend::disposing;
256 //Will be called from ComponentPackageImpl
257 void initServiceRdbFiles();
260 //______________________________________________________________________________
261 const Reference<registry::XSimpleRegistry>
262 BackendImpl::ComponentPackageImpl::getRDB() const
264 BackendImpl * that = getMyBackend();
265 //Late "initialization" of the services rdb files
266 //This is to prevent problems when running several
267 //instances of OOo with root rights in parallel. This
268 //would otherwise cause problems when copying the rdbs.
269 //Now this code is only performed if isRegistered or processPackage
270 //is called.
272 const ::osl::MutexGuard guard( getMutex() );
273 if (!that->bSwitchedRdbFiles)
275 that->bSwitchedRdbFiles = true;
276 that->initServiceRdbFiles();
280 if (m_loader.equalsAsciiL(
281 RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.SharedLibrary") ))
282 return that->m_xNativeRDB;
283 else
284 return that->m_xCommonRDB;
287 BackendImpl * BackendImpl::ComponentPackageImpl::getMyBackend() const
289 BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
290 if (NULL == pBackend)
292 //Throws a DisposedException
293 check();
294 //We should never get here...
295 throw RuntimeException(
296 OUSTR("Failed to get the BackendImpl"),
297 static_cast<OWeakObject*>(const_cast<ComponentPackageImpl *>(this)));
299 return pBackend;
303 //______________________________________________________________________________
304 void BackendImpl::ComponentPackageImpl::disposing()
306 m_xRemoteContext.clear();
307 Package::disposing();
310 //______________________________________________________________________________
311 void BackendImpl::TypelibraryPackageImpl::disposing()
313 m_xTDprov.clear();
314 Package::disposing();
317 //______________________________________________________________________________
318 void BackendImpl::disposing()
320 try {
321 m_backendObjects = t_string2object();
322 if (m_xNativeRDB.is()) {
323 m_xNativeRDB->close();
324 m_xNativeRDB.clear();
326 if (m_xCommonRDB.is()) {
327 m_xCommonRDB->close();
328 m_xCommonRDB.clear();
330 unorc_flush( Reference<XCommandEnvironment>() );
332 PackageRegistryBackend::disposing();
334 catch (RuntimeException &) {
335 throw;
337 catch (Exception &) {
338 Any exc( ::cppu::getCaughtException() );
339 throw lang::WrappedTargetRuntimeException(
340 OUSTR("caught unexpected exception while disposing..."),
341 static_cast<OWeakObject *>(this), exc );
345 void BackendImpl::initServiceRdbFiles()
347 const Reference<XCommandEnvironment> xCmdEnv;
348 if (! m_readOnly) {
349 ::ucbhelper::Content cacheDir( getCachePath(), xCmdEnv );
350 ::ucbhelper::Content oldRDB;
351 // switch common rdb:
352 if (m_commonRDB.getLength() > 0)
353 create_ucb_content(
354 &oldRDB, makeURL( getCachePath(), m_commonRDB ),
355 xCmdEnv, false /* no throw */ );
356 m_commonRDB = m_commonRDB.equalsAsciiL(
357 RTL_CONSTASCII_STRINGPARAM("common.rdb") )
358 ? OUSTR("common_.rdb") : OUSTR("common.rdb");
359 if (oldRDB.get().is())
362 if (! cacheDir.transferContent(
363 oldRDB, ::ucbhelper::InsertOperation_COPY,
364 m_commonRDB, NameClash::OVERWRITE ))
367 throw RuntimeException(
368 OUSTR("UCB transferContent() failed!"), 0 );
370 oldRDB = ::ucbhelper::Content();
372 // switch native rdb:
373 if (m_nativeRDB.getLength() > 0)
374 create_ucb_content(
375 &oldRDB, makeURL( getCachePath(), m_nativeRDB ),
376 xCmdEnv, false /* no throw */ );
377 const OUString plt_rdb( getPlatformString() + OUSTR(".rdb") );
378 const OUString plt_rdb_( getPlatformString() + OUSTR("_.rdb") );
379 m_nativeRDB = m_nativeRDB.equals( plt_rdb ) ? plt_rdb_ : plt_rdb;
380 if (oldRDB.get().is())
382 if (! cacheDir.transferContent(
383 oldRDB, ::ucbhelper::InsertOperation_COPY,
384 m_nativeRDB, NameClash::OVERWRITE ))
385 throw RuntimeException(
386 OUSTR("UCB transferContent() failed!"), 0 );
389 // UNO is bootstrapped, flush for next process start:
390 m_unorc_modified = true;
391 unorc_flush( Reference<XCommandEnvironment>() );
394 // common rdb for java, native rdb for shared lib components
395 if (m_commonRDB.getLength() > 0) {
396 m_xCommonRDB.set(
397 m_xComponentContext->getServiceManager()
398 ->createInstanceWithContext(
399 OUSTR("com.sun.star.registry.SimpleRegistry"),
400 m_xComponentContext ), UNO_QUERY_THROW );
401 m_xCommonRDB->open(
402 makeURL( expandUnoRcUrl(getCachePath()), m_commonRDB ),
403 m_readOnly, !m_readOnly );
405 if (m_nativeRDB.getLength() > 0) {
406 m_xNativeRDB.set(
407 m_xComponentContext->getServiceManager()
408 ->createInstanceWithContext(
409 OUSTR("com.sun.star.registry.SimpleRegistry"),
410 m_xComponentContext ), UNO_QUERY_THROW );
411 m_xNativeRDB->open(
412 makeURL( expandUnoRcUrl(getCachePath()), m_nativeRDB ),
413 m_readOnly, !m_readOnly );
417 //______________________________________________________________________________
418 BackendImpl::BackendImpl(
419 Sequence<Any> const & args,
420 Reference<XComponentContext> const & xComponentContext )
421 : PackageRegistryBackend( args, xComponentContext ),
422 m_unorc_inited( false ),
423 m_unorc_modified( false ),
424 bSwitchedRdbFiles(false),
425 m_xDynComponentTypeInfo( new Package::TypeInfo(
426 OUSTR("application/"
427 "vnd.sun.star.uno-component;"
428 "type=native;platform=") +
429 getPlatformString(),
430 OUSTR("*" SAL_DLLEXTENSION),
431 getResourceString(RID_STR_DYN_COMPONENT),
432 RID_IMG_COMPONENT,
433 RID_IMG_COMPONENT_HC ) ),
434 m_xJavaComponentTypeInfo( new Package::TypeInfo(
435 OUSTR("application/"
436 "vnd.sun.star.uno-component;"
437 "type=Java"),
438 OUSTR("*.jar"),
439 getResourceString(RID_STR_JAVA_COMPONENT),
440 RID_IMG_JAVA_COMPONENT,
441 RID_IMG_JAVA_COMPONENT_HC ) ),
442 m_xPythonComponentTypeInfo( new Package::TypeInfo(
443 OUSTR("application/"
444 "vnd.sun.star.uno-component;"
445 "type=Python"),
446 OUSTR("*.py"),
447 getResourceString(
448 RID_STR_PYTHON_COMPONENT),
449 RID_IMG_COMPONENT,
450 RID_IMG_COMPONENT_HC ) ),
451 m_xRDBTypelibTypeInfo( new Package::TypeInfo(
452 OUSTR("application/"
453 "vnd.sun.star.uno-typelibrary;"
454 "type=RDB"),
455 OUSTR("*.rdb"),
456 getResourceString(RID_STR_RDB_TYPELIB),
457 RID_IMG_TYPELIB, RID_IMG_TYPELIB_HC ) ),
458 m_xJavaTypelibTypeInfo( new Package::TypeInfo(
459 OUSTR("application/"
460 "vnd.sun.star.uno-typelibrary;"
461 "type=Java"),
462 OUSTR("*.jar"),
463 getResourceString(RID_STR_JAVA_TYPELIB),
464 RID_IMG_JAVA_TYPELIB,
465 RID_IMG_JAVA_TYPELIB_HC ) ),
466 m_typeInfos( 5 )
468 m_typeInfos[ 0 ] = m_xDynComponentTypeInfo;
469 m_typeInfos[ 1 ] = m_xJavaComponentTypeInfo;
470 m_typeInfos[ 2 ] = m_xPythonComponentTypeInfo;
471 m_typeInfos[ 3 ] = m_xRDBTypelibTypeInfo;
472 m_typeInfos[ 4 ] = m_xJavaTypelibTypeInfo;
474 const Reference<XCommandEnvironment> xCmdEnv;
476 if (transientMode())
478 // in-mem rdbs:
479 // common rdb for java, native rdb for shared lib components
480 m_xCommonRDB.set(
481 xComponentContext->getServiceManager()->createInstanceWithContext(
482 OUSTR("com.sun.star.registry.SimpleRegistry"),
483 xComponentContext ), UNO_QUERY_THROW );
484 m_xCommonRDB->open( OUString() /* in-mem */,
485 false /* ! read-only */, true /* create */ );
486 m_xNativeRDB.set(
487 xComponentContext->getServiceManager()->createInstanceWithContext(
488 OUSTR("com.sun.star.registry.SimpleRegistry"),
489 xComponentContext ), UNO_QUERY_THROW );
490 m_xNativeRDB->open( OUString() /* in-mem */,
491 false /* ! read-only */, true /* create */ );
493 else
495 unorc_verify_init( xCmdEnv );
499 // XPackageRegistry
500 //______________________________________________________________________________
501 Sequence< Reference<deployment::XPackageTypeInfo> >
502 BackendImpl::getSupportedPackageTypes() throw (RuntimeException)
504 return m_typeInfos;
507 // PackageRegistryBackend
508 //______________________________________________________________________________
509 Reference<deployment::XPackage> BackendImpl::bindPackage_(
510 OUString const & url, OUString const & mediaType_,
511 Reference<XCommandEnvironment> const & xCmdEnv )
513 OUString mediaType(mediaType_);
514 if (mediaType.getLength() == 0 ||
515 mediaType.equalsAsciiL(
516 RTL_CONSTASCII_STRINGPARAM(
517 "application/vnd.sun.star.uno-component") ) ||
518 mediaType.equalsAsciiL(
519 RTL_CONSTASCII_STRINGPARAM(
520 "application/vnd.sun.star.uno-typelibrary") ))
522 // detect exact media-type:
523 ::ucbhelper::Content ucbContent;
524 if (create_ucb_content( &ucbContent, url, xCmdEnv )) {
525 const OUString title( ucbContent.getPropertyValue(
526 StrTitle::get() ).get<OUString>() );
527 if (title.endsWithIgnoreAsciiCaseAsciiL(
528 RTL_CONSTASCII_STRINGPARAM(SAL_DLLEXTENSION) ))
530 mediaType = OUSTR("application/vnd.sun.star.uno-component;"
531 "type=native;platform=") +
532 getPlatformString();
534 else if (title.endsWithIgnoreAsciiCaseAsciiL(
535 RTL_CONSTASCII_STRINGPARAM(".jar") ))
537 if (jarManifestHeaderPresent(
538 url, OUSTR("RegistrationClassName"), xCmdEnv ))
539 mediaType = OUSTR(
540 "application/vnd.sun.star.uno-component;type=Java");
541 if (mediaType.getLength() == 0)
542 mediaType = OUSTR(
543 "application/vnd.sun.star.uno-typelibrary;type=Java");
545 else if (title.endsWithIgnoreAsciiCaseAsciiL(
546 RTL_CONSTASCII_STRINGPARAM(".py") ))
547 mediaType =
548 OUSTR("application/vnd.sun.star.uno-component;type=Python");
549 else if (title.endsWithIgnoreAsciiCaseAsciiL(
550 RTL_CONSTASCII_STRINGPARAM(".rdb") ))
551 mediaType =
552 OUSTR("application/vnd.sun.star.uno-typelibrary;type=RDB");
554 if (mediaType.getLength() == 0)
555 throw lang::IllegalArgumentException(
556 StrCannotDetectMediaType::get() + url,
557 static_cast<OWeakObject *>(this), static_cast<sal_Int16>(-1) );
560 String type, subType;
561 INetContentTypeParameterList params;
562 if (INetContentTypes::parse( mediaType, type, subType, &params ))
564 if (type.EqualsIgnoreCaseAscii("application"))
566 ::ucbhelper::Content ucbContent( url, xCmdEnv );
567 const OUString name( ucbContent.getPropertyValue(
568 StrTitle::get() ).get<OUString>() );
569 if (subType.EqualsIgnoreCaseAscii("vnd.sun.star.uno-component"))
571 // xxx todo: probe and evaluate component xml description
573 INetContentTypeParameter const * param = params.find(
574 ByteString("platform") );
575 if (param == 0 || platform_fits( param->m_sValue )) {
576 param = params.find( ByteString("type") );
577 if (param != 0)
579 String const & value = param->m_sValue;
580 if (value.EqualsIgnoreCaseAscii("native")) {
581 return new BackendImpl::ComponentPackageImpl(
582 this, url, name, m_xDynComponentTypeInfo,
583 OUSTR("com.sun.star.loader.SharedLibrary") );
585 if (value.EqualsIgnoreCaseAscii("Java")) {
586 return new BackendImpl::ComponentPackageImpl(
587 this, url, name, m_xJavaComponentTypeInfo,
588 OUSTR("com.sun.star.loader.Java2") );
590 if (value.EqualsIgnoreCaseAscii("Python")) {
591 return new BackendImpl::ComponentPackageImpl(
592 this, url, name, m_xPythonComponentTypeInfo,
593 OUSTR("com.sun.star.loader.Python") );
598 else if (subType.EqualsIgnoreCaseAscii(
599 "vnd.sun.star.uno-typelibrary"))
601 INetContentTypeParameter const * param = params.find(
602 ByteString("type") );
603 if (param != 0) {
604 String const & value = param->m_sValue;
605 if (value.EqualsIgnoreCaseAscii("RDB"))
607 return new BackendImpl::TypelibraryPackageImpl(
608 this, url, name, m_xRDBTypelibTypeInfo,
609 false /* rdb */ );
611 if (value.EqualsIgnoreCaseAscii("Java")) {
612 return new BackendImpl::TypelibraryPackageImpl(
613 this, url, name, m_xJavaTypelibTypeInfo,
614 true /* jar */ );
620 throw lang::IllegalArgumentException(
621 StrUnsupportedMediaType::get() + mediaType,
622 static_cast<OWeakObject *>(this),
623 static_cast<sal_Int16>(-1) );
626 //##############################################################################
628 //______________________________________________________________________________
629 void BackendImpl::unorc_verify_init(
630 Reference<XCommandEnvironment> const & xCmdEnv )
632 if (transientMode())
633 return;
634 const ::osl::MutexGuard guard( getMutex() );
635 if (! m_unorc_inited)
637 // common rc:
638 ::ucbhelper::Content ucb_content;
639 if (create_ucb_content(
640 &ucb_content,
641 makeURL( getCachePath(), OUSTR("unorc") ),
642 xCmdEnv, false /* no throw */ ))
644 OUString line;
645 if (readLine( &line, OUSTR("UNO_JAVA_CLASSPATH="), ucb_content,
646 RTL_TEXTENCODING_UTF8 ))
648 sal_Int32 index = sizeof ("UNO_JAVA_CLASSPATH=") - 1;
649 do {
650 OUString token( line.getToken( 0, ' ', index ).trim() );
651 if (token.getLength() > 0) {
652 // cleanup, check if existing:
653 if (create_ucb_content(
654 0, expandUnoRcTerm(token), xCmdEnv,
655 false /* no throw */ )) {
656 m_jar_typelibs.push_back( token );
658 else
659 OSL_ENSURE(
660 0, "### invalid UNO_JAVA_CLASSPATH entry!" );
663 while (index >= 0);
665 if (readLine( &line, OUSTR("UNO_TYPES="), ucb_content,
666 RTL_TEXTENCODING_UTF8 )) {
667 sal_Int32 index = sizeof ("UNO_TYPES=") - 1;
668 do {
669 OUString token( line.getToken( 0, ' ', index ).trim() );
670 if (token.getLength() > 0) {
671 if (token[ 0 ] == '?')
672 token = token.copy( 1 );
673 // cleanup, check if existing:
674 if (create_ucb_content(
675 0, expandUnoRcTerm(token),
676 xCmdEnv, false /* no throw */ )) {
677 m_rdb_typelibs.push_back( token );
679 else
680 OSL_ENSURE( 0, "### invalid UNO_TYPES entry!" );
683 while (index >= 0);
685 if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
686 RTL_TEXTENCODING_UTF8 )) {
687 sal_Int32 start = sizeof ("UNO_SERVICES=?$ORIGIN/") - 1;
688 sal_Int32 sep = line.indexOf( ' ', start );
689 OSL_ASSERT( sep > 0 );
690 m_commonRDB = line.copy( start, sep - start );
693 // native rc:
694 if (create_ucb_content(
695 &ucb_content,
696 makeURL( getCachePath(), getPlatformString() + OUSTR("rc")),
697 xCmdEnv, false /* no throw */ )) {
698 if (readLine( &line, OUSTR("UNO_SERVICES="), ucb_content,
699 RTL_TEXTENCODING_UTF8 )) {
700 m_nativeRDB = line.copy(
701 sizeof ("UNO_SERVICES=?$ORIGIN/") - 1 );
705 m_unorc_modified = false;
706 m_unorc_inited = true;
710 //______________________________________________________________________________
711 void BackendImpl::unorc_flush( Reference<XCommandEnvironment> const & xCmdEnv )
713 if (transientMode())
714 return;
715 if (!m_unorc_inited || !m_unorc_modified)
716 return;
718 ::rtl::OStringBuffer buf;
719 // UNO_USER_PACKAGES_CACHE, UNO_SHARED_PACKAGES_CACHE have to be resolved
720 // locally:
721 if (m_eContext == CONTEXT_USER) {
722 buf.append( RTL_CONSTASCII_STRINGPARAM(
723 "UNO_USER_PACKAGES_CACHE=$ORIGIN/../..") );
725 else if (m_eContext == CONTEXT_SHARED) {
726 buf.append( RTL_CONSTASCII_STRINGPARAM(
727 "UNO_SHARED_PACKAGES_CACHE=$ORIGIN/../..") );
729 else
730 OSL_ASSERT(0);
731 buf.append(LF);
733 if (! m_jar_typelibs.empty())
735 t_stringlist::const_iterator iPos( m_jar_typelibs.begin() );
736 t_stringlist::const_iterator const iEnd( m_jar_typelibs.end() );
737 buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_JAVA_CLASSPATH=") );
738 while (iPos != iEnd) {
739 // encoded ASCII file-urls:
740 const ::rtl::OString item(
741 ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
742 buf.append( item );
743 ++iPos;
744 if (iPos != iEnd)
745 buf.append( ' ' );
747 buf.append(LF);
749 if (! m_rdb_typelibs.empty())
751 t_stringlist::const_iterator iPos( m_rdb_typelibs.begin() );
752 t_stringlist::const_iterator const iEnd( m_rdb_typelibs.end() );
753 buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_TYPES=") );
754 while (iPos != iEnd) {
755 buf.append( '?' );
756 // encoded ASCII file-urls:
757 const ::rtl::OString item(
758 ::rtl::OUStringToOString( *iPos, RTL_TEXTENCODING_ASCII_US ) );
759 buf.append( item );
760 ++iPos;
761 if (iPos != iEnd)
762 buf.append( ' ' );
764 buf.append(LF);
766 if (m_commonRDB.getLength() > 0 || m_nativeRDB.getLength() > 0)
768 buf.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=?$ORIGIN/") );
769 buf.append( ::rtl::OUStringToOString(
770 m_commonRDB, RTL_TEXTENCODING_ASCII_US ) );
771 if (m_nativeRDB.getLength() > 0)
773 buf.append( RTL_CONSTASCII_STRINGPARAM(
774 " ${$ORIGIN/${_OS}_${_ARCH}rc:UNO_SERVICES}") );
775 buf.append(LF);
777 // write native rc:
778 ::rtl::OStringBuffer buf2;
779 buf2.append( RTL_CONSTASCII_STRINGPARAM("UNO_SERVICES=?$ORIGIN/") );
780 buf2.append( ::rtl::OUStringToOString(
781 m_nativeRDB, RTL_TEXTENCODING_ASCII_US ) );
782 buf2.append(LF);
784 const Reference<io::XInputStream> xData(
785 ::xmlscript::createInputStream(
786 ::rtl::ByteSequence(
787 reinterpret_cast<sal_Int8 const *>(buf2.getStr()),
788 buf2.getLength() ) ) );
789 ::ucbhelper::Content ucb_content(
790 makeURL( getCachePath(), getPlatformString() + OUSTR("rc") ),
791 xCmdEnv );
792 ucb_content.writeStream( xData, true /* replace existing */ );
796 // write unorc:
797 const Reference<io::XInputStream> xData(
798 ::xmlscript::createInputStream(
799 ::rtl::ByteSequence(
800 reinterpret_cast<sal_Int8 const *>(buf.getStr()),
801 buf.getLength() ) ) );
802 ::ucbhelper::Content ucb_content(
803 makeURL( getCachePath(), OUSTR("unorc") ), xCmdEnv );
804 ucb_content.writeStream( xData, true /* replace existing */ );
806 m_unorc_modified = false;
809 //------------------------------------------------------------------------------
810 inline OUString makeRcTerm( OUString const & url )
812 OSL_ASSERT( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM(
813 "vnd.sun.star.expand:") ) );
814 if (url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.expand:") )) {
815 // cut protocol:
816 OUString rcterm( url.copy( sizeof ("vnd.sun.star.expand:") - 1 ) );
817 // decode uric class chars:
818 rcterm = ::rtl::Uri::decode(
819 rcterm, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
820 return rcterm;
822 else
823 return url;
826 //______________________________________________________________________________
827 bool BackendImpl::addToUnoRc( bool jarFile, OUString const & url_,
828 Reference<XCommandEnvironment> const & xCmdEnv )
830 const OUString rcterm( makeRcTerm(url_) );
831 const ::osl::MutexGuard guard( getMutex() );
832 unorc_verify_init( xCmdEnv );
833 t_stringlist & rSet = getTypelibs(jarFile);
834 if (::std::find( rSet.begin(), rSet.end(), rcterm ) == rSet.end()) {
835 rSet.push_front( rcterm ); // prepend to list, thus overriding
836 // write immediately:
837 m_unorc_modified = true;
838 unorc_flush( xCmdEnv );
839 return true;
841 else
842 return false;
845 //______________________________________________________________________________
846 bool BackendImpl::removeFromUnoRc(
847 bool jarFile, OUString const & url_,
848 Reference<XCommandEnvironment> const & xCmdEnv )
850 const OUString rcterm( makeRcTerm(url_) );
851 const ::osl::MutexGuard guard( getMutex() );
852 unorc_verify_init( xCmdEnv );
853 getTypelibs(jarFile).remove( rcterm );
854 // write immediately:
855 m_unorc_modified = true;
856 unorc_flush( xCmdEnv );
857 return true;
860 //______________________________________________________________________________
861 bool BackendImpl::hasInUnoRc(
862 bool jarFile, OUString const & url_ )
864 const OUString rcterm( makeRcTerm(url_) );
865 const ::osl::MutexGuard guard( getMutex() );
866 t_stringlist const & rSet = getTypelibs(jarFile);
867 return ::std::find( rSet.begin(), rSet.end(), rcterm ) != rSet.end();
870 //______________________________________________________________________________
871 void BackendImpl::releaseObject( OUString const & id )
873 const ::osl::MutexGuard guard( getMutex() );
874 if ( m_backendObjects.erase( id ) != 1 )
876 OSL_ASSERT( false );
880 //______________________________________________________________________________
881 Reference<XInterface> BackendImpl::getObject( OUString const & id )
883 const ::osl::MutexGuard guard( getMutex() );
884 const t_string2object::const_iterator iFind( m_backendObjects.find( id ) );
885 if (iFind == m_backendObjects.end())
886 return Reference<XInterface>();
887 else
888 return iFind->second;
891 //______________________________________________________________________________
892 Reference<XInterface> BackendImpl::insertObject(
893 OUString const & id, Reference<XInterface> const & xObject )
895 const ::osl::MutexGuard guard( getMutex() );
896 const ::std::pair<t_string2object::iterator, bool> insertion(
897 m_backendObjects.insert( t_string2object::value_type(
898 id, xObject ) ) );
899 return insertion.first->second;
902 //------------------------------------------------------------------------------
903 Reference<XComponentContext> raise_uno_process(
904 Reference<XComponentContext> const & xContext,
905 ::rtl::Reference<AbortChannel> const & abortChannel )
907 OSL_ASSERT( xContext.is() );
909 ::rtl::OUString url(
910 Reference<util::XMacroExpander>(
911 xContext->getValueByName(
912 OUSTR("/singletons/com.sun.star.util.theMacroExpander") ),
913 UNO_QUERY_THROW )->
914 expandMacros( OUSTR("$URE_BIN_DIR/uno") ) );
916 ::rtl::OUStringBuffer buf;
917 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno:pipe,name=") );
918 OUString pipeId( generateRandomPipeId() );
919 buf.append( pipeId );
920 buf.appendAscii(
921 RTL_CONSTASCII_STRINGPARAM(";urp;uno.ComponentContext") );
922 const OUString connectStr( buf.makeStringAndClear() );
924 // raise core UNO process to register/run a component,
925 // javavm service uses unorc next to executable to retrieve deployed
926 // jar typelibs
928 ::std::vector<OUString> args;
929 #if OSL_DEBUG_LEVEL <= 1
930 args.push_back( OUSTR("--quiet") );
931 #endif
932 args.push_back( OUSTR("--singleaccept") );
933 args.push_back( OUSTR("-u") );
934 args.push_back( connectStr );
935 // don't inherit from unorc:
936 args.push_back( OUSTR("-env:INIFILENAME=") );
938 //now add the bootstrap variables which were supplied on the command line
939 ::std::vector<OUString> bootvars = getCmdBootstrapVariables();
940 args.insert(args.end(), bootvars.begin(), bootvars.end());
942 oslProcess hProcess = raiseProcess(
943 url, comphelper::containerToSequence(args) );
944 try {
945 return Reference<XComponentContext>(
946 resolveUnoURL( connectStr, xContext, abortChannel.get() ),
947 UNO_QUERY_THROW );
949 catch (...) {
950 // try to terminate process:
951 if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
953 OSL_ASSERT( false );
955 throw;
959 //------------------------------------------------------------------------------
960 Reference<loader::XImplementationLoader>
961 BackendImpl::ComponentPackageImpl::getComponentInfo(
962 t_stringlist * pImplNames, t_stringpairvec * pSingletons,
963 Reference<XComponentContext> const & xContext )
965 const Reference<loader::XImplementationLoader> xLoader(
966 xContext->getServiceManager()->createInstanceWithContext(
967 m_loader, xContext ), UNO_QUERY );
968 if (! xLoader.is())
969 return Reference<loader::XImplementationLoader>();
971 // HACK: highly dependent on stoc/source/servicemanager
972 // and stoc/source/implreg implementation which rely on the same
973 // services.rdb format!
975 const Reference<registry::XSimpleRegistry> xMemReg(
976 xContext->getServiceManager()->createInstanceWithContext(
977 OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
978 UNO_QUERY_THROW );
979 xMemReg->open( OUString() /* in mem */, false, true );
980 xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), getURL() );
982 const Sequence< Reference<registry::XRegistryKey> > keys(
983 xMemReg->getRootKey()->openKeys() );
984 for ( sal_Int32 pos = keys.getLength(); pos--; )
986 Reference<registry::XRegistryKey> const & xImplKey = keys[ pos ];
987 const OUString implName(
988 xImplKey->getKeyName().copy( 1 /*leading slash*/ ) );
990 // check for singletons:
991 const Reference<registry::XRegistryKey> xSingletonKey(
992 xImplKey->openKey( OUSTR("UNO/SINGLETONS") ) );
993 if (xSingletonKey.is() && xSingletonKey->isValid())
995 const Sequence< Reference<registry::XRegistryKey> > singletonKeys(
996 xSingletonKey->openKeys() );
997 for ( sal_Int32 i = singletonKeys.getLength(); i--; )
999 Reference<registry::XRegistryKey> const & xSingleton =
1000 singletonKeys[ i ];
1001 pSingletons->push_back(
1002 ::std::pair<OUString, OUString>(
1003 xSingleton->getKeyName().copy(
1004 implName.getLength() +
1005 sizeof ("//UNO/SINGLETONS/") - 1 ),
1006 xSingleton->getStringValue() ) );
1009 else
1011 pImplNames->push_back( implName );
1015 return xLoader;
1018 // Package
1019 //______________________________________________________________________________
1020 beans::Optional< beans::Ambiguous<sal_Bool> >
1021 BackendImpl::ComponentPackageImpl::isRegistered_(
1022 ::osl::ResettableMutexGuard &,
1023 ::rtl::Reference<AbortChannel> const & abortChannel,
1024 Reference<XCommandEnvironment> const & )
1026 if (m_registered == REG_UNINIT)
1028 m_registered = REG_NOT_REGISTERED;
1029 const Reference<registry::XSimpleRegistry> xRDB( getRDB() );
1030 if (xRDB.is())
1032 // lookup rdb for location URL:
1033 const Reference<registry::XRegistryKey> xRootKey(
1034 xRDB->getRootKey() );
1035 const Reference<registry::XRegistryKey> xImplKey(
1036 xRootKey->openKey( OUSTR("IMPLEMENTATIONS") ) );
1037 Sequence<OUString> implNames;
1038 if (xImplKey.is() && xImplKey->isValid())
1039 implNames = xImplKey->getKeyNames();
1040 OUString const * pImplNames = implNames.getConstArray();
1041 sal_Int32 pos = implNames.getLength();
1042 for ( ; pos--; )
1044 checkAborted( abortChannel );
1045 const OUString key(
1046 pImplNames[ pos ] + OUSTR("/UNO/LOCATION") );
1047 const Reference<registry::XRegistryKey> xKey(
1048 xRootKey->openKey(key) );
1049 if (xKey.is() && xKey->isValid()) {
1050 const OUString location( xKey->getAsciiValue() );
1051 if (location.equalsIgnoreAsciiCase( getURL() ))
1052 break;
1055 if (pos >= 0)
1056 m_registered = REG_REGISTERED;
1059 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1060 true /* IsPresent */,
1061 beans::Ambiguous<sal_Bool>(
1062 m_registered == REG_REGISTERED,
1063 m_registered == REG_VOID /* IsAmbiguous */ ) );
1066 //______________________________________________________________________________
1067 void BackendImpl::ComponentPackageImpl::processPackage_(
1068 ::osl::ResettableMutexGuard &,
1069 bool doRegisterPackage,
1070 ::rtl::Reference<AbortChannel> const & abortChannel,
1071 Reference<XCommandEnvironment> const & xCmdEnv )
1073 BackendImpl * that = getMyBackend();
1074 const bool java = m_loader.equalsAsciiL(
1075 RTL_CONSTASCII_STRINGPARAM("com.sun.star.loader.Java2") );
1076 const OUString url( getURL() );
1077 bool isJavaTypelib = java &&
1078 !jarManifestHeaderPresent( url, OUSTR("UNO-Type-Path"), xCmdEnv );
1080 if (doRegisterPackage)
1082 if (isJavaTypelib)
1083 that->addToUnoRc( java, url, xCmdEnv );
1085 if (! m_xRemoteContext.is()) {
1086 m_xRemoteContext.set(
1087 that->getObject( url ), UNO_QUERY );
1088 if (! m_xRemoteContext.is()) {
1089 m_xRemoteContext.set(
1090 that->insertObject( url, raise_uno_process(
1091 that->getComponentContext(),
1092 abortChannel ) ),
1093 UNO_QUERY_THROW );
1097 const Reference<registry::XSimpleRegistry> xServicesRDB( getRDB() );
1098 const Reference<registry::XImplementationRegistration> xImplReg(
1099 m_xRemoteContext->getServiceManager()->createInstanceWithContext(
1100 OUSTR("com.sun.star.registry.ImplementationRegistration"),
1101 m_xRemoteContext ), UNO_QUERY_THROW );
1102 xImplReg->registerImplementation( m_loader, url, xServicesRDB );
1104 t_stringlist implNames;
1105 t_stringpairvec singletons;
1106 const Reference<loader::XImplementationLoader> xLoader(
1107 getComponentInfo( &implNames, &singletons, m_xRemoteContext ) );
1109 // factories live insertion:
1110 const Reference<container::XSet> xSet(
1111 that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW );
1112 for ( t_stringlist::const_iterator iPos( implNames.begin() );
1113 iPos != implNames.end(); ++iPos )
1115 checkAborted( abortChannel );
1116 OUString const & implName = *iPos;
1117 // activate factory:
1118 const Reference<XInterface> xFactory(
1119 xLoader->activate(
1120 implName, OUString(), url,
1121 xServicesRDB->getRootKey()->openKey(
1122 OUSTR("/IMPLEMENTATIONS/") + implName ) ) );
1123 try {
1124 xSet->insert( Any(xFactory) );
1125 } // ignore if factory has already been inserted:
1126 catch (container::ElementExistException &) {
1127 OSL_ENSURE( 0, "### factory already registered?" );
1131 if (! singletons.empty())
1133 // singletons live insertion:
1134 const Reference<container::XNameContainer> xRootContext(
1135 that->getComponentContext()->getValueByName(
1136 OUSTR("_root") ), UNO_QUERY );
1137 if (xRootContext.is())
1139 for ( t_stringpairvec::const_iterator iPos(
1140 singletons.begin() );
1141 iPos != singletons.end(); ++iPos )
1143 ::std::pair<OUString, OUString> const & sp = *iPos;
1144 const OUString name( OUSTR("/singletons/") + sp.first );
1145 // assure no arguments:
1146 try {
1147 xRootContext->removeByName( name + OUSTR("/arguments"));
1148 } catch (container::NoSuchElementException &) {}
1149 // used service:
1150 try {
1151 xRootContext->insertByName(
1152 name + OUSTR("/service"), Any(sp.second) );
1153 } catch (container::ElementExistException &) {
1154 xRootContext->replaceByName(
1155 name + OUSTR("/service"), Any(sp.second) );
1157 // singleton entry:
1158 try {
1159 xRootContext->insertByName( name, Any() );
1160 } catch (container::ElementExistException & exc) {
1161 (void) exc; // avoid warnings
1162 OSL_ENSURE(
1163 0, OUStringToOString(
1164 exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
1165 xRootContext->replaceByName( name, Any() );
1171 m_registered = REG_REGISTERED;
1173 else // revokePackage()
1175 // set to VOID during revocation process:
1176 m_registered = REG_VOID;
1178 Reference<XComponentContext> xContext;
1179 if (m_xRemoteContext.is()) // has been activated in this process
1180 xContext = m_xRemoteContext;
1181 else // has been deployed in former times
1182 xContext = that->getComponentContext();
1184 t_stringlist implNames;
1185 t_stringpairvec singletons;
1186 getComponentInfo( &implNames, &singletons, xContext );
1188 // factories live removal:
1189 const Reference<container::XSet> xSet(
1190 that->getComponentContext()->getServiceManager(), UNO_QUERY_THROW );
1191 for ( t_stringlist::const_iterator iPos( implNames.begin() );
1192 iPos != implNames.end(); ++iPos )
1194 OUString const & implName = *iPos;
1195 try {
1196 xSet->remove( Any(implName) );
1197 } // ignore if factory has not been live deployed:
1198 catch (container::NoSuchElementException &) {
1202 if (! singletons.empty())
1204 // singletons live removal:
1205 const Reference<container::XNameContainer> xRootContext(
1206 that->getComponentContext()->getValueByName(
1207 OUSTR("_root") ), UNO_QUERY );
1208 if (xRootContext.is())
1210 for ( t_stringpairvec::const_iterator iPos(
1211 singletons.begin() );
1212 iPos != singletons.end(); ++iPos )
1214 ::std::pair<OUString, OUString> const & sp = *iPos;
1215 const OUString name( OUSTR("/singletons/") + sp.first );
1216 // arguments:
1217 try {
1218 xRootContext->removeByName( name + OUSTR("/arguments"));
1220 catch (container::NoSuchElementException &) {}
1221 // used service:
1222 try {
1223 xRootContext->removeByName( name + OUSTR("/service") );
1225 catch (container::NoSuchElementException &) {}
1226 // singleton entry:
1227 try {
1228 xRootContext->removeByName( name );
1230 catch (container::NoSuchElementException & exc) {
1231 (void) exc; // avoid warnings
1232 OSL_ENSURE(
1233 0, OUStringToOString(
1234 exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
1240 const Reference<registry::XSimpleRegistry> xServicesRDB( getRDB() );
1241 const Reference<registry::XImplementationRegistration> xImplReg(
1242 xContext->getServiceManager()->createInstanceWithContext(
1243 OUSTR("com.sun.star.registry.ImplementationRegistration"),
1244 xContext ), UNO_QUERY_THROW );
1245 xImplReg->revokeImplementation( url, xServicesRDB );
1247 if (isJavaTypelib)
1248 that->removeFromUnoRc( java, url, xCmdEnv );
1250 if (m_xRemoteContext.is()) {
1251 that->releaseObject( url );
1252 m_xRemoteContext.clear();
1255 m_registered = REG_NOT_REGISTERED;
1259 //##############################################################################
1261 // Package
1262 BackendImpl * BackendImpl::TypelibraryPackageImpl::getMyBackend() const
1264 BackendImpl * pBackend = static_cast<BackendImpl *>(m_myBackend.get());
1265 if (NULL == pBackend)
1267 //May throw a DisposedException
1268 check();
1269 //We should never get here...
1270 throw RuntimeException(
1271 OUSTR("Failed to get the BackendImpl"),
1272 static_cast<OWeakObject*>(const_cast<TypelibraryPackageImpl *>(this)));
1274 return pBackend;
1276 //______________________________________________________________________________
1277 beans::Optional< beans::Ambiguous<sal_Bool> >
1278 BackendImpl::TypelibraryPackageImpl::isRegistered_(
1279 ::osl::ResettableMutexGuard &,
1280 ::rtl::Reference<AbortChannel> const &,
1281 Reference<XCommandEnvironment> const & )
1283 BackendImpl * that = getMyBackend();
1284 return beans::Optional< beans::Ambiguous<sal_Bool> >(
1285 true /* IsPresent */,
1286 beans::Ambiguous<sal_Bool>(
1287 that->hasInUnoRc( m_jarFile, getURL() ),
1288 false /* IsAmbiguous */ ) );
1291 //______________________________________________________________________________
1292 void BackendImpl::TypelibraryPackageImpl::processPackage_(
1293 ::osl::ResettableMutexGuard &,
1294 bool doRegisterPackage,
1295 ::rtl::Reference<AbortChannel> const &,
1296 Reference<XCommandEnvironment> const & xCmdEnv )
1298 BackendImpl * that = getMyBackend();
1299 const OUString url( getURL() );
1301 if (doRegisterPackage)
1303 // live insertion:
1304 if (m_jarFile) {
1305 // xxx todo add to classpath at runtime: ???
1306 //SB: It is probably not worth it to add the live inserted type
1307 // library JAR to the UnoClassLoader in the soffice process. Any
1308 // live inserted component JAR that might reference this type
1309 // library JAR runs in its own uno process, so there is probably no
1310 // Java code in the soffice process that would see any UNO types
1311 // introduced by this type library JAR.
1313 else // RDB:
1315 Reference<XComponentContext> const & xContext =
1316 that->getComponentContext();
1317 if (! m_xTDprov.is())
1319 m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1320 if (! m_xTDprov.is())
1322 const Reference<registry::XSimpleRegistry> xReg(
1323 xContext->getServiceManager()
1324 ->createInstanceWithContext(
1325 OUSTR("com.sun.star.registry.SimpleRegistry"),
1326 xContext ), UNO_QUERY_THROW );
1327 xReg->open( expandUnoRcUrl(url),
1328 true /* read-only */, false /* ! create */ );
1329 const Any arg(xReg);
1330 Reference<container::XHierarchicalNameAccess> xTDprov(
1331 xContext->getServiceManager()
1332 ->createInstanceWithArgumentsAndContext(
1333 OUSTR("com.sun.star.comp.stoc."
1334 "RegistryTypeDescriptionProvider"),
1335 Sequence<Any>( &arg, 1 ), xContext ), UNO_QUERY );
1336 OSL_ASSERT( xTDprov.is() );
1337 if (xTDprov.is())
1338 m_xTDprov.set( that->insertObject( url, xTDprov ),
1339 UNO_QUERY_THROW );
1342 if (m_xTDprov.is()) {
1343 Reference<container::XSet> xSet(
1344 xContext->getValueByName(
1345 OUSTR("/singletons/com.sun.star."
1346 "reflection.theTypeDescriptionManager") ),
1347 UNO_QUERY_THROW );
1348 xSet->insert( Any(m_xTDprov) );
1352 that->addToUnoRc( m_jarFile, url, xCmdEnv );
1354 else // revokePackage()
1356 that->removeFromUnoRc( m_jarFile, url, xCmdEnv );
1358 // revoking types at runtime, possible, sensible?
1359 if (!m_xTDprov.is())
1360 m_xTDprov.set( that->getObject( url ), UNO_QUERY );
1361 if (m_xTDprov.is()) {
1362 // remove live:
1363 const Reference<container::XSet> xSet(
1364 that->getComponentContext()->getValueByName(
1365 OUSTR("/singletons/com.sun.star."
1366 "reflection.theTypeDescriptionManager") ),
1367 UNO_QUERY_THROW );
1368 xSet->remove( Any(m_xTDprov) );
1370 that->releaseObject( url );
1371 m_xTDprov.clear();
1376 } // anon namespace
1378 namespace sdecl = comphelper::service_decl;
1379 sdecl::class_<BackendImpl, sdecl::with_args<true> > serviceBI;
1380 extern sdecl::ServiceDecl const serviceDecl(
1381 serviceBI,
1382 "com.sun.star.comp.deployment.component.PackageRegistryBackend",
1383 BACKEND_SERVICE_NAME );
1385 } // namespace component
1386 } // namespace backend
1387 } // namespace dp_registry