Merge lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module

Proposed by Juan Zacarias on 2012-09-10
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/xqxq-url-resolver
Merge into: lp:zorba/xqxq-module
Diff against target: 600 lines (+453/-4)
14 files modified
src/xqxq.xq (+115/-1)
src/xqxq.xq.src/xqxq.cpp (+160/-2)
src/xqxq.xq.src/xqxq.h (+39/-1)
test/ExpQueryResults/xqxq/uri-mapper.xml.res (+2/-0)
test/ExpQueryResults/xqxq/uri-mapper2.xml.res (+2/-0)
test/ExpQueryResults/xqxq/url-module-resolver.xml.res (+2/-0)
test/ExpQueryResults/xqxq/url-schema-resolver.xml.res (+2/-0)
test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res (+2/-0)
test/Queries/xqxq/test.xsd (+14/-0)
test/Queries/xqxq/uri-mapper.xq (+27/-0)
test/Queries/xqxq/uri-mapper2.xq (+22/-0)
test/Queries/xqxq/url-module-resolver.xq (+17/-0)
test/Queries/xqxq/url-schema-resolver.xq (+20/-0)
test/Queries/xqxq/url-schema-resolver2.xq (+29/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/xqxq-url-resolver
Reviewer Review Type Date Requested Status
Matthias Brantner 2012-09-10 Needs Fixing on 2012-10-18
Sorin Marian Nasoi Approve on 2012-10-18
Chris Hillery 2012-09-10 Approve on 2012-10-18
Review via email: mp+123604@code.launchpad.net

This proposal has been superseded by a proposal from 2012-10-19.

Commit Message

bug903797
prepare-main-module now can get the xs:QName of a function as a url resolver

To post a comment you must log in.

There is a memory leak in the implementation.

To check simply run
ctest -R url-
and look into the build/Testing/Temporary/LastTest.log.

Here is what you will see:

test xqxq/url-schema-resolver
[...]
=== end of result ===
testdriver: success (non-canonical result # 1 matches)
testdriver: test runtime was 37041us
testdriver: success
ID: 78 Referenced URI: http://www.zorba-xquery.com/modules/xqxq/url-resolver
ID: 113 Referenced URI: http://www.zorba-xquery.com/modules/xqxq
terminate called after throwing an instance of 'zorba::ZorbaException'
  what(): Zorba did not close properly, objects may still in memory.
2 referenced URI(s) remain in the string pool.
For help avoiding this message please refer to http://www.zorba-xquery.com/html/documentation in section General Architecture -> Memory Leaks.

review: Needs Fixing
Chris Hillery (ceejatec) wrote :

I initially saw some bad memory hits when I did a build of this branch as well, but after merging the latest trunk and doing a clean build, it all looks good. I do not see the memory leaks Sorin noted; I ran the url- tests with valgrind, and the only memory leaks reported were the known ones from inside the http-client module.

Sorin, please re-review now; if you see any problems, try a completely clean re-build. Thanks.

review: Approve
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/xqxq-url-resolver into lp:zorba/xqxq-module failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:274 (message):
  Validation queue job xqxq-url-resolver-2012-10-18T06-21-40.181Z is
  finished. The final status was:

  6 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Chris Hillery (ceejatec) wrote :

Whoops, right - this merge proposal won't pass until https://code.launchpad.net/~zorba-coders/zorba/zorba-xqxq-url-resolver/+merge/123602 is merged. Ignore these test failures for now.

review: Approve

I don't feel comfortable with the QName solution. It would be great if HOFs could be used for this. As far as I understood earlier discussions, this should have been developed together with Nicolae. Using HOFs would also solve the static context problem. Maybe the HOF feature already allows this relatively simple use case.

Can a sequence of mappers be registered?

The documentation should say that mapper:uri-mapper should return xs:string*.

s/lilfetime/lifetime
s/recive/receive
s/namesapce/namespace
s/th /the /

review: Needs Fixing
43. By Chris Hillery on 2012-10-19

Rework to use higher-order functions (HOF) rather than QNames to identify
URL resolver and URI mapper functions. Expanded function description and
modified/cleaned up test cases accordingly.

44. By Chris Hillery on 2012-10-19

Removed dead code.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/xqxq.xq'
2--- src/xqxq.xq 2012-09-28 13:48:30 +0000
3+++ src/xqxq.xq 2012-10-19 01:07:20 +0000
4@@ -26,9 +26,12 @@
5 module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
6
7 declare namespace an = "http://www.zorba-xquery.com/annotations";
8-
9 declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
10+declare namespace op = "http://www.zorba-xquery.com/options/features";
11+declare namespace f = "http://www.zorba-xquery.com/features";
12+
13 declare option ver:module-version "1.0";
14+declare option op:enable "f:hof";
15
16 (:~
17 : The function prepares a given XQuery program for execution.
18@@ -56,6 +59,106 @@
19 xs:anyURI external;
20
21 (:~
22+ : The function prepares a given XQuery program for execution.
23+ : If the program was successfully compiled, the function returns an
24+ : identifier as xs:anyURI. This URI can be passed to other functions
25+ : of this module (e.g. to actually evaluate the program). The URI
26+ : is opaque and its lilfetime is bound by the lifetime of the XQuery
27+ : program that invoked this function. Further reference or uses
28+ : of the identifier lead to unexpected results.
29+ :
30+ : Important notes regarding the second and third parameters of the function:
31+ : --------------------------------------------------------------------------
32+ :
33+ : These parameters allow you to specify a URL resolver and a URI mapper
34+ : for Zorba to use when executing this query. See
35+ : http://www.zorba-xquery.com/html/documentation/2.7.0/zorba/uriresolvers
36+ :
37+ : The second parameter is a function item for a URL
38+ : resolver. The URL resolver function must recive 2 parameters:
39+ : A $namespace as xs:string that will contain the url to be resolved.
40+ : A $entity as xs:string that will contain the type of resolving needed;
41+ : this can be 2 values "module" and "schema".
42+ : The function must return an empty sequence when the specified $namespace
43+ : or $entity are not the ones to be resolved.
44+ :
45+ : Example:
46+ :
47+ : declare function mymod:url-resolver($namespace as xs:string, $entity as xs:string)
48+ : {
49+ : if($namespace = 'http://test.xq')
50+ : then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
51+ : else ()
52+ : };
53+ :
54+ : The URL resolver function's namespace, name, and parameter naming are
55+ : not restricted by XQXQ.
56+ :
57+ : The URL resolver function's return type is not restricted, it could be a string, a sequence,
58+ : a node, etc. All the outputs types are to be serialized as a string.
59+ :
60+ : The third parameter is a function item for a URI mapper.
61+ : The URI mapper function, just like the URL resolver, receives 2 parameters:
62+ : A $namespace as xs:string that will contain the URI to be mapped.
63+ : A $entity as xs:string that will contain the type of resolving needed;
64+ : this can be 2 values "module" and "schema".
65+ : The URI mapper must return an empty sequence when the specified $namesapce or $entity
66+ : are not to be mapped. Unlike the URL resolver this function must return a sequence of strings.
67+ :
68+ : Example:
69+ :
70+ : declare function mymod:uri-mapper($namespace as xs:string, $entity as xs:string)
71+ : {
72+ : if($namespace = 'http://test')
73+ : then ("http://www.zorba-xquery.com/test", "http://foo.com/schema/test")
74+ : else ()
75+ : };
76+ :
77+ : The URI mapper function's namespace, name, and parameter naming are
78+ : not restricted by XQXQ.
79+ :
80+ : In order to pass the above URL resolver and URI mapper to this function,
81+ : use the following syntax:
82+ :
83+ : variable $queryID := xqxq:prepare-main-module("..query text..",
84+ : mymod:url-resolver#2, mymod:uri-mapper#2);
85+ :
86+ : That is, the QName of the function followed by "#2". This is XQuery
87+ : "higher-order function" syntax, meaning the function with the specified
88+ : QName which takes two arguments. Since URL resolvers and URI mappers
89+ : must take two arguments, both will always be specified with "#2".
90+ :
91+ : Note that parameters 2 and 3 should be declared as follows:
92+ : as function($url as xs:string, $entity as xs:string) as item()
93+ : as function($uri as xs:string, $entity as xs:string) as xs:string*
94+ : However Zorba's implementation of higher-order functions (HOF) is not
95+ : yet complete enough to allow for this. When Zorba's HOF implementation
96+ : is complete this function signature will be changed.
97+ :
98+ : Both the URL resolver and URI mapper functions are optional, meaning you
99+ : may pass the empty-sequence () for either.
100+ :
101+ : Successfully prepared queries need to be deleted by passing the resulting
102+ : identifier to the xqxq:delete-query function of this module.
103+ :
104+ : @param $main-module-text the XQuery program that should be prepared.
105+ : The program needs to be a XQuery main module.
106+ :
107+ : @param $resolver the URL resolver function.
108+ :
109+ : @param $mapper the URI mapper function.
110+ :
111+ : @return an identifier for the compiled program that can be passed
112+ : as arguments to other functions of this module.
113+ :
114+ : @error any (static or type) error that may be raised during the compilation
115+ : of the query. For example, err:XPST0003 if the given XQuery program could
116+ : not be parsed.
117+ :)
118+declare %an:sequential function xqxq:prepare-main-module($main-module-text as xs:string, $resolver as item()?, $mapper as item()?) as
119+ xs:anyURI external;
120+
121+(:~
122 : This function compiles a given XQuery library module. It can be used
123 : to compile-check a module.
124 :
125@@ -265,3 +368,14 @@
126 :)
127 declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
128 empty-sequence() external;
129+
130+
131+(:~
132+ : Internal helper function. Only necessary because of incomplete HOF
133+ : support in Zorba.
134+ :)
135+declare %private function xqxq:hof-invoker($hof as item(),
136+ $ns as xs:string, $entity as xs:string) as item()*
137+{
138+ $hof($ns, $entity)
139+};
140
141=== modified file 'src/xqxq.xq.src/xqxq.cpp'
142--- src/xqxq.xq.src/xqxq.cpp 2012-10-01 17:54:38 +0000
143+++ src/xqxq.xq.src/xqxq.cpp 2012-10-19 01:07:20 +0000
144@@ -226,6 +226,131 @@
145
146 /*******************************************************************************************
147 *******************************************************************************************/
148+ static void streamReleaser(std::istream* aStream)
149+ {
150+ delete aStream;
151+ }
152+
153+ void
154+ PrepareMainModuleFunction::XQXQURIMapper::mapURI(
155+ String aUri,
156+ EntityData const* aEntityData,
157+ std::vector<String>& oUris)
158+ {
159+ //Create entityData string to send to the new url resolver
160+ String lDataKind;
161+ switch (aEntityData->getKind())
162+ {
163+ case EntityData::SCHEMA:
164+ lDataKind = "schema";
165+ break;
166+ case EntityData::MODULE:
167+ lDataKind = "module";
168+ break;
169+ default:
170+ break;
171+ }
172+
173+ //construct the arguments for the url resolver
174+ std::vector<ItemSequence_t> lArgs;
175+ ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
176+ ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
177+ ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
178+ lArgs.push_back(lSeq0);
179+ lArgs.push_back(lSeq1);
180+ lArgs.push_back(lSeq2);
181+
182+ //invoke the HOF helper function using the arguments generated
183+ Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
184+ ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
185+
186+ //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
187+ //and then checking if it was empty.
188+ Iterator_t lIter = lResult->getIterator();
189+ Item lItem;
190+ lIter->open();
191+ while (lIter->next(lItem))
192+ {
193+ std::cout << lItem.getStringValue() << std::endl;
194+ oUris.push_back(lItem.getStringValue());
195+ }
196+ lIter->close();
197+
198+ }
199+
200+
201+ Resource*
202+ PrepareMainModuleFunction::XQXQURLResolver::resolveURL(
203+ const String& aUrl,
204+ EntityData const* aEntityData)
205+ {
206+ //Create entityData string to send to the new url resolver
207+ String lDataKind;
208+ switch (aEntityData->getKind())
209+ {
210+ case EntityData::SCHEMA:
211+ lDataKind = "schema";
212+ break;
213+ case EntityData::MODULE:
214+ lDataKind = "module";
215+ break;
216+ default:
217+ break;
218+ }
219+
220+ //construct the arguments for the url resolver
221+ std::vector<ItemSequence_t> lArgs;
222+ ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
223+ ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
224+ ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
225+ lArgs.push_back(lSeq0);
226+ lArgs.push_back(lSeq1);
227+ lArgs.push_back(lSeq2);
228+
229+ //invoke the HOF helper function using the arguments generated
230+ Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
231+ ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
232+
233+ //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
234+ //and then checking if it was empty.
235+ Iterator_t lIter = lResult->getIterator();
236+ Item lItem;
237+ lIter->open();
238+ lIter->next(lItem);
239+ lIter->close();
240+ if (lItem.isNull())
241+ return NULL;
242+
243+ //Serialize resulting sequence of the resolver
244+ Zorba_SerializerOptions_t lOpt;
245+ if (lItem.isNode())
246+ lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
247+ else
248+ lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
249+ lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
250+ Serializer_t lSer = Serializer::createSerializer(lOpt);
251+ std::stringstream lSerResult;
252+ lSer->serialize(lResult, lSerResult);
253+
254+ //return resource
255+ return StreamResource::create(new std::istringstream(lSerResult.str()), &streamReleaser);
256+
257+ /*
258+ // we have only one module
259+ if (aEntityData->getKind() == EntityData::MODULE &&
260+ aUrl == "http://www.zorba-xquery.com/modules/xqxq/test")
261+ {
262+ return StreamResource::create
263+ (new std::istringstream
264+ ("module namespace test = 'http://www.zorba-xquery.com/modules/xqxq/test'; "
265+ "declare function test:foo() { 'foo' };"), &streamReleaser);
266+ }
267+ else {
268+ return NULL;
269+ }
270+ */
271+ }
272+
273 zorba::ItemSequence_t
274 PrepareMainModuleFunction::evaluate(
275 const Arguments_t& aArgs,
276@@ -233,6 +358,8 @@
277 const zorba::DynamicContext* aDctx) const
278 {
279 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
280+ StaticContext_t lSctxChild = aSctx->createChildContext();
281+ StaticContext_t lMapperSctx = aSctx->createChildContext();
282
283 QueryMap* lQueryMap;
284 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
285@@ -247,9 +374,34 @@
286
287 XQuery_t lQuery;
288
289+ StaticContext_t ltempSctx = lZorba->createStaticContext();
290+ XQXQURLResolver* lResolver = NULL;
291+ XQXQURIMapper* lMapper = NULL;
292+
293+ if ( aArgs.size() > 2 )
294+ {
295+ Item lMapperFunctionItem = getItemArgument(aArgs, 2);
296+ if (!lMapperFunctionItem.isNull())
297+ {
298+ lMapper = new XQXQURIMapper(lMapperFunctionItem, lSctxChild);
299+ ltempSctx->registerURIMapper(lMapper);
300+ }
301+ }
302+
303+ if ( aArgs.size() > 1 )
304+ {
305+ Item lResolverFunctionItem = getItemArgument(aArgs, 1);
306+ if (!lResolverFunctionItem.isNull())
307+ {
308+ lResolver = new XQXQURLResolver(lResolverFunctionItem, lSctxChild);
309+ ltempSctx->registerURLResolver(lResolver);
310+ }
311+
312+ }
313+
314 try
315 {
316- lQuery = lZorba->compileQuery(lQueryString);
317+ lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
318 }
319 catch (XQueryException& xe)
320 {
321@@ -277,12 +429,18 @@
322 lStream << lUUID;
323
324 String lStrUUID = lStream.str();
325+
326+ lQueryMap->storeQuery(lStrUUID, lQuery);
327
328- lQueryMap->storeQuery(lStrUUID, lQuery);
329+ if (lResolver)
330+ delete lResolver;
331+ if (lMapper)
332+ delete lMapper;
333
334 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
335 }
336
337+
338 /*******************************************************************************************
339 *******************************************************************************************/
340 zorba::ItemSequence_t
341
342=== modified file 'src/xqxq.xq.src/xqxq.h'
343--- src/xqxq.xq.src/xqxq.h 2012-10-01 17:54:38 +0000
344+++ src/xqxq.xq.src/xqxq.h 2012-10-19 01:07:20 +0000
345@@ -49,6 +49,7 @@
346
347 };
348
349+
350 class QueryMap : public ExternalFunctionParameter{
351 private:
352 typedef std::map<String, XQuery_t> QueryMap_t;
353@@ -117,7 +118,7 @@
354 public:
355 PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
356
357- virtual ~PrepareMainModuleFunction(){}
358+ virtual ~PrepareMainModuleFunction(){ }
359
360 virtual zorba::String
361 getLocalName() const { return "prepare-main-module"; }
362@@ -126,6 +127,43 @@
363 evaluate(const Arguments_t&,
364 const zorba::StaticContext*,
365 const zorba::DynamicContext*) const;
366+
367+ protected:
368+
369+ class XQXQURLResolver : public URLResolver
370+ {
371+ protected:
372+ Item theFunction;
373+ StaticContext_t theCtx;
374+
375+ public:
376+ XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx) : URLResolver(), theFunction(aFunction), theCtx(aSctx) {}
377+
378+ virtual ~XQXQURLResolver(){ }
379+
380+ virtual Resource* resolveURL(const String& aUrl,
381+ EntityData const* aEntityData);
382+
383+ };
384+
385+ class XQXQURIMapper : public URIMapper
386+ {
387+ protected:
388+ Item theFunction;
389+ StaticContext_t theCtx;
390+
391+ public:
392+ XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx) : URIMapper(), theFunction(aFunction), theCtx(aSctx) {}
393+
394+ virtual ~XQXQURIMapper(){ }
395+
396+ virtual void mapURI(
397+ const zorba::String aUri,
398+ EntityData const* aEntityData,
399+ std::vector<zorba::String>& oUris);
400+
401+ };
402+
403 };
404
405 class PrepareLibraryModuleFunction : public XQXQFunction{
406
407=== added file 'test/ExpQueryResults/xqxq/uri-mapper.xml.res'
408--- test/ExpQueryResults/xqxq/uri-mapper.xml.res 1970-01-01 00:00:00 +0000
409+++ test/ExpQueryResults/xqxq/uri-mapper.xml.res 2012-10-19 01:07:20 +0000
410@@ -0,0 +1,2 @@
411+<?xml version="1.0" encoding="UTF-8"?>
412+foo
413
414=== added file 'test/ExpQueryResults/xqxq/uri-mapper2.xml.res'
415--- test/ExpQueryResults/xqxq/uri-mapper2.xml.res 1970-01-01 00:00:00 +0000
416+++ test/ExpQueryResults/xqxq/uri-mapper2.xml.res 2012-10-19 01:07:20 +0000
417@@ -0,0 +1,2 @@
418+<?xml version="1.0" encoding="UTF-8"?>
419+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
420
421=== added file 'test/ExpQueryResults/xqxq/url-module-resolver.xml.res'
422--- test/ExpQueryResults/xqxq/url-module-resolver.xml.res 1970-01-01 00:00:00 +0000
423+++ test/ExpQueryResults/xqxq/url-module-resolver.xml.res 2012-10-19 01:07:20 +0000
424@@ -0,0 +1,2 @@
425+<?xml version="1.0" encoding="UTF-8"?>
426+foo
427
428=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver.xml.res'
429--- test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 1970-01-01 00:00:00 +0000
430+++ test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 2012-10-19 01:07:20 +0000
431@@ -0,0 +1,2 @@
432+<?xml version="1.0" encoding="UTF-8"?>
433+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
434
435=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res'
436--- test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 1970-01-01 00:00:00 +0000
437+++ test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 2012-10-19 01:07:20 +0000
438@@ -0,0 +1,2 @@
439+<?xml version="1.0" encoding="UTF-8"?>
440+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
441
442=== added file 'test/Queries/xqxq/test.xsd'
443--- test/Queries/xqxq/test.xsd 1970-01-01 00:00:00 +0000
444+++ test/Queries/xqxq/test.xsd 2012-10-19 01:07:20 +0000
445@@ -0,0 +1,14 @@
446+<?xml version="1.0"?>
447+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
448+ targetNamespace="http://test"
449+ xmlns="http://test"
450+ elementFormDefault="qualified">
451+ <xs:element name="test">
452+ <xs:complexType>
453+ <xs:sequence>
454+ <xs:element name="subtest" type="xs:string"/>
455+ <xs:element name="subtest2" type="xs:string"/>
456+ </xs:sequence>
457+ </xs:complexType>
458+ </xs:element>
459+</xs:schema>
460\ No newline at end of file
461
462=== added file 'test/Queries/xqxq/uri-mapper.xq'
463--- test/Queries/xqxq/uri-mapper.xq 1970-01-01 00:00:00 +0000
464+++ test/Queries/xqxq/uri-mapper.xq 2012-10-19 01:07:20 +0000
465@@ -0,0 +1,27 @@
466+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
467+
468+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
469+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
470+declare namespace op = "http://www.zorba-xquery.com/options/features";
471+declare namespace f = "http://www.zorba-xquery.com/features";
472+declare option op:enable "f:hof";
473+
474+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
475+ if($namespace = 'http://foo')
476+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
477+ else ()
478+};
479+
480+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
481+{
482+ if($namespace = 'http://test')
483+ then 'http://foo'
484+ else ()
485+};
486+
487+variable $queryID := xqxq:prepare-main-module
488+(
489+ "import module namespace test = 'http://test'; test:foo()",
490+ resolver:url-resolver#2, mapper:uri-mapper#2
491+);
492+xqxq:evaluate($queryID)
493
494=== added file 'test/Queries/xqxq/uri-mapper2.xq'
495--- test/Queries/xqxq/uri-mapper2.xq 1970-01-01 00:00:00 +0000
496+++ test/Queries/xqxq/uri-mapper2.xq 2012-10-19 01:07:20 +0000
497@@ -0,0 +1,22 @@
498+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
499+
500+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
501+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
502+declare namespace op = "http://www.zorba-xquery.com/options/features";
503+declare namespace f = "http://www.zorba-xquery.com/features";
504+declare option op:enable "f:hof";
505+
506+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
507+{
508+ if ($namespace = 'http://test' and $entity = 'schema')
509+ then resolve-uri('test.xsd')
510+ else ()
511+};
512+
513+variable $queryID := xqxq:prepare-main-module
514+(
515+ "import schema namespace test = 'http://test'; validate{<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
516+ (),
517+ mapper:uri-mapper#2
518+);
519+xqxq:evaluate($queryID)
520
521=== added file 'test/Queries/xqxq/url-module-resolver.xq'
522--- test/Queries/xqxq/url-module-resolver.xq 1970-01-01 00:00:00 +0000
523+++ test/Queries/xqxq/url-module-resolver.xq 2012-10-19 01:07:20 +0000
524@@ -0,0 +1,17 @@
525+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
526+
527+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
528+declare namespace op = "http://www.zorba-xquery.com/options/features";
529+declare namespace f = "http://www.zorba-xquery.com/features";
530+declare option op:enable "f:hof";
531+
532+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
533+ if($namespace = 'http://test.xq')
534+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
535+ else ()
536+};
537+
538+variable $queryID := xqxq:prepare-main-module(
539+ "import module namespace test = 'http://test'; test:foo()",
540+ resolver:url-resolver#2, ());
541+xqxq:evaluate($queryID)
542
543=== added file 'test/Queries/xqxq/url-schema-resolver.xq'
544--- test/Queries/xqxq/url-schema-resolver.xq 1970-01-01 00:00:00 +0000
545+++ test/Queries/xqxq/url-schema-resolver.xq 2012-10-19 01:07:20 +0000
546@@ -0,0 +1,20 @@
547+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
548+
549+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
550+
551+declare namespace op = "http://www.zorba-xquery.com/options/features";
552+declare namespace f = "http://www.zorba-xquery.com/features";
553+declare option op:enable "f:hof";
554+
555+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
556+ if($namespace = 'http://test' and $entity = 'schema')
557+ then
558+ doc('test.xsd')
559+ else
560+ ()
561+};
562+
563+variable $queryID := xqxq:prepare-main-module(
564+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
565+ resolver:url-resolver#2, ());
566+xqxq:evaluate($queryID)
567
568=== added file 'test/Queries/xqxq/url-schema-resolver2.xq'
569--- test/Queries/xqxq/url-schema-resolver2.xq 1970-01-01 00:00:00 +0000
570+++ test/Queries/xqxq/url-schema-resolver2.xq 2012-10-19 01:07:20 +0000
571@@ -0,0 +1,29 @@
572+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
573+
574+import module namespace ddl =
575+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";
576+import module namespace dml =
577+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/dml";
578+
579+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
580+declare namespace op = "http://www.zorba-xquery.com/options/features";
581+declare namespace f = "http://www.zorba-xquery.com/features";
582+declare option op:enable "f:hof";
583+
584+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
585+ if ($entity = 'schema')
586+ then
587+ dml:collection("http://www.zorba-xquery.com/modules/xqxq")//xs:schema[@targetNamespace=$namespace]
588+ else
589+ ()
590+};
591+
592+declare variable $coll := "http://www.zorba-xquery.com/modules/xqxq";
593+declare variable $schema := doc("test.xsd");
594+ddl:create($coll);
595+
596+dml:apply-insert-nodes-first($coll, $schema);
597+variable $query-key := xqxq:prepare-main-module(
598+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
599+ resolver:url-resolver#2, ());
600+xqxq:evaluate($query-key)

Subscribers

People subscribed via source and target branches

to all changes: