Project

Profile

Help

XQuery function annotations

Added by Denis Sukhoroslov over 7 years ago

Hi,

I'm trying to process RESTXQ annotations with Saxon-HE 9.7.0-8. I got annotations assigned on XQueryFunction and use them to build REST service around the annotated functions dynamicly. A couple of issues are:

  1. currently annotations is a private field and not accessible directly from external code. So, I use reflection to get them. Is it possible to provide public access to anotations?
  2. the annotations declared as private Map<StructuredQName, Annotation> annotationMap = new HashMap<StructuredQName, Annotation>();

looks like it is not possible to specify the same annotation with different parameters on the same function several times, like the below:

declare %rest:POST %rest:consumes("application/xml") %rest:produces("application/json") %rest:query-param("uri", "{$uri}", "unknown") %rest:query-param("content", "{$content}", "empty") function tpox:create-security($uri as xs:string, $content as xs:string) as item()? { bgdm:store-document(xs:anyURI($uri), $content) };

Currently Saxon just throws exception parsing my module with this function declaration. Wouldn't be better to use another data structure which will allow as to have many annotations with the same name?

Thanks, Denis.


Replies (5)

Please register to reply

RE: XQuery function annotations - Added by Michael Kay over 7 years ago

First concern here is the error message

Annotation rest:query-param appears more than once

As far as I can see, you are right in saying that there is no rule in the XQuery spec to say that two annotations cannot have the same name, and Saxon is wrong to impose such a rule. I will add a test case to the QT3 test suite checking for this situation (which Saxon will fail) - I'll be interested to see if any other vendors challenge this test, suggesting that the rule is simply missing from the spec.

The second point is about revealing function annotations in the Java API. We don't really provide a stable and well documented API to access information about a compiled XQuery module, unless you count the fn:load-xquery-module() function -- but there's nothing like fn:function-annotations() in the standard function library to expose information about function annotations (if there were, then allowing more than one annotation with the same name would certainly complicate this API).

RE: XQuery function annotations - Added by Michael Kay over 7 years ago

I have created a bug entry

https://saxonica.plan.io/issues/2993

to track the spec conformance issue raised here.

RE: XQuery function annotations - Added by Denis Sukhoroslov over 7 years ago

Michael,

yes, as I can see some other products expect the same annotations on one XQuery function, the XQuery/XUnit framework, for instance: https://en.wikibooks.org/wiki/XQuery/XUnit_Annotations#Passing_Parameters_to_Assertions.

regarding the access to compiled module functions and their annotations, it would be very useful for IDEs/XQuery editors which use Saxon under knees. I'm wondering why Oxygen didn't raise the same issue yet..

Thanks, Denis.

RE: XQuery function annotations - Added by Denis Sukhoroslov over 7 years ago

Michael,

I see you've fixed the issue. Thank you so much, it'll save me lot of time. Do you plan to publish a new minor version, or should I build it myself (don't know where the Saxon source repository is, actually)?

Thanks, Denis.

RE: XQuery function annotations - Added by Michael Kay over 7 years ago

Building Saxon-HE isn't a trivial undertaking, so you're probably better off waiting for our next maintenance release. Which is overdue, but we're working on a couple of fairly tough bugs and want to hold it till they are resolved.

The source code of Saxon-HE is available in two forms. The raw source is in Subversion at

https://dev.saxonica.com/repos/archive/opensource/

The preprocessed source for each maintainance release is published as a ZIP file on the sourceforge site - but that doesn't help you if you want access to the latest source fixes.

To compile from the raw source you first need to apply a preprocessing step, which involves downloading the preprocessor tool (I forget its name). It's all there in the Ant build files - but the build files are far more general and complex than you need because they also build Saxon-PE and EE, on both Java and .NET.

    (1-5/5)

    Please register to reply