You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by da...@apache.org on 2025/06/06 03:46:31 UTC

(openoffice) branch trunk updated: Port main/sax component_getFactory() to the component context API.

This is an automated email from the ASF dual-hosted git repository.

damjan pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/openoffice.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 85ec52e3ec Port main/sax component_getFactory() to the component context API.
85ec52e3ec is described below

commit 85ec52e3ec50dfd34a97af98ddb418c203742409
Author: Damjan Jovanovic <da...@apache.org>
AuthorDate: Fri Jun 6 05:45:43 2025 +0200

    Port main/sax component_getFactory() to the component context API.
    
    Patch by: me
---
 main/sax/source/expatwrap/factory.hxx     |  2 +-
 main/sax/source/expatwrap/sax_expat.cxx   | 77 ++++++++++++++-----------------
 main/sax/source/expatwrap/saxwriter.cxx   |  2 +-
 main/sax/source/fastparser/facreg.cxx     | 60 +++++++++++-------------
 main/sax/source/fastparser/fastparser.cxx |  7 ++-
 main/sax/source/fastparser/fastparser.hxx |  1 +
 main/sax/source/tools/fastserializer.cxx  |  2 +-
 7 files changed, 71 insertions(+), 80 deletions(-)

diff --git a/main/sax/source/expatwrap/factory.hxx b/main/sax/source/expatwrap/factory.hxx
index f92c994d8e..98a2765727 100644
--- a/main/sax/source/expatwrap/factory.hxx
+++ b/main/sax/source/expatwrap/factory.hxx
@@ -22,7 +22,7 @@
 
 namespace sax_expatwrap {
 Reference< XInterface > SAL_CALL SaxWriter_CreateInstance(
-	const Reference< XMultiServiceFactory > & rSMgr ) throw (Exception);
+	const Reference< XComponentContext > & rCtx ) throw (Exception);
 OUString SaxWriter_getServiceName() throw();
 OUString SaxWriter_getImplementationName() throw();
 Sequence< OUString > 	SaxWriter_getSupportedServiceNames(void) throw();
diff --git a/main/sax/source/expatwrap/sax_expat.cxx b/main/sax/source/expatwrap/sax_expat.cxx
index d37fecdc23..88beb4e28a 100644
--- a/main/sax/source/expatwrap/sax_expat.cxx
+++ b/main/sax/source/expatwrap/sax_expat.cxx
@@ -38,6 +38,7 @@
 #include <cppuhelper/weak.hxx>
 #include <cppuhelper/implbase1.hxx>
 #include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implementationentry.hxx>
 
 #include <expat.h>
 
@@ -133,8 +134,6 @@ OUString XmlChar2OUString( const XML_Char *p )
 	}\
 	((void)0)
 
-#define IMPLEMENTATION_NAME	"com.sun.star.comp.extensions.xml.sax.ParserExpat"
-#define SERVICE_NAME		"com.sun.star.xml.sax.Parser"
 
 class SaxExpatParser_Impl;
 
@@ -154,6 +153,7 @@ public:
 public:
 
 	// The implementation details
+    static OUString					getImplementationName_Static(void) throw();
     static Sequence< OUString > 	getSupportedServiceNames_Static(void) throw ();
 
 public:
@@ -189,19 +189,22 @@ private:
 // the extern interface 
 //---------------------------------------
 Reference< XInterface > SAL_CALL SaxExpatParser_CreateInstance(
-	const Reference< XMultiServiceFactory  >  & ) throw(Exception)
+	Reference< XComponentContext > const & ) throw(Exception)
 {	
 	SaxExpatParser *p = new SaxExpatParser;
 
 	return Reference< XInterface > ( (OWeakObject * ) p );
 }
 
-
+OUString SaxExpatParser::getImplementationName_Static() throw ()
+{
+	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.xml.sax.ParserExpat" ) );
+}
 
 Sequence< OUString > 	SaxExpatParser::getSupportedServiceNames_Static(void) throw ()
 {
 	Sequence<OUString> aRet(1);
-	aRet.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME) );
+	aRet.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Parser" ) );
 	return aRet;
 }
 
@@ -591,7 +594,7 @@ void SaxExpatParser::setLocale( const Locale & locale )	throw (RuntimeException)
 // XServiceInfo
 OUString SaxExpatParser::getImplementationName() throw ()
 {
-    return OUString::createFromAscii( IMPLEMENTATION_NAME );
+    return getImplementationName_Static();
 }
 
 // XServiceInfo
@@ -610,10 +613,7 @@ sal_Bool SaxExpatParser::supportsService(const OUString& ServiceName) throw ()
 // XServiceInfo
 Sequence< OUString > SaxExpatParser::getSupportedServiceNames(void) throw ()
 {
-    
-    Sequence<OUString> seq(1);
-    seq.getArray()[0] = OUString::createFromAscii( SERVICE_NAME );
-    return seq;
+    return getSupportedServiceNames_Static();
 }
 
 
@@ -1021,6 +1021,28 @@ void SaxExpatParser_Impl::callbackEndCDATA( void *pvThis )
 }
 using namespace sax_expatwrap;
 
+
+static struct ::cppu::ImplementationEntry g_component_entries[] =
+{
+	{
+		SaxExpatParser_CreateInstance,
+		SaxExpatParser::getImplementationName_Static,
+		SaxExpatParser::getSupportedServiceNames_Static,
+		::cppu::createSingleComponentFactory,
+		0,
+		0
+	},
+	{
+		SaxWriter_CreateInstance,
+		SaxWriter_getImplementationName,
+		SaxWriter_getSupportedServiceNames,
+		::cppu::createSingleComponentFactory,
+		0,
+		0
+	},
+	{ 0, 0, 0, 0, 0, 0 }
+};
+
 extern "C" 
 {
 
@@ -1031,40 +1053,9 @@ SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
 }
 
 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
-	const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
+	const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
 {
-	void * pRet = 0;
-	
-	if (pServiceManager )
-	{
-		Reference< XSingleServiceFactory > xRet;
-		Reference< XMultiServiceFactory > xSMgr =
-			reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
-		
-		OUString aImplementationName = OUString::createFromAscii( pImplName );
-		
-		if (aImplementationName ==
-			OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATION_NAME  ) ) )
-		{
-			xRet = createSingleFactory( xSMgr, aImplementationName,
-										SaxExpatParser_CreateInstance,
-										SaxExpatParser::getSupportedServiceNames_Static() );
-		}
-		else if ( aImplementationName == SaxWriter_getImplementationName() )
-		{
-			xRet = createSingleFactory( xSMgr, aImplementationName,
-										SaxWriter_CreateInstance,
-										SaxWriter_getSupportedServiceNames() );
-		}
-
-		if (xRet.is())
-		{
-			xRet->acquire();
-			pRet = xRet.get();
-		}
-	}
-	
-	return pRet;
+	return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, g_component_entries );
 }
 		
 
diff --git a/main/sax/source/expatwrap/saxwriter.cxx b/main/sax/source/expatwrap/saxwriter.cxx
index a7a87cf630..5b472483c6 100644
--- a/main/sax/source/expatwrap/saxwriter.cxx
+++ b/main/sax/source/expatwrap/saxwriter.cxx
@@ -1016,7 +1016,7 @@ private:
 // the extern interface
 //---------------------------------------
 Reference < XInterface > SAL_CALL SaxWriter_CreateInstance(
-	const Reference < XMultiServiceFactory >  &  )
+	const Reference < XComponentContext >  &  )
 	throw (Exception)
 {
 	SAXWriter *p = new SAXWriter;
diff --git a/main/sax/source/fastparser/facreg.cxx b/main/sax/source/fastparser/facreg.cxx
index 31a1cbfdc4..0fdf329bc8 100644
--- a/main/sax/source/fastparser/facreg.cxx
+++ b/main/sax/source/fastparser/facreg.cxx
@@ -22,6 +22,7 @@
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/weak.hxx>
 #include <cppuhelper/implbase2.hxx>
+#include <cppuhelper/implementationentry.hxx>
 
 #include "../tools/fastserializer.hxx"
 #include "fastparser.hxx"
@@ -39,17 +40,39 @@ namespace sax_fastparser
 //--------------------------------------
 // the extern interface 
 //---------------------------------------
-Reference< XInterface > SAL_CALL FastSaxParser_CreateInstance( const Reference< XMultiServiceFactory  >  & ) throw(Exception)
+Reference< XInterface > SAL_CALL FastSaxParser_CreateInstance( const Reference< XComponentContext >  & ) throw(Exception)
 {	
 	FastSaxParser *p = new FastSaxParser;
 	return Reference< XInterface > ( (OWeakObject * ) p );
 }
 
-Reference< XInterface > SAL_CALL FastSaxSerializer_CreateInstance( const Reference< XMultiServiceFactory  >  & ) throw(Exception)
+Reference< XInterface > SAL_CALL FastSaxSerializer_CreateInstance( const Reference< XComponentContext >  & ) throw(Exception)
 {	
 	FastSaxSerializer *p = new FastSaxSerializer;
 	return Reference< XInterface > ( (OWeakObject * ) p );
 }
+
+struct ::cppu::ImplementationEntry g_component_entries[] =
+{
+	{
+		FastSaxParser_CreateInstance,
+		FastSaxParser::getImplementationName_Static,
+		FastSaxParser::getSupportedServiceNames_Static,
+		::cppu::createSingleComponentFactory,
+		0,
+		0
+	},
+	{
+		FastSaxSerializer_CreateInstance,
+		FastSaxSerializer::getImplementationName_Static,
+		FastSaxSerializer::getSupportedServiceNames_Static,
+		::cppu::createSingleComponentFactory,
+		0,
+		0
+	},
+	{ 0, 0, 0, 0, 0, 0 }
+};
+
 }
 
 extern "C"
@@ -61,38 +84,9 @@ SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
 	*ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
 }
 
-SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ )
+SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
 {
-	void * pRet = 0;
-
-	if (pServiceManager )
-	{
-		Reference< XSingleServiceFactory > xRet;
-		Reference< XMultiServiceFactory > xSMgr( reinterpret_cast< XMultiServiceFactory * > ( pServiceManager ) );
-
-		OUString aImplementationName( OUString::createFromAscii( pImplName ) );
-		
-		if (aImplementationName == OUString( RTL_CONSTASCII_USTRINGPARAM( PARSER_IMPLEMENTATION_NAME  ) ) )
-		{
-			xRet = createSingleFactory( xSMgr, aImplementationName,
-										FastSaxParser_CreateInstance,
-										FastSaxParser::getSupportedServiceNames_Static() );
-		}
-		else if (aImplementationName == OUString( RTL_CONSTASCII_USTRINGPARAM( SERIALIZER_IMPLEMENTATION_NAME  ) ) )
-		{
-			xRet = createSingleFactory( xSMgr, aImplementationName,
-										FastSaxSerializer_CreateInstance,
-										FastSaxSerializer::getSupportedServiceNames_Static() );
-		}
-
-		if (xRet.is())
-		{
-			xRet->acquire();
-			pRet = xRet.get();
-		}
-	}
-
-	return pRet;
+	return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, g_component_entries );
 }
 
 
diff --git a/main/sax/source/fastparser/fastparser.cxx b/main/sax/source/fastparser/fastparser.cxx
index c775ef4983..c566f5178a 100644
--- a/main/sax/source/fastparser/fastparser.cxx
+++ b/main/sax/source/fastparser/fastparser.cxx
@@ -539,6 +539,11 @@ void FastSaxParser::setLocale( const Locale & Locale ) throw (RuntimeException)
 	maData.maLocale = Locale;
 }
 
+OUString FastSaxParser::getImplementationName_Static(void)
+{
+    return OUString::createFromAscii( PARSER_IMPLEMENTATION_NAME );
+}
+
 Sequence< OUString > FastSaxParser::getSupportedServiceNames_Static(void)
 {
 	Sequence<OUString> aRet(1);
@@ -549,7 +554,7 @@ Sequence< OUString > FastSaxParser::getSupportedServiceNames_Static(void)
 // XServiceInfo
 OUString FastSaxParser::getImplementationName() throw (RuntimeException)
 {
-    return OUString::createFromAscii( PARSER_IMPLEMENTATION_NAME );
+    return getImplementationName_Static();
 }
 
 // XServiceInfo
diff --git a/main/sax/source/fastparser/fastparser.hxx b/main/sax/source/fastparser/fastparser.hxx
index 909126e184..3876867491 100644
--- a/main/sax/source/fastparser/fastparser.hxx
+++ b/main/sax/source/fastparser/fastparser.hxx
@@ -100,6 +100,7 @@ public:
     virtual ~FastSaxParser();
 
     // The implementation details
+    static ::rtl::OUString getImplementationName_Static(void);
     static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static(void);
 
     // XFastParser
diff --git a/main/sax/source/tools/fastserializer.cxx b/main/sax/source/tools/fastserializer.cxx
index a0d58e0e28..5d0a52c62e 100644
--- a/main/sax/source/tools/fastserializer.cxx
+++ b/main/sax/source/tools/fastserializer.cxx
@@ -278,7 +278,7 @@ namespace sax_fastparser {
 	// XServiceInfo
 	OUString FastSaxSerializer::getImplementationName() throw (RuntimeException)
 	{
-		return OUString::createFromAscii( SERIALIZER_IMPLEMENTATION_NAME );
+		return getImplementationName_Static();
 	}
 
 	// XServiceInfo