Merge lp:~zorba-coders/zorba/move-xqxq-core into lp:zorba

Proposed by Chris Hillery
Status: Merged
Approved by: Juan Zacarias
Approved revision: 11112
Merged at revision: 11112
Proposed branch: lp:~zorba-coders/zorba/move-xqxq-core
Merge into: lp:zorba
Diff against target: 2428 lines (+2067/-1)
62 files modified
ChangeLog (+1/-0)
modules/CMakeLists.txt (+1/-0)
modules/ExternalModules.conf (+0/-1)
modules/xqxq/CMakeLists.txt (+15/-0)
modules/xqxq/xqxq.xq (+381/-0)
modules/xqxq/xqxq.xq.src/xqxq.cpp (+817/-0)
modules/xqxq/xqxq.xq.src/xqxq.h (+456/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res (+2/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res (+2/-0)
test/rbkt/Queries/zorba/xqxq/bind-context-item.xq (+6/-0)
test/rbkt/Queries/zorba/xqxq/bind-variable.xq (+4/-0)
test/rbkt/Queries/zorba/xqxq/context-item.xml (+1/-0)
test/rbkt/Queries/zorba/xqxq/delete.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/delete.xq (+5/-0)
test/rbkt/Queries/zorba/xqxq/error-in-query.spec (+2/-0)
test/rbkt/Queries/zorba/xqxq/error-in-query.xq (+21/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-sequential.xq (+17/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq (+6/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq (+7/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/evaluate-updating2.xq (+15/-0)
test/rbkt/Queries/zorba/xqxq/evaluate.xq (+5/-0)
test/rbkt/Queries/zorba/xqxq/evaluate2.xq (+6/-0)
test/rbkt/Queries/zorba/xqxq/evaluate3.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/evaluate3.xq (+15/-0)
test/rbkt/Queries/zorba/xqxq/external-module.xq (+8/-0)
test/rbkt/Queries/zorba/xqxq/get-external-variables.xq (+4/-0)
test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq (+4/-0)
test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq (+10/-0)
test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq (+7/-0)
test/rbkt/Queries/zorba/xqxq/is-sequential.xq (+18/-0)
test/rbkt/Queries/zorba/xqxq/is-updating.xq (+20/-0)
test/rbkt/Queries/zorba/xqxq/multiple-queries.xq (+9/-0)
test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec (+1/-0)
test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq (+3/-0)
test/rbkt/Queries/zorba/xqxq/test.xml (+1/-0)
test/rbkt/Queries/zorba/xqxq/test.xsd (+14/-0)
test/rbkt/Queries/zorba/xqxq/uri-mapper.xq (+27/-0)
test/rbkt/Queries/zorba/xqxq/uri-mapper2.xq (+22/-0)
test/rbkt/Queries/zorba/xqxq/url-module-resolver.xq (+17/-0)
test/rbkt/Queries/zorba/xqxq/url-schema-resolver.xq (+20/-0)
test/rbkt/Queries/zorba/xqxq/url-schema-resolver2.xq (+29/-0)
test/rbkt/Queries/zorba/xqxq/url-schema-resolver3.xq (+29/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/move-xqxq-core
Reviewer Review Type Date Requested Status
Juan Zacarias Approve
Matthias Brantner Approve
Chris Hillery Approve
Review via email: mp+131295@code.launchpad.net

Commit message

Moved XQXQ into Zorba core.

To post a comment you must log in.
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Conditional approval because everything seems to work.

However, the ChangeLog should be updated and an email should be sent to the list letting everybody know that they have to remove xqxq from their zorba_modules directories.

review: Approve
11112. By Chris Hillery

Updated ChangeLog.

Revision history for this message
Chris Hillery (ceejatec) wrote :

I have pushed a ChangeLog change.

Tested locally: If I bump the XQXQ version number to 1.1, it can actually co-exist with the non-core module. Should I do this for convenience, or is it better to force people to remove the old one?

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

> I have pushed a ChangeLog change.
>
> Tested locally: If I bump the XQXQ version number to 1.1, it can actually co-
> exist with the non-core module. Should I do this for convenience, or is it
> better to force people to remove the old one?
Good question. My feeling is that the old one should be removed because both of the modules provide exactly the same functionality.

Revision history for this message
Chris Hillery (ceejatec) wrote :

> My feeling is that the old one should be removed because both
> of the modules provide exactly the same functionality.

I tend to agree. Ok, I won't push that change, and I'll send out an email.

Juan, please review soon; thanks!

Revision history for this message
Juan Zacarias (juan457) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job move-xqxq-core-2012-10-26T14-50-00.735Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'ChangeLog'
--- ChangeLog 2012-10-24 12:49:43 +0000
+++ ChangeLog 2012-10-25 00:20:28 +0000
@@ -11,6 +11,7 @@
11 * Optimized the MarkFreeVars optimizer rule11 * Optimized the MarkFreeVars optimizer rule
1212
13Bug Fixes/Other Changes:13Bug Fixes/Other Changes:
14 * Change XQXQ (XQuery-for-XQuery) module now part of Zorba core
14 * Fixed mustCopyInputNodes() method of no-copy, and jsoniq functions.15 * Fixed mustCopyInputNodes() method of no-copy, and jsoniq functions.
15 * Fixed bug #868640 (Node lifetime is shorter than expected due to let16 * Fixed bug #868640 (Node lifetime is shorter than expected due to let
16 variable inlining)17 variable inlining)
1718
=== modified file 'modules/CMakeLists.txt'
--- modules/CMakeLists.txt 2012-09-19 21:16:15 +0000
+++ modules/CMakeLists.txt 2012-10-25 00:20:28 +0000
@@ -15,6 +15,7 @@
15ADD_SUBDIRECTORY(com)15ADD_SUBDIRECTORY(com)
16ADD_SUBDIRECTORY(org)16ADD_SUBDIRECTORY(org)
17ADD_SUBDIRECTORY(functx)17ADD_SUBDIRECTORY(functx)
18ADD_SUBDIRECTORY(xqxq)
18ADD_SUBDIRECTORY(w3c)19ADD_SUBDIRECTORY(w3c)
1920
20# Add external module projects - any subdirectories of a directory21# Add external module projects - any subdirectories of a directory
2122
=== modified file 'modules/ExternalModules.conf'
--- modules/ExternalModules.conf 2012-10-23 21:21:20 +0000
+++ modules/ExternalModules.conf 2012-10-25 00:20:28 +0000
@@ -42,7 +42,6 @@
42read-pdf bzr lp:zorba/read-pdf-module zorba-2.742read-pdf bzr lp:zorba/read-pdf-module zorba-2.7
43security bzr lp:zorba/security-module43security bzr lp:zorba/security-module
44system bzr lp:zorba/system-module zorba-2.744system bzr lp:zorba/system-module zorba-2.7
45xqxq bzr lp:zorba/xqxq-module zorba-2.7
46email bzr lp:zorba/email-module zorba-2.745email bzr lp:zorba/email-module zorba-2.7
47util-jvm bzr lp:zorba/util-jvm-module zorba-2.746util-jvm bzr lp:zorba/util-jvm-module zorba-2.7
48schema-tools bzr lp:zorba/schema-tools-module zorba-2.747schema-tools bzr lp:zorba/schema-tools-module zorba-2.7
4948
=== added directory 'modules/xqxq'
=== added file 'modules/xqxq/CMakeLists.txt'
--- modules/xqxq/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ modules/xqxq/CMakeLists.txt 2012-10-25 00:20:28 +0000
@@ -0,0 +1,15 @@
1# Copyright 2006-2012 The FLWOR Foundation.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/xqxq" VERSION 1.0 FILE "xqxq.xq")
0\ No newline at end of file16\ No newline at end of file
117
=== added file 'modules/xqxq/xqxq.xq'
--- modules/xqxq/xqxq.xq 1970-01-01 00:00:00 +0000
+++ modules/xqxq/xqxq.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,381 @@
1xquery version "3.0";
2(:
3 : Copyright 2011 The FLWOR Foundation.
4 :
5 : Licensed under the Apache License, Version 2.0 (the "License");
6 : you may not use this file except in compliance with the License.
7 : You may obtain a copy of the License at
8 :
9 : http://www.apache.org/licenses/LICENSE-2.0
10 :
11 : Unless required by applicable law or agreed to in writing, software
12 : distributed under the License is distributed on an "AS IS" BASIS,
13 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 : See the License for the specific language governing permissions and
15 : limitations under the License.
16:)
17
18(:~
19 : This module contains functions to compile and evaluate XQuery
20 : programs. Also, it contains function that allow to parameterize
21 : the static or dynamic evaluation phase.
22 :
23 : @author Juan Zacarias
24 : @project Zorba/Programming Languages/XQuery
25 :)
26module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
27
28declare namespace an = "http://www.zorba-xquery.com/annotations";
29declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
30declare namespace op = "http://www.zorba-xquery.com/options/features";
31declare namespace f = "http://www.zorba-xquery.com/features";
32
33declare option ver:module-version "1.0";
34declare option op:enable "f:hof";
35
36(:~
37 : The function prepares a given XQuery program for execution.
38 : If the program was successfully compiled, the function returns an
39 : identifier as xs:anyURI. This URI can be passed to other functions
40 : of this module (e.g. to actually evaluate the program). The URI
41 : is opaque and its lilfetime is bound by the lifetime of the XQuery
42 : program that invoked this function. Further reference or uses
43 : of the identifier lead to unexpected results.
44 :
45 : Successfully prepared queries need to be deleted by passing the resulting
46 : identifier to the xqxq:delete-query function of this module.
47 :
48 : @param $main-module-text the XQuery program that should be prepared.
49 : The program needs to be a XQuery main module.
50 :
51 : @return an identifier for the compiled program that can be passed
52 : as arguments to other functions of this module.
53 :
54 : @error any (static or type) error that may be raised during the compilation
55 : of the query. For example, err:XPST0003 if the given XQuery program could
56 : not be parsed.
57 :)
58declare %an:sequential function xqxq:prepare-main-module($main-module-text as xs:string) as
59 xs:anyURI external;
60
61(:~
62 : The function prepares a given XQuery program for execution.
63 : If the program was successfully compiled, the function returns an
64 : identifier as xs:anyURI. This URI can be passed to other functions
65 : of this module (e.g. to actually evaluate the program). The URI
66 : is opaque and its lilfetime is bound by the lifetime of the XQuery
67 : program that invoked this function. Further reference or uses
68 : of the identifier lead to unexpected results.
69 :
70 : Important notes regarding the second and third parameters of the function:
71 : --------------------------------------------------------------------------
72 :
73 : These parameters allow you to specify a URL resolver and a URI mapper
74 : for Zorba to use when executing this query. See
75 : http://www.zorba-xquery.com/html/documentation/2.7.0/zorba/uriresolvers
76 :
77 : The second parameter is a function item for a URL
78 : resolver. The URL resolver function must recive 2 parameters:
79 : A $namespace as xs:string that will contain the url to be resolved.
80 : A $entity as xs:string that will contain the type of resolving needed;
81 : this can be 2 values "module" and "schema".
82 : The function must return an empty sequence when the specified $namespace
83 : or $entity are not the ones to be resolved.
84 :
85 : Example:
86 :
87 : declare function mymod:url-resolver($namespace as xs:string, $entity as xs:string)
88 : {
89 : if($namespace = 'http://test.xq')
90 : then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
91 : else ()
92 : };
93 :
94 : The URL resolver function's namespace, name, and parameter naming are
95 : not restricted by XQXQ.
96 :
97 : The URL resolver function's return type is not restricted, it could be a string, a sequence,
98 : a node, etc. All the outputs types are to be serialized as a string.
99 :
100 : The third parameter is a function item for a URI mapper.
101 : The URI mapper function, just like the URL resolver, receives 2 parameters:
102 : A $namespace as xs:string that will contain the URI to be mapped.
103 : A $entity as xs:string that will contain the type of resolving needed;
104 : this can be 2 values "module" and "schema".
105 : The URI mapper must return an empty sequence when the specified $namesapce or $entity
106 : are not to be mapped. Unlike the URL resolver this function must return a sequence of strings.
107 :
108 : Example:
109 :
110 : declare function mymod:uri-mapper($namespace as xs:string, $entity as xs:string)
111 : {
112 : if($namespace = 'http://test')
113 : then ("http://www.zorba-xquery.com/test", "http://foo.com/schema/test")
114 : else ()
115 : };
116 :
117 : The URI mapper function's namespace, name, and parameter naming are
118 : not restricted by XQXQ.
119 :
120 : In order to pass the above URL resolver and URI mapper to this function,
121 : use the following syntax:
122 :
123 : variable $queryID := xqxq:prepare-main-module("..query text..",
124 : mymod:url-resolver#2, mymod:uri-mapper#2);
125 :
126 : That is, the QName of the function followed by "#2". This is XQuery
127 : "higher-order function" syntax, meaning the function with the specified
128 : QName which takes two arguments. Since URL resolvers and URI mappers
129 : must take two arguments, both will always be specified with "#2".
130 :
131 : Note that parameters 2 and 3 should be declared as follows:
132 : as function($url as xs:string, $entity as xs:string) as item()
133 : as function($uri as xs:string, $entity as xs:string) as xs:string*
134 : However Zorba's implementation of higher-order functions (HOF) is not
135 : yet complete enough to allow for this. When Zorba's HOF implementation
136 : is complete this function signature will be changed.
137 :
138 : Both the URL resolver and URI mapper functions are optional, meaning you
139 : may pass the empty-sequence () for either.
140 :
141 : Successfully prepared queries need to be deleted by passing the resulting
142 : identifier to the xqxq:delete-query function of this module.
143 :
144 : @param $main-module-text the XQuery program that should be prepared.
145 : The program needs to be a XQuery main module.
146 :
147 : @param $resolver the URL resolver function.
148 :
149 : @param $mapper the URI mapper function.
150 :
151 : @return an identifier for the compiled program that can be passed
152 : as arguments to other functions of this module.
153 :
154 : @error any (static or type) error that may be raised during the compilation
155 : of the query. For example, err:XPST0003 if the given XQuery program could
156 : not be parsed.
157 :)
158declare %an:sequential function xqxq:prepare-main-module($main-module-text as xs:string, $resolver as item()?, $mapper as item()?) as
159 xs:anyURI external;
160
161(:~
162 : This function compiles a given XQuery library module. It can be used
163 : to compile-check a module.
164 :
165 : @param $library-module-text the XQuery library module that should
166 : be prepared.
167 :
168 : @return the function is declared as sequential.It returns the
169 : empty-sequence.
170 :
171 : @error any (static or type) error that may be raised during the compilation
172 : of the library module. For example, err:XPST0003 if the given XQuery library
173 : module could not be parsed.
174 :)
175declare %an:sequential function xqxq:prepare-library-module($library-module-text as xs:string) as
176 empty-sequence() external ;
177
178(:~
179 : The function tests if the context-item is bound for the
180 : execution of the query referred to by the given query identifier.
181 :
182 : @param $query-key the identifier for a compiled query
183 :
184 : @return true if the context-item is bound, false otherwise.
185 :
186 : @error xqxq:NoQueryMatch if no query with the given identifier
187 : was prepared.
188 :)
189declare function xqxq:is-bound-context-item($query-key as xs:anyURI)
190 as xs:boolean external;
191
192
193(:~
194 : The function tests if the given variable is bound for the
195 : execution of the query referred to by the given query identifier.
196 :
197 : @param $query-key the identifier for a compiled query
198 : @param $var-name the name of the variable
199 :
200 : @return true if the variable is bound, false otherwise.
201 :
202 : @error xqxq:NoQueryMatch if no query with the given identifier
203 : was prepared.
204 : @error xqxq:UndeclaredVariable if the given variable is not declared
205 : in the query.
206 :)
207declare function xqxq:is-bound-variable($query-key as xs:anyURI, $var-name as
208 xs:QName) as xs:boolean external;
209
210(:~
211 : The function returns the names of the external variables that
212 : are declared in the given query (either in the main module or
213 : in any of the imported library modules).
214 :
215 : @param $query-key the identifier for a compiled query
216 :
217 : @return the sequence of names of the said external variables.
218 :
219 : @error xqxq:NoQueryMatch if no query with the given identifier
220 : was prepared.
221 :)
222declare function xqxq:external-variables($query-key as xs:anyURI) as
223 xs:QName* external ;
224
225(:~
226 : The function tests if the query identified by the given key
227 : is an updating query.
228 :
229 : @param $query-key the identifier for a compiled query
230 :
231 : @return true if the query is an updating query, false otherwise.
232 :
233 : @error xqxq:NoQueryMatch if no query with the given identifier
234 : was prepared.
235 :)
236declare function xqxq:is-updating($query-key as xs:anyURI) as
237 xs:boolean external;
238
239(:~
240 : The function tests if the query identified by the given key
241 : is sequential query.
242 :
243 : @param $query-key the identifier for a compiled query
244 :
245 : @return true if the query is a sequential, false otherwise.
246 :
247 : @error xqxq:NoQueryMatch if no query with the given identifier
248 : was prepared.
249 :)
250declare function xqxq:is-sequential($query-key as xs:anyURI) as
251 xs:boolean external;
252
253(:~
254 : This function binds the context-item of the prepared query
255 : identified by the given key to the $dot argument.
256 :
257 : @param $query-key the identifier for a compiled query
258 : @param $dot the context item to bind
259 :
260 : @return the function has side effects and returns the empty
261 : sequence.
262 :
263 : @error xqxq:NoQueryMatch if no query with the given identifier
264 : was prepared.
265 :)
266declare %an:sequential function xqxq:bind-context-item($query-key as xs:anyURI,
267 $dot as item()) as empty-sequence() external ;
268
269(:~
270 : This function binds the variable with name $name of
271 : the prepared query identified by $query-key to the given sequence.
272 :
273 : @param $query-key the identifier for a compiled query
274 : @param $name the name of the external variable to bind
275 : @param $value the sequence to which the external variable $name
276 : should be bound
277 :
278 : @return the function has side effects and returns the empty
279 : sequence.
280 :
281 : @error xqxq:NoQueryMatch if no query with the given identifier
282 : was prepared.
283 : @error xqxq:UndeclaredVariable if the given variable is not declared
284 : in the query.
285 :)
286declare %an:sequential function xqxq:bind-variable($query-key as xs:anyURI,
287 $var as xs:QName, $value as item()*) as empty-sequence() external ;
288
289
290(:~
291 : Evaluates the given prepared query and returns the result
292 : of the evaluation. The query must not be sequential or
293 : updating.
294 :
295 : @param $query-key the identifier for a compiled query
296 :
297 : @return the result of evaluating the given query
298 :
299 : @error xqxq:NoQueryMatch if no query with the given identifier
300 : was prepared.
301 :
302 : @error xqxq:QueryIsUpdating if the query is an updating query.
303 :
304 : @error xqxq:QueryIsSequential if the query is sequential.
305 :
306 : @error any dynamic error that is raised by evaluating the
307 : given query.
308 :
309 :)
310declare function xqxq:evaluate($query-key as xs:anyURI) as item()* external;
311
312(:~
313 : Evaluates the given prepared query and applies the updates
314 : computed by this query. The query must be an updating query.
315 :
316 : @param $query-key the identifier for a compiled query
317 :
318 : @return the function has side effects because it applies
319 : the updates of the query. It returns the empty sequence.
320 :
321 : @error xqxq:NoQueryMatch if no query with the given identifier
322 : was prepared.
323 :
324 : @error xqxq:QueryNotUpdating if the query is not an updating query.
325 :
326 : @error xqxq:QueryIsSequential if the query is sequential.
327 :
328 : @error any dynamic error that is raised by evaluating the
329 : given query or applying its updates.
330 :
331 :)
332declare updating function xqxq:evaluate-updating($query-key as xs:anyURI) external;
333
334(:~
335 : Evaluates the given prepared query and returns the result
336 : of the evaluation. The query must be sequential.
337 :
338 : @param $query-key the identifier for a compiled query
339 :
340 : @return the result of evaluating the query.
341 :
342 : @error xqxq:NoQueryMatch if no query with the given identifier
343 : was prepared.
344 :
345 : @error xqxq:QueryNotSequential if the query is not sequential.
346 :
347 : @error xqxq:QueryIsUpdating if the query is an updating query.
348 :
349 : @error any dynamic error that is raised by evaluating the
350 : given query.
351 :
352 :)
353declare %an:sequential function xqxq:evaluate-sequential($query-key as
354 xs:string) as item()* external;
355
356(:~
357 : Deletes the prepared query associated with the given identifier.
358 : After the query is deleted, the corresponding identifier should
359 : not be used as argument to any of the functions of this module.
360 :
361 : @param $query-key the identifier for a compiled query
362 :
363 : @return the function has side effects and returns the empty sequence.
364 :
365 : @error xqxq:NoQueryMatch if no query with the given identifier
366 : was prepared.
367 :
368 :)
369declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
370 empty-sequence() external;
371
372
373(:~
374 : Internal helper function. Only necessary because of incomplete HOF
375 : support in Zorba.
376 :)
377declare %private function xqxq:hof-invoker($hof as item(),
378 $ns as xs:string, $entity as xs:string) as item()*
379{
380 $hof($ns, $entity)
381};
0382
=== added directory 'modules/xqxq/xqxq.xq.src'
=== added file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
--- modules/xqxq/xqxq.xq.src/xqxq.cpp 1970-01-01 00:00:00 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.cpp 2012-10-25 00:20:28 +0000
@@ -0,0 +1,817 @@
1#include <zorba/item_factory.h>
2#include <zorba/singleton_item_sequence.h>
3#include <zorba/diagnostic_list.h>
4#include <zorba/empty_sequence.h>
5#include <zorba/store_manager.h>
6#include <zorba/user_exception.h>
7#include <zorba/uri_resolvers.h>
8#include <zorba/vector_item_sequence.h>
9#include <zorba/serializer.h>
10#include <zorba/xquery.h>
11#include <time.h>
12#include <stdio.h>
13#include <zorba/util/uuid.h>
14#include <vector>
15
16#include "xqxq.h"
17
18namespace zorba { namespace xqxq {
19
20 /*******************************************************************************************
21 *******************************************************************************************/
22
23 zorba::ExternalFunction*
24 XQXQModule::getExternalFunction(const zorba::String& localName)
25 {
26
27 FuncMap_t::iterator lIte = theFunctions.find(localName);
28
29 ExternalFunction*& lFunc = theFunctions[localName];
30
31 if (lIte == theFunctions.end())
32 {
33 if (localName == "prepare-main-module")
34 {
35 lFunc = new PrepareMainModuleFunction(this);
36 }
37 if (localName == "prepare-library-module")
38 {
39 lFunc = new PrepareLibraryModuleFunction(this);
40 }
41 else if (localName == "is-bound-context-item")
42 {
43 lFunc = new IsBoundContextItemFunction(this);
44 }
45 else if (localName == "is-bound-variable")
46 {
47 lFunc = new IsBoundVariableFunction(this);
48 }
49 else if (localName == "external-variables")
50 {
51 lFunc = new GetExternalVariablesFunction(this);
52 }
53 else if (localName == "is-updating")
54 {
55 lFunc = new IsUpdatingFunction(this);
56 }
57 else if (localName == "is-sequential")
58 {
59 lFunc = new IsSequentialFunction(this);
60 }
61 else if (localName == "bind-context-item")
62 {
63 lFunc = new BindContextItemFunction(this);
64 }
65 else if (localName == "bind-variable")
66 {
67 lFunc = new BindVariableFunction(this);
68 }
69 else if (localName == "evaluate")
70 {
71 lFunc = new EvaluateFunction(this);
72 }
73 else if (localName == "evaluate-updating")
74 {
75 lFunc = new EvaluateUpdatingFunction(this);
76 }
77 else if (localName == "evaluate-sequential")
78 {
79 lFunc = new EvaluateSequentialFunction(this);
80 }
81 else if (localName == "delete-query")
82 {
83 lFunc = new DeleteQueryFunction(this);
84 }
85 }
86
87 return lFunc;
88 }
89
90 void XQXQModule::destroy()
91 {
92 delete this;
93 }
94
95 XQXQModule::~XQXQModule()
96 {
97 for (FuncMap_t::const_iterator lIter = theFunctions.begin();
98 lIter != theFunctions.end(); ++lIter)
99 {
100 delete lIter->second;
101 }
102 theFunctions.clear();
103 }
104
105 /*******************************************************************************************
106 *******************************************************************************************/
107 XQXQFunction::XQXQFunction(const XQXQModule* aModule)
108 : theModule(aModule)
109 {
110 srand(time(NULL));
111 }
112
113 XQXQFunction::~XQXQFunction()
114 {
115
116 }
117
118 String XQXQFunction::getURI() const
119 {
120 return theModule->getURI();
121 }
122
123 String
124 XQXQFunction::getOneStringArgument(const Arguments_t& aArgs, int aPos) const
125 {
126 Item lItem;
127 Iterator_t args_iter = aArgs[aPos]->getIterator();
128 args_iter->open();
129 args_iter->next(lItem);
130 String lTmpString = lItem.getStringValue();
131 args_iter->close();
132 return lTmpString;
133 }
134
135
136 Item
137 XQXQFunction::getItemArgument(const Arguments_t& aArgs, int aPos) const
138 {
139 Item lItem;
140 Iterator_t args_iter = aArgs[aPos]->getIterator();
141 args_iter->open();
142 args_iter->next(lItem);
143 args_iter->close();
144
145 return lItem;
146 }
147
148 Iterator_t
149 XQXQFunction::getIterArgument(const Arguments_t& aArgs, int aPos) const
150 {
151 Iterator_t args_iter = aArgs[aPos]->getIterator();
152 return args_iter;
153 }
154
155 XQuery_t
156 XQXQFunction::getQuery(
157 const zorba::DynamicContext* aDctx,
158 const zorba::String& aIdent) const
159 {
160 QueryMap* lQueryMap;
161 if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
162 {
163 throwError("NoQueryMatch", "No query with the given identifier was found");
164 }
165
166 XQuery_t lQuery;
167 if (!(lQuery = lQueryMap->getQuery(aIdent)))
168 throwError("NoQueryMatch", "No query with the given identifier was found");
169
170 return lQuery;
171 }
172
173 void
174 XQXQFunction::throwError(const char *err_localname, const std::string aErrorMessage)
175 {
176 String errNS(XQXQ_MODULE_NAMESPACE);
177 String errName(err_localname);
178 Item errQName = XQXQModule::getItemFactory()->createQName(errNS, errName);
179 String errDescription(aErrorMessage);
180 throw USER_EXCEPTION(errQName, errDescription);
181 }
182
183 /*******************************************************************************************
184 *******************************************************************************************/
185
186 QueryData::QueryData(XQuery_t aQuery, URIMapper *aMapper, URLResolver *aResolver)
187 : theQuery(aQuery),
188 theURIMapper(aMapper),
189 theURLResolver(aResolver)
190 {
191 }
192
193 QueryData::~QueryData()
194 {
195 theQuery->close();
196 delete theURIMapper;
197 delete theURLResolver;
198 }
199
200 /*******************************************************************************************
201 *******************************************************************************************/
202
203 QueryMap::QueryMap()
204 {
205 QueryMap::queryMap = new QueryMap_t();
206 }
207
208 bool
209 QueryMap::storeQuery(const String& aKeyName, XQuery_t aQuery,
210 URIMapper* aMapper, URLResolver* aResolver)
211 {
212 QueryData_t lQueryData(new QueryData(aQuery, aMapper, aResolver));
213 std::pair<QueryMap_t::iterator,bool> ret;
214 ret = queryMap->insert(std::pair<String, QueryData_t>(aKeyName, lQueryData));
215 return ret.second;
216 }
217
218 XQuery_t
219 QueryMap::getQuery(const String& aKeyName)
220 {
221 QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName);
222
223 if(lIter == queryMap->end())
224 return NULL;
225
226 XQuery_t lQuery = lIter->second->getQuery();
227
228 return lQuery;
229 }
230
231 bool
232 QueryMap::deleteQuery(const String& aKeyName)
233 {
234 QueryMap::QueryMap_t::iterator lIter = queryMap->find(aKeyName);
235
236 if(lIter == queryMap->end())
237 return false;
238
239 queryMap->erase(lIter);
240 return true;
241 }
242
243 void
244 QueryMap::destroy() throw()
245 {
246 if(queryMap)
247 {
248 for (QueryMap_t::const_iterator lIter = queryMap->begin();
249 lIter != queryMap->end(); ++lIter)
250 {
251 deleteQuery(lIter->first);
252 }
253 queryMap->clear();
254 delete queryMap;
255 }
256 delete this;
257 }
258
259 /*******************************************************************************************
260 *******************************************************************************************/
261 static void streamReleaser(std::istream* aStream)
262 {
263 delete aStream;
264 }
265
266 void
267 PrepareMainModuleFunction::XQXQURIMapper::mapURI(
268 String aUri,
269 EntityData const* aEntityData,
270 std::vector<String>& oUris)
271 {
272 //Create entityData string to send to the new url resolver
273 String lDataKind;
274 switch (aEntityData->getKind())
275 {
276 case EntityData::SCHEMA:
277 lDataKind = "schema";
278 break;
279 case EntityData::MODULE:
280 lDataKind = "module";
281 break;
282 default:
283 break;
284 }
285
286 //construct the arguments for the url resolver
287 std::vector<ItemSequence_t> lArgs;
288 ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
289 ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
290 ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
291 lArgs.push_back(lSeq0);
292 lArgs.push_back(lSeq1);
293 lArgs.push_back(lSeq2);
294
295 //invoke the HOF helper function using the arguments generated
296 Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
297 ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
298
299 //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
300 //and then checking if it was empty.
301 Iterator_t lIter = lResult->getIterator();
302 Item lItem;
303 lIter->open();
304 while (lIter->next(lItem))
305 {
306 std::cout << lItem.getStringValue() << std::endl;
307 oUris.push_back(lItem.getStringValue());
308 }
309 lIter->close();
310
311 }
312
313
314 Resource*
315 PrepareMainModuleFunction::XQXQURLResolver::resolveURL(
316 const String& aUrl,
317 EntityData const* aEntityData)
318 {
319 //Create entityData string to send to the new url resolver
320 String lDataKind;
321 switch (aEntityData->getKind())
322 {
323 case EntityData::SCHEMA:
324 lDataKind = "schema";
325 break;
326 case EntityData::MODULE:
327 lDataKind = "module";
328 break;
329 default:
330 break;
331 }
332
333 //construct the arguments for the url resolver
334 std::vector<ItemSequence_t> lArgs;
335 ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
336 ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
337 ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
338 lArgs.push_back(lSeq0);
339 lArgs.push_back(lSeq1);
340 lArgs.push_back(lSeq2);
341
342 //invoke the HOF helper function using the arguments generated
343 Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
344 ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
345
346 //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
347 //and then checking if it was empty.
348 Iterator_t lIter = lResult->getIterator();
349 Item lItem;
350 lIter->open();
351 lIter->next(lItem);
352 lIter->close();
353 if (lItem.isNull())
354 return NULL;
355
356 //Serialize resulting sequence of the resolver
357 Zorba_SerializerOptions_t lOpt;
358 if (lItem.isNode())
359 lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
360 else
361 lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
362 lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
363 Serializer_t lSer = Serializer::createSerializer(lOpt);
364 std::stringstream lSerResult;
365 lSer->serialize(lResult, lSerResult);
366
367 //return resource
368 return StreamResource::create(new std::istringstream(lSerResult.str()), &streamReleaser);
369 }
370
371 zorba::ItemSequence_t
372 PrepareMainModuleFunction::evaluate(
373 const Arguments_t& aArgs,
374 const zorba::StaticContext* aSctx,
375 const zorba::DynamicContext* aDctx) const
376 {
377 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
378 StaticContext_t lSctxChild = aSctx->createChildContext();
379
380 QueryMap* lQueryMap;
381 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
382 {
383 lQueryMap = new QueryMap();
384 lDynCtx->addExternalFunctionParameter("xqxqQueryMap", lQueryMap);
385 }
386
387 Zorba *lZorba = Zorba::getInstance(0);
388
389 String lQueryString = getOneStringArgument(aArgs, 0);
390
391 XQuery_t lQuery;
392
393 StaticContext_t ltempSctx = lZorba->createStaticContext();
394 std::auto_ptr<XQXQURLResolver> lResolver;
395 std::auto_ptr<XQXQURIMapper> lMapper;
396
397 if ( aArgs.size() > 2 )
398 {
399 Item lMapperFunctionItem = getItemArgument(aArgs, 2);
400 if (!lMapperFunctionItem.isNull())
401 {
402 lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
403 ltempSctx->registerURIMapper(lMapper.get());
404 }
405 }
406
407 if ( aArgs.size() > 1 )
408 {
409 Item lResolverFunctionItem = getItemArgument(aArgs, 1);
410 if (!lResolverFunctionItem.isNull())
411 {
412 lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
413 ltempSctx->registerURLResolver(lResolver.get());
414 }
415
416 }
417
418 try
419 {
420 lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
421 }
422 catch (XQueryException& xe)
423 {
424 lQuery = NULL;
425 std::ostringstream err;
426 err << "The query compiled using xqxq:prepare-main-module raised an error at"
427 << " line " << xe.source_line() << " column " << xe.source_column() << ": " << xe.what();
428 Item errQName = XQXQModule::getItemFactory()->createQName(
429 xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
430 throw USER_EXCEPTION(errQName, err.str());
431 }
432 catch (ZorbaException& e)
433 {
434 lQuery = NULL;
435 std::ostringstream err;
436 err << "The query compiled using xqxq:prepare-main-module raised an error: "
437 << e.what();
438 Item errQName = XQXQModule::getItemFactory()->createQName(
439 e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
440 throw USER_EXCEPTION(errQName, err.str());
441 }
442
443 uuid lUUID;
444 uuid::create(&lUUID);
445
446 std::stringstream lStream;
447 lStream << lUUID;
448
449 String lStrUUID = lStream.str();
450
451 lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
452
453 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
454 }
455
456
457 /*******************************************************************************************
458 *******************************************************************************************/
459 zorba::ItemSequence_t
460 PrepareLibraryModuleFunction::evaluate(
461 const Arguments_t& aArgs,
462 const zorba::StaticContext* aSctx,
463 const zorba::DynamicContext* aDctx) const
464 {
465 Zorba *lZorba = Zorba::getInstance(0);
466 String lQueryString = getOneStringArgument(aArgs, 0);
467
468 Zorba_CompilerHints_t hints;
469 hints.lib_module = true;
470
471 try
472 {
473 lZorba->compileQuery(lQueryString, hints);
474 }
475 catch (XQueryException& xe)
476 {
477 std::ostringstream err;
478 err << "The query compiled using xqxq:prepare-library-module raised an error at"
479 << " line " << xe.source_line() << " column " << xe.source_column() << ": " << xe.what();
480 Item errQName = XQXQModule::getItemFactory()->createQName(
481 xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
482 throw USER_EXCEPTION(errQName, err.str());
483 }
484 catch (ZorbaException& e)
485 {
486 std::ostringstream err;
487 err << "The query compiled using xqxq:prepare-main-query raised an error: "
488 << e.what();
489 Item errQName = XQXQModule::getItemFactory()->createQName(
490 e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
491 throw USER_EXCEPTION(errQName, err.str());
492 }
493 return ItemSequence_t(new EmptySequence());
494 }
495
496 /*******************************************************************************************
497 *******************************************************************************************/
498 zorba::ItemSequence_t
499 IsBoundContextItemFunction::evaluate(
500 const Arguments_t& aArgs,
501 const zorba::StaticContext* aSctx,
502 const zorba::DynamicContext* aDctx) const
503 {
504
505 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
506
507 XQuery_t lQuery = getQuery(aDctx, lQueryID);
508
509 bool lIsContextItemBound = lQuery->getDynamicContext()->isBoundContextItem();
510
511 return ItemSequence_t(new SingletonItemSequence(
512 XQXQModule::getItemFactory()->createBoolean(lIsContextItemBound)));
513 }
514
515 /*******************************************************************************************
516 *******************************************************************************************/
517 zorba::ItemSequence_t
518 IsBoundVariableFunction::evaluate(
519 const Arguments_t& aArgs,
520 const zorba::StaticContext* aSctx,
521 const zorba::DynamicContext* aDctx) const
522 {
523 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
524
525 XQuery_t lQuery = getQuery(aDctx, lQueryID);
526
527 Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
528 bool lIsBoundVariable = false;
529
530 try
531 {
532 lIsBoundVariable = lQuery->getDynamicContext()->isBoundExternalVariable(lVarQName.getNamespace(),lVarQName.getLocalName());
533 }
534 catch (ZorbaException& ze)
535 {
536 if (ze.diagnostic() == zerr::ZAPI0011_ELEMENT_NOT_DECLARED)
537 XQXQFunction::throwError("UndeclaredVariable", ze.what());
538 throw; // should not happen
539 }
540 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lIsBoundVariable)));
541
542 }
543
544 /*******************************************************************************************
545 *******************************************************************************************/
546 zorba::ItemSequence_t
547 GetExternalVariablesFunction::evaluate(
548 const Arguments_t& aArgs,
549 const zorba::StaticContext* aSctx,
550 const zorba::DynamicContext* aDctx) const
551 {
552
553 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
554
555 XQuery_t lQuery = getQuery(aDctx, lQueryID);
556
557 std::vector<Item> lVars;
558 Iterator_t lVarsIterator;
559 lQuery->getExternalVariables(lVarsIterator);
560
561 Item lVar;
562 lVarsIterator->open();
563 while(lVarsIterator->next(lVar))
564 lVars.push_back(lVar);
565 lVarsIterator->close();
566
567 return ItemSequence_t(new VectorItemSequence(lVars));
568 }
569 /*******************************************************************************************
570 *******************************************************************************************/
571 zorba::ItemSequence_t
572 IsUpdatingFunction::evaluate(
573 const Arguments_t& aArgs,
574 const zorba::StaticContext* aSctx,
575 const zorba::DynamicContext* aDctx) const
576 {
577 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
578
579 XQuery_t lQuery = getQuery(aDctx, lQueryID);
580
581 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isUpdating())));
582 }
583
584 /*******************************************************************************************
585 *******************************************************************************************/
586 zorba::ItemSequence_t
587 IsSequentialFunction::evaluate(
588 const Arguments_t& aArgs,
589 const zorba::StaticContext* aSctx,
590 const zorba::DynamicContext* aDctx) const
591 {
592 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
593
594 XQuery_t lQuery = getQuery(aDctx, lQueryID);
595
596 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isSequential())));
597 }
598
599 /*******************************************************************************************
600 *******************************************************************************************/
601 zorba::ItemSequence_t
602 BindContextItemFunction::evaluate(
603 const Arguments_t& aArgs,
604 const zorba::StaticContext* aSctx,
605 const zorba::DynamicContext* aDctx) const
606 {
607 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
608
609 XQuery_t lQuery = getQuery(aDctx, lQueryID);
610
611 // shouldn't raise errors
612 Item lItemContext = XQXQFunction::getItemArgument(aArgs, 1);
613 lQuery->getDynamicContext()->setContextItem(lItemContext);
614
615 return ItemSequence_t(new EmptySequence());
616 }
617
618 /*******************************************************************************************
619 *******************************************************************************************/
620 zorba::ItemSequence_t
621 BindContextPositionFunction::evaluate(
622 const Arguments_t& aArgs,
623 const zorba::StaticContext* aSctx,
624 const zorba::DynamicContext* aDctx) const
625 {
626
627 XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
628
629 return ItemSequence_t(new EmptySequence());
630 }
631
632 /*******************************************************************************************
633 *******************************************************************************************/
634 zorba::ItemSequence_t
635 BindContextSizeFunction::evaluate(
636 const Arguments_t& aArgs,
637 const zorba::StaticContext* aSctx,
638 const zorba::DynamicContext* aDctx) const
639 {
640
641 XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
642
643 return ItemSequence_t(new EmptySequence());
644 }
645
646 /*******************************************************************************************
647 *******************************************************************************************/
648 zorba::ItemSequence_t
649 BindVariableFunction::evaluate(
650 const Arguments_t& aArgs,
651 const zorba::StaticContext* aSctx,
652 const zorba::DynamicContext* aDctx) const
653 {
654 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
655
656 XQuery_t lQuery = getQuery(aDctx, lQueryID);
657
658 Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
659
660 Iterator_t lVarValue = XQXQFunction::getIterArgument(aArgs, 2);
661
662 if (!lQuery->getDynamicContext()->setVariable(
663 lVarQName.getNamespace(), lVarQName.getLocalName() , lVarValue))
664 {
665 std::ostringstream lMsg;
666 lMsg << "{" << lVarQName.getNamespace() << "}" << lVarQName.getLocalName()
667 << ": undefined variable";
668 throwError("UndeclaredVariable", lMsg.str());
669 }
670
671 return ItemSequence_t(new EmptySequence());
672 }
673
674 /*******************************************************************************************
675 *******************************************************************************************/
676 bool
677 EvaluateItemSequence::EvaluateIterator::next(Item& aItem)
678 {
679 try
680 {
681 return theIterator->next(aItem);
682 }
683 catch (XQueryException& xe)
684 {
685 std::ostringstream err;
686 err << "The query " << "(" << theQueryID << ") evaluated using xqxq:evaluate raised an error at"
687 << " line " << xe.source_line() << " column " << xe.source_column() << ": " << xe.what();
688 Item errQName = XQXQModule::getItemFactory()->createQName(
689 xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
690 throw USER_EXCEPTION(errQName, err.str());
691 }
692 catch (ZorbaException& e)
693 {
694 std::ostringstream err;
695 err << "The query " << "(" << theQueryID << ") evaluated using xqxq:evaluate raised an error at"
696 << e.what();
697 Item errQName = XQXQModule::getItemFactory()->createQName(
698 e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
699 throw USER_EXCEPTION(errQName, err.str());
700 }
701 }
702
703 /*******************************************************************************************
704 *******************************************************************************************/
705 zorba::ItemSequence_t
706 EvaluateFunction::evaluate(
707 const Arguments_t& aArgs,
708 const zorba::StaticContext* aSctx,
709 const zorba::DynamicContext* aDctx) const
710 {
711 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
712
713 XQuery_t lQuery = getQuery(aDctx, lQueryID);
714
715 if(lQuery->isUpdating())
716 {
717 throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
718 }
719
720
721 if(lQuery->isSequential())
722 {
723 throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");
724 }
725
726 Iterator_t lIterQuery = lQuery->iterator();
727
728 return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
729 }
730
731 /*******************************************************************************************
732 *******************************************************************************************/
733 zorba::ItemSequence_t
734 EvaluateUpdatingFunction::evaluate(
735 const Arguments_t& aArgs,
736 const zorba::StaticContext* aSctx,
737 const zorba::DynamicContext* aDctx) const
738 {
739 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
740
741 XQuery_t lQuery = getQuery(aDctx, lQueryID);
742
743 if(lQuery->isSequential())
744 {
745 throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");
746 }
747
748 if(!lQuery->isUpdating())
749 {
750 throwError("QueryNotUpdating", "Executing Query should be updating.") ;
751 }
752
753 Iterator_t lIterQuery = lQuery->iterator();
754 return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
755}
756
757 /*******************************************************************************************
758 *******************************************************************************************/
759 zorba::ItemSequence_t
760 EvaluateSequentialFunction::evaluate(
761 const Arguments_t& aArgs,
762 const zorba::StaticContext* aSctx,
763 const zorba::DynamicContext* aDctx) const
764 {
765 String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
766
767 XQuery_t lQuery = getQuery(aDctx, lQueryID);
768
769 if(lQuery->isUpdating())
770 {
771 throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
772 }
773
774 if(!lQuery->isSequential())
775 {
776 throwError("QueryNotSequential", "Executing Query should be sequential.");
777 }
778
779 Iterator_t lIterQuery = lQuery->iterator();
780 return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
781 }
782
783 /*******************************************************************************************
784 *******************************************************************************************/
785 zorba::ItemSequence_t
786 DeleteQueryFunction::evaluate(
787 const Arguments_t& aArgs,
788 const zorba::StaticContext* aSctx,
789 const zorba::DynamicContext* aDctx) const
790 {
791 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
792
793 QueryMap* lQueryMap;
794 if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
795 {
796 throwError("NoQueryMatch", "String identifying query does not exists.");
797 }
798
799 if (!lQueryMap->deleteQuery(lQueryID))
800 {
801 throwError("NoQueryMatch","String identifying query does not exists.");
802 }
803
804 return ItemSequence_t(new EmptySequence());
805 }
806
807}/*namespace xqxq*/ }/*namespace zorba*/
808
809#ifdef WIN32
810# define DLL_EXPORT __declspec(dllexport)
811#else
812# define DLL_EXPORT __attribute__ ((visibility("default")))
813#endif
814
815extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
816 return new zorba::xqxq::XQXQModule();
817}
0818
=== added file 'modules/xqxq/xqxq.xq.src/xqxq.h'
--- modules/xqxq/xqxq.xq.src/xqxq.h 1970-01-01 00:00:00 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.h 2012-10-25 00:20:28 +0000
@@ -0,0 +1,456 @@
1#ifndef __COM_ZORBA_WWW_MODULES_XQXQ_H__
2#define __COM_ZORBA_WWW_MODULES_XQXQ_H__
3
4#include <map>
5
6#include <zorba/zorba.h>
7#include <zorba/external_module.h>
8#include <zorba/function.h>
9#include <zorba/dynamic_context.h>
10
11#define XQXQ_MODULE_NAMESPACE "http://www.zorba-xquery.com/modules/xqxq"
12
13namespace zorba { namespace xqxq {
14
15
16
17 class XQXQModule : public ExternalModule {
18 protected:
19 class ltstr
20 {
21 public:
22 bool operator()(const String& s1, const String& s2) const
23 {
24 return s1.compare(s2) < 0;
25 }
26 };
27
28 typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
29
30 FuncMap_t theFunctions;
31
32 public:
33
34 virtual ~XQXQModule();
35
36 virtual zorba::String
37 getURI() const {return XQXQ_MODULE_NAMESPACE;}
38
39 virtual zorba::ExternalFunction*
40 getExternalFunction(const String& localName);
41
42 virtual void destroy();
43
44 static ItemFactory*
45 getItemFactory()
46 {
47 return Zorba::getInstance(0)->getItemFactory();
48 }
49
50 };
51
52 /**
53 * @brief Bag class for objects associated with a prepared query
54 */
55 class QueryData : public SmartObject
56 {
57 private:
58 XQuery_t theQuery;
59 URIMapper* theURIMapper;
60 URLResolver* theURLResolver;
61
62 public:
63 QueryData(XQuery_t aQuery, URIMapper* aMapper, URLResolver* aResolver);
64 virtual ~QueryData();
65 XQuery_t getQuery() { return theQuery; }
66 };
67 typedef SmartPtr<QueryData> QueryData_t;
68
69 class QueryMap : public ExternalFunctionParameter
70 {
71 private:
72 typedef std::map<String, QueryData_t> QueryMap_t;
73 QueryMap_t* queryMap;
74
75 public:
76 QueryMap();
77 bool
78 storeQuery(const String&, XQuery_t, URIMapper*, URLResolver*);
79 XQuery_t
80 getQuery(const String&);
81 bool
82 deleteQuery(const String&);
83 virtual void
84 destroy() throw();
85 };
86
87 class XQXQFunction : public ContextualExternalFunction
88 {
89 protected:
90 const XQXQModule* theModule;
91
92 String
93 getOneStringArgument(const Arguments_t&, int) const;
94
95 Item
96 getItemArgument(const Arguments_t&, int) const;
97
98 Iterator_t
99 getIterArgument(const Arguments_t&, int) const;
100
101 static void
102 throwError(const char*, const std::string);
103
104 XQuery_t
105 getQuery(
106 const zorba::DynamicContext* dctx,
107 const zorba::String& aIdent) const;
108
109 public:
110
111 XQXQFunction(const XQXQModule* module);
112
113 virtual ~XQXQFunction();
114
115 virtual String
116 getURI() const;
117 };
118
119
120
121 class PrepareMainModuleFunction : public XQXQFunction{
122 public:
123 PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
124
125 virtual ~PrepareMainModuleFunction(){ }
126
127 virtual zorba::String
128 getLocalName() const { return "prepare-main-module"; }
129
130 virtual zorba::ItemSequence_t
131 evaluate(const Arguments_t&,
132 const zorba::StaticContext*,
133 const zorba::DynamicContext*) const;
134
135 protected:
136
137 class XQXQURLResolver : public URLResolver
138 {
139 protected:
140 Item theFunction;
141 StaticContext_t theCtx;
142
143 public:
144 XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx) : URLResolver(), theFunction(aFunction), theCtx(aSctx) {}
145
146 virtual ~XQXQURLResolver(){ }
147
148 virtual Resource* resolveURL(const String& aUrl,
149 EntityData const* aEntityData);
150
151 };
152
153 class XQXQURIMapper : public URIMapper
154 {
155 protected:
156 Item theFunction;
157 StaticContext_t theCtx;
158
159 public:
160 XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx) : URIMapper(), theFunction(aFunction), theCtx(aSctx) {}
161
162 virtual ~XQXQURIMapper(){ }
163
164 virtual void mapURI(
165 const zorba::String aUri,
166 EntityData const* aEntityData,
167 std::vector<zorba::String>& oUris);
168
169 };
170
171 };
172
173 class PrepareLibraryModuleFunction : public XQXQFunction{
174 public:
175 PrepareLibraryModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
176
177 virtual ~PrepareLibraryModuleFunction(){}
178
179 virtual zorba::String
180 getLocalName() const { return "prepare-library-module"; }
181
182 virtual zorba::ItemSequence_t
183 evaluate(const Arguments_t&,
184 const zorba::StaticContext*,
185 const zorba::DynamicContext*) const;
186 };
187
188 class IsBoundContextItemFunction : public XQXQFunction{
189 public:
190 IsBoundContextItemFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
191
192 virtual ~IsBoundContextItemFunction(){}
193
194 virtual zorba::String
195 getLocalName() const { return "is-bound-context-item"; }
196
197 virtual zorba::ItemSequence_t
198 evaluate(const Arguments_t&,
199 const zorba::StaticContext*,
200 const zorba::DynamicContext*) const;
201 };
202
203 class IsBoundVariableFunction : public XQXQFunction{
204 public:
205 IsBoundVariableFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
206
207 virtual ~IsBoundVariableFunction(){}
208
209 virtual zorba::String
210 getLocalName() const { return "is-bound-variable"; }
211
212 virtual zorba::ItemSequence_t
213 evaluate(const Arguments_t&,
214 const zorba::StaticContext*,
215 const zorba::DynamicContext*) const;
216 };
217
218 class GetExternalVariablesFunction : public XQXQFunction{
219 public:
220 GetExternalVariablesFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
221
222 virtual ~GetExternalVariablesFunction() {}
223
224 virtual zorba::String
225 getLocalName() const {return "external-variables"; }
226
227 virtual zorba::ItemSequence_t
228 evaluate(const Arguments_t&,
229 const zorba::StaticContext*,
230 const zorba::DynamicContext*) const;
231 };
232
233 class IsUpdatingFunction : public XQXQFunction{
234 public:
235 IsUpdatingFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
236
237 virtual ~IsUpdatingFunction() {}
238
239 virtual zorba::String
240 getLocalName() const {return "is-updating"; }
241
242 virtual zorba::ItemSequence_t
243 evaluate(const Arguments_t&,
244 const zorba::StaticContext*,
245 const zorba::DynamicContext*) const;
246
247 };
248
249 class IsSequentialFunction : public XQXQFunction{
250 public:
251 IsSequentialFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
252
253 virtual ~IsSequentialFunction() {}
254
255 virtual zorba::String
256 getLocalName() const {return "is-sequential"; }
257
258 virtual zorba::ItemSequence_t
259 evaluate(const Arguments_t&,
260 const zorba::StaticContext*,
261 const zorba::DynamicContext*) const;
262 };
263
264 class BindContextItemFunction : public XQXQFunction{
265 public:
266 BindContextItemFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
267
268 virtual ~BindContextItemFunction() {}
269
270 virtual zorba::String
271 getLocalName() const {return "bind-context-item"; }
272
273 virtual zorba::ItemSequence_t
274 evaluate(const Arguments_t&,
275 const zorba::StaticContext*,
276 const zorba::DynamicContext*) const;
277 };
278
279 class BindContextPositionFunction : public XQXQFunction{
280 public:
281 BindContextPositionFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
282
283 virtual ~BindContextPositionFunction() {}
284
285 virtual zorba::String
286 getLocalName() const {return "bind-context-position"; }
287
288 virtual zorba::ItemSequence_t
289 evaluate(const Arguments_t&,
290 const zorba::StaticContext*,
291 const zorba::DynamicContext*) const;
292 };
293
294 class BindContextSizeFunction : public XQXQFunction{
295 public:
296 BindContextSizeFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
297
298 virtual ~BindContextSizeFunction() {}
299
300 virtual zorba::String
301 getLocalName() const {return "bind-context-size"; }
302
303 virtual zorba::ItemSequence_t
304 evaluate(const Arguments_t&,
305 const zorba::StaticContext*,
306 const zorba::DynamicContext*) const;
307 };
308
309 class BindVariableFunction : public XQXQFunction{
310 public:
311 BindVariableFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
312
313 virtual ~BindVariableFunction() {}
314
315 virtual zorba::String
316 getLocalName() const {return "bind-variable"; }
317
318 virtual zorba::ItemSequence_t
319 evaluate(const Arguments_t&,
320 const zorba::StaticContext*,
321 const zorba::DynamicContext*) const;
322 };
323
324 /*******************************************************************************************
325 *******************************************************************************************/
326 class EvaluateItemSequence : public ItemSequence
327 {
328 protected:
329
330 class EvaluateIterator : public Iterator
331 {
332 protected:
333 Iterator_t theIterator;
334
335 String theQueryID;
336
337 public:
338 EvaluateIterator(Iterator_t& aIter, String aQueryID)
339 : theIterator(aIter), theQueryID(aQueryID)
340 {
341 }
342
343 virtual ~EvaluateIterator(){}
344
345 virtual void
346 open()
347 {
348 theIterator->open();
349 }
350
351 virtual bool
352 next(Item& aItem);
353
354 virtual void
355 close()
356 {
357 theIterator->close();
358 }
359
360 virtual bool
361 isOpen() const
362 {
363 return theIterator->isOpen();
364 }
365
366 };
367
368 typedef zorba::SmartPtr<EvaluateIterator> EvaluateIterator_t;
369 EvaluateIterator_t theIter;
370
371 public:
372 EvaluateItemSequence(Iterator_t& aIter, String& aQueryID)
373 :theIter (new EvaluateIterator(aIter, aQueryID))
374 {
375
376 }
377
378 virtual ~EvaluateItemSequence() {}
379
380 Iterator_t
381 getIterator() { return theIter.get(); }
382 };
383
384 class EvaluateFunction : public XQXQFunction{
385 public:
386 EvaluateFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
387
388 virtual ~EvaluateFunction() {}
389
390 virtual zorba::String
391 getLocalName() const {return "evaluate"; }
392
393 virtual zorba::ItemSequence_t
394 evaluate(const Arguments_t&,
395 const zorba::StaticContext*,
396 const zorba::DynamicContext*) const;
397 };
398
399 class EvaluateUpdatingFunction : public XQXQFunction{
400 public:
401 EvaluateUpdatingFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
402
403 virtual ~EvaluateUpdatingFunction() {}
404
405 virtual zorba::String
406 getLocalName() const {return "evaluate-updating"; }
407
408 virtual zorba::ItemSequence_t
409 evaluate(const Arguments_t&,
410 const zorba::StaticContext*,
411 const zorba::DynamicContext*) const;
412 };
413
414 class EvaluateSequentialFunction : public XQXQFunction{
415 public:
416 EvaluateSequentialFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
417
418 virtual ~EvaluateSequentialFunction() {}
419
420 virtual zorba::String
421 getLocalName() const {return "evaluate-sequential"; }
422
423 virtual zorba::ItemSequence_t
424 evaluate(const Arguments_t&,
425 const zorba::StaticContext*,
426 const zorba::DynamicContext*) const;
427
428 virtual String getURI() const {
429 return theModule->getURI();
430 }
431
432 protected:
433 const XQXQModule* theModule;
434 };
435
436 class DeleteQueryFunction : public XQXQFunction{
437 public:
438 DeleteQueryFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
439
440 virtual ~DeleteQueryFunction() {}
441
442 virtual zorba::String
443 getLocalName() const {return "delete-query"; }
444
445 virtual zorba::ItemSequence_t
446 evaluate(const Arguments_t&,
447 const zorba::StaticContext*,
448 const zorba::DynamicContext*) const;
449 };
450
451
452
453}/*xqxq namespace*/}/*zorba namespace*/
454
455
456#endif //_COM_ZORBA_WWW_MODULES_XQXQ_H_
0457
=== added directory 'test/rbkt/ExpQueryResults/zorba/xqxq'
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<parent><child>Content</child></parent>
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
22
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
22
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2a
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2false
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true true false
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true false
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2true false
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
22 3
0\ No newline at end of file3\ No newline at end of file
14
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2foo
03
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
03
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2foo
03
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
03
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
03
=== added file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
03
=== added directory 'test/rbkt/Queries/zorba/xqxq'
=== added file 'test/rbkt/Queries/zorba/xqxq/bind-context-item.xq'
--- test/rbkt/Queries/zorba/xqxq/bind-context-item.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/bind-context-item.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,6 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
4variable $xml := doc("context-item.xml");
5xqxq:bind-context-item($query-key, $xml);
6xqxq:is-bound-context-item($query-key)
07
=== added file 'test/rbkt/Queries/zorba/xqxq/bind-variable.xq'
--- test/rbkt/Queries/zorba/xqxq/bind-variable.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/bind-variable.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,4 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2variable $query-key := xqxq:prepare-main-module('declare variable $a external; $a');
3xqxq:bind-variable($query-key,xs:QName('a'),"foo");
4xqxq:is-bound-variable($query-key, xs:QName('a'))
0\ No newline at end of file5\ No newline at end of file
16
=== added file 'test/rbkt/Queries/zorba/xqxq/context-item.xml'
--- test/rbkt/Queries/zorba/xqxq/context-item.xml 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/context-item.xml 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1<parent></parent>
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/delete.spec'
--- test/rbkt/Queries/zorba/xqxq/delete.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/delete.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/modules/xqxq:NoQueryMatch
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/delete.xq'
--- test/rbkt/Queries/zorba/xqxq/delete.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/delete.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,5 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("1+1");
4xqxq:delete-query($query-key);
5xqxq:evaluate($query-key)
06
=== added file 'test/rbkt/Queries/zorba/xqxq/error-in-query.spec'
--- test/rbkt/Queries/zorba/xqxq/error-in-query.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/error-in-query.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,2 @@
1Error: http://www.w3.org/2005/xqt-errors:XQST0033
2
03
=== added file 'test/rbkt/Queries/zorba/xqxq/error-in-query.xq'
--- test/rbkt/Queries/zorba/xqxq/error-in-query.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/error-in-query.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,21 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace op = 'http://www.zorba-xquery.com/options/features';
4declare namespace f = 'http://www.zorba-xquery.com/features';
5declare option op:enable 'f:hof';
6
7declare function local:url-resolver($namespace as xs:string, $entity as xs:string) {
8switch($entity)
9case 'schema'
10 return switch($namespace)
11 case 'http://www.w3.org/XQueryTest' return doc('/tmp/atomic.xsd')
12 default return ()
13default return ()
14};
15
16variable $queryID := xqxq:prepare-main-module(
17 "declare namespace foo='http://test';
18 declare namespace foo='http://test';
19 1",
20 local:url-resolver#2, ());
21xqxq:evaluate($queryID)
022
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-sequential.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-sequential.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,17 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module('
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
5declare namespace an = "http://www.zorba-xquery.com/annotations";
6declare %an:sequential function local:foo() {
7 ddl:create(xs:QName("hola"),(<a/>,<b/>));
8
9 exit returning true();
10};
11
12local:foo()
13');
14variable $xml := doc("context-item.xml");
15xqxq:bind-context-item($query-key, $xml);
16xqxq:evaluate-sequential($query-key)
17
018
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsUpdating
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,6 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
4variable $xml := doc("context-item.xml");
5xqxq:bind-context-item($query-key, $xml);
6xqxq:evaluate-sequential($query-key)
0\ No newline at end of file7\ No newline at end of file
18
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,7 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
4variable $xml := doc("context-item.xml");
5xqxq:bind-context-item($query-key, $xml);
6xqxq:evaluate-updating($query-key);
7$xml
0\ No newline at end of file8\ No newline at end of file
19
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsSequential
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating2.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-updating2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-updating2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,15 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module('
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
5declare namespace an = "http://www.zorba-xquery.com/annotations";
6declare %an:sequential function local:foo() {
7 ddl:create(xs:QName("hola"),(<a/>,<b/>));
8
9 exit returning ();
10};
11
12local:foo()
13');
14xqxq:evaluate-updating($query-key);
15
016
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,5 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("1+1");
4variable $a := xqxq:evaluate($query-key);
5$a
06
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate2.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,6 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("declare variable $a external; $a+1");
4xqxq:bind-variable($query-key, xs:QName("a"), 1);
5variable $b := xqxq:evaluate($query-key);
6$b
07
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate3.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate3.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate3.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsSequential
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/evaluate3.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate3.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate3.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,15 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module('
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
5declare namespace an = "http://www.zorba-xquery.com/annotations";
6declare %an:sequential function local:foo() {
7 ddl:create(xs:QName("hola"),(<a/>,<b/>));
8
9 exit returning ();
10};
11
12local:foo()
13');
14variable $a := xqxq:evaluate($query-key);
15$a
016
=== added file 'test/rbkt/Queries/zorba/xqxq/external-module.xq'
--- test/rbkt/Queries/zorba/xqxq/external-module.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/external-module.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,8 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module('
4 import module namespace r = "http://www.zorba-xquery.com/modules/random";
5
6 count((for $i in 1 to 10 return r:random(10), r:random())) eq 101
7 ');
8xqxq:evaluate($query-key)
0\ No newline at end of file9\ No newline at end of file
110
=== added file 'test/rbkt/Queries/zorba/xqxq/get-external-variables.xq'
--- test/rbkt/Queries/zorba/xqxq/get-external-variables.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/get-external-variables.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,4 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2variable $query-key2 := xqxq:prepare-main-module('declare variable $c external; $c');
3variable $query-key := xqxq:prepare-main-module('declare variable $a external;declare variable $d := "hi"; $a');
4xqxq:external-variables($query-key)
0\ No newline at end of file5\ No newline at end of file
16
=== added file 'test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,4 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key := xqxq:prepare-main-module("insert node <child/> into /parent");
4xqxq:is-bound-context-item($query-key)
05
=== added file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,10 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2variable $query-key := xqxq:prepare-main-module('
3 declare variable $a external;
4 declare variable $b external := 2;
5 declare variable $c external;
6 $a');
7xqxq:bind-variable($query-key, xs:QName('a'), "foo");
8xqxq:is-bound-variable($query-key, xs:QName('a')),
9xqxq:is-bound-variable($query-key, xs:QName('b')),
10xqxq:is-bound-variable($query-key, xs:QName('c'))
0\ No newline at end of file11\ No newline at end of file
112
=== added file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.zorba-xquery.com/modules/xqxq:UndeclaredVariable
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,7 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2variable $query-key := xqxq:prepare-main-module('
3 declare variable $a external;
4 declare variable $b external := 2;
5 declare variable $c external;
6 $a');
7xqxq:is-bound-variable($query-key, xs:QName('x'))
0\ No newline at end of file8\ No newline at end of file
19
=== added file 'test/rbkt/Queries/zorba/xqxq/is-sequential.xq'
--- test/rbkt/Queries/zorba/xqxq/is-sequential.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-sequential.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,18 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key1 := xqxq:prepare-main-module('
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
5declare namespace an = "http://www.zorba-xquery.com/annotations";
6declare %an:sequential function local:foo() {
7 ddl:create(xs:QName("hola"),(<a/>,<b/>));
8
9 exit returning ();
10};
11
12local:foo()
13');
14variable $query-key2 := xqxq:prepare-main-module("insert node <child/> into /parent");
15variable $is-sequential := xqxq:is-sequential($query-key1);
16variable $is-not-sequential := xqxq:is-sequential($query-key2);
17$is-sequential, $is-not-sequential
18
019
=== added file 'test/rbkt/Queries/zorba/xqxq/is-updating.xq'
--- test/rbkt/Queries/zorba/xqxq/is-updating.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-updating.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,20 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key1 := xqxq:prepare-main-module('
4import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";
5declare namespace an = "http://www.zorba-xquery.com/annotations";
6declare %an:sequential function local:foo() {
7 ddl:create(xs:QName("hola"),(<a/>,<b/>));
8
9 exit returning ();
10};
11
12local:foo()
13');
14variable $query-key2 := xqxq:prepare-main-module("insert node <child/> into /parent");
15variable $is-updating := xqxq:is-updating($query-key2);
16variable $is-not-updating := xqxq:is-updating($query-key1);
17xqxq:delete-query($query-key1);
18xqxq:delete-query($query-key2);
19$is-updating, $is-not-updating
20
021
=== added file 'test/rbkt/Queries/zorba/xqxq/multiple-queries.xq'
--- test/rbkt/Queries/zorba/xqxq/multiple-queries.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/multiple-queries.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,9 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3variable $query-key1 := xqxq:prepare-main-module("1+1");
4variable $query-key2 := xqxq:prepare-main-module("1+2");
5variable $a := xqxq:evaluate($query-key1);
6variable $b := xqxq:evaluate($query-key2);
7xqxq:delete-query($query-key1);
8xqxq:delete-query($query-key2);
9$a, $b
010
=== added file 'test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec'
--- test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1Error: http://www.w3.org/2005/xqt-errors:XPST0003
02
=== added file 'test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq'
--- test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,3 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3xqxq:prepare-library-module('module namespace foo = "foo:bar"; declare function foo:bar() { 1 }')
04
=== added file 'test/rbkt/Queries/zorba/xqxq/test.xml'
--- test/rbkt/Queries/zorba/xqxq/test.xml 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/test.xml 2012-10-25 00:20:28 +0000
@@ -0,0 +1,1 @@
1<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'test/rbkt/Queries/zorba/xqxq/test.xsd'
--- test/rbkt/Queries/zorba/xqxq/test.xsd 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/test.xsd 2012-10-25 00:20:28 +0000
@@ -0,0 +1,14 @@
1<?xml version="1.0"?>
2<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3 targetNamespace="http://test"
4 xmlns="http://test"
5 elementFormDefault="qualified">
6 <xs:element name="test">
7 <xs:complexType>
8 <xs:sequence>
9 <xs:element name="subtest" type="xs:string"/>
10 <xs:element name="subtest2" type="xs:string"/>
11 </xs:sequence>
12 </xs:complexType>
13 </xs:element>
14</xs:schema>
0\ No newline at end of file15\ No newline at end of file
116
=== added file 'test/rbkt/Queries/zorba/xqxq/uri-mapper.xq'
--- test/rbkt/Queries/zorba/xqxq/uri-mapper.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/uri-mapper.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,27 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
5declare namespace op = "http://www.zorba-xquery.com/options/features";
6declare namespace f = "http://www.zorba-xquery.com/features";
7declare option op:enable "f:hof";
8
9declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
10 if($namespace = 'http://foo')
11 then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
12 else ()
13};
14
15declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
16{
17 if($namespace = 'http://test')
18 then 'http://foo'
19 else ()
20};
21
22variable $queryID := xqxq:prepare-main-module
23(
24 "import module namespace test = 'http://test'; test:foo()",
25 resolver:url-resolver#2, mapper:uri-mapper#2
26);
27xqxq:evaluate($queryID)
028
=== added file 'test/rbkt/Queries/zorba/xqxq/uri-mapper2.xq'
--- test/rbkt/Queries/zorba/xqxq/uri-mapper2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/uri-mapper2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,22 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
5declare namespace op = "http://www.zorba-xquery.com/options/features";
6declare namespace f = "http://www.zorba-xquery.com/features";
7declare option op:enable "f:hof";
8
9declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
10{
11 if ($namespace = 'http://test' and $entity = 'schema')
12 then resolve-uri('test.xsd')
13 else ()
14};
15
16variable $queryID := xqxq:prepare-main-module
17(
18 "import schema namespace test = 'http://test'; validate{<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
19 (),
20 mapper:uri-mapper#2
21);
22xqxq:evaluate($queryID)
023
=== added file 'test/rbkt/Queries/zorba/xqxq/url-module-resolver.xq'
--- test/rbkt/Queries/zorba/xqxq/url-module-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/url-module-resolver.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,17 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4declare namespace op = "http://www.zorba-xquery.com/options/features";
5declare namespace f = "http://www.zorba-xquery.com/features";
6declare option op:enable "f:hof";
7
8declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
9 if($namespace = 'http://test.xq')
10 then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
11 else ()
12};
13
14variable $queryID := xqxq:prepare-main-module(
15 "import module namespace test = 'http://test'; test:foo()",
16 resolver:url-resolver#2, ());
17xqxq:evaluate($queryID)
018
=== added file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver.xq'
--- test/rbkt/Queries/zorba/xqxq/url-schema-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/url-schema-resolver.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,20 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4
5declare namespace op = "http://www.zorba-xquery.com/options/features";
6declare namespace f = "http://www.zorba-xquery.com/features";
7declare option op:enable "f:hof";
8
9declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
10 if($namespace = 'http://test' and $entity = 'schema')
11 then
12 doc('test.xsd')
13 else
14 ()
15};
16
17variable $queryID := xqxq:prepare-main-module(
18 "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
19 resolver:url-resolver#2, ());
20xqxq:evaluate($queryID)
021
=== added file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver2.xq'
--- test/rbkt/Queries/zorba/xqxq/url-schema-resolver2.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/url-schema-resolver2.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,29 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3import module namespace ddl =
4 "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";
5import module namespace dml =
6 "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/dml";
7
8declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
9declare namespace op = "http://www.zorba-xquery.com/options/features";
10declare namespace f = "http://www.zorba-xquery.com/features";
11declare option op:enable "f:hof";
12
13declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
14 if ($entity = 'schema')
15 then
16 dml:collection("http://www.zorba-xquery.com/modules/xqxq")//xs:schema[@targetNamespace=$namespace]
17 else
18 ()
19};
20
21declare variable $coll := "http://www.zorba-xquery.com/modules/xqxq";
22declare variable $schema := doc("test.xsd");
23ddl:create($coll);
24
25dml:apply-insert-nodes-first($coll, $schema);
26variable $query-key := xqxq:prepare-main-module(
27 "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
28 resolver:url-resolver#2, ());
29xqxq:evaluate($query-key)
030
=== added file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver3.xq'
--- test/rbkt/Queries/zorba/xqxq/url-schema-resolver3.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/xqxq/url-schema-resolver3.xq 2012-10-25 00:20:28 +0000
@@ -0,0 +1,29 @@
1import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2
3declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
4
5declare namespace op = "http://www.zorba-xquery.com/options/features";
6declare namespace f = "http://www.zorba-xquery.com/features";
7declare option op:enable "f:hof";
8
9declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
10 if($namespace = 'http://test' and $entity = 'schema')
11 then
12 doc('test.xsd')
13 else
14 ()
15};
16
17variable $contextQueryID := xqxq:prepare-main-module(
18 "import schema namespace test = 'http://test';
19 declare variable $cwd as xs:anyURI external;
20 validate { doc(resolve-uri('test.xml', $cwd)) }",
21 resolver:url-resolver#2, ());
22xqxq:bind-variable($contextQueryID, fn:QName("", "cwd"), resolve-uri("."));
23variable $contextItem := xqxq:evaluate($contextQueryID);
24
25variable $queryID := xqxq:prepare-main-module(
26 "import schema namespace test = 'http://test'; //*:test",
27 resolver:url-resolver#2, ());
28xqxq:bind-context-item($queryID, $contextItem);
29xqxq:evaluate($queryID)

Subscribers

People subscribed via source and target branches