Tabish F. Mufti schrieb:
You can avoid these problems, if you write your protocol handler as a
multi-instance service."
So how can I write a multi-instance service ?
The difference between multi-instance and one instance service
(singleton) will be made on creation time.
Every java service must have a statuc function called
"__getServiceFactory()". Here you decide, if you return a factory
creating new instances of your classes every time ... or if you create
one singleton of your service only and return always the same instance.
Please read the devlopers guide:
"http://api.openoffice.org/docs/DevelopersGuide/Components/Components.xhtml"
especialy chapter 4.5 "Simple Component in Java".
I you wish to access your "server" everytimes a menu / toolbar item is
clicked ... you have to implement your ProtocolHandler / Job as
singleton.
I need to access my "server" from the menu/toolbar as well as through the
ooimpress slide, it'll probably be some button placed on every slide on
which click event I want to contact the server. So would it work for both
cases ?
Yes; that's possible. You need:
a) a singleton UNO service implementing your server
b) a multi UNO service as ProtocolHandler
What's happen then ?
Every times you click into the menu/toolbar a new instance of your
ProtocolHandler will be created. These ProtocolHandler internaly will
create the server (as UNO service!). But everytimes you will get the
same server instance (because it's a singleton). So the ProcotolHandler
can work on these server and if the dispatch() call was finished the
ProtocolHandler can "die". The server will stay alive (because it's hold
alive by UNO and the factory).
So you will have 1 Server and N ProtocolHandler.
Please note: the server will live for the whole time the office runs.
So the server must be informed in case the office will shutdown.
The best way is to implement the interface com.sun.star.lang.XComponent
on the server. UNO will call it's dispose() method then. So the server
knows when the office will die.
BUT: You shouldnt make expensive things inside this dispose() call.
Because if this call reach you most parts of the office was already
released. If you whish to have a "more featured" environment on shutdown
you must register your server as listener on the right places.
The communication between your ProtocolHandler services and your UNO
service implementation can use UNO interfaces only. Two solutions are
possible:
i) You design zour own set own interfaces and methods using IDL files.
ii) You "recylce" existing interfaces of the namespace "com.sun.star" .-)
E.g. the XDispatch API seams to be flexible enough to implement every
communication between two objects .-))
Hopefully this helps you a little bit.
Regards
Andreas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]