Calling External JARs - how to deal with Java vector types?

The story so far…

I’ve succeeded in calling external third-party JARs in the CLASSPATH with the syntax

rval = Packages.au.com.csw.Eclaim.getInstance().getSessionId();

So far so good,

My current problem is working with Javascript data types in Servoy; most of the external Java methods return a vector type. I’m assuming this the equivalent of an Array in Javascript?? If it is, I haven’t found how to make it work.

If I’m calling the method from a Java app, I code it like this (works fine in JRE 1.4)

int rval = 0;
int sessionId = 123456; //eg
int errorCode = 2003;  //eg
Vector result = new Vector();


rval =  Eclaim.getInstance().getErrorText(sessionId, errorCode, result );

// then convert the vector result to a string

String sResult = "";
sResult = result.get(0);
return sResult;

In Servoy (Javascript)

var rval = 0;
var sessionId = 123456; //eg
var errorCode = 2003;  //eg
var result = new Array();

rval =  Packages.au.com.csw.Eclaim.getInstance().getErrorText(sessionId, errorCode, result );

Servoy spits at this point with
org.mozilla.javascript.EvaluatorException: Cannot convert [Ljava.lang.Object;@4ee76d to java.util.Vector (hicGetErrorText, line 6)

I’ve tried all sorts of variations of result with and without (), , (0) etc. with different error messages.

Any suggestions to make this work? My only thought is to create an intermediary external Java class that will convert the vector into strings and pass it to my Servoy script.

Antonio,

I tend to stay away from using Java directly from within Servoy. One of the reason is your issue. The conversion of all those Objects that JavaScript is not aware of. As far as I know this needs to be solved from within Java itself so your suggestion:

My only thought is to create an intermediary external Java class that will convert the vector into strings and pass it to my Servoy script.

is imho the first option when you want to keep working like you do… The other option is of course to write a plugin…

For future readers of this post, this works.

getErrorText() is an external java method, with the signature int, string, vector.

We can define a java vector ‘result’ in a Servoy JS method; in addition to returning rval, the external method pushes stuff into the vector ‘result’ , and we can read it out with .elementAt(i)

var result = new java.util.Vector()

var rval =   Packages.au.com.csw.Eclaim.getInstance().getErrorText(sessionId, errorCode, result ); 

application.output(result.elementAt(0))

application.output(result.elementAt(1))

Thanks to Cybersack for the tip.