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

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
 
Line 10: Line 10:
 
{{DISPLAYTITLE:Mapping of Singletons}}
 
{{DISPLAYTITLE:Mapping of Singletons}}
 
A new-style singleton of the form
 
A new-style singleton of the form
 
+
<syntaxhighlight lang="idl">
 
   singleton Name: XIfc;
 
   singleton Name: XIfc;
 
+
</syntaxhighlight>
 
is mapped to a public Java class with the same name. The class has a single method
 
is mapped to a public Java class with the same name. The class has a single method
 
+
<syntaxhighlight lang="java">
 
   public static XIfc get(com.sun.star.uno.XComponentContext context) { ... }
 
   public static XIfc get(com.sun.star.uno.XComponentContext context) { ... }
 
+
</syntaxhighlight>
 
The semantics of such a singleton getter method in Java are as follows:
 
The semantics of such a singleton getter method in Java are as follows:
  
 
* The <idl>com.sun.star.uno.XComponentContext</idl> argument must be non-null.
 
* The <idl>com.sun.star.uno.XComponentContext</idl> argument must be non-null.
  
* The singleton getter uses [http://api.openoffice.org/docs/common/ref/com/sun/star/uno/XComponentContext.html#getValueByName com.sun.star.uno.XComponentContext:getValueByName] to obtain the singleton instance (within the "<code>/singletons/</code>" name space).
+
* The singleton getter uses <idlm>com.sun.star.uno.XComponentContext:getValueByName</idlm> to obtain the singleton instance (within the "<code>/singletons/</code>" name space).
  
 
* If no singleton instance could be obtained, the singleton getter fails by throwing a <idl>com.sun.star.uno.DeploymentException</idl>. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.
 
* If no singleton instance could be obtained, the singleton getter fails by throwing a <idl>com.sun.star.uno.DeploymentException</idl>. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.

Latest revision as of 12:56, 23 December 2020



A new-style singleton of the form

  singleton Name: XIfc;

is mapped to a public Java class with the same name. The class has a single method

  public static XIfc get(com.sun.star.uno.XComponentContext context) { ... }

The semantics of such a singleton getter method in Java are as follows:

  • The singleton getter uses getValueByName to obtain the singleton instance (within the "/singletons/" name space).
  • If no singleton instance could be obtained, the singleton getter fails by throwing a com.sun.star.uno.DeploymentException. The net effect is that a singleton getter either returns the requested non-null singleton instance, or throws an exception; a singleton getter will never return a null instance.

Old-style singletons are not mapped into the Java language binding.

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