Difference between revisions of "Documentation/DevGuide/ProUNO/Singletons"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Professional UNO)
Line 18: Line 18:
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Professional UNO]]
+
 
 +
[[Category:Documentation/Developers Guide/Professional UNO]]

Revision as of 15:17, 8 May 2008



Singletons are used to specify named objects where exactly one instance can exist in the life of a UNO component context. A singleton references one interface type and specifies that the only existing instance of this singleton can be reached over the component context using the name of the singleton. If no instance of the singleton exists, the component context will instantiate a new one. An example of such a new-style singleton is

  module com { module sun { module star { module deployment {
  singleton thePackageManagerFactory: XPackageManagerFactory;
  }; }; }; };

The various language bindings offer language-specific ways to obtain the instance of a new-style singleton, given a component context. For example, in Java and C++ there is a static method (resp. function) named get, that takes as its only argument an XComponentContext and returns the (appropriately typed) singleton instance. If the instance cannot be obtained, a com.sun.star.uno.DeploymentException is thrown.

There are also old-style singletons, which reference (old-style) services instead of interfaces. However, for old-style services, the language bindings offer no get functionality.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools