odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java | 29 ++++------ odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java | 22 ++----- odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java | 22 ++----- odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java | 22 ++----- 4 files changed, 38 insertions(+), 57 deletions(-)
New commits: commit dc795cbd2dcb50e555945a91925616c7b3e58ee9 Author: Stephan Bergmann <sberg...@redhat.com> Date: Fri Jun 20 18:26:11 2014 +0200 Make Linguistic SDK example use __getComponentFactory ...instead of legacy __getServiceFactory. This fixes a subtle bug: When these Java extensions are live-deployed, they are offloaded to an additional uno process. Their __getServiceFactory methods were called with the uno process (component context's) service manager, which they stored away for later use in OneInstanceFactory.createInstance. So even if later on an instance was created with the main LO process's component context, the uno process's component context would be used to instantiate the (C++) com.sun.star.linguistic2.LinguProperties service (in the uno process!), and that happens to internally use comphelper::getProcessServiceFactory, which would be null in the uno process, comphelper::getProcessServiceFactory comphelper::getProcessComponentContext (anonymous namespace)::getConfigurationProvider utl::ConfigManager::acquireTree utl::ConfigManager::addConfigItem utl::ConfigItem::ConfigItem SvtLinguConfigItem::SvtLinguConfigItem SvtLinguConfig::GetConfigItem SvtLinguConfig::GetConfigItem SvtLinguConfig::GetProperty LinguProps::getPropertyValue gcc3::callVirtualMethod ... Change-Id: Ib6f5a5dd6d0adbbe14d60aaff3a8b6ba24235d11 diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java index 2a33ecb..63c2718 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java @@ -32,11 +32,11 @@ * *************************************************************************/ -import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XInitialization; -import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.beans.XPropertySet; +import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XInterface; import com.sun.star.uno.UnoRuntime; @@ -49,32 +49,29 @@ import java.lang.reflect.Constructor; public class OneInstanceFactory implements - XSingleServiceFactory, + XSingleComponentFactory, XServiceInfo { Class aMyClass; String aSvcImplName; String[] aSupportedSvcNames; XInterface xInstantiatedService; - XMultiServiceFactory xMultiFactory; public OneInstanceFactory( Class aMyClass, String aSvcImplName, - String[] aSupportedSvcNames, - XMultiServiceFactory xMultiFactory ) + String[] aSupportedSvcNames ) { this.aMyClass = aMyClass; this.aSvcImplName = aSvcImplName; this.aSupportedSvcNames = aSupportedSvcNames; - this.xMultiFactory = xMultiFactory; xInstantiatedService = null; } - // XSingleServiceFactory + // XSingleComponentFactory - public Object createInstance() + public Object createInstanceWithContext( XComponentContext context ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException { @@ -91,15 +88,17 @@ public class OneInstanceFactory implements //!! workaround for services not always being created //!! via 'createInstanceWithArguments' XInitialization xIni = UnoRuntime.queryInterface( - XInitialization.class, createInstance()); + XInitialization.class, createInstanceWithContext(context)); if (xIni != null) { Object[] aArguments = new Object[]{ null, null }; - if (xMultiFactory != null) + if (context != null) { XPropertySet xPropSet = UnoRuntime.queryInterface( - XPropertySet.class , xMultiFactory.createInstance( - "com.sun.star.linguistic2.LinguProperties" ) ); + XPropertySet.class, + context.getServiceManager().createInstanceWithContext( + "com.sun.star.linguistic2.LinguProperties", + context ) ); aArguments[0] = xPropSet; } xIni.initialize( aArguments ); @@ -108,14 +107,14 @@ public class OneInstanceFactory implements return xInstantiatedService; } - public Object createInstanceWithArguments( Object[] aArguments ) + public Object createInstanceWithArgumentsAndContext( Object[] aArguments, XComponentContext context ) throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException { if (xInstantiatedService == null) { XInitialization xIni = UnoRuntime.queryInterface( - XInitialization.class, createInstance()); + XInitialization.class, createInstanceWithContext( context )); if (xIni != null) xIni.initialize( aArguments ); } diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java index ffa8358..f74c5a7 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java @@ -37,8 +37,7 @@ import com.sun.star.lib.uno.helper.ComponentBase; import com.sun.star.uno.UnoRuntime; // factories -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XSingleComponentFactory; // supported Interfaces import com.sun.star.linguistic2.XHyphenator; @@ -493,26 +492,21 @@ public class SampleHyphenator extends ComponentBase implements * Returns a factory for creating the service. * This method is called by the <code>JavaLoader</code> * <p> - * @return returns a <code>XSingleServiceFactory</code> for creating the component + * @return returns a <code>XComponentServiceFactory</code> for creating the component * @param implName the name of the implementation for which a service is desired - * @param multiFactory the service manager to be used if needed - * @param regKey the registryKey * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory( - String aImplName, - XMultiServiceFactory xMultiFactory, - com.sun.star.registry.XRegistryKey xRegKey ) + public static XSingleComponentFactory __getComponentFactory( + String aImplName ) { - XSingleServiceFactory xSingleServiceFactory = null; + XSingleComponentFactory xSingleComponentFactory = null; if( aImplName.equals( _aSvcImplName ) ) { - xSingleServiceFactory = new OneInstanceFactory( + xSingleComponentFactory = new OneInstanceFactory( SampleHyphenator.class, _aSvcImplName, - getSupportedServiceNames_Static(), - xMultiFactory ); + getSupportedServiceNames_Static() ); } - return xSingleServiceFactory; + return xSingleComponentFactory; } /** diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java index 00fbab8..7887fa0 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java @@ -37,8 +37,7 @@ import com.sun.star.lib.uno.helper.ComponentBase; import com.sun.star.uno.UnoRuntime; // factories -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XSingleComponentFactory; // supported Interfaces import com.sun.star.linguistic2.XSpellChecker; @@ -436,26 +435,21 @@ public class SampleSpellChecker extends ComponentBase implements * Returns a factory for creating the service. * This method is called by the <code>JavaLoader</code> * <p> - * @return returns a <code>XSingleServiceFactory</code> for creating the component + * @return returns a <code>XSingleComponentFactory</code> for creating the component * @param implName the name of the implementation for which a service is desired - * @param multiFactory the service manager to be used if needed - * @param regKey the registryKey * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory( - String aImplName, - XMultiServiceFactory xMultiFactory, - com.sun.star.registry.XRegistryKey xRegKey ) + public static XSingleComponentFactory __getComponentFactory( + String aImplName ) { - XSingleServiceFactory xSingleServiceFactory = null; + XSingleComponentFactory xSingleComponentFactory = null; if( aImplName.equals( _aSvcImplName ) ) { - xSingleServiceFactory = new OneInstanceFactory( + xSingleComponentFactory = new OneInstanceFactory( SampleSpellChecker.class, _aSvcImplName, - getSupportedServiceNames_Static(), - xMultiFactory ); + getSupportedServiceNames_Static() ); } - return xSingleServiceFactory; + return xSingleComponentFactory; } /** diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java index ee02953..5feb49b 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java @@ -37,8 +37,7 @@ import com.sun.star.lib.uno.helper.ComponentBase; import com.sun.star.uno.UnoRuntime; // factories -import com.sun.star.lang.XMultiServiceFactory; -import com.sun.star.lang.XSingleServiceFactory; +import com.sun.star.lang.XSingleComponentFactory; // supported Interfaces import com.sun.star.linguistic2.XThesaurus; @@ -272,26 +271,21 @@ public class SampleThesaurus extends ComponentBase implements * Returns a factory for creating the service. * This method is called by the <code>JavaLoader</code> * <p> - * @return returns a <code>XSingleServiceFactory</code> for creating the component + * @return returns a <code>XSingleComponentFactory</code> for creating the component * @param implName the name of the implementation for which a service is desired - * @param multiFactory the service manager to be used if needed - * @param regKey the registryKey * @see com.sun.star.comp.loader.JavaLoader */ - public static XSingleServiceFactory __getServiceFactory( - String aImplName, - XMultiServiceFactory xMultiFactory, - com.sun.star.registry.XRegistryKey xRegKey ) + public static XSingleComponentFactory __getComponentFactory( + String aImplName ) { - XSingleServiceFactory xSingleServiceFactory = null; + XSingleComponentFactory xSingleComponentFactory = null; if( aImplName.equals( _aSvcImplName ) ) { - xSingleServiceFactory = new OneInstanceFactory( + xSingleComponentFactory = new OneInstanceFactory( SampleThesaurus.class, _aSvcImplName, - getSupportedServiceNames_Static(), - xMultiFactory ); + getSupportedServiceNames_Static() ); } - return xSingleServiceFactory; + return xSingleComponentFactory; } /** _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits