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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
(2 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
{{DISPLAYTITLE:Singletons}}
 
{{DISPLAYTITLE:Singletons}}
 
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
 
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
  <source lang="idl">
+
<syntaxhighlight lang="idl">
 
   module com { module sun { module star { module deployment {
 
   module com { module sun { module star { module deployment {
 
   singleton thePackageManagerFactory: XPackageManagerFactory;
 
   singleton thePackageManagerFactory: XPackageManagerFactory;
 
   }; }; }; };
 
   }; }; }; };
  </source>
+
</syntaxhighlight>
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 <idls>com.sun.star.uno.XComponentContext</idls> and returns the (appropriately typed) singleton instance. If the instance cannot be obtained, a <idl>com.sun.star.uno.DeploymentException</idl> is thrown.
+
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 a <idls>com.sun.star.uno.XComponentContext</idls> and returns the (appropriately typed) singleton instance. If the instance cannot be obtained, a <idl>com.sun.star.uno.DeploymentException</idl> 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.
 
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.

Latest revision as of 10:45, 23 December 2020



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 a 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
In other languages