← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/update3.0_zorba-query-module into lp:zorba

 

Juan Zacarias has proposed merging lp:~zorba-coders/zorba/update3.0_zorba-query-module into lp:zorba.

Commit message:
Update 3.0 for xqxq

Renamed xqxq module to zorba-query module (zq module)

Requested reviews:
  Chris Hillery (ceejatec)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/update3.0_zorba-query-module/+merge/179756

Update 3.0 for xqxq

Renamed xqxq module to zorba-query module (zq module)
-- 
https://code.launchpad.net/~zorba-coders/zorba/update3.0_zorba-query-module/+merge/179756
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-08-09 23:05:46 +0000
+++ ChangeLog	2013-08-12 17:27:54 +0000
@@ -69,7 +69,8 @@
     (doing implicit iteration over the input sequence and skipping items
      that are not objects/arrays).
   * Bug fix: selector value in object/array navigation is always cast to
-    string/integer
+    string/integer.
+  * Renamed XQXQ module to zorba-query module (ZQ module).
 
 version 2.9
 
@@ -95,7 +96,7 @@
   * Allow multiple default function namespaces.
   * Implemented computed namespace constructors and namespace-node() kindTest.
   * $array() => jn:members($array), $object() => jn:keys($object)
-  * Added xqxq:variable-value function.
+  * Added zq:variable-value function.
   * Added canonicalize function to modules/xml.
   * Added support for xs:dateTimeStamp type from XMLSchema 1.1, bug #924754.
   * Implemented resolution of module-import cycles according to the W3C XQuery 3.0 spec.

=== modified file 'doc/zorba/xqdoc/images/modules.svg'
--- doc/zorba/xqdoc/images/modules.svg	2013-08-07 05:28:39 +0000
+++ doc/zorba/xqdoc/images/modules.svg	2013-08-12 17:27:54 +0000
@@ -594,10 +594,10 @@
 <text text-anchor="middle" x="1306" y="-511.8" font-family="Times,serif" font-size="14.00">Programming Languages</text>
 </a>
 </g>
-<g id="graph100" class="cluster"><title>clusterZorbaProgrammingLanguagesXQXQ</title>
-<a xlink:title="Zorba/Programming Languages/XQXQ">
+<g id="graph100" class="cluster"><title>clusterZorbaProgrammingLanguagesZQ</title>
+<a xlink:title="Zorba/Programming Languages/ZQ">
 <polygon fill="lightsteelblue" stroke="black" points="1308,-421 1308,-496 1382,-496 1382,-421 1308,-421"/>
-<text text-anchor="middle" x="1345" y="-480.8" font-family="Times,serif" font-size="14.00">XQXQ</text>
+<text text-anchor="middle" x="1345" y="-480.8" font-family="Times,serif" font-size="14.00">ZQ</text>
 </a>
 </g>
 <g id="graph101" class="cluster"><title>clusterZorbaProgrammingLanguagesXSLT</title>
@@ -1895,9 +1895,9 @@
 </g>
 <!-- 45 -->
 <g id="node178" class="node"><title>45</title>
-<a xlink:href="../modules_zorba_programming_languages_XQXQ.html" xlink:title="(Zorba-core) module uri=http://www.zorba-xquery.com/modules/xqxq";>
+<a xlink:href="../modules_zorba_programming_languages_ZQ.html" xlink:title="(Zorba-core) module uri=http://zorba.io/modules/zorba-query";>
 <ellipse fill="white" stroke="white" cx="1345" cy="-447" rx="28.3955" ry="18"/>
-<text text-anchor="middle" x="1345" y="-443.3" font-family="Times,serif" font-size="14.00" fill="red">xqxq</text>
+<text text-anchor="middle" x="1345" y="-443.3" font-family="Times,serif" font-size="14.00" fill="red">zorba-query</text>
 </a>
 </g>
 <!-- 51 -->

=== modified file 'doc/zorba/xqdoc/images/modules_new.svg'
--- doc/zorba/xqdoc/images/modules_new.svg	2013-08-07 05:28:39 +0000
+++ doc/zorba/xqdoc/images/modules_new.svg	2013-08-12 17:27:54 +0000
@@ -595,9 +595,9 @@
 </a>
 </g>
 <g id="graph100" class="cluster"><title>clusterZorbaProgrammingLanguagesXQXQ</title>
-<a xlink:title="Zorba/Programming Languages/XQXQ">
+<a xlink:title="Zorba/Programming Languages/ZQ">
 <polygon fill="lightsteelblue" stroke="black" points="1308,-421 1308,-496 1382,-496 1382,-421 1308,-421"/>
-<text text-anchor="middle" x="1345" y="-480.8" font-family="Times,serif" font-size="14.00">XQXQ</text>
+<text text-anchor="middle" x="1345" y="-480.8" font-family="Times,serif" font-size="14.00">ZQ</text>
 </a>
 </g>
 <g id="graph101" class="cluster"><title>clusterZorbaProgrammingLanguagesXSLT</title>
@@ -1895,9 +1895,9 @@
 </g>
 <!-- 45 -->
 <g id="node178" class="node"><title>45</title>
-<a xlink:href="../modules_zorba_programming_languages_XQXQ.html" xlink:title="(Zorba-core) module uri=http://www.zorba-xquery.com/modules/xqxq";>
+<a xlink:href="../modules_zorba_programming_languages_ZQ.html" xlink:title="(Zorba-core) module uri=http://zorba.io/modules/zorba-query";>
 <ellipse fill="white" stroke="white" cx="1345" cy="-447" rx="28.3955" ry="18"/>
-<text text-anchor="middle" x="1345" y="-443.3" font-family="Times,serif" font-size="14.00" fill="red">xqxq</text>
+<text text-anchor="middle" x="1345" y="-443.3" font-family="Times,serif" font-size="14.00" fill="red">zorba-query</text>
 </a>
 </g>
 <!-- 51 -->

=== modified file 'modules/CMakeLists.txt'
--- modules/CMakeLists.txt	2013-08-07 23:46:25 +0000
+++ modules/CMakeLists.txt	2013-08-12 17:27:54 +0000
@@ -16,7 +16,7 @@
 ADD_SUBDIRECTORY(com)
 ADD_SUBDIRECTORY(org)
 ADD_SUBDIRECTORY(functx)
-ADD_SUBDIRECTORY(xqxq)
+ADD_SUBDIRECTORY(zorba-query)
 ADD_SUBDIRECTORY(w3c)
 ADD_SUBDIRECTORY(full-text)
 ADD_SUBDIRECTORY(xml)

=== removed file 'modules/xqxq/CMakeLists.txt'
--- modules/xqxq/CMakeLists.txt	2013-04-09 14:22:41 +0000
+++ modules/xqxq/CMakeLists.txt	1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
-# Copyright 2006-2012 The FLWOR Foundation.
-# 
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-# 
-# http://www.apache.org/licenses/LICENSE-2.0
-# 
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/xqxq"; VERSION 2.0 FILE "xqxq.xq")
\ No newline at end of file

=== removed directory 'modules/xqxq/xqxq.xq.src'
=== removed file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
--- modules/xqxq/xqxq.xq.src/xqxq.cpp	2013-08-01 11:24:18 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.cpp	1970-01-01 00:00:00 +0000
@@ -1,1107 +0,0 @@
-#include <zorba/item_factory.h>
-#include <zorba/singleton_item_sequence.h>
-#include <zorba/diagnostic_list.h>
-#include <zorba/empty_sequence.h>
-#include <zorba/store_manager.h>
-#include <zorba/user_exception.h>
-#include <zorba/uri_resolvers.h>
-#include <zorba/vector_item_sequence.h>
-#include <zorba/serializer.h>
-#include <zorba/xquery.h>
-#include <time.h>
-#include <stdio.h>
-#include <zorba/util/uuid.h>
-#include <vector>
-
-#include "xqxq.h"
-
-namespace zorba { namespace xqxq {
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ExternalFunction*
-XQXQModule::getExternalFunction(const zorba::String& localName)
-{
-  FuncMap_t::iterator lIte = theFunctions.find(localName);
-    
-  ExternalFunction*& lFunc = theFunctions[localName];
-
-  if (lIte == theFunctions.end())
-  {
-    if (localName == "prepare-main-module")
-    {
-      lFunc = new PrepareMainModuleFunction(this);
-    }
-    if (localName == "prepare-library-module")
-    {
-      lFunc = new PrepareLibraryModuleFunction(this);
-    }
-    else if (localName == "is-bound-context-item")
-    {
-      lFunc = new IsBoundContextItemFunction(this);
-    }
-    else if (localName == "is-bound-variable")
-    {
-      lFunc = new IsBoundVariableFunction(this);
-    }
-    else if (localName == "external-variables")
-    {
-      lFunc = new GetExternalVariablesFunction(this);
-    }
-    else if (localName == "is-updating")
-    {
-      lFunc = new IsUpdatingFunction(this);        
-    }
-    else if (localName == "is-sequential")
-    {
-      lFunc = new IsSequentialFunction(this);
-    }      
-    else if (localName == "bind-context-item")
-    {
-      lFunc = new BindContextItemFunction(this);
-    }
-    else if (localName == "bind-variable")
-    {
-      lFunc = new BindVariableFunction(this);
-    }
-    else if (localName == "evaluate")
-    {
-      lFunc = new EvaluateFunction(this);
-    }
-    else if (localName == "evaluate-updating")
-    {
-      lFunc = new EvaluateUpdatingFunction(this);
-    }
-    else if (localName == "evaluate-sequential")
-    {
-      lFunc = new EvaluateSequentialFunction(this);
-    }
-    else if (localName == "delete-query")
-    {
-      lFunc = new DeleteQueryFunction(this);
-    }
-    else if (localName == "variable-value")
-    {
-      lFunc = new VariableValueFunction(this);
-    }
-    else if (localName == "query-plan")
-    {
-      lFunc = new QueryPlanFunction(this);
-    }
-    else if (localName == "load-from-query-plan")
-    {
-      lFunc = new LoadFromQueryPlanFunction(this);
-    }
-  }
-  
-  return lFunc;
-}
-    
-
-/*******************************************************************************
-
-********************************************************************************/
-void XQXQModule::destroy() 
-{
-  delete this;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-XQXQModule::~XQXQModule()
-{
-  for (FuncMap_t::const_iterator lIter = theFunctions.begin();
-       lIter != theFunctions.end(); ++lIter) 
-  {
-    delete lIter->second;
-  }
-  theFunctions.clear();
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-QueryData::QueryData(XQuery_t aQuery, URIMapper *aMapper, URLResolver *aResolver)
-  :
-  theQuery(aQuery),
-  theURIMapper(aMapper),
-  theURLResolver(aResolver)
-{
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-QueryData::~QueryData()
-{
-  theQuery->close();
-  delete theURIMapper;
-  delete theURLResolver;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-QueryMap::QueryMap()
-{
-  theQueryMap = new QueryMap_t();
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-bool  QueryMap::storeQuery(
-    const String& aKeyName,
-    XQuery_t aQuery,
-    URIMapper* aMapper,
-    URLResolver* aResolver)
-{
-  QueryData_t lQueryData(new QueryData(aQuery, aMapper, aResolver));
-
-  std::pair<QueryMap_t::iterator,bool> ret;
-
-  ret = theQueryMap->insert(std::pair<String, QueryData_t>(aKeyName, lQueryData));
-
-  return ret.second;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-XQuery_t QueryMap::getQuery(const String& aKeyName)
-{
-  QueryMap::QueryMap_t::iterator lIter = theQueryMap->find(aKeyName);
-
-  if (lIter == theQueryMap->end())
-    return NULL;
-    
-  XQuery_t lQuery = lIter->second->getQuery();
-
-  return lQuery;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-bool QueryMap::deleteQuery(const String& aKeyName)
-{
-  QueryMap::QueryMap_t::iterator lIter = theQueryMap->find(aKeyName);
-
-  if (lIter == theQueryMap->end())
-    return false;
-
-  theQueryMap->erase(lIter);
-  return true;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void QueryMap::destroy() throw()
-{
-  if (theQueryMap)
-  {
-    delete theQueryMap;
-  }
-  delete this;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-static void streamReleaser(std::istream* aStream)
-{
-  delete aStream;
-}  
-  
-
-/*******************************************************************************
-
-********************************************************************************/
-void XQXQFunction::throwError(const char *err_localname, const std::string& aErrorMessage)
-{
-  String errNS(XQXQ_MODULE_NAMESPACE);
-  String errName(err_localname);
-  Item errQName = XQXQModule::getItemFactory()->createQName(errNS, errName);
-  String errDescription(aErrorMessage);
-  throw USER_EXCEPTION(errQName, errDescription);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-XQXQFunction::XQXQFunction(const XQXQModule* aModule)
-  :
-  theModule(aModule)
-{
-  srand(::time(NULL));
-}
-    
-
-/*******************************************************************************
-
-********************************************************************************/
-XQXQFunction::~XQXQFunction()
-{
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-String XQXQFunction::getURI() const 
-{
-  return theModule->getURI();
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-String XQXQFunction::getOneStringArgument(const Arguments_t& aArgs, int aPos) const
-{
-  Item lItem;
-  Iterator_t args_iter = aArgs[aPos]->getIterator();
-  args_iter->open();
-  args_iter->next(lItem);
-  String lTmpString = lItem.getStringValue();
-  args_iter->close();
-  return lTmpString;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-Item XQXQFunction::getItemArgument(const Arguments_t& aArgs, int aPos) const
-{
-  Item lItem;
-  Iterator_t args_iter = aArgs[aPos]->getIterator();
-  args_iter->open();
-  args_iter->next(lItem);
-  args_iter->close();
-  
-  return lItem;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-Iterator_t XQXQFunction::getIterArgument(const Arguments_t& aArgs, int aPos) const
-{
-  Iterator_t args_iter = aArgs[aPos]->getIterator();
-  return args_iter;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-XQuery_t XQXQFunction::getQuery(
-    const zorba::DynamicContext* aDctx,
-    const zorba::String& aIdent) const
-{
-  QueryMap* lQueryMap;
-
-  if (!(lQueryMap =
-        dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    throwError("NoQueryMatch", "No query with the given identifier was found");
-  }
-  
-  XQuery_t lQuery;
-  if (!(lQuery = lQueryMap->getQuery(aIdent)))
-    throwError("NoQueryMatch", "No query with the given identifier was found");
-  
-  return lQuery;
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void  XQXQURIMapper::mapURI(
-    String aUri,
-    EntityData const* aEntityData,
-    std::vector<String>& oUris)
-{
-  //Create entityData string to send to the new url resolver
-  String lDataKind;
-  switch (aEntityData->getKind())
-  {
-  case EntityData::SCHEMA:
-    lDataKind = "schema";
-    break;
-  case EntityData::MODULE:
-    lDataKind = "module";
-    break;
-  default:
-    break;
-  }
-  
-  //construct the arguments for the url resolver
-  std::vector<ItemSequence_t> lArgs;
-  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
-  ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUri));
-  ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
-  lArgs.push_back(lSeq0);
-  lArgs.push_back(lSeq1);
-  lArgs.push_back(lSeq2);
-
-  //invoke the HOF helper function using the arguments generated
-  Item lHofHelper = XQXQModule::getItemFactory()->
-  createQName("http://www.zorba-xquery.com/modules/xqxq";, "xqxq", "hof-invoker");
-
-  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
-  
-  //Check if the result is an empty sequence by creating an Iterator, this is
-  // cheaper than serializing the result and then checking if it was empty.
-  Iterator_t lIter = lResult->getIterator();
-  Item lItem;
-  lIter->open();
-  while (lIter->next(lItem))
-  {
-    //std::cout << lItem.getStringValue() << std::endl;
-    oUris.push_back(lItem.getStringValue());
-  }
-  lIter->close();  
-}
-      
-
-/*******************************************************************************
-
-********************************************************************************/
-Resource* XQXQURLResolver::resolveURL(
-    const String& aUrl,
-    EntityData const* aEntityData)
-{ 
-  //Create entityData string to send to the new url resolver
-  String lDataKind;
-  switch (aEntityData->getKind())
-  {
-  case EntityData::SCHEMA:
-    lDataKind = "schema";
-    break;
-  case EntityData::MODULE:
-    lDataKind = "module";
-    break;
-  default:
-    break;
-  }
-
-  //construct the arguments for the url resolver
-  std::vector<ItemSequence_t> lArgs;
-  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
-  ItemSequence_t lSeq1 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(aUrl));
-  ItemSequence_t lSeq2 = new SingletonItemSequence(XQXQModule::getItemFactory()->createString(lDataKind));
-  lArgs.push_back(lSeq0);
-  lArgs.push_back(lSeq1);
-  lArgs.push_back(lSeq2);
-  
-  //invoke the HOF helper function using the arguments generated
-  Item lHofHelper = XQXQModule::getItemFactory()->
-  createQName("http://www.zorba-xquery.com/modules/xqxq";, "xqxq", "hof-invoker");
-
-  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
-
-  // Check if the result is an empty sequence by creating an Iterator, this is
-  // cheaper than serializing the result and then checking if it was empty.
-  Iterator_t lIter = lResult->getIterator();
-  Item lItem;
-  lIter->open();
-  lIter->next(lItem);
-  lIter->close();
-  lIter = NULL;
-
-  if (lItem.isNull())
-    return NULL;
-
-  //Serialize resulting sequence of the resolver
-  Zorba_SerializerOptions_t lOpt;
-  if (lItem.isNode())
-    lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
-  else
-    lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
-
-  lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
-  Serializer_t lSer = Serializer::createSerializer(lOpt);
-  std::stringstream lSerResult;
-  lSer->serialize(lResult, lSerResult);
-  
-  //return resource
-  return StreamResource::create(new std::istringstream(lSerResult.str()),
-                                &streamReleaser);
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t PrepareMainModuleFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
-  StaticContext_t lSctxChild = aSctx->createChildContext();
-   
-  QueryMap* lQueryMap;
-  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    lQueryMap = new QueryMap();
-    lDynCtx->addExternalFunctionParameter("xqxqQueryMap", lQueryMap);     
-  }
-
-  Zorba* lZorba = Zorba::getInstance(0);
-
-  String lQueryString = getOneStringArgument(aArgs, 0); 
-    
-  XQuery_t lQuery;
-    
-  StaticContext_t ltempSctx = lZorba->createStaticContext();
-
-  std::auto_ptr<XQXQURLResolver> lResolver;
-  std::auto_ptr<XQXQURIMapper> lMapper;
-
-  if ( aArgs.size() > 2 )
-  {
-    Item lMapperFunctionItem = getItemArgument(aArgs, 2);
-    if (!lMapperFunctionItem.isNull())
-    {
-      lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
-      ltempSctx->registerURIMapper(lMapper.get());
-    }
-  }
-
-  if ( aArgs.size() > 1 )
-  {
-    Item lResolverFunctionItem = getItemArgument(aArgs, 1);
-    if (!lResolverFunctionItem.isNull())
-    {
-      lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
-      ltempSctx->registerURLResolver(lResolver.get());
-    }  
-  }
-  
-  try
-  {
-    //std::cout << "Hello: " << lQueryString << std::endl;
-    lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
-  }
-  catch (XQueryException& xe)
-  {
-    lQuery = NULL;
-    std::ostringstream err;
-    err << "The query compiled using xqxq:prepare-main-module raised an error at"
-        << " file " << xe.source_uri() << " line " << xe.source_line()
-        << " column " << xe.source_column() << ": " << xe.what();
-    // << " -- Query string : " << std::endl << lQueryString;
-
-    Item errQName = XQXQModule::getItemFactory()->createQName(
-                                xe.diagnostic().qname().ns(),
-                                xe.diagnostic().qname().localname());
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-  catch (ZorbaException& e)
-  {
-    lQuery = NULL;
-    std::ostringstream err;
-    err << "The query compiled using xqxq:prepare-main-module raised an error: "
-        << e.what();
-
-    Item errQName = XQXQModule::getItemFactory()->
-    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
-
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-  
-  uuid lUUID;
-  uuid::create(&lUUID);
-  
-  std::stringstream lStream;
-  lStream << lUUID;
-  
-  String lStrUUID = lStream.str();
-  
-  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
-  
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
-}
-    
-    
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t PrepareLibraryModuleFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  Zorba *lZorba = Zorba::getInstance(0);
-  String lQueryString = getOneStringArgument(aArgs, 0);     
- 
-  Zorba_CompilerHints_t hints;
-  hints.lib_module = true;
-
-  try
-  {
-    lZorba->compileQuery(lQueryString, hints);
-  }
-  catch (XQueryException& xe)
-  {
-    std::ostringstream err;
-    err << "The query compiled using xqxq:prepare-library-module raised an error at"
-        << " line " << xe.source_line() << " column " << xe.source_column()
-        << ": " << xe.what();
-
-    Item errQName = XQXQModule::getItemFactory()->
-    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
-
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-  catch (ZorbaException& e)
-  {
-    std::ostringstream err;
-    err << "The query compiled using xqxq:prepare-main-query raised an error: "
-        << e.what();
-
-      Item errQName = XQXQModule::getItemFactory()->
-      createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
-
-      throw USER_EXCEPTION(errQName, err.str());
-    }
-    return ItemSequence_t(new EmptySequence());
-  }
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t IsBoundContextItemFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  bool lIsContextItemBound = lQuery->getDynamicContext()->isBoundContextItem();
-
-  return ItemSequence_t(new SingletonItemSequence(
-          XQXQModule::getItemFactory()->createBoolean(lIsContextItemBound)));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t IsBoundVariableFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
-  bool lIsBoundVariable = false;
-
-  try
-  {
-    lIsBoundVariable = lQuery->getDynamicContext()->isBoundExternalVariable(lVarQName.getNamespace(),lVarQName.getLocalName());
-  }
-  catch (ZorbaException& ze)
-  {
-    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
-      XQXQFunction::throwError("UndeclaredVariable", ze.what());  
-    throw; // should not happen
-  }
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lIsBoundVariable)));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t GetExternalVariablesFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{  
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-    
-  std::vector<Item> lVars;
-  Iterator_t lVarsIterator;
-  lQuery->getExternalVariables(lVarsIterator);
-
-  Item lVar;
-  lVarsIterator->open();
-  while(lVarsIterator->next(lVar))
-    lVars.push_back(lVar);
-  lVarsIterator->close();
-  
-  return ItemSequence_t(new VectorItemSequence(lVars));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t IsUpdatingFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isUpdating())));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t IsSequentialFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createBoolean(lQuery->isSequential())));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t BindContextItemFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  // shouldn't raise errors
-  Item lItemContext = XQXQFunction::getItemArgument(aArgs, 1);
-  lQuery->getDynamicContext()->setContextItem(lItemContext);
-
-  return ItemSequence_t(new EmptySequence());
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t BindContextPositionFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
-
-  return ItemSequence_t(new EmptySequence());
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t BindContextSizeFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  XQXQFunction::throwError("ImplementationError", "This function is not implemented yet");
-
-  return ItemSequence_t(new EmptySequence());
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t BindVariableFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-    
-  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1); 
-
-  Iterator_t lVarValue = XQXQFunction::getIterArgument(aArgs, 2); 
-
-  if (!lQuery->getDynamicContext()->setVariable(lVarQName.getNamespace(),
-                                                lVarQName.getLocalName(),
-                                                lVarValue))
-  {
-    std::ostringstream lMsg;
-    lMsg << "{" << lVarQName.getNamespace() << "}" << lVarQName.getLocalName()
-         << ": undefined variable";
-
-    throwError("UndeclaredVariable", lMsg.str());
-  }
-
-  return ItemSequence_t(new EmptySequence());
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-bool EvaluateItemSequence::EvaluateIterator::next(Item& aItem)
-{
-  try
-  {
-    return theIterator->next(aItem);
-  }
-  catch (XQueryException& xe)
-  {
-    std::ostringstream err;
-    err << "The query " << "(" << theQueryID
-        << ") evaluated using xqxq:evaluate raised an error at"
-        << " line " << xe.source_line() << " column "
-        << xe.source_column() << ": " << xe.what();
-
-    Item errQName = XQXQModule::getItemFactory()->
-    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
-
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-  catch (ZorbaException& e)
-  {
-    std::ostringstream err;
-    err << "The query " << "(" << theQueryID
-        << ") evaluated using xqxq:evaluate raised an error at"
-        << e.what();
-
-    Item errQName = XQXQModule::getItemFactory()->
-    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
-
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t EvaluateFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  if (lQuery->isUpdating())
-  {
-    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
-  }
-     
-  if (lQuery->isSequential())
-  {
-    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");
-  }
-      
-  Iterator_t lIterQuery = lQuery->iterator();
-
-  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t EvaluateUpdatingFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-    
-  if (lQuery->isSequential())
-  {
-    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");   
-  }
-
-  if(!lQuery->isUpdating())
-  {
-    throwError("QueryNotUpdating", "Executing Query should be updating.") ; 
-  }
-  
-  Iterator_t lIterQuery = lQuery->iterator();
-  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t EvaluateSequentialFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs, 0);
-  
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  if(lQuery->isUpdating())
-  {
-    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
-  }
-
-  if(!lQuery->isSequential())
-  {
-    throwError("QueryNotSequential", "Executing Query should be sequential.");    
-  }
-
-  Iterator_t lIterQuery = lQuery->iterator();
-  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t DeleteQueryFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-
-  QueryMap* lQueryMap;
-  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    throwError("NoQueryMatch", "String identifying query does not exists.");
-  }
-
-  if (!lQueryMap->deleteQuery(lQueryID))
-  {
-    throwError("NoQueryMatch","String identifying query does not exists.");
-  }
-      
-  return ItemSequence_t(new EmptySequence());
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t VariableValueFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-
-  QueryMap* lQueryMap;
-  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    throwError("NoQueryMatch", "String identifying query does not exists.");
-  }
-
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
-  bool lIsBoundVariable = false;
-
-  zorba::DynamicContext* lCtx = lQuery->getDynamicContext();
-  zorba::String lNS = lVarQName.getNamespace(), lLocal = lVarQName.getLocalName();
-
-  try
-  {
-    lIsBoundVariable = lCtx->isBoundExternalVariable(lNS, lLocal);
-  }
-  catch (ZorbaException& ze)
-  {
-    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
-      XQXQFunction::throwError("UndeclaredVariable", ze.what());  
-    throw; // should not happen
-  }
-
-  if (!lIsBoundVariable)
-  {
-    std::ostringstream lMsg;
-    lMsg << lLocal << ": variable not bound";
-    XQXQFunction::throwError("UnboundVariable", lMsg.str());  
-  }
-
-  zorba::Iterator_t lIterator;
-  zorba::Item lItem;
-
-  lCtx->getVariable(lNS, lLocal, lItem, lIterator);
-      
-  if (lIterator)
-  {
-    return ItemSequence_t(new ValueItemSequence(lIterator));
-  }
-  else
-  {
-    return ItemSequence_t(new SingletonItemSequence(lItem));
-  }
-}
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t QueryPlanFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
-
-  QueryMap* lQueryMap;
-  if (!(lQueryMap = dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    throwError("NoQueryMatch", "String identifying query does not exists.");
-  }
-
-  XQuery_t lQuery = getQuery(aDctx, lQueryID);
-
-  std::auto_ptr<std::stringstream> lExcPlan;
-  lExcPlan.reset(new std::stringstream());
-  if (!lQuery->saveExecutionPlan(*lExcPlan.get()))
-  {
-    throwError("QueryPlanError", "FAILED getting query execution plan.");
-  }
-  
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createStreamableBase64Binary(*lExcPlan.release(), &streamReleaser)));
-}
- 
-
-/*******************************************************************************
-
-********************************************************************************/
-zorba::ItemSequence_t LoadFromQueryPlanFunction::evaluate(
-    const Arguments_t& aArgs,
-    const zorba::StaticContext* aSctx,
-    const zorba::DynamicContext* aDctx) const 
-{
-  Item lQueryPlanItem = XQXQFunction::getItemArgument(aArgs,0);
-  std::istream& lQueryPlanStream = lQueryPlanItem.getStream();
-
-  DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
-  StaticContext_t lSctxChild = aSctx->createChildContext();
-   
-  QueryMap* lQueryMap;
-  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("xqxqQueryMap"))))
-  {
-    lQueryMap = new QueryMap();
-    lDynCtx->addExternalFunctionParameter("xqxqQueryMap", lQueryMap);     
-  }
-
-  Zorba* lZorba = Zorba::getInstance(0);
-  XQuery_t lQuery;
-  
-  std::auto_ptr<XQXQURLResolver> lResolver;
-  std::auto_ptr<XQXQURIMapper> lMapper;
-  try
-  {
-    lQuery = lZorba->createQuery();
-    if ( aArgs.size() > 2)
-    {
-      QueryPlanSerializationCallback lPlanSer;
-
-      Item lMapperFunctionItem = getItemArgument(aArgs, 2);
-      if (!lMapperFunctionItem.isNull())
-      {
-        lMapper.reset(new XQXQURIMapper(lMapperFunctionItem, lSctxChild));
-        lPlanSer.add_URIMapper(lMapper.get());
-      }
-
-      Item lResolverFunctionItem = getItemArgument(aArgs, 1);
-      if (!lResolverFunctionItem.isNull())
-      {
-        lResolver.reset(new XQXQURLResolver(lResolverFunctionItem, lSctxChild));
-        lPlanSer.add_URLResolver(lResolver.get());
-      }
-
-      lQuery->loadExecutionPlan(lQueryPlanStream, &lPlanSer);
-    }
-    else
-    { 
-      lQuery->loadExecutionPlan(lQueryPlanStream);
-    }
-  }
-  catch (XQueryException& xe)
-  {
-    lQuery = NULL;
-    std::ostringstream err;
-    err << "The query loaded from the query plan raised an error at"
-      << " file" << xe.source_uri() << " line" << xe.source_line()
-      << " column" << xe.source_column() << ": " << xe.what();
-    Item errQName = XQXQModule::getItemFactory()->createQName(
-      xe.diagnostic().qname().ns(),
-      xe.diagnostic().qname().localname());
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-  catch (ZorbaException& ze)
-  {
-    lQuery = NULL;
-    std::ostringstream err;
-    if (ze.diagnostic() == zerr::ZCSE0013_UNABLE_TO_LOAD_QUERY)
-      err << "The query loaded from the query plan raised an error: failed to load pre-compiled query: document, collection, or module resolver required but not given.";
-    else
-      err << "The query loaded from the query plan raised an error: "<< ze.what();
-    Item errQName = XQXQModule::getItemFactory()->createQName(
-      ze.diagnostic().qname().ns(),
-      ze.diagnostic().qname().localname());
-    throw USER_EXCEPTION(errQName, err.str());
-  }
-
-  uuid lUUID;
-  uuid::create(&lUUID);
-
-  std::stringstream lStream;
-  lStream << lUUID;
-
-  String lStrUUID = lStream.str();
-
-  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
-  return ItemSequence_t(new SingletonItemSequence(XQXQModule::getItemFactory()->createAnyURI(lStrUUID)));
-}
-
-}/*namespace xqxq*/ }/*namespace zorba*/
-
-#ifdef WIN32
-#  define DLL_EXPORT __declspec(dllexport)
-#else
-#  define DLL_EXPORT __attribute__ ((visibility("default")))
-#endif
-
-extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
-  return new zorba::xqxq::XQXQModule();
-}

=== removed file 'modules/xqxq/xqxq.xq.src/xqxq.h'
--- modules/xqxq/xqxq.xq.src/xqxq.h	2013-04-15 12:07:41 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.h	1970-01-01 00:00:00 +0000
@@ -1,651 +0,0 @@
-#ifndef __COM_ZORBA_WWW_MODULES_XQXQ_H__
-#define __COM_ZORBA_WWW_MODULES_XQXQ_H__
-
-#include <map>
-
-#include <zorba/zorba.h>
-#include <zorba/external_module.h>
-#include <zorba/function.h>
-#include <zorba/dynamic_context.h>
-#include <zorba/serialization_callback.h>
-
-#define XQXQ_MODULE_NAMESPACE "http://www.zorba-xquery.com/modules/xqxq";
-
-namespace zorba { namespace xqxq {
-  
-  
-/*******************************************************************************
-
-********************************************************************************/
-class XQXQModule : public ExternalModule 
-{
-protected:
-  class ltstr
-  {
-  public:
-    bool operator()(const String& s1, const String& s2) const
-    {
-      return s1.compare(s2) < 0;
-    }
-  };
-
-  typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
-
-protected:
-  FuncMap_t theFunctions;
-
-public:
-
-  virtual ~XQXQModule();
-
-  virtual zorba::String getURI() const {return XQXQ_MODULE_NAMESPACE;}
-
-  virtual zorba::ExternalFunction* getExternalFunction(const String& localName);
-
-  virtual void destroy();
-
-  static ItemFactory* getItemFactory()
-  {
-    return Zorba::getInstance(0)->getItemFactory();
-  }
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class XQXQURLResolver : public URLResolver
-{
-protected:
-  Item             theFunction;
-  StaticContext_t  theCtx;
-
-public:
-  XQXQURLResolver(Item& aFunction, StaticContext_t& aSctx)
-    :
-    URLResolver(),
-    theFunction(aFunction),
-    theCtx(aSctx)
-  {
-  }
-        
-  virtual ~XQXQURLResolver() { }
-      
-  virtual Resource* resolveURL(const String& url, EntityData const* entityData);
-};
-  
-
-class XQXQURIMapper : public URIMapper
-{
-protected:
-  Item            theFunction;
-  StaticContext_t theCtx;
-    
-public:
-  XQXQURIMapper(Item& aFunction, StaticContext_t& aSctx)
-    :
-    URIMapper(),
-    theFunction(aFunction),
-    theCtx(aSctx)
-  {
-  }
-    
-  virtual ~XQXQURIMapper(){ }
-    
-  virtual void mapURI(
-    const zorba::String aUri,
-    EntityData const* aEntityData,
-    std::vector<zorba::String>& oUris);
-};
-/*******************************************************************************
-  Bag class for objects associated with a prepared query
-********************************************************************************/
-class QueryData : public SmartObject
-{
-private:
-  XQuery_t      theQuery;
-  URIMapper   * theURIMapper;
-  URLResolver * theURLResolver;
-  
-public:
-  QueryData(XQuery_t aQuery, URIMapper* aMapper, URLResolver* aResolver);
-
-  virtual ~QueryData();
-
-  XQuery_t getQuery() { return theQuery; }
-};
-
-
-typedef SmartPtr<QueryData> QueryData_t;
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class QueryMap : public ExternalFunctionParameter
-{
-private:
-  typedef std::map<String, QueryData_t> QueryMap_t;
-
-private:
-  QueryMap_t  * theQueryMap;
-
-public:
-  QueryMap();
-
-  bool storeQuery(const String&, XQuery_t, URIMapper*, URLResolver*);
-  
-  XQuery_t getQuery(const String&);
-  
-  bool deleteQuery(const String&);
-  
-  virtual void destroy() throw();
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class XQXQFunction : public ContextualExternalFunction
-{
-protected:
-  const XQXQModule * theModule;
-
-protected:
-  static void throwError(const char*, const std::string&);
-
-protected:
-  String getOneStringArgument(const Arguments_t&, int) const;
-
-  Item getItemArgument(const Arguments_t&, int) const;
-
-  Iterator_t getIterArgument(const Arguments_t&, int) const;
-
-  XQuery_t getQuery(
-      const zorba::DynamicContext* dctx,
-      const zorba::String& aIdent) const;
-
-public:
-  XQXQFunction(const XQXQModule* module);
-
-  virtual ~XQXQFunction();
-
-  virtual String getURI() const;
-};
-
-  
-/*******************************************************************************
-
-********************************************************************************/
-class PrepareMainModuleFunction : public XQXQFunction
-{
-public:
-  PrepareMainModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~PrepareMainModuleFunction(){  }
-      
-  virtual zorba::String
-  getLocalName() const { return "prepare-main-module"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class PrepareLibraryModuleFunction : public XQXQFunction
-{
-public:
-  PrepareLibraryModuleFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~PrepareLibraryModuleFunction(){}
-      
-  virtual zorba::String
-  getLocalName() const { return "prepare-library-module"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class IsBoundContextItemFunction : public XQXQFunction
-{
-public:
-  IsBoundContextItemFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~IsBoundContextItemFunction(){}
-
-  virtual zorba::String
-  getLocalName() const { return "is-bound-context-item"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-    
-    
-/*******************************************************************************
-
-********************************************************************************/
-class IsBoundVariableFunction : public XQXQFunction
-{
-public:
-  IsBoundVariableFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~IsBoundVariableFunction(){}
-
-  virtual zorba::String
-  getLocalName() const { return "is-bound-variable"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-    
-
-/*******************************************************************************
-
-********************************************************************************/
-class GetExternalVariablesFunction : public XQXQFunction
-{
-public:
-  GetExternalVariablesFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~GetExternalVariablesFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "external-variables"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class IsUpdatingFunction : public XQXQFunction
-{
-public:
-  IsUpdatingFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~IsUpdatingFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "is-updating"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;  
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class IsSequentialFunction : public XQXQFunction
-{
-public:
-  IsSequentialFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~IsSequentialFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "is-sequential"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class BindContextItemFunction : public XQXQFunction
-{
-public:
-  BindContextItemFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~BindContextItemFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "bind-context-item"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class BindContextPositionFunction : public XQXQFunction
-{
-public:
-  BindContextPositionFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~BindContextPositionFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "bind-context-position"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class BindContextSizeFunction : public XQXQFunction
-{
-public:
-  BindContextSizeFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~BindContextSizeFunction() {}
-  
-  virtual zorba::String
-  getLocalName() const {return "bind-context-size"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class BindVariableFunction : public XQXQFunction
-{
-public:
-  BindVariableFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~BindVariableFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "bind-variable"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class EvaluateItemSequence : public ItemSequence
-{
-protected:
-
-  class EvaluateIterator : public Iterator
-  {
-  protected:
-    Iterator_t theIterator;
-
-    String     theQueryID;
-
-  public:
-    EvaluateIterator(Iterator_t& aIter, String aQueryID)
-      :
-      theIterator(aIter),
-      theQueryID(aQueryID)
-    {
-    }
-
-    virtual ~EvaluateIterator(){}
-
-    virtual void open() { theIterator->open(); }
-
-    virtual bool next(Item& aItem);
-
-    virtual void close() { theIterator->close(); }
-
-    virtual bool isOpen() const { return theIterator->isOpen(); }
-  };
-
-  typedef zorba::SmartPtr<EvaluateIterator> EvaluateIterator_t;
-
-protected:
-  EvaluateIterator_t theIter; 
-
-public:
-  EvaluateItemSequence(Iterator_t& aIter, String& aQueryID)
-    :
-    theIter(new EvaluateIterator(aIter, aQueryID))
-  {
-  }
-  
-  virtual ~EvaluateItemSequence() {}
-
-  Iterator_t getIterator() { return theIter.get(); }
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class EvaluateFunction : public XQXQFunction
-{
-public:
-  EvaluateFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~EvaluateFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "evaluate"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class EvaluateUpdatingFunction : public XQXQFunction
-{
-public:
-  EvaluateUpdatingFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~EvaluateUpdatingFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "evaluate-updating"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class EvaluateSequentialFunction : public XQXQFunction
-{
-public:
-  EvaluateSequentialFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~EvaluateSequentialFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "evaluate-sequential"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-  
-  virtual String getURI() const {
-    return theModule->getURI();
-  }
-  
-protected:
-  const XQXQModule* theModule;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class DeleteQueryFunction : public XQXQFunction
-{
-public:
-  DeleteQueryFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~DeleteQueryFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "delete-query"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-};
-
-  class VariableValueFunction : public XQXQFunction{
-    protected:
-      class ValueItemSequence : public ItemSequence
-      {
-        protected:
-          Iterator_t theIterator;
-
-        public:
-          ValueItemSequence(Iterator_t& aIter)
-            : theIterator(aIter)
-          {
-          }
-
-          virtual ~ValueItemSequence(){}
-
-          Iterator_t
-          getIterator() { return theIterator; }
-
-      };
-    public:
-      VariableValueFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-      virtual ~VariableValueFunction() {}
-
-      virtual zorba::String
-        getLocalName() const {return "variable-value"; }
-
-      virtual zorba::ItemSequence_t
-        evaluate(const Arguments_t&,
-                 const zorba::StaticContext*,
-                 const zorba::DynamicContext*) const;
-  };
-
-/*******************************************************************************
-
-********************************************************************************/
-class QueryPlanFunction : public XQXQFunction
-{
-public:
-  QueryPlanFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~QueryPlanFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "query-plan"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-  
-  virtual String getURI() const {
-    return theModule->getURI();
-  }
-  
-protected:
-  const XQXQModule* theModule;
-};
-
-
-/*******************************************************************************
-
-********************************************************************************/
-class LoadFromQueryPlanFunction : public XQXQFunction
-{
-public:
-  LoadFromQueryPlanFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
-
-  virtual ~LoadFromQueryPlanFunction() {}
-
-  virtual zorba::String
-  getLocalName() const {return "load-from-query-plan"; }
-
-  virtual zorba::ItemSequence_t
-  evaluate(const Arguments_t&,
-           const zorba::StaticContext*,
-           const zorba::DynamicContext*) const;
-  
-  virtual String getURI() const {
-    return theModule->getURI();
-  }
-  
-protected:
-  const XQXQModule* theModule;
-
-  class QueryPlanSerializationCallback : public zorba::SerializationCallback
-  {
-    std::vector<URIMapper*> theUriMappers;
-    std::vector<URLResolver*>theUrlResolvers;
-
-  public:
-    QueryPlanSerializationCallback()
-    {
-    }
-
-    virtual ~QueryPlanSerializationCallback() {}
-
-    void add_URIMapper(URIMapper* aMapper)
-    {
-      theUriMappers.push_back(aMapper);
-    }
-
-    void add_URLResolver(URLResolver* aResolver)
-    {
-      theUrlResolvers.push_back(aResolver);
-    }
-
-    virtual URIMapper*
-      getURIMapper(size_t  i ) const { return theUriMappers.size() < i? NULL : theUriMappers[i]; }
-
-    virtual URLResolver*
-    getURLResolver(size_t i) const { return theUrlResolvers.size() < i? NULL : theUrlResolvers[i]; }
-  };
-};
-}/*xqxq namespace*/}/*zorba namespace*/
-
-
-#endif //_COM_ZORBA_WWW_MODULES_XQXQ_H_

=== renamed directory 'modules/xqxq' => 'modules/zorba-query'
=== added file 'modules/zorba-query/CMakeLists.txt'
--- modules/zorba-query/CMakeLists.txt	1970-01-01 00:00:00 +0000
+++ modules/zorba-query/CMakeLists.txt	2013-08-12 17:27:54 +0000
@@ -0,0 +1,15 @@
+# Copyright 2006-2012 The FLWOR Foundation.
+# 
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+# 
+# http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+DECLARE_ZORBA_MODULE (URI "http://zorba.io/modules/zorba-query"; VERSION 2.0 FILE "zorba-query.xq")
\ No newline at end of file

=== renamed file 'modules/xqxq/xqxq.xq' => 'modules/zorba-query/xqxq.xq.THIS'
=== added file 'modules/zorba-query/zorba-query.xq'
--- modules/zorba-query/zorba-query.xq	1970-01-01 00:00:00 +0000
+++ modules/zorba-query/zorba-query.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,472 @@
+xquery version "3.0";
+(:
+ : Copyright 2011 The FLWOR Foundation.
+ :
+ : Licensed under the Apache License, Version 2.0 (the "License");
+ : you may not use this file except in compliance with the License.
+ : You may obtain a copy of the License at
+ :
+ : http://www.apache.org/licenses/LICENSE-2.0
+ :
+ : Unless required by applicable law or agreed to in writing, software
+ : distributed under the License is distributed on an "AS IS" BASIS,
+ : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ : See the License for the specific language governing permissions and
+ : limitations under the License.
+:)
+
+(:~
+ : This module contains functions to compile and evaluate XQuery
+ : programs. Also, it contains function that allow to parameterize
+ : the static or dynamic evaluation phase.
+ :
+ : @author Juan Zacarias
+ : @project Zorba/Programming Languages/ZQ
+ :)
+module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare namespace ver = "http://www.zorba-xquery.com/options/versioning";;
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare option ver:module-version "2.0";
+
+(:~
+ : The function prepares a given XQuery program for execution.
+ : If the program was successfully compiled, the function returns an
+ : identifier as xs:anyURI. This URI can be passed to other functions
+ : of this module (e.g. to actually evaluate the program). The URI
+ : is opaque and its lilfetime is bound by the lifetime of the XQuery
+ : program that invoked this function. Further reference or uses
+ : of the identifier lead to unexpected results.
+ :
+ : Successfully prepared queries need to be deleted by passing the resulting
+ : identifier to the zq:delete-query function of this module.
+ :
+ : @param $main-module-text the XQuery program that should be prepared.
+ :   The program needs to be a XQuery main module.
+ :
+ : @return an identifier for the compiled program that can be passed
+ :   as arguments to other functions of this module.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the query. For example, err:XPST0003 if the given XQuery program could
+ : not be parsed.
+ :)
+declare %an:sequential function zq:prepare-main-module($main-module-text as xs:string) as 
+  xs:anyURI external;
+
+(:~
+ : The function prepares a given XQuery program for execution.
+ : If the program was successfully compiled, the function returns an
+ : identifier as xs:anyURI. This URI can be passed to other functions
+ : of this module (e.g. to actually evaluate the program). The URI
+ : is opaque and its lilfetime is bound by the lifetime of the XQuery
+ : program that invoked this function. Further reference or uses
+ : of the identifier lead to unexpected results.
+ : 
+ : Important notes regarding the second and third parameters of the function:
+ : --------------------------------------------------------------------------
+ :
+ : These parameters allow you to specify a URL resolver and a URI mapper
+ : for Zorba to use when executing this query. See
+ : http://www.zorba-xquery.com/html/documentation/2.7.0/zorba/uriresolvers
+ :
+ : The second parameter is a function item for a URL
+ : resolver. The URL resolver function must recive 2 parameters:
+ :   A $namespace as xs:string that will contain the url to be resolved.
+ :   A $entity as xs:string that will contain the type of resolving needed;
+ :   this can be 2 values "module" and "schema".
+ : The function must return an empty sequence when the specified $namespace
+ : or $entity are not the ones to be resolved.
+ :
+ : Example:
+ :   
+ : declare function mymod:url-resolver($namespace as xs:string, $entity as xs:string)
+ : {
+ :  if($namespace = 'http://test.xq')
+ :  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+ :  else ()
+ : };
+ :
+ : The URL resolver function's namespace, name, and parameter naming are
+ : not restricted by ZQ.
+ :
+ : The URL resolver function's return type is not restricted, it could be a string, a sequence,
+ : a node, etc. All the outputs types are to be serialized as a string.
+ :
+ : The third parameter is a function item for a URI mapper.
+ : The URI mapper function, just like the URL resolver, receives 2 parameters:
+ :   A $namespace as xs:string that will contain the URI to be mapped.
+ :   A $entity as xs:string that will contain the type of resolving needed;
+ :   this can be 2 values "module" and "schema".
+ : The URI mapper must return an empty sequence when the specified $namesapce or $entity
+ : are not to be mapped. Unlike the URL resolver this function must return a sequence of strings.
+ :
+ : Example:
+ :
+ : declare function mymod:uri-mapper($namespace as xs:string, $entity as xs:string)
+ : {
+ :  if($namespace = 'http://test')
+ :  then ("http://www.zorba-xquery.com/test";, "http://foo.com/schema/test";)
+ :  else ()
+ : };
+ :
+ : The URI mapper function's namespace, name, and parameter naming are
+ : not restricted by ZQ.
+ :
+ : In order to pass the above URL resolver and URI mapper to this function,
+ : use the following syntax:
+ :
+ :   variable $queryID := zq:prepare-main-module("..query text..",
+ :      mymod:url-resolver#2, mymod:uri-mapper#2);
+ :
+ : That is, the QName of the function followed by "#2". This is XQuery
+ : "higher-order function" syntax, meaning the function with the specified
+ : QName which takes two arguments. Since URL resolvers and URI mappers
+ : must take two arguments, both will always be specified with "#2".
+ :
+ : Note that parameters 2 and 3 should be declared as follows:
+ :    as function($url as xs:string, $entity as xs:string) as item()
+ :    as function($uri as xs:string, $entity as xs:string) as xs:string*
+ : However Zorba's implementation of higher-order functions (HOF) is not
+ : yet complete enough to allow for this. When Zorba's HOF implementation
+ : is complete this function signature will be changed.
+ :
+ : Both the URL resolver and URI mapper functions are optional, meaning you
+ : may pass the empty-sequence () for either.
+ :
+ : Successfully prepared queries need to be deleted by passing the resulting
+ : identifier to the zq:delete-query function of this module.
+ :
+ : @param $main-module-text the XQuery program that should be prepared.
+ :   The program needs to be a XQuery main module.
+ :
+ : @param $resolver the URL resolver function.
+ : 
+ : @param $mapper the URI mapper function.
+ :
+ : @return an identifier for the compiled program that can be passed
+ :   as arguments to other functions of this module.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the query. For example, err:XPST0003 if the given XQuery program could
+ : not be parsed.
+ :)
+declare %an:sequential function zq:prepare-main-module($main-module-text as xs:string, $resolver as item()?, $mapper as item()?) as 
+  xs:anyURI external;
+
+(:~
+ : This function compiles a given XQuery library module. It can be used
+ : to compile-check a module. 
+ :
+ : @param $library-module-text the XQuery library module that should
+ :  be prepared. 
+ :
+ : @return the function is declared as sequential.It returns the
+ :  empty-sequence.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the library module. For example, err:XPST0003 if the given XQuery library
+ : module could not be parsed.
+ :)
+declare %an:sequential function zq:prepare-library-module($library-module-text as xs:string) as 
+  empty-sequence() external ;
+
+(:~
+ : The function tests if the context-item is bound for the
+ : execution of the query referred to by the given query identifier.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return true if the context-item is bound, false otherwise.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :)
+declare function zq:is-bound-context-item($query-key as xs:anyURI) 
+  as xs:boolean  external;
+  
+
+(:~
+ : The function tests if the given variable is bound for the
+ : execution of the query referred to by the given query identifier.
+ :
+ : @param $query-key the identifier for a compiled query
+ : @param $var-name the name of the variable
+ :
+ : @return true if the variable is bound, false otherwise.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ : @error zq:UndeclaredVariable if the given variable is not declared
+ :   in the query.
+ :)
+declare function zq:is-bound-variable($query-key as xs:anyURI, $var-name as 
+  xs:QName) as xs:boolean  external;
+
+(:~
+ : The function returns the names of the external variables that
+ : are declared in the given query (either in the main module or
+ : in any of the imported library modules).
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return the sequence of names of the said external variables.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :)
+declare function zq:external-variables($query-key as xs:anyURI) as
+  xs:QName* external ;
+  
+(:~
+ : The function tests if the query identified by the given key
+ : is an updating query.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return true if the query is an updating query, false otherwise.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :)
+declare function zq:is-updating($query-key as xs:anyURI) as
+  xs:boolean external;  
+
+(:~
+ : The function tests if the query identified by the given key
+ : is sequential query.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return true if the query is a sequential, false otherwise.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :)
+declare function zq:is-sequential($query-key as xs:anyURI) as
+  xs:boolean external;
+  
+(:~
+ : This function binds the context-item of the prepared query
+ : identified by the given key to the $dot argument.
+ :
+ : @param $query-key the identifier for a compiled query
+ : @param $dot the context item to bind
+ :
+ : @return the function has side effects and returns the empty
+ :   sequence.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :)
+declare %an:sequential function zq:bind-context-item($query-key as xs:anyURI,
+  $dot as item()) as empty-sequence() external ;
+
+(:~
+ : This function binds the variable with name $name of
+ : the prepared query identified by $query-key to the given sequence.
+ :
+ : @param $query-key the identifier for a compiled query
+ : @param $name the name of the external variable to bind
+ : @param $value the sequence to which the external variable $name
+ :  should be bound
+ :
+ : @return the function has side effects and returns the empty
+ :   sequence.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ : @error zq:UndeclaredVariable if the given variable is not declared
+ :   in the query.
+ :)
+declare %an:sequential function zq:bind-variable($query-key as xs:anyURI,
+  $var as xs:QName, $value as item()*) as empty-sequence() external ;
+
+
+(:~
+ : Evaluates the given prepared query and returns the result
+ : of the evaluation. The query must not be sequential or
+ : updating.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return the result of evaluating the given query
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :
+ : @error zq:QueryIsUpdating if the query is an updating query.
+ :
+ : @error zq:QueryIsSequential if the query is sequential.
+ :
+ : @error any dynamic error that is raised by evaluating the
+ :   given query.
+ :
+ :)
+declare function zq:evaluate($query-key as xs:anyURI) as item()* external;
+
+(:~
+ : Evaluates the given prepared query and applies the updates
+ : computed by this query. The query must be an updating query.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return the function has side effects because it applies
+ :  the updates of the query. It returns the empty sequence.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :
+ : @error zq:QueryNotUpdating if the query is not an updating query.
+ :
+ : @error zq:QueryIsSequential if the query is sequential.
+ :
+ : @error any dynamic error that is raised by evaluating the
+ :   given query or applying its updates.
+ :
+ :)
+declare updating function zq:evaluate-updating($query-key as xs:anyURI) external;
+
+(:~ 
+ : Evaluates the given prepared query and returns the result
+ : of the evaluation. The query must be sequential.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return the result of evaluating the query.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :
+ : @error zq:QueryNotSequential if the query is not sequential.
+ :
+ : @error zq:QueryIsUpdating if the query is an updating query.
+ :
+ : @error any dynamic error that is raised by evaluating the
+ :   given query.
+ :
+ :)
+declare %an:sequential function zq:evaluate-sequential($query-key as
+  xs:string) as item()* external;
+  
+(:~ 
+ : Deletes the prepared query associated with the given identifier.
+ : After the query is deleted, the corresponding identifier should
+ : not be used as argument to any of the functions of this module.
+ :
+ : @param $query-key the identifier for a compiled query
+ :
+ : @return the function has side effects and returns the empty sequence.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ :
+ :)
+declare %an:sequential function zq:delete-query($query-key as xs:anyURI) as
+  empty-sequence() external;
+
+(:~
+ : This function returns the value of a variable that is bound in the
+ : given query.
+ :
+ : @param $query-key the identifier of a compiled query.
+ : @param $var-name the name of the variable whose value should be returned.
+ :
+ : @return the value bound to the given variable.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ : @error zq:UndeclaredVariable if the given variable is not declared
+ :   in the query.
+ : @error zq:UnboundVariable if the given variable doesn't have a value.
+ :)
+declare function zq:variable-value($query-key as xs:anyURI, $var-name as 
+  xs:QName) as item()* external;
+
+(:~
+ : Returns the compiled query identified by the given query-key 
+ : as binary data.
+ :
+ : @param $query-key the identifier of a compiled query.
+ :
+ : @return the query as xs:base64Binary.
+ :
+ : @error zq:NoQueryMatch if no query with the given identifier
+ :   was prepared.
+ : @error zq:QueryPlanError if there is an error serializing the query.
+ :)
+declare function zq:query-plan($query-key as xs:anyURI) 
+  as xs:base64Binary external;
+  
+  
+(:~
+ : The function loads a given XQuery program for execution from a 
+ : xs:base64Binary query plan, obtained through the zq:query-plan function.
+ : If the program was successfully loaded, the function returns an
+ : identifier as xs:anyURI. This URI can be passed to other functions
+ : of this module (e.g. to actually evaluate the program). The URI
+ : is opaque and its lifetime is bound by the lifetime of the XQuery
+ : program that invoked this function. Further reference or uses
+ : of the identifier lead to unexpected results.
+ :
+ : Successfully prepared queries need to be deleted by passing the resulting
+ : identifier to the zq:delete-query function of this module.
+ :
+ : @param $main-module-text the XQuery program that should be prepared.
+ :   The program needs to be a XQuery main module.
+ :
+ : @return an identifier for the compiled program that can be passed
+ :   as arguments to other functions of this module.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the query. For example, err:XPST0003 if the given XQuery program could
+ : not be parsed.
+ :)    
+declare function zq:load-from-query-plan($plan as xs:base64Binary)
+  as xs:anyURI external;
+
+(:~
+ : The function loads a given XQuery program for execution from a 
+ : xs:base64Binary query plan, obtained through the zq:query-plan function.
+ : If the program was successfully loaded, the function returns an
+ : identifier as xs:anyURI. This URI can be passed to other functions
+ : of this module (e.g. to actually evaluate the program). The URI
+ : is opaque and its lilfetime is bound by the lifetime of the XQuery
+ : program that invoked this function. Further reference or uses
+ : of the identifier lead to unexpected results.
+ : 
+ : For important notes regarding the second and third parameters of the 
+ : function, review the comments in zq:prepare-main-module#3.
+ :
+ : Successfully prepared queries need to be deleted by passing the resulting
+ : identifier to the zq:delete-query function of this module.
+ :
+ : @param $main-module-text the XQuery program that should be prepared.
+ :   The program needs to be a XQuery main module.
+ :
+ : @param $resolver the URL resolver function.
+ : 
+ : @param $mapper the URI mapper function.
+ :
+ : @return an identifier for the compiled program that can be passed
+ :   as arguments to other functions of this module.
+ :
+ : @error any (static or type) error that may be raised during the compilation
+ : of the query. For example, err:XPST0003 if the given XQuery program could
+ : not be parsed.
+ :)  
+declare function zq:load-from-query-plan($plan as xs:base64Binary,
+  $resolver as item()?, $mapper as item()?) as xs:anyURI external;
+
+(:~
+ : Internal helper function. Only necessary because of incomplete HOF
+ : support in Zorba.
+ :)
+declare %private function zq:hof-invoker($hof as item(),
+  $ns as xs:string, $entity as xs:string) as item()*
+{
+   $hof($ns, $entity)
+};

=== added directory 'modules/zorba-query/zorba-query.xq.src'
=== added file 'modules/zorba-query/zorba-query.xq.src/zorba-query.cpp'
--- modules/zorba-query/zorba-query.xq.src/zorba-query.cpp	1970-01-01 00:00:00 +0000
+++ modules/zorba-query/zorba-query.xq.src/zorba-query.cpp	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1107 @@
+#include <zorba/item_factory.h>
+#include <zorba/singleton_item_sequence.h>
+#include <zorba/diagnostic_list.h>
+#include <zorba/empty_sequence.h>
+#include <zorba/store_manager.h>
+#include <zorba/user_exception.h>
+#include <zorba/uri_resolvers.h>
+#include <zorba/vector_item_sequence.h>
+#include <zorba/serializer.h>
+#include <zorba/xquery.h>
+#include <time.h>
+#include <stdio.h>
+#include <zorba/util/uuid.h>
+#include <vector>
+
+#include "zorba-query.h"
+
+namespace zorba { namespace zorbaquery {
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ExternalFunction*
+ZorbaQueryModule::getExternalFunction(const zorba::String& localName)
+{
+  FuncMap_t::iterator lIte = theFunctions.find(localName);
+    
+  ExternalFunction*& lFunc = theFunctions[localName];
+
+  if (lIte == theFunctions.end())
+  {
+    if (localName == "prepare-main-module")
+    {
+      lFunc = new PrepareMainModuleFunction(this);
+    }
+    if (localName == "prepare-library-module")
+    {
+      lFunc = new PrepareLibraryModuleFunction(this);
+    }
+    else if (localName == "is-bound-context-item")
+    {
+      lFunc = new IsBoundContextItemFunction(this);
+    }
+    else if (localName == "is-bound-variable")
+    {
+      lFunc = new IsBoundVariableFunction(this);
+    }
+    else if (localName == "external-variables")
+    {
+      lFunc = new GetExternalVariablesFunction(this);
+    }
+    else if (localName == "is-updating")
+    {
+      lFunc = new IsUpdatingFunction(this);        
+    }
+    else if (localName == "is-sequential")
+    {
+      lFunc = new IsSequentialFunction(this);
+    }      
+    else if (localName == "bind-context-item")
+    {
+      lFunc = new BindContextItemFunction(this);
+    }
+    else if (localName == "bind-variable")
+    {
+      lFunc = new BindVariableFunction(this);
+    }
+    else if (localName == "evaluate")
+    {
+      lFunc = new EvaluateFunction(this);
+    }
+    else if (localName == "evaluate-updating")
+    {
+      lFunc = new EvaluateUpdatingFunction(this);
+    }
+    else if (localName == "evaluate-sequential")
+    {
+      lFunc = new EvaluateSequentialFunction(this);
+    }
+    else if (localName == "delete-query")
+    {
+      lFunc = new DeleteQueryFunction(this);
+    }
+    else if (localName == "variable-value")
+    {
+      lFunc = new VariableValueFunction(this);
+    }
+    else if (localName == "query-plan")
+    {
+      lFunc = new QueryPlanFunction(this);
+    }
+    else if (localName == "load-from-query-plan")
+    {
+      lFunc = new LoadFromQueryPlanFunction(this);
+    }
+  }
+  
+  return lFunc;
+}
+    
+
+/*******************************************************************************
+
+********************************************************************************/
+void ZorbaQueryModule::destroy() 
+{
+  delete this;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+ZorbaQueryModule::~ZorbaQueryModule()
+{
+  for (FuncMap_t::const_iterator lIter = theFunctions.begin();
+       lIter != theFunctions.end(); ++lIter) 
+  {
+    delete lIter->second;
+  }
+  theFunctions.clear();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+QueryData::QueryData(XQuery_t aQuery, URIMapper *aMapper, URLResolver *aResolver)
+  :
+  theQuery(aQuery),
+  theURIMapper(aMapper),
+  theURLResolver(aResolver)
+{
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+QueryData::~QueryData()
+{
+  theQuery->close();
+  delete theURIMapper;
+  delete theURLResolver;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+QueryMap::QueryMap()
+{
+  theQueryMap = new QueryMap_t();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+bool  QueryMap::storeQuery(
+    const String& aKeyName,
+    XQuery_t aQuery,
+    URIMapper* aMapper,
+    URLResolver* aResolver)
+{
+  QueryData_t lQueryData(new QueryData(aQuery, aMapper, aResolver));
+
+  std::pair<QueryMap_t::iterator,bool> ret;
+
+  ret = theQueryMap->insert(std::pair<String, QueryData_t>(aKeyName, lQueryData));
+
+  return ret.second;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+XQuery_t QueryMap::getQuery(const String& aKeyName)
+{
+  QueryMap::QueryMap_t::iterator lIter = theQueryMap->find(aKeyName);
+
+  if (lIter == theQueryMap->end())
+    return NULL;
+    
+  XQuery_t lQuery = lIter->second->getQuery();
+
+  return lQuery;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+bool QueryMap::deleteQuery(const String& aKeyName)
+{
+  QueryMap::QueryMap_t::iterator lIter = theQueryMap->find(aKeyName);
+
+  if (lIter == theQueryMap->end())
+    return false;
+
+  theQueryMap->erase(lIter);
+  return true;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void QueryMap::destroy() throw()
+{
+  if (theQueryMap)
+  {
+    delete theQueryMap;
+  }
+  delete this;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+static void streamReleaser(std::istream* aStream)
+{
+  delete aStream;
+}  
+  
+
+/*******************************************************************************
+
+********************************************************************************/
+void ZorbaQueryFunction::throwError(const char *err_localname, const std::string& aErrorMessage)
+{
+  String errNS(ZORBA_QUERY_MODULE_NAMESPACE);
+  String errName(err_localname);
+  Item errQName = ZorbaQueryModule::getItemFactory()->createQName(errNS, errName);
+  String errDescription(aErrorMessage);
+  throw USER_EXCEPTION(errQName, errDescription);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+ZorbaQueryFunction::ZorbaQueryFunction(const ZorbaQueryModule* aModule)
+  :
+  theModule(aModule)
+{
+  srand(::time(NULL));
+}
+    
+
+/*******************************************************************************
+
+********************************************************************************/
+ZorbaQueryFunction::~ZorbaQueryFunction()
+{
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+String ZorbaQueryFunction::getURI() const 
+{
+  return theModule->getURI();
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+String ZorbaQueryFunction::getOneStringArgument(const Arguments_t& aArgs, int aPos) const
+{
+  Item lItem;
+  Iterator_t args_iter = aArgs[aPos]->getIterator();
+  args_iter->open();
+  args_iter->next(lItem);
+  String lTmpString = lItem.getStringValue();
+  args_iter->close();
+  return lTmpString;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+Item ZorbaQueryFunction::getItemArgument(const Arguments_t& aArgs, int aPos) const
+{
+  Item lItem;
+  Iterator_t args_iter = aArgs[aPos]->getIterator();
+  args_iter->open();
+  args_iter->next(lItem);
+  args_iter->close();
+  
+  return lItem;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+Iterator_t ZorbaQueryFunction::getIterArgument(const Arguments_t& aArgs, int aPos) const
+{
+  Iterator_t args_iter = aArgs[aPos]->getIterator();
+  return args_iter;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+XQuery_t ZorbaQueryFunction::getQuery(
+    const zorba::DynamicContext* aDctx,
+    const zorba::String& aIdent) const
+{
+  QueryMap* lQueryMap;
+
+  if (!(lQueryMap =
+        dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    throwError("NoQueryMatch", "No query with the given identifier was found");
+  }
+  
+  XQuery_t lQuery;
+  if (!(lQuery = lQueryMap->getQuery(aIdent)))
+    throwError("NoQueryMatch", "No query with the given identifier was found");
+  
+  return lQuery;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void  ZorbaQueryURIMapper::mapURI(
+    String aUri,
+    EntityData const* aEntityData,
+    std::vector<String>& oUris)
+{
+  //Create entityData string to send to the new url resolver
+  String lDataKind;
+  switch (aEntityData->getKind())
+  {
+  case EntityData::SCHEMA:
+    lDataKind = "schema";
+    break;
+  case EntityData::MODULE:
+    lDataKind = "module";
+    break;
+  default:
+    break;
+  }
+  
+  //construct the arguments for the url resolver
+  std::vector<ItemSequence_t> lArgs;
+  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
+  ItemSequence_t lSeq1 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(aUri));
+  ItemSequence_t lSeq2 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(lDataKind));
+  lArgs.push_back(lSeq0);
+  lArgs.push_back(lSeq1);
+  lArgs.push_back(lSeq2);
+
+  //invoke the HOF helper function using the arguments generated
+  Item lHofHelper = ZorbaQueryModule::getItemFactory()->
+  createQName("http://zorba.io/modules/zorba-query";, "zq", "hof-invoker");
+
+  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
+  
+  //Check if the result is an empty sequence by creating an Iterator, this is
+  // cheaper than serializing the result and then checking if it was empty.
+  Iterator_t lIter = lResult->getIterator();
+  Item lItem;
+  lIter->open();
+  while (lIter->next(lItem))
+  {
+    //std::cout << lItem.getStringValue() << std::endl;
+    oUris.push_back(lItem.getStringValue());
+  }
+  lIter->close();  
+}
+      
+
+/*******************************************************************************
+
+********************************************************************************/
+Resource* ZorbaQueryURLResolver::resolveURL(
+    const String& aUrl,
+    EntityData const* aEntityData)
+{ 
+  //Create entityData string to send to the new url resolver
+  String lDataKind;
+  switch (aEntityData->getKind())
+  {
+  case EntityData::SCHEMA:
+    lDataKind = "schema";
+    break;
+  case EntityData::MODULE:
+    lDataKind = "module";
+    break;
+  default:
+    break;
+  }
+
+  //construct the arguments for the url resolver
+  std::vector<ItemSequence_t> lArgs;
+  ItemSequence_t lSeq0 = new SingletonItemSequence(theFunction);
+  ItemSequence_t lSeq1 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(aUrl));
+  ItemSequence_t lSeq2 = new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createString(lDataKind));
+  lArgs.push_back(lSeq0);
+  lArgs.push_back(lSeq1);
+  lArgs.push_back(lSeq2);
+  
+  //invoke the HOF helper function using the arguments generated
+  Item lHofHelper = ZorbaQueryModule::getItemFactory()->
+  createQName("http://zorba.io/modules/zorba-query";, "zq", "hof-invoker");
+
+  ItemSequence_t lResult = theCtx->invoke(lHofHelper, lArgs);
+
+  // Check if the result is an empty sequence by creating an Iterator, this is
+  // cheaper than serializing the result and then checking if it was empty.
+  Iterator_t lIter = lResult->getIterator();
+  Item lItem;
+  lIter->open();
+  lIter->next(lItem);
+  lIter->close();
+  lIter = NULL;
+
+  if (lItem.isNull())
+    return NULL;
+
+  //Serialize resulting sequence of the resolver
+  Zorba_SerializerOptions_t lOpt;
+  if (lItem.isNode())
+    lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_XML;
+  else
+    lOpt.ser_method = ZORBA_SERIALIZATION_METHOD_TEXT;
+
+  lOpt.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+  Serializer_t lSer = Serializer::createSerializer(lOpt);
+  std::stringstream lSerResult;
+  lSer->serialize(lResult, lSerResult);
+  
+  //return resource
+  return StreamResource::create(new std::istringstream(lSerResult.str()),
+                                &streamReleaser);
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t PrepareMainModuleFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
+  StaticContext_t lSctxChild = aSctx->createChildContext();
+   
+  QueryMap* lQueryMap;
+  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    lQueryMap = new QueryMap();
+    lDynCtx->addExternalFunctionParameter("zqQueryMap", lQueryMap);     
+  }
+
+  Zorba* lZorba = Zorba::getInstance(0);
+
+  String lQueryString = getOneStringArgument(aArgs, 0); 
+    
+  XQuery_t lQuery;
+    
+  StaticContext_t ltempSctx = lZorba->createStaticContext();
+
+  std::auto_ptr<ZorbaQueryURLResolver> lResolver;
+  std::auto_ptr<ZorbaQueryURIMapper> lMapper;
+
+  if ( aArgs.size() > 2 )
+  {
+    Item lMapperFunctionItem = getItemArgument(aArgs, 2);
+    if (!lMapperFunctionItem.isNull())
+    {
+      lMapper.reset(new ZorbaQueryURIMapper(lMapperFunctionItem, lSctxChild));
+      ltempSctx->registerURIMapper(lMapper.get());
+    }
+  }
+
+  if ( aArgs.size() > 1 )
+  {
+    Item lResolverFunctionItem = getItemArgument(aArgs, 1);
+    if (!lResolverFunctionItem.isNull())
+    {
+      lResolver.reset(new ZorbaQueryURLResolver(lResolverFunctionItem, lSctxChild));
+      ltempSctx->registerURLResolver(lResolver.get());
+    }  
+  }
+  
+  try
+  {
+    //std::cout << "Hello: " << lQueryString << std::endl;
+    lQuery = lZorba->compileQuery(lQueryString, ltempSctx);
+  }
+  catch (XQueryException& xe)
+  {
+    lQuery = NULL;
+    std::ostringstream err;
+    err << "The query compiled using zq:prepare-main-module raised an error at"
+        << " file " << xe.source_uri() << " line " << xe.source_line()
+        << " column " << xe.source_column() << ": " << xe.what();
+    // << " -- Query string : " << std::endl << lQueryString;
+
+    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
+                                xe.diagnostic().qname().ns(),
+                                xe.diagnostic().qname().localname());
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+  catch (ZorbaException& e)
+  {
+    lQuery = NULL;
+    std::ostringstream err;
+    err << "The query compiled using zq:prepare-main-module raised an error: "
+        << e.what();
+
+    Item errQName = ZorbaQueryModule::getItemFactory()->
+    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
+
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+  
+  uuid lUUID;
+  uuid::create(&lUUID);
+  
+  std::stringstream lStream;
+  lStream << lUUID;
+  
+  String lStrUUID = lStream.str();
+  
+  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
+  
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createAnyURI(lStrUUID)));
+}
+    
+    
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t PrepareLibraryModuleFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  Zorba *lZorba = Zorba::getInstance(0);
+  String lQueryString = getOneStringArgument(aArgs, 0);     
+ 
+  Zorba_CompilerHints_t hints;
+  hints.lib_module = true;
+
+  try
+  {
+    lZorba->compileQuery(lQueryString, hints);
+  }
+  catch (XQueryException& xe)
+  {
+    std::ostringstream err;
+    err << "The query compiled using zq:prepare-library-module raised an error at"
+        << " line " << xe.source_line() << " column " << xe.source_column()
+        << ": " << xe.what();
+
+    Item errQName = ZorbaQueryModule::getItemFactory()->
+    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
+
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+  catch (ZorbaException& e)
+  {
+    std::ostringstream err;
+    err << "The query compiled using zq:prepare-main-query raised an error: "
+        << e.what();
+
+      Item errQName = ZorbaQueryModule::getItemFactory()->
+      createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
+
+      throw USER_EXCEPTION(errQName, err.str());
+    }
+    return ItemSequence_t(new EmptySequence());
+  }
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t IsBoundContextItemFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  bool lIsContextItemBound = lQuery->getDynamicContext()->isBoundContextItem();
+
+  return ItemSequence_t(new SingletonItemSequence(
+          ZorbaQueryModule::getItemFactory()->createBoolean(lIsContextItemBound)));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t IsBoundVariableFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1);
+  bool lIsBoundVariable = false;
+
+  try
+  {
+    lIsBoundVariable = lQuery->getDynamicContext()->isBoundExternalVariable(lVarQName.getNamespace(),lVarQName.getLocalName());
+  }
+  catch (ZorbaException& ze)
+  {
+    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
+      ZorbaQueryFunction::throwError("UndeclaredVariable", ze.what());  
+    throw; // should not happen
+  }
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lIsBoundVariable)));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t GetExternalVariablesFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{  
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+    
+  std::vector<Item> lVars;
+  Iterator_t lVarsIterator;
+  lQuery->getExternalVariables(lVarsIterator);
+
+  Item lVar;
+  lVarsIterator->open();
+  while(lVarsIterator->next(lVar))
+    lVars.push_back(lVar);
+  lVarsIterator->close();
+  
+  return ItemSequence_t(new VectorItemSequence(lVars));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t IsUpdatingFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lQuery->isUpdating())));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t IsSequentialFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createBoolean(lQuery->isSequential())));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t BindContextItemFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  // shouldn't raise errors
+  Item lItemContext = ZorbaQueryFunction::getItemArgument(aArgs, 1);
+  lQuery->getDynamicContext()->setContextItem(lItemContext);
+
+  return ItemSequence_t(new EmptySequence());
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t BindContextPositionFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  ZorbaQueryFunction::throwError("ImplementationError", "This function is not implemented yet");
+
+  return ItemSequence_t(new EmptySequence());
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t BindContextSizeFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  ZorbaQueryFunction::throwError("ImplementationError", "This function is not implemented yet");
+
+  return ItemSequence_t(new EmptySequence());
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t BindVariableFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+    
+  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1); 
+
+  Iterator_t lVarValue = ZorbaQueryFunction::getIterArgument(aArgs, 2); 
+
+  if (!lQuery->getDynamicContext()->setVariable(lVarQName.getNamespace(),
+                                                lVarQName.getLocalName(),
+                                                lVarValue))
+  {
+    std::ostringstream lMsg;
+    lMsg << "{" << lVarQName.getNamespace() << "}" << lVarQName.getLocalName()
+         << ": undefined variable";
+
+    throwError("UndeclaredVariable", lMsg.str());
+  }
+
+  return ItemSequence_t(new EmptySequence());
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+bool EvaluateItemSequence::EvaluateIterator::next(Item& aItem)
+{
+  try
+  {
+    return theIterator->next(aItem);
+  }
+  catch (XQueryException& xe)
+  {
+    std::ostringstream err;
+    err << "The query " << "(" << theQueryID
+        << ") evaluated using zq:evaluate raised an error at"
+        << " line " << xe.source_line() << " column "
+        << xe.source_column() << ": " << xe.what();
+
+    Item errQName = ZorbaQueryModule::getItemFactory()->
+    createQName(xe.diagnostic().qname().ns(), xe.diagnostic().qname().localname());
+
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+  catch (ZorbaException& e)
+  {
+    std::ostringstream err;
+    err << "The query " << "(" << theQueryID
+        << ") evaluated using zq:evaluate raised an error at"
+        << e.what();
+
+    Item errQName = ZorbaQueryModule::getItemFactory()->
+    createQName(e.diagnostic().qname().ns(), e.diagnostic().qname().localname());
+
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t EvaluateFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  if (lQuery->isUpdating())
+  {
+    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
+  }
+     
+  if (lQuery->isSequential())
+  {
+    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");
+  }
+      
+  Iterator_t lIterQuery = lQuery->iterator();
+
+  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t EvaluateUpdatingFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+    
+  if (lQuery->isSequential())
+  {
+    throwError("QueryIsSequential", "Executing Query shouldn't be sequential.");   
+  }
+
+  if(!lQuery->isUpdating())
+  {
+    throwError("QueryNotUpdating", "Executing Query should be updating.") ; 
+  }
+  
+  Iterator_t lIterQuery = lQuery->iterator();
+  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t EvaluateSequentialFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs, 0);
+  
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  if(lQuery->isUpdating())
+  {
+    throwError("QueryIsUpdating", "Executing Query shouldn't be updating.");
+  }
+
+  if(!lQuery->isSequential())
+  {
+    throwError("QueryNotSequential", "Executing Query should be sequential.");    
+  }
+
+  Iterator_t lIterQuery = lQuery->iterator();
+  return ItemSequence_t(new EvaluateItemSequence(lIterQuery, lQueryID));
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t DeleteQueryFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+
+  QueryMap* lQueryMap;
+  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    throwError("NoQueryMatch", "String identifying query does not exists.");
+  }
+
+  if (!lQueryMap->deleteQuery(lQueryID))
+  {
+    throwError("NoQueryMatch","String identifying query does not exists.");
+  }
+      
+  return ItemSequence_t(new EmptySequence());
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t VariableValueFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+
+  QueryMap* lQueryMap;
+  if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    throwError("NoQueryMatch", "String identifying query does not exists.");
+  }
+
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  Item lVarQName = ZorbaQueryFunction::getItemArgument(aArgs, 1);
+  bool lIsBoundVariable = false;
+
+  zorba::DynamicContext* lCtx = lQuery->getDynamicContext();
+  zorba::String lNS = lVarQName.getNamespace(), lLocal = lVarQName.getLocalName();
+
+  try
+  {
+    lIsBoundVariable = lCtx->isBoundExternalVariable(lNS, lLocal);
+  }
+  catch (ZorbaException& ze)
+  {
+    if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
+      ZorbaQueryFunction::throwError("UndeclaredVariable", ze.what());  
+    throw; // should not happen
+  }
+
+  if (!lIsBoundVariable)
+  {
+    std::ostringstream lMsg;
+    lMsg << lLocal << ": variable not bound";
+    ZorbaQueryFunction::throwError("UnboundVariable", lMsg.str());  
+  }
+
+  zorba::Iterator_t lIterator;
+  zorba::Item lItem;
+
+  lCtx->getVariable(lNS, lLocal, lItem, lIterator);
+      
+  if (lIterator)
+  {
+    return ItemSequence_t(new ValueItemSequence(lIterator));
+  }
+  else
+  {
+    return ItemSequence_t(new SingletonItemSequence(lItem));
+  }
+}
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t QueryPlanFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  String lQueryID = ZorbaQueryFunction::getOneStringArgument(aArgs,0);
+
+  QueryMap* lQueryMap;
+  if (!(lQueryMap = dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    throwError("NoQueryMatch", "String identifying query does not exists.");
+  }
+
+  XQuery_t lQuery = getQuery(aDctx, lQueryID);
+
+  std::auto_ptr<std::stringstream> lExcPlan;
+  lExcPlan.reset(new std::stringstream());
+  if (!lQuery->saveExecutionPlan(*lExcPlan.get()))
+  {
+    throwError("QueryPlanError", "FAILED getting query execution plan.");
+  }
+  
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createStreamableBase64Binary(*lExcPlan.release(), &streamReleaser)));
+}
+ 
+
+/*******************************************************************************
+
+********************************************************************************/
+zorba::ItemSequence_t LoadFromQueryPlanFunction::evaluate(
+    const Arguments_t& aArgs,
+    const zorba::StaticContext* aSctx,
+    const zorba::DynamicContext* aDctx) const 
+{
+  Item lQueryPlanItem = ZorbaQueryFunction::getItemArgument(aArgs,0);
+  std::istream& lQueryPlanStream = lQueryPlanItem.getStream();
+
+  DynamicContext* lDynCtx = const_cast<DynamicContext*>(aDctx);
+  StaticContext_t lSctxChild = aSctx->createChildContext();
+   
+  QueryMap* lQueryMap;
+  if (!(lQueryMap = dynamic_cast<QueryMap*>(lDynCtx->getExternalFunctionParameter("zqQueryMap"))))
+  {
+    lQueryMap = new QueryMap();
+    lDynCtx->addExternalFunctionParameter("zqQueryMap", lQueryMap);     
+  }
+
+  Zorba* lZorba = Zorba::getInstance(0);
+  XQuery_t lQuery;
+  
+  std::auto_ptr<ZorbaQueryURLResolver> lResolver;
+  std::auto_ptr<ZorbaQueryURIMapper> lMapper;
+  try
+  {
+    lQuery = lZorba->createQuery();
+    if ( aArgs.size() > 2)
+    {
+      QueryPlanSerializationCallback lPlanSer;
+
+      Item lMapperFunctionItem = getItemArgument(aArgs, 2);
+      if (!lMapperFunctionItem.isNull())
+      {
+        lMapper.reset(new ZorbaQueryURIMapper(lMapperFunctionItem, lSctxChild));
+        lPlanSer.add_URIMapper(lMapper.get());
+      }
+
+      Item lResolverFunctionItem = getItemArgument(aArgs, 1);
+      if (!lResolverFunctionItem.isNull())
+      {
+        lResolver.reset(new ZorbaQueryURLResolver(lResolverFunctionItem, lSctxChild));
+        lPlanSer.add_URLResolver(lResolver.get());
+      }
+
+      lQuery->loadExecutionPlan(lQueryPlanStream, &lPlanSer);
+    }
+    else
+    { 
+      lQuery->loadExecutionPlan(lQueryPlanStream);
+    }
+  }
+  catch (XQueryException& xe)
+  {
+    lQuery = NULL;
+    std::ostringstream err;
+    err << "The query loaded from the query plan raised an error at"
+      << " file" << xe.source_uri() << " line" << xe.source_line()
+      << " column" << xe.source_column() << ": " << xe.what();
+    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
+      xe.diagnostic().qname().ns(),
+      xe.diagnostic().qname().localname());
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+  catch (ZorbaException& ze)
+  {
+    lQuery = NULL;
+    std::ostringstream err;
+    if (ze.diagnostic() == zerr::ZCSE0013_UNABLE_TO_LOAD_QUERY)
+      err << "The query loaded from the query plan raised an error: failed to load pre-compiled query: document, collection, or module resolver required but not given.";
+    else
+      err << "The query loaded from the query plan raised an error: "<< ze.what();
+    Item errQName = ZorbaQueryModule::getItemFactory()->createQName(
+      ze.diagnostic().qname().ns(),
+      ze.diagnostic().qname().localname());
+    throw USER_EXCEPTION(errQName, err.str());
+  }
+
+  uuid lUUID;
+  uuid::create(&lUUID);
+
+  std::stringstream lStream;
+  lStream << lUUID;
+
+  String lStrUUID = lStream.str();
+
+  lQueryMap->storeQuery(lStrUUID, lQuery, lMapper.release(), lResolver.release());
+  return ItemSequence_t(new SingletonItemSequence(ZorbaQueryModule::getItemFactory()->createAnyURI(lStrUUID)));
+}
+
+}/*namespace zorbaquery*/ }/*namespace zorba*/
+
+#ifdef WIN32
+#  define DLL_EXPORT __declspec(dllexport)
+#else
+#  define DLL_EXPORT __attribute__ ((visibility("default")))
+#endif
+
+extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
+  return new zorba::zorbaquery::ZorbaQueryModule();
+}

=== added file 'modules/zorba-query/zorba-query.xq.src/zorba-query.h'
--- modules/zorba-query/zorba-query.xq.src/zorba-query.h	1970-01-01 00:00:00 +0000
+++ modules/zorba-query/zorba-query.xq.src/zorba-query.h	2013-08-12 17:27:54 +0000
@@ -0,0 +1,651 @@
+#ifndef __COM_ZORBA_WWW_MODULES_ZORBA_QUERY_H__
+#define __COM_ZORBA_WWW_MODULES_ZORBA_QUERY_H__
+
+#include <map>
+
+#include <zorba/zorba.h>
+#include <zorba/external_module.h>
+#include <zorba/function.h>
+#include <zorba/dynamic_context.h>
+#include <zorba/serialization_callback.h>
+
+#define ZORBA_QUERY_MODULE_NAMESPACE "http://zorba.io/modules/zorba-query";
+
+namespace zorba { namespace zorbaquery {
+  
+  
+/*******************************************************************************
+
+********************************************************************************/
+class ZorbaQueryModule : public ExternalModule 
+{
+protected:
+  class ltstr
+  {
+  public:
+    bool operator()(const String& s1, const String& s2) const
+    {
+      return s1.compare(s2) < 0;
+    }
+  };
+
+  typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
+
+protected:
+  FuncMap_t theFunctions;
+
+public:
+
+  virtual ~ZorbaQueryModule();
+
+  virtual zorba::String getURI() const {return ZORBA_QUERY_MODULE_NAMESPACE;}
+
+  virtual zorba::ExternalFunction* getExternalFunction(const String& localName);
+
+  virtual void destroy();
+
+  static ItemFactory* getItemFactory()
+  {
+    return Zorba::getInstance(0)->getItemFactory();
+  }
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class ZorbaQueryURLResolver : public URLResolver
+{
+protected:
+  Item             theFunction;
+  StaticContext_t  theCtx;
+
+public:
+  ZorbaQueryURLResolver(Item& aFunction, StaticContext_t& aSctx)
+    :
+    URLResolver(),
+    theFunction(aFunction),
+    theCtx(aSctx)
+  {
+  }
+        
+  virtual ~ZorbaQueryURLResolver() { }
+      
+  virtual Resource* resolveURL(const String& url, EntityData const* entityData);
+};
+  
+
+class ZorbaQueryURIMapper : public URIMapper
+{
+protected:
+  Item            theFunction;
+  StaticContext_t theCtx;
+    
+public:
+  ZorbaQueryURIMapper(Item& aFunction, StaticContext_t& aSctx)
+    :
+    URIMapper(),
+    theFunction(aFunction),
+    theCtx(aSctx)
+  {
+  }
+    
+  virtual ~ZorbaQueryURIMapper(){ }
+    
+  virtual void mapURI(
+    const zorba::String aUri,
+    EntityData const* aEntityData,
+    std::vector<zorba::String>& oUris);
+};
+/*******************************************************************************
+  Bag class for objects associated with a prepared query
+********************************************************************************/
+class QueryData : public SmartObject
+{
+private:
+  XQuery_t      theQuery;
+  URIMapper   * theURIMapper;
+  URLResolver * theURLResolver;
+  
+public:
+  QueryData(XQuery_t aQuery, URIMapper* aMapper, URLResolver* aResolver);
+
+  virtual ~QueryData();
+
+  XQuery_t getQuery() { return theQuery; }
+};
+
+
+typedef SmartPtr<QueryData> QueryData_t;
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class QueryMap : public ExternalFunctionParameter
+{
+private:
+  typedef std::map<String, QueryData_t> QueryMap_t;
+
+private:
+  QueryMap_t  * theQueryMap;
+
+public:
+  QueryMap();
+
+  bool storeQuery(const String&, XQuery_t, URIMapper*, URLResolver*);
+  
+  XQuery_t getQuery(const String&);
+  
+  bool deleteQuery(const String&);
+  
+  virtual void destroy() throw();
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class ZorbaQueryFunction : public ContextualExternalFunction
+{
+protected:
+  const ZorbaQueryModule * theModule;
+
+protected:
+  static void throwError(const char*, const std::string&);
+
+protected:
+  String getOneStringArgument(const Arguments_t&, int) const;
+
+  Item getItemArgument(const Arguments_t&, int) const;
+
+  Iterator_t getIterArgument(const Arguments_t&, int) const;
+
+  XQuery_t getQuery(
+      const zorba::DynamicContext* dctx,
+      const zorba::String& aIdent) const;
+
+public:
+  ZorbaQueryFunction(const ZorbaQueryModule* module);
+
+  virtual ~ZorbaQueryFunction();
+
+  virtual String getURI() const;
+};
+
+  
+/*******************************************************************************
+
+********************************************************************************/
+class PrepareMainModuleFunction : public ZorbaQueryFunction
+{
+public:
+  PrepareMainModuleFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~PrepareMainModuleFunction(){  }
+      
+  virtual zorba::String
+  getLocalName() const { return "prepare-main-module"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class PrepareLibraryModuleFunction : public ZorbaQueryFunction
+{
+public:
+  PrepareLibraryModuleFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~PrepareLibraryModuleFunction(){}
+      
+  virtual zorba::String
+  getLocalName() const { return "prepare-library-module"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class IsBoundContextItemFunction : public ZorbaQueryFunction
+{
+public:
+  IsBoundContextItemFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~IsBoundContextItemFunction(){}
+
+  virtual zorba::String
+  getLocalName() const { return "is-bound-context-item"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+    
+    
+/*******************************************************************************
+
+********************************************************************************/
+class IsBoundVariableFunction : public ZorbaQueryFunction
+{
+public:
+  IsBoundVariableFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~IsBoundVariableFunction(){}
+
+  virtual zorba::String
+  getLocalName() const { return "is-bound-variable"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+    
+
+/*******************************************************************************
+
+********************************************************************************/
+class GetExternalVariablesFunction : public ZorbaQueryFunction
+{
+public:
+  GetExternalVariablesFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~GetExternalVariablesFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "external-variables"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class IsUpdatingFunction : public ZorbaQueryFunction
+{
+public:
+  IsUpdatingFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~IsUpdatingFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "is-updating"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;  
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class IsSequentialFunction : public ZorbaQueryFunction
+{
+public:
+  IsSequentialFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~IsSequentialFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "is-sequential"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class BindContextItemFunction : public ZorbaQueryFunction
+{
+public:
+  BindContextItemFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~BindContextItemFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "bind-context-item"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class BindContextPositionFunction : public ZorbaQueryFunction
+{
+public:
+  BindContextPositionFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~BindContextPositionFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "bind-context-position"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class BindContextSizeFunction : public ZorbaQueryFunction
+{
+public:
+  BindContextSizeFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~BindContextSizeFunction() {}
+  
+  virtual zorba::String
+  getLocalName() const {return "bind-context-size"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class BindVariableFunction : public ZorbaQueryFunction
+{
+public:
+  BindVariableFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~BindVariableFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "bind-variable"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class EvaluateItemSequence : public ItemSequence
+{
+protected:
+
+  class EvaluateIterator : public Iterator
+  {
+  protected:
+    Iterator_t theIterator;
+
+    String     theQueryID;
+
+  public:
+    EvaluateIterator(Iterator_t& aIter, String aQueryID)
+      :
+      theIterator(aIter),
+      theQueryID(aQueryID)
+    {
+    }
+
+    virtual ~EvaluateIterator(){}
+
+    virtual void open() { theIterator->open(); }
+
+    virtual bool next(Item& aItem);
+
+    virtual void close() { theIterator->close(); }
+
+    virtual bool isOpen() const { return theIterator->isOpen(); }
+  };
+
+  typedef zorba::SmartPtr<EvaluateIterator> EvaluateIterator_t;
+
+protected:
+  EvaluateIterator_t theIter; 
+
+public:
+  EvaluateItemSequence(Iterator_t& aIter, String& aQueryID)
+    :
+    theIter(new EvaluateIterator(aIter, aQueryID))
+  {
+  }
+  
+  virtual ~EvaluateItemSequence() {}
+
+  Iterator_t getIterator() { return theIter.get(); }
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class EvaluateFunction : public ZorbaQueryFunction
+{
+public:
+  EvaluateFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~EvaluateFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "evaluate"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class EvaluateUpdatingFunction : public ZorbaQueryFunction
+{
+public:
+  EvaluateUpdatingFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~EvaluateUpdatingFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "evaluate-updating"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class EvaluateSequentialFunction : public ZorbaQueryFunction
+{
+public:
+  EvaluateSequentialFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~EvaluateSequentialFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "evaluate-sequential"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+  
+  virtual String getURI() const {
+    return theModule->getURI();
+  }
+  
+protected:
+  const ZorbaQueryModule* theModule;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class DeleteQueryFunction : public ZorbaQueryFunction
+{
+public:
+  DeleteQueryFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~DeleteQueryFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "delete-query"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+};
+
+  class VariableValueFunction : public ZorbaQueryFunction{
+    protected:
+      class ValueItemSequence : public ItemSequence
+      {
+        protected:
+          Iterator_t theIterator;
+
+        public:
+          ValueItemSequence(Iterator_t& aIter)
+            : theIterator(aIter)
+          {
+          }
+
+          virtual ~ValueItemSequence(){}
+
+          Iterator_t
+          getIterator() { return theIterator; }
+
+      };
+    public:
+      VariableValueFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+      virtual ~VariableValueFunction() {}
+
+      virtual zorba::String
+        getLocalName() const {return "variable-value"; }
+
+      virtual zorba::ItemSequence_t
+        evaluate(const Arguments_t&,
+                 const zorba::StaticContext*,
+                 const zorba::DynamicContext*) const;
+  };
+
+/*******************************************************************************
+
+********************************************************************************/
+class QueryPlanFunction : public ZorbaQueryFunction
+{
+public:
+  QueryPlanFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~QueryPlanFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "query-plan"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+  
+  virtual String getURI() const {
+    return theModule->getURI();
+  }
+  
+protected:
+  const ZorbaQueryModule* theModule;
+};
+
+
+/*******************************************************************************
+
+********************************************************************************/
+class LoadFromQueryPlanFunction : public ZorbaQueryFunction
+{
+public:
+  LoadFromQueryPlanFunction(const ZorbaQueryModule* aModule) : ZorbaQueryFunction(aModule) {}
+
+  virtual ~LoadFromQueryPlanFunction() {}
+
+  virtual zorba::String
+  getLocalName() const {return "load-from-query-plan"; }
+
+  virtual zorba::ItemSequence_t
+  evaluate(const Arguments_t&,
+           const zorba::StaticContext*,
+           const zorba::DynamicContext*) const;
+  
+  virtual String getURI() const {
+    return theModule->getURI();
+  }
+  
+protected:
+  const ZorbaQueryModule* theModule;
+
+  class QueryPlanSerializationCallback : public zorba::SerializationCallback
+  {
+    std::vector<URIMapper*> theUriMappers;
+    std::vector<URLResolver*>theUrlResolvers;
+
+  public:
+    QueryPlanSerializationCallback()
+    {
+    }
+
+    virtual ~QueryPlanSerializationCallback() {}
+
+    void add_URIMapper(URIMapper* aMapper)
+    {
+      theUriMappers.push_back(aMapper);
+    }
+
+    void add_URLResolver(URLResolver* aResolver)
+    {
+      theUrlResolvers.push_back(aResolver);
+    }
+
+    virtual URIMapper*
+      getURIMapper(size_t  i ) const { return theUriMappers.size() < i? NULL : theUriMappers[i]; }
+
+    virtual URLResolver*
+    getURLResolver(size_t i) const { return theUrlResolvers.size() < i? NULL : theUrlResolvers[i]; }
+  };
+};
+}/*zorbaquery namespace*/}/*zorba namespace*/
+
+
+#endif //_COM_ZORBA_WWW_MODULES_ZORBA_QUERY_H_

=== modified file 'test/fots_driver/cli.xq'
--- test/fots_driver/cli.xq	2013-05-20 17:56:33 +0000
+++ test/fots_driver/cli.xq	2013-08-12 17:27:54 +0000
@@ -157,14 +157,14 @@
 
 (:~
  : Enable or disable verbose output. When this is set to true the exact query
- : that is run by XQXQ is also written down into a query_*.xq file.
+ : that is run by ZQ is also written down into a query_*.xq file.
  :)
 declare variable $verbose as xs:string external := "false";
 
 
 (:~
  : Enable or disable plan serializer usage. When this is set to true the query
- : plan is saved then loaded and executed by XQXQ.
+ : plan is saved then loaded and executed by ZQ.
  :)
 declare variable $usePlanSerializer as xs:string external := "false";
 

=== modified file 'test/fots_driver/environment.xq'
--- test/fots_driver/environment.xq	2013-08-09 08:27:30 +0000
+++ test/fots_driver/environment.xq	2013-08-12 17:27:54 +0000
@@ -22,8 +22,8 @@
 module namespace env =
   "http://www.zorba-xquery.com/fots-driver/environment";;
 
-import module namespace xqxq =
-  "http://www.zorba-xquery.com/modules/xqxq";;
+import module namespace zq =
+  "http://zorba.io/modules/zorba-query";;
 
 import module namespace util =
   "http://www.zorba-xquery.com/fots-driver/util"; at "util.xq";
@@ -330,15 +330,15 @@
  : If a test-case query TQ references a source doc via the context item, this
  : function creates and returns the xquery code for computing a value for the
  : context item and binding this value inside TQ. The result of this function
- : is added to the query FQ that will be evaluated via XQXQ by the fots test
- : driver. The function assumes that TQ will appear as a nested XQXQ query
- : within FQ, and that $queryID is the FQ variable storing the XQXQ query id
+ : is added to the query FQ that will be evaluated via ZQ by the fots test
+ : driver. The function assumes that TQ will appear as a nested ZQ query
+ : within FQ, and that $queryID is the FQ variable storing the ZQ query id
  : of TQ.
  :
  : If the source doc needs to be validated, the code created by this function
  : looks like this:
  :
- :  variable $contextItemQuery := xqxq:prepare-main-module
+ :  variable $contextItemQuery := zq:prepare-main-module
  :  (
  :  '
  :  import schema some-prefix = "some-URI";
@@ -348,16 +348,16 @@
  :  (), mapper:uri-mapper#2
  :  );
  :
- : variable $contextItem := xqxq:evaluate($contextItemQuery);
+ : variable $contextItem := zq:evaluate($contextItemQuery);
  :
- : xqxq:bind-context-item($queryID, $contextItem);
+ : zq:bind-context-item($queryID, $contextItem);
  :
  : If no validation is required, the code created by this function looks like
  : this:
  :
  : variable $contextItem := doc("some-xml-file");
  :
- : xqxq:bind-context-item($queryID, $contextItem);
+ : zq:bind-context-item($queryID, $contextItem);
  :
  : @param $env The environment (local or non-local) that applies to the current
  :             test case.
@@ -380,14 +380,14 @@
     (
     env:compute-context-item($env, $envBaseURI, $needsDTDValidation),
     "",
-    'xqxq:bind-context-item($queryID, $contextItem);'
+    'zq:bind-context-item($queryID, $contextItem);'
     )
     ,
     "&#xA;"
     )
   else if(exists($env/fots:context-item/@select))
   then
-    concat('xqxq:bind-context-item($queryID,',
+    concat('zq:bind-context-item($queryID,',
            $env/fots:context-item/@select,
            ');')
   else
@@ -418,7 +418,7 @@
     string-join(
     (
     "&#xA;",
-    "variable $contextItemQuery := xqxq:prepare-main-module",
+    "variable $contextItemQuery := zq:prepare-main-module",
     "(",
     "'",
     if ($needsSchemaValidation) then env:get-schema-import($env) else (),
@@ -431,7 +431,7 @@
     "(), mapper:uri-mapper#2",
     ");",
     "",
-    "variable $contextItem := xqxq:evaluate($contextItemQuery);"
+    "variable $contextItem := zq:evaluate($contextItemQuery);"
     )
     ,
     "&#xA;")
@@ -466,17 +466,17 @@
 
 (:~
  : Creates the xquery code for assigning values to the external variables of
- : a nested XQXQ query. The nested XQXQ query is a test-case query TQ, and the
+ : a nested zorba-query query. The nested ZQ query is a test-case query TQ, and the
  : result of this function is added to the query FQ that will be evaluated via
- : XQXQ by the fots test driver. The function assumes that TQ will appear as a
- : nested XQXQ query within FQ, and that $queryID is the FQ variable storing
- : the XQXQ query id of TQ.
+ : ZQ by the fots test driver. The function assumes that TQ will appear as a
+ : nested ZQ query within FQ, and that $queryID is the FQ variable storing
+ : the ZQ query id of TQ.
  :
  : @param $env The environment (local or non-local) that applies to the current
  :        test case
  : @param $envBaseURI The absolute pathname of the directory containing the
  :        file that defines the environment.
- : @return the strings for variable binding in XQXQ.
+ : @return the strings for variable binding in ZQ.
  :)
 declare function env:set-variables(
   $env        as element(fots:environment)?,
@@ -492,7 +492,7 @@
     (
       for $src in $env/fots:source[starts-with(@role, "$")]
       return
-        concat('xqxq:bind-variable($queryID, xs:QName("',
+        concat('zq:bind-variable($queryID, xs:QName("',
                substring-after($src/@role, "$"),
                '"), ',
                'doc("',
@@ -510,7 +510,7 @@
       let $varName := $param/@name
       where (exists($select) and exists($param[@declared eq "true"]))
       return
-        concat('xqxq:bind-variable( $queryID, xs:QName("',
+        concat('zq:bind-variable( $queryID, xs:QName("',
                $param/@name,
                '"), ',
                $varValue,
@@ -523,13 +523,13 @@
 
 
 (:~
- : Returns the XQXQ URL resolver declaration.
+ : Returns the ZQ URL resolver declaration.
  :
  : @param $case the test case.
  : @param $env the environment.
  : @param $envBaseURI URI of the environment.
  : @param $testSetBaseURI URI to the test set that defines the test case.
- : @return the XQXQ URL resolver declaration.
+ : @return the ZQ URL resolver declaration.
  :)
 declare function env:resolver(
   $case           as element(fots:test-case),
@@ -620,12 +620,12 @@
 
 
 (:~
- : Returns the XQXQ URL mapper declaration.
+ : Returns the ZQ URL mapper declaration.
  : @param $case the test case.
  : @param $env the environment.
  : @param $envBaseURI URI of the environment.
  : @param $testSetBaseURI URI to the test set that defines the test case.
- : @return the XQXQ URL mapper declaration.
+ : @return the ZQ URL mapper declaration.
  :)
 declare function env:mapper(
   $case           as element(fots:test-case),

=== modified file 'test/fots_driver/evaluate.xq'
--- test/fots_driver/evaluate.xq	2013-08-09 08:27:30 +0000
+++ test/fots_driver/evaluate.xq	2013-08-12 17:27:54 +0000
@@ -25,8 +25,8 @@
 import schema namespace output =
   "http://www.w3.org/2010/xslt-xquery-serialization";;
 
-import module namespace xqxq =
-  "http://www.zorba-xquery.com/modules/xqxq";;
+import module namespace zq =
+  "http://zorba.io/modules/zorba-query";;
 
 import module namespace schema =
   "http://www.zorba-xquery.com/modules/schema";;
@@ -296,13 +296,13 @@
              "declare variable $result external; ",
              xs:string($expResult));
 
-    variable $queryKey := xqxq:prepare-main-module($queryText);
+    variable $queryKey := zq:prepare-main-module($queryText);
 
-    variable $queryKeyResult := xqxq:bind-variable($queryKey,
+    variable $queryKeyResult := zq:bind-variable($queryKey,
                                                    xs:QName('result'),
                                                    $result);
 
-    variable $queryResult := xqxq:evaluate($queryKey);
+    variable $queryResult := zq:evaluate($queryKey);
  
    if ($queryResult)
    then ()
@@ -346,11 +346,11 @@
       "declare variable $x external;",
       "let $y := (",string(data($expResult)),") return ",
       "every $i in 1 to max((count($x),count($y))) satisfies deep-equal($x[$i],$y[$i])");
-    variable $queryKey := xqxq:prepare-main-module($queryText),
-             $queryKeyResult := xqxq:bind-variable($queryKey,
+    variable $queryKey := zq:prepare-main-module($queryText),
+             $queryKeyResult := zq:bind-variable($queryKey,
                                                    xs:QName('x'),
                                                    $result),
-             $queryResult := xqxq:evaluate($queryKey);
+             $queryResult := zq:evaluate($queryKey);
     if ($queryResult)
     then ()
     else "'assert-deep-eq' returned: actual result is not deep-equal to expected result."
@@ -404,12 +404,12 @@
                   then concat("'",$expResult,"'")
                   else $expResult,
                   ")"));
-    variable  $queryKey := xqxq:prepare-main-module($queryText);
+    variable  $queryKey := zq:prepare-main-module($queryText);
   
-    xqxq:bind-variable($queryKey,
+    zq:bind-variable($queryKey,
                       xs:QName('x'),
                       $result);
-    variable $queryResult := xqxq:evaluate($queryKey);
+    variable $queryResult := zq:evaluate($queryKey);
     if ($queryResult)
     then ()
     else "'assert-eq' returned: result doesn't match expected result."
@@ -463,11 +463,11 @@
       "let $y := (",string(data($expResult)),") return ",
       "deep-equal(local:order-string-values($x), local:order-string-values($y)) or
        deep-equal(reverse($x), $y)");
-    variable $queryKey := xqxq:prepare-main-module($queryText),
-             $queryKeyResult := xqxq:bind-variable($queryKey,
+    variable $queryKey := zq:prepare-main-module($queryText),
+             $queryKeyResult := zq:bind-variable($queryKey,
                                                   xs:QName('x'),
                                                   $result),
-             $queryResult := xqxq:evaluate($queryKey);
+             $queryResult := zq:evaluate($queryKey);
     if ($queryResult)
     then ()
     else "'assert-permutation' returned: result isn't a permutation of expected result."
@@ -609,11 +609,11 @@
   {
     variable $queryText := concat( "declare variable $x external; $x instance of ",
                                   data($expResult));
-    variable $queryKey := xqxq:prepare-main-module($queryText),
-             $queryKeyResult := xqxq:bind-variable($queryKey,
+    variable $queryKey := zq:prepare-main-module($queryText),
+             $queryKeyResult := zq:bind-variable($queryKey,
                                                   xs:QName('x'),
                                                   $result),
-             $queryResult := xqxq:evaluate($queryKey);
+             $queryResult := zq:evaluate($queryKey);
     if ($queryResult)
     then ()
     else concat("'assert-type' returned: result doesn't have type '",

=== modified file 'test/fots_driver/execute.xq'
--- test/fots_driver/execute.xq	2013-08-09 08:27:30 +0000
+++ test/fots_driver/execute.xq	2013-08-12 17:27:54 +0000
@@ -22,8 +22,8 @@
 module namespace execute =
   "http://www.zorba-xquery.com/fots-driver/execute";;
 
-import module namespace xqxq =
-  "http://www.zorba-xquery.com/modules/xqxq#2.0";;
+import module namespace zq =
+  "http://zorba.io/modules/zorba-query#2.0";;
 
 import module namespace eval =
   "http://www.zorba-xquery.com/fots-driver/evaluate"; at "evaluate.xq";
@@ -43,17 +43,17 @@
 declare option op:disable "f:trace";
 
 (:~
- : XQXQ invoke.
- : @param $xqxqQueryText the query that will be run.
+ : ZQ invoke.
+ : @param $zqQueryText the query that will be run.
  : @param $case the test case.
  : @param $verbose if set to TRUE it will also output the actual result.
  : @param $testSetBaseURI the URI of the directory that contains the file of the
           associated test set.
  : @param $usePlanSerializer if true the plan serializer is used.
- : @return the result of running the query with XQXQ.
+ : @return the result of running the query with ZQ.
  :)
-declare %ann:sequential function execute:xqxq-invoke(
-  $xqxqQueryText      as xs:string,
+declare %ann:sequential function execute:zq-invoke(
+  $zqQueryText      as xs:string,
   $case               as element(fots:test-case),
   $verbose            as xs:boolean?,
   $testSetBaseURI     as xs:anyURI,
@@ -64,22 +64,22 @@
   {
     if($usePlanSerializer) then
     {
-      variable $queryKey := xqxq:prepare-main-module($xqxqQueryText);
-      variable $queryPlan := xqxq:query-plan($queryKey);
-      variable $queryPlanKey := xqxq:load-from-query-plan($queryPlan);
-      variable $queryResult := xqxq:evaluate-sequential($queryPlanKey);
+      variable $queryKey := zq:prepare-main-module($zqQueryText);
+      variable $queryPlan := zq:query-plan($queryKey);
+      variable $queryPlanKey := zq:load-from-query-plan($queryPlan);
+      variable $queryResult := zq:evaluate-sequential($queryPlanKey);
 
-      xqxq:delete-query($queryPlanKey);
-      xqxq:delete-query($queryKey);
+      zq:delete-query($queryPlanKey);
+      zq:delete-query($queryKey);
 
       eval:result($queryResult, $case/fots:result/*, $testSetBaseURI)
     }
     else
     {
-      variable $queryKey := xqxq:prepare-main-module($xqxqQueryText);
-      variable $queryResult := xqxq:evaluate-sequential($queryKey);
+      variable $queryKey := zq:prepare-main-module($zqQueryText);
+      variable $queryResult := zq:evaluate-sequential($queryKey);
 
-      xqxq:delete-query($queryKey);
+      zq:delete-query($queryKey);
 
       eval:result($queryResult, $case/fots:result/*, $testSetBaseURI)
     }

=== modified file 'test/fots_driver/fots-driver.xq'
--- test/fots_driver/fots-driver.xq	2013-08-09 08:27:30 +0000
+++ test/fots_driver/fots-driver.xq	2013-08-12 17:27:54 +0000
@@ -884,7 +884,7 @@
       "&#xA;"
       );
 
-    variable $xqxqQuery := driver:create-XQXQ-query($query,
+    variable $zqQuery := driver:create-ZQ-query($query,
                                                     $case,
                                                     $env,
                                                     $envBaseURI,
@@ -894,12 +894,12 @@
     (:if $verbose then print the query to a file:)
     if ($verbose and
         ($cliMode eq "run-test-case"))
-    then util:write-query-to-file($xqxqQuery, $queryName);
+    then util:write-query-to-file($zqQuery, $queryName);
     else ();
 
     variable $startDateTime := datetime:current-dateTime();
 
-    variable $result := execute:xqxq-invoke($xqxqQuery,
+    variable $result := execute:zq-invoke($zqQuery,
                                             $case,
                                             $verbose,
                                             $testSetURI,
@@ -912,7 +912,7 @@
     if ($checkPass) then
       feedback:pass($case,
                     $result,
-                    $xqxqQuery,
+                    $zqQuery,
                     $env,
                     $duration,
                     $verbose,
@@ -925,7 +925,7 @@
     else
      feedback:fail($case,
                    $result,
-                   $xqxqQuery,
+                   $zqQuery,
                    $testSetName,
                    $env,
                    $duration,
@@ -954,9 +954,9 @@
 
 
 (:~
- : Creates the text for the complete query FQ that will be evaluated via XQXQ
+ : Creates the text for the complete query FQ that will be evaluated via ZQ
  : by the fots test driver. The actual test-case query TQ will be evaluated as
- : a nested XQXQ query within FQ. FQ may contain additional nested XQXQ queries,
+ : a nested ZQ query within FQ. FQ may contain additional nested zorba-query queries,
  : for example to compute values for external variables declared in TQ.
  :
  : @param $queryText the text for the test-case query TQ. It is content of
@@ -970,7 +970,7 @@
  :        These may be defined at test-set level and/or test-case level.
  : @return the query that will be evaluated.
  :)
-declare %private function driver:create-XQXQ-query(
+declare %private function driver:create-ZQ-query(
   $queryText          as xs:string,
   $case               as element(fots:test-case),
   $env                as element(fots:environment)?,
@@ -993,7 +993,7 @@
     (
     (
     "",
-    "import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';",
+    "import module namespace zq = 'http://zorba.io/modules/zorba-query';",
    
     if ($needsDTDValidation) then
       ("import module namespace zorba-xml = 'http://zorba.io/modules/xml';",
@@ -1001,11 +1001,11 @@
     else (),
    
     if (exists($resolver))
-    then "declare namespace resolver = 'http://www.zorba-xquery.com/modules/xqxq/url-resolver';"
+    then "declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';"
     else (),
 
     if (exists($mapper))
-    then "declare namespace mapper = 'http://www.zorba-xquery.com/modules/xqxq/uri-mapper';"
+    then "declare namespace mapper = 'http://zorba.io/modules/zorba-query/uri-mapper';"
     else (),
 
     "",
@@ -1035,7 +1035,7 @@
     let $escAposQueryText := replace($queryText,"'","''")
     let $escAmpQueryText  := replace($escAposQueryText, '&amp;', '&amp;amp;')
     return concat(
-           "variable $queryID := xqxq:prepare-main-module&#xA;(",
+           "variable $queryID := zq:prepare-main-module&#xA;(",
            "&#xA;",
            "'",
            "&#xA;",
@@ -1056,9 +1056,9 @@
     env:set-variables($env, $envBaseURI),
     env:set-variables($case/fots:environment, $testSetURI),
 
-    "xqxq:evaluate($queryID),",
+    "zq:evaluate($queryID),",
     "",
-    "xqxq:delete-query($queryID)",
+    "zq:delete-query($queryID)",
     "        "
     ),
     "&#xA;"

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/bind-context-item.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/bind-variable.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-sequential.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate-updating.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<parent><child>Content</child></parent>
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-2
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/evaluate2.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-2
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/external-module.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/get-external-variables.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-a
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-context-item.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-false
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res	2013-02-15 06:11:20 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true true false foo

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-sequential.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true false
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-updating.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true false
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/multiple-queries.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-2 3
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/query-plan.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/query-plan.xml.res	2013-03-22 17:54:58 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/query-plan.xml.res	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-2
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/query-plan2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/query-plan2.xml.res	2013-03-22 17:54:58 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/query-plan2.xml.res	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-foo
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/query-plan3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/query-plan3.xml.res	2013-03-22 17:54:58 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/query-plan3.xml.res	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-foo
\ No newline at end of file

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-foo

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/uri-mapper2.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-module-resolver.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-foo

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver2.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== removed file 'test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res	2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/url-schema-resolver3.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== renamed directory 'test/rbkt/ExpQueryResults/zorba/xqxq' => 'test/rbkt/ExpQueryResults/zorba/zorba-query'
=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/bind-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/bind-context-item.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/bind-context-item.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/bind-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/bind-variable.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/bind-variable.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-sequential.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-sequential.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-updating.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate-updating.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<parent><child>Content</child></parent>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+2
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/evaluate2.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+2
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/external-module.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/external-module.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/external-module.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/get-external-variables.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/get-external-variables.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/get-external-variables.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+a
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-context-item.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-context-item.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-context-item.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+false
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-variable.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/is-bound-variable.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true true false foo

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/is-sequential.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/is-sequential.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/is-sequential.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true false
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/is-updating.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/is-updating.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/is-updating.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+true false
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/multiple-queries.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/multiple-queries.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/multiple-queries.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+2 3
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+2
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan2.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+foo
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan3.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/query-plan3.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+foo
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+foo

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/uri-mapper2.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/url-module-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/url-module-resolver.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/url-module-resolver.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+foo

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver2.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== added file 'test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver3.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/zorba-query/url-schema-resolver3.xml.res	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>

=== removed file 'test/rbkt/Queries/zorba/xqxq/bind-context-item.xq'
--- test/rbkt/Queries/zorba/xqxq/bind-context-item.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/bind-context-item.xq	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
-variable $xml := doc("context-item.xml");
-xqxq:bind-context-item($query-key, $xml); 
-xqxq:is-bound-context-item($query-key)

=== removed file 'test/rbkt/Queries/zorba/xqxq/bind-variable.xq'
--- test/rbkt/Queries/zorba/xqxq/bind-variable.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/bind-variable.xq	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-variable $query-key := xqxq:prepare-main-module('declare variable $a external; $a');
-xqxq:bind-variable($query-key,xs:QName('a'),"foo");
-xqxq:is-bound-variable($query-key, xs:QName('a'))
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/context-item.xml'
--- test/rbkt/Queries/zorba/xqxq/context-item.xml	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/context-item.xml	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-<parent></parent>
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/delete.spec'
--- test/rbkt/Queries/zorba/xqxq/delete.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/delete.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.zorba-xquery.com/modules/xqxq:NoQueryMatch
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/delete.xq'
--- test/rbkt/Queries/zorba/xqxq/delete.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/delete.xq	1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("1+1");
-xqxq:delete-query($query-key);
-xqxq:evaluate($query-key)

=== removed file 'test/rbkt/Queries/zorba/xqxq/error-in-query.spec'
--- test/rbkt/Queries/zorba/xqxq/error-in-query.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/error-in-query.spec	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-Error: http://www.w3.org/2005/xqt-errors:XQST0033
-

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsUpdating
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-sequential2.xq	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
-variable $xml := doc("context-item.xml");
-xqxq:bind-context-item($query-key, $xml);  
-xqxq:evaluate-sequential($query-key)
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-updating.xq	1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("insert node <child>Content</child> into /parent");
-variable $xml := doc("context-item.xml");
-xqxq:bind-context-item($query-key, $xml);  
-xqxq:evaluate-updating($query-key);
-$xml
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate-updating2.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsSequential
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate.xq	1970-01-01 00:00:00 +0000
@@ -1,5 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("1+1");
-variable $a := xqxq:evaluate($query-key);
-$a

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate2.xq'
--- test/rbkt/Queries/zorba/xqxq/evaluate2.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate2.xq	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("declare variable $a external; $a+1");
-xqxq:bind-variable($query-key, xs:QName("a"), 1);
-variable $b := xqxq:evaluate($query-key);
-$b

=== removed file 'test/rbkt/Queries/zorba/xqxq/evaluate3.spec'
--- test/rbkt/Queries/zorba/xqxq/evaluate3.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/evaluate3.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.zorba-xquery.com/modules/xqxq:QueryIsSequential
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/external-module.xq'
--- test/rbkt/Queries/zorba/xqxq/external-module.xq	2013-07-17 09:01:57 +0000
+++ test/rbkt/Queries/zorba/xqxq/external-module.xq	1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module('
-    import module namespace r = "http://zorba.io/modules/random";;
-
-    count((for $i in 1 to 10 return r:random(10), r:random())) eq 101
-    ');
-xqxq:evaluate($query-key)
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/get-external-variables.xq'
--- test/rbkt/Queries/zorba/xqxq/get-external-variables.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/get-external-variables.xq	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-variable $query-key2 := xqxq:prepare-main-module('declare variable $c external; $c');
-variable $query-key := xqxq:prepare-main-module('declare variable $a external;declare variable $d := "hi"; $a');                                                
-xqxq:external-variables($query-key)
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-context-item.xq	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key := xqxq:prepare-main-module("insert node <child/> into /parent");  
-xqxq:is-bound-context-item($query-key)

=== removed file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq	2013-02-15 06:11:20 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq	1970-01-01 00:00:00 +0000
@@ -1,11 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-variable $query-key := xqxq:prepare-main-module('
-  declare variable $a external;
-  declare variable $b external := 2;
-  declare variable $c external;
-  $a');
-xqxq:bind-variable($query-key, xs:QName('a'), "foo");
-xqxq:is-bound-variable($query-key, xs:QName('a')),
-xqxq:is-bound-variable($query-key, xs:QName('b')),
-xqxq:is-bound-variable($query-key, xs:QName('c')),
-xqxq:variable-value($query-key, xs:QName('a'))

=== removed file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable2.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.zorba-xquery.com/modules/xqxq:UndeclaredVariable
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable2.xq	1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-variable $query-key := xqxq:prepare-main-module('
-  declare variable $a external;
-  declare variable $b external := 2;
-  declare variable $c external;
-  $a');
-xqxq:is-bound-variable($query-key, xs:QName('x'))
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/multiple-queries.xq'
--- test/rbkt/Queries/zorba/xqxq/multiple-queries.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/multiple-queries.xq	1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $query-key1 := xqxq:prepare-main-module("1+1");
-variable $query-key2 := xqxq:prepare-main-module("1+2");
-variable $a := xqxq:evaluate($query-key1);
-variable $b := xqxq:evaluate($query-key2);
-xqxq:delete-query($query-key1);
-xqxq:delete-query($query-key2);
-$a, $b

=== removed file 'test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec'
--- test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/prepare-library-module.spec	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-Error: http://www.w3.org/2005/xqt-errors:XPST0003

=== removed file 'test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq'
--- test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/prepare-library-module.xq	1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-xqxq:prepare-library-module('module namespace foo = "foo:bar"; declare function foo:bar() { 1 }')

=== removed file 'test/rbkt/Queries/zorba/xqxq/query-plan.xq'
--- test/rbkt/Queries/zorba/xqxq/query-plan.xq	2013-03-22 23:09:40 +0000
+++ test/rbkt/Queries/zorba/xqxq/query-plan.xq	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-import module namespace xqxq = 'http://www.zorba-xquery.com/modules/xqxq';
-
-variable $queryID := xqxq:prepare-main-module("1+1");
-variable $query-plan := xqxq:query-plan($queryID); 
-variable $queryID2 := xqxq:load-from-query-plan($query-plan);
-xqxq:evaluate ($queryID2)

=== removed file 'test/rbkt/Queries/zorba/xqxq/test.xml'
--- test/rbkt/Queries/zorba/xqxq/test.xml	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/test.xml	1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
\ No newline at end of file

=== removed file 'test/rbkt/Queries/zorba/xqxq/test.xsd'
--- test/rbkt/Queries/zorba/xqxq/test.xsd	2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/test.xsd	1970-01-01 00:00:00 +0000
@@ -1,14 +0,0 @@
-<?xml version="1.0"?>
-<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
-  targetNamespace="http://test";
-  xmlns="http://test";
-  elementFormDefault="qualified">
-  <xs:element name="test">
-    <xs:complexType>
-      <xs:sequence>
-        <xs:element name="subtest" type="xs:string"/>
-        <xs:element name="subtest2" type="xs:string"/>
-      </xs:sequence>
-    </xs:complexType>
-  </xs:element>
-</xs:schema>                                                               
\ No newline at end of file

=== renamed directory 'test/rbkt/Queries/zorba/xqxq' => 'test/rbkt/Queries/zorba/zorba-query'
=== added file 'test/rbkt/Queries/zorba/zorba-query/bind-context-item.xq'
--- test/rbkt/Queries/zorba/zorba-query/bind-context-item.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/bind-context-item.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,6 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("insert node <child>Content</child> into /parent");
+variable $xml := doc("context-item.xml");
+zq:bind-context-item($query-key, $xml); 
+zq:is-bound-context-item($query-key)

=== added file 'test/rbkt/Queries/zorba/zorba-query/bind-variable.xq'
--- test/rbkt/Queries/zorba/zorba-query/bind-variable.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/bind-variable.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,4 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+variable $query-key := zq:prepare-main-module('declare variable $a external; $a');
+zq:bind-variable($query-key,xs:QName('a'),"foo");
+zq:is-bound-variable($query-key, xs:QName('a'))
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/context-item.xml'
--- test/rbkt/Queries/zorba/zorba-query/context-item.xml	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/context-item.xml	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+<parent></parent>
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/delete.spec'
--- test/rbkt/Queries/zorba/zorba-query/delete.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/delete.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-query:NoQueryMatch
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/delete.xq'
--- test/rbkt/Queries/zorba/zorba-query/delete.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/delete.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,5 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("1+1");
+zq:delete-query($query-key);
+zq:evaluate($query-key)

=== added file 'test/rbkt/Queries/zorba/zorba-query/error-in-query.spec'
--- test/rbkt/Queries/zorba/zorba-query/error-in-query.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/error-in-query.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,2 @@
+Error: http://www.w3.org/2005/xqt-errors:XQST0033
+

=== added file 'test/rbkt/Queries/zorba/zorba-query/error-in-query.xq'
--- test/rbkt/Queries/zorba/zorba-query/error-in-query.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/error-in-query.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,20 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace op = 'http://www.zorba-xquery.com/options/features';
+declare namespace f = 'http://www.zorba-xquery.com/features';
+
+declare function local:url-resolver($namespace as xs:string, $entity as xs:string) {
+switch($entity)
+case 'schema'
+  return switch($namespace)
+         case 'http://www.w3.org/XQueryTest' return doc('/tmp/atomic.xsd')
+         default return ()
+default return ()
+};
+
+variable $queryID := zq:prepare-main-module(
+  "declare namespace foo='http://test';
+   declare namespace foo='http://test';
+   1",
+   local:url-resolver#2, ());
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/error-in-query.xq' => 'test/rbkt/Queries/zorba/zorba-query/error-in-query.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-sequential.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-sequential.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-sequential.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,17 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module('
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";;
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare %an:sequential function local:foo() {
+  ddl:create(xs:QName("hola"),(<a/>,<b/>));                  
+  
+  exit returning true();
+};
+
+local:foo()
+');    
+variable $xml := doc("context-item.xml");
+zq:bind-context-item($query-key, $xml);  
+zq:evaluate-sequential($query-key)
+ 

=== renamed file 'test/rbkt/Queries/zorba/xqxq/evaluate-sequential.xq' => 'test/rbkt/Queries/zorba/zorba-query/evaluate-sequential.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.spec'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-query:QueryIsUpdating
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-sequential2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,6 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("insert node <child>Content</child> into /parent");
+variable $xml := doc("context-item.xml");
+zq:bind-context-item($query-key, $xml);  
+zq:evaluate-sequential($query-key)
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-updating.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-updating.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-updating.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,7 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("insert node <child>Content</child> into /parent");
+variable $xml := doc("context-item.xml");
+zq:bind-context-item($query-key, $xml);  
+zq:evaluate-updating($query-key);
+$xml
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.spec'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-query:QueryIsSequential
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,15 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module('
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";;
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare %an:sequential function local:foo() {
+  ddl:create(xs:QName("hola"),(<a/>,<b/>));                  
+  
+  exit returning ();
+};
+
+local:foo()
+');    
+zq:evaluate-updating($query-key);
+ 

=== renamed file 'test/rbkt/Queries/zorba/xqxq/evaluate-updating2.xq' => 'test/rbkt/Queries/zorba/zorba-query/evaluate-updating2.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,5 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("1+1");
+variable $a := zq:evaluate($query-key);
+$a

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate2.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,6 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("declare variable $a external; $a+1");
+zq:bind-variable($query-key, xs:QName("a"), 1);
+variable $b := zq:evaluate($query-key);
+$b

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate3.spec'
--- test/rbkt/Queries/zorba/zorba-query/evaluate3.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate3.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-query:QueryIsSequential
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/evaluate3.xq'
--- test/rbkt/Queries/zorba/zorba-query/evaluate3.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/evaluate3.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,15 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module('
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";;
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare %an:sequential function local:foo() {
+  ddl:create(xs:QName("hola"),(<a/>,<b/>));                  
+  
+  exit returning ();
+};
+
+local:foo()
+');
+variable $a := zq:evaluate($query-key);
+$a

=== renamed file 'test/rbkt/Queries/zorba/xqxq/evaluate3.xq' => 'test/rbkt/Queries/zorba/zorba-query/evaluate3.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/external-module.xq'
--- test/rbkt/Queries/zorba/zorba-query/external-module.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/external-module.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,8 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module('
+    import module namespace r = "http://zorba.io/modules/random";;
+
+    count((for $i in 1 to 10 return r:random(10), r:random())) eq 101
+    ');
+zq:evaluate($query-key)
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/get-external-variables.xq'
--- test/rbkt/Queries/zorba/zorba-query/get-external-variables.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/get-external-variables.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,4 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+variable $query-key2 := zq:prepare-main-module('declare variable $c external; $c');
+variable $query-key := zq:prepare-main-module('declare variable $a external;declare variable $d := "hi"; $a');                                                
+zq:external-variables($query-key)
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/is-bound-context-item.xq'
--- test/rbkt/Queries/zorba/zorba-query/is-bound-context-item.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-bound-context-item.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,4 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key := zq:prepare-main-module("insert node <child/> into /parent");  
+zq:is-bound-context-item($query-key)

=== added file 'test/rbkt/Queries/zorba/zorba-query/is-bound-variable.xq'
--- test/rbkt/Queries/zorba/zorba-query/is-bound-variable.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-bound-variable.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,11 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+variable $query-key := zq:prepare-main-module('
+  declare variable $a external;
+  declare variable $b external := 2;
+  declare variable $c external;
+  $a');
+zq:bind-variable($query-key, xs:QName('a'), "foo");
+zq:is-bound-variable($query-key, xs:QName('a')),
+zq:is-bound-variable($query-key, xs:QName('b')),
+zq:is-bound-variable($query-key, xs:QName('c')),
+zq:variable-value($query-key, xs:QName('a'))

=== added file 'test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.spec'
--- test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-query:UndeclaredVariable
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.xq'
--- test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-bound-variable2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,7 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+variable $query-key := zq:prepare-main-module('
+  declare variable $a external;
+  declare variable $b external := 2;
+  declare variable $c external;
+  $a');
+zq:is-bound-variable($query-key, xs:QName('x'))
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/is-sequential.xq'
--- test/rbkt/Queries/zorba/zorba-query/is-sequential.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-sequential.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,18 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key1 := zq:prepare-main-module('
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";;
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare %an:sequential function local:foo() {
+  ddl:create(xs:QName("hola"),(<a/>,<b/>));                  
+  
+  exit returning ();
+};
+
+local:foo()
+');  
+variable $query-key2 := zq:prepare-main-module("insert node <child/> into /parent");  
+variable $is-sequential := zq:is-sequential($query-key1);
+variable $is-not-sequential := zq:is-sequential($query-key2); 
+$is-sequential, $is-not-sequential
+ 

=== renamed file 'test/rbkt/Queries/zorba/xqxq/is-sequential.xq' => 'test/rbkt/Queries/zorba/zorba-query/is-sequential.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/is-updating.xq'
--- test/rbkt/Queries/zorba/zorba-query/is-updating.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/is-updating.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,20 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key1 := zq:prepare-main-module('
+import module namespace ddl = "http://www.zorba-xquery.com/modules/store/dynamic/collections/ddl";;
+declare namespace an = "http://www.zorba-xquery.com/annotations";;
+declare %an:sequential function local:foo() {
+  ddl:create(xs:QName("hola"),(<a/>,<b/>));                  
+  
+  exit returning ();
+};
+
+local:foo()
+');  
+variable $query-key2 := zq:prepare-main-module("insert node <child/> into /parent");  
+variable $is-updating := zq:is-updating($query-key2);
+variable $is-not-updating := zq:is-updating($query-key1); 
+zq:delete-query($query-key1);
+zq:delete-query($query-key2);
+$is-updating, $is-not-updating
+ 

=== renamed file 'test/rbkt/Queries/zorba/xqxq/is-updating.xq' => 'test/rbkt/Queries/zorba/zorba-query/is-updating.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/multiple-queries.xq'
--- test/rbkt/Queries/zorba/zorba-query/multiple-queries.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/multiple-queries.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,9 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $query-key1 := zq:prepare-main-module("1+1");
+variable $query-key2 := zq:prepare-main-module("1+2");
+variable $a := zq:evaluate($query-key1);
+variable $b := zq:evaluate($query-key2);
+zq:delete-query($query-key1);
+zq:delete-query($query-key2);
+$a, $b

=== added file 'test/rbkt/Queries/zorba/zorba-query/prepare-library-module.spec'
--- test/rbkt/Queries/zorba/zorba-query/prepare-library-module.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/prepare-library-module.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://www.w3.org/2005/xqt-errors:XPST0003

=== added file 'test/rbkt/Queries/zorba/zorba-query/prepare-library-module.xq'
--- test/rbkt/Queries/zorba/zorba-query/prepare-library-module.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/prepare-library-module.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,3 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+zq:prepare-library-module('module namespace foo = "foo:bar"; declare function foo:bar() { 1 }')

=== added file 'test/rbkt/Queries/zorba/zorba-query/query-plan.xq'
--- test/rbkt/Queries/zorba/zorba-query/query-plan.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/query-plan.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,6 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+variable $queryID := zq:prepare-main-module("1+1");
+variable $query-plan := zq:query-plan($queryID); 
+variable $queryID2 := zq:load-from-query-plan($query-plan);
+zq:evaluate ($queryID2)

=== added file 'test/rbkt/Queries/zorba/zorba-query/query-plan2.xq'
--- test/rbkt/Queries/zorba/zorba-query/query-plan2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/query-plan2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,20 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://test.xq')
+  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+  else ()
+};
+
+variable $queryID := zq:prepare-main-module(
+  "import module namespace test = 'http://test'; test:foo()",
+  resolver:url-resolver#2, ());
+
+
+variable $query-plan := zq:query-plan($queryID); 
+variable $queryID2 := zq:load-from-query-plan($query-plan, resolver:url-resolver#2, ());
+zq:evaluate ($queryID2)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/query-plan2.xq' => 'test/rbkt/Queries/zorba/zorba-query/query-plan2.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/query-plan3.xq'
--- test/rbkt/Queries/zorba/zorba-query/query-plan3.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/query-plan3.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,28 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace mapper = 'http://zorba.io/modules/zorba-query/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://foo')
+  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+  else ()
+};
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+   if($namespace = 'http://test')
+   then 'http://foo'
+   else ()
+};
+
+variable $queryID := zq:prepare-main-module
+(
+  "import module namespace test = 'http://test'; test:foo()", 
+  resolver:url-resolver#2, mapper:uri-mapper#2
+);
+variable $query-plan := zq:query-plan($queryID); 
+variable $queryID2 := zq:load-from-query-plan($query-plan, resolver:url-resolver#2, mapper:uri-mapper#2);
+zq:evaluate ($queryID2)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/query-plan3.xq' => 'test/rbkt/Queries/zorba/zorba-query/query-plan3.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/query-plan4.spec'
--- test/rbkt/Queries/zorba/zorba-query/query-plan4.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/query-plan4.spec	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+Error: http://zorba.io/modules/zorba-errors:ZCSE0013

=== renamed file 'test/rbkt/Queries/zorba/xqxq/query-plan4.spec' => 'test/rbkt/Queries/zorba/zorba-query/query-plan4.spec.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/query-plan4.xq'
--- test/rbkt/Queries/zorba/zorba-query/query-plan4.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/query-plan4.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,28 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace mapper = 'http://zorba.io/modules/zorba-query/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://foo')
+  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+  else ()
+};
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+   if($namespace = 'http://test')
+   then 'http://foo'
+   else ()
+};
+
+variable $queryID := zq:prepare-main-module
+(
+  "import module namespace test = 'http://test'; test:foo()", 
+  resolver:url-resolver#2, mapper:uri-mapper#2
+);
+variable $query-plan := zq:query-plan($queryID); 
+variable $queryID2 := zq:load-from-query-plan($query-plan);
+zq:evaluate ($queryID2)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/query-plan4.xq' => 'test/rbkt/Queries/zorba/zorba-query/query-plan4.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/test.xml'
--- test/rbkt/Queries/zorba/zorba-query/test.xml	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/test.xml	2013-08-12 17:27:54 +0000
@@ -0,0 +1,1 @@
+<test:test xmlns:test="http://test";><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/test.xsd'
--- test/rbkt/Queries/zorba/zorba-query/test.xsd	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/test.xsd	2013-08-12 17:27:54 +0000
@@ -0,0 +1,14 @@
+<?xml version="1.0"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
+  targetNamespace="http://test";
+  xmlns="http://test";
+  elementFormDefault="qualified">
+  <xs:element name="test">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="subtest" type="xs:string"/>
+        <xs:element name="subtest2" type="xs:string"/>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>                                                               
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/zorba-query/uri-mapper.xq'
--- test/rbkt/Queries/zorba/zorba-query/uri-mapper.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/uri-mapper.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,26 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace mapper = 'http://zorba.io/modules/zorba-query/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://foo')
+  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+  else ()
+};
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+   if($namespace = 'http://test')
+   then 'http://foo'
+   else ()
+};
+
+variable $queryID := zq:prepare-main-module
+(
+  "import module namespace test = 'http://test'; test:foo()", 
+  resolver:url-resolver#2, mapper:uri-mapper#2
+);
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/uri-mapper.xq' => 'test/rbkt/Queries/zorba/zorba-query/uri-mapper.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/uri-mapper2.xq'
--- test/rbkt/Queries/zorba/zorba-query/uri-mapper2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/uri-mapper2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,21 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace mapper = 'http://zorba.io/modules/zorba-query/uri-mapper';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function mapper:uri-mapper($namespace as xs:string, $entity as xs:string)
+{
+  if ($namespace = 'http://test' and $entity = 'schema')
+  then resolve-uri('test.xsd')
+  else ()
+};
+
+variable $queryID := zq:prepare-main-module
+(
+  "import schema namespace test = 'http://test'; validate{<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}", 
+  (),
+  mapper:uri-mapper#2
+);
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/uri-mapper2.xq' => 'test/rbkt/Queries/zorba/zorba-query/uri-mapper2.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/url-module-resolver.xq'
--- test/rbkt/Queries/zorba/zorba-query/url-module-resolver.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/url-module-resolver.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,16 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://test.xq')
+  then "module namespace test = 'http://test'; declare function test:foo(){'foo'};"
+  else ()
+};
+
+variable $queryID := zq:prepare-main-module(
+  "import module namespace test = 'http://test'; test:foo()",
+  resolver:url-resolver#2, ());
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/url-module-resolver.xq' => 'test/rbkt/Queries/zorba/zorba-query/url-module-resolver.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver.xq'
--- test/rbkt/Queries/zorba/zorba-query/url-schema-resolver.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/url-schema-resolver.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,19 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://test' and $entity = 'schema')
+  then 
+    doc('test.xsd')
+  else 
+    ()
+};
+
+variable $queryID := zq:prepare-main-module(
+  "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
+  resolver:url-resolver#2, ());
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver.xq' => 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver2.xq'
--- test/rbkt/Queries/zorba/zorba-query/url-schema-resolver2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/url-schema-resolver2.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,28 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+import module namespace ddl =
+    "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/ddl";;
+import module namespace dml =
+    "http://www.zorba-xquery.com/modules/store/dynamic/collections/w3c/dml";;
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if ($entity = 'schema')
+  then
+    dml:collection("http://zorba.io/modules/zorba-query";)//xs:schema[@targetNamespace=$namespace]
+  else
+    ()
+};
+
+declare variable $coll := "http://zorba.io/modules/zorba-query";;
+declare variable $schema := doc("test.xsd");
+ddl:create($coll);
+
+dml:apply-insert-nodes-first($coll, $schema);
+variable $query-key := zq:prepare-main-module(
+  "import schema namespace test = 'http://test'; validate {<test:test><test:subtest>a</test:subtest><test:subtest2>a</test:subtest2></test:test>}",
+  resolver:url-resolver#2, ());
+zq:evaluate($query-key)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver2.xq' => 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver2.xq.THIS'
=== added file 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver3.xq'
--- test/rbkt/Queries/zorba/zorba-query/url-schema-resolver3.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/zorba-query/url-schema-resolver3.xq	2013-08-12 17:27:54 +0000
@@ -0,0 +1,28 @@
+import module namespace zq = 'http://zorba.io/modules/zorba-query';
+
+declare namespace resolver = 'http://zorba.io/modules/zorba-query/url-resolver';
+
+declare namespace op = "http://www.zorba-xquery.com/options/features";;
+declare namespace f = "http://www.zorba-xquery.com/features";;
+
+declare function resolver:url-resolver($namespace as xs:string, $entity as xs:string) {
+  if($namespace = 'http://test' and $entity = 'schema')
+  then 
+    doc('test.xsd')
+  else 
+    ()
+};
+
+variable $contextQueryID := zq:prepare-main-module(
+  "import schema namespace test = 'http://test';
+  declare variable $cwd as xs:anyURI external;
+  validate { doc(resolve-uri('test.xml', $cwd)) }",
+  resolver:url-resolver#2, ());
+zq:bind-variable($contextQueryID, fn:QName("", "cwd"), resolve-uri("."));
+variable $contextItem := zq:evaluate($contextQueryID);
+
+variable $queryID := zq:prepare-main-module(
+  "import schema namespace test = 'http://test'; //*:test",
+  resolver:url-resolver#2, ());
+zq:bind-context-item($queryID, $contextItem);
+zq:evaluate($queryID)

=== renamed file 'test/rbkt/Queries/zorba/xqxq/url-schema-resolver3.xq' => 'test/rbkt/Queries/zorba/zorba-query/url-schema-resolver3.xq.THIS'

Follow ups