← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/identifiers into lp:zorba

 

Federico Cavalieri has proposed merging lp:~zorba-coders/zorba/identifiers into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/identifiers/+merge/78383

Changed the implementation of the reference module.
Now the module provides functions to compute an immutable and opaque reference 
for any node, either temporary or stored in a collection and for retrieving
nodes given their identifier. The identifiers are immutable, i.e. a node 
identifier do not change during the node lifetime. Identifiers are also 
unique, in that, a generated identifier has never been generated before.
A node, at any time during its lifetime, can be retrieved by its identifier.
-- 
https://code.launchpad.net/~zorba-coders/zorba/identifiers/+merge/78383
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2011-10-05 22:39:18 +0000
+++ ChangeLog	2011-10-06 10:15:01 +0000
@@ -41,6 +41,8 @@
   * Fixed bug #863730 (static delete-node* functions don't raise ZDDY0012)
   * Implemented the probe-index-range-value for general indexes
   * Fixed bug #867662 ("nullptr" warning)
+  * Fixed bug #869024 (segmentation fault with node-reference)
+  * Fixed bug #869025 (segmentation fault with node-reference)
 
 version 2.0.1
 

=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2011-10-04 05:28:07 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2011-10-06 10:15:01 +0000
@@ -488,6 +488,10 @@
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZAPI0028_INVALID_NODE_URI;
 
+extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZAPI0029_REFERENCE_ALREADY_PRESENT;
+
+extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZAPI0030_NO_CURRENT_REFERENCE;
+
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZAPI0039_XQUERY_HAS_ITERATOR_ALREADY;
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZAPI0040_ITERATOR_NOT_OPEN;

=== modified file 'modules/com/zorba-xquery/www/modules/node-reference.xq'
--- modules/com/zorba-xquery/www/modules/node-reference.xq	2011-08-26 23:36:24 +0000
+++ modules/com/zorba-xquery/www/modules/node-reference.xq	2011-10-06 10:15:01 +0000
@@ -17,15 +17,19 @@
 :)
 
 (:~
- : The module provides functions to compute a stable reference (URI) for
- : a node that is stored in a collection and vice versa.
+ : The module provides functions to compute an immutable and opaque reference 
+ : for any node, either temporary or stored in a collection and for retrieving
+ : nodes given their identifier. The identifiers are immutable, i.e. a node 
+ : identifier do not change during the node lifetime. Identifiers are also 
+ : unique, in that, a generated identifier has never been generated before.
+ : A node, at any time during its lifetime, can be retrieved by its identifier.
  :
  : <p>Please see the <a href="../../html/data_lifecycle.html">data lifecycle
  : documentation</a> about details on management and manipulation of collections.</p>
  : 
  : @see <a href="../../html/data_lifecycle.html">Data Lifecycle</a>
  :
- : @author Matthias Brantner
+ : @author Federico Cavalieri
  :
  : @project XDM/node
  :
@@ -38,14 +42,17 @@
 declare option ver:module-version "2.0";
 
 (:~
- : Compute a stable and opaque node reference (with type xs:anyURI) for
- : a given node.
- :
- : <p>The function can only compute reference for nodes that a stored
- : in a collection [zerr:ZAPI0080].</p>
- :
- : <p>The returned URI is stable, i.e. it still can be dereferenced if
- : the node or the containing collection is modified.</p>
+ : Computes an immutable and opaque node reference (with type xs:anyURI) for
+ : a given node, either temporary or stored in a collection.
+ : 
+ : <p>The generated identifier is immutable, i.e. a node 
+ : identifier do not change during the node lifetime.</p>
+ :
+ : <p>Identifiers are also unique, in that, a generated identifier has never
+ : been generated before.</p>
+ :
+ : A node, at any time during its lifetime, can be retrieved by its 
+ : identifier. 
  :
  : @param $arg the node for which the URI should be computed
  :
@@ -58,7 +65,7 @@
 (:~
  : Returns the node identified by the given node reference.
  :
- : <p>The function may return the empty sequence if the node
+ : <p>The function returns the empty sequence if the node
  : that is referenced was deleted.</p>
  :
  : @param $arg the URI of the node to retrieve.
@@ -71,4 +78,4 @@
  :)
 declare function ref:node-by-reference(
   $arg as xs:anyURI
-) as node()? external;
+) as node()? external;
\ No newline at end of file

=== modified file 'modules/com/zorba-xquery/www/modules/pregenerated/errors.xq'
--- modules/com/zorba-xquery/www/modules/pregenerated/errors.xq	2011-09-30 14:06:33 +0000
+++ modules/com/zorba-xquery/www/modules/pregenerated/errors.xq	2011-10-06 10:15:01 +0000
@@ -277,6 +277,14 @@
 
 (:~
 :)
+declare variable $zerr:ZAPI0029 as xs:QName := fn:QName($zerr:NS, "zerr:ZAPI0029");
+
+(:~
+:)
+declare variable $zerr:ZAPI0030 as xs:QName := fn:QName($zerr:NS, "zerr:ZAPI0030");
+
+(:~
+:)
 declare variable $zerr:ZAPI0039 as xs:QName := fn:QName($zerr:NS, "zerr:ZAPI0039");
 
 (:~

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2011-10-04 05:28:07 +0000
+++ src/diagnostics/diagnostic_en.xml	2011-10-06 10:15:01 +0000
@@ -1768,6 +1768,14 @@
       <value>"$1": invalid node URI</value>
     </diagnostic>
 
+    <diagnostic code="ZAPI0029" name="REFERENCE_ALREADY_PRESENT">
+      <value>"$1": reference already present in the store</value>
+    </diagnostic>
+   
+    <diagnostic code="ZAPI0030" name="NO_CURRENT_REFERENCE">
+      <value>node has no current reference</value>
+    </diagnostic>
+
     <diagnostic code="ZAPI0039" name="XQUERY_HAS_ITERATOR_ALREADY">
       <value>XQuery has iterator already</value>
     </diagnostic>

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2011-10-04 05:28:07 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2011-10-06 10:15:01 +0000
@@ -711,6 +711,12 @@
 ZorbaErrorCode ZAPI0028_INVALID_NODE_URI( "ZAPI0028" );
 
 
+ZorbaErrorCode ZAPI0029_REFERENCE_ALREADY_PRESENT( "ZAPI0029" );
+
+
+ZorbaErrorCode ZAPI0030_NO_CURRENT_REFERENCE( "ZAPI0030" );
+
+
 ZorbaErrorCode ZAPI0039_XQUERY_HAS_ITERATOR_ALREADY( "ZAPI0039" );
 
 

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2011-10-04 05:28:07 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2011-10-06 10:15:01 +0000
@@ -238,6 +238,8 @@
   { "ZAPI0021", "\"$1\": item to load is not a node" },
   { "ZAPI0027", "cannot update dynamic context with iterators" },
   { "ZAPI0028", "\"$1\": invalid node URI" },
+  { "ZAPI0029", "\"$1\": reference already present in the store" },
+  { "ZAPI0030", "node has no current reference" },
   { "ZAPI0039", "XQuery has iterator already" },
   { "ZAPI0040", "iterator is not open" },
   { "ZAPI0041", "iterator is already open" },

=== modified file 'src/runtime/nodes/nodes_impl.cpp'
--- src/runtime/nodes/nodes_impl.cpp	2011-08-04 02:39:56 +0000
+++ src/runtime/nodes/nodes_impl.cpp	2011-10-06 10:15:01 +0000
@@ -33,43 +33,51 @@
 
 namespace zorba {
 
-bool NodeReferenceIterator::nextImpl(store::Item_t& result, PlanState& planState) const
-{
-  PlanIteratorState *state;
-  bool valid;
-  store::Item_t inNode;
-  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
-
-  valid = consumeNext(inNode, theChildren[0], planState);
-  assert(valid);
-
-  if (! inNode->getCollection() )
-  {
-    throw XQUERY_EXCEPTION(
-      zerr::ZAPI0080_CANNOT_RETRIEVE_NODE_REFERENCE,
-      ERROR_LOC( loc )
-    );
-  }
-
-  STACK_PUSH(GENV_STORE.getReference(result, inNode), state);
-  STACK_END(state);
-}
-
-bool NodeByReferenceIterator::nextImpl(store::Item_t& result, PlanState& planState) const
-{
-  store::Item_t inUri;
-  bool valid;
-
-  PlanIteratorState *state;
-  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
-
-  valid = consumeNext(inUri, theChildren[0], planState);
-  assert(valid);
-
-  STACK_PUSH(GENV_STORE.getNodeByReference(result, inUri), state);
+/*******************************************************************************
+********************************************************************************/
+bool
+NodeReferenceIterator::nextImpl(store::Item_t& aResult, PlanState& aPlanState) const
+{
+  store::Item_t lNode;
+  store::Item_t lGenerateIdentifier;
+  zstring lNodeId;
+
+  PlanIteratorState *state;
+  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);
+
+  consumeNext(lNode, theChildren[0].getp(), aPlanState);
+
+  STACK_PUSH(GENV_STORE.getReference(aResult, lNode), state);
+
   STACK_END (state);
 }
 
+/*******************************************************************************
+********************************************************************************/
+bool
+NodeByReferenceIterator::nextImpl(store::Item_t& result, PlanState& planState) const
+{
+    store::Item_t lUUID;
+    bool haveResult;
+
+    PlanIteratorState *state;
+    DEFAULT_STACK_INIT(PlanIteratorState, state, planState);
+
+    consumeNext(lUUID, theChildren[0].getp(), planState);
+    try
+    {
+      haveResult=GENV_STORE.getNodeByReference(result, lUUID->getStringValue());
+    }
+    catch (ZorbaException& e)
+    {
+      set_source( e, loc );
+      throw;
+    }
+    STACK_PUSH(haveResult, state);
+
+    STACK_END (state);
+}
+
 
 // 14.2 fn:local-name
 //---------------------
@@ -354,9 +362,9 @@
           // need to convert the opaque uri into a valid ncname
           // e.g. z0.1.1.c.50
 #ifndef NDEBUG
-          ZORBA_ASSERT( uri_string.find_first_of("zorba:") == 0 );
+          ZORBA_ASSERT( uri_string.find_first_of("urn:uuid:") == 0 );
 #endif
-          lRes = "z" + uri_string.substr(uri_string.find_first_of(":") + 1);
+          lRes = "u" + uri_string.substr(9);
         }
       }
       retval = GENV_ITEMFACTORY->createString(result, lRes);

=== modified file 'src/runtime/nodes/pregenerated/nodes.h'
--- src/runtime/nodes/pregenerated/nodes.h	2011-06-16 19:47:58 +0000
+++ src/runtime/nodes/pregenerated/nodes.h	2011-10-06 10:15:01 +0000
@@ -34,10 +34,10 @@
 namespace zorba {
 
 /**
- * 
- *  Iterator to implement the zorba:node-reference function.
- *  
- * Author: Zorba Team
+ *        
+ *      declare function ref:node-reference($node as node) as xs:anyURI
+ *    
+ * Author: Federico Cavalieri
  */
 class NodeReferenceIterator : public NaryBaseIterator<NodeReferenceIterator, PlanIteratorState>
 { 
@@ -71,9 +71,9 @@
 
 /**
  * 
- *      Iterator to implement the zorba:node-by-reference function.
+ *      declare function id:node-by-identifier($identifier as xs:anyURI) as node()?
  *    
- * Author: Zorba Team
+ * Author: Federico Cavalieri
  */
 class NodeByReferenceIterator : public NaryBaseIterator<NodeByReferenceIterator, PlanIteratorState>
 { 

=== modified file 'src/runtime/spec/nodes/nodes.xml'
--- src/runtime/spec/nodes/nodes.xml	2011-08-04 02:39:56 +0000
+++ src/runtime/spec/nodes/nodes.xml	2011-10-06 10:15:01 +0000
@@ -11,45 +11,49 @@
   xmlns:zorba="http://www.zorba-xquery.com";
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
   xsi:schemaLocation="http://www.zorba-xquery.com ../runtime.xsd">
-    
-<!--
-/*******************************************************************************
-********************************************************************************/
--->
-<zorba:iterator name="NodeReferenceIterator">
-
-  <zorba:description author="Zorba Team">
-  Iterator to implement the zorba:node-reference function.
-  </zorba:description>
-
-  <zorba:function>
-    <zorba:signature localname="node-reference" prefix="fn-zorba-ref">
-      <zorba:param>node()</zorba:param>
-      <zorba:output>xs:anyURI</zorba:output>
-    </zorba:signature>
-  </zorba:function>
-
-</zorba:iterator>
-
-<!--
-/*******************************************************************************
-********************************************************************************/
--->
-<zorba:iterator name="NodeByReferenceIterator">
-
-    <zorba:description author="Zorba Team">
-      Iterator to implement the zorba:node-by-reference function.
-    </zorba:description>
-
-    <zorba:function>
+
+<!--
+/*******************************************************************************
+********************************************************************************/
+-->
+  <zorba:iterator name="NodeReferenceIterator">
+
+    <zorba:description author="Federico Cavalieri">       
+      declare function ref:node-reference($node as node) as xs:anyURI
+    </zorba:description>
+    
+    <zorba:function>
+    
+      <zorba:signature localname="node-reference" prefix="fn-zorba-ref">
+        <zorba:param>node()</zorba:param>   
+        <zorba:output>xs:anyURI</zorba:output>
+      </zorba:signature>
+      
+    </zorba:function>
+
+  </zorba:iterator>
+
+<!--
+/*******************************************************************************
+********************************************************************************/
+-->
+  <zorba:iterator name="NodeByReferenceIterator">
+
+    <zorba:description author="Federico Cavalieri">
+      declare function id:node-by-identifier($identifier as xs:anyURI) as node()?
+    </zorba:description>
+
+    <zorba:function>
+    
       <zorba:signature localname="node-by-reference" prefix="fn-zorba-ref">
         <zorba:param>xs:anyURI</zorba:param>
         <zorba:output>node()?</zorba:output>
       </zorba:signature>
+      
     </zorba:function>
-
-</zorba:iterator>
-
+        
+  </zorba:iterator>
+    
 <!--
 /*******************************************************************************
 ********************************************************************************/

=== modified file 'src/store/api/copymode.h'
--- src/store/api/copymode.h	2011-06-14 17:26:33 +0000
+++ src/store/api/copymode.h	2011-10-06 10:15:01 +0000
@@ -34,13 +34,15 @@
   bool  theTypePreserve;
   bool  theNsPreserve;
   bool  theNsInherit;
+  bool  theCopyReference;
 
   CopyMode()
     :
     theDoCopy(true),
     theTypePreserve(true),
     theNsPreserve(true),
-    theNsInherit(true)
+    theNsInherit(true),
+    theCopyReference(false)
   {
   }
 
@@ -49,7 +51,8 @@
     theDoCopy(aCopyMode.theDoCopy),
     theTypePreserve(aCopyMode.theTypePreserve),
     theNsPreserve(aCopyMode.theNsPreserve),
-    theNsInherit(aCopyMode.theNsInherit)
+    theNsInherit(aCopyMode.theNsInherit),
+    theCopyReference(aCopyMode.theCopyReference)
   {
   }
 
@@ -57,12 +60,14 @@
         bool copy,
         bool typePreserve,
         bool nsPreserve,
-        bool nsInherit)
+        bool nsInherit,
+        bool copyReference=false)
   {
     theDoCopy = copy;
     theTypePreserve = typePreserve;
     theNsPreserve = nsPreserve;
     theNsInherit = nsInherit;
+    theCopyReference= copyReference;
   }
 
   std::string toString() const
@@ -76,6 +81,8 @@
     s += (theNsPreserve ? "T" : "F");
     s += " ";
     s += (theNsInherit ? "T" : "F");
+    s += " ";
+    s += (theCopyReference ? "T" : "F");
     s += "]";
     return s;
   }

=== modified file 'src/store/api/store.h'
--- src/store/api/store.h	2011-09-27 10:43:46 +0000
+++ src/store/api/store.h	2011-10-06 10:15:01 +0000
@@ -87,26 +87,35 @@
    */
   virtual TempSeq_t createTempSeq(bool lazy) = 0;
 
-
-  /* -------------------------- Reference Management --------------------------*/
-		
-  /** 
-   * Computes the URI of the passed item.
-   *
-   * @param item XDM item
-   * @return Returns an item of type xs:uri 
-   */
-  virtual bool getReference(Item_t& result, const Item* node) = 0;
-		
-  /**
-   * Returns Item which is identified by a reference
-   *
-   * @param uri Has to be an xs:URI item
-   * @returns referenced item if it exists, otherwise NULL
-   */
-  virtual bool getNodeByReference(Item_t& result, const Item* uri) = 0;
-		
-		
+  /* ----------------------- Node Reference Management -------------------------*/
+
+  /**
+   * Computes the reference of the given node.
+   *
+   * @param node XDM node
+   * @return the identifier as an item of type xs:anyURI
+   */
+  virtual bool getReference(Item_t& result, Item* node) = 0;
+
+  /**
+   * Returns whether a reference has already been generated for the given node.
+   *
+   * @param item XDM node
+   * @return whether a reference has already been generated for the given node.
+   */
+  virtual bool hasReference(const Item* node) = 0;
+
+  /**
+   * Returns the node which is identified by the given reference.
+   * If the given reference is not a valid reference, as generated by
+   * getReference, error ZAPI0028 is raised.
+   *
+   * @param reference an xs:anyURI item
+   * @returns the node identified by the reference, NULL otherwise
+   */
+  virtual bool getNodeByReference(store::Item_t& result, const zstring& reference) = 0;
+
+
   /* --------------------------- Node Id Management ---------------------------*/
 
   /**

=== modified file 'src/store/naive/node_items.cpp'
--- src/store/naive/node_items.cpp	2011-10-03 08:49:55 +0000
+++ src/store/naive/node_items.cpp	2011-10-06 10:15:01 +0000
@@ -234,7 +234,7 @@
 
   if (theTypesMap == NULL)
   {
-    theTypesMap = new NodeTypeMap(source->theTypesMap->object_count(), false);
+    theTypesMap = new NodeTypeMap(source->theTypesMap->size(), false);
   }
 
   NodeTypeMap::iterator ite = source->theTypesMap->begin();
@@ -693,6 +693,7 @@
   }
 #endif
 
+  GET_STORE().unregisterNode(this);
   delete this;
 }
 
@@ -1350,7 +1351,7 @@
 XmlNode* DocumentNode::copyInternal(
     InternalNode*          rootParent,
     InternalNode*          parent,
-    csize                pos,
+    csize                  pos,
     const XmlNode*         rootCopy,
     const store::CopyMode& copymode) const
 {
@@ -1387,6 +1388,10 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this, copyNode);
+
+
   NODE_TRACE1("}");
   NODE_TRACE1("Copied doc node " << this << " to node " << copyNode);
 
@@ -2011,6 +2016,9 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this,copyNode);
+
   NODE_TRACE1("Copied elem node " << this << " to node " << copyNode
               << " name = " << theName->getStringValue() << " parent = "
               << (parent ? parent : 0x0)
@@ -3125,6 +3133,9 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this,copyNode);
+
   NODE_TRACE1("Copied attribute node " << this << " to node " << copyNode
               << " name = " << theName->show() << " parent = "
               << std::hex << (parent ? (ulong)parent : 0) << " pos = " << pos
@@ -3593,6 +3604,9 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this,copyNode);
+
   NODE_TRACE1("Copied text node " << this << " to node " << copyNode
               << " parent = " << std::hex << (parent ? (ulong)parent : 0)
               << " pos = " << pos);
@@ -4079,6 +4093,9 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this,copyNode);
+
   NODE_TRACE1("Copied pi node " << this << " to node " << copyNode
               << " parent = " << std::hex << (parent ? (ulong)parent : 0)
               << " pos = " << pos);
@@ -4202,6 +4219,9 @@
     throw;
   }
 
+  if (copymode.theCopyReference)
+    GET_STORE().copyReference(this,copyNode);
+
   NODE_TRACE1("Copied coment node " << this << " to node " << copyNode
               << " parent = " << std::hex << (parent ? (ulong)parent : 0)
               << " pos = " << pos);

=== modified file 'src/store/naive/node_items.h'
--- src/store/naive/node_items.h	2011-09-23 14:26:00 +0000
+++ src/store/naive/node_items.h	2011-10-06 10:15:01 +0000
@@ -309,30 +309,31 @@
 public:
   enum NodeFlags
   {
-    NodeKindMask      =   0x7,
-    IsId              =   0x8,
-    IsIdRefs          =   0x10,
-    HaveTypedValue    =   0x20,    // for element nodes only
-    HaveEmptyValue    =   0x40,    // for element nodes only
-    IsTyped           =   0x80,    // for text nodes only
-    HaveListValue     =   0x100,   // for text and attribute nodes only
+    NodeKindMask        =   0x7,
+    IsId                =   0x8,
+    IsIdRefs            =   0x10,
+    HaveTypedValue      =   0x20,    // for element nodes only
+    HaveEmptyValue      =   0x40,    // for element nodes only
+    IsTyped             =   0x80,    // for text nodes only
+    HaveListValue       =   0x100,   // for text and attribute nodes only
 
-    HaveLocalBindings =   0x200,   // for element nodes only
-    HaveBaseUri       =   0x400,   // for element nodes only
-    IsBaseUri         =   0x800,   // for attribute nodes only
-    IsHidden          =   0x1000,  // for attribute nodes only
-    IsInSubstGroup    =   0x2000,  // for element nodes only
+    HaveLocalBindings   =   0x200,   // for element nodes only
+    HaveBaseUri         =   0x400,   // for element nodes only
+    IsBaseUri           =   0x800,   // for attribute nodes only
+    IsHidden            =   0x1000,  // for attribute nodes only
+    IsInSubstGroup      =   0x2000,  // for element nodes only
 
     // For element nodes only. The flag is set for a node N if there is another
     // node M in its subtree such that N and M have the same name.
-    IsRecursive       =   0x4000
+    IsRecursive         =   0x4000,
 
 #ifndef EMBEDED_TYPE
-    ,
     // For element and attribute nodes only. The flag is set if the node has
     // a type other than untyped (for elements) or untypedAtomic (for attributes)
-    HaveType  =   0x8000
+    HaveType            =   0x8000,
 #endif
+
+    HaveReference       = 0x10000
   };
 
 protected:
@@ -495,6 +496,10 @@
 
   void setFlags(uint32_t flags) { theFlags = flags; }
 
+  bool haveReference() const         { return (theFlags & HaveReference) != 0; }
+  void setHaveReference()            { theFlags |= HaveReference; }
+  void resetHaveReference()          { theFlags &= ~HaveReference; }
+
 #ifndef ZORBA_NO_FULL_TEXT
   FTTokenIterator_t getTokens( TokenizerProvider const&, Tokenizer::Numbers&,
                                locale::iso639_1::type, bool = false ) const;

=== modified file 'src/store/naive/simple_index_value.cpp'
--- src/store/naive/simple_index_value.cpp	2011-10-03 08:49:55 +0000
+++ src/store/naive/simple_index_value.cpp	2011-10-06 10:15:01 +0000
@@ -147,7 +147,7 @@
 ********************************************************************************/
 ulong ValueHashIndex::size() const
 {
-  return theMap.object_count();
+  return theMap.size();
 }
 
 

=== modified file 'src/store/naive/simple_store.cpp'
--- src/store/naive/simple_store.cpp	2011-10-03 08:49:55 +0000
+++ src/store/naive/simple_store.cpp	2011-10-06 10:15:01 +0000
@@ -57,6 +57,8 @@
 #include "store/naive/pul_primitive_factory.h"
 
 #include "util/cxx_util.h"
+#include "util/uuid/uuid.h"
+#include "zorbautils/string_util.h"
 
 #ifndef ZORBA_NO_FULL_TEXT
 #include "runtime/full_text/default_tokenizer.h"
@@ -104,7 +106,8 @@
   theIndices(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
   theICs(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
   theHashMaps(0, NULL, CollectionSet::DEFAULT_COLLECTION_MAP_SIZE, true),
-  theTraceLevel(0)
+  theTraceLevel(0),
+  theNodeToReferencesMap(128, true)
 #ifndef ZORBA_NO_FULL_TEXT
   , theStemmerProvider( nullptr )
   , theTokenizerProvider( nullptr )
@@ -334,6 +337,32 @@
       theNodeFactory = NULL;
     }
 
+    if (theNodeToReferencesMap.size() > 0)
+    {
+      NodeRefMap::iterator iter = theNodeToReferencesMap.begin();
+      NodeRefMap::iterator end = theNodeToReferencesMap.end();
+      for (; iter != end; ++iter)
+      {
+        std::cerr << "Reference: " << (*iter).second
+                  << "is still in the nodes to references map" << std::endl;
+      }
+      ZORBA_FATAL(0, theNodeToReferencesMap.size() + 
+                     " node references still in the nodes to references map");
+    }
+
+    if (theReferencesToNodeMap.size() > 0)
+    {
+      RefNodeMap::iterator iter = theReferencesToNodeMap.begin();
+      RefNodeMap::iterator end = theReferencesToNodeMap.end();
+      for (; iter != end; ++iter)
+      {
+        std::cerr << "Reference: " << (*iter).first 
+                  << "is still in the references to nodes map" << std::endl;
+      }
+      ZORBA_FATAL(0, theReferencesToNodeMap.size() +
+                     " node references still in the references to nodes map");
+    }
+
     // do cleanup of the libxml2 library
     // however, after that, a user will have to call
     // LIBXML_TEST_VERSION if he wants to use libxml2
@@ -1313,360 +1342,200 @@
 }
 
 
-/*******************************************************************************
-  Computes the URI for the given node.
-********************************************************************************/
-bool SimpleStore::getReference(store::Item_t& result, const store::Item* node)
-{
-  std::ostringstream stream;
-
-  const OrdPathNode* n = static_cast<const OrdPathNode*>(node);
-  stream << "zorba:"
-         << n->getCollectionId() << "."
-         << n->getTreeId() << "."
-         << n->getTree()->getPosition() + 1;
-
-#ifdef TEXT_ORDPATH
-
-  if (n->getNodeKind() == store::StoreConsts::attributeNode)
-  {
-    stream <<  ".a."
-  }
-  else
-  {
-    stream <<  ".c."
-  }
-  stream << n->getOrdPath().serialize();
-
-#else
-
-  if (n->getNodeKind() == store::StoreConsts::attributeNode)
-  {
-    stream << ".a."
-           << static_cast<const OrdPathNode*>(n)->getOrdPath().serialize();
-  }
-  else if (n->getNodeKind() == store::StoreConsts::textNode)
-  {
-    stream << ".a."
-           << static_cast<const OrdPathNode*>(n->getParent())->getOrdPath().serialize();
-  }
-  else
-  {
-    stream << ".c."
-           << static_cast<const OrdPathNode*>(n)->getOrdPath().serialize();
-  }
-#endif
-
-  zstring str(stream.str());
-
-  return theItemFactory->createAnyURI(result, str);
-}
-
-
-/*******************************************************************************
-  Returns Item which is identified by a reference
-
-  @param uri Has to be an xs:URI item
-  @returns referenced item if it exists, otherwise NULL
-********************************************************************************/
-bool SimpleStore::getNodeByReference(store::Item_t& result, const store::Item* uri)
-{
-  const zstring& str = uri->getString();
-
-  ulong prefixlen = (ulong)strlen("zorba:");
-
-  if (strncmp(str.c_str(), "zorba:", prefixlen))
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  const char* start;
-  long tmp = 0;
-
-  //
-  // Decode collection id
-  //
-  start = str.c_str() + prefixlen;
-  char* next = const_cast<char*>(start);
-
-  tmp = strtol(start, &next, 10);
-
-  if (tmp < 0 || tmp == LONG_MAX)
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  start = next;
-
-  if (*start != '.')
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  ++start;
-
-  ulong collectionId = (ulong)tmp;
-
-  //
-  // Decode tree id
-  //
-  tmp = strtol(start, &next, 10);
-
-  if (tmp <= 0 || tmp == LONG_MAX)
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  start = next;
-
-  if (*start != '.')
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  ++start;
-
-  ulong treeId = (ulong)tmp;
-
-  //
-  // Decode tree position within collection
-  //
-  tmp = strtol(start, &next, 10);
-
-  if (tmp <= 0 || tmp == LONG_MAX)
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  start = next;
-
-  if (*start != '.')
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  ++start;
-
-  ulong treePos = (ulong)tmp;
-
-  //
-  // Check if the uri specifies attribute node or not
-  //
-  bool attributeNode;
-
-  if (*start == 'a')
-    attributeNode = true;
-  else if (*start == 'c')
-    attributeNode = false;
-  else
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  ++start;
-  if (*start != '.')
-    throw ZORBA_EXCEPTION(
-      zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS( str )
-    );
-
-  ++start;
-
-  //
-  // Search for the tree
-  //
-  XmlNode* rootNode = NULL;
-
-  if (collectionId == 0)
-  {
-    DocumentSet::iterator it = theDocuments.begin();
-    DocumentSet::iterator end = theDocuments.end();
-
-    for (; it != end; ++it)
-    {
-      rootNode = (*it).second.getp();
-
-      if (rootNode->getTreeId() == treeId)
-        break;
-    }
-
-    if (it == end)
-      rootNode = NULL;
-  }
-  else
-  {
-    // Look for the collection
-    SimpleCollection* collection;
-
-    CollectionIterator_t lIter = theCollections->collections();
-    lIter->open();
-
-    store::Collection_t lCollection;
-    bool lFound = false;
-
-    // search the collection
-    while (lIter->next(lCollection))
-    {
-      collection = static_cast<SimpleCollection*>(lCollection.getp());
-
-      if (collection->getId() == collectionId) {
-        lFound = true;
-        break;
-      }
-    }
-
-    if (!lFound)
-    {
-      lIter = theCollections->collections(true);
-      lIter->open();
-
-      // search the collection
-      while (lIter->next(lCollection))
-      {
-        collection = static_cast<SimpleCollection*>(lCollection.getp());
-
-        if (collection->getId() == collectionId) {
-          lFound = true;
-          break;
-        }
-      }
-    }
-
-    // If collection found, look for the tree
-    if (lFound)
-    {
-      store::Item_t rootItem = collection->nodeAt(treePos);
-
-      rootNode = BASE_NODE(rootItem);
-
-      if (rootNode == NULL || rootNode->getTreeId() != treeId)
-      {
-        store::Iterator_t treeIter = collection->getIterator();
-
-        treeIter->open();
-
-        while (treeIter->next(rootItem))
-        {
-          rootNode = BASE_NODE(rootItem);
-          if (rootNode->getTreeId() == treeId)
-            break;
-        }
-
-        treeIter->close();
-
-        rootNode = BASE_NODE(rootItem);
-      }
-    }
-  }
-
-  if (rootNode == NULL)
-  {
-    result = NULL;
-    return false;
-  }
-
-  //
-  // Search for node in the tree
-  //
-
-  OrdPath op((unsigned char*)start, (ulong)strlen(start));
-
-#ifdef TEXT_ORDPATH
-  if (static_cast<OrdPathNode*>(rootNode)->getOrdPath() == op)
-  {
-    result = rootNode;
-    return true;
-  }
-#else
-  if (rootNode->getNodeKind() == store::StoreConsts::textNode)
-  {
-    result = NULL;
-    return false;
-  }
-  else if (static_cast<OrdPathNode*>(rootNode)->getOrdPath() == op)
-  {
-    result = rootNode;
-    return true;
-  }
-#endif
-
-  XmlNode* parent = rootNode;
-
-  while (1)
-  {
-    ulong i;
-
-    if (parent->getNodeKind() != store::StoreConsts::documentNode &&
-        parent->getNodeKind() != store::StoreConsts::elementNode)
-    {
-      result = NULL;
-      return false;
-    }
-
-    if (attributeNode && parent->getNodeKind() == store::StoreConsts::elementNode)
-    {
-      ElementNode* elemParent = reinterpret_cast<ElementNode*>(parent);
-
-      ulong numAttrs = elemParent->numAttrs();
-      for (i = 0; i < numAttrs; i++)
-      {
-        AttributeNode* child = elemParent->getAttr(i);
-
-        OrdPath::RelativePosition pos =  child->getOrdPath().getRelativePosition(op);
-
-        if (pos == OrdPath::SELF)
-        {
-          result = child;
-          return true;
-        }
-        else if (pos != OrdPath::FOLLOWING)
-        {
-          result = NULL;
-          return false;
-        }
-      }
-    }
-
-    InternalNode* parent2 = reinterpret_cast<InternalNode*>(parent);
-
-    ulong numChildren = parent2->numChildren();
-    for (i = 0; i < numChildren; i++)
-    {
-#ifdef TEXT_ORDPATH
-      OrdPathNode* child = static_cast<OrdPathNode*>(parent2->getChild(i));
-#else
-      XmlNode* c = parent2->getChild(i);
-
-      if (c->getNodeKind() == store::StoreConsts::textNode)
-        continue;
-
-      OrdPathNode* child = static_cast<OrdPathNode*>(c);
-#endif
-
-      OrdPath::RelativePosition pos =  child->getOrdPath().getRelativePosition(op);
-
-      if (pos == OrdPath::SELF)
-      {
-        result = child;
-        return true;
-      }
-      else if (pos == OrdPath::DESCENDANT)
-      {
-        parent = child;
-        break;
-      }
-      else if (pos != OrdPath::FOLLOWING)
-      {
-        result = NULL;
-        return false;
-      }
-    }
-
-    if (i == numChildren)
-    {
-      result = NULL;
-      return false;
-    }
-  }
+/* ------------------------ Node References Management ---------------------------*/
+
+
+/*******************************************************************************
+ Computes the reference of the given node.
+ 
+ @param node XDM node
+ @return the identifier as an item of type xs:anyURI
+********************************************************************************/
+bool SimpleStore::getReference(store::Item_t& result, store::Item* node)
+{
+  XmlNode* xmlNode = static_cast<XmlNode*>(node);
+
+  if (xmlNode->haveReference())
+  {
+    NodeRefMap::iterator resIt = theNodeToReferencesMap.find(xmlNode);
+
+    ZORBA_FATAL(resIt != theNodeToReferencesMap.end(),"Node reference cannot be found");
+
+    zstring id = (*resIt).second;
+    return theItemFactory->createAnyURI(result, id);
+  }
+
+  uuid_t uuid;
+  uuid_create(&uuid);
+  zstring uuidStr = uuidToURI(uuid);
+
+  xmlNode->setHaveReference();
+
+  theNodeToReferencesMap.insert(xmlNode, uuidStr);
+  theReferencesToNodeMap[uuidStr] = node;
+
+  return theItemFactory->createAnyURI(result, uuidStr);
+}
+
+
+/*******************************************************************************
+  Returns the already computed reference of the given node. If no reference has
+  already been computed for the given node error ZAPI0030 is raised.
+ 
+  @param result reference as an item of type xs:string
+  @param node XDM node
+  @return whether the reference has been created successfully
+********************************************************************************/
+bool SimpleStore::getCurrentReference(store::Item_t& result, const store::Item* node)
+{
+  const XmlNode* xmlNode = static_cast<const XmlNode*>(node);
+  if (!xmlNode->haveReference())
+    throw ZORBA_EXCEPTION(zerr::ZAPI0030_NO_CURRENT_REFERENCE);
+
+  NodeRefMap::iterator resIt = theNodeToReferencesMap.find(xmlNode);
+
+  ZORBA_FATAL(resIt != theNodeToReferencesMap.end(),"Node reference cannot be found");
+
+  zstring id = (*resIt).second;
+  return theItemFactory->createAnyURI(result, id);
+}
+
+
+/*******************************************************************************
+  Returns the node which is identified by the given reference.
+ 
+  @param reference an xs:anyURI item
+  @result the node identified by the reference, or NULL if no node with the given
+          reference exists
+  @return false if no node with the given reference exists; true otherwise.
+********************************************************************************/
+bool SimpleStore::getNodeByReference(store::Item_t& result, const zstring& reference)
+{
+  if (reference.length() != 45 ||
+      !utf8::match_whole(reference, "urn:uuid:[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"))
+  {
+    throw ZORBA_EXCEPTION(zerr::ZAPI0028_INVALID_NODE_URI, ERROR_PARAMS(reference));
+  }
+
+  RefNodeMap::iterator resIt;
+
+  if ((resIt = theReferencesToNodeMap.find(reference)) != theReferencesToNodeMap.end())
+  {
+    result = resIt->second;
+    return true;
+  }
+
+  result = NULL;
+  return false;
+}
+
+
+/*******************************************************************************
+  Returns whether a reference has already been generated for the given node.
+ 
+  @param item XDM node
+  @return whether a reference has already been generated for the given node.
+********************************************************************************/
+bool SimpleStore::hasReference(const store::Item* node)
+{
+  return static_cast<const XmlNode*>(node)->haveReference();
+}
+
+
+/*******************************************************************************
+  Copies the reference of a source node to a target node. The source
+  node must already have a reference. The target nodes acquires the
+  source reference but it is not registered in the reference-to-node
+  map.If no reference has already been computed for the given node
+  error ZAPI0030 is raised.
+
+  Used in PUL manipulation.
+ 
+  @param source source XDM node
+  @param target target XDM node
+********************************************************************************/
+void SimpleStore::copyReference(const XmlNode* source, XmlNode* target)
+{
+  store::Item_t reference;
+  getCurrentReference(reference, source);
+
+  unregisterNode(target);
+
+  target->setHaveReference();
+
+  zstring refStr;
+  reference->getStringValue2(refStr);
+
+  theNodeToReferencesMap.insert(target, refStr);
+}
+
+
+/*******************************************************************************
+  Sets the reference of a node to a given value.
+  Used in PUL manipulation.
+ 
+  @param node  XDM node
+  @param reference the reference to set
+********************************************************************************/
+void SimpleStore::restoreReference(XmlNode* node, const zstring& reference)
+{
+  unregisterNode(node);
+  theNodeToReferencesMap.insert(std::pair<const XmlNode*, zstring>(node, reference));
+
+  node->setHaveReference();
+}
+
+
+/*******************************************************************************
+  Register the reference of a given node in the references to node map
+  The node must already have an reference, otherwise error ZAPI0030 is raised.
+  The node reference must not be used for any other
+  node in the reference-to-node map, otherwise error ZAPI0029 is raised.
+  Used in PUL manipulation.
+ 
+  @param node XDM node
+********************************************************************************/
+void SimpleStore::registerReference(XmlNode* node)
+{
+  store::Item_t reference;
+  getCurrentReference(reference, node);
+
+  store::Item_t result;
+  if (getNodeByReference(result, reference->getStringValue()))
+  {
+    throw ZORBA_EXCEPTION(zerr::ZAPI0029_REFERENCE_ALREADY_PRESENT,
+    ERROR_PARAMS(reference->getStringValue()));
+  }
+
+  theReferencesToNodeMap[reference->getStringValue()] = node;
+}
+
+
+/*******************************************************************************
+  Removes a node from the reference-to-nodes and nodes-to-references maps.
+ 
+  @param node XDM node
+  @return whether the node was registered or not.
+********************************************************************************/
+bool SimpleStore::unregisterNode(XmlNode* node)
+{
+  if (!node->haveReference())
+    return false;
+
+  NodeRefMap::iterator resIt;
+
+  if ((resIt = theNodeToReferencesMap.find(node)) != theNodeToReferencesMap.end())
+  {
+    zstring value = (*resIt).second;
+    theNodeToReferencesMap.erase(resIt);
+    node->resetHaveReference();
+
+    theReferencesToNodeMap.erase(value);
+
+    return true;
+  }
+  else
+    return false;
 }
 
 

=== modified file 'src/store/naive/simple_store.h'
--- src/store/naive/simple_store.h	2011-09-26 22:49:54 +0000
+++ src/store/naive/simple_store.h	2011-10-06 10:15:01 +0000
@@ -18,6 +18,7 @@
 
 #include "store/naive/shared_types.h"
 #include "store/naive/store_defs.h"
+#include "store/naive/hashmap_nodep.h"
 
 #if (defined (WIN32) || defined (WINCE))
 #include "store/naive/node_items.h"
@@ -66,35 +67,42 @@
 
 
 /*******************************************************************************
-  theSchemaTypeNames   : Maps each enum value from SchemaTypeNames (see
-                         store_defs.h) to its associated QName item.
-
-  theCollectionCounter : Incremented every time a new collection is created. The
-                         current value of the counter is then assigned as the
-                         id of the new collection.
-
-  theNamespacePool     :
-  theQNamePool         :
-
-  theItemFactory       : Factory to create items.
-  theIteratorFactory   : Factory to create iterators.
-  theNodeFactory       : Factory to create node items.
-
-  theDocuments         : A hashmap that for each xml tree that does not belong
-                         to any collection, maps the URI of the tree to the root
-                         node of the tree.
-  theCollections       : Container which contains the collections of the store.
-                         It includes a map that maps the qname of each collection
-                         to the collection's container object.
-  theIndices           : A hashmap that for each index, maps the qname of the
-                         index to the index container object.
-  theICs               : A hashmap the for each integrity constraint, maps the
-                         qname of the ic to the ic's container object.
+  theSchemaTypeNames     : Maps each enum value from SchemaTypeNames (see
+                           store_defs.h) to its associated QName item.
+
+  theCollectionCounter   : Incremented every time a new collection is created. The
+                           current value of the counter is then assigned as the
+                           id of the new collection.
+
+  theNamespacePool       :
+  theQNamePool           :
+
+  theItemFactory         : Factory to create items.
+  theIteratorFactory     : Factory to create iterators.
+  theNodeFactory         : Factory to create node items.
+
+  theDocuments           : A hashmap that for each xml tree that does not belong
+                           to any collection, maps the URI of the tree to the root
+                           node of the tree.
+  theCollections         : Container which contains the collections of the store.
+                           It includes a map that maps the qname of each collection
+                           to the collection's container object.
+  theIndices             : A hashmap that for each index, maps the qname of the
+                           index to the index container object.
+  theICs                 : A hashmap the for each integrity constraint, maps the
+                           qname of the ic to the ic's container object.
+  theReferencesToNodeMap : A hashmap that maps node references to the referenced
+                           nodes
+  theNodeToReferencesMap : A hashmap that maps nodes into their references
+
 ********************************************************************************/
 class SimpleStore : public store::Store
 {
   friend class zorba::StoreManager;
 
+  typedef std::map<const zstring, const store::Item*> RefNodeMap;
+  typedef NodePointerHashMap<zstring> NodeRefMap;
+
 public:
   static const char* XS_URI;
   static const char* XML_URI;
@@ -142,25 +150,15 @@
 
   long                          theTraceLevel;
 
+  RefNodeMap                    theReferencesToNodeMap;
+  NodeRefMap                    theNodeToReferencesMap;
+
 #ifndef ZORBA_NO_FULL_TEXT
   internal::StemmerProvider const * theStemmerProvider;
   TokenizerProvider const     * theTokenizerProvider;
 #endif /* ZORBA_NO_FULL_TEXT */
 
 public:
-  // needs to be virtual to allow implementation of additional stores
-  virtual void populateValueIndex(
-      const store::Index_t& index,
-      store::Iterator* sourceIter,
-      ulong numColumns);
-
-  // needs to be virtual to allow implementation of additional stores
-  virtual void populateGeneralIndex(
-      const store::Index_t& index,
-      store::Iterator* sourceIter,
-      ulong numColumns);
-
-public:
   void shutdown(bool soft = true);
 
   store::ItemFactory* getItemFactory() const;
@@ -179,7 +177,9 @@
 
   long getTraceLevel() const { return theTraceLevel; }
 
-  XmlLoader* getXmlLoader(XQueryDiagnostics*, const store::LoadProperties& loadProperties);
+  XmlLoader* getXmlLoader(
+      XQueryDiagnostics*,
+      const store::LoadProperties& loadProperties);
 
   ulong createCollectionId();
 
@@ -204,16 +204,30 @@
   store::Iterator_t listCollectionNames(bool aDynamicCollections = false);
 
   store::Index_t createIndex(
-        const store::Item_t& qname,
-        const store::IndexSpecification& spec,
-        store::Iterator* sourceIter);
-
-  // needs to be virtual to allow implementation of additional stores
-  virtual
-  store::Index_t refreshIndex(
-        const store::Item_t& qname,
-        const store::IndexSpecification& spec,
-        store::Iterator* sourceIter);
+      const store::Item_t& qname,
+      const store::IndexSpecification& spec,
+      store::Iterator* sourceIter);
+  
+  // needs to be virtual to allow implementation of additional stores
+  virtual void populateValueIndex(
+      const store::Index_t& index,
+      store::Iterator* sourceIter,
+      ulong numColumns);
+
+  // needs to be virtual to allow implementation of additional stores
+  virtual void populateGeneralIndex(
+      const store::Index_t& index,
+      store::Iterator* sourceIter,
+      ulong numColumns);
+
+  // needs to be virtual to allow implementation of additional stores
+  virtual store::Index_t refreshIndex(
+      const store::Item_t& qname,
+      const store::IndexSpecification& spec,
+      store::Iterator* sourceIter);
+
+  // needs to be virtual to allow implementation of additional stores
+  virtual const IndexSet& getIndices() const { return theIndices; }
 
   void addIndex(store::Index_t& index);
 
@@ -223,23 +237,20 @@
 
   store::Iterator_t listIndexNames();
 
-  // needs to be virtual to allow implementation of additional stores
-  virtual
-  const IndexSet& getIndices() const { return theIndices; }
-
   store::IC_t activateIC(
-        const store::Item_t& icQName,
-        const store::Item_t& collectionQName,
-        bool& isApplied);
-
+      const store::Item_t& icQName,
+      const store::Item_t& collectionQName,
+      bool& isApplied);
+  
   store::IC_t activateForeignKeyIC(
-        const store::Item_t& icQName,
-        const store::Item_t& fromCollectionQName,
-        const store::Item_t& toCollectionQName,
-        bool& isApplied);
+      const store::Item_t& icQName,
+      const store::Item_t& fromCollectionQName,
+      const store::Item_t& toCollectionQName,
+      bool& isApplied);
 
-  store::IC_t deactivateIC(const store::Item_t& icQName,
-        bool& isApplied);
+  store::IC_t deactivateIC(
+      const store::Item_t& icQName,
+      bool& isApplied);
 
   store::Iterator_t listActiveICNames();
 
@@ -328,9 +339,25 @@
         bool& found,
         bool& unique);
 
-  bool getReference(store::Item_t& result, const store::Item* node);
-
-  bool getNodeByReference(store::Item_t& result, const store::Item* uri);
+  /* ------------------------ Node Reference Management ---------------------------*/
+
+  bool getReference(store::Item_t& result, store::Item* node);
+
+  bool getCurrentReference(store::Item_t& result, const store::Item* node);
+
+  bool hasReference(const store::Item* node);
+
+  bool getNodeByReference(store::Item_t& result, const zstring& reference);
+
+  bool unregisterNode(XmlNode* node);
+
+  void copyReference(const XmlNode* source, XmlNode* target);
+
+  void restoreReference(XmlNode* node, const zstring& reference);
+
+  void registerReference(XmlNode* node);
+
+  /* ------------------------ Node Reference Management ---------------------------*/
 
   store::TempSeq_t createTempSeq(bool lazy);
 

=== modified file 'src/util/uuid/uuid.cpp'
--- src/util/uuid/uuid.cpp	2011-09-02 21:41:55 +0000
+++ src/util/uuid/uuid.cpp	2011-10-06 10:15:01 +0000
@@ -235,6 +235,18 @@
   return lResult;
 }
 
+/* uuidToString -- transform a UUID to a uri*/
+zstring uuidToURI(const uuid_t& u)
+{
+  char lBuffer[200];
+  sprintf(lBuffer, "urn:uuid:%8.8x-%4.4x-%4.4x-%2.2x%2.2x-9300a64ac3cd", u.time_low, u.time_mid,
+          u.time_hi_and_version, u.clock_seq_hi_and_reserved,
+          u.clock_seq_low);
+
+  zstring lResult = lBuffer;
+  return lResult;
+}
+
 /*
 //This appendix lists the name space IDs for some potentially
 //interesting namespaces, as initialized C structures and in the

=== modified file 'src/util/uuid/uuid.h'
--- src/util/uuid/uuid.h	2011-09-02 21:41:55 +0000
+++ src/util/uuid/uuid.h	2011-10-06 10:15:01 +0000
@@ -36,6 +36,9 @@
 /* uuidToString -- transform a UUID to a string */
 zstring uuidToString(const uuid_t& uuid);
 
+/* uuidToURI -- transform a UUID to a URI-formatted string */
+zstring uuidToURI(const uuid_t& uuid);
+
 } // namespace zorba
 #endif /* ZORBA_UTIL_UUID_H */
 /* vim:set et sw=2 ts=2: */

=== modified file 'src/zorbautils/hashmap.h'
--- src/zorbautils/hashmap.h	2011-10-03 08:49:55 +0000
+++ src/zorbautils/hashmap.h	2011-10-06 10:15:01 +0000
@@ -416,14 +416,25 @@
   return (theNumEntries == 0);
 }
 
+
 /*******************************************************************************
 
 ********************************************************************************/
-ulong object_count() const
+ulong size() const
 {
   return theNumEntries;
 }
 
+
+/*******************************************************************************
+
+********************************************************************************/
+size_t capacity() const
+{
+  return theHashTab.size();
+}
+
+
 /*******************************************************************************
 
 ********************************************************************************/
@@ -432,14 +443,6 @@
   return theCompareFunction;
 }
 
-/*******************************************************************************
-
-********************************************************************************/
-size_t capacity() const
-{
-  return theHashTab.size();
-}
-
 
 /*******************************************************************************
 
@@ -566,6 +569,30 @@
 /******************************************************************************
   If the set does not already contain an item I that is "equal" to the given
   item, make a copy of the given item and its associated value and place the
+  new (item, value) pair in the map; then return true. Otherwise, return false.
+********************************************************************************/
+bool insert(const std::pair<const T, V>& pair)
+{
+  bool found;
+  ulong hval = hash(pair.first);
+
+  SYNC_CODE(AutoMutex lock(theMutexp);)
+
+  HASHENTRY<T, V>* entry = hashInsert(pair.first, hval, found);
+
+  if (!found)
+  {
+    entry->theItem = pair.first;
+    entry->theValue = pair.second;
+  }
+
+  return !found;
+}
+
+
+/******************************************************************************
+  If the set does not already contain an item I that is "equal" to the given
+  item, make a copy of the given item and its associated value and place the
   new (item, value) pair in the map; then return true. Otherwise, return false,
   as well as a copy of the value associated with the found item I.
 ********************************************************************************/

=== added file 'test/rbkt/ExpQueryResults/zorba/paths/ref1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/paths/ref1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/paths/ref1.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,387 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<people>
+<person id="person0">
+<name>Huei Demke</name>
+<emailaddress>mailto:Demke@xxxxx</emailaddress>
+<address>
+<street>95 Grinter St</street>
+<city>Macon</city>
+<country>United States</country>
+<zipcode>32</zipcode>
+</address>
+<creditcard>8182 1228 4493 3873</creditcard>
+<profile income="55386.86">
+<education>High School</education>
+<gender>male</gender>
+<business>No</business>
+<age>37</age>
+</profile>
+</person>
+<person id="person1">
+<name>Daishiro Juric</name>
+<emailaddress>mailto:Juric@xxxxxxxxxxxxxx</emailaddress>
+<phone>+0 (692) 53964736</phone>
+<address>
+<street>5 Pinet St</street>
+<city>Athens</city>
+<country>United States</country>
+<province>Vermont</province>
+<zipcode>13</zipcode>
+</address>
+<homepage>http://www.rwth-aachen.de/~Juric</homepage>
+<creditcard>7833 6950 5399 8913</creditcard>
+<watches>
+<watch open_auction="open_auction2"/>
+<watch open_auction="open_auction4"/>
+<watch open_auction="open_auction5"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction9"/>
+<watch open_auction="open_auction0"/>
+</watches>
+</person>
+<person id="person2">
+<name>Kawon Unni</name>
+<emailaddress>mailto:Unni@xxxxxxxx</emailaddress>
+<phone>+0 (866) 58076283</phone>
+<watches>
+<watch open_auction="open_auction0"/>
+<watch open_auction="open_auction7"/>
+<watch open_auction="open_auction2"/>
+<watch open_auction="open_auction4"/>
+</watches>
+</person>
+<person id="person3">
+<name>Ewing Andrade</name>
+<emailaddress>mailto:Andrade@xxxxxxx</emailaddress>
+<profile income="41889.41">
+<interest category="category0"/>
+<interest category="category0"/>
+<education>Graduate School</education>
+<gender>female</gender>
+<business>Yes</business>
+<age>18</age>
+</profile>
+<watches>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction10"/>
+<watch open_auction="open_auction2"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction5"/>
+</watches>
+</person>
+<person id="person4">
+<name>Jamaludin Kleiser</name>
+<emailaddress>mailto:Kleiser@xxxxxx</emailaddress>
+<phone>+0 (400) 25499686</phone>
+<homepage>http://www.edu.hk/~Kleiser</homepage>
+<profile income="9876.00">
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<education>High School</education>
+<business>No</business>
+<age>34</age>
+</profile>
+</person>
+<person id="person5">
+<name>Eliana Ruemmler</name>
+<emailaddress>mailto:Ruemmler@xxxxxxxx</emailaddress>
+<phone>+0 (361) 10427629</phone>
+<homepage>http://www.forth.gr/~Ruemmler</homepage>
+<watches>
+</watches>
+</person>
+<person id="person6">
+<name>Bassem Nagasaki</name>
+<emailaddress>mailto:Nagasaki@xxxxxxxxxxxxx</emailaddress>
+<phone>+0 (182) 62129440</phone>
+<homepage>http://www.panasonic.com/~Nagasaki</homepage>
+<creditcard>6012 3708 3300 9328</creditcard>
+</person>
+<person id="person7">
+<name>Mehrdad McCay</name>
+<emailaddress>mailto:McCay@xxxxxxx</emailaddress>
+<address>
+<street>40 Kipper St</street>
+<city>Lyon</city>
+<country>United States</country>
+<zipcode>33</zipcode>
+</address>
+<homepage>http://www.acm.org/~McCay</homepage>
+<watches>
+<watch open_auction="open_auction10"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction7"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction10"/>
+</watches>
+</person>
+<person id="person8">
+<name>Bassem Manderick</name>
+<emailaddress>mailto:Manderick@xxxxxxxx</emailaddress>
+<phone>+0 (18) 14026838</phone>
+<address>
+<street>45 Ratnaker St</street>
+<city>Zihuatenejo</city>
+<country>United States</country>
+<province>Illinois</province>
+<zipcode>4</zipcode>
+</address>
+<creditcard>8940 7694 6616 2527</creditcard>
+<watches>
+<watch open_auction="open_auction2"/>
+<watch open_auction="open_auction7"/>
+<watch open_auction="open_auction8"/>
+<watch open_auction="open_auction8"/>
+<watch open_auction="open_auction2"/>
+</watches>
+</person>
+<person id="person9">
+<name>Jarkko Nozawa</name>
+<emailaddress>mailto:Nozawa@xxxxxxxxxxxx</emailaddress>
+<phone>+0 (835) 5433372</phone>
+<homepage>http://www.concordia.ca/~Nozawa</homepage>
+<creditcard>2447 4672 2532 3021</creditcard>
+<profile income="57878.50">
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<business>No</business>
+<age>33</age>
+</profile>
+</person>
+<person id="person10">
+<name>Masanao Marsiglia</name>
+<emailaddress>mailto:Marsiglia@xxxxxx</emailaddress>
+<address>
+<street>22 Caticha St</street>
+<city>Phoenix</city>
+<country>United States</country>
+<province>Alaska</province>
+<zipcode>31</zipcode>
+</address>
+<creditcard>8543 4364 4394 3142</creditcard>
+<profile income="44300.88">
+<interest category="category0"/>
+<interest category="category0"/>
+<education>Other</education>
+<gender>female</gender>
+<business>Yes</business>
+<age>48</age>
+</profile>
+<watches>
+<watch open_auction="open_auction0"/>
+<watch open_auction="open_auction9"/>
+</watches>
+</person>
+<person id="person11">
+<name>Saul Schaap</name>
+<emailaddress>mailto:Schaap@xxxxxxxx</emailaddress>
+<phone>+0 (255) 85051213</phone>
+<address>
+<street>11 Gumm St</street>
+<city>Cody</city>
+<country>United States</country>
+<province>Montana</province>
+<zipcode>28</zipcode>
+</address>
+<profile income="33731.14">
+<interest category="category0"/>
+<education>College</education>
+<business>Yes</business>
+<age>23</age>
+</profile>
+<watches>
+<watch open_auction="open_auction3"/>
+<watch open_auction="open_auction7"/>
+<watch open_auction="open_auction0"/>
+<watch open_auction="open_auction1"/>
+<watch open_auction="open_auction8"/>
+<watch open_auction="open_auction0"/>
+<watch open_auction="open_auction9"/>
+</watches>
+</person>
+<person id="person12">
+<name>Kishor Monkewich</name>
+<emailaddress>mailto:Monkewich@xxxxxxxx</emailaddress>
+<phone>+0 (254) 26597439</phone>
+<address>
+<street>6 Thiria St</street>
+<city>Denver</city>
+<country>United States</country>
+<province>Mississipi</province>
+<zipcode>20</zipcode>
+</address>
+<homepage>http://www.llnl.gov/~Monkewich</homepage>
+<creditcard>7036 1307 7693 1072</creditcard>
+<profile income="43552.04">
+<interest category="category0"/>
+<gender>female</gender>
+<business>Yes</business>
+</profile>
+</person>
+<person id="person13">
+<name>Martti Halgason</name>
+<emailaddress>mailto:Halgason@xxxxxxxxxxxxx</emailaddress>
+<phone>+0 (778) 41220156</phone>
+<profile income="41407.27">
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<gender>female</gender>
+<business>Yes</business>
+<age>20</age>
+</profile>
+<watches>
+<watch open_auction="open_auction7"/>
+</watches>
+</person>
+<person id="person14">
+<name>Laurian Grass</name>
+<emailaddress>mailto:Grass@xxxxxxxx</emailaddress>
+<phone>+0 (486) 33977729</phone>
+<address>
+<street>44 Wergeland St</street>
+<city>Mobile</city>
+<country>United States</country>
+<zipcode>29</zipcode>
+</address>
+<creditcard>1021 8216 1485 5908</creditcard>
+<profile income="53231.89">
+<interest category="category0"/>
+<gender>male</gender>
+<business>Yes</business>
+<age>28</age>
+</profile>
+</person>
+<person id="person15">
+<name>Shooichi Oerlemans</name>
+<emailaddress>mailto:Oerlemans@xxxxx</emailaddress>
+<address>
+<street>7 Rein St</street>
+<city>Alexandria</city>
+<country>Cook Islands</country>
+<zipcode>13</zipcode>
+</address>
+<creditcard>1796 7353 7134 5098</creditcard>
+<watches>
+<watch open_auction="open_auction9"/>
+<watch open_auction="open_auction1"/>
+<watch open_auction="open_auction2"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction8"/>
+<watch open_auction="open_auction8"/>
+</watches>
+</person>
+<person id="person16">
+<name>Uzi Atrawala</name>
+<emailaddress>mailto:Atrawala@xxxxxxxx</emailaddress>
+<phone>+49 (161) 95788409</phone>
+<address>
+<street>77 Coyle St</street>
+<city>Great</city>
+<country>United States</country>
+<province>Oklahoma</province>
+<zipcode>14</zipcode>
+</address>
+<profile income="26302.86">
+<interest category="category0"/>
+<interest category="category0"/>
+<interest category="category0"/>
+<gender>male</gender>
+<business>Yes</business>
+</profile>
+</person>
+<person id="person17">
+<name>Aloys Singleton</name>
+<emailaddress>mailto:Singleton@xxxxxxxxxxxx</emailaddress>
+<phone>+0 (735) 97531072</phone>
+</person>
+<person id="person18">
+<name>Maha DuBourdieux</name>
+<emailaddress>mailto:DuBourdieux@xxxxxxxxxxx</emailaddress>
+<phone>+0 (43) 57060411</phone>
+<homepage>http://www.clustra.com/~DuBourdieux</homepage>
+<profile income="32624.17">
+<interest category="category0"/>
+<business>Yes</business>
+</profile>
+<watches>
+</watches>
+</person>
+<person id="person19">
+<name>Masaski Carrere</name>
+<emailaddress>mailto:Carrere@xxxxxx</emailaddress>
+<phone>+0 (155) 68703448</phone>
+<address>
+<street>51 Bedard St</street>
+<city>Copenhagen</city>
+<country>United States</country>
+<zipcode>29</zipcode>
+</address>
+<homepage>http://www.lri.fr/~Carrere</homepage>
+<watches>
+<watch open_auction="open_auction8"/>
+</watches>
+</person>
+<person id="person20">
+<name>Nestoras Gausemeier</name>
+<emailaddress>mailto:Gausemeier@xxxxxxxxxxx</emailaddress>
+<phone>+0 (864) 72833728</phone>
+<address>
+<street>80 Melter St</street>
+<city>Ciudad</city>
+<country>Greenland</country>
+<zipcode>23</zipcode>
+</address>
+<creditcard>4586 2519 6227 6395</creditcard>
+</person>
+<person id="person21">
+<name>Yechezkel Calmet</name>
+<emailaddress>mailto:Calmet@xxxxxxxx</emailaddress>
+<watches>
+<watch open_auction="open_auction3"/>
+<watch open_auction="open_auction9"/>
+<watch open_auction="open_auction0"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction2"/>
+</watches>
+</person>
+<person id="person22">
+<name>Slavian Usery</name>
+<emailaddress>mailto:Usery@xxxxxxxxxxx</emailaddress>
+<creditcard>7501 3122 6462 7866</creditcard>
+<watches>
+</watches>
+</person>
+<person id="person23">
+<name>Piere Schiex</name>
+<emailaddress>mailto:Schiex@xxxxxx</emailaddress>
+<homepage>http://www.sfu.ca/~Schiex</homepage>
+<creditcard>1536 3643 2092 5012</creditcard>
+<watches>
+<watch open_auction="open_auction6"/>
+<watch open_auction="open_auction4"/>
+</watches>
+</person>
+<person id="person24">
+<name>Shaoyun Morreau</name>
+<emailaddress>mailto:Morreau@xxxxxxxx</emailaddress>
+<phone>+83 (890) 82752371</phone>
+<creditcard>6926 3703 6920 9765</creditcard>
+</person>
+</people>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/reference/reference_1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_1.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_1.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<result><before>45</before><after>45</after><stable>true</stable></result>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/reference/reference_2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_2.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<elem>elem</elem><attr attr="attr"/><?pi pi?><!--comment-->document
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/reference/reference_3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_3.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_3.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<result><out-of-module-global><root>reference.xqlib</root></out-of-module-global><put-doc><root>doc</root></put-doc><in-scope><root>global</root></in-scope><temporary-variable-out-of-scope/><temporary-variable-in-scope><root>1</root><root>2</root><root>3</root></temporary-variable-in-scope><temporary-variable-in-scope><root>temp</root></temporary-variable-in-scope><in-map><a>1</a></in-map></result>
\ No newline at end of file

=== added file 'test/rbkt/ExpQueryResults/zorba/reference/reference_4.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_4.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_4.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,1 @@
+<?xml version="1.0" encoding="UTF-8"?>

=== added file 'test/rbkt/ExpQueryResults/zorba/reference/reference_5.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_5.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_5.xml.res	2011-10-06 10:15:01 +0000
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<result><temporary-variable-in-scope><root>temp</root></temporary-variable-in-scope><temporary-variable-in-scope><root>temp</root></temporary-variable-in-scope><temporary-variable-in-scope><root>temp</root><root>temp</root><root>temp</root></temporary-variable-in-scope><temporary-variable-in-scope><root>temp</root></temporary-variable-in-scope></result>

=== modified file 'test/rbkt/ExpQueryResults/zorba/reference/reference_coll_1.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_coll_1.xml.res	2011-06-24 19:58:33 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_coll_1.xml.res	2011-10-06 10:15:01 +0000
@@ -1,1 +1,2 @@
-<b><z/></b>
+<?xml version="1.0" encoding="UTF-8"?>
+<b><z/></b>
\ No newline at end of file

=== modified file 'test/rbkt/ExpQueryResults/zorba/reference/reference_coll_2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_coll_2.xml.res	2011-06-24 19:58:33 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_coll_2.xml.res	2011-10-06 10:15:01 +0000
@@ -1,1 +1,2 @@
-<z/>
+<?xml version="1.0" encoding="UTF-8"?>
+<z/>
\ No newline at end of file

=== modified file 'test/rbkt/ExpQueryResults/zorba/reference/reference_coll_3.xml.res'
--- test/rbkt/ExpQueryResults/zorba/reference/reference_coll_3.xml.res	2011-06-24 19:58:33 +0000
+++ test/rbkt/ExpQueryResults/zorba/reference/reference_coll_3.xml.res	2011-10-06 10:15:01 +0000
@@ -1,1 +1,2 @@
-e
+<?xml version="1.0" encoding="UTF-8"?>
+e
\ No newline at end of file

=== modified file 'test/rbkt/Queries/CMakeLists.txt'
--- test/rbkt/Queries/CMakeLists.txt	2011-09-12 23:22:24 +0000
+++ test/rbkt/Queries/CMakeLists.txt	2011-10-06 10:15:01 +0000
@@ -269,4 +269,6 @@
 EXPECTED_FAILURE(test/rbkt/zorba/http-client/put/put3_binary_element 3391756)
 EXPECTED_FAILURE(test/rbkt/zorba/http-client/post/post3_binary_element 3391756)
 
+EXPECTED_FAILURE(test/rbkt/zorba/reference/reference_5 868640)
+
 # vim:set et sw=2 ts=2:

=== modified file 'test/rbkt/Queries/zorba/paths/ref1.spec'
--- test/rbkt/Queries/zorba/paths/ref1.spec	2011-08-04 02:39:56 +0000
+++ test/rbkt/Queries/zorba/paths/ref1.spec	2011-10-06 10:15:01 +0000
@@ -1,4 +1,3 @@
 Args: 
 -x 
 input-context:=xs:string($RBKT_SRC_DIR/Queries/zorba/xmark/auction.xml)
-Error: http://www.zorba-xquery.com/errors:ZAPI0080

=== removed file 'test/rbkt/Queries/zorba/reference/error.spec'
--- test/rbkt/Queries/zorba/reference/error.spec	2011-06-09 12:58:16 +0000
+++ test/rbkt/Queries/zorba/reference/error.spec	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-Args: 
--x 
-input-context:=xs:string($RBKT_SRC_DIR/Queries/zorba/reference/books.xml)
-Error: http://www.w3.org/2005/xqt-errors:XPST0017

=== removed file 'test/rbkt/Queries/zorba/reference/error.xq'
--- test/rbkt/Queries/zorba/reference/error.xq	2010-11-09 22:35:09 +0000
+++ test/rbkt/Queries/zorba/reference/error.xq	1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
-declare namespace ref = "http://www.zorba-xquery.com/modules/node-reference";;
-
-declare variable $input-context external;
-
-let $book := doc($input-context)/bib/book[1]
-return ref:node-reference($book)

=== added file 'test/rbkt/Queries/zorba/reference/reference.xqlib'
--- test/rbkt/Queries/zorba/reference/reference.xqlib	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference.xqlib	2011-10-06 10:15:01 +0000
@@ -0,0 +1,3 @@
+module namespace idd= "http://www.zorba-xquery.com/reference";;
+
+declare variable $idd:node:=<root>reference.xqlib</root>;

=== added file 'test/rbkt/Queries/zorba/reference/reference_1.xq'
--- test/rbkt/Queries/zorba/reference/reference_1.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_1.xq	2011-10-06 10:15:01 +0000
@@ -0,0 +1,13 @@
+import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
+
+variable $node:=<root><child>text</child></root>;
+
+variable $before-currentid:=id:node-reference($node);
+variable $got:=id:node-reference($node);
+variable $after:=id:node-reference($node);
+
+<result>
+<before>{fn:string-length($before-currentid)}</before>
+<after>{fn:string-length($got)}</after>
+<stable>{$got eq $after}</stable>
+</result>
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/reference/reference_2.xq'
--- test/rbkt/Queries/zorba/reference/reference_2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_2.xq	2011-10-06 10:15:01 +0000
@@ -0,0 +1,14 @@
+import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
+
+variable $el:=element {"elem"}{"elem"};
+variable $attr:=attribute{"attr"}{"attr"};
+variable $pi:=processing-instruction {"pi"}{"pi"};
+variable $comm:=comment {"comment"};
+variable $doc:=document {"document"};
+
+
+id:node-by-reference(id:node-reference($el)),
+element {"attr"}{id:node-by-reference(id:node-reference($attr))},
+id:node-by-reference(id:node-reference($pi)),
+id:node-by-reference(id:node-reference($comm)),
+id:node-by-reference(id:node-reference($doc))
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/reference/reference_3.xq'
--- test/rbkt/Queries/zorba/reference/reference_3.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_3.xq	2011-10-06 10:15:01 +0000
@@ -0,0 +1,33 @@
+import module namespace idd = "http://www.zorba-xquery.com/reference"; at "reference.xqlib";
+import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
+import module namespace doc = "http://www.zorba-xquery.com/modules/store/dynamic/documents";;
+import module namespace map = "http://www.zorba-xquery.com/modules/store/data-structures/unordered-map";;
+
+variable $node:=<root>global</root>;
+variable $x := <a>1</a>;
+fn:put(<root>doc</root>,"doc");
+
+map:create(xs:QName("local:bar"), xs:QName("xs:integer"));
+map:insert(xs:QName("local:bar"), id:node-reference($x), 1);
+
+
+
+<result>
+<out-of-module-global>{id:node-by-reference(id:node-reference($idd:node))}</out-of-module-global>
+<put-doc>{id:node-by-reference(id:node-reference(doc:document("doc")))}</put-doc>
+<in-scope>{id:node-by-reference(id:node-reference($node))}</in-scope>
+
+<temporary-variable-out-of-scope>{id:node-by-reference(id:node-reference(<root>temp</root>))}</temporary-variable-out-of-scope>
+<temporary-variable-in-scope>{
+for $i in (1 to 3)
+let $temp:=<root>{$i}</root>
+where string($temp) = string($i)   
+let $ref:=id:node-reference($temp)
+return
+id:node-by-reference($ref)
+}</temporary-variable-in-scope>
+<temporary-variable-in-scope>{variable $temp:=<root>temp</root>; id:node-by-reference(id:node-reference($temp))}</temporary-variable-in-scope>
+<in-map>
+{id:node-by-reference(map:get(xs:QName("local:bar"), 1))}
+</in-map>
+</result>
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/reference/reference_4.spec'
--- test/rbkt/Queries/zorba/reference/reference_4.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_4.spec	2011-10-06 10:15:01 +0000
@@ -0,0 +1,1 @@
+Error: http://www.zorba-xquery.com/errors:ZAPI0028

=== added file 'test/rbkt/Queries/zorba/reference/reference_4.xq'
--- test/rbkt/Queries/zorba/reference/reference_4.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_4.xq	2011-10-06 10:15:01 +0000
@@ -0,0 +1,3 @@
+import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
+
+id:node-by-reference(xs:anyURI("this:is-not-a-reference"))
\ No newline at end of file

=== added file 'test/rbkt/Queries/zorba/reference/reference_5.xq'
--- test/rbkt/Queries/zorba/reference/reference_5.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/reference/reference_5.xq	2011-10-06 10:15:01 +0000
@@ -0,0 +1,29 @@
+import module namespace idd = "http://www.zorba-xquery.com/reference"; at "reference.xqlib";
+import module namespace id = "http://www.zorba-xquery.com/modules/node-reference";;
+import module namespace doc = "http://www.zorba-xquery.com/modules/store/dynamic/documents";;
+
+variable $node:=<root>global</root>;
+
+fn:put(<root>doc</root>,"doc");
+
+
+<result>
+<temporary-variable-in-scope>{let $temp:=<root>temp</root> return id:node-by-reference(id:node-reference($temp))}</temporary-variable-in-scope>
+<temporary-variable-in-scope>{
+let $temp:=<root>temp</root> 
+return
+let $ref:=id:node-reference($temp)
+return
+id:node-by-reference($ref)
+}</temporary-variable-in-scope>
+<temporary-variable-in-scope>{
+for $i in (1 to 3)
+let $temp:=<root>temp</root> 
+let $ref:=id:node-reference($temp)
+return
+id:node-by-reference($ref)
+}</temporary-variable-in-scope>
+
+<temporary-variable-in-scope>{let $temp:=<root>temp</root> return id:node-by-reference(id:node-reference($temp))}</temporary-variable-in-scope>
+
+</result>

=== removed file 'test/rbkt/Queries/zorba/reference/reference_doc_example_01.spec'
--- test/rbkt/Queries/zorba/reference/reference_doc_example_01.spec	2011-08-04 02:39:56 +0000
+++ test/rbkt/Queries/zorba/reference/reference_doc_example_01.spec	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-Args: 
--x 
-input-context:=xs:string($RBKT_SRC_DIR/Queries/zorba/reference/books.xml)
-Error: http://www.zorba-xquery.com/errors:ZAPI0080

=== removed file 'test/rbkt/Queries/zorba/reference/reference_doc_example_01.xq'
--- test/rbkt/Queries/zorba/reference/reference_doc_example_01.xq	2011-06-24 19:58:33 +0000
+++ test/rbkt/Queries/zorba/reference/reference_doc_example_01.xq	1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
-import module namespace ref =
-  "http://www.zorba-xquery.com/modules/node-reference";;
-
-declare variable $input-context external;
-
-let $book := doc($input-context)/bib/book[1]
-return ref:node-reference($book)

=== removed file 'test/rbkt/Queries/zorba/reference/reference_doc_example_02.spec'
--- test/rbkt/Queries/zorba/reference/reference_doc_example_02.spec	2011-08-04 02:39:56 +0000
+++ test/rbkt/Queries/zorba/reference/reference_doc_example_02.spec	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-Args: 
--x 
-input-context:=xs:string($RBKT_SRC_DIR/Queries/zorba/reference/books.xml)
-Error: http://www.zorba-xquery.com/errors:ZAPI0080

=== removed file 'test/rbkt/Queries/zorba/reference/reference_doc_example_02.xq'
--- test/rbkt/Queries/zorba/reference/reference_doc_example_02.xq	2011-06-24 19:58:33 +0000
+++ test/rbkt/Queries/zorba/reference/reference_doc_example_02.xq	1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-import module namespace ref =
-  "http://www.zorba-xquery.com/modules/node-reference";;
-
-declare variable $input-context external;
-
-let $book := doc($input-context)/bib/book[1]
-let $bookref := ref:node-reference($book)
-return ref:node-by-reference($bookref)


Follow ups