Hi Tobias,
>
> 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.
If the two interfaces have the same methods, why create two separate
interfaces at all. The RegistrationClass (JudasComponent in your case)
does not need to have an UNO interface, so you can also leave the
JudasComponent idl files out (but if you want to define some extra
methods on it, you'll need the idl files of course).
>
> 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!
I would recommend to name your idl files according to the name of the
interface / service / singleton that is defined in it. So I would rename
the ild file containing the singleton to twcSpringLoader.idl (OOo
convention is to use 'the' for singletons, so it would become
theSpringLoader).
According to this document:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/WritingU
NO/Core_Interfaces_to_Implement it is recommended to implement the
interface XTypeProvider, XServiceInfo and XWeak. Since XWeak extends the
other interfaces (as well as XInterface) you can extend your interface
from XWeak. There is also a helper class in Java called WeakBase that
does implement all methods defined in those interfaces.
You'll probably need methods on your SpringLoader singleton to set /
retrieve the connection (or some other data). These methods must be
defined in XSprinLoader. So your interface would become something like
this:
-----%<-----
#ifndef __de_twc_oocom_comp_xspringloader_idl__
#define __de_twc_oocom_comp_xspringloader_idl__
#include <com/sun/star/uno/XWeak.idl>
module de { module twc { module oocom { module comp {
interface XSpringLoader : com::sun::star::uno::XWeak {
void setConnectionString([in] string connectionString);
string getConnectionString();
};
}; }; }; };
#endif
-----%<-----
Creating an implementation in Java is nothing different from an
implementation for an ordinary service:
-----%<-----
public class SpringLoaderImpl extends WeakBase implements XSpringLoader
{
// seems to be the convention in OOo UNO services, can be used
// by JonasComponent for registration
public static final String __serviceName =
"de.twc.oocom.comp.theSpringLoader";
public void setConnectionString(String connectionString) {
// do some nice things with the connection string
}
public String getConnectionString() {
return connectionString;
}
}
-----%<-----
>
> >>> 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?
>
Yes, I think it is, but note that you need SpringLoaderImpl.class to
refer the implementation that you created in Java, not to the singleton
class definition that is generated for your.
>
> I found an example for it.
>
> Thanks again for your great help!
>
> Greetings, Tobias
>
You're welcome.
Regards,
Daan
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]