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

Proposed by Chris Hillery
Status: Merged
Approved by: Sorin Marian Nasoi
Approved revision: 44
Merged at revision: 40
Proposed branch: lp:~zorba-coders/zorba/xqxq-url-resolver
Merge into: lp:zorba/xqxq-module
Diff against target: 585 lines (+438/-4)
14 files modified
src/xqxq.xq (+115/-1)
src/xqxq.xq.src/xqxq.cpp (+145/-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
Sorin Marian Nasoi Approve
Matthias Brantner Approve
Chris Hillery Approve
Review via email: mp+130460@code.launchpad.net

This proposal supersedes a proposal from 2012-09-10.

Commit message

Bug 903797: add feature to prepare-main-module() to enable URI mappers and URL resolvers written in XQuery.

To post a comment you must log in.
Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

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.

Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

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
Revision history for this message
Chris Hillery (ceejatec) wrote :

Now using HOF!

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 xqxq-url-resolver-2012-10-19T01-22-47.205Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 2 Pending.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) :
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 xqxq-url-resolver-2012-10-19T08-27-45.258Z 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
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:25:26 +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:25:26 +0000
144@@ -226,6 +226,116 @@
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 zorba::ItemSequence_t
259 PrepareMainModuleFunction::evaluate(
260 const Arguments_t& aArgs,
261@@ -233,6 +343,8 @@
262 const zorba::DynamicContext* aDctx) const
263 {
264 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
265+ StaticContext_t lSctxChild = aSctx->createChildContext();
266+ StaticContext_t lMapperSctx = aSctx->createChildContext();
267
268 QueryMap* lQueryMap;
269 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
270@@ -247,9 +359,34 @@
271
272 XQuery_t lQuery;
273
274+ StaticContext_t ltempSctx = lZorba->createStaticContext();
275+ XQXQURLResolver* lResolver = NULL;
276+ XQXQURIMapper* lMapper = NULL;
277+
278+ if ( aArgs.size() > 2 )
279+ {
280+ Item lMapperFunctionItem = getItemArgument(aArgs, 2);
281+ if (!lMapperFunctionItem.isNull())
282+ {
283+ lMapper = new XQXQURIMapper(lMapperFunctionItem, lSctxChild);
284+ ltempSctx->registerURIMapper(lMapper);
285+ }
286+ }
287+
288+ if ( aArgs.size() > 1 )
289+ {
290+ Item lResolverFunctionItem = getItemArgument(aArgs, 1);
291+ if (!lResolverFunctionItem.isNull())
292+ {
293+ lResolver = new XQXQURLResolver(lResolverFunctionItem, lSctxChild);
294+ ltempSctx->registerURLResolver(lResolver);
295+ }
296+
297+ }
298+
299 try
300 {
301- lQuery = lZorba->compileQuery(lQueryString);
302+ lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
303 }
304 catch (XQueryException& xe)
305 {
306@@ -277,12 +414,18 @@
307 lStream << lUUID;
308
309 String lStrUUID = lStream.str();
310+
311+ lQueryMap->storeQuery(lStrUUID, lQuery);
312
313- lQueryMap->storeQuery(lStrUUID, lQuery);
314+ if (lResolver)
315+ delete lResolver;
316+ if (lMapper)
317+ delete lMapper;
318
319 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
320 }
321
322+
323 /*******************************************************************************************
324 *******************************************************************************************/
325 zorba::ItemSequence_t
326
327=== modified file 'src/xqxq.xq.src/xqxq.h'
328--- src/xqxq.xq.src/xqxq.h 2012-10-01 17:54:38 +0000
329+++ src/xqxq.xq.src/xqxq.h 2012-10-19 01:25:26 +0000
330@@ -49,6 +49,7 @@
331
332 };
333
334+
335 class QueryMap : public ExternalFunctionParameter{
336 private:
337 typedef std::map<String, XQuery_t> QueryMap_t;
338@@ -117,7 +118,7 @@
339 public:
340 PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
341
342- virtual ~PrepareMainModuleFunction(){}
343+ virtual ~PrepareMainModuleFunction(){ }
344
345 virtual zorba::String
346 getLocalName() const { return "prepare-main-module"; }
347@@ -126,6 +127,43 @@
348 evaluate(const Arguments_t&,
349 const zorba::StaticContext*,
350 const zorba::DynamicContext*) const;
351+
352+ protected:
353+
354+ class XQXQURLResolver : public URLResolver
355+ {
356+ protected:
357+ Item theFunction;
358+ StaticContext_t theCtx;
359+
360+ public:
361+ XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx) : URLResolver(), theFunction(aFunction), theCtx(aSctx) {}
362+
363+ virtual ~XQXQURLResolver(){ }
364+
365+ virtual Resource* resolveURL(const String& aUrl,
366+ EntityData const* aEntityData);
367+
368+ };
369+
370+ class XQXQURIMapper : public URIMapper
371+ {
372+ protected:
373+ Item theFunction;
374+ StaticContext_t theCtx;
375+
376+ public:
377+ XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx) : URIMapper(), theFunction(aFunction), theCtx(aSctx) {}
378+
379+ virtual ~XQXQURIMapper(){ }
380+
381+ virtual void mapURI(
382+ const zorba::String aUri,
383+ EntityData const* aEntityData,
384+ std::vector<zorba::String>& oUris);
385+
386+ };
387+
388 };
389
390 class PrepareLibraryModuleFunction : public XQXQFunction{
391
392=== added file 'test/ExpQueryResults/xqxq/uri-mapper.xml.res'
393--- test/ExpQueryResults/xqxq/uri-mapper.xml.res 1970-01-01 00:00:00 +0000
394+++ test/ExpQueryResults/xqxq/uri-mapper.xml.res 2012-10-19 01:25:26 +0000
395@@ -0,0 +1,2 @@
396+<?xml version="1.0" encoding="UTF-8"?>
397+foo
398
399=== added file 'test/ExpQueryResults/xqxq/uri-mapper2.xml.res'
400--- test/ExpQueryResults/xqxq/uri-mapper2.xml.res 1970-01-01 00:00:00 +0000
401+++ test/ExpQueryResults/xqxq/uri-mapper2.xml.res 2012-10-19 01:25:26 +0000
402@@ -0,0 +1,2 @@
403+<?xml version="1.0" encoding="UTF-8"?>
404+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
405
406=== added file 'test/ExpQueryResults/xqxq/url-module-resolver.xml.res'
407--- test/ExpQueryResults/xqxq/url-module-resolver.xml.res 1970-01-01 00:00:00 +0000
408+++ test/ExpQueryResults/xqxq/url-module-resolver.xml.res 2012-10-19 01:25:26 +0000
409@@ -0,0 +1,2 @@
410+<?xml version="1.0" encoding="UTF-8"?>
411+foo
412
413=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver.xml.res'
414--- test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 1970-01-01 00:00:00 +0000
415+++ test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 2012-10-19 01:25:26 +0000
416@@ -0,0 +1,2 @@
417+<?xml version="1.0" encoding="UTF-8"?>
418+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
419
420=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res'
421--- test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 1970-01-01 00:00:00 +0000
422+++ test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 2012-10-19 01:25:26 +0000
423@@ -0,0 +1,2 @@
424+<?xml version="1.0" encoding="UTF-8"?>
425+<test:test xmlns:test="http://test"><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
426
427=== added file 'test/Queries/xqxq/test.xsd'
428--- test/Queries/xqxq/test.xsd 1970-01-01 00:00:00 +0000
429+++ test/Queries/xqxq/test.xsd 2012-10-19 01:25:26 +0000
430@@ -0,0 +1,14 @@
431+<?xml version="1.0"?>
432+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
433+ targetNamespace="http://test"
434+ xmlns="http://test"
435+ elementFormDefault="qualified">
436+ <xs:element name="test">
437+ <xs:complexType>
438+ <xs:sequence>
439+ <xs:element name="subtest" type="xs:string"/>
440+ <xs:element name="subtest2" type="xs:string"/>
441+ </xs:sequence>
442+ </xs:complexType>
443+ </xs:element>
444+</xs:schema>
445\ No newline at end of file
446
447=== added file 'test/Queries/xqxq/uri-mapper.xq'
448--- test/Queries/xqxq/uri-mapper.xq 1970-01-01 00:00:00 +0000
449+++ test/Queries/xqxq/uri-mapper.xq 2012-10-19 01:25:26 +0000
450@@ -0,0 +1,27 @@
451+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
452+
453+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
454+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
455+declare namespace op = "http://www.zorba-xquery.com/options/features";
456+declare namespace f = "http://www.zorba-xquery.com/features";
457+declare option op:enable "f:hof";
458+
459+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
460+ if($namespace = 'http://foo')
461+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
462+ else ()
463+};
464+
465+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
466+{
467+ if($namespace = 'http://test')
468+ then 'http://foo'
469+ else ()
470+};
471+
472+variable $queryID := xqxq:prepare-main-module
473+(
474+ "import module namespace test = 'http://test'; test:foo()",
475+ resolver:url-resolver#2, mapper:uri-mapper#2
476+);
477+xqxq:evaluate($queryID)
478
479=== added file 'test/Queries/xqxq/uri-mapper2.xq'
480--- test/Queries/xqxq/uri-mapper2.xq 1970-01-01 00:00:00 +0000
481+++ test/Queries/xqxq/uri-mapper2.xq 2012-10-19 01:25:26 +0000
482@@ -0,0 +1,22 @@
483+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
484+
485+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
486+declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';
487+declare namespace op = "http://www.zorba-xquery.com/options/features";
488+declare namespace f = "http://www.zorba-xquery.com/features";
489+declare option op:enable "f:hof";
490+
491+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
492+{
493+ if ($namespace = 'http://test' and $entity = 'schema')
494+ then resolve-uri('test.xsd')
495+ else ()
496+};
497+
498+variable $queryID := xqxq:prepare-main-module
499+(
500+ "import schema namespace test = 'http://test'; validate{<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
501+ (),
502+ mapper:uri-mapper#2
503+);
504+xqxq:evaluate($queryID)
505
506=== added file 'test/Queries/xqxq/url-module-resolver.xq'
507--- test/Queries/xqxq/url-module-resolver.xq 1970-01-01 00:00:00 +0000
508+++ test/Queries/xqxq/url-module-resolver.xq 2012-10-19 01:25:26 +0000
509@@ -0,0 +1,17 @@
510+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
511+
512+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
513+declare namespace op = "http://www.zorba-xquery.com/options/features";
514+declare namespace f = "http://www.zorba-xquery.com/features";
515+declare option op:enable "f:hof";
516+
517+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
518+ if($namespace = 'http://test.xq')
519+ then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
520+ else ()
521+};
522+
523+variable $queryID := xqxq:prepare-main-module(
524+ "import module namespace test = 'http://test'; test:foo()",
525+ resolver:url-resolver#2, ());
526+xqxq:evaluate($queryID)
527
528=== added file 'test/Queries/xqxq/url-schema-resolver.xq'
529--- test/Queries/xqxq/url-schema-resolver.xq 1970-01-01 00:00:00 +0000
530+++ test/Queries/xqxq/url-schema-resolver.xq 2012-10-19 01:25:26 +0000
531@@ -0,0 +1,20 @@
532+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
533+
534+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
535+
536+declare namespace op = "http://www.zorba-xquery.com/options/features";
537+declare namespace f = "http://www.zorba-xquery.com/features";
538+declare option op:enable "f:hof";
539+
540+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
541+ if($namespace = 'http://test' and $entity = 'schema')
542+ then
543+ doc('test.xsd')
544+ else
545+ ()
546+};
547+
548+variable $queryID := xqxq:prepare-main-module(
549+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
550+ resolver:url-resolver#2, ());
551+xqxq:evaluate($queryID)
552
553=== added file 'test/Queries/xqxq/url-schema-resolver2.xq'
554--- test/Queries/xqxq/url-schema-resolver2.xq 1970-01-01 00:00:00 +0000
555+++ test/Queries/xqxq/url-schema-resolver2.xq 2012-10-19 01:25:26 +0000
556@@ -0,0 +1,29 @@
557+import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
558+
559+import module namespace ddl =
560+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";
561+import module namespace dml =
562+ "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/dml";
563+
564+declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';
565+declare namespace op = "http://www.zorba-xquery.com/options/features";
566+declare namespace f = "http://www.zorba-xquery.com/features";
567+declare option op:enable "f:hof";
568+
569+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
570+ if ($entity = 'schema')
571+ then
572+ dml:collection("http://www.zorba-xquery.com/modules/xqxq")//xs:schema[@targetNamespace=$namespace]
573+ else
574+ ()
575+};
576+
577+declare variable $coll := "http://www.zorba-xquery.com/modules/xqxq";
578+declare variable $schema := doc("test.xsd");
579+ddl:create($coll);
580+
581+dml:apply-insert-nodes-first($coll, $schema);
582+variable $query-key := xqxq:prepare-main-module(
583+ "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
584+ resolver:url-resolver#2, ());
585+xqxq:evaluate($query-key)

Subscribers

People subscribed via source and target branches

to all changes: