Class ServiceManager

  • All Implemented Interfaces:
    com.sun.star.container.XContentEnumerationAccess, com.sun.star.container.XElementAccess, com.sun.star.container.XEnumerationAccess, com.sun.star.container.XSet, com.sun.star.lang.XComponent, com.sun.star.lang.XMultiComponentFactory, com.sun.star.lang.XMultiServiceFactory, com.sun.star.lang.XServiceInfo, com.sun.star.uno.XInterface

    public class ServiceManager
    extends java.lang.Object
    implements com.sun.star.lang.XMultiServiceFactory, com.sun.star.lang.XMultiComponentFactory, com.sun.star.container.XSet, com.sun.star.container.XContentEnumerationAccess, com.sun.star.lang.XComponent, com.sun.star.lang.XServiceInfo
    The ServiceManager class is an implementation of the ServiceManagerthe central class needed for implementing or using UNO components in Java.

    The Methods queryInterface and isSame delegate calls to the implementing objects and are used instead of casts and identity comparisons.

    Since:
    UDK1.0
    See Also:
    XMultiServiceFactory, XSet, XContentEnumerationAccess, XComponent, XServiceInfo
    • Field Summary

      • Fields inherited from interface com.sun.star.lang.XComponent

        UNOTYPEINFO
      • Fields inherited from interface com.sun.star.container.XContentEnumerationAccess

        UNOTYPEINFO
      • Fields inherited from interface com.sun.star.lang.XMultiComponentFactory

        UNOTYPEINFO
      • Fields inherited from interface com.sun.star.lang.XMultiServiceFactory

        UNOTYPEINFO
      • Fields inherited from interface com.sun.star.lang.XServiceInfo

        UNOTYPEINFO
      • Fields inherited from interface com.sun.star.container.XSet

        UNOTYPEINFO
    • Constructor Summary

      Constructors 
      Constructor Description
      ServiceManager()
      Creates a new instance of the ServiceManager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addEventListener​(com.sun.star.lang.XEventListener xListener)
      Adds a new EventListener.
      com.sun.star.container.XEnumeration createContentEnumeration​(java.lang.String serviceName)
      Provides an enumeration of all factories for a specified service.
      com.sun.star.container.XEnumeration createEnumeration()
      Provides an enumeration of all registered services.
      java.lang.Object createInstance​(java.lang.String serviceSpecifier)
      Creates a new instance of a specified service.
      java.lang.Object createInstanceWithArguments​(java.lang.String serviceSpecifier, java.lang.Object[] args)
      Creates a new instance of a specified service with the given parameters.
      java.lang.Object createInstanceWithArgumentsAndContext​(java.lang.String rServiceSpecifier, java.lang.Object[] rArguments, com.sun.star.uno.XComponentContext xContext)
      Create a service instance with given context and arguments.
      java.lang.Object createInstanceWithContext​(java.lang.String rServiceSpecifier, com.sun.star.uno.XComponentContext xContext)
      Create a service instance with given context.
      void dispose()
      Removes all listeners from the ServiceManager and clears the list of the services.
      java.lang.String[] getAvailableServiceNames()
      Supplies a list of all available services names.
      Type getElementType()
      Provides the UNO type of the ServiceManager
      java.lang.String getImplementationName()
      Returns the implementation name of the ServiceManager component.
      java.lang.String[] getSupportedServiceNames()
      Supplies list of all supported services.
      boolean has​(java.lang.Object object)
      Checks if a component is registered at the ServiceManager.
      boolean hasElements()
      Checks if the any components are registered.
      void insert​(java.lang.Object object)
      Adds a SingleServiceFactory to the ServiceManager.
      void remove​(java.lang.Object object)
      Removes a SingleServiceFactory from the ServiceManager.
      void removeEventListener​(com.sun.star.lang.XEventListener xListener)
      Removes a EventListener from the ServiceManager.
      void setDefaultContext​(com.sun.star.uno.XComponentContext context)  
      boolean supportsService​(java.lang.String serviceName)
      Checks if the ServiceManager supports a service.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ServiceManager

        public ServiceManager()
        Creates a new instance of the ServiceManager.
    • Method Detail

      • setDefaultContext

        public void setDefaultContext​(com.sun.star.uno.XComponentContext context)
      • createInstance

        public java.lang.Object createInstance​(java.lang.String serviceSpecifier)
                                        throws com.sun.star.uno.Exception,
                                               com.sun.star.uno.RuntimeException
        Creates a new instance of a specified service.

        Therefore the associated factory of the service is looked up and used to instantiate a new component.

        Specified by:
        createInstance in interface com.sun.star.lang.XMultiServiceFactory
        Parameters:
        serviceSpecifier - indicates the service or component name.
        Returns:
        newly created component.
        Throws:
        com.sun.star.uno.Exception
        com.sun.star.uno.RuntimeException
        See Also:
        XMultiServiceFactory
      • createInstanceWithArguments

        public java.lang.Object createInstanceWithArguments​(java.lang.String serviceSpecifier,
                                                            java.lang.Object[] args)
                                                     throws com.sun.star.uno.Exception,
                                                            com.sun.star.uno.RuntimeException
        Creates a new instance of a specified service with the given parameters.

        Therefore the associated factory of the service is looked up and used to instantiate a new component.

        Specified by:
        createInstanceWithArguments in interface com.sun.star.lang.XMultiServiceFactory
        Parameters:
        serviceSpecifier - indicates the service or component name.
        Returns:
        newly created component.
        Throws:
        com.sun.star.uno.Exception
        com.sun.star.uno.RuntimeException
        See Also:
        XMultiServiceFactory
      • getAvailableServiceNames

        public java.lang.String[] getAvailableServiceNames()
                                                    throws com.sun.star.uno.RuntimeException
        Supplies a list of all available services names.
        Specified by:
        getAvailableServiceNames in interface com.sun.star.container.XContentEnumerationAccess
        Specified by:
        getAvailableServiceNames in interface com.sun.star.lang.XMultiComponentFactory
        Specified by:
        getAvailableServiceNames in interface com.sun.star.lang.XMultiServiceFactory
        Returns:
        list of Strings of all service names.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XContentEnumerationAccess
      • createInstanceWithContext

        public java.lang.Object createInstanceWithContext​(java.lang.String rServiceSpecifier,
                                                          com.sun.star.uno.XComponentContext xContext)
                                                   throws com.sun.star.uno.Exception
        Create a service instance with given context.
        Specified by:
        createInstanceWithContext in interface com.sun.star.lang.XMultiComponentFactory
        Parameters:
        rServiceSpecifier - service name.
        xContext - context.
        Returns:
        service instance.
        Throws:
        com.sun.star.uno.Exception
      • createInstanceWithArgumentsAndContext

        public java.lang.Object createInstanceWithArgumentsAndContext​(java.lang.String rServiceSpecifier,
                                                                      java.lang.Object[] rArguments,
                                                                      com.sun.star.uno.XComponentContext xContext)
                                                               throws com.sun.star.uno.Exception
        Create a service instance with given context and arguments.
        Specified by:
        createInstanceWithArgumentsAndContext in interface com.sun.star.lang.XMultiComponentFactory
        Parameters:
        rServiceSpecifier - service name.
        rArguments - arguments.
        xContext - context.
        Returns:
        service instance.
        Throws:
        com.sun.star.uno.Exception
      • dispose

        public void dispose()
                     throws com.sun.star.uno.RuntimeException
        Removes all listeners from the ServiceManager and clears the list of the services.
        Specified by:
        dispose in interface com.sun.star.lang.XComponent
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XComponent
      • addEventListener

        public void addEventListener​(com.sun.star.lang.XEventListener xListener)
                              throws com.sun.star.uno.RuntimeException
        Adds a new EventListener.

        The listener is notified when a service is added (removed) to (from) the ServiceManager.

        If the listener is already registered a com.sun.star.uno.RuntimeException will be thrown.

        Specified by:
        addEventListener in interface com.sun.star.lang.XComponent
        Parameters:
        xListener - the new listener which should been added.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XComponent
      • removeEventListener

        public void removeEventListener​(com.sun.star.lang.XEventListener xListener)
                                 throws com.sun.star.uno.RuntimeException
        Removes a EventListener from the ServiceManager.

        If the listener is not registered a com.sun.star.uno.RuntimeException will be thrown.

        Specified by:
        removeEventListener in interface com.sun.star.lang.XComponent
        Parameters:
        xListener - the new listener which should been removed.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XComponent
      • has

        public boolean has​(java.lang.Object object)
                    throws com.sun.star.uno.RuntimeException
        Checks if a component is registered at the ServiceManager.

        The given object argument must provide a XServiceInfo interface.

        Specified by:
        has in interface com.sun.star.container.XSet
        Parameters:
        object - object which provides a XServiceInfo interface.
        Returns:
        true if the component is registered otherwise false.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XSet, XServiceInfo
      • insert

        public void insert​(java.lang.Object object)
                    throws com.sun.star.lang.IllegalArgumentException,
                           com.sun.star.container.ElementExistException,
                           com.sun.star.uno.RuntimeException
        Adds a SingleServiceFactory to the ServiceManager.
        Specified by:
        insert in interface com.sun.star.container.XSet
        Parameters:
        object - factory which should be added.
        Throws:
        com.sun.star.lang.IllegalArgumentException
        com.sun.star.container.ElementExistException
        com.sun.star.uno.RuntimeException
        See Also:
        XSet, XSingleServiceFactory
      • remove

        public void remove​(java.lang.Object object)
                    throws com.sun.star.lang.IllegalArgumentException,
                           com.sun.star.container.NoSuchElementException,
                           com.sun.star.uno.RuntimeException
        Removes a SingleServiceFactory from the ServiceManager.
        Specified by:
        remove in interface com.sun.star.container.XSet
        Parameters:
        object - factory which should be removed.
        Throws:
        com.sun.star.lang.IllegalArgumentException
        com.sun.star.container.NoSuchElementException
        com.sun.star.uno.RuntimeException
        See Also:
        XSet, XSingleServiceFactory
      • createEnumeration

        public com.sun.star.container.XEnumeration createEnumeration()
                                                              throws com.sun.star.uno.RuntimeException
        Provides an enumeration of all registered services.
        Specified by:
        createEnumeration in interface com.sun.star.container.XEnumerationAccess
        Returns:
        an enumeration of all available services.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XEnumerationAccess
      • getElementType

        public Type getElementType()
                            throws com.sun.star.uno.RuntimeException
        Provides the UNO type of the ServiceManager
        Specified by:
        getElementType in interface com.sun.star.container.XElementAccess
        Returns:
        the UNO type of the ServiceManager.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XElementAccess, TypeClass
      • hasElements

        public boolean hasElements()
        Checks if the any components are registered.
        Specified by:
        hasElements in interface com.sun.star.container.XElementAccess
        Returns:
        true - if the list of the registered components is not empty - otherwise false.
        See Also:
        XElementAccess
      • createContentEnumeration

        public com.sun.star.container.XEnumeration createContentEnumeration​(java.lang.String serviceName)
                                                                     throws com.sun.star.uno.RuntimeException
        Provides an enumeration of all factories for a specified service.
        Specified by:
        createContentEnumeration in interface com.sun.star.container.XContentEnumerationAccess
        Parameters:
        serviceName - name of the requested service.
        Returns:
        an enumeration for service name.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XContentEnumerationAccess
      • getImplementationName

        public java.lang.String getImplementationName()
                                               throws com.sun.star.uno.RuntimeException
        Returns the implementation name of the ServiceManager component.
        Specified by:
        getImplementationName in interface com.sun.star.lang.XServiceInfo
        Returns:
        the class name of the ServiceManager.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XServiceInfo
      • supportsService

        public boolean supportsService​(java.lang.String serviceName)
                                throws com.sun.star.uno.RuntimeException
        Checks if the ServiceManager supports a service.
        Specified by:
        supportsService in interface com.sun.star.lang.XServiceInfo
        Parameters:
        serviceName - service name which should be checked.
        Returns:
        true if the service is supported - otherwise false.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XServiceInfo
      • getSupportedServiceNames

        public java.lang.String[] getSupportedServiceNames()
                                                    throws com.sun.star.uno.RuntimeException
        Supplies list of all supported services.
        Specified by:
        getSupportedServiceNames in interface com.sun.star.lang.XServiceInfo
        Returns:
        a list of all supported service names.
        Throws:
        com.sun.star.uno.RuntimeException
        See Also:
        XServiceInfo