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
=== modified file 'src/xqxq.xq'
--- src/xqxq.xq 2012-09-28 13:48:30 +0000
+++ src/xqxq.xq 2012-10-19 01:25:26 +0000
@@ -26,9 +26,12 @@
26module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';26module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
2727
28declare namespace an = "http://www.zorba-xquery.com/annotations";28declare namespace an = "http://www.zorba-xquery.com/annotations";
29
30declare namespace ver = "http://www.zorba-xquery.com/options/versioning";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
31declare option ver:module-version "1.0";33declare option ver:module-version "1.0";
34declare option op:enable "f:hof";
3235
33(:~36(:~
34 : The function prepares a given XQuery program for execution.37 : The function prepares a given XQuery program for execution.
@@ -56,6 +59,106 @@
56 xs:anyURI external;59 xs:anyURI external;
5760
58(:~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(:~
59 : This function compiles a given XQuery library module. It can be used162 : This function compiles a given XQuery library module. It can be used
60 : to compile-check a module. 163 : to compile-check a module.
61 :164 :
@@ -265,3 +368,14 @@
265 :)368 :)
266declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as369declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
267 empty-sequence() external;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};
268382
=== modified file 'src/xqxq.xq.src/xqxq.cpp'
--- src/xqxq.xq.src/xqxq.cpp 2012-10-01 17:54:38 +0000
+++ src/xqxq.xq.src/xqxq.cpp 2012-10-19 01:25:26 +0000
@@ -226,6 +226,116 @@
226226
227 /*******************************************************************************************227 /*******************************************************************************************
228 *******************************************************************************************/228 *******************************************************************************************/
229 static void streamReleaser(std::istream* aStream)
230 {
231 delete aStream;
232 }
233
234 void
235 PrepareMainModuleFunction::XQXQURIMapper::mapURI(
236 String aUri,
237 EntityData const* aEntityData,
238 std::vector<String>& oUris)
239 {
240 //Create entityData string to send to the new url resolver
241 String lDataKind;
242 switch (aEntityData->getKind())
243 {
244 case EntityData::SCHEMA:
245 lDataKind = "schema";
246 break;
247 case EntityData::MODULE:
248 lDataKind = "module";
249 break;
250 default:
251 break;
252 }
253
254 //construct the arguments for the url resolver
255 std::vector<ItemSequence_t> lArgs;
256 ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
257 ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
258 ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
259 lArgs.push_back(lSeq0);
260 lArgs.push_back(lSeq1);
261 lArgs.push_back(lSeq2);
262
263 //invoke the HOF helper function using the arguments generated
264 Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
265 ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
266
267 //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
268 //and then checking if it was empty.
269 Iterator_t lIter = lResult->getIterator();
270 Item lItem;
271 lIter->open();
272 while (lIter->next(lItem))
273 {
274 std::cout << lItem.getStringValue() << std::endl;
275 oUris.push_back(lItem.getStringValue());
276 }
277 lIter->close();
278
279 }
280
281
282 Resource*
283 PrepareMainModuleFunction::XQXQURLResolver::resolveURL(
284 const String& aUrl,
285 EntityData const* aEntityData)
286 {
287 //Create entityData string to send to the new url resolver
288 String lDataKind;
289 switch (aEntityData->getKind())
290 {
291 case EntityData::SCHEMA:
292 lDataKind = "schema";
293 break;
294 case EntityData::MODULE:
295 lDataKind = "module";
296 break;
297 default:
298 break;
299 }
300
301 //construct the arguments for the url resolver
302 std::vector<ItemSequence_t> lArgs;
303 ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
304 ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
305 ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
306 lArgs.push_back(lSeq0);
307 lArgs.push_back(lSeq1);
308 lArgs.push_back(lSeq2);
309
310 //invoke the HOF helper function using the arguments generated
311 Item lHofHelper = XQXQModule::getItemFactory()->createQName("http://www.zorba-xquery.com/modules/xqxq", "xqxq", "hof-invoker");
312 ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
313
314 //Check if the result is an empty sequence by creating an Iterator, this is cheaper than serializing the result
315 //and then checking if it was empty.
316 Iterator_t lIter = lResult->getIterator();
317 Item lItem;
318 lIter->open();
319 lIter->next(lItem);
320 lIter->close();
321 if (lItem.isNull())
322 return NULL;
323
324 //Serialize resulting sequence of the resolver
325 Zorba_SerializerOptions_t lOpt;
326 if (lItem.isNode())
327 lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
328 else
329 lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
330 lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
331 Serializer_t lSer = Serializer::createSerializer(lOpt);
332 std::stringstream lSerResult;
333 lSer->serialize(lResult, lSerResult);
334
335 //return resource
336 return StreamResource::create(new std::istringstream(lSerResult.str()), &streamReleaser);
337 }
338
229 zorba::ItemSequence_t339 zorba::ItemSequence_t
230 PrepareMainModuleFunction::evaluate(340 PrepareMainModuleFunction::evaluate(
231 const Arguments_t& aArgs,341 const Arguments_t& aArgs,
@@ -233,6 +343,8 @@
233 const zorba::DynamicContext* aDctx) const 343 const zorba::DynamicContext* aDctx) const
234 {344 {
235 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);345 DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
346 StaticContext_t lSctxChild = aSctx->createChildContext();
347 StaticContext_t lMapperSctx = aSctx->createChildContext();
236 348
237 QueryMap* lQueryMap;349 QueryMap* lQueryMap;
238 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))350 if(!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
@@ -247,9 +359,34 @@
247 359
248 XQuery_t lQuery;360 XQuery_t lQuery;
249 361
362 StaticContext_t ltempSctx = lZorba->createStaticContext();
363 XQXQURLResolver* lResolver = NULL;
364 XQXQURIMapper* lMapper = NULL;
365
366 if ( aArgs.size() > 2 )
367 {
368 Item lMapperFunctionItem = getItemArgument(aArgs, 2);
369 if (!lMapperFunctionItem.isNull())
370 {
371 lMapper = new XQXQURIMapper(lMapperFunctionItem, lSctxChild);
372 ltempSctx->registerURIMapper(lMapper);
373 }
374 }
375
376 if ( aArgs.size() > 1 )
377 {
378 Item lResolverFunctionItem = getItemArgument(aArgs, 1);
379 if (!lResolverFunctionItem.isNull())
380 {
381 lResolver = new XQXQURLResolver(lResolverFunctionItem, lSctxChild);
382 ltempSctx->registerURLResolver(lResolver);
383 }
384
385 }
386
250 try387 try
251 {388 {
252 lQuery = lZorba->compileQuery(lQueryString);389 lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
253 }390 }
254 catch (XQueryException& xe)391 catch (XQueryException& xe)
255 {392 {
@@ -277,12 +414,18 @@
277 lStream << lUUID;414 lStream << lUUID;
278415
279 String lStrUUID = lStream.str();416 String lStrUUID = lStream.str();
417
418 lQueryMap->storeQuery(lStrUUID, lQuery);
280 419
281 lQueryMap->storeQuery(lStrUUID, lQuery);420 if (lResolver)
421 delete lResolver;
422 if (lMapper)
423 delete lMapper;
282424
283 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));425 return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
284 }426 }
285427
428
286 /*******************************************************************************************429 /*******************************************************************************************
287 *******************************************************************************************/430 *******************************************************************************************/
288 zorba::ItemSequence_t431 zorba::ItemSequence_t
289432
=== modified file 'src/xqxq.xq.src/xqxq.h'
--- src/xqxq.xq.src/xqxq.h 2012-10-01 17:54:38 +0000
+++ src/xqxq.xq.src/xqxq.h 2012-10-19 01:25:26 +0000
@@ -49,6 +49,7 @@
4949
50 };50 };
5151
52
52 class QueryMap : public ExternalFunctionParameter{53 class QueryMap : public ExternalFunctionParameter{
53 private:54 private:
54 typedef std::map<String, XQuery_t> QueryMap_t;55 typedef std::map<String, XQuery_t> QueryMap_t;
@@ -117,7 +118,7 @@
117 public:118 public:
118 PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}119 PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
119120
120 virtual ~PrepareMainModuleFunction(){}121 virtual ~PrepareMainModuleFunction(){ }
121 122
122 virtual zorba::String123 virtual zorba::String
123 getLocalName() const { return "prepare-main-module"; }124 getLocalName() const { return "prepare-main-module"; }
@@ -126,6 +127,43 @@
126 evaluate(const Arguments_t&,127 evaluate(const Arguments_t&,
127 const zorba::StaticContext*,128 const zorba::StaticContext*,
128 const zorba::DynamicContext*) const;129 const zorba::DynamicContext*) const;
130
131 protected:
132
133 class XQXQURLResolver : public URLResolver
134 {
135 protected:
136 Item theFunction;
137 StaticContext_t theCtx;
138
139 public:
140 XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx) : URLResolver(), theFunction(aFunction), theCtx(aSctx) {}
141
142 virtual ~XQXQURLResolver(){ }
143
144 virtual Resource* resolveURL(const String& aUrl,
145 EntityData const* aEntityData);
146
147 };
148
149 class XQXQURIMapper : public URIMapper
150 {
151 protected:
152 Item theFunction;
153 StaticContext_t theCtx;
154
155 public:
156 XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx) : URIMapper(), theFunction(aFunction), theCtx(aSctx) {}
157
158 virtual ~XQXQURIMapper(){ }
159
160 virtual void mapURI(
161 const zorba::String aUri,
162 EntityData const* aEntityData,
163 std::vector<zorba::String>& oUris);
164
165 };
166
129 };167 };
130168
131 class PrepareLibraryModuleFunction : public XQXQFunction{169 class PrepareLibraryModuleFunction : public XQXQFunction{
132170
=== added file 'test/ExpQueryResults/xqxq/uri-mapper.xml.res'
--- test/ExpQueryResults/xqxq/uri-mapper.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/uri-mapper.xml.res 2012-10-19 01:25:26 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2foo
03
=== added file 'test/ExpQueryResults/xqxq/uri-mapper2.xml.res'
--- test/ExpQueryResults/xqxq/uri-mapper2.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/uri-mapper2.xml.res 2012-10-19 01:25:26 +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/ExpQueryResults/xqxq/url-module-resolver.xml.res'
--- test/ExpQueryResults/xqxq/url-module-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-module-resolver.xml.res 2012-10-19 01:25:26 +0000
@@ -0,0 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>
2foo
03
=== added file 'test/ExpQueryResults/xqxq/url-schema-resolver.xml.res'
--- test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-schema-resolver.xml.res 2012-10-19 01:25:26 +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/ExpQueryResults/xqxq/url-schema-resolver2.xml.res'
--- test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 1970-01-01 00:00:00 +0000
+++ test/ExpQueryResults/xqxq/url-schema-resolver2.xml.res 2012-10-19 01:25:26 +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/Queries/xqxq/test.xsd'
--- test/Queries/xqxq/test.xsd 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/test.xsd 2012-10-19 01:25:26 +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/Queries/xqxq/uri-mapper.xq'
--- test/Queries/xqxq/uri-mapper.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/uri-mapper.xq 2012-10-19 01:25:26 +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/Queries/xqxq/uri-mapper2.xq'
--- test/Queries/xqxq/uri-mapper2.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/uri-mapper2.xq 2012-10-19 01:25:26 +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/Queries/xqxq/url-module-resolver.xq'
--- test/Queries/xqxq/url-module-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-module-resolver.xq 2012-10-19 01:25:26 +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/Queries/xqxq/url-schema-resolver.xq'
--- test/Queries/xqxq/url-schema-resolver.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-schema-resolver.xq 2012-10-19 01:25:26 +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/Queries/xqxq/url-schema-resolver2.xq'
--- test/Queries/xqxq/url-schema-resolver2.xq 1970-01-01 00:00:00 +0000
+++ test/Queries/xqxq/url-schema-resolver2.xq 2012-10-19 01:25:26 +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)

Subscribers

People subscribed via source and target branches

to all changes: