news.gmane.org schrieb:

> Mathias Bauer ha scritto:
>> news.gmane.org wrote:
>> 
>>>             XModel oModel = 
>>> (XModel)UnoRuntime.queryInterface(XModel.class,oEvent.Source);
>>>             if (oModel!=null) {
>>>                     System.out.println("Document URL is: " + 
>>> oModel.getURL());
>>>             }
>>>     }
>> 
>> You should be aware that getURL() will return an empty string if the
>> document is an untitled one and as you can have more than of untitled
>> document it doesn't qualify as an identifier.
>> 
>> You could use the document (reference) itself as a unique identifier.
>> You then must register as a listener so you get a notification when the
>> document is disposed so that you can release your reference.
> 
> The problem is: how do I get the document refernce from the EventObject?
> I've tried this:
> 
> OfficeDocument oDocument = 
> (OfficeDocument)UnoRuntime.queryInterface(OfficeDocument.class,oEvent.Source);
> 
> but I'm getting a ClassCastException.

OfficeDocument is not a valid type here. You have to use any interface
from our documents - I would recommend to use com.sun.star.XModel.

> And what about releasing the reference? Do you mean the document 
> reference passed to the listener when constructing it?

I assumed that if you wanted to use the reference to the document as an
identifier for it you will need to store it somewhere in a list, a table
or whatsoever. In this case you must remove it from this list again when
it gets disposed. For this purpose a listener comes in handy.

Ciao,
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]

Reply via email to