Hi,

Stephan Bergmann pisze:
==

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;
  }
}


==

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).

Good, then I'll refactor, add Javadoc, synchronization and what not. changeContext simply re-initializes values of private variables set in the constructor. I could do without it but it would introduce a lot more UNO calls and class instantiations, and I like caching instances.

What do you mean by DRY-ness? Lack of verbosity in the code?

Thanks again,
Marcin

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

Reply via email to