summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cppuhelper/inc/cppuhelper/component_context.hxx104
-rw-r--r--cppuhelper/inc/cppuhelper/factory.hxx24
-rw-r--r--cppuhelper/inc/cppuhelper/shlib.hxx9
-rw-r--r--cppuhelper/prj/d.lst2
-rw-r--r--cppuhelper/source/component_context.cxx361
-rw-r--r--cppuhelper/source/factory.cxx270
-rw-r--r--cppuhelper/source/makefile.mk23
-rw-r--r--cppuhelper/source/servicefactory.cxx410
-rw-r--r--cppuhelper/source/shlib.cxx12
-rw-r--r--cppuhelper/source/tdmgr.cxx695
10 files changed, 1592 insertions, 318 deletions
diff --git a/cppuhelper/inc/cppuhelper/component_context.hxx b/cppuhelper/inc/cppuhelper/component_context.hxx
new file mode 100644
index 000000000000..c2cf465d2476
--- /dev/null
+++ b/cppuhelper/inc/cppuhelper/component_context.hxx
@@ -0,0 +1,104 @@
+/*************************************************************************
+ *
+ * $RCSfile: component_context.hxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:54:52 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+#ifndef _CPPUHELPER_COMPONENT_CONTEXT_HXX_
+#define _CPPUHELPER_COMPONENT_CONTEXT_HXX_
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
+
+
+namespace cppu /** */ //for docpp
+{
+
+struct ContextEntry_Init
+{
+ /** late init denotes a object that will be raised when first get() is calling for it
+
+ The context implementation expects either a com.sun.star.lang.XSingleComponentFactory
+ object as value (to instanciate the object) or a string as value for raising
+ a service via the used service manager
+ */
+ bool bLateInitService;
+ /** name of context value
+ */
+ ::rtl::OUString name;
+ /** context value
+ */
+ ::com::sun::star::uno::Any value;
+};
+
+/** Creates a component context with the given entries.
+
+ @param pEntries array of entries
+ @param nEntries number of entries
+ @param xDelegate delegation to further context, if value was not found
+ @return new context object
+*/
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
+SAL_CALL createComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xDelegate =
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >() )
+ SAL_THROW( () );
+
+}
+
+#endif
diff --git a/cppuhelper/inc/cppuhelper/factory.hxx b/cppuhelper/inc/cppuhelper/factory.hxx
index 5ebbd2a0f12a..23db6e6345ef 100644
--- a/cppuhelper/inc/cppuhelper/factory.hxx
+++ b/cppuhelper/inc/cppuhelper/factory.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: factory.hxx,v $
*
- * $Revision: 1.3 $
+ * $Revision: 1.4 $
*
- * last change: $Author: dbo $ $Date: 2001-03-12 16:52:03 $
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:54:52 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -69,6 +69,8 @@
#include <uno/dispatcher.h>
#endif
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
@@ -152,6 +154,24 @@ typedef uno_Interface* (SAL_CALL * CreateComponentFactoryFunc)(
namespace cppu
{
+typedef ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
+ SAL_CALL * ComponentFactoryFunc)(
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext )
+ SAL_THROW( (::com::sun::star::uno::Exception) );
+
+/** Creates a single component factory supporting the XSingleComponentFactory interface.
+
+ @param fptr function pointer for instanciating the object
+ @param rImplementationName implementation name of service
+ @param rServiceNames supported services
+*/
+::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >
+SAL_CALL createSingleComponentFactory(
+ ComponentFactoryFunc fptr,
+ ::rtl::OUString const & rImplementationName,
+ ::com::sun::star::uno::Sequence< ::rtl::OUString > const & rServiceNames )
+ SAL_THROW( () );
+
/**
* The type of the instanciate function used as argument of the create*Fcatory functions.
* @see createSingleFactory
diff --git a/cppuhelper/inc/cppuhelper/shlib.hxx b/cppuhelper/inc/cppuhelper/shlib.hxx
index e5725e6141e3..dad79d13671f 100644
--- a/cppuhelper/inc/cppuhelper/shlib.hxx
+++ b/cppuhelper/inc/cppuhelper/shlib.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: shlib.hxx,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: dbo $ $Date: 2001-03-09 12:15:26 $
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:54:52 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -61,7 +61,6 @@
#ifndef _CPPUHELPER_SHLIB_HXX_
#define _CPPUHELPER_SHLIB_HXX_
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/registry/XRegistryKey.hpp>
#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
@@ -88,10 +87,12 @@ namespace cppu
service manager to be provided to the component
@param xKey
registry key to be provided to the component
+ @return
+ factory instance
@throws ::com::sun::star::loader::CannotActivateFactoryException
if activation failed
*/
-::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
+::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
SAL_CALL loadSharedLibComponentFactory(
::rtl::OUString const & rLibName, ::rtl::OUString const & rPath,
::rtl::OUString const & rImplName,
diff --git a/cppuhelper/prj/d.lst b/cppuhelper/prj/d.lst
index eb85ef8009f5..e607a24b2d42 100644
--- a/cppuhelper/prj/d.lst
+++ b/cppuhelper/prj/d.lst
@@ -29,10 +29,12 @@ mkdir: %_DEST%\inc%_EXT%\cppuhelper
..\inc\cppuhelper\compbase12.hxx %_DEST%\inc%_EXT%\cppuhelper\compbase12.hxx
..\inc\cppuhelper\shlib.hxx %_DEST%\inc%_EXT%\cppuhelper\shlib.hxx
+..\inc\cppuhelper\tdmgr.hxx %_DEST%\inc%_EXT%\cppuhelper\tdmgr.hxx
..\inc\cppuhelper\extract.hxx %_DEST%\inc%_EXT%\cppuhelper\extract.hxx
..\inc\cppuhelper\exc_hlp.hxx %_DEST%\inc%_EXT%\cppuhelper\exc_hlp.hxx
..\inc\cppuhelper\typeprovider.hxx %_DEST%\inc%_EXT%\cppuhelper\typeprovider.hxx
..\inc\cppuhelper\factory.hxx %_DEST%\inc%_EXT%\cppuhelper\factory.hxx
+..\inc\cppuhelper\component_context.hxx %_DEST%\inc%_EXT%\cppuhelper\component_context.hxx
..\inc\cppuhelper\interfacecontainer.hxx %_DEST%\inc%_EXT%\cppuhelper\interfacecontainer.hxx
..\inc\cppuhelper\interfacecontainer.h %_DEST%\inc%_EXT%\cppuhelper\interfacecontainer.h
..\inc\cppuhelper\component.hxx %_DEST%\inc%_EXT%\cppuhelper\component.hxx
diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx
new file mode 100644
index 000000000000..b9d9b1804e6b
--- /dev/null
+++ b/cppuhelper/source/component_context.cxx
@@ -0,0 +1,361 @@
+/*************************************************************************
+ *
+ * $RCSfile: component_context.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef _OSL_DIAGNOSE_H_
+#include <osl/diagnose.h>
+#endif
+#ifndef _OSL_MUTEX_HXX_
+#include <osl/mutex.hxx>
+#endif
+
+#ifndef _CPPUHELPER_COMPBASE1_HXX
+#include <cppuhelper/compbase1.hxx>
+#endif
+#ifndef _CPPUHELPER_COMPONENT_CONTEXT_HXX
+#include <cppuhelper/component_context.hxx>
+#endif
+
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/registry/XSimpleRegistry.hpp>
+
+#include <hash_map>
+
+using namespace ::osl;
+using namespace ::rtl;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star;
+
+
+namespace cppu
+{
+
+//==================================================================================================
+struct MutexHolder
+{
+ Mutex m_mutex;
+};
+//==================================================================================================
+class ComponentContext
+ : public MutexHolder
+ , public WeakComponentImplHelper1< XComponentContext >
+{
+ Reference< XComponentContext > m_xDelegate;
+
+ struct ContextEntry
+ {
+ bool bLateInitService;
+ Any value;
+
+ inline ContextEntry( bool bLateInitService_, Any const & value_ )
+ : bLateInitService( bLateInitService_ )
+ , value( value_ )
+ {}
+ };
+ typedef ::std::hash_map< OUString, ContextEntry *, OUStringHash > t_map;
+ t_map m_map;
+
+ Reference< lang::XMultiComponentFactory > m_xSMgr;
+
+protected:
+ virtual void SAL_CALL disposing();
+
+public:
+ ComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< XComponentContext > const & xDelegate )
+ SAL_THROW( () );
+ ComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< registry::XSimpleRegistry > const & xRegistry )
+ SAL_THROW( () );
+ virtual ~ComponentContext();
+
+ // XComponentContext
+ virtual Any SAL_CALL getValueByName( OUString const & rName )
+ throw (RuntimeException);
+ virtual Reference< lang::XMultiComponentFactory > SAL_CALL getServiceManager()
+ throw (RuntimeException);
+};
+//__________________________________________________________________________________________________
+Any ComponentContext::getValueByName( OUString const & rName )
+ throw (RuntimeException)
+{
+ /** map is anytime untouched, if an uninit value will be inited, synch is done on mutex.
+ */
+
+ t_map::const_iterator const iFind( m_map.find( rName ) );
+ if (iFind != m_map.end())
+ {
+ ContextEntry * pEntry = iFind->second;
+
+ if (pEntry->bLateInitService)
+ {
+ try
+ {
+ Reference< XInterface > xInstance;
+
+ Reference< lang::XSingleComponentFactory > xFac;
+ if (pEntry->value >>= xFac) // try via factory
+ {
+ xInstance = xFac->createInstanceWithContext( this );
+ }
+ else // optionally service name
+ {
+ OUString aServiceName;
+ if ((pEntry->value >>= aServiceName) && aServiceName.getLength())
+ {
+ if (m_xSMgr.is())
+ {
+ xInstance = m_xSMgr->createInstanceWithContext( aServiceName, this );
+ }
+#ifdef _DEBUG
+ else
+ {
+ OSL_TRACE( "### no service manager given for instanciating singletons!" );
+ }
+#endif
+ }
+ }
+
+ if (xInstance.is())
+ {
+ ClearableMutexGuard aGuard( m_mutex );
+ if (! pEntry->bLateInitService) // inited in the meantime?
+ {
+ aGuard.clear();
+ // service has entered the context in the meantime
+ // => try to dispose this one
+ Reference< lang::XComponent > xComp( xInstance, UNO_QUERY );
+ if (xComp.is())
+ {
+ xComp->dispose();
+ }
+ }
+ else
+ {
+ pEntry->value = makeAny( xInstance );
+ pEntry->bLateInitService = false;
+ }
+
+ return pEntry->value;
+ }
+ else
+ {
+ OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_ASCII_US ) );
+ OSL_TRACE( "### cannot raise singleton: $s\n", aStr.getStr() );
+ }
+ }
+ catch (Exception & rExc)
+ {
+#ifdef _DEBUG
+ OString aStr( OUStringToOString( rName, RTL_TEXTENCODING_ASCII_US ) );
+ OString aStr2( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
+ OSL_TRACE( "### exception occured raising singleton %s: %s\n", aStr.getStr(), aStr2.getStr() );
+#endif
+ }
+ }
+ else
+ {
+ return pEntry->value;
+ }
+
+ return Any(); // error occured
+ }
+
+ if (m_xDelegate.is())
+ {
+ return m_xDelegate->getValueByName( rName );
+ }
+
+ return Any();
+}
+//__________________________________________________________________________________________________
+Reference< lang::XMultiComponentFactory > ComponentContext::getServiceManager()
+ throw (RuntimeException)
+{
+ return m_xSMgr;
+}
+//__________________________________________________________________________________________________
+ComponentContext::~ComponentContext()
+{
+}
+//__________________________________________________________________________________________________
+void ComponentContext::disposing()
+{
+ MutexGuard aGuard( m_mutex );
+ for ( t_map::const_iterator iPos( m_map.begin() ); iPos != m_map.end(); ++iPos )
+ {
+ ContextEntry * pEntry = iPos->second;
+ Reference< lang::XComponent > xComp;
+ pEntry->value >>= xComp;
+ delete pEntry;
+
+ if (xComp.is())
+ {
+ xComp->dispose();
+ }
+ }
+ m_map.clear();
+
+ // dispose service manager
+ Reference< lang::XComponent > xComp( m_xSMgr, UNO_QUERY );
+ if (xComp.is())
+ {
+ xComp->dispose();
+ }
+}
+//__________________________________________________________________________________________________
+ComponentContext::ComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< XComponentContext > const & xDelegate )
+ SAL_THROW( () )
+ : WeakComponentImplHelper1< XComponentContext >( m_mutex )
+ , m_xDelegate( xDelegate )
+{
+ while (nEntries--)
+ {
+ ContextEntry_Init const & rEntry = pEntries[ nEntries ];
+
+ if (rEntry.name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.lang.ServiceManager") ))
+ {
+ if (rEntry.value >>= m_xSMgr)
+ continue;
+ }
+ m_map[ rEntry.name ] = new ContextEntry( rEntry.bLateInitService, rEntry.value );
+ }
+ if (!m_xSMgr.is() && m_xDelegate.is())
+ {
+ m_xSMgr = m_xDelegate->getServiceManager();
+ }
+}
+//__________________________________________________________________________________________________
+ComponentContext::ComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< registry::XSimpleRegistry > const & xRegistry )
+ SAL_THROW( () )
+ : WeakComponentImplHelper1< XComponentContext >( m_mutex )
+{
+ // inited values
+ while (nEntries--)
+ {
+ ContextEntry_Init const & rEntry = pEntries[ nEntries ];
+
+ if (rEntry.name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.lang.ServiceManager") ))
+ {
+ if (rEntry.value >>= m_xSMgr)
+ continue;
+ }
+ m_map[ rEntry.name ] = new ContextEntry( rEntry.bLateInitService, rEntry.value );
+ }
+
+ // late init singleton services
+ if (xRegistry.is())
+ {
+ Reference< registry::XRegistryKey > xKey( xRegistry->getRootKey() );
+ if (xKey.is())
+ {
+ xKey = xKey->openKey( OUString( RTL_CONSTASCII_USTRINGPARAM("/SINGLETONS") ) );
+ if (xKey.is())
+ {
+ Sequence< Reference< registry::XRegistryKey > > keys( xKey->openKeys() );
+ Reference< registry::XRegistryKey > const * pKeys = keys.getConstArray();
+ for ( sal_Int32 nPos = keys.getLength(); nPos--; )
+ {
+ try
+ {
+ Reference< registry::XRegistryKey > const & xKey = pKeys[ nPos ];
+ m_map[ xKey->getKeyName().copy( 11 ) ] =
+ new ContextEntry( true, makeAny( xKey->getAsciiValue() ) );
+ }
+ catch (Exception & rExc)
+ {
+#ifdef _DEBUG
+ OString aStr( OUStringToOString( xKey->getKeyName().copy( 11 ), RTL_TEXTENCODING_ASCII_US ) );
+ OString aStr2( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
+ OSL_TRACE( "### failed reading singleton [%s] service name from registry: %s", aStr.getStr(), aStr2.getStr() );
+#endif
+ }
+ }
+ }
+ }
+ }
+}
+
+//==================================================================================================
+Reference< XComponentContext > SAL_CALL createInitialComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< registry::XSimpleRegistry > const & xRegistry )
+ SAL_THROW( () )
+{
+ return new ComponentContext( pEntries, nEntries, xRegistry );
+}
+
+//##################################################################################################
+Reference< XComponentContext > SAL_CALL createComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< XComponentContext > const & xDelegate )
+ SAL_THROW( () )
+{
+ return new ComponentContext( pEntries, nEntries, xDelegate );
+}
+
+}
diff --git a/cppuhelper/source/factory.cxx b/cppuhelper/source/factory.cxx
index e363d344ba43..891eb50254a5 100644
--- a/cppuhelper/source/factory.cxx
+++ b/cppuhelper/source/factory.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: factory.cxx,v $
*
- * $Revision: 1.5 $
+ * $Revision: 1.6 $
*
- * last change: $Author: jl $ $Date: 2001-03-12 13:39:32 $
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -85,6 +85,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/loader/XImplementationLoader.hpp>
#include <com/sun/star/lang/XComponent.hpp>
@@ -92,6 +93,7 @@
using namespace osl;
using namespace rtl;
+using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::loader;
@@ -106,17 +108,20 @@ namespace cppu
class OSingleFactoryHelper
: public XServiceInfo
, public XSingleServiceFactory
+ , public lang::XSingleComponentFactory
{
public:
OSingleFactoryHelper(
const Reference<XMultiServiceFactory > & rServiceManager,
const OUString & rImplementationName_,
ComponentInstantiation pCreateFunction_,
+ ComponentFactoryFunc fptr,
const Sequence< OUString > * pServiceNames_ )
SAL_THROW( () )
: xSMgr( rServiceManager )
, aImplementationName( rImplementationName_ )
, pCreateFunction( pCreateFunction_ )
+ , m_fptr( fptr )
{
if( pServiceNames_ )
aServiceNames = *pServiceNames_;
@@ -130,6 +135,7 @@ public:
: xSMgr( rServiceManager )
, aImplementationName( rImplementationName_ )
, pCreateFunction( NULL )
+ , m_fptr( 0 )
{}
// XInterface
@@ -141,6 +147,14 @@ public:
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments)
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ // XSingleComponentFactory
+ virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException);
+ virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
+ Sequence< Any > const & rArguments,
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException);
// XServiceInfo
OUString SAL_CALL getImplementationName()
@@ -156,11 +170,13 @@ protected:
* in the createInstance and createInstanceWithArguments methods.
* @return the newly created instance. Do not return a previous (one instance) instance.
*/
- virtual Reference<XInterface > createInstanceEveryTime()
+ virtual Reference<XInterface > createInstanceEveryTime(
+ Reference< XComponentContext > const & xContext )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
Reference<XMultiServiceFactory > xSMgr;
ComponentInstantiation pCreateFunction;
+ ComponentFactoryFunc m_fptr;
Sequence< OUString > aServiceNames;
OUString aImplementationName;
};
@@ -170,43 +186,84 @@ Any OSingleFactoryHelper::queryInterface( const Type & rType )
throw(::com::sun::star::uno::RuntimeException)
{
return ::cppu::queryInterface(
- rType, static_cast< XSingleServiceFactory * >( this ), static_cast< XServiceInfo * >( this ) );
+ rType,
+ static_cast< XSingleComponentFactory * >( this ),
+ static_cast< XSingleServiceFactory * >( this ),
+ static_cast< XServiceInfo * >( this ) );
}
// OSingleFactoryHelper
-Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime()
+Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime(
+ Reference< XComponentContext > const & xContext )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
{
- if( pCreateFunction )
- return pCreateFunction( xSMgr );
+ if (m_fptr)
+ {
+ return (*m_fptr)( xContext );
+ }
+ else if( pCreateFunction )
+ {
+#ifdef DEBUG
+ if (xContext.is())
+ {
+ OSL_TRACE( "### ignoring context calling OSingleFactoryHelper::createInstanceEveryTime()!\n" );
+ }
+#endif
+ return (*pCreateFunction)( xSMgr );
+ }
else
- return Reference<XInterface >();
+ {
+ return Reference< XInterface >();
+ }
}
// XSingleServiceFactory
Reference<XInterface > OSingleFactoryHelper::createInstance()
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
{
- return createInstanceEveryTime();
+ return createInstanceWithContext( Reference< XComponentContext >() );
}
// XSingleServiceFactory
-Reference<XInterface > OSingleFactoryHelper::createInstanceWithArguments
-(
- const Sequence<Any>& Arguments
-)
+Reference<XInterface > OSingleFactoryHelper::createInstanceWithArguments(
+ const Sequence<Any>& Arguments )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
{
- Reference<XInterface > xRet = createInstanceEveryTime();
+ return createInstanceWithArgumentsAndContext(
+ Arguments, Reference< XComponentContext >() );
+}
+
+// XSingleComponentFactory
+//__________________________________________________________________________________________________
+Reference< XInterface > OSingleFactoryHelper::createInstanceWithContext(
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException)
+{
+ return createInstanceEveryTime( xContext );
+}
+//__________________________________________________________________________________________________
+Reference< XInterface > OSingleFactoryHelper::createInstanceWithArgumentsAndContext(
+ Sequence< Any > const & rArguments,
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException)
+{
+ Reference< XInterface > xRet( createInstanceWithContext( xContext ) );
- if( Arguments.getLength() )
+ if (rArguments.getLength())
{
- Reference<XInitialization > xInit( xRet, UNO_QUERY );
- if( xInit.is() )
- xInit->initialize( Arguments );
+ Reference< lang::XInitialization > xInit( xRet, UNO_QUERY );
+ if (xInit.is())
+ {
+ xInit->initialize( rArguments );
+ }
else
- throw IllegalArgumentException();
+ {
+ throw lang::IllegalArgumentException(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("cannot pass arguments to component => no XInitialization implemented!") ),
+ Reference< XInterface >(), 0 );
+ }
}
+
return xRet;
}
@@ -218,7 +275,8 @@ OUString OSingleFactoryHelper::getImplementationName()
}
// XServiceInfo
-sal_Bool OSingleFactoryHelper::supportsService(const OUString& ServiceName)
+sal_Bool OSingleFactoryHelper::supportsService(
+ const OUString& ServiceName )
throw(::com::sun::star::uno::RuntimeException)
{
Sequence< OUString > seqServices = getSupportedServiceNames();
@@ -256,11 +314,12 @@ public:
const Reference<XMultiServiceFactory > & rServiceManager,
const OUString & rImplementationName_,
ComponentInstantiation pCreateFunction_,
+ ComponentFactoryFunc fptr,
const Sequence< OUString > * pServiceNames_,
sal_Bool bOneInstance_ = sal_False )
SAL_THROW( () )
: OComponentHelper( aMutex )
- , OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, pServiceNames_ )
+ , OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ )
, bOneInstance( bOneInstance_ )
{
}
@@ -319,21 +378,16 @@ Any OFactoryComponentHelper::queryAggregation( const Type & rType )
Sequence< Type > OFactoryComponentHelper::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< XSingleServiceFactory > *)0 ),
- ::getCppuType( (const Reference< XServiceInfo > *)0 ),
- OComponentHelper::getTypes() );
- pTypes = &aTypes;
- }
- }
- return pTypes->getTypes();
+ Type ar[ 3 ];
+ ar[ 0 ] = ::getCppuType( (const Reference< XSingleServiceFactory > *)0 );
+ ar[ 1 ] = ::getCppuType( (const Reference< XServiceInfo > *)0 );
+
+ if (m_fptr)
+ ar[ 2 ] = ::getCppuType( (const Reference< XSingleComponentFactory > *)0 );
+
+ return Sequence< Type >( ar, m_fptr ? 3 : 2 );
}
+
Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId()
throw (::com::sun::star::uno::RuntimeException)
{
@@ -410,58 +464,125 @@ public:
const Reference<XRegistryKey > & xImplementationKey_,
sal_Bool bOneInstance_ = sal_False )
SAL_THROW( () )
- : OFactoryComponentHelper( rServiceManager, rImplementationName_, 0, 0, bOneInstance_ )
+ : OFactoryComponentHelper( rServiceManager, rImplementationName_, 0, 0, 0, bOneInstance_ )
, xImplementationKey( xImplementationKey_ )
{}
// OSingleFactoryHelper
- Reference<XInterface > createInstanceEveryTime()
+ Reference<XInterface > createInstanceEveryTime(
+ Reference< XComponentContext > const & xContext )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
// XSingleServiceFactory
Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments)
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
+ // XSingleComponentFactory
+ Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
+ Sequence< Any > const & rArguments,
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException);
// XServiceInfo
Sequence< OUString > SAL_CALL getSupportedServiceNames(void)
throw(::com::sun::star::uno::RuntimeException);
private:
- Reference< XSingleServiceFactory > createModuleFactory()
+ Reference< XInterface > createModuleFactory()
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
/** The registry key of the implementation section */
Reference<XRegistryKey > xImplementationKey;
/** The factory created with the loader. */
- Reference<XSingleServiceFactory > xModuleFactory;
+ Reference<XSingleComponentFactory > xModuleFactory;
+ Reference<XSingleServiceFactory > xModuleFactoryDepr;
};
-Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime()
+Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime(
+ Reference< XComponentContext > const & xContext )
+ throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
+{
+ if( !xModuleFactory.is() || !xModuleFactoryDepr.is() )
+ {
+ MutexGuard aGuard( aMutex );
+ if( !xModuleFactory.is() || !xModuleFactoryDepr.is() )
+ {
+ Reference< XInterface > x( createModuleFactory() );
+ xModuleFactory.set( x, UNO_QUERY );
+ xModuleFactoryDepr.set( x, UNO_QUERY );
+ }
+ }
+ if( xModuleFactory.is() )
+ {
+ return xModuleFactory->createInstanceWithContext( xContext );
+ }
+ else if( xModuleFactoryDepr.is() )
+ {
+ return xModuleFactoryDepr->createInstance();
+ }
+
+ return Reference<XInterface >();
+}
+
+Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArguments(
+ const Sequence<Any>& Arguments )
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
{
- if( pCreateFunction )
- // the create function is set, do not use the implementation loader.
- return OFactoryComponentHelper::createInstanceEveryTime();
+ if( !xModuleFactoryDepr.is() )
+ {
+ MutexGuard aGuard( aMutex );
+ if( !xModuleFactory.is() || !xModuleFactoryDepr.is() )
+ {
+ Reference< XInterface > x( createModuleFactory() );
+ xModuleFactoryDepr.set( x, UNO_QUERY );
+ }
+ }
+ if( xModuleFactoryDepr.is() )
+ {
+ return xModuleFactoryDepr->createInstanceWithArguments( Arguments );
+ }
+
+ return Reference<XInterface >();
+}
- if( !xModuleFactory.is() )
+Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndContext(
+ Sequence< Any > const & rArguments,
+ Reference< XComponentContext > const & xContext )
+ throw (Exception, RuntimeException)
+{
+ if( !xModuleFactory.is() || !xModuleFactoryDepr.is() )
{
MutexGuard aGuard( aMutex );
- if( !xModuleFactory.is() ) // is xModuleFactory really not set (MultiThreaded!)
+ if( !xModuleFactory.is() || !xModuleFactoryDepr.is() )
{
- xModuleFactory = createModuleFactory();
+ Reference< XInterface > x( createModuleFactory() );
+ xModuleFactory.set( x, UNO_QUERY );
+ xModuleFactoryDepr.set( x, UNO_QUERY );
}
}
if( xModuleFactory.is() )
- return xModuleFactory->createInstance();
+ {
+ return xModuleFactory->createInstanceWithArgumentsAndContext( rArguments, xContext );
+ }
+ else if( xModuleFactoryDepr.is() )
+ {
+#ifdef DEBUG
+ if (xContext.is())
+ {
+ OSL_TRACE( "### ignoring context calling ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!\n" );
+ }
+#endif
+ return xModuleFactoryDepr->createInstanceWithArguments( rArguments );
+ }
return Reference<XInterface >();
}
+
// OSingleFactoryHelper
-Reference< XSingleServiceFactory > ORegistryFactoryHelper::createModuleFactory()
+Reference< XInterface > ORegistryFactoryHelper::createModuleFactory()
throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
{
- Reference<XSingleServiceFactory > xFactory;
+ Reference< XInterface > xFactory;
try
{
MutexGuard aGuard( aMutex );
@@ -522,7 +643,7 @@ Reference< XSingleServiceFactory > ORegistryFactoryHelper::createModuleFactory()
// is specified, implemented and used.
try
{
- xMF = xLoader->activate( aImplementationName, aActivatorUrl, aLocation, xImplementationKey );
+ xFactory = xLoader->activate( aImplementationName, aActivatorUrl, aLocation, xImplementationKey );
}
catch( CannotActivateFactoryException& e)
{
@@ -530,7 +651,6 @@ Reference< XSingleServiceFactory > ORegistryFactoryHelper::createModuleFactory()
OSL_ENSURE( !msg.getLength(), msg.getStr() );
}
}
- xFactory = Reference<XSingleServiceFactory >( xMF, UNO_QUERY );
}
}
catch (InvalidRegistryException &)
@@ -540,24 +660,6 @@ Reference< XSingleServiceFactory > ORegistryFactoryHelper::createModuleFactory()
return xFactory;
}
-Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArguments(const Sequence<Any>& Arguments)
- throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
-{
- if( !xModuleFactory.is() )
- {
- MutexGuard aGuard( aMutex );
- if( !xModuleFactory.is() ) // MultiThreaded!
- {
- xModuleFactory = createModuleFactory();
- }
- }
-
- if( xModuleFactory.is() )
- return xModuleFactory->createInstanceWithArguments( Arguments );
-
- return Reference<XInterface >();
-}
-
// XServiceInfo
Sequence< OUString > ORegistryFactoryHelper::getSupportedServiceNames(void)
throw(::com::sun::star::uno::RuntimeException)
@@ -684,8 +786,8 @@ Reference<XSingleServiceFactory > SAL_CALL createSingleFactory(
const Sequence< OUString > & rServiceNames )
SAL_THROW( () )
{
- return new OFactoryComponentHelper( rServiceManager, rImplementationName,
- pCreateFunction, &rServiceNames, sal_False );
+ return new OFactoryComponentHelper(
+ rServiceManager, rImplementationName, pCreateFunction, 0, &rServiceNames, sal_False );
}
// global function
@@ -694,7 +796,8 @@ Reference<XSingleServiceFactory > SAL_CALL createFactoryProxy(
const Reference<XSingleServiceFactory > & rFactory )
SAL_THROW( () )
{
- return new OFactoryProxyHelper( rServiceManager, rFactory );
+ return new OFactoryProxyHelper(
+ rServiceManager, rFactory );
}
// global function
@@ -705,8 +808,8 @@ Reference<XSingleServiceFactory > SAL_CALL createOneInstanceFactory(
const Sequence< OUString > & rServiceNames )
SAL_THROW( () )
{
- return new OFactoryComponentHelper( rServiceManager, rImplementationName,
- pCreateFunction, &rServiceNames, sal_True );
+ return new OFactoryComponentHelper(
+ rServiceManager, rImplementationName, pCreateFunction, 0, &rServiceNames, sal_True );
}
// global function
@@ -716,8 +819,8 @@ Reference<XSingleServiceFactory > SAL_CALL createSingleRegistryFactory(
const Reference<XRegistryKey > & rImplementationKey )
SAL_THROW( () )
{
- return new ORegistryFactoryHelper( rServiceManager, rImplementationName,
- rImplementationKey, sal_False );
+ return new ORegistryFactoryHelper(
+ rServiceManager, rImplementationName, rImplementationKey, sal_False );
}
// global function
@@ -727,8 +830,19 @@ Reference<XSingleServiceFactory > SAL_CALL createOneInstanceRegistryFactory(
const Reference<XRegistryKey > & rImplementationKey )
SAL_THROW( () )
{
- return new ORegistryFactoryHelper( rServiceManager, rImplementationName,
- rImplementationKey, sal_True );
+ return new ORegistryFactoryHelper(
+ rServiceManager, rImplementationName, rImplementationKey, sal_True );
+}
+
+//##################################################################################################
+Reference< lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(
+ ComponentFactoryFunc fptr,
+ OUString const & rImplementationName,
+ Sequence< OUString > const & rServiceNames )
+ SAL_THROW( () )
+{
+ return new OFactoryComponentHelper(
+ Reference< XMultiServiceFactory >(), rImplementationName, 0, fptr, &rServiceNames, sal_False );
}
}
diff --git a/cppuhelper/source/makefile.mk b/cppuhelper/source/makefile.mk
index 7652974c6224..ec6d3cbb915f 100644
--- a/cppuhelper/source/makefile.mk
+++ b/cppuhelper/source/makefile.mk
@@ -2,9 +2,9 @@
#
# $RCSfile: makefile.mk,v $
#
-# $Revision: 1.10 $
+# $Revision: 1.11 $
#
-# last change: $Author: jsc $ $Date: 2001-05-04 13:38:30 $
+# last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@@ -86,20 +86,33 @@ UNOTYPES= \
com.sun.star.container.XSet \
com.sun.star.uno.XWeak \
com.sun.star.uno.XAggregation \
+ com.sun.star.uno.XComponentContext \
com.sun.star.lang.XMultiServiceFactory \
com.sun.star.lang.XSingleServiceFactory \
+ com.sun.star.lang.XMultiComponentFactory \
+ com.sun.star.lang.XSingleComponentFactory \
com.sun.star.lang.XServiceInfo \
com.sun.star.lang.XInitialization \
+ com.sun.star.lang.XEventListener \
com.sun.star.reflection.XIdlReflection \
com.sun.star.reflection.XIdlClass \
com.sun.star.reflection.XIdlClassProvider \
com.sun.star.reflection.XIndirectTypeDescription \
- com.sun.star.reflection.XMethodParameter \
+ com.sun.star.reflection.XMethodParameter \
com.sun.star.reflection.XInterfaceMemberTypeDescription \
+ com.sun.star.reflection.XTypeDescription \
+ com.sun.star.reflection.XEnumTypeDescription \
+ com.sun.star.reflection.XArrayTypeDescription \
+ com.sun.star.reflection.XInterfaceAttributeTypeDescription \
+ com.sun.star.reflection.XInterfaceMethodTypeDescription \
+ com.sun.star.reflection.XInterfaceTypeDescription \
+ com.sun.star.reflection.XCompoundTypeDescription \
+ com.sun.star.reflection.XUnionTypeDescription \
com.sun.star.beans.XPropertySet \
com.sun.star.beans.XMultiPropertySet \
com.sun.star.beans.XFastPropertySet \
com.sun.star.beans.PropertyAttribute \
+ com.sun.star.container.XHierarchicalNameAccess \
com.sun.star.registry.XRegistryKey \
com.sun.star.loader.XImplementationLoader \
com.sun.star.lang.XTypeProvider \
@@ -115,8 +128,10 @@ SLOFILES= \
$(SLO)$/interfacecontainer.obj \
$(SLO)$/stdidlclass.obj \
$(SLO)$/factory.obj \
+ $(SLO)$/component_context.obj \
$(SLO)$/component.obj \
- $(SLO)$/shlib.obj
+ $(SLO)$/shlib.obj \
+ $(SLO)$/tdmgr.obj
SHL1TARGET= $(TARGET)$(UDK_MAJOR)$(COM)
diff --git a/cppuhelper/source/servicefactory.cxx b/cppuhelper/source/servicefactory.cxx
index 2721e4a25a82..47d2179f66fe 100644
--- a/cppuhelper/source/servicefactory.cxx
+++ b/cppuhelper/source/servicefactory.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: servicefactory.cxx,v $
*
- * $Revision: 1.9 $
+ * $Revision: 1.10 $
*
- * last change: $Author: jl $ $Date: 2001-03-12 13:39:32 $
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -72,12 +72,18 @@
#include <rtl/ustrbuf.hxx>
#endif
+#include <cppuhelper/tdmgr.hxx>
#include <cppuhelper/shlib.hxx>
+#include <cppuhelper/factory.hxx>
+#include <cppuhelper/component_context.hxx>
-#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
+#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/registry/XSimpleRegistry.hpp>
#include <com/sun/star/registry/XImplementationRegistration.hpp>
@@ -88,83 +94,42 @@ using namespace com::sun::star::lang;
using namespace com::sun::star::loader;
using namespace com::sun::star::registry;
using namespace com::sun::star::container;
+using namespace com::sun::star;
namespace cppu
{
//==================================================================================================
-static inline Reference< XSingleServiceFactory > loadLibComponentFactory(
- const OUString & rLibName, const OUString & rImplName,
- const OUString & rBootstrapPath,
- const Reference< XMultiServiceFactory > & xSF, const Reference< XRegistryKey > & xKey )
-{
- return loadSharedLibComponentFactory( rLibName, rBootstrapPath, rImplName, xSF, xKey );
-}
+Reference< XComponentContext > SAL_CALL createInitialComponentContext(
+ ContextEntry_Init const * pEntries, sal_Int32 nEntries,
+ Reference< registry::XSimpleRegistry > const & xRegistry )
+ SAL_THROW( () );
//==================================================================================================
-static Reference< ::com::sun::star::lang::XSingleServiceFactory> SAL_CALL createLoaderFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
+static Reference< XInterface > SAL_CALL createInstance(
+ Reference< XInterface > const & xFactory,
+ Reference< XComponentContext > const & xContext = Reference< XComponentContext >() )
{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("cpld") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.DLLComponentLoader") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory > SAL_CALL createSimpleRegistryFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("simreg") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory> SAL_CALL createDefaultRegistryFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("defreg") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.DefaultRegistry") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory> SAL_CALL createNestedRegistryFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("defreg") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory> SAL_CALL createImplRegFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("impreg") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.ImplementationRegistration") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory> SAL_CALL createRegTDProviderFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("rdbtdp") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
-}
-//==================================================================================================
-static Reference< XSingleServiceFactory> SAL_CALL createTDManagerFactory(
- const Reference< XMultiServiceFactory > & xSF, const OUString & rBootstrapPath )
-{
- return loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("tdmgr") ),
- OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.TypeDescriptionManager") ),
- rBootstrapPath, xSF, Reference< XRegistryKey >() );
+ Reference< XSingleComponentFactory > xFac( xFactory, UNO_QUERY );
+ if (xFac.is())
+ {
+ return xFac->createInstanceWithContext( xContext );
+ }
+ else
+ {
+ Reference< XSingleServiceFactory > xFac( xFactory, UNO_QUERY );
+ if (xFac.is())
+ {
+ OSL_ENSURE( !xContext.is(), "### ignoring context!" );
+ return xFac->createInstance();
+ }
+ }
+ throw Exception(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("no factory object given!") ),
+ Reference< XInterface >() );
}
+
//==================================================================================================
static Reference< XMultiServiceFactory > createImplServiceFactory(
const OUString & rWriteRegistry,
@@ -173,195 +138,192 @@ static Reference< XMultiServiceFactory > createImplServiceFactory(
const OUString & rBootstrapPath )
SAL_THROW( (::com::sun::star::uno::Exception) )
{
- Reference< XSingleServiceFactory > xSMFac( loadLibComponentFactory(
- OUString( RTL_CONSTASCII_USTRINGPARAM("smgr") ),
+ Reference< XInterface > xSMFac( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("smgr") ), rBootstrapPath,
OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.ORegistryServiceManager") ),
- rBootstrapPath, Reference< XMultiServiceFactory >(), Reference< XRegistryKey >() ) );
+ Reference< XMultiServiceFactory >(), Reference< XRegistryKey >() ) );
- // stop here if not at least a service manager is available
- if ( !xSMFac.is() )
+ Reference< XMultiServiceFactory > xSF( createInstance( xSMFac ), UNO_QUERY );
+ Reference< XInitialization > xSFInit( xSF, UNO_QUERY );
+ if (! xSFInit.is())
{
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("service manager component not available")),
- Reference< XInterface >() );
+ throw Exception(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("servicemanager does not support XInitialization!") ),
+ Reference< XInterface >() );
}
- Reference< XMultiServiceFactory > xSF( xSMFac->createInstance(), UNO_QUERY );
- Reference< XInitialization > xInit( xSF, UNO_QUERY );
+ Reference< XInterface > xSimRegFac( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("simreg") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.SimpleRegistry") ),
+ xSF, Reference< XRegistryKey >() ) );
+
+ Reference< XInterface > xNesRegFac( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("defreg") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.NestedRegistry") ),
+ xSF, Reference< XRegistryKey >() ) );
+
+ // write initial shared lib loader, simple registry, default registry, impl reg
+ Reference< XSet > xSet( xSF, UNO_QUERY );
- OSL_ENSURE( xInit.is() && xSF.is(), "### failed loading servicemanager!" );
- if (xInit.is() && xSF.is())
+ // loader
{
- Reference< XSingleServiceFactory > xSimRegFac( createSimpleRegistryFactory( xSF, rBootstrapPath ) );
- Reference< XSingleServiceFactory > xNesRegFac( createNestedRegistryFactory( xSF, rBootstrapPath ) );
- OSL_ENSURE( xSimRegFac.is() && xNesRegFac.is(), "### cannot get registry factories!" );
+ Any aFac( makeAny( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("cpld") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.DLLComponentLoader") ),
+ xSF, Reference< XRegistryKey >() ) ) );
+ xSet->insert( aFac );
+ OSL_ENSURE( xSet->has( aFac ), "### failed registering loader!" );
+ }
+ // simple registry
+ xSet->insert( makeAny( xSimRegFac ) );
+ OSL_ENSURE( xSet->has( makeAny( xSimRegFac ) ), "### failed registering simple registry!" );
+ // nested registry
+ xSet->insert( makeAny( xNesRegFac ) );
+ OSL_ENSURE( xSet->has( makeAny( xNesRegFac ) ), "### failed registering default registry!" );
+ // implementation registration
+ {
+ Any aFac( makeAny( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("impreg") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.ImplementationRegistration") ),
+ xSF, Reference< XRegistryKey >() ) ) );
+ xSet->insert( aFac );
+ OSL_ENSURE( xSet->has( aFac ), "### failed registering impl reg!" );
+ }
- // write initial shared lib loader, simple registry, default registry, impl reg
- Reference< XSet > xSet( xSF, UNO_QUERY );
+ Reference< XSimpleRegistry > xRegistry;
- // loader
- {
- Reference< XSingleServiceFactory > xFac( createLoaderFactory( xSF, rBootstrapPath ) );
- if ( !xFac.is() )
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("shared library loader component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xFac ) );
- OSL_ENSURE( xSet->has( makeAny( xFac ) ), "### failed registering loader!" );
- }
- // simple registry
- {
- if ( !xSimRegFac.is() )
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("simple registry component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xSimRegFac ) );
- OSL_ENSURE( xSet->has( makeAny( xSimRegFac ) ), "### failed registering simple registry!" );
- }
- // nested registry
- {
- if ( !xNesRegFac.is() )
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("nested registry component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xNesRegFac ) );
- OSL_ENSURE( xSet->has( makeAny( xNesRegFac ) ), "### failed registering default registry!" );
- }
- // implementation registration
- {
- Reference< XSingleServiceFactory > xFac( createImplRegFactory( xSF, rBootstrapPath ) );
- if ( !xFac.is() )
+ // open a registry
+ sal_Bool bRegistryShouldBeValid = sal_False;
+ if (rWriteRegistry.getLength() && !rReadRegistry.getLength())
+ {
+ bRegistryShouldBeValid = sal_True;
+ xRegistry.set( createInstance( xSimRegFac ), UNO_QUERY );
+ if (xRegistry.is())
{
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("implementation registration component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xFac ) );
- OSL_ENSURE( xSet->has( makeAny( xFac ) ), "### failed registering impl reg!" );
+ if (bReadOnly)
+ {
+ xRegistry->open( rWriteRegistry, sal_True, sal_False );
+ }
+ else
+ {
+ xRegistry->open( rWriteRegistry, sal_False, sal_True );
+ }
}
+ }
+ else if (rWriteRegistry.getLength() && rReadRegistry.getLength()) // default registry
+ {
+ bRegistryShouldBeValid = sal_True;
+ xRegistry.set( createInstance( xNesRegFac ), UNO_QUERY );
- Reference< XSimpleRegistry > xRegistry;
-
- // open a registry
- sal_Bool bRegistryShouldBeValid = sal_False;
- if (rWriteRegistry.getLength() && !rReadRegistry.getLength())
+ Reference< XSimpleRegistry > xWriteReg( createInstance( xSimRegFac ), UNO_QUERY );
+ if (xWriteReg.is())
{
- bRegistryShouldBeValid = sal_True;
- xRegistry = Reference< XSimpleRegistry >::query( xSimRegFac->createInstance() );
- if (xRegistry.is())
+ if (bReadOnly)
{
- if (bReadOnly)
+ try
{
- xRegistry->open( rWriteRegistry, sal_True, sal_False );
- } else
+ xWriteReg->open( rWriteRegistry, sal_True, sal_False );
+ }
+ catch (InvalidRegistryException &)
{
- xRegistry->open( rWriteRegistry, sal_False, sal_True );
}
- }
- }
- else // default registry
- if (rWriteRegistry.getLength() && rReadRegistry.getLength() )
- {
- bRegistryShouldBeValid = sal_True;
- xRegistry = Reference< XSimpleRegistry >::query( xNesRegFac->createInstance() );
- Reference< XSimpleRegistry > xWriteReg = Reference< XSimpleRegistry >::query( xSimRegFac->createInstance() );
- if ( xWriteReg.is() )
- {
- if (bReadOnly)
- {
- try
- {
- xWriteReg->open( rWriteRegistry, sal_True, sal_False );
- }
- catch(InvalidRegistryException&)
- {
- }
-
- if (!xWriteReg->isValid())
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("specified first registry could not be open readonly")),
- Reference< XInterface >() );
- }
- } else
+ if (!xWriteReg->isValid())
{
- xWriteReg->open( rWriteRegistry, sal_False, sal_True );
+ throw Exception(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("specified first registry could not be open readonly!") ),
+ Reference< XInterface >() );
}
}
-
- Reference< XSimpleRegistry > xReadReg = Reference< XSimpleRegistry >::query( xSimRegFac->createInstance() );
- if ( xReadReg.is() )
+ else
{
- xReadReg->open( rReadRegistry, sal_True, sal_False );
+ xWriteReg->open( rWriteRegistry, sal_False, sal_True );
}
-
- Reference< XInitialization > xInit( xRegistry, UNO_QUERY );
- Sequence< Any > aInitSeq( 2 );
- aInitSeq[0] <<= xWriteReg;
- aInitSeq[1] <<= xReadReg;
- xInit->initialize( aInitSeq );
}
- if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
+ Reference< XSimpleRegistry > xReadReg( createInstance( xSimRegFac ), UNO_QUERY );
+ if (xReadReg.is())
{
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("specified registry could not be initialized")),
- Reference< XInterface >() );
+ xReadReg->open( rReadRegistry, sal_True, sal_False );
}
-// OSL_ENSURE( xRegistry.is(), "### got no registry!" );
- Reference< XInterface > xInst;
- if (xRegistry.is())
- {
- // init service factory with registry
- Sequence< Any > aSeq( 1 );
- // registry to work on
- aSeq[0] = makeAny( xRegistry );
- xInit->initialize( aSeq );
+ Reference< XInitialization > xInit( xRegistry, UNO_QUERY );
+ Sequence< Any > aInitSeq( 2 );
+ aInitSeq[ 0 ] <<= xWriteReg;
+ aInitSeq[ 1 ] <<= xReadReg;
+ xInit->initialize( aInitSeq );
+ }
- xInst = xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.TypeDescriptionManager")) );
- }
+ if (bRegistryShouldBeValid && (!xRegistry.is() || !xRegistry->isValid()))
+ {
+ throw Exception(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("specified registry could not be initialized") ),
+ Reference< XInterface >() );
+ }
+
+ // default initial context
+ ContextEntry_Init context_values[ 4 ];
+ sal_Int32 nEntries = 1;
+ // smgr
+ context_values[ 0 ].bLateInitService = false;
+ context_values[ 0 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.lang.ServiceManager") );
+ context_values[ 0 ].value = makeAny( xSF );
- // initial td manager held by service manager
- if (! xInst.is())
+ // additional service factories
+ // registry td provider
{
- // td registry provider registration
- {
- Reference< XSingleServiceFactory > xFac( createRegTDProviderFactory( xSF, rBootstrapPath ) );
- if ( !xFac.is() )
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("type description provider component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xFac ) );
- OSL_ENSURE( xSet->has( makeAny( xFac ) ), "### failed registering registry td provider!" );
- }
- // stoc td manager registration
- {
- Reference< XSingleServiceFactory > xFac( createTDManagerFactory( xSF, rBootstrapPath ) );
- if ( !xFac.is() )
- {
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("type description manager component not available")),
- Reference< XInterface >() );
- }
- xSet->insert( makeAny( xFac ) );
- OSL_ENSURE( xSet->has( makeAny( xFac ) ), "### failed registering td manager!" );
- }
- xInst = xSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.TypeDescriptionManager")) );
+ Any aFac( makeAny( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("rdbtdp") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider") ),
+ xSF, Reference< XRegistryKey >() ) ) );
+ xSet->insert( aFac );
+ OSL_ENSURE( xSet->has( aFac ), "### failed registering registry td provider!" );
}
- if (xInst.is())
- {
- Reference< XInitialization > xTDMInit( xInst, UNO_QUERY );
- if (xTDMInit.is())
- xTDMInit->initialize( Sequence< Any >() );
- } else
+ // td manager
{
- throw Exception( OUString(RTL_CONSTASCII_USTRINGPARAM("service \"com.sun.star.reflection.TypeDescriptionManager\" could not be initialized")),
- Reference< XInterface >() );
+ Any aFac( makeAny( loadSharedLibComponentFactory(
+ OUString( RTL_CONSTASCII_USTRINGPARAM("tdmgr") ), rBootstrapPath,
+ OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.TypeDescriptionManager") ),
+ xSF, Reference< XRegistryKey >() ) ) );
+ xSet->insert( aFac );
+ OSL_ENSURE( xSet->has( aFac ), "### failed registering registry td provider!" );
}
- return xSF;
+
+ // xxx todo
+ if (xRegistry.is())
+ {
+ // rdbtdp: registries to be used
+ context_values[ 1 ].bLateInitService = false;
+ context_values[ 1 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.RegistryTypeDescriptionProvider.Registries") );
+ context_values[ 1 ].value = makeAny( Sequence< Reference< XSimpleRegistry > >( &xRegistry, 1 ) );
+ // tdmgr: cache size
+ context_values[ 2 ].bLateInitService = false;
+ context_values[ 2 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.TypeDescriptionManager.CacheSize") );
+ context_values[ 2 ].value = makeAny( (sal_Int32)512 );
+ // tdmgr
+ context_values[ 3 ].bLateInitService = true;
+ context_values[ 3 ].name = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.TypeDescriptionManager") );
+ context_values[ 3 ].value = makeAny( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.reflection.TypeDescriptionManager") ) );
+
+ nEntries = 4;
}
- return Reference< XMultiServiceFactory >();
+
+ Reference< XComponentContext > xContext( createInitialComponentContext(
+ context_values, nEntries, xRegistry ) );
+
+ Sequence< Any > aSFInit( 2 );
+ aSFInit[ 0 ] <<= xRegistry;
+ aSFInit[ 1 ] <<= xContext;
+ xSFInit->initialize( aSFInit );
+
+ Reference< container::XHierarchicalNameAccess > xTDMgr;
+ if (xContext->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM(
+ "com.sun.star.reflection.TypeDescriptionManager") ) ) >>= xTDMgr)
+ {
+ installTypeDescriptionManager( xTDMgr );
+ }
+
+ return xSF;
}
//==================================================================================================
diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx
index 6b4998b40ce4..d71da44db791 100644
--- a/cppuhelper/source/shlib.cxx
+++ b/cppuhelper/source/shlib.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: shlib.cxx,v $
*
- * $Revision: 1.7 $
+ * $Revision: 1.8 $
*
- * last change: $Author: kz $ $Date: 2001-03-28 09:23:17 $
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -298,7 +298,7 @@ static OUString makeComponentPath( const OUString & rLibName, const OUString & r
}
//==================================================================================================
-Reference< XSingleServiceFactory > SAL_CALL loadSharedLibComponentFactory(
+Reference< XInterface > SAL_CALL loadSharedLibComponentFactory(
OUString const & rLibName, OUString const & rPath,
OUString const & rImplName,
Reference< XMultiServiceFactory > const & xMgr,
@@ -325,7 +325,7 @@ Reference< XSingleServiceFactory > SAL_CALL loadSharedLibComponentFactory(
throw CannotActivateFactoryException( aExcMsg, Reference< XInterface >() );
}
- Reference< XSingleServiceFactory > xRet;
+ Reference< XInterface > xRet;
void * pSym;
OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
@@ -409,8 +409,8 @@ Reference< XSingleServiceFactory > SAL_CALL loadSharedLibComponentFactory(
}
else
{
- XSingleServiceFactory * pRet = (XSingleServiceFactory *)
- (*((component_getFactoryFunc)pSym))( aImplName.getStr(), xMgr.get(), xKey.get() );
+ XInterface * pRet = (XInterface *)(*((component_getFactoryFunc)pSym))(
+ aImplName.getStr(), xMgr.get(), xKey.get() );
if (pRet)
{
xRet = pRet;
diff --git a/cppuhelper/source/tdmgr.cxx b/cppuhelper/source/tdmgr.cxx
new file mode 100644
index 000000000000..b35388798593
--- /dev/null
+++ b/cppuhelper/source/tdmgr.cxx
@@ -0,0 +1,695 @@
+/*************************************************************************
+ *
+ * $RCSfile: tdmgr.cxx,v $
+ *
+ * $Revision: 1.1 $
+ *
+ * last change: $Author: dbo $ $Date: 2001-05-08 15:56:02 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * either of the following licenses
+ *
+ * - GNU Lesser General Public License Version 2.1
+ * - Sun Industry Standards Source License Version 1.1
+ *
+ * Sun Microsystems Inc., October, 2000
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2000 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ *
+ * Sun Industry Standards Source License Version 1.1
+ * =================================================
+ * The contents of this file are subject to the Sun Industry Standards
+ * Source License Version 1.1 (the "License"); You may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at http://www.openoffice.org/license.html.
+ *
+ * Software provided under this License is provided on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
+ * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
+ * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
+ * See the License for the specific provisions governing your rights and
+ * obligations concerning the Software.
+ *
+ * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
+ *
+ * Copyright: 2000 by Sun Microsystems, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * Contributor(s): _______________________________________
+ *
+ *
+ ************************************************************************/
+
+#ifndef MACOSX
+#include <malloc.h>
+#endif
+#ifdef SOLARIS
+#include <alloca.h>
+#endif
+
+#include <osl/diagnose.h>
+#include <rtl/alloc.h>
+#include <rtl/ustring.hxx>
+#include <rtl/string.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+#include <typelib/typedescription.h>
+
+#include <com/sun/star/lang/XComponent.hpp>
+#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
+#include <com/sun/star/reflection/XTypeDescription.hpp>
+#include <com/sun/star/reflection/XEnumTypeDescription.hpp>
+#include <com/sun/star/reflection/XArrayTypeDescription.hpp>
+#include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
+#include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
+#include <com/sun/star/reflection/XInterfaceAttributeTypeDescription.hpp>
+#include <com/sun/star/reflection/XMethodParameter.hpp>
+#include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
+#include <com/sun/star/reflection/XInterfaceTypeDescription.hpp>
+#include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
+#include <com/sun/star/reflection/XUnionTypeDescription.hpp>
+
+using namespace ::rtl;
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::reflection;
+
+
+namespace cppu
+{
+
+static typelib_TypeDescription * createCTD( const Reference< XTypeDescription > & xType );
+
+//==================================================================================================
+inline static sal_Int64 coerceToInt64( const Any & rVal )
+{
+ switch (rVal.getValueTypeClass())
+ {
+ case TypeClass_CHAR:
+ return *(sal_Unicode *)rVal.getValue();
+ case TypeClass_BOOLEAN:
+ return (*(sal_Bool *)rVal.getValue() ? 1 : 0);
+ case TypeClass_BYTE:
+ return *(sal_Int8 *)rVal.getValue();
+ case TypeClass_SHORT:
+ return *(sal_Int16 *)rVal.getValue();
+ case TypeClass_UNSIGNED_SHORT:
+ return *(sal_uInt16 *)rVal.getValue();
+ case TypeClass_LONG:
+ return *(sal_Int32 *)rVal.getValue();
+ case TypeClass_UNSIGNED_LONG:
+ return *(sal_uInt32 *)rVal.getValue();
+ case TypeClass_HYPER:
+ return *(sal_Int64 *)rVal.getValue();
+ case TypeClass_UNSIGNED_HYPER:
+ return *(sal_uInt64 *)rVal.getValue();
+ case TypeClass_ENUM:
+ return *(int *)rVal.getValue();
+ }
+ OSL_ENSURE( sal_False, "### cannot read union discriminant: no ordinal type!" );
+ return 0; // dummy
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XUnionTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ OUString aTypeName( xType->getName() );
+
+ // discriminant type
+ Reference< XTypeDescription > xDiscrTD( xType->getDiscriminantType() );
+ OUString aDiscrTypeName( xDiscrTD->getName() );
+ typelib_TypeDescriptionReference * pDiscrTypeRef = 0;
+ typelib_typedescriptionreference_new( &pDiscrTypeRef,
+ (typelib_TypeClass)xDiscrTD->getTypeClass(),
+ aDiscrTypeName.pData );
+ // default member type
+ Reference< XTypeDescription > xDefaultMemberTD( xType->getDefaultMemberType() );
+ OUString aDefMemberTypeName( xDefaultMemberTD->getName() );
+ typelib_TypeDescriptionReference * pDefMemberTypeRef = 0;
+ typelib_typedescriptionreference_new( &pDefMemberTypeRef,
+ (typelib_TypeClass)xDefaultMemberTD->getTypeClass(),
+ aDefMemberTypeName.pData );
+ // init array
+ Sequence< Any > aDiscriminants( xType->getDiscriminants() );
+ Sequence< Reference< XTypeDescription > > aMemberTypes( xType->getMemberTypes() );
+ Sequence< OUString > aMemberNames( xType->getMemberNames() );
+ sal_Int32 nMembers = aDiscriminants.getLength();
+ OSL_ASSERT( nMembers == aMemberNames.getLength() && nMembers == aMemberTypes.getLength() );
+
+ const Any * pDiscriminants = aDiscriminants.getConstArray();
+ const Reference< XTypeDescription > * pMemberTypes = aMemberTypes.getConstArray();
+ const OUString * pMemberNames = aMemberNames.getConstArray();
+
+ typelib_Union_Init * pMembers = (typelib_Union_Init *)alloca( nMembers * sizeof(typelib_Union_Init) );
+
+ sal_Int32 nPos;
+ for ( nPos = nMembers; nPos--; )
+ {
+ typelib_Union_Init & rEntry = pMembers[nPos];
+ // member discriminant
+ rEntry.nDiscriminant = coerceToInt64( pDiscriminants[nPos] );
+ // member type
+ OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
+ rEntry.pTypeRef = 0;
+ typelib_typedescriptionreference_new( &rEntry.pTypeRef,
+ (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass(),
+ aMemberTypeName.pData );
+ // member name
+ rEntry.pMemberName = pMemberNames[nPos].pData;
+ }
+
+ typelib_typedescription_newUnion( &pRet, aTypeName.pData,
+ pDiscrTypeRef,
+ coerceToInt64( xType->getDefaultDiscriminant() ),
+ pDefMemberTypeRef,
+ nMembers, pMembers );
+
+ for ( nPos = nMembers; nPos--; )
+ {
+ typelib_typedescriptionreference_release( pMembers[nPos].pTypeRef );
+ }
+
+ typelib_typedescriptionreference_release( pDiscrTypeRef );
+ typelib_typedescriptionreference_release( pDefMemberTypeRef );
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XCompoundTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ typelib_TypeDescription * pBaseType = createCTD(
+ Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
+ if (pBaseType)
+ typelib_typedescription_register( &pBaseType );
+
+ // construct member init array
+ const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
+ const Sequence< OUString > & rMemberNames = xType->getMemberNames();
+
+ const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
+ const OUString * pMemberNames = rMemberNames.getConstArray();
+
+ sal_Int32 nMembers = rMemberTypes.getLength();
+ OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
+
+ OUString aTypeName( xType->getName() );
+
+ typelib_CompoundMember_Init * pMemberInits = (typelib_CompoundMember_Init *)alloca(
+ sizeof(typelib_CompoundMember_Init) * nMembers );
+
+ sal_Int32 nPos;
+ for ( nPos = nMembers; nPos--; )
+ {
+ typelib_CompoundMember_Init & rInit = pMemberInits[nPos];
+ rInit.eTypeClass = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
+
+ OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
+ rtl_uString_acquire( rInit.pTypeName = aMemberTypeName.pData );
+
+ // string is held by rMemberNames
+ rInit.pMemberName = pMemberNames[nPos].pData;
+ }
+
+ typelib_typedescription_new(
+ &pRet,
+ (typelib_TypeClass)xType->getTypeClass(),
+ aTypeName.pData,
+ (pBaseType ? pBaseType->pWeakRef : 0),
+ nMembers, pMemberInits );
+
+ // cleanup
+ for ( nPos = nMembers; nPos--; )
+ {
+ rtl_uString_release( pMemberInits[nPos].pTypeName );
+ }
+ if (pBaseType)
+ typelib_typedescription_release( pBaseType );
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XInterfaceAttributeTypeDescription > & xAttribute )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xAttribute.is())
+ {
+ OUString aMemberName( xAttribute->getName() );
+ Reference< XTypeDescription > xType( xAttribute->getType() );
+ OUString aMemberTypeName( xType->getName() );
+
+ typelib_typedescription_newInterfaceAttribute(
+ (typelib_InterfaceAttributeTypeDescription **)&pRet,
+ xAttribute->getPosition(),
+ aMemberName.pData, // name
+ (typelib_TypeClass)xType->getTypeClass(),
+ aMemberTypeName.pData, // type name
+ xAttribute->isReadOnly() );
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XInterfaceMethodTypeDescription > & xMethod )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xMethod.is())
+ {
+ Reference< XTypeDescription > xReturnType( xMethod->getReturnType() );
+
+ // init all params
+ const Sequence<Reference< XMethodParameter > > & rParams = xMethod->getParameters();
+ const Reference< XMethodParameter > * pParams = rParams.getConstArray();
+ sal_Int32 nParams = rParams.getLength();
+
+ typelib_Parameter_Init * pParamInit = (typelib_Parameter_Init *)alloca(
+ sizeof(typelib_Parameter_Init) * nParams );
+
+ sal_Int32 nPos;
+ for ( nPos = nParams; nPos--; )
+ {
+ const Reference< XMethodParameter > & xParam = pParams[nPos];
+ const Reference< XTypeDescription > & xType = xParam->getType();
+ typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
+
+ rInit.eTypeClass = (typelib_TypeClass)xType->getTypeClass();
+ OUString aParamTypeName( xType->getName() );
+ rtl_uString_acquire( rInit.pTypeName = aParamTypeName.pData );
+ OUString aParamName( xParam->getName() );
+ rtl_uString_acquire( rInit.pParamName = aParamName.pData );
+ rInit.bIn = xParam->isIn();
+ rInit.bOut = xParam->isOut();
+ }
+
+ // init all exception strings
+ const Sequence<Reference< XTypeDescription > > & rExceptions = xMethod->getExceptions();
+ const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
+ sal_Int32 nExceptions = rExceptions.getLength();
+ rtl_uString ** ppExceptionNames = (rtl_uString **)alloca(
+ sizeof(rtl_uString *) * nExceptions );
+
+ for ( nPos = nExceptions; nPos--; )
+ {
+ OUString aExceptionTypeName( pExceptions[nPos]->getName() );
+ rtl_uString_acquire( ppExceptionNames[nPos] = aExceptionTypeName.pData );
+ }
+
+ OUString aTypeName( xMethod->getName() );
+ OUString aReturnTypeName( xReturnType->getName() );
+
+ typelib_typedescription_newInterfaceMethod(
+ (typelib_InterfaceMethodTypeDescription **)&pRet,
+ xMethod->getPosition(),
+ xMethod->isOneway(),
+ aTypeName.pData,
+ (typelib_TypeClass)xReturnType->getTypeClass(),
+ aReturnTypeName.pData,
+ nParams, pParamInit,
+ nExceptions, ppExceptionNames );
+
+ for ( nPos = nParams; nPos--; )
+ {
+ rtl_uString_release( pParamInit[nPos].pTypeName );
+ rtl_uString_release( pParamInit[nPos].pParamName );
+ }
+ for ( nPos = nExceptions; nPos--; )
+ {
+ rtl_uString_release( ppExceptionNames[nPos] );
+ }
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XInterfaceTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ typelib_TypeDescription * pBaseType = createCTD(
+ Reference< XInterfaceTypeDescription >::query( xType->getBaseType() ) );
+ if (pBaseType)
+ typelib_typedescription_register( &pBaseType );
+
+ // construct all member refs
+ const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
+ sal_Int32 nMembers = rMembers.getLength();
+
+ typelib_TypeDescriptionReference ** ppMemberRefs = (typelib_TypeDescriptionReference **)alloca(
+ sizeof(typelib_TypeDescriptionReference *) * nMembers );
+
+ const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
+
+ OUString aTypeName( xType->getName() );
+
+ sal_Int32 nPos;
+ for ( nPos = nMembers; nPos--; )
+ {
+ OUString aMemberTypeName( pMembers[nPos]->getName() );
+ ppMemberRefs[nPos] = 0;
+ typelib_typedescriptionreference_new(
+ ppMemberRefs + nPos,
+ (typelib_TypeClass)pMembers[nPos]->getTypeClass(),
+ aMemberTypeName.pData );
+ }
+
+ Uik uik = xType->getUik();
+
+ typelib_typedescription_newInterface(
+ (typelib_InterfaceTypeDescription **)&pRet,
+ aTypeName.pData,
+ uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5,
+ (pBaseType ? pBaseType->pWeakRef : 0),
+ nMembers, ppMemberRefs );
+
+ // cleanup refs and base type
+ if (pBaseType)
+ typelib_typedescription_release( pBaseType );
+
+ for ( nPos = nMembers; nPos--; )
+ {
+ typelib_typedescriptionreference_release( ppMemberRefs[nPos] );
+ }
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD( const Reference< XEnumTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ OUString aTypeName( xType->getName() );
+ Sequence< OUString > aNames( xType->getEnumNames() );
+ OSL_ASSERT( sizeof(OUString) == sizeof(rtl_uString *) ); // !!!
+ Sequence< sal_Int32 > aValues( xType->getEnumValues() );
+
+ typelib_typedescription_newEnum(
+ &pRet, aTypeName.pData, xType->getDefaultEnumValue(),
+ aNames.getLength(),
+ (rtl_uString **)aNames.getConstArray(),
+ const_cast< sal_Int32 * >( aValues.getConstArray() ) );
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XArrayTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ typelib_TypeDescription * pElementType = createCTD( xType->getType() );
+ typelib_typedescription_register( &pElementType );
+
+ Sequence< sal_Int32 > dims( xType->getDimensions() );
+ OSL_ASSERT( dims.getLength() == xType->getNumberOfDimensions() );
+
+ OUString aTypeName( xType->getName() );
+
+ typelib_typedescription_newArray(
+ &pRet, pElementType->pWeakRef,
+ dims.getLength(), const_cast< sal_Int32 * >( dims.getConstArray() ) );
+
+ // cleanup
+ if (pElementType)
+ typelib_typedescription_release( pElementType );
+ }
+ return pRet;
+}
+//==================================================================================================
+inline static typelib_TypeDescription * createCTD(
+ const Reference< XIndirectTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+ if (xType.is())
+ {
+ typelib_TypeDescription * pRefType = createCTD( xType->getReferencedType() );
+ typelib_typedescription_register( &pRefType );
+
+ OUString aTypeName( xType->getName() );
+
+ typelib_typedescription_new(
+ &pRet,
+ (typelib_TypeClass)xType->getTypeClass(),
+ aTypeName.pData,
+ pRefType->pWeakRef,
+ 0, 0 );
+
+ // cleanup
+ if (pRefType)
+ typelib_typedescription_release( pRefType );
+ }
+ return pRet;
+}
+
+//==================================================================================================
+typelib_TypeDescription * createCTD( const Reference< XTypeDescription > & xType )
+{
+ typelib_TypeDescription * pRet = 0;
+
+ if (xType.is())
+ {
+ switch (xType->getTypeClass())
+ {
+ // built in types
+ case TypeClass_VOID:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("void") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_VOID, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_CHAR:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("char") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_CHAR, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_BOOLEAN:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("boolean") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_BOOLEAN, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_BYTE:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("byte") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_BYTE, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_SHORT:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("short") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_SHORT, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_UNSIGNED_SHORT:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_SHORT, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_LONG:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("long") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_UNSIGNED_LONG:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned long") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_LONG, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_HYPER:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("hyper") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_HYPER, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_UNSIGNED_HYPER:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned hyper") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_HYPER, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_FLOAT:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("float") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_FLOAT, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_DOUBLE:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("double") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_STRING:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_STRING, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_TYPE:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_TYPE, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+ case TypeClass_ANY:
+ {
+ OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
+ typelib_typedescription_new( &pRet, typelib_TypeClass_ANY, aTypeName.pData, 0, 0, 0 );
+ break;
+ }
+
+ case TypeClass_UNION:
+ pRet = createCTD( Reference< XUnionTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_EXCEPTION:
+ case TypeClass_STRUCT:
+ pRet = createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_ENUM:
+ pRet = createCTD( Reference< XEnumTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_TYPEDEF:
+ {
+ Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
+ if (xTypedef.is())
+ pRet = createCTD( xTypedef->getReferencedType() );
+ break;
+ }
+ case TypeClass_ARRAY:
+ pRet = createCTD( Reference< XArrayTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_SEQUENCE:
+ pRet = createCTD( Reference< XIndirectTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_INTERFACE:
+ pRet = createCTD( Reference< XInterfaceTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_INTERFACE_METHOD:
+ pRet = createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
+ break;
+ case TypeClass_INTERFACE_ATTRIBUTE:
+ pRet = createCTD( Reference< XInterfaceAttributeTypeDescription >::query( xType ) );
+ break;
+ }
+ }
+
+ return pRet;
+}
+
+
+//==================================================================================================
+extern "C"
+{
+static void SAL_CALL typelib_callback(
+ void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName )
+{
+ OSL_ENSURE( pContext && ppRet && pTypeName, "### null ptr!" );
+ if (ppRet)
+ {
+ if (*ppRet)
+ {
+ ::typelib_typedescription_release( *ppRet );
+ *ppRet = 0;
+ }
+ if (pContext && pTypeName)
+ {
+ try
+ {
+ OUString const & rTypeName = * reinterpret_cast< OUString const * >( &pTypeName );
+ Reference< XTypeDescription > xTD;
+ if (reinterpret_cast< container::XHierarchicalNameAccess * >( pContext )->getByHierarchicalName(
+ rTypeName ) >>= xTD)
+ {
+ *ppRet = createCTD( xTD );
+ }
+ }
+ catch (...)
+ {
+ }
+ }
+#ifdef DEBUG
+ if (! *ppRet)
+ {
+ OString aTypeName( OUStringToOString( pTypeName, RTL_TEXTENCODING_ASCII_US ) );
+ OSL_TRACE( "### typelib type not accessable: %s\n", aTypeName.getStr() );
+ }
+#endif
+ }
+}
+}
+
+//==================================================================================================
+class EventListenerImpl
+ : public WeakImplHelper1< lang::XEventListener >
+{
+ Reference< container::XHierarchicalNameAccess > m_xTDMgr;
+
+public:
+ inline EventListenerImpl(
+ Reference< container::XHierarchicalNameAccess > const & xTDMgr )
+ SAL_THROW( () )
+ : m_xTDMgr( xTDMgr )
+ {}
+
+ // XEventListener
+ virtual void SAL_CALL disposing( lang::EventObject const & rEvt )
+ throw (RuntimeException);
+};
+//__________________________________________________________________________________________________
+void EventListenerImpl::disposing( lang::EventObject const & rEvt )
+ throw (RuntimeException)
+{
+ OSL_ASSERT( rEvt.Source == m_xTDMgr );
+ // deregister of c typelib callback
+ ::typelib_typedescription_revokeCallback( m_xTDMgr.get(), typelib_callback );
+}
+
+//==================================================================================================
+sal_Bool SAL_CALL installTypeDescriptionManager(
+ Reference< container::XHierarchicalNameAccess > const & xTDMgr )
+ SAL_THROW( () )
+{
+ Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
+ if (xComp.is())
+ {
+ xComp->addEventListener( new EventListenerImpl( xTDMgr ) );
+ // register c typelib callback
+ ::typelib_typedescription_registerCallback( xTDMgr.get(), typelib_callback );
+ return sal_True;
+ }
+ return sal_False;
+}
+
+} // end namespace cppu