summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2012-04-20 22:46:42 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-04-20 22:57:32 +0200
commitc2fd9b533cfad18735df212cc7fd61443628dc0c (patch)
tree92417b3365012a8e405982302d5fcffd4f03e4e9 /desktop
parentb2fdaed46509127ec3ac2fb87404bc1b51d77778 (diff)
New cppu::defaultBootstrap_InitialComponentContext implementation
...that no longer uses XSimpleRegistry structures for the service data and thus is potentially more performant. * Registry-based functions from cppuhelper/bootstrap are deprecated now, client code should always use defaultBootstrap_InitialComponentContext. * References to the obsolete UNO_WRITERDB have been removed. * Some of the functions in cppuhelper/source that are used from multiple .cxx but had not been properly placed into .hxx have been cleaned up. * css.lang.ServiceManager XSet insert/remove now support special sequence<NamedValue> to improve live deployment/removal of XML-based extension components data. * 09524d410bbaad2a0b9b39811cb5cc16621b1396 "stoc: accelerate opening of multiple XML .rdb files in a directory" and its follow-up cb5c881a7f179391ee853f76e159254c97d776a3 "avoid using the new rdb reading logic for empty/non-existent directories" have been obsoleted by this change and have been reverted again.
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/deployment/registry/component/dp_component.cxx405
1 files changed, 182 insertions, 223 deletions
diff --git a/desktop/source/deployment/registry/component/dp_component.cxx b/desktop/source/deployment/registry/component/dp_component.cxx
index 8bfcbd5b44e4..6d5fb619553c 100644
--- a/desktop/source/deployment/registry/component/dp_component.cxx
+++ b/desktop/source/deployment/registry/component/dp_component.cxx
@@ -132,6 +132,13 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
factories,
Reference<XComponentContext> const & xContext );
+ void componentLiveInsertion(
+ ComponentBackendDb::Data const & data,
+ std::vector< css::uno::Reference< css::uno::XInterface > > const &
+ factories);
+
+ void componentLiveRemoval(ComponentBackendDb::Data const & data);
+
virtual void SAL_CALL disposing();
// Package
@@ -338,22 +345,6 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
css::uno::Reference< css::registry::XRegistryKey > const & base,
rtl::OUString const & path);
- void extractComponentData(
- css::uno::Reference< css::uno::XComponentContext > const & context,
- css::uno::Reference< css::registry::XRegistryKey > const & registry,
- ComponentBackendDb::Data * data,
- std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
- css::uno::Reference< css::loader::XImplementationLoader > const *
- componentLoader,
- rtl::OUString const * componentUrl);
-
- void componentLiveInsertion(
- ComponentBackendDb::Data const & data,
- std::vector< css::uno::Reference< css::uno::XInterface > > const &
- factories);
-
- void componentLiveRemoval(ComponentBackendDb::Data const & data);
-
css::uno::Reference< css::uno::XComponentContext > getRootContext() const;
public:
@@ -1173,16 +1164,116 @@ css::uno::Reference< css::registry::XRegistryKey > BackendImpl::openRegistryKey(
return key;
}
-void BackendImpl::extractComponentData(
+css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
+ const
+{
+ css::uno::Reference< css::uno::XComponentContext > rootContext(
+ getComponentContext()->getValueByName(
+ rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
+ css::uno::UNO_QUERY);
+ return rootContext.is() ? rootContext : getComponentContext();
+}
+
+//______________________________________________________________________________
+void BackendImpl::releaseObject( OUString const & id )
+{
+ const ::osl::MutexGuard guard( getMutex() );
+ m_backendObjects.erase( id );
+}
+
+//______________________________________________________________________________
+Reference<XInterface> BackendImpl::getObject( OUString const & id )
+{
+ const ::osl::MutexGuard guard( getMutex() );
+ const t_string2object::const_iterator iFind( m_backendObjects.find( id ) );
+ if (iFind == m_backendObjects.end())
+ return Reference<XInterface>();
+ else
+ return iFind->second;
+}
+
+//______________________________________________________________________________
+Reference<XInterface> BackendImpl::insertObject(
+ OUString const & id, Reference<XInterface> const & xObject )
+{
+ const ::osl::MutexGuard guard( getMutex() );
+ const ::std::pair<t_string2object::iterator, bool> insertion(
+ m_backendObjects.insert( t_string2object::value_type(
+ id, xObject ) ) );
+ return insertion.first->second;
+}
+
+//------------------------------------------------------------------------------
+Reference<XComponentContext> raise_uno_process(
+ Reference<XComponentContext> const & xContext,
+ ::rtl::Reference<AbortChannel> const & abortChannel )
+{
+ OSL_ASSERT( xContext.is() );
+
+ ::rtl::OUString url(
+ Reference<util::XMacroExpander>(
+ xContext->getValueByName(
+ OUSTR("/singletons/com.sun.star.util.theMacroExpander") ),
+ UNO_QUERY_THROW )->
+ expandMacros( OUSTR("$URE_BIN_DIR/uno") ) );
+
+ ::rtl::OUStringBuffer buf;
+ buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno:pipe,name=") );
+ OUString pipeId( generateRandomPipeId() );
+ buf.append( pipeId );
+ buf.appendAscii(
+ RTL_CONSTASCII_STRINGPARAM(";urp;uno.ComponentContext") );
+ const OUString connectStr( buf.makeStringAndClear() );
+
+ // raise core UNO process to register/run a component,
+ // javavm service uses unorc next to executable to retrieve deployed
+ // jar typelibs
+
+ ::std::vector<OUString> args;
+#if OSL_DEBUG_LEVEL == 0
+ args.push_back( OUSTR("--quiet") );
+#endif
+ args.push_back( OUSTR("--singleaccept") );
+ args.push_back( OUSTR("-u") );
+ args.push_back( connectStr );
+ // don't inherit from unorc:
+ args.push_back( OUSTR("-env:INIFILENAME=") );
+
+ //now add the bootstrap variables which were supplied on the command line
+ ::std::vector<OUString> bootvars = getCmdBootstrapVariables();
+ args.insert(args.end(), bootvars.begin(), bootvars.end());
+
+ oslProcess hProcess = raiseProcess(
+ url, comphelper::containerToSequence(args) );
+ try {
+ return Reference<XComponentContext>(
+ resolveUnoURL( connectStr, xContext, abortChannel.get() ),
+ UNO_QUERY_THROW );
+ }
+ catch (...) {
+ // try to terminate process:
+ if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
+ {
+ OSL_ASSERT( false );
+ }
+ throw;
+ }
+}
+
+//------------------------------------------------------------------------------
+namespace {
+
+void extractComponentData(
css::uno::Reference< css::uno::XComponentContext > const & context,
css::uno::Reference< css::registry::XRegistryKey > const & registry,
ComponentBackendDb::Data * data,
std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
- css::uno::Reference< css::loader::XImplementationLoader > const *
+ css::uno::Reference< css::loader::XImplementationLoader > const &
componentLoader,
- rtl::OUString const * componentUrl)
+ rtl::OUString const & componentUrl)
{
- OSL_ASSERT(context.is() && registry.is() && data != 0);
+ OSL_ASSERT(
+ context.is() && registry.is() && data != 0 && componentLoader.is());
rtl::OUString registryName(registry->getKeyName());
sal_Int32 prefix = registryName.getLength();
if (!registryName.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM("/"))) {
@@ -1211,51 +1302,56 @@ void BackendImpl::extractComponentData(
}
}
if (factories != 0) {
- css::uno::Reference< css::loader::XImplementationLoader > loader;
- if (componentLoader == 0) {
- rtl::OUString activator(
- openRegistryKey(
- keys[i],
- rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("UNO/ACTIVATOR")))->
- getAsciiValue());
- loader.set(
- smgr->createInstanceWithContext(activator, context),
- css::uno::UNO_QUERY);
- if (!loader.is()) {
- throw css::deployment::DeploymentException(
- (rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM(
- "cannot instantiate loader ")) +
- activator),
- static_cast< OWeakObject * >(this), Any());
- }
- } else {
- OSL_ASSERT(componentLoader->is());
- loader = *componentLoader;
- }
factories->push_back(
- loader->activate(
- name, rtl::OUString(),
- (componentUrl == 0
- ? (openRegistryKey(
- keys[i],
- rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("UNO/LOCATION")))->
- getAsciiValue())
- : *componentUrl),
- keys[i]));
+ componentLoader->activate(
+ name, rtl::OUString(), componentUrl, keys[i]));
}
}
}
-void BackendImpl::componentLiveInsertion(
+}
+
+void BackendImpl::ComponentPackageImpl::getComponentInfo(
+ ComponentBackendDb::Data * data,
+ std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
+ Reference<XComponentContext> const & xContext )
+{
+ const Reference<loader::XImplementationLoader> xLoader(
+ xContext->getServiceManager()->createInstanceWithContext(
+ m_loader, xContext ), UNO_QUERY );
+ if (! xLoader.is())
+ {
+ throw css::deployment::DeploymentException(
+ (rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("cannot instantiate loader ")) +
+ m_loader),
+ static_cast< OWeakObject * >(this), Any());
+ }
+
+ // HACK: highly dependent on stoc/source/servicemanager
+ // and stoc/source/implreg implementation which rely on the same
+ // services.rdb format!
+ // .../UNO/LOCATION and .../UNO/ACTIVATOR appear not to be written by
+ // writeRegistryInfo, however, but are knwon, fixed values here, so
+ // can be passed into extractComponentData
+ rtl::OUString url(getURL());
+ const Reference<registry::XSimpleRegistry> xMemReg(
+ xContext->getServiceManager()->createInstanceWithContext(
+ OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
+ UNO_QUERY_THROW );
+ xMemReg->open( OUString() /* in mem */, false, true );
+ xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
+ extractComponentData(
+ xContext, xMemReg->getRootKey(), data, factories, xLoader, url);
+}
+
+void BackendImpl::ComponentPackageImpl::componentLiveInsertion(
ComponentBackendDb::Data const & data,
std::vector< css::uno::Reference< css::uno::XInterface > > const &
factories)
{
css::uno::Reference< css::uno::XComponentContext > rootContext(
- getRootContext());
+ getMyBackend()->getRootContext());
css::uno::Reference< css::container::XSet > set(
rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
@@ -1310,9 +1406,11 @@ void BackendImpl::componentLiveInsertion(
}
}
-void BackendImpl::componentLiveRemoval(ComponentBackendDb::Data const & data) {
+void BackendImpl::ComponentPackageImpl::componentLiveRemoval(
+ ComponentBackendDb::Data const & data)
+{
css::uno::Reference< css::uno::XComponentContext > rootContext(
- getRootContext());
+ getMyBackend()->getRootContext());
css::uno::Reference< css::container::XSet > set(
rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
for (t_stringlist::const_iterator i(data.implementationNames.begin());
@@ -1351,137 +1449,6 @@ void BackendImpl::componentLiveRemoval(ComponentBackendDb::Data const & data) {
}
}
-css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
- const
-{
- css::uno::Reference< css::uno::XComponentContext > rootContext(
- getComponentContext()->getValueByName(
- rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
- css::uno::UNO_QUERY);
- return rootContext.is() ? rootContext : getComponentContext();
-}
-
-//______________________________________________________________________________
-void BackendImpl::releaseObject( OUString const & id )
-{
- const ::osl::MutexGuard guard( getMutex() );
- m_backendObjects.erase( id );
-}
-
-//______________________________________________________________________________
-Reference<XInterface> BackendImpl::getObject( OUString const & id )
-{
- const ::osl::MutexGuard guard( getMutex() );
- const t_string2object::const_iterator iFind( m_backendObjects.find( id ) );
- if (iFind == m_backendObjects.end())
- return Reference<XInterface>();
- else
- return iFind->second;
-}
-
-//______________________________________________________________________________
-Reference<XInterface> BackendImpl::insertObject(
- OUString const & id, Reference<XInterface> const & xObject )
-{
- const ::osl::MutexGuard guard( getMutex() );
- const ::std::pair<t_string2object::iterator, bool> insertion(
- m_backendObjects.insert( t_string2object::value_type(
- id, xObject ) ) );
- return insertion.first->second;
-}
-
-//------------------------------------------------------------------------------
-Reference<XComponentContext> raise_uno_process(
- Reference<XComponentContext> const & xContext,
- ::rtl::Reference<AbortChannel> const & abortChannel )
-{
- OSL_ASSERT( xContext.is() );
-
- ::rtl::OUString url(
- Reference<util::XMacroExpander>(
- xContext->getValueByName(
- OUSTR("/singletons/com.sun.star.util.theMacroExpander") ),
- UNO_QUERY_THROW )->
- expandMacros( OUSTR("$URE_BIN_DIR/uno") ) );
-
- ::rtl::OUStringBuffer buf;
- buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno:pipe,name=") );
- OUString pipeId( generateRandomPipeId() );
- buf.append( pipeId );
- buf.appendAscii(
- RTL_CONSTASCII_STRINGPARAM(";urp;uno.ComponentContext") );
- const OUString connectStr( buf.makeStringAndClear() );
-
- // raise core UNO process to register/run a component,
- // javavm service uses unorc next to executable to retrieve deployed
- // jar typelibs
-
- ::std::vector<OUString> args;
-#if OSL_DEBUG_LEVEL == 0
- args.push_back( OUSTR("--quiet") );
-#endif
- args.push_back( OUSTR("--singleaccept") );
- args.push_back( OUSTR("-u") );
- args.push_back( connectStr );
- // don't inherit from unorc:
- args.push_back( OUSTR("-env:INIFILENAME=") );
-
- //now add the bootstrap variables which were supplied on the command line
- ::std::vector<OUString> bootvars = getCmdBootstrapVariables();
- args.insert(args.end(), bootvars.begin(), bootvars.end());
-
- oslProcess hProcess = raiseProcess(
- url, comphelper::containerToSequence(args) );
- try {
- return Reference<XComponentContext>(
- resolveUnoURL( connectStr, xContext, abortChannel.get() ),
- UNO_QUERY_THROW );
- }
- catch (...) {
- // try to terminate process:
- if ( osl_terminateProcess( hProcess ) != osl_Process_E_None )
- {
- OSL_ASSERT( false );
- }
- throw;
- }
-}
-
-//------------------------------------------------------------------------------
-void BackendImpl::ComponentPackageImpl::getComponentInfo(
- ComponentBackendDb::Data * data,
- std::vector< css::uno::Reference< css::uno::XInterface > > * factories,
- Reference<XComponentContext> const & xContext )
-{
- const Reference<loader::XImplementationLoader> xLoader(
- xContext->getServiceManager()->createInstanceWithContext(
- m_loader, xContext ), UNO_QUERY );
- if (! xLoader.is())
- {
- throw css::deployment::DeploymentException(
- (rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM("cannot instantiate loader ")) +
- m_loader),
- static_cast< OWeakObject * >(this), Any());
- }
-
- // HACK: highly dependent on stoc/source/servicemanager
- // and stoc/source/implreg implementation which rely on the same
- // services.rdb format!
- // .../UNO/LOCATION and .../UNO/ACTIVATOR appear not to be written by
- // writeRegistryInfo, however, but are knwon, fixed values here, so
- // can be passed into extractComponentData
- rtl::OUString url(getURL());
- const Reference<registry::XSimpleRegistry> xMemReg(
- xContext->getServiceManager()->createInstanceWithContext(
- OUSTR("com.sun.star.registry.SimpleRegistry"), xContext ),
- UNO_QUERY_THROW );
- xMemReg->open( OUString() /* in mem */, false, true );
- xLoader->writeRegistryInfo( xMemReg->getRootKey(), OUString(), url );
- getMyBackend()->extractComponentData(
- xContext, xMemReg->getRootKey(), data, factories, &xLoader, &url);
-}
-
// Package
//______________________________________________________________________________
//We could use here BackendImpl::hasActiveEntry. However, this check is just as well.
@@ -1608,7 +1575,7 @@ void BackendImpl::ComponentPackageImpl::processPackage_(
std::vector< css::uno::Reference< css::uno::XInterface > > factories;
getComponentInfo(&data, startup ? 0 : &factories, context);
if (!startup) {
- that->componentLiveInsertion(data, factories);
+ componentLiveInsertion(data, factories);
}
m_registered = REG_REGISTERED;
that->addDataToDb(url, data);
@@ -1622,7 +1589,7 @@ void BackendImpl::ComponentPackageImpl::processPackage_(
context = that->getComponentContext();
}
if (!startup) {
- that->componentLiveRemoval(data);
+ componentLiveRemoval(data);
}
css::uno::Reference< css::registry::XImplementationRegistration >(
context->getServiceManager()->createInstanceWithContext(
@@ -1913,13 +1880,9 @@ void BackendImpl::ComponentsPackageImpl::processPackage_(
BackendImpl * that = getMyBackend();
rtl::OUString url(getURL());
if (doRegisterPackage) {
- ComponentBackendDb::Data data;
- data.javaTypeLibrary = false;
- css::uno::Reference< css::uno::XComponentContext > context;
- if (startup) {
- context = that->getComponentContext();
- } else {
- context.set(that->getObject(url), css::uno::UNO_QUERY);
+ if (!startup) {
+ css::uno::Reference< css::uno::XComponentContext > context(
+ that->getObject(url), css::uno::UNO_QUERY);
if (!context.is()) {
context.set(
that->insertObject(
@@ -1928,39 +1891,35 @@ void BackendImpl::ComponentsPackageImpl::processPackage_(
that->getComponentContext(), abortChannel)),
css::uno::UNO_QUERY_THROW);
}
+ // This relies on the root component context's service manager
+ // supporting the extended XSet semantics:
+ css::uno::Sequence< css::beans::NamedValue > args(2);
+ args[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uri"));
+ args[0].Value <<= expandUnoRcUrl(url);
+ args[1].Name = rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("component-context"));
+ args[1].Value <<= context;
+ css::uno::Reference< css::container::XSet > smgr(
+ that->getRootContext()->getServiceManager(),
+ css::uno::UNO_QUERY_THROW);
+ smgr->insert(css::uno::makeAny(args));
}
-
- std::vector< css::uno::Reference< css::uno::XInterface > > factories;
-
- css::uno::Reference< css::registry::XSimpleRegistry > registry(
- css::uno::Reference< css::lang::XMultiComponentFactory >(
- that->getComponentContext()->getServiceManager(),
- css::uno::UNO_SET_THROW)->createInstanceWithContext(
- rtl::OUString(
- RTL_CONSTASCII_USTRINGPARAM(
- "com.sun.star.registry.SimpleRegistry")),
- that->getComponentContext()),
- css::uno::UNO_QUERY_THROW);
- registry->open(expandUnoRcUrl(url), true, false);
- getMyBackend()->extractComponentData(
- context,
- that->openRegistryKey(
- registry->getRootKey(),
- rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IMPLEMENTATIONS"))),
- &data, startup ? 0 : &factories, 0, 0);
- registry->close();
- if (!startup) {
- that->componentLiveInsertion(data, factories);
- }
- that->addDataToDb(url, data);
that->addToUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
} else { // revoke
that->removeFromUnoRc(RCITEM_COMPONENTS, url, xCmdEnv);
if (!startup) {
- that->componentLiveRemoval(that->readDataFromDb(url));
+ // This relies on the root component context's service manager
+ // supporting the extended XSet semantics:
+ css::uno::Sequence< css::beans::NamedValue > args(1);
+ args[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("uri"));
+ args[0].Value <<= expandUnoRcUrl(url);
+ css::uno::Reference< css::container::XSet > smgr(
+ that->getRootContext()->getServiceManager(),
+ css::uno::UNO_QUERY_THROW);
+ smgr->remove(css::uno::makeAny(args));
}
that->releaseObject(url);
- that->revokeEntryFromDb(url);
+ that->revokeEntryFromDb(url); // in case it got added with old code
}
}