Marcin Miłkowski wrote:
Hi again,

Stephan wrote:

I do not understand your first part (about classpath), but multiple instances are of course still generated when you use com.sun.star.comp.loader.FactoryHelper.createComponentFactory in __getComponentFactory. You have to return your own implementation of XSingleComponentFactory from __geComponentFactory, which controls the number of instances generated.

OK, I used this simple code as my implementation of the XSingleFactory:

==

class SingletonFactory implements XSingleComponentFactory {

  private Object instance = null;

public Object createInstanceWithArgumentsAndContext(Object[] arg0, XComponentContext arg1) throws com.sun.star.uno.Exception {
    if (instance == null) {
      instance = new de.danielnaber.languagetool.openoffice.Main(arg1);
    } else {
de.danielnaber.languagetool.openoffice.Main x = (de.danielnaber.languagetool.openoffice.Main) instance;
      x.changeContext(arg1);
    }
    return instance;
  }

public Object createInstanceWithContext(XComponentContext arg0) throws com.sun.star.uno.Exception {
    if (instance == null) {
      instance = new de.danielnaber.languagetool.openoffice.Main(arg0);
    } else {
de.danielnaber.languagetool.openoffice.Main x = (de.danielnaber.languagetool.openoffice.Main) instance;
      x.changeContext(arg0);
    }
    return instance;
  }
}


==

to create single instance of my class. Now it works as expected (as you can see, I also switch context that is saved as a private class variable).

My worry is that what I did can go against some UNO principles. I don't get any null pointers and it seems to work but I'd be grateful if you could tell me if it doesn't look horribly broken to you. It solves all my problems but I could be wrong...

Looks OK in principle (modulo missing synchronization of access to variable instance, a lack of DRY-ness, unhelpful parameter names arg0/1, and a dubious changeContext).

-Stephan

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

Reply via email to