Class ServiceManager

java.lang.Object
com.sun.star.comp.servicemanager.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 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
    Creates a new instance of the ServiceManager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addEventListener(com.sun.star.lang.XEventListener xListener)
    Adds a new EventListener.
    com.sun.star.container.XEnumeration
    Provides an enumeration of all factories for a specified service.
    com.sun.star.container.XEnumeration
    Provides an enumeration of all registered services.
    createInstance(String serviceSpecifier)
    Creates a new instance of a specified service.
    createInstanceWithArguments(String serviceSpecifier, Object[] args)
    Creates a new instance of a specified service with the given parameters.
    createInstanceWithArgumentsAndContext(String rServiceSpecifier, Object[] rArguments, com.sun.star.uno.XComponentContext xContext)
    Create a service instance with given context and arguments.
    createInstanceWithContext(String rServiceSpecifier, com.sun.star.uno.XComponentContext xContext)
    Create a service instance with given context.
    void
    Removes all listeners from the ServiceManager and clears the list of the services.
    Supplies a list of all available services names.
    Provides the UNO type of the ServiceManager
    Returns the implementation name of the ServiceManager component.
    Supplies list of all supported services.
    boolean
    has(Object object)
    Checks if a component is registered at the ServiceManager.
    boolean
    Checks if the any components are registered.
    void
    insert(Object object)
    Adds a SingleServiceFactory to the ServiceManager.
    void
    remove(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(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 Details

    • ServiceManager

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

    • setDefaultContext

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

      public Object createInstance(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 Object createInstanceWithArguments(String serviceSpecifier, 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 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 Object createInstanceWithContext(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 Object createInstanceWithArgumentsAndContext(String rServiceSpecifier, 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(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(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(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(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 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(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 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