Dear Stefano,
as there is no XQuery equivalent for Provami, it won't be possible to bind a class instance to an XQuery variable – at least according to the XQJ specs, as far as I can remember. If there should be other implementations who offer this functionality, or if you think it should indeed be possible, feel free to let me know how the class instance is to be handled by XQuery.
All the best, Christian
On Thu, Jul 1, 2010 at 11:53 PM, Stefano Santoro stefano@santoro.org wrote:
Hi,
I am having trouble binding a java object to an XQuery external variable.
Here is my simple java class:
public class Provami {
private int items; private String name;
public Provami() { }
public Provami(String name, int items) { this.items = items; this.name = name; }
public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
public int getItems() { return this.items; }
public void setItems( int items) { this.items = items; } }
and here is my XQuery sample
declare namespace provami = "java:Provami"; declare variable $bar as xs:anyAtomicType external;
let $foo := provami:new() return element a { element i {provami:setName($foo, 'nome'), provami:getName($foo)}, element i {provami:getName($bar)} }
I have tried two approaches with XQJ:
- to create an atomic type
groovy:000> otype = conn.createAtomicType(XQItemType.XQBASETYPE_ANYATOMICTYPE, new QName("java:Provami"),null) groovy:000> ixpr.bindObject(new QName("bar"), new Provami("passato", 4), otype) ERROR org.basex.api.xqj.BXQException: No mapping known for 'Provami'. at org.basex.api.xqj.BXQAbstract.create (BXQAbstract.java:128) at org.basex.api.xqj.BXQDynamicContext.bindObject (BXQDynamicContext.java:147) at groovysh_evaluate.run (groovysh_evaluate:13) ...
- I have also tried to create an item
groovy:000> itm = conn.createItemFromObject(new Provami('roba',4), null) ERROR org.basex.api.xqj.BXQException: No mapping known for 'Provami'. at org.basex.api.xqj.BXQAbstract.create (BXQAbstract.java:128) at org.basex.api.xqj.BXQDataFactory.createItemFromObject (BXQDataFactory.java:231) at org.basex.api.xqj.BXQDataFactory.createItemFromObject (BXQDataFactory.java:39) at groovysh_evaluate.run (groovysh_evaluate:13) ...
Could you please advice on how I may successfully bind the parameter.
Thanks Stefano _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk