Marcin Miłkowski wrote:
Hi,

I'm implementing a class that implements a known OOo service (actually, several ones, but the important one is XGrammarChecker). The problem is that the class is instantiated many times in OOo whenever a UI item is used, and the instances created do not share data.

Note that com.sun.star.linguistic2.XGrammarChecker is an interface, not a service.

So I think I should guarantee that the service is instantiated only once per OOo instance. As far as I understand, I need to make a singleton class for this purpose. The docs (if one can call it docs) refer to writing an IDL spec which is not useful for implementing a known UNO service, so I think in this case writing IDL is completely superfluous. All I want from the class is that it's created only once per JVM in OOo (the code is in Java). What should I do to make my class a one-instance class? Is it enough to add some registry code to __writeRegistryServiceInfo?

New UNOIDL ("singleton Foo: XBar;") is not needed here---it would declare that there is a singleton UNO object obtainable with a certain name at the global component context. Rather, you want to change the details of a Java implementation of some UNO object.

Your __getServiceFactory method is the place to turn to. Let it return a com.sun.star.lang.XSingleComponentFactory whose createInstanceWithContext and createInstanceWithArgumentsAndContext methods control the number of instances generated (which might be difficult for example if you need to support non-trivial argument lists, which I do not know since XGrammarChecker is an interface and not a service).

However, be aware that XGrammarChecker has methods like startDocument documented as "This enables the grammar checker to maintain state information about the document".

-Stephan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to