Hi Tobias,

Find my comments inlined in your message below

> -----Original Message-----
> From: Tobias Krais [mailto:[EMAIL PROTECTED]
> Sent: Friday, June 27, 2008 10:02
> To: dev@api.openoffice.org
> Subject: Re: [api-dev] Loading Extension on startup of OpenOffice and
use
> it later
> 
> 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...

> 
> > 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:
> -----%<-----
> #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 {
>               published singleton twcSpringLoader : XSpringLoader;
>       };
> 
>  }; }; }; };
> #endif
> -----%<-----
> But my idlc compiler won't compile:
> -----%<-----
> ...XSpringLoader.idl(8) : error in lookup of symbol: 'published'
> ...XSpringLoader.idl(8) : Illegal syntax or missing identifier after
> operation type: syntax error, unexpected IDL_SINGLETON, expecting
> IDL_IDENTIFIER or IDL_GET or IDL_SET or IDL_PUBLISHED
> -----%<-----
> 
> > 2. The UNO singleton is then defined as follows:
> >     published singleton theConnectionManager : XConnectionManager;
> 
> What is incorrect in the above idl file?
> 

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.

> > 3. Implement the singleton by creating an implementation of the
> > XConnectionManager interface, say ConnectionManagerImpl.
> 
> OK. This will look like this:
> -----%<-----
> package de.twc.oocom.comp;
> 
> public class SpringLoaderImpl implements XSpringLoader {
>       //myCode
> }
> -----%<-----
> 
> > 4. Store the singleton by adding the following code to
> > __writeRegistryServiceInfo in you component registration class:
> >     try {
> >             XRegistryKey newKey =
> > xRegistryKey.createKey(ConnectionManagerImpl.class.getName() +
> > "/UNO/SINGLETONS/" + theConnectionManager.class.getName());
> >
> >
newKey.setStringValue("de.krais.tobias.sample.theConnectionManager");
> >     } catch (InvalidRegistryException e) {
> >             return false;
> >     }
> 
> Should I add this code in the new class SpringLoaderImpl or in the
class
> JudasComponent, which im my "main" class for the extension?

This code should be in the class that is registered in the MANIFEST.MF
file in your jar as RegistrationClassName

> 
> > 5. __getComponentFactory can be updated as you would do for an
ordinary
> > service (no special handling for singletons required)
> > 6. Now the singleton can be retrieved by calling
> > theConnectionManager.get(componentContext)
> 
> I have to read about this...
> 
> Thanks a lot for your help! It boosts my task!
> 
> Greetings, Tobias
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

Daan

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

Reply via email to