Tabish F. Mufti wrote:
[...]
# compile
idlc -C -I. -I${SDK_DIR}/idl -O${WorkDir} theSentence.idl
idlc -C -I. -I${SDK_DIR}/idl -O${WorkDir} XSentence.idl

# create registory database (.rdb)
regmerge ${WorkDir}/ex_comp.rdb /UCR ${WorkDir}/theSentence.urd
regmerge ${WorkDir}/ex_comp.rdb /UCR ${WorkDir}/XSentence.urd

# view a registry database
#regview ${WorkDir}/ex_comp.rdb

# generate java souce file for new types from rdb
javamaker -BUCR -nD \
         -Tcom.sun.star.ex.comp.XSentence \
         ${OOo_DIR}/program/types.rdb \
         -O${WorkDir} \
         ${WorkDir}/ex_comp.rd

I had all the above but there was a slight mistake somewhere. Anywayz it
compiled & packaged was deployed.

Now I get an exception on this line:

com.sun.star.ex.comp.XSentence sentence =
com.sun.star.ex.comp.theSentence.get(xContext);

In queryDispatch in ProtocolHandler: myInput:
com.sun.star.uno.DeploymentException: component context fails to supply
singleton com.sun.star.ex.comp.theSentence of type
com.sun.star.ex.comp.XSentence
       at com.sun.star.ex.comp.theSentence.get(Unknown Source)
       at com.sun.star.ex.comp.SentenceProtocolHandler$OwnDispatch.dispatch
(SentenceProtocolHandler.java:129)


OK, I see your problem.  Singletons (and services) have three parts:

First, you need a UNOIDL file containing the singleton's "declaration" (i.e., containing a line like "singleton theSentence: XSentence;", as your theSentence.idl). From that, javamaker creates a helper class (theSentence.class) that allows client code to obtain the singleton instance at runtime, *if certain conditions are met.*

Second, there needs to be a "definition" of the singleton (i.e., for example a Java class you provide that implements the XSentence interface and also provides code to register the singleton implementation with a component context). How the necessary code to register a *service* implementation looks like is described in the DevGuide (<http://api.openoffice.org/docs/DevelopersGuide/DevelopersGuide.pdf>), sections 4.5.3--4.5.5); however, a description of the necessary code for a *singleton* implementation seems to be missing. [*]

Third (and this is where the "certain conditions" from above are provided), a call to theSentence.get(componentContext) will only succeed if componentContext is a component context in which the "definition" of the singleton (the Java class you need to provide) has been registered. How this registration works depends on the nature of the component context:

- If the component context is a binary UNO one from the OOo installation (e.g., obtained from com.sun.star.comp.helper.Bootstrap.bootstrap or com.sun.star.comp.helper.Bootstrap.defaultBootstrap_InitialComponentContext), the singleton must be registered in the OOo services.rdb (for example via regcomp, see the DevGuide for details).

- If the component context is a pure Java UNO one (e.g., obtained from com.sun.star.comp.helper.Bootstrap.createInitialComponentContext), you have to register the singleton directly at the component context "by hand." Again, how this is done seems not to be well documented. [**]

Please allow me some more time to come back with example code that sheds more light on how [*] and [**] actually work.

-Stephan

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

Reply via email to