Matthias B. wrote: > I have a component that registers on the GlobalEventBroadcaster to > listen for new documents (OnCreate event) to do some processing on > every text document that is opened. Now I have the problem that > OpenOffice.org broadcasts these events even for internal documents > that it creates temporarily. For instance when I insert an AutoText, > OOo apparently creates a text document in the background and > broadcasts and OnCreate event for it. When doing a MailMerge it > creates lots of these background documents. > > This creates all kinds of trouble. For instance these documents are > quickly disposed which causes DisposedExceptions in my component and > while my component catches these and can deal with the situation, OOo > becomes unstable and eventually crashes or freezes when this happens > too often during mail merge.
You should catch these exceptions or register as a Listener and get notified when the document is disposed. As the DevGuide says, every code that stores references to objects implementing XComponent (like documents) not only temporarily (means: on the stack) must do either of these. A third option is to use a WeakReference instead of a "hard" one and always try to make it "hard" before using it. > I think OOo should not even broadcast events for these documents. They > are implementation details subject to change. Components have no > business dealing with them. What is an "implementation detail" might be in the eye of the beholder. A temporary document created while doing mail merge can be seen as "implementation detail", but not if there is an extension that wants to hook into the handling of database fields in general, like e.g. Stampit. I know for sure that we would break that extension by not broadcasting the events for documents created while doing mail merge. So how should we define "internal"? Isn't it better to be as flexible as possible and let the API users decide whether they are interested in a particular document or not? Admittedly, this requires some help: > But anyway, how do I ignore these documents? And how do I avoid the > race condition between me testing if this is an internal document that > I should ignore and the OOo internal code disposing the document > potentially before I had the chance to test it. We could think about a way to identify documents as "internal", e.g. by a property. But again, this status must be defined before. Regards, Mathias -- Mathias Bauer (mba) - Project Lead OpenOffice.org Writer OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS Please don't reply to "[email protected]". I use it for the OOo lists and only rarely read other mails sent to it. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
