Project

Profile

Help

Java ext. function getting a List of Lists

Added by Anonymous almost 16 years ago

Legacy ID: #5232357 Legacy Poster: antbo (antbo)

Hello, I'm using Saxon B8.8. I'm calling a Java extension function from an XQuery. For instance: declare namespace test='java:my.package.Test'; let $list1 := ('a1','b1') let $list2 := ($list1,'a2','b2') return test:myFunc($list2) Question: What I would like is to receive into myFunc a List containing a List and 2 Strings: {{'a1','b1'},'a2','b2'}. But myFunc is actually receiving a List containing 4 Strings: {'a1','b1','a2','b2'}. Am I doing something wrong? (I may understand this behavior is correct as doing a "for" loop over $list2 iterates onto each single String) Is there another way to achieve what I want? Problem: To achieve my goal, I tried to introduce a wrapping method creating an object hiding the List. This object has only one member attribute: the List object it receives into its constructor: declare namespace test='java:my.package.Test'; let $list1 := ('a1','b1') let $list2 := (test:wrapList($list1),'a2','b2') return test:myFunc($list2) This works fine: myFunc is receiving a List containing {ListWrapper,'a2','b2'}, and ListWrapper contains {'a1','b1'}. But the problem arises when the ListWrapper is returned by the query. For example: let $list1 := ('a1','b1') return test:wrapList($list1) Here I get a NPE into net.sf.saxon.value.ObjectValue.getItemType() because the TypeHierarchy parameter is null. The call stack is: java.lang.NullPointerException at net.sf.saxon.value.ObjectValue.getItemType() at net.sf.saxon.value.Value.convert() at net.sf.saxon.query.XQueryExpression.evaluate() ... Am I missing something? Thanks for your help.


Replies (4)

Please register to reply

RE: Java ext. function getting a List of Lists - Added by Anonymous almost 16 years ago

Legacy ID: #5232433 Legacy Poster: Michael Kay (mhkay)

The XPath data model (XDM) doesn't support sequences of sequences, so there's no natural way of handling a value that comes from the Java world that's a List containing a List. So the only way to do this is to wrap the Lists in Java objects that Saxon doesn't try to treat specially, which is what you have done. >Here I get a NPE into net.sf.saxon.value.ObjectValue.getItemType() because the TypeHierarchy parameter is null. That's clearly a bug, so the first thing that you should do is to try it on a more recent release. The current release is 9.1.0.2.

RE: Java ext. function getting a List of Lists - Added by Anonymous almost 16 years ago

Legacy ID: #5233062 Legacy Poster: Vladimir Nesterovsky (vnesterovsky)

You might want to try tuples/maps extensions: http://www.nesterovsky-bros.com/download/saxon.extensions.9.1.zip See "Tuples and maps in Saxon" at http://www.nesterovsky-bros.com/weblog/2008/05/18/TuplesAndMapsInSaxon.aspx

RE: Java ext. function getting a List of Lists - Added by Anonymous almost 16 years ago

Legacy ID: #5233065 Legacy Poster: David Lee (daldei)

I have worked around this feature of the language by using an element structure to simulate "sequences of sequences". Its a bit overkill but it gets the job done. Like this. let $l1 := <l><e>1</e><e>2</e><e>3</e></l> , $l2 := ( $l1 , 4 , 5 , 6 ) Produces a sequence like ( <l> ... </l> , 4, 5 , 6 ) with creative use of functions to compose and decompose the structure it can serve the same purpose as sequence of sequence.

RE: Java ext. function getting a List of Lists - Added by Anonymous almost 16 years ago

Legacy ID: #5233112 Legacy Poster: Vladimir Nesterovsky (vnesterovsky)

Alternatively, one may use sequence terminators: ( 1, 2, $terminator, 3, $terminator, 4, $terminator, 5 ) where $terminator is xs:QName see http://www.nesterovsky-bros.com/weblog/2008/02/19/SequenceOfSequencesInXslt20.aspx

    (1-4/4)

    Please register to reply