double[] return type from extension
Added by Anonymous over 18 years ago
Legacy ID: #3860788 Legacy Poster: Henryk Hecht (henrykhecht)
I'm a bit new to Saxon 8, so please excuse me if I'm simply doing something wrong. I'm trying to write a java extension function that [does something] and returns an array of doubles. It appears to me as though by the time the double[] gets back to the stylesheet, it's been converted to Object[] (or sequence of Object, I suppose). This is what I know so far: 1. double, float, int, and String return types behave as expected. 2. int[] and String[] return types also behave as expected. 3. float[] or double[] are converted to something that prints as e.g.: [D@b988a6 The "whatever" appears to be constant across runs and does not depend on the value of the elements of the array, though I am not totally confident of this. According to the documentation: --- If the returned value is an instance of the Java class java.util.List, or if it is an array, the XPath value will be the sequence represented by the contents of this List or array. The members of the list or array will each be converted to an XPath value, as if each member was supplied from a separate function call. An error is reported if the result contains a list or array nested within another list or array. The contents of the list or array are copied immediately on return from the function, so the original List or array object itself may be safely re-used. --- Which does not appear to be happening, as double[] is most certainly not being converted to a sequence of what double is ordinarily converted to (xs:double, I suppose). Is this a bug? Am I doing something incorrectly, or am I simply missing the point? My inclination is that this is a bug as the results of 1,2,3 above are not logically consistent, but I am not experienced enough to judge. This is with Saxon-B 8.7.3 Java, on Sun java 1.5.0_07 on IA32. I can provide sample code if necessary, but it should be trivial enough that even I can't get it wrong. -- HH
Replies (4)
Please register to reply
RE: double[] return type from extension - Added by Anonymous over 18 years ago
Legacy ID: #3861761 Legacy Poster: Michael Kay (mhkay)
I think that what you're doing should work. I'll give it a try when I get back from vacation at the weekend.
RE: double[] return type from extension - Added by Anonymous over 18 years ago
Legacy ID: #3862526 Legacy Poster: Henryk Hecht (henrykhecht)
Thank you, I appreciate your help. I've collected a few additional data points: 1. Double (the object) works 2. Double[] works 3. java.util.LinkedList with Doubles works So it would appear that the only thing that doesn't work is double[] (and float[]). 2 or 3 above give me a satisfactory solution for the time being, so you needn't hurry about it. If I have time I will look into the Saxon source myself, but it is doubtful that I will accomplish anything in so doing as I am not familiar with it. Please enjoy the remainder of your vacation. -- HH
RE: double[] return type from extension - Added by Anonymous over 18 years ago
Legacy ID: #3866956 Legacy Poster: Michael Kay (mhkay)
Yes, there was a simple omission from the list of primitive types being handled on return from an extension function call: double[] and float[] were missing from the list for some reason. Now remedied. If you want to patch it yourself, look for the line } else if (object instanceof boolean[]) { around line 911 of net.sf.saxon.value.Value, and add the code: } else if (object instanceof double[]) { Item[] array = new Item[((double[])object).length]; for (int i = 0; i < ((double[])object).length; i++){ array[i] = new DoubleValue(((double[])object)[i]); } return new SequenceExtent(array); } else if (object instanceof float[]) { Item[] array = new Item[((float[])object).length]; for (int i = 0; i < ((float[])object).length; i++){ array[i] = new FloatValue(((float[])object)[i]); } return new SequenceExtent(array); Thanks for bringing this to my attention.
RE: double[] return type from extension - Added by Anonymous over 18 years ago
Legacy ID: #3867335 Legacy Poster: Henryk Hecht (henrykhecht)
Thank you for your help, I doubt I would have found the solution so quickly. I'll test your patch as soon as I am able (I can put it off a bit as Double[] worked), but you may assume that if you hear nothing further about it, it worked. -- HH
Please register to reply