Tobias Krais wrote:
> Hi Stephan,
>
>
>>com.sun.star.container.XIndexAccess.getByIndex
returns an ANY value,
>>which in the Java-UNO binding maps to
>>java.lang.Object/com.sun.star.uno.Any in a somewhat
hard-to-use way:
>>
>>PropertyValue[] oDateiMenuSettings;
>>try {
>> oDateiMenuSettings =
com.sun.star.uno.AnyConverter.toObject(
>> PropertyValue[].class,
oMenuBarSettings.getByIndex(0));
>>} catch (com.sun.star.lang.IllegalArgumentException
e) {
>> throw new RuntimeException(e.toString());
>>}
>
>
> thanks for the hint. The code above does not work for
me, because an
> Object is returned and a PropertyValue[] is expected. I
first have to
> cast it. Here the code I use:
Yes, the above code does not work (I wrote it down without
trying it
out), the (hopefully) correct version would be
PropertyValue[] oDateiMenuSettings;
try {
oDateiMenuSettings = (PropertyValue[])
com.sun.star.uno.AnyConverter.toObject(
PropertyValue[].class,
oMenuBarSettings.getByIndex(0));
} catch (com.sun.star.lang.IllegalArgumentException e) {
throw new RuntimeException(e.toString());
}
-Stephan
> -----%<-----
> PropertyValue[] oDateiMenuSettings = (PropertyValue[])
> UnoRuntime.queryInterface(PropertyValue[].class,
> oMenuBarSettings.getByIndex(0));
> XIndexAccess xoDateiMenuSettings = (XIndexAccess)
> UnoRuntime.queryInterface(XIndexAccess.class,
> (Object)oDateiMenuSettings[2].Value);
> PropertyValue[] speichernUnter = (PropertyValue[])
>
UnoRuntime.queryInterface(PropertyValue[].class,
> xoDateiMenuSettings.getByIndex(8));
> -----%<-----
>
>
>>UnoRuntime.queryInterface is used to go from a
reference of UNO
>>interface type A to some UNO object to a reference
of UNO interface type
>>B to the same UNO object.
>
>
> I read this in the dev-guide.
>
>
>>AnyConverter is used to extract (the Java
>>representations of) arbitrary UNO values contained
in (the Java
>>representaton of) a UNO ANY value.
>
>
> This is new for me and interesting. I think I will use
it in future.
> This seems to be the "clean" way of my code
above.
>
> Thanks,
>
> Tobias
------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribe api.openoffice.org
For additional commands, e-mail: dev-help api.openoffice.org
|