Hi Sven,
Victoria, Sven wrote:
Hi,
I tried (with success) the SDraw.java example
<OpenOffice sdk>/examples/java/Drawing/SDraw.java
and for the sake of learning changed the call in Main() to draw a line
from:
oShapes.add(createShape(xDrawDoc,2000,1500,1000,1000,"Line",0));
to:
oShapes.add(createShape(xDrawDoc,2000,1500,1000,1000,"Line2",0));
and I got the following error:
"Couldn't create instance com.sun.star.lang.ServiceNotRegisteredException:
Can't change colors java.lang.NullPointerException"
Strange error here, so I look in createShape() and see:
public static XShape createShape(XComponent oDoc, int height, int width, int x,
int y, String kind, int col) {
...
Object oInt = oDocMSF.createInstance("com.sun.star.drawing."+kind+"Shape");
oShape = (XShape)UnoRuntime.queryInterface( XShape.class, oInt );
size.Height = height;
size.Width = width;
position.X = x;
position.Y = y;
oShape.setSize(size);
oShape.setPosition(position);
...
}
and it fails on createInstance() where 'kind' is in this case "Line2".
I can understand why it fails but I do not understand how string based instancing
improves type safety over explicit instancing (I would rather fix compiler errors
then debug run time errors). What I would expect is something like:
...
XShape oShape = oDocMSF.createLine(x,y, width, height);
oShape.setSize(size);
oShape.setPosition(position);
...
This looks cleaner/shorter/more type safe and even faster since queryInterface()
overhead is avoided.
You are right and we have addressed this issue with the new UNO ease of
use features
(http://udk.openoffice.org/common/man/draft/multinherit.html). In your
example Line2 would be a service implementing one multiple inheritance
interface (e.g. XLine2 where XLine2 inherit from XShape) + special
constructor methods. In your code you would write simply:
XLine2 oLine = Line2.create(doc_specific_context, x,y, width, height)
oLine.setSize(size);
oLine.setPosition(position)
The doc_specific_context is necessary to hide the implementation detail
of document specific service factories (without going into detail here)
You see it would be really easy and type safe. But that will be only
available for new API's and probably for often used existing API's where
we will extend this new UNO features. It is currently not specified
which existing API's this will be ;-(
Juergen
The developer documents state a lot of times how programming with the UNO model
is type safe and wonderfull.
I am not trying to bash anyone but what point am I missing here? Please enlighten me...
Regards,
Sven
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]