Hello all, How can I call a method with variable arguments in BaseX with Java binding? I am trying to do this:
|let $string := 'Format string: %1$d - %2$s'|| || let $i := 1|| || let $j := 'text'|| || return Q{java.lang.String}format·java.lang.String·java.lang.Object*($string, $string, $i, $j)|
However, I got the error: [XPDY0002] {java.lang.String}format·java.lang.Stri...: Context is undeclared. Thank you for your time.
Hi Luan,
try this:
declare namespace java = "java:java.lang.String";
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' let $args := ($i, $j)
return java:format($string, $args)
Best regards Johannes
Am 23.04.2019 um 06:29 schrieb Luan Bui:
Hello all, How can I call a method with variable arguments in BaseX with Java binding? I am trying to do this:
|let $string := 'Format string: %1$d - %2$s'|| || let $i := 1|| || let $j := 'text'|| || return Q{java.lang.String}format·java.lang.String·java.lang.Object*($string, $string, $i, $j)|
However, I got the error: [XPDY0002] {java.lang.String}format·java.lang.Stri...: Context is undeclared. Thank you for your time.
And a complementary remark: You can also use the built-in function out:format (it will be optimized better than Java functions):
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return out:format($string, $i, $j)
For formatting numbers, XQuery provides the function fn:format-number:
format-number(1, '0000')
Best, Christian
On Tue, Apr 23, 2019 at 6:41 AM Johannes Bauer johannes.bauer@tanner.de wrote:
Hi Luan,
try this:
declare namespace java = "java:java.lang.String";
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' let $args := ($i, $j)
return java:format($string, $args)
Best regards Johannes
Am 23.04.2019 um 06:29 schrieb Luan Bui:
Hello all, How can I call a method with variable arguments in BaseX with Java binding? I am trying to do this:
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return Q{java.lang.String}format·java.lang.String·java.lang.Object*($string, $string, $i, $j)
However, I got the error: [XPDY0002] {java.lang.String}format·java.lang.Stri...: Context is undeclared. Thank you for your time.
Hi all, Thanks for your answers. Actually I have to use Java binding to call some methods, the code which I provided is just an example. I wanted to call this method:
publicProcessingResult https://get.carrot2.org/stable/javadoc/org/carrot2/core/ProcessingResult.html process(List http://docs.oracle.com/javase/7/docs/api/java/util/List.html?is-external=true<Document https://get.carrot2.org/stable/javadoc/org/carrot2/core/Document.html> documents, String http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true queryHint, Class http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html?is-external=true<?>... processingComponentClasses) throwsProcessingException https://get.carrot2.org/stable/javadoc/org/carrot2/core/ProcessingException.html
(https://get.carrot2.org/stable/javadoc/org/carrot2/core/Controller.html#proc...)
On 4/23/2019 13:51, Christian Grün wrote:
And a complementary remark: You can also use the built-in function out:format (it will be optimized better than Java functions):
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return out:format($string, $i, $j)
For formatting numbers, XQuery provides the function fn:format-number:
format-number(1, '0000')
Best, Christian
On Tue, Apr 23, 2019 at 6:41 AM Johannes Bauer johannes.bauer@tanner.de wrote:
Hi Luan,
try this:
declare namespace java = "java:java.lang.String";
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' let $args := ($i, $j)
return java:format($string, $args)
Best regards Johannes
Am 23.04.2019 um 06:29 schrieb Luan Bui:
Hello all, How can I call a method with variable arguments in BaseX with Java binding? I am trying to do this:
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return Q{java.lang.String}format·java.lang.String·java.lang.Object*($string, $string, $i, $j)
However, I got the error: [XPDY0002] {java.lang.String}format·java.lang.Stri...: Context is undeclared. Thank you for your time.
In that case Johannes’ approach might be the solution.
I say “might”, though, because it’s not always possible to uniquely address Java functions and process their result (addressing varargs is just one example). If you have more than a single Java call in your code, and if it turns that it cannot be written in XQuery, it might be a better option to write a dedicated Java class that does the detail work and returns a single result to XQuery.
On Tue, Apr 23, 2019 at 9:01 AM Luan Bui luan.bui@tanner.de wrote:
Hi all, Thanks for your answers. Actually I have to use Java binding to call some methods, the code which I provided is just an example. I wanted to call this method:
public ProcessingResult process(List<Document> documents, String queryHint, Class<?>... processingComponentClasses) throws ProcessingException
(https://get.carrot2.org/stable/javadoc/org/carrot2/core/Controller.html#proc...)
On 4/23/2019 13:51, Christian Grün wrote:
And a complementary remark: You can also use the built-in function out:format (it will be optimized better than Java functions):
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return out:format($string, $i, $j)
For formatting numbers, XQuery provides the function fn:format-number:
format-number(1, '0000')
Best, Christian
On Tue, Apr 23, 2019 at 6:41 AM Johannes Bauer johannes.bauer@tanner.de wrote:
Hi Luan,
try this:
declare namespace java = "java:java.lang.String";
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' let $args := ($i, $j)
return java:format($string, $args)
Best regards Johannes
Am 23.04.2019 um 06:29 schrieb Luan Bui:
Hello all, How can I call a method with variable arguments in BaseX with Java binding? I am trying to do this:
let $string := 'Format string: %1$d - %2$s' let $i := 1 let $j := 'text' return Q{java.lang.String}format·java.lang.String·java.lang.Object*($string, $string, $i, $j)
However, I got the error: [XPDY0002] {java.lang.String}format·java.lang.Stri...: Context is undeclared. Thank you for your time.
-- With best regards,
Bui The Luan (Mr.) Lead Software Developer
TANNER Vietnam Ltd. 43D/8, Ho Van Hue Street Ward 9, Phu Nhuan Dist Ho Chi Minh City, Vietnam
Tax Code: 0303 620 482
tel. +84 28 3997 3452 - 103 fax. +84 28 3997 3465 mobi. +84 168 688 0001 luan.bui@tanner.de http://www.tanner.vn
basex-talk@mailman.uni-konstanz.de