Adding custom function handlers

ODK Developers,

JavaRosa supports custom functions via the IFunctionHandler interface,
which is handy. It looks like these can be added via the evaluation context
created in FormLoaderTask.java. However, there are two questions I have:

  1. Why doesn't the core ODK team ever use this facility to add JavaRosa
    functions? Rather, new ODK functions seem to be added by hand into
    JavaRosa's XPathFuncExpr.java, in the ODK JavaRosa repo. This makes me
    somewhat suspicious about the stability of the IFunctionHandler interface.

  2. Best I can tell, my old ODK_Validate.jar from about a year ago let
    unknown functions slide (i.e., it didn't generate an errors). With the
    latest ODK_Validate.jar, however, you get errors like
    "org.javarosa.xpath.XPathUnhandledException: XPath evaluation: cannot
    handle function 'testfunc'" if you try to validate a form that includes a
    calculate binding with an unknown function. Is my best option to build a
    custom ODK_Validate.jar with my custom functions defined
    in FormValidator.java's EvaluationContext, or would it be better to
    generate an ODK_Validate.jar that goes back to not caring about unknown
    functions?

I'd be grateful for any thoughts, as always.

Thanks,

Chris

The ODK team seeks to add new functions into the mainline javarosa code. In
that regard, I view the IFuntionHandler mechanism as a way of adding
non-mainline functionality, rather than extending the mainline.

I believe the issue with (2) disappears if you build a custom ODK Validate
that registers your handlers into the javarosa framework before you process
the form (if not, it is a bug). The tighter reporting was probably
something I picked up when I merged in post-1.0-alpha changes into our
javarosa branch. It wasn't anything that the ODK team directly set out to
change. On the other hand, it is useful to report unrecognized functions
to the user, as they often are mis-spellings of an intended function.

Mitch

··· On Thu, Apr 25, 2013 at 2:36 AM, Christopher Robert wrote:

ODK Developers,

JavaRosa supports custom functions via the IFunctionHandler interface,
which is handy. It looks like these can be added via the evaluation context
created in FormLoaderTask.java. However, there are two questions I have:

  1. Why doesn't the core ODK team ever use this facility to add JavaRosa
    functions? Rather, new ODK functions seem to be added by hand into
    JavaRosa's XPathFuncExpr.java, in the ODK JavaRosa repo. This makes me
    somewhat suspicious about the stability of the IFunctionHandler interface.

  2. Best I can tell, my old ODK_Validate.jar from about a year ago let
    unknown functions slide (i.e., it didn't generate an errors). With the
    latest ODK_Validate.jar, however, you get errors like
    "org.javarosa.xpath.XPathUnhandledException: XPath evaluation: cannot
    handle function 'testfunc'" if you try to validate a form that includes a
    calculate binding with an unknown function. Is my best option to build a
    custom ODK_Validate.jar with my custom functions defined
    in FormValidator.java's EvaluationContext, or would it be better to
    generate an ODK_Validate.jar that goes back to not caring about unknown
    functions?

I'd be grateful for any thoughts, as always.

Thanks,

Chris

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Thanks, Mitch.

We'll fork odk.validate and register our custom handlers there. (Just one
more fork to maintain!) You're right that catching misspellings during
validation is useful. I've just submitted an issue regarding how they're
reported in XLSForm (since now the error is truncated to the point you
can't actually see what the error is) -- but that's an easy fix.

Thanks again,

Chris

··· On Thu, Apr 25, 2013 at 6:50 PM, Mitch Sundt wrote:

The ODK team seeks to add new functions into the mainline javarosa code.
In that regard, I view the IFuntionHandler mechanism as a way of adding
non-mainline functionality, rather than extending the mainline.

I believe the issue with (2) disappears if you build a custom ODK Validate
that registers your handlers into the javarosa framework before you process
the form (if not, it is a bug). The tighter reporting was probably
something I picked up when I merged in post-1.0-alpha changes into our
javarosa branch. It wasn't anything that the ODK team directly set out to
change. On the other hand, it is useful to report unrecognized functions
to the user, as they often are mis-spellings of an intended function.

Mitch

On Thu, Apr 25, 2013 at 2:36 AM, Christopher Robert <crobert@surveycto.com wrote:

ODK Developers,

JavaRosa supports custom functions via the IFunctionHandler interface,
which is handy. It looks like these can be added via the evaluation context
created in FormLoaderTask.java. However, there are two questions I have:

  1. Why doesn't the core ODK team ever use this facility to add JavaRosa
    functions? Rather, new ODK functions seem to be added by hand into
    JavaRosa's XPathFuncExpr.java, in the ODK JavaRosa repo. This makes me
    somewhat suspicious about the stability of the IFunctionHandler interface.

  2. Best I can tell, my old ODK_Validate.jar from about a year ago let
    unknown functions slide (i.e., it didn't generate an errors). With the
    latest ODK_Validate.jar, however, you get errors like
    "org.javarosa.xpath.XPathUnhandledException: XPath evaluation: cannot
    handle function 'testfunc'" if you try to validate a form that includes a
    calculate binding with an unknown function. Is my best option to build a
    custom ODK_Validate.jar with my custom functions defined
    in FormValidator.java's EvaluationContext, or would it be better to
    generate an ODK_Validate.jar that goes back to not caring about unknown
    functions?

I'd be grateful for any thoughts, as always.

Thanks,

Chris

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
You received this message because you are subscribed to the Google Groups
"ODK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.