From 57a14ea0bed679c4b120c0371ab5316faf7c883f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 25 Apr 2013 13:58:29 +0200 Subject: [PATCH] Clean up Java ServiceManager bootstrapping ...and remove the unused feature of initializing it with an obsolete XSimpleRegistry. Change-Id: I333dae51f67c16da3e6822ba81e4b8ca125188a5 --- .../com/sun/star/comp/helper/Bootstrap.java | 25 +- .../comp/servicemanager/ServiceManager.java | 272 +----------------- 2 files changed, 8 insertions(+), 289 deletions(-) diff --git a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java index 2087aeca5689..989e283853b0 100644 --- a/javaunohelper/com/sun/star/comp/helper/Bootstrap.java +++ b/javaunohelper/com/sun/star/comp/helper/Bootstrap.java @@ -23,11 +23,11 @@ package com.sun.star.comp.helper; import com.sun.star.bridge.UnoUrlResolver; import com.sun.star.bridge.XUnoUrlResolver; import com.sun.star.comp.loader.JavaLoader; +import com.sun.star.comp.servicemanager.ServiceManager; import com.sun.star.container.XSet; import com.sun.star.lang.XInitialization; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiComponentFactory; -import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lib.util.NativeLibraryLoader; import com.sun.star.loader.XImplementationLoader; import com.sun.star.uno.UnoRuntime; @@ -98,19 +98,10 @@ public class Bootstrap { static public XComponentContext createInitialComponentContext( Hashtable context_entries ) throws Exception { + ServiceManager xSMgr = new ServiceManager(); + XImplementationLoader xImpLoader = UnoRuntime.queryInterface( XImplementationLoader.class, new JavaLoader() ); - - // Get the factory of the ServiceManager - XSingleComponentFactory smgr_fac = UnoRuntime.queryInterface( - XSingleComponentFactory.class, xImpLoader.activate( - "com.sun.star.comp.servicemanager.ServiceManager", null, null, null ) ); - - // Create an instance of the ServiceManager - XMultiComponentFactory xSMgr = UnoRuntime.queryInterface( - XMultiComponentFactory.class, smgr_fac.createInstanceWithContext( null ) ); - - // post init loader XInitialization xInit = UnoRuntime.queryInterface( XInitialization.class, xImpLoader ); Object[] args = new Object [] { xSMgr }; @@ -126,16 +117,10 @@ public class Bootstrap { // ... xxx todo: add standard entries XComponentContext xContext = new ComponentContext( context_entries, null ); - // post init smgr - xInit = UnoRuntime.queryInterface( - XInitialization.class, xSMgr ); - args = new Object [] { null, xContext }; // no registry, default context - xInit.initialize( args ); + xSMgr.setDefaultContext(xContext); XSet xSet = UnoRuntime.queryInterface( XSet.class, xSMgr ); - // insert the service manager - xSet.insert( smgr_fac ); - // and basic jurt factories + // insert basic jurt factories insertBasicFactories( xSet, xImpLoader ); return xContext; diff --git a/jurt/com/sun/star/comp/servicemanager/ServiceManager.java b/jurt/com/sun/star/comp/servicemanager/ServiceManager.java index a76120ac0ffa..dd595e77f6de 100644 --- a/jurt/com/sun/star/comp/servicemanager/ServiceManager.java +++ b/jurt/com/sun/star/comp/servicemanager/ServiceManager.java @@ -18,7 +18,6 @@ package com.sun.star.comp.servicemanager; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; @@ -27,15 +26,11 @@ import com.sun.star.container.XEnumeration; import com.sun.star.container.XSet; import com.sun.star.lang.XComponent; import com.sun.star.lang.XEventListener; -import com.sun.star.lang.XInitialization; import com.sun.star.lang.XMultiComponentFactory; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XServiceInfo; import com.sun.star.lang.XSingleComponentFactory; import com.sun.star.lang.XSingleServiceFactory; -import com.sun.star.loader.XImplementationLoader; -import com.sun.star.registry.XRegistryKey; -import com.sun.star.registry.XSimpleRegistry; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XComponentContext; @@ -52,7 +47,6 @@ import com.sun.star.uno.XComponentContext; * @see com.sun.star.container.XContentEnumerationAccess * @see com.sun.star.lang.XComponent * @see com.sun.star.lang.XServiceInfo - * @see com.sun.star.lang.XInitialization * @since UDK1.0 */ public class ServiceManager implements XMultiServiceFactory, @@ -60,8 +54,7 @@ public class ServiceManager implements XMultiServiceFactory, XSet, XContentEnumerationAccess, XComponent, - XServiceInfo, - XInitialization + XServiceInfo { private static final boolean DEBUG = false; @@ -71,8 +64,6 @@ public class ServiceManager implements XMultiServiceFactory, private static com.sun.star.uno.Type UNO_TYPE = null; - XImplementationLoader loader = null; - static String[] supportedServiceNames = { "com.sun.star.lang.MultiServiceFactory", "com.sun.star.lang.ServiceManager" @@ -93,159 +84,9 @@ public class ServiceManager implements XMultiServiceFactory, factoriesByServiceNames = new java.util.HashMap>(); m_xDefaultContext = null; } - /** - * Creates a new instance of the ServiceManager. - */ - public ServiceManager( XComponentContext xContext ) { - eventListener = new ArrayList(); - factoriesByImplNames = new java.util.HashMap(); - factoriesByServiceNames = new java.util.HashMap>(); - m_xDefaultContext = xContext; - } - /** - * Returns the service factory for the ServiceManager. If the given implementation name - * does not equal to the ServiceManagers class name null will be returned. - *

- * @return the factory for the ServiceManager. - * @param implName the implementation name of the of the service. - * Must be equal to com.sun.star.comp.servicemanager.ServicManager - * @param multiFactory refernce of the MultiServiceFactory. This parameter will be ignored. - * @param regKey the root key of the registry. This parameter will be ignored. - */ - public static XSingleServiceFactory getServiceFactory( String implName, - XMultiServiceFactory multiFactory, - XRegistryKey regKey) - { - if ( implName.equals(ServiceManager.class.getName()) ) - return new ServiceManagerFactory(); - - return null; - } - - - /** - * Supplies a Java component loader. The loader component must be enlisted at the ServiceManager before. - *

- * @return a new instance of the Java component loader - * @see com.sun.star.loader.Java - */ - private XImplementationLoader getLoader() - throws com.sun.star.uno.Exception, - com.sun.star.uno.RuntimeException - { - Object[] param = { this }; - DEBUG("make loader"); - Object loaderObj = createInstanceWithArgumentsAndContext( - "com.sun.star.loader.Java", param, m_xDefaultContext ); - - if (loaderObj == null) - throw new com.sun.star.uno.Exception("Can get an instance of com.sun.star.loader.Java"); - - return UnoRuntime.queryInterface( XImplementationLoader.class, loaderObj ); - } - - /** - * Registers a list of components given by their class names. - *

- * @param newImpls list of the components that should be registered, given by their class names. - * If any exception occurred during the registration, the process will be canceled. - * @see com.sun.star.container.XSet - */ - private void xaddFactories( String[] newImpls ) - throws com.sun.star.uno.Exception - { - for (int i=0; i clazz = Class.forName( newImpls[i] ); - - Class[] methodClassParam = { String.class, XMultiServiceFactory.class, XRegistryKey.class }; - java.lang.reflect.Method getFactoryMeth ; - try { - getFactoryMeth = clazz.getMethod("__getServiceFactory", methodClassParam); - } - catch (NoSuchMethodException noSuchMethodEx) { - getFactoryMeth = null; - } - catch (SecurityException securityExc) { - getFactoryMeth = null; - } - - if (getFactoryMeth == null) - getFactoryMeth = clazz.getMethod("getServiceFactory", methodClassParam); - - Object[] methodParams = { newImpls[i], this, null }; - newFactory = getFactoryMeth.invoke( clazz, methodParams ); - } - catch (NoSuchMethodException ex) {} - catch (SecurityException ex) {} - catch (ClassNotFoundException ex) {} - catch (IllegalAccessException ex) {} - catch (IllegalArgumentException ex) {} - catch (InvocationTargetException ex) {} - -//****************************** END DEPRECATED ****************************************** - } - - if ( newFactory == null ) - throw new com.sun.star.loader.CannotActivateFactoryException("Can not get factory for " + newImpls[i]); - - insert( newFactory ); - } // end of for ... - } - - /** - * The method is used to add components to the ServiceManager. The first argument indicates a SimpleRegistry. - * The components which should be added will be searched under the Implementations key in the registry. - *

- * @param args the first argument ( args[0] ) specifices the SimpleRegistry object - * @see com.sun.star.lang.XInitialization - * @see com.sun.star.lang.RegistryServiceManager - * @see com.sun.star.registry.XSimpleRegistry - */ - public void initialize( Object args[] ) - throws com.sun.star.uno.Exception, - com.sun.star.uno.RuntimeException { - XSimpleRegistry xSimpleRegistry ; - try { - xSimpleRegistry = (XSimpleRegistry) args[0]; - if (xSimpleRegistry != null) - { - XRegistryKey rootkey = xSimpleRegistry.getRootKey(); - - XRegistryKey implkey_xRegistryKey = rootkey.openKey("Implementations"); - if(implkey_xRegistryKey != null) { - XRegistryKey xRegistryKeys[] = implkey_xRegistryKey.openKeys(); - - for(int i = 0; i < xRegistryKeys.length; ++ i) { - xaddFactories(new String[]{xRegistryKeys[i].getStringValue()}); - } - } - } - - if (args.length > 1) - { - m_xDefaultContext = (XComponentContext)args[ 1 ]; - } - } - catch (ArrayIndexOutOfBoundsException e) - { - throw new com.sun.star.lang.IllegalArgumentException("Argument must not be null."); - } + public void setDefaultContext(XComponentContext context) { + m_xDefaultContext = context; } /** @@ -803,110 +644,3 @@ public class ServiceManager implements XMultiServiceFactory, } } } -/** - * The ServiceManagerFactory is the factory class for the - * ServiceManager. As all factories it implments the - * com.sun.star.lang.XSingleServiceFactory and the com.sun.star.lang.XServiceInfo - * interfaces. - *

- * @see com.sun.star.lang.XSingleServiceFactory - * @see com.sun.star.lang.XServiceInfo - * @since UDK1.0 -*/ -class ServiceManagerFactory implements XServiceInfo, XSingleComponentFactory, XSingleServiceFactory -{ - /** - * Creates a new instance of the ServiceManagerFactory. - */ - public ServiceManagerFactory() { - } - - /** - * Supplies the implementation name of the ServiceManager. - *

- * @return ServiceManager class name. - * @see com.sun.star.lang.XServiceInfo - */ - public String getImplementationName() - throws com.sun.star.uno.RuntimeException - { - return ServiceManager.class.getName(); - } - - /** - * Checks whether or not a service is supported. - *

- * @return true - if the service is supported, otherwise false. - * @param serviceName the name of the service that should be checked. - * @see com.sun.star.lang.XServiceInfo - */ - public boolean supportsService( String serviceName ) - throws com.sun.star.uno.RuntimeException - { - for ( int i=0; iServiceManager. - *

- * @return a list aof all supported service names. - * @see com.sun.star.lang.XServiceInfo - */ - public String[] getSupportedServiceNames() - throws com.sun.star.uno.RuntimeException - { - return ServiceManager.supportedServiceNames; - } - - /** - * Creates a new instance of the ServiceManager. - *

- * @return newly created ServiceManager object. - * @see com.sun.star.lang.XSingleServiceFactory - */ - public java.lang.Object createInstance() - throws com.sun.star.uno.Exception, - com.sun.star.uno.RuntimeException - { - return new ServiceManager(); - } - - /** - * Creates a new instance of the ServiceManager with arguments. - * At this time it always throws a com.sun.star.lang.NoSuchMethodException - * because there is no the ServiceManager has no constructor with - * arguments. - *

- * @return null - always throws an exception - * @param aArguments arguments for new instance. - * @see com.sun.star.lang.XSingleServiceFactory - */ - public java.lang.Object createInstanceWithArguments( java.lang.Object[] aArguments ) - throws com.sun.star.uno.Exception, - com.sun.star.uno.RuntimeException - { - throw new com.sun.star.lang.NoSuchMethodException("Constructor with arguments is not supported."); - } - - // XSingleComponentFactory impl - //______________________________________________________________________________________________ - public Object createInstanceWithContext( XComponentContext xContext ) - throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException - { - return new ServiceManager( xContext ); - } - //______________________________________________________________________________________________ - public Object createInstanceWithArgumentsAndContext( - Object aArguments [], XComponentContext xContext ) - throws com.sun.star.uno.Exception, com.sun.star.uno.RuntimeException - { - throw new com.sun.star.lang.NoSuchMethodException( - "ServiceManagerFactory.createInstanceWithArgumentsAndContext() not impl!" ); - } -} - -