Hi Daan,
>> for I am very new to singletons, please allow me some more questions.
>> May be some are silly, but I have a lack of knowledge...
>
> Singletons definitely need more documentation, we found out how to
> register them by looking through the OOo rdb files...
I agree. I googled the whole web and there are no examples or any
guidance - out of you ;-)
>>> 1. You first need to create an UNO interface for your extension (say
>>> XConnectionManager)
>> I have already created a UNO interface for my extension:
>> - XJudasComponent.idl and
>> - JudasComponent.idl
>>
>> Now I add a new idl file named XSpringLoader.idl:
> My bad, didn't tell you that the singleton definition needs another idl
> file, so you get one idl file defining the interface, and another
> defining the singleton. Btw, likely you don't want the published keyword
> before the singleton definition as that means your interface needs to be
> published also.
If I need another idl file for the singleton, is it possible to reuse
the XJudasComponent.idl file instead of creating the XSpringLoader.idl
file? The contents of the files are very similar, except for the name.
My XSpringLoader.idl file now looks like this:
-----%<-----
#ifndef __de_twc_oocom_comp_xspringloader_idl__
#define __de_twc_oocom_comp_xspringloader_idl__
#include <com/sun/star/uno/XInterface.idl>
module de { module twc { module oocom { module comp {
interface XSpringLoader : com::sun::star::uno::XInterface {
};
}; }; }; };
#endif
-----%<-----
And my new SpringLoaderImpl.idl file looks like this:
-----%<-----
#ifndef __de_twc_oocom_comp_springloaderimpl_idl__
#define __de_twc_oocom_comp_springloaderimpl_idl__
#include "XSpringLoader.idl"
module de { module twc { module oocom { module comp {
singleton twcSpringLoader : XSpringLoader;
}; }; }; };
#endif
-----%<-----
Both compile like a charm :-)
>>> 3. Implement the singleton by creating an implementation of the
>>> XConnectionManager interface, say ConnectionManagerImpl.
Do you have a code example you can share with me? Something like an
singleton class skeleton? This would help me a lot!
>>> 4. Store the singleton by adding the following code to
>>> __writeRegistryServiceInfo in you component registration class:
> This code should be in the class that is registered in the MANIFEST.MF
> file in your jar as RegistrationClassName
OK. In my case this is the class JudasComponent. This method now looks
like this:
-----%<-----
public static boolean __writeRegistryServiceInfo(XRegistryKey regKey) {
try {
XRegistryKey newKey =
regKey.createKey(SpringLoaderImpl.class.getName() +
"/UNO/SINGLETONS/" + twcSpringLoader.class.getName());
newKey.setStringValue("de.twc.oocom.comp.twcSpringLoader");
} catch (InvalidRegistryException e) {
return false;
}
boolean protocol = FactoryHelper.writeRegistryServiceInfo(
JudasProtocolHandler.class.getName(), SERVICENAME, regKey);
return protocol;
}
-----%<-----
>>> 5. __getComponentFactory can be updated as you would do for an
> ordinary
>>> service (no special handling for singletons required)
I have no __getComponentFactory method in my class, I only have a
__getServiceFactory(String, MultiServiceFactory, XRegistryKey). But I
think that won't make a difference. Here is the method:
-----%<-----
public static XSingleServiceFactory __getServiceFactory (String
implName, XMultiServiceFactory multiFactory, XRegistryKey
regKey) {
XSingleServiceFactory xSingleServiceFactory = null;
if (implName.equals(JudasProtocolHandler.class.getName())) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(
JudasProtocolHandler.class,
SERVICENAME,
multiFactory,
regKey);
}
else if (implName.equals(SpringLoaderImpl.class.getName())) {
xSingleServiceFactory = FactoryHelper.getServiceFactory(
SpringLoaderImpl.class,
"de.twc.oocom.comp.twcSpringLoader",
multiFactory,
regKey);
}
return xSingleServiceFactory;
}
-----%<-----
Is this correct?
>>> 6. Now the singleton can be retrieved by calling
>>> theConnectionManager.get(componentContext)
>> I have to read about this...
I found an example for it.
Thanks again for your great help!
Greetings, Tobias
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]