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:
1) 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) ...
2) 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
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
Hi Christian,
I am routing for Germany tomorrow.
Michael Kay at Saxonica came up with this aproach (http://sn.im/ypvwa)
XQDataSource ds = new SaxonXQDataSource(); XQConnection conn = ds.getConnection();
XQPreparedExpression exp = conn.prepareExpression( "declare namespace jt = 'http://saxon.sf.net/java-type%27;%5Cn" + "declare namespace Locale = 'java:java.util.Locale';\n" + "declare variable $locale as jt:java.util.Locale external;\n" + "Locale:getDisplayLanguage($locale)");
XQItemType localeType = conn.createAtomicType( XQItemType.XQBASETYPE_ANYATOMICTYPE, new QName("http://saxon.sf.net/java-type", "java.util.Locale"), null); XQItem italianLocale = conn.createItemFromObject(Locale.ITALIAN, localeType); exp.bindItem(new QName("locale"), italianLocale); XQResultSequence result = exp.executeQuery(); while (result.next()) { XQItem item = result.getItem(); System.out.println("Locale: " + item.getItemAsString(null)); }
Maybe a variation of the same?
Ciao Stefano
On Fri, Jul 2, 2010 at 3:54 AM, Christian Grün christian.gruen@gmail.com wrote:
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
Santoro,
seems as if Michael uses his XML Schema infra structure to define new Java types in XQuery; something we can't offer out of the box. I've added your feature request to our internal todo list, however.
Allora, giorni belli in Germania! Christian
On Fri, Jul 2, 2010 at 3:41 PM, Stefano Santoro stefano@santoro.org wrote:
Hi Christian,
I am routing for Germany tomorrow.
Michael Kay at Saxonica came up with this aproach (http://sn.im/ypvwa)
XQDataSource ds = new SaxonXQDataSource(); XQConnection conn = ds.getConnection();
XQPreparedExpression exp = conn.prepareExpression( "declare namespace jt = 'http://saxon.sf.net/java-type%27;%5Cn" + "declare namespace Locale = 'java:java.util.Locale';\n" + "declare variable $locale as jt:java.util.Locale external;\n" + "Locale:getDisplayLanguage($locale)");
XQItemType localeType = conn.createAtomicType( XQItemType.XQBASETYPE_ANYATOMICTYPE, new QName("http://saxon.sf.net/java-type", "java.util.Locale"), null); XQItem italianLocale = conn.createItemFromObject(Locale.ITALIAN, localeType); exp.bindItem(new QName("locale"), italianLocale); XQResultSequence result = exp.executeQuery(); while (result.next()) { XQItem item = result.getItem(); System.out.println("Locale: " + item.getItemAsString(null)); }
Maybe a variation of the same?
Ciao Stefano
On Fri, Jul 2, 2010 at 3:54 AM, Christian Grün christian.gruen@gmail.com wrote:
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
basex-talk@mailman.uni-konstanz.de