diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2002-06-14 12:26:30 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2002-06-14 12:26:30 +0000 |
commit | 8f0762f89160b4082da93c9e1b0ff99df15dd976 (patch) | |
tree | 7d8eb3ae7cef3fc3b41504e70fb0d1c92e60e631 | |
parent | cec9e449acbec8a6ccc8acd7206a9b4ec441c063 (diff) |
#100075# modifying loaders, using macro expander singleton; service manager review
-rw-r--r-- | stoc/source/inspect/insp.xml | 1 | ||||
-rw-r--r-- | stoc/source/inspect/introspection.cxx | 32 | ||||
-rw-r--r-- | stoc/source/invocation/inv.xml | 1 | ||||
-rw-r--r-- | stoc/source/invocation/invocation.cxx | 26 | ||||
-rw-r--r-- | stoc/source/javaloader/javaloader.cxx | 47 | ||||
-rw-r--r-- | stoc/source/loader/dllcomponentloader.cxx | 89 | ||||
-rw-r--r-- | stoc/source/security/makefile.mk | 6 | ||||
-rw-r--r-- | stoc/source/servicemanager/servicemanager.cxx | 710 | ||||
-rw-r--r-- | stoc/test/testcorefl.cxx | 22 |
9 files changed, 610 insertions, 324 deletions
diff --git a/stoc/source/inspect/insp.xml b/stoc/source/inspect/insp.xml index 0ca7fb5f12f4..4c4f5e699ead 100644 --- a/stoc/source/inspect/insp.xml +++ b/stoc/source/inspect/insp.xml @@ -35,6 +35,7 @@ <type> com.sun.star.uno.XAggregation </type> <type> com.sun.star.uno.XWeak </type> <type> com.sun.star.uno.TypeClass </type> + <type> com.sun.star.uno.DeploymentException </type> <type> com.sun.star.container.XEnumerationAccess </type> <type> com.sun.star.container.XNameContainer </type> <type> com.sun.star.container.XIndexContainer </type> diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index deddadcb4fac..4350ac2236b0 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -2,9 +2,9 @@ * * $RCSfile: introspection.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: ab $ $Date: 2002-04-10 15:28:45 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -92,6 +92,7 @@ #include <cppuhelper/implbase3.hxx> #include <cppuhelper/typeprovider.hxx> +#include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -1757,9 +1758,30 @@ ImplIntrospection::ImplIntrospection( const Reference<XMultiServiceFactory> & rX #endif // Spezielle Klassen holen - Reference< XInterface > xServiceIface = m_xSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")) ); - if( xServiceIface.is() ) - mxCoreReflection = Reference< XIdlReflection >::query( xServiceIface ); +// Reference< XInterface > xServiceIface = m_xSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")) ); +// if( xServiceIface.is() ) +// mxCoreReflection = Reference< XIdlReflection >::query( xServiceIface ); + Reference< XPropertySet > xProps( rXSMgr, UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + if (xProps.is()) + { + Reference< XComponentContext > xContext; + xProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext; + OSL_ASSERT( xContext.is() ); + if (xContext.is()) + { + xContext->getValueByName( + OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection") ) ) >>= mxCoreReflection; + OSL_ENSURE( mxCoreReflection.is(), "### CoreReflection singleton not accessable!?" ); + } + } + if (! mxCoreReflection.is()) + { + throw DeploymentException( + OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ), + Reference< XInterface >() ); + } mxElementAccessClass = mxCoreReflection->forName( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.container.XElementAccess")) ); mxNameContainerClass = mxCoreReflection->forName( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.container.XNameContainer")) ); diff --git a/stoc/source/invocation/inv.xml b/stoc/source/invocation/inv.xml index 01b5045b4335..1267d1063d36 100644 --- a/stoc/source/invocation/inv.xml +++ b/stoc/source/invocation/inv.xml @@ -53,6 +53,7 @@ XNameContainer and XEnumerationContainer <type> com.sun.star.lang.XMultiComponentFactory </type> <type> com.sun.star.lang.XSingleComponentFactory </type> <type> com.sun.star.registry.XRegistryKey </type> + <type> com.sun.star.uno.DeploymentException </type> <type> com.sun.star.uno.XAggregation </type> <type> com.sun.star.uno.XWeak </type> <type> com.sun.star.uno.XComponentContext </type> diff --git a/stoc/source/invocation/invocation.cxx b/stoc/source/invocation/invocation.cxx index 463c7731ce22..0e5903c1f082 100644 --- a/stoc/source/invocation/invocation.cxx +++ b/stoc/source/invocation/invocation.cxx @@ -2,9 +2,9 @@ * * $RCSfile: invocation.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: hr $ $Date: 2001-09-11 13:48:48 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -78,6 +78,7 @@ #include <cppuhelper/typeprovider.hxx> #include <cppuhelper/implbase2.hxx> +#include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/script/FailReason.hpp> #include <com/sun/star/script/XTypeConverter.hpp> #include <com/sun/star/script/XInvocation.hpp> @@ -1162,11 +1163,22 @@ InvocationService::InvocationService( const Reference<XComponentContext> & xCtx OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.Introspection")), xCtx), UNO_QUERY); - xCoreReflection = Reference<XIdlReflection>( - mxSMgr->createInstanceWithContext( - OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")), - xCtx), - UNO_QUERY); + mxCtx->getValueByName( + OUString( + RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection")) ) + >>= xCoreReflection; + OSL_ENSURE( xCoreReflection.is(), "### CoreReflection singleton not accessable!?" ); + if (! xCoreReflection.is()) + { + throw DeploymentException( + OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection singleton not accessable") ), + Reference< XInterface >() ); + } +// xCoreReflection = Reference<XIdlReflection>( +// mxSMgr->createInstanceWithContext( +// OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.CoreReflection")), +// xCtx), +// UNO_QUERY); } InvocationService::~InvocationService() diff --git a/stoc/source/javaloader/javaloader.cxx b/stoc/source/javaloader/javaloader.cxx index 7293a2fb783c..8f48804c8667 100644 --- a/stoc/source/javaloader/javaloader.cxx +++ b/stoc/source/javaloader/javaloader.cxx @@ -2,9 +2,9 @@ * * $RCSfile: javaloader.cxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: jbu $ $Date: 2002-04-26 16:40:15 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,7 +66,6 @@ #include <rtl/ustring> #include <rtl/process.h> -#include <rtl/bootstrap.hxx> #include <rtl/ustrbuf.hxx> #include <uno/environment.h> @@ -149,7 +148,6 @@ namespace stoc_javaloader { Reference<XMultiComponentFactory> _xSMgr; Reference<XComponentContext> _xCtx; Reference<XImplementationLoader> _javaLoader; - ::rtl::Bootstrap _bootstrap; public: JavaComponentLoader(const Reference<XComponentContext> & xCtx) throw(RuntimeException); @@ -166,34 +164,9 @@ namespace stoc_javaloader { virtual sal_Bool SAL_CALL writeRegistryInfo(const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl) throw(CannotRegisterImplementationException, RuntimeException); }; - /* Using bootstrap variables here is only a very temporary solution, the right thing will - be to have a macroexpander singleton the component context, however we couldn't - introduce new types in a product patch. - */ - static OUString getIniName() - { - OUString exe; - osl_getExecutableFile( &(exe.pData) ); - - sal_Int32 nIndex = exe.lastIndexOf( '/' ); - OUString ret; - if( exe.getLength() && nIndex != -1 ) - { - OUStringBuffer buf( exe.getLength() + 10 ); - buf.append( exe.getStr() , nIndex +1 ).appendAscii( SAL_CONFIGFILE("uno") ); - ret = buf.makeStringAndClear(); - } -#ifdef DEBUG - OString o = OUStringToOString( ret , RTL_TEXTENCODING_ASCII_US ); - printf( "Used ininame %s\n" , o.getStr() ); -#endif - return ret; - } - JavaComponentLoader::JavaComponentLoader(const Reference<XComponentContext> & xCtx) throw(RuntimeException) : _xSMgr(xCtx->getServiceManager()) , _xCtx( xCtx ) - , _bootstrap( getIniName() ) { sal_Int32 size = 0; uno_Environment ** ppJava_environments = NULL; @@ -348,13 +321,7 @@ namespace stoc_javaloader { sal_Bool SAL_CALL JavaComponentLoader::writeRegistryInfo(const Reference<XRegistryKey> & xKey, const OUString & blabla, const OUString & rLibName) throw(CannotRegisterImplementationException, RuntimeException) { - OUString libPath( rLibName ); - rtl_bootstrap_expandMacros_from_handle( *(void **)&_bootstrap, &(libPath.pData) ); -#ifdef DEBUG - OString o = OUStringToOString( libPath, RTL_TEXTENCODING_ASCII_US ); - fprintf( stderr, "C++-JavaLoader::writeRegistryInfo using path %s\n" , o.getStr() ); -#endif - return _javaLoader->writeRegistryInfo(xKey, blabla, libPath); + return _javaLoader->writeRegistryInfo(xKey, blabla, rLibName); } @@ -364,13 +331,7 @@ namespace stoc_javaloader { const Reference<XRegistryKey> & xKey) throw(CannotActivateFactoryException, RuntimeException) { - OUString libPath( rLibName ); - rtl_bootstrap_expandMacros_from_handle( *(void **)&_bootstrap, &(libPath.pData) ); -#ifdef DEBUG - OString o = OUStringToOString( libPath, RTL_TEXTENCODING_ASCII_US ); - fprintf( stderr, "C++-JavaLoader::activate using path %s\n" , o.getStr() ); -#endif - return _javaLoader->activate(rImplName, blabla, libPath, xKey); + return _javaLoader->activate(rImplName, blabla, rLibName, xKey); } static Mutex & getInitMutex() diff --git a/stoc/source/loader/dllcomponentloader.cxx b/stoc/source/loader/dllcomponentloader.cxx index f07bd1419200..63405a0c0a7d 100644 --- a/stoc/source/loader/dllcomponentloader.cxx +++ b/stoc/source/loader/dllcomponentloader.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dllcomponentloader.cxx,v $ * - * $Revision: 1.11 $ + * $Revision: 1.12 $ * - * last change: $Author: jbu $ $Date: 2001-06-22 16:20:59 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:29 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,6 +59,9 @@ * ************************************************************************/ +#ifdef _DEBUG +#include <stdio.h> +#endif #include <stdlib.h> #include <osl/file.h> #include <vector> @@ -80,6 +83,12 @@ #ifndef _RTL_STRBUF_HXX_ #include <rtl/strbuf.hxx> #endif +#ifndef _RTL_URI_HXX_ +#include <rtl/uri.hxx> +#endif +#ifdef _DEBUG +#include <rtl/ustrbuf.hxx> +#endif #ifndef _UNO_ENVIRONMENT_H_ #include <uno/environment.h> @@ -107,13 +116,23 @@ #include <cppuhelper/implementationentry.hxx> #endif +#include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/loader/XImplementationLoader.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XInitialization.hpp> #include <com/sun/star/registry/XRegistryKey.hpp> +#include <com/sun/star/util/XMacroExpander.hpp> + +#define SERVICENAME "com.sun.star.loader.SharedLibrary" +#define IMPLNAME "com.sun.star.comp.stoc.DLLComponentLoader" + +#define EXPAND_PROTOCOL "vnd.sun.star.expand" +#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) + +using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::loader; using namespace com::sun::star::lang; @@ -122,9 +141,6 @@ using namespace cppu; using namespace rtl; using namespace osl; -#define SERVICENAME "com.sun.star.loader.SharedLibrary" -#define IMPLNAME "com.sun.star.comp.stoc.DLLComponentLoader" - namespace stoc_loader { static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; @@ -186,14 +202,20 @@ public: virtual sal_Bool SAL_CALL writeRegistryInfo( const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl ) throw(CannotRegisterImplementationException, RuntimeException); private: + Reference< util::XMacroExpander > m_xMacroExpander; + OUString expand_url( OUString const & url ) + SAL_THROW( (RuntimeException) ); + + Reference< XComponentContext > m_xContext; Reference<XMultiServiceFactory> m_xSMgr; }; //************************************************************************* DllComponentLoader::DllComponentLoader( const Reference<XComponentContext> & xCtx ) + : m_xContext( xCtx ) { g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); - m_xSMgr = Reference< XMultiServiceFactory > ( xCtx->getServiceManager(), UNO_QUERY ); + m_xSMgr.set( m_xContext->getServiceManager(), UNO_QUERY ); } //************************************************************************* @@ -253,6 +275,55 @@ void DllComponentLoader::initialize( const ::com::sun::star::uno::Sequence< ::co // m_xSMgr = rServiceManager; } +//================================================================================================== +OUString DllComponentLoader::expand_url( OUString const & url ) + SAL_THROW( (RuntimeException) ) +{ + if (0 == url.compareToAscii( RTL_CONSTASCII_STRINGPARAM(EXPAND_PROTOCOL ":") )) + { + if (! m_xMacroExpander.is()) + { + Reference< util::XMacroExpander > xExpander; + m_xContext->getValueByName( + OUSTR("/singletons/com.sun.star.util.theMacroExpander") ) >>= xExpander; + if (! xExpander.is()) + { + throw DeploymentException( + OUSTR("no macro expander singleton available!"), Reference< XInterface >() ); + } + MutexGuard guard( Mutex::getGlobalMutex() ); + if (! m_xMacroExpander.is()) + { + m_xMacroExpander = xExpander; + } + } + + // cut protocol + OUString macro( url.copy( sizeof (EXPAND_PROTOCOL ":") -1 ) ); + // decode uric class chars + macro = Uri::decode( macro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ); + // expand macro string + OUString ret( m_xMacroExpander->expandMacros( macro ) ); +#ifdef _DEBUG + OUStringBuffer buf( 128 ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("DllComponentLoader::expand_url(): ") ); + buf.append( url ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" => ") ); + buf.append( macro ); + buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" => ") ); + buf.append( ret ); + OString str( OUStringToOString( buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) ); +// OSL_TRACE( str.getStr() ); + // use printf here, because OSL_TRACE forwards to printf directly, so %... gets lost + fprintf( stderr, "%s\n", str.getStr() ); +#endif + return ret; + } + else + { + return url; + } +} //************************************************************************* Reference<XInterface> SAL_CALL DllComponentLoader::activate( @@ -261,7 +332,8 @@ Reference<XInterface> SAL_CALL DllComponentLoader::activate( throw(CannotActivateFactoryException, RuntimeException) { - return loadSharedLibComponentFactory( rLibName, OUString(), rImplName, m_xSMgr, xKey ); + return loadSharedLibComponentFactory( + expand_url( rLibName ), OUString(), rImplName, m_xSMgr, xKey ); } @@ -271,7 +343,8 @@ sal_Bool SAL_CALL DllComponentLoader::writeRegistryInfo( throw(CannotRegisterImplementationException, RuntimeException) { - writeSharedLibComponentInfo( rLibName, OUString(), m_xSMgr, xKey ); + writeSharedLibComponentInfo( + expand_url( rLibName ), OUString(), m_xSMgr, xKey ); return sal_True; } diff --git a/stoc/source/security/makefile.mk b/stoc/source/security/makefile.mk index 42f7ff3102ec..77c2774fe233 100644 --- a/stoc/source/security/makefile.mk +++ b/stoc/source/security/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.2 $ +# $Revision: 1.3 $ # -# last change: $Author: dbo $ $Date: 2002-03-04 17:43:21 $ +# last change: $Author: dbo $ $Date: 2002-06-14 13:26:30 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -101,7 +101,7 @@ DEF1NAME=$(SHL1TARGET) # msvc++: no inlining for debugging .IF "$(COM)" == "MSC" -CFLAGS += /Ob0 +CFLAGS += -Ob0 .ENDIF # some diagnose diff --git a/stoc/source/servicemanager/servicemanager.cxx b/stoc/source/servicemanager/servicemanager.cxx index db5e35bed149..d63195945c16 100644 --- a/stoc/source/servicemanager/servicemanager.cxx +++ b/stoc/source/servicemanager/servicemanager.cxx @@ -2,9 +2,9 @@ * * $RCSfile: servicemanager.cxx,v $ * - * $Revision: 1.15 $ + * $Revision: 1.16 $ * - * last change: $Author: dbo $ $Date: 2002-04-29 11:59:19 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -105,8 +105,10 @@ #endif #include <cppuhelper/component_context.hxx> #include <cppuhelper/bootstrap.hxx> +#include <cppuhelper/compbase8.hxx> +#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiComponentFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -124,7 +126,6 @@ #include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/uno/XUnloadingPreference.hpp> - using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::beans; @@ -141,6 +142,54 @@ namespace stoc_smgr static rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; +static Sequence< sal_Int8 > smgr_getImplementationId() +{ + static OImplementationId * s_pId = 0; + if (! s_pId) + { + MutexGuard aGuard( Mutex::getGlobalMutex() ); + if (! s_pId) + { + static OImplementationId s_aId; + s_pId = &s_aId; + } + } + return s_pId->getImplementationId(); +} + +static Sequence< OUString > smgr_wrapper_getSupportedServiceNames() +{ + static Sequence < OUString > *pNames = 0; + if( ! pNames ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( !pNames ) + { + static Sequence< OUString > seqNames(1); + seqNames.getArray()[0] = OUString( + RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.MultiServiceFactory") ); + pNames = &seqNames; + } + } + return *pNames; +} + +static OUString smgr_wrapper_getImplementationName() +{ + static OUString *pImplName = 0; + if( ! pImplName ) + { + MutexGuard guard( Mutex::getGlobalMutex() ); + if( ! pImplName ) + { + static OUString implName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.stoc.OServiceManagerWrapper" ) ); + pImplName = &implName; + } + } + return *pImplName; +} + static Sequence< OUString > smgr_getSupportedServiceNames() { static Sequence < OUString > *pNames = 0; @@ -255,7 +304,8 @@ static Sequence< OUString > retrieveAsciiValueList( } } catch( InvalidRegistryException & ) - {} + { + } } return seq; } @@ -316,13 +366,9 @@ public: ServiceEnumeration_Impl( const Sequence< Reference<XInterface > > & rFactories ) : aFactories( rFactories ) , nIt( 0 ) - { - g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); - } + { g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); } virtual ~ServiceEnumeration_Impl() - { - g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); - }; + { g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); } // XEnumeration sal_Bool SAL_CALL hasMoreElements() @@ -489,19 +535,20 @@ void OServiceManager_Listener::disposing(const EventObject & rEvt ) *****************************************************************************/ struct OServiceManagerMutex { - Mutex m_mutex; + Mutex m_mutex; }; extern "C" void SAL_CALL smgrUnloadingListener(void* id); +typedef WeakComponentImplHelper8< + lang::XMultiServiceFactory, lang::XMultiComponentFactory, lang::XServiceInfo, + lang::XInitialization, lang::XUnoTunnel, + container::XSet, container::XContentEnumerationAccess, + beans::XPropertySet > t_OServiceManager_impl; + class OServiceManager - : public XMultiServiceFactory - , public XMultiComponentFactory - , public XSet - , public XContentEnumerationAccess - , public XServiceInfo - , public OServiceManagerMutex - , public OComponentHelper + : public OServiceManagerMutex + , public t_OServiceManager_impl { public: friend void SAL_CALL smgrUnloadingListener(void* id); @@ -509,11 +556,13 @@ public: OServiceManager( Reference< XComponentContext > const & xContext ); virtual ~OServiceManager(); - virtual Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL acquire() throw() - { OComponentHelper::acquire(); } - virtual void SAL_CALL release() throw() - { OComponentHelper::release(); } + // XUnoTunnel + sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id ) + throw (RuntimeException); + + // XInitialization + void SAL_CALL initialize( Sequence< Any > const & args ) + throw (Exception); // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException); @@ -554,10 +603,6 @@ public: virtual void SAL_CALL insert( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL remove( const Any & Element ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - // XTypeProvider - virtual Sequence< Type > SAL_CALL getTypes() throw(::com::sun::star::uno::RuntimeException); - virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(::com::sun::star::uno::RuntimeException); - // XContentEnumerationAccess //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException); @@ -565,6 +610,22 @@ public: // XComponent virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); + // XPropertySet + Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() + throw(::com::sun::star::uno::RuntimeException); + void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + Any SAL_CALL getPropertyValue(const OUString& PropertyName) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + protected: sal_Bool haveFactoryWithThisImplementation(const OUString& aImplName); @@ -572,6 +633,7 @@ protected: virtual Sequence< Reference< XInterface > > queryServiceFactories(const OUString& aServiceName); Reference< XComponentContext > m_xContext; + sal_Int32 m_nUnloadingListenerId; // Does clean up when the unloading mechanism has been set off. It is called from @@ -592,11 +654,240 @@ private: Reference<XEventListener > xFactoryListener; }; +//################################################################################################## +//################################################################################################## +//################################################################################################## + +class OServiceManagerWrapper : public OServiceManagerMutex, public t_OServiceManager_impl +{ + Reference< XComponentContext > m_xContext; + OServiceManager * m_root; + inline OServiceManager * getRoot() SAL_THROW( (RuntimeException) ) + { + if (! m_root) + { + throw DisposedException( + OUString( RTL_CONSTASCII_USTRINGPARAM("call on already disposed smgr!") ), + Reference< XInterface >() ); + } + return m_root; + } + +protected: + virtual void SAL_CALL disposing(); + +public: + OServiceManagerWrapper( + Reference< XComponentContext > const & xContext ) + SAL_THROW( (RuntimeException) ); + virtual ~OServiceManagerWrapper() SAL_THROW( () ); + + // XUnoTunnel + sal_Int64 SAL_CALL getSomething( Sequence< sal_Int8 > const & id ) throw (RuntimeException) + { return getRoot()->getSomething( id ); } + + // XInitialization + void SAL_CALL initialize( Sequence< Any > const & args ) throw (Exception) + { getRoot()->initialize( args ); } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw (RuntimeException) + { return getRoot()->getImplementationName(); } + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (RuntimeException) + { return getRoot()->supportsService( ServiceName ); } + virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException) + { return getRoot()->getSupportedServiceNames(); } + + // XMultiComponentFactory + virtual Reference< XInterface > SAL_CALL createInstanceWithContext( + OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext ) + throw (Exception, RuntimeException) + { return getRoot()->createInstanceWithContext( rServiceSpecifier, xContext ); } + virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( + OUString const & rServiceSpecifier, + Sequence< Any > const & rArguments, + Reference< XComponentContext > const & xContext ) + throw (Exception, RuntimeException) + { return getRoot()->createInstanceWithArgumentsAndContext( rServiceSpecifier, rArguments, xContext ); } +// virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() +// throw (RuntimeException); + + // XMultiServiceFactory + virtual Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException) + { return getRoot()->getAvailableServiceNames(); } + virtual Reference<XInterface > SAL_CALL createInstance(const OUString & name) throw (Exception) + { return getRoot()->createInstanceWithContext( name, m_xContext ); } + virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const OUString & name, const Sequence<Any >& Arguments) throw (Exception) + { return getRoot()->createInstanceWithArgumentsAndContext( name, Arguments, m_xContext ); } + + // XElementAccess + virtual Type SAL_CALL getElementType() throw (RuntimeException) + { return getRoot()->getElementType(); } + virtual sal_Bool SAL_CALL hasElements() throw (RuntimeException) + { return getRoot()->hasElements(); } + + // XEnumerationAccess + virtual Reference<XEnumeration > SAL_CALL createEnumeration() throw (RuntimeException) + { return getRoot()->createEnumeration(); } + + // XSet + virtual sal_Bool SAL_CALL has( const Any & Element ) throw (RuntimeException) + { return getRoot()->has( Element ); } + virtual void SAL_CALL insert( const Any & Element ) throw (lang::IllegalArgumentException, container::ElementExistException, RuntimeException) + { getRoot()->insert( Element ); } + virtual void SAL_CALL remove( const Any & Element ) throw (lang::IllegalArgumentException, container::NoSuchElementException, RuntimeException) + { getRoot()->remove( Element ); } + + // XContentEnumerationAccess + //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); + virtual Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw (RuntimeException) + { return getRoot()->createContentEnumeration( aServiceName ); } + + // XPropertySet + Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() throw (RuntimeException) + { return getRoot()->getPropertySetInfo(); } + + void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue) + throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException); + Any SAL_CALL getPropertyValue(const OUString& PropertyName) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException); + + void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) + { getRoot()->addPropertyChangeListener( PropertyName, aListener ); } + void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) + { getRoot()->removePropertyChangeListener( PropertyName, aListener ); } + void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) + { getRoot()->addVetoableChangeListener( PropertyName, aListener ); } + void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) + { getRoot()->removeVetoableChangeListener( PropertyName, aListener ); } +}; +//__________________________________________________________________________________________________ +void SAL_CALL OServiceManagerWrapper::setPropertyValue( + const OUString& PropertyName, const Any& aValue ) + throw (beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, RuntimeException) +{ + if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) + { + Reference< XComponentContext > xContext; + if (aValue >>= xContext) + { + MutexGuard aGuard( m_mutex ); + m_xContext = xContext; + } + else + { + throw IllegalArgumentException( + OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ), + (OWeakObject *)this, 1 ); + } + } + else + { + getRoot()->setPropertyValue( PropertyName, aValue ); + } +} +//__________________________________________________________________________________________________ +Any SAL_CALL OServiceManagerWrapper::getPropertyValue( + const OUString& PropertyName ) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, RuntimeException) +{ + if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) + { + MutexGuard aGuard( m_mutex ); + if( m_xContext.is() ) + return makeAny( m_xContext ); + else + return Any(); + } + else + { + return getRoot()->getPropertyValue( PropertyName ); + } +} +//__________________________________________________________________________________________________ +void OServiceManagerWrapper::disposing() +{ + m_xContext.clear(); + + if (m_root) + { +// no m_root->dispose(), because every context disposes its service manager... + m_root->release(); + m_root = 0; + } +} +//__________________________________________________________________________________________________ +OServiceManagerWrapper::~OServiceManagerWrapper() SAL_THROW( () ) +{ + if (m_root) + { + m_root->release(); + m_root = 0; + } + + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} +//__________________________________________________________________________________________________ +OServiceManagerWrapper::OServiceManagerWrapper( + Reference< XComponentContext > const & xContext ) + SAL_THROW( (RuntimeException) ) + : t_OServiceManager_impl( m_mutex ) + , m_xContext( xContext ) + , m_root( 0 ) +{ + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + + Reference< XUnoTunnel > xTunnel( m_xContext->getServiceManager(), UNO_QUERY ); + OSL_ASSERT( xTunnel.is() ); + if (xTunnel.is()) + { + m_root = (OServiceManager *)xTunnel->getSomething( smgr_getImplementationId() ); + OSL_ASSERT( m_root ); + if (m_root) + { + m_root->acquire(); + } + } + + if (! m_root) + { + throw RuntimeException( + OUString( RTL_CONSTASCII_USTRINGPARAM("can only wrap OServiceManager instances!") ), + Reference< XInterface >() ); + } +} + +static Reference<XInterface > SAL_CALL OServiceManagerWrapper_CreateInstance( + const Reference< XComponentContext > & xContext ) + throw (Exception) +{ + return (OWeakObject *)new OServiceManagerWrapper( xContext ); +} + +//################################################################################################## +//################################################################################################## +//################################################################################################## + +// XUnoTunnel +sal_Int64 OServiceManager::getSomething( Sequence< sal_Int8 > const & id ) + throw (RuntimeException) +{ + if (id == smgr_getImplementationId()) + return (sal_Int64)this; + else + return 0; +} + /** * Create a ServiceManager */ OServiceManager::OServiceManager( Reference< XComponentContext > const & xContext ) - : OComponentHelper( m_mutex ) + : t_OServiceManager_impl( m_mutex ) , m_xContext( xContext ) { g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); @@ -710,7 +1001,7 @@ void OServiceManager::onUnloadingNotify() m_SetLoadedFactories.clear(); } -// OComponentHelper +// XComponent void OServiceManager::dispose() throw(::com::sun::star::uno::RuntimeException) { @@ -744,7 +1035,7 @@ void OServiceManager::dispose() } // set the service manager to disposed - OComponentHelper::dispose(); + t_OServiceManager_impl::dispose(); // dispose HashSet_Ref aImplMap; @@ -768,42 +1059,90 @@ void OServiceManager::dispose() m_nUnloadingListenerId=0; } -// XTypeProvider -Sequence< Type > OServiceManager::getTypes() +// XPropertySet +Reference<XPropertySetInfo > OServiceManager::getPropertySetInfo() throw(::com::sun::star::uno::RuntimeException) { - static OTypeCollection * s_pTypes = 0; - if (! s_pTypes) + return Reference<XPropertySetInfo >(); +} + +void OServiceManager::setPropertyValue( + const OUString& PropertyName, const Any& aValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! s_pTypes) + Reference< XComponentContext > xContext; + if (aValue >>= xContext) { - static OTypeCollection s_aTypes( - ::getCppuType( (const Reference< XMultiComponentFactory > *)0 ), - ::getCppuType( (const Reference< XMultiServiceFactory > *)0 ), - ::getCppuType( (const Reference< XSet > *)0 ), - ::getCppuType( (const Reference< XContentEnumerationAccess > *)0 ), - ::getCppuType( (const Reference< XServiceInfo > *)0 ), - OComponentHelper::getTypes() ); - s_pTypes = &s_aTypes; + MutexGuard aGuard( m_mutex ); + m_xContext = xContext; + } + else + { + throw IllegalArgumentException( + OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ), + (OWeakObject *)this, 1 ); } } - return s_pTypes->getTypes(); + else + { + throw UnknownPropertyException( + OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property ") ) + PropertyName, + (OWeakObject *)this ); + } } -Sequence< sal_Int8 > OServiceManager::getImplementationId() - throw (::com::sun::star::uno::RuntimeException) + +Any OServiceManager::getPropertyValue(const OUString& PropertyName) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) { - static OImplementationId * s_pId = 0; - if (! s_pId) + if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! s_pId) - { - static OImplementationId s_aId; - s_pId = &s_aId; - } + MutexGuard aGuard( m_mutex ); + if( m_xContext.is() ) + return makeAny( m_xContext ); + else + return Any(); } - return s_pId->getImplementationId(); + else + { + UnknownPropertyException except; + except.Message = OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager : unknown property " ) ); + except.Message += PropertyName; + throw except; + } +} + +void OServiceManager::addPropertyChangeListener( + const OUString& PropertyName, + const Reference<XPropertyChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + throw UnknownPropertyException(); +} + +void OServiceManager::removePropertyChangeListener( + const OUString& PropertyName, + const Reference<XPropertyChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + throw UnknownPropertyException(); +} + +void OServiceManager::addVetoableChangeListener( + const OUString& PropertyName, + const Reference<XVetoableChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + throw UnknownPropertyException(); +} + +void OServiceManager::removeVetoableChangeListener( + const OUString& PropertyName, + const Reference<XVetoableChangeListener >& aListener) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) +{ + throw UnknownPropertyException(); } // OServiceManager @@ -815,23 +1154,6 @@ Reference<XEventListener > OServiceManager::getFactoryListener() return xFactoryListener; } -// XInterface -Any OServiceManager::queryInterface( const Type & rType ) - throw(::com::sun::star::uno::RuntimeException) -{ - Any aRet( ::cppu::queryInterface( - rType, - static_cast< XMultiComponentFactory * >( this ), - static_cast< XMultiServiceFactory * >( this ), - static_cast< XServiceInfo * >( this ), - static_cast< XContentEnumerationAccess *>( this ), - static_cast< XSet *>( this ), - static_cast< XEnumerationAccess *>( this ), - static_cast< XElementAccess *>( this ) ) ); - - return (aRet.hasValue() ? aRet : OComponentHelper::queryInterface( rType )); -} - // XMultiServiceFactory, XContentEnumeration Sequence< OUString > OServiceManager::getAvailableServiceNames( HashSet_OWString & aNameSet ) { @@ -860,9 +1182,24 @@ Sequence< OUString > OServiceManager::getAvailableServiceNames( HashSet_OWString // XMultiComponentFactory Reference< XInterface > OServiceManager::createInstanceWithContext( - OUString const & rServiceSpecifier, Reference< XComponentContext > const & xContext ) + OUString const & rServiceSpecifier, + Reference< XComponentContext > const & xContext ) throw (Exception, RuntimeException) { +#ifdef _DEBUG + Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + if (xProps.is()) + { + Reference< XComponentContext > xDefContext; + xProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext; + OSL_ENSURE( + xContext == xDefContext, + "### default context of service manager singleton differs from context holding it!" ); + } +#endif + Sequence< Reference< XInterface > > factories( queryServiceFactories( rServiceSpecifier ) ); Reference< XInterface > const * p = factories.getConstArray(); for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos ) @@ -909,6 +1246,20 @@ Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext( Reference< XComponentContext > const & xContext ) throw (Exception, RuntimeException) { +#ifdef _DEBUG + Reference< beans::XPropertySet > xProps( xContext->getServiceManager(), UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + if (xProps.is()) + { + Reference< XComponentContext > xDefContext; + xProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xDefContext; + OSL_ENSURE( + xContext == xDefContext, + "### default context of service manager singleton differs from context holding it!" ); + } +#endif + Sequence< Reference< XInterface > > factories( queryServiceFactories( rServiceSpecifier ) ); Reference< XInterface > const * p = factories.getConstArray(); for ( sal_Int32 nPos = 0; nPos < factories.getLength(); ++nPos ) @@ -920,7 +1271,6 @@ Reference< XInterface > OServiceManager::createInstanceWithArgumentsAndContext( { Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY ); if (xFac.is()) - { return xFac->createInstanceWithArgumentsAndContext( rArguments, xContext ); } @@ -964,7 +1314,8 @@ Reference<XInterface > OServiceManager::createInstance( const OUString& rServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) { - return createInstanceWithContext( rServiceSpecifier, m_xContext ); + return createInstanceWithContext( + rServiceSpecifier, m_xContext ); } // XMultibleServiceFactory @@ -973,7 +1324,15 @@ Reference<XInterface > OServiceManager::createInstanceWithArguments( const Sequence<Any >& rArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) { - return createInstanceWithArgumentsAndContext( rServiceSpecifier, rArguments, m_xContext ); + return createInstanceWithArgumentsAndContext( + rServiceSpecifier, rArguments, m_xContext ); +} + +// XInitialization +void OServiceManager::initialize( Sequence< Any > const & ) + throw (Exception) +{ + OSL_ENSURE( 0, "not impl!" ); } // XServiceInfo @@ -1215,20 +1574,11 @@ void OServiceManager::remove( const Any & Element ) /***************************************************************************** class ORegistryServiceManager *****************************************************************************/ -class ORegistryServiceManager - : public XInitialization - , public XPropertySet - , public OServiceManager +class ORegistryServiceManager : public OServiceManager { public: ORegistryServiceManager( Reference< XComponentContext > const & xContext ); - ~ORegistryServiceManager(); - - Any SAL_CALL queryInterface( const Type & rType ) throw(::com::sun::star::uno::RuntimeException); - void SAL_CALL acquire() throw() - { OServiceManager::acquire(); } - void SAL_CALL release() throw() - { OServiceManager::release(); } + virtual ~ORegistryServiceManager(); // XInitialization void SAL_CALL initialize(const Sequence< Any >& Arguments) @@ -1243,10 +1593,6 @@ public: // XMultiServiceFactory Sequence< OUString > SAL_CALL getAvailableServiceNames() throw(::com::sun::star::uno::RuntimeException); - // XTypeProvider - Sequence< Type > SAL_CALL getTypes() throw(::com::sun::star::uno::RuntimeException); - Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(::com::sun::star::uno::RuntimeException); - // XContentEnumerationAccess //Sequence< OUString > getAvailableServiceNames() throw( (Exception) ); Reference<XEnumeration > SAL_CALL createContentEnumeration(const OUString& aServiceName) throw(::com::sun::star::uno::RuntimeException); @@ -1254,21 +1600,9 @@ public: // XComponent void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); - // XPropertySet - Reference<XPropertySetInfo > SAL_CALL getPropertySetInfo() - throw(::com::sun::star::uno::RuntimeException); - void SAL_CALL setPropertyValue(const OUString& PropertyName, const Any& aValue) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + // OServiceManager Any SAL_CALL getPropertyValue(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL addPropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL removePropertyChangeListener(const OUString& PropertyName, const Reference<XPropertyChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); - void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const Reference<XVetoableChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); protected: //OServiceManager @@ -1299,7 +1633,6 @@ ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > , m_init( false ) #endif { - g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); } /** @@ -1307,10 +1640,9 @@ ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > */ ORegistryServiceManager::~ORegistryServiceManager() { - g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); } -// OComponentHelper +// XComponent void ORegistryServiceManager::dispose() throw(::com::sun::star::uno::RuntimeException) { @@ -1322,41 +1654,6 @@ void ORegistryServiceManager::dispose() m_xRootKey = Reference<XRegistryKey >(); } -// XTypeProvider -Sequence< Type > ORegistryServiceManager::getTypes() - throw(::com::sun::star::uno::RuntimeException) -{ - static OTypeCollection * pTypes = 0; - if (! pTypes) - { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! pTypes) - { - static OTypeCollection aTypes( - ::getCppuType( (const Reference< XPropertySet > *)0 ), - ::getCppuType( (const Reference< XInitialization > *)0 ), - OServiceManager::getTypes() ); - pTypes = &aTypes; - } - } - return pTypes->getTypes(); -} -Sequence< sal_Int8 > ORegistryServiceManager::getImplementationId() - throw (::com::sun::star::uno::RuntimeException) -{ - static OImplementationId * pId = 0; - if (! pId) - { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! pId) - { - static OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); -} - /** * Return the root key of the registry. The Default registry service is ordered * if no registry is set. @@ -1477,39 +1774,16 @@ void ORegistryServiceManager::fillAllNamesFromRegistry( HashSet_OWString & rSet } } -// XInterface -Any ORegistryServiceManager::queryInterface( const Type & rType ) - throw(::com::sun::star::uno::RuntimeException) -{ - Any aRet( cppu::queryInterface( - rType, - static_cast< XInitialization * >( this ), - static_cast< XPropertySet * >( this ) ) ); - - return (aRet.hasValue() ? aRet : OServiceManager::queryInterface( rType )); -} - // XInitialization void ORegistryServiceManager::initialize(const Sequence< Any >& Arguments) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) { - // read out default context to be used for components - // => bootstrap problem: first service manager has to be instanced without context, - // default context for createInstance() (!= createInstanceWithContext()) calls - // gets this context - MutexGuard aGuard( m_mutex ); if (Arguments.getLength() > 0) { m_xRootKey.clear(); Arguments[ 0 ] >>= m_xRegistry; } - - if (!m_xContext.is() && (Arguments.getLength() > 1)) - { - Arguments[ 1 ] >>= m_xContext; - } - #ifdef _DEBUG // to find all bootstrapping processes to be fixed... OSL_ENSURE( !m_init, "### second init of service manager instance!" ); @@ -1581,98 +1855,19 @@ Reference<XEnumeration > ORegistryServiceManager::createContentEnumeration(const return OServiceManager::createContentEnumeration( aServiceName ); } -// XPropertySet -Reference<XPropertySetInfo > ORegistryServiceManager::getPropertySetInfo() - throw(::com::sun::star::uno::RuntimeException) -{ - return Reference<XPropertySetInfo >(); -} - -void ORegistryServiceManager::setPropertyValue( - const OUString& PropertyName, const Any& aValue ) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) -{ - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) - { - Reference< XComponentContext > xContext; - if (aValue >>= xContext) - { - MutexGuard aGuard( m_mutex ); - m_xContext = xContext; - } - else - { - throw IllegalArgumentException( - OUString( RTL_CONSTASCII_USTRINGPARAM("no XComponentContext given!") ), - (OWeakObject *)this, 1 ); - } - } - else - { - throw UnknownPropertyException( - OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property ") ) + PropertyName, - (OWeakObject *)this ); - } -} - +// OServiceManager Any ORegistryServiceManager::getPropertyValue(const OUString& PropertyName) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) { - Any ret; - if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Registry") )) { MutexGuard aGuard( m_mutex ); if( m_xRegistry.is() ) - { - ret = makeAny( m_xRegistry ); - } - } - else if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DefaultContext") )) - { - MutexGuard aGuard( m_mutex ); - if( m_xContext.is() ) - { - ret = makeAny( m_xContext ); - } - } - else - { - UnknownPropertyException except; - except.Message = OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager : unknown property " ) ); - except.Message += PropertyName; - throw except; + return makeAny( m_xRegistry ); + else + return Any(); } - - return ret; -} - -void ORegistryServiceManager::addPropertyChangeListener(const OUString& PropertyName, - const Reference<XPropertyChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) -{ - throw UnknownPropertyException(); -} - -void ORegistryServiceManager::removePropertyChangeListener(const OUString& PropertyName, - const Reference<XPropertyChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) -{ - throw UnknownPropertyException(); -} - -void ORegistryServiceManager::addVetoableChangeListener(const OUString& PropertyName, - const Reference<XVetoableChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) -{ - throw UnknownPropertyException(); -} - -void ORegistryServiceManager::removeVetoableChangeListener(const OUString& PropertyName, - const Reference<XVetoableChangeListener >& aListener) - throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) -{ - throw UnknownPropertyException(); + return OServiceManager::getPropertyValue( PropertyName ); } @@ -1682,7 +1877,10 @@ void ORegistryServiceManager::removeVetoableChangeListener(const OUString& Prope static Reference<XInterface > SAL_CALL OServiceManager_CreateInstance( const Reference< XComponentContext > & xContext ) { - return Reference<XInterface >( SAL_STATIC_CAST( XInterface *, SAL_STATIC_CAST( OWeakObject *, new OServiceManager( xContext ) ) ) ); + return Reference<XInterface >( + SAL_STATIC_CAST( + XInterface *, SAL_STATIC_CAST( + OWeakObject *, new OServiceManager( xContext ) ) ) ); } /** @@ -1692,7 +1890,10 @@ static Reference<XInterface > SAL_CALL ORegistryServiceManager_CreateInstance( const Reference< XComponentContext > & xContext ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) { - return Reference<XInterface >( SAL_STATIC_CAST( XInterface *, SAL_STATIC_CAST( OWeakObject *, new ORegistryServiceManager( xContext ) ) ) ); + return Reference<XInterface >( + SAL_STATIC_CAST( + XInterface *, SAL_STATIC_CAST( + OWeakObject *, new ORegistryServiceManager( xContext ) ) ) ); } /* This is the listener function used by the service manager in order @@ -1731,6 +1932,11 @@ static struct ImplementationEntry g_entries[] = regsmgr_getSupportedServiceNames, createSingleComponentFactory, &g_moduleCount.modCnt , 0 }, + { + OServiceManagerWrapper_CreateInstance, smgr_wrapper_getImplementationName, + smgr_wrapper_getSupportedServiceNames, createSingleComponentFactory, + &g_moduleCount.modCnt , 0 + }, { 0, 0, 0, 0, 0, 0 } }; diff --git a/stoc/test/testcorefl.cxx b/stoc/test/testcorefl.cxx index 78aa9f5c8f2c..e7dd5ef7a1da 100644 --- a/stoc/test/testcorefl.cxx +++ b/stoc/test/testcorefl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: testcorefl.cxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: hr $ $Date: 2001-11-14 13:14:53 $ + * last change: $Author: dbo $ $Date: 2002-06-14 13:26:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -96,6 +96,7 @@ using namespace ModuleA; using namespace ModuleB; using namespace ModuleC; using namespace ModuleA::ModuleB; +using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; @@ -414,12 +415,20 @@ int __cdecl main( int argc, char * argv[] ) { Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory( OUString( RTL_CONSTASCII_USTRINGPARAM("stoctest.rdb") ) ) ); + Reference< XComponentContext > xContext; + Reference< beans::XPropertySet > xProps( xMgr, UNO_QUERY ); + OSL_ASSERT( xProps.is() ); + xProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xContext; + OSL_ASSERT( xContext.is() ); + xMgr.clear(); sal_Bool bSucc = sal_False; try { Reference< XImplementationRegistration > xImplReg( - xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.ImplementationRegistration") ) ), UNO_QUERY ); + xContext->getServiceManager()->createInstanceWithContext( + OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.registry.ImplementationRegistration") ), xContext ), UNO_QUERY ); OSL_ENSURE( xImplReg.is(), "### no impl reg!" ); OUString aLibName( OUString::createFromAscii(REG_PREFIX) ); @@ -430,8 +439,9 @@ int __cdecl main( int argc, char * argv[] ) xImplReg->registerImplementation( OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), aLibName, Reference< XSimpleRegistry >() ); - Reference< XIdlReflection > xRefl( xMgr->createInstance( OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ), UNO_QUERY ); - OSL_ENSURE( xRefl.is(), "### no corereflection!" ); + Reference< XIdlReflection > xRefl; + xContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.reflection.theCoreReflection")) ) >>= xRefl; + OSL_ENSURE( xRefl.is(), "### CoreReflection singleton not accessable!?" ); bSucc = test_corefl( xRefl ); } @@ -444,7 +454,7 @@ int __cdecl main( int argc, char * argv[] ) OSL_TRACE( "\n" ); } - Reference< XComponent >( xMgr, UNO_QUERY )->dispose(); + Reference< XComponent >( xContext, UNO_QUERY )->dispose(); printf( "testcorefl %s !\n", (bSucc ? "succeeded" : "failed") ); return (bSucc ? 0 : -1); |