Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/threads into 
lp:zorba.

Commit message:
fixed memory leak related to function annotations

Requested reviews:
  Markos Zaharioudakis (markos-za)

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

fixed memory leak related to function annotations
-- 
https://code.launchpad.net/~zorba-coders/zorba/threads/+merge/177897
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2013-06-14 23:46:26 +0000
+++ bin/zorbacmd.cpp	2013-07-31 16:13:34 +0000
@@ -272,14 +272,14 @@
 ********************************************************************************/
 bool populateDynamicContext(
     Zorba* zorba,
+    XmlDataManager* xmlMgr,
     zorba::DynamicContext* aDynamicContext,
     const ZorbaCMDProperties& props)
 {
   if ( props.contextItem().size() != 0 ) 
   {
-    XmlDataManager* lXmlMgr = zorba->getXmlDataManager();
     std::ifstream lInStream(props.contextItem().c_str());
-    Item lDoc = lXmlMgr->parseXML(lInStream);
+    Item lDoc = xmlMgr->parseXML(lInStream);
     aDynamicContext->setContextItem(lDoc);
   }
 
@@ -293,9 +293,8 @@
     {
       if ((*lIter).inline_file)
       {
-        XmlDataManager* lXmlMgr = zorba->getXmlDataManager();
         std::ifstream lInStream((*lIter).var_value.c_str());
-        Item lDoc = lXmlMgr->parseXML(lInStream);
+        Item lDoc = xmlMgr->parseXML(lInStream);
         aDynamicContext->setVariable((*lIter).var_name, lDoc);
       }
       else
@@ -642,6 +641,7 @@
 int
 compileAndExecute(
     zorba::Zorba* zorbaInstance,
+    zorba::XmlDataManager* xmlDataMgr,
     const ZorbaCMDProperties& properties,
     zorba::StaticContext_t& staticContext,
     const std::string& qfilepath,
@@ -715,7 +715,8 @@
     lHints.lib_module = true;
   }
 
-  Zorba_SerializerOptions lSerOptions = Zorba_SerializerOptions::SerializerOptionsFromStringParams(properties.getSerializerParameters());
+  Zorba_SerializerOptions lSerOptions = 
+  Zorba_SerializerOptions::SerializerOptionsFromStringParams(properties.getSerializerParameters());
 
   createSerializerOptions(lSerOptions, properties);
 
@@ -831,7 +832,10 @@
         zorba::DynamicContext* lDynamicContext = query->getDynamicContext();
         try
         {
-          if ( ! populateDynamicContext(zorbaInstance, lDynamicContext, properties) )
+          if ( ! populateDynamicContext(zorbaInstance,
+                                        xmlDataMgr,
+                                        lDynamicContext,
+                                        properties) )
           {
             properties.printHelp(std::cout);
             return 21;
@@ -894,11 +898,9 @@
     //
     if (doTiming)
     {
-      XmlDataManager* store = zorbaInstance->getXmlDataManager();
-
       timing.startTimer(TimingInfo::UNLOAD_TIMER, i);
 
-      DocumentManager* docMgr = store->getDocumentManager();
+      DocumentManager* docMgr = xmlDataMgr->getDocumentManager();
       ItemSequence_t docsSeq = docMgr->availableDocuments();
       Iterator_t lIter = docsSeq->getIterator();
       lIter->open();
@@ -1019,6 +1021,8 @@
 
   zorba::Zorba* lZorbaInstance = zorba::Zorba::getInstance(store);
 
+  zorba::XmlDataManager_t xmlDataMgr = lZorbaInstance->createXmlDataManager();
+
 #ifdef DO_AUDIT
   zorba::audit::Provider* lAuditProvider = lZorbaInstance->getAuditProvider();
 
@@ -1240,7 +1244,11 @@
 
         lQuery->compile(*lXQ.get(), lHints);
         zorba::DynamicContext* lDynamicContext = lQuery->getDynamicContext();
-        if (!populateDynamicContext(lZorbaInstance, lDynamicContext, properties)) {
+        if (!populateDynamicContext(lZorbaInstance,
+                                    xmlDataMgr,
+                                    lDynamicContext,
+                                    properties))
+        {
           return 9;
         }
 

=== modified file 'include/zorba/api_shared_types.h'
--- include/zorba/api_shared_types.h	2013-06-12 04:55:14 +0000
+++ include/zorba/api_shared_types.h	2013-07-31 16:13:34 +0000
@@ -61,6 +61,7 @@
 typedef SmartPtr<QueryLocation>   QueryLocation_t;
 typedef SmartPtr<Serializer>      Serializer_t;
 typedef SmartPtr<StaticContext>   StaticContext_t;
+typedef SmartPtr<XmlDataManager>  XmlDataManager_t;
 typedef SmartPtr<TypeIdentifier>  TypeIdentifier_t;
 typedef SmartPtr<XQuery>          XQuery_t;
 

=== modified file 'include/zorba/xmldatamanager.h'
--- include/zorba/xmldatamanager.h	2013-02-07 17:24:36 +0000
+++ include/zorba/xmldatamanager.h	2013-07-31 16:13:34 +0000
@@ -23,224 +23,223 @@
 
 namespace zorba {
 
-  /** \brief Using the XmlDataManager one can manage documents and collections.
-   *
-   * The XmlDataManager is a singleton instance. The Zorba object is reponsible
-   * for maintaining its lifetime. The instance can be accessed by calling
-   * getXmlDataManager() on the Zorba object. It may not be accessed anymore
-   * after Zorba::shutdown() has been called.
-   *
-   * XmlDataManager is a thread-safe class.
+/** \brief Using the XmlDataManager one can manage documents and collections.
+ *
+ * Instances of XmlDataManager are created via the Zorba::createXmlDataManager()
+ * method. All such instances must be destroyed before Zorba::shutdown() is
+ * called.
+ */
+  class ZORBA_DLL_PUBLIC XmlDataManager : public SmartObject
+{
+ public:
+  /**
+   * \brief The ParseOptions class stores various properties that affect
+   *        how a document is parsed. An instance of this class is passed
+   *        as input to the parseXML function.
    */
-  class ZORBA_DLL_PUBLIC XmlDataManager
+  class ParseOptions
   {
+  private:
+    bool              theDtdValidation;
+    bool              theExternalEntityProcessing;
+    
   public:
-    /**
-     * \brief The ParseOptions class stores various properties that affect
-     *        how a document is parsed. An instance of this class is passed
-     *        as input to the parseXML function.
-     */
-    class ParseOptions
-    {
-    private:
-      bool              theDtdValidation;
-      bool              theExternalEntityProcessing;
-
-    public:
-      ParseOptions() :
-        theDtdValidation(false),
-        theExternalEntityProcessing(false)
-      {}
-
-      ~ParseOptions() {}
-
-      /**
-       * Set the property enableDtd, which specifies whether the
-       * document should be validated against its associated DTD (if
-       * any).
-       */
-      void setDtdValidation(bool aEnable)
-      {
-        theDtdValidation = aEnable;
-      }
-
-      /**
-       * Returns true if dtd validation is enabled, false otherwise.
-       */
-      bool isDtdValidationEnabled() const
-      {
-        return theDtdValidation;
-      }
-
-      /**
-       * Set the property to enable or disable processing of XML external entities. 
-       * If the option is enabled, the input must conform to the syntax
-       * _extParsedEnt_ (production [78] in XML 1.0); and since there is no DTD,
-       * the content must include no entity references. The result of the
-       * function call is a sequence of nodes.
-       */
-      void setExternalEntityProcessing(bool aEnable)
-      {
-        theExternalEntityProcessing = aEnable;
-      }
-
-      /**
-       * Returns true if external entity processig is enabled,
-       * false otherwise.
-       */
-      bool isExternalEntityProcessingEnabled() const
-      {
-        return theExternalEntityProcessing;
-      }
-    };
-
-    virtual DocumentManager*
-    getDocumentManager() const = 0;
-
-    /** \brief Returns a CollectionManager responsible for all collections.
-     * 
-     * The collection manager provides a set of functions for managing
-     * collections identified by a QName and their contents.
-     *
-     * Please note that the resulting manager is only responsible for
-     * dynamic collections identified by a QName, i.e. those that are
-     * not declared in the prolog of a module or identified by a URI.
-     *
-     * @return The collection manager responsible for managing
-     *   collections.
-     *
-     */
-    virtual CollectionManager*
-    getCollectionManager() const = 0;
-
-    /** \brief Returns a CollectionManager responsible for collections
-     * identified by a URI.
-     * 
-     * The collection manager provides a set of functions for managing
-     * collections identified by a URI and their contents.
-     *
-     * Please note that the resulting manager is only responsible for
-     * dynamic collections identified by a URI, i.e. those that are
-     * not declared in the prolog of a module or identified by a QName.
-     *
-     * @return The collection manager responsible for managing
-     *   collections.
-     *
-     */
-    virtual CollectionManager*
-    getW3CCollectionManager() const = 0;
-
-    /** \brief Parse an XML document and return an Item.
-     *
-     */
-    virtual Item
-    parseXML(std::istream& aStream) const = 0;
-
-    /** \brief Parse an XML document and return an Item.
-     *
-     * @param aStream the input stream whose content should be parsed
-     * @param aBaseURI the base URI which will be used as the base URI
-     *                 of the document. This serves both as the base URI
-     *                 used by the XML parser to resolve relative entity
-     *                 references within the document, and as the base URI
-     *                 of the document node that is returned.
-     */
-    virtual Item
-    parseXML(std::istream& aStream, const String& aBaseURI) const = 0;
-
-    /** \brief Parse an XML document and return a sequence of nodes.
-     *
-     * This function parses the given input stream and returns the result
-     * as a sequence of nodes. If external entity processing is disabled
-     * the result will be a singleton sequence consisting of one document
-     * node. Otherwise, the result is the sequence of the external entity
-     * nodes.
-     *
-     * @param aStream the input stream whose content should be parsed
-     * @param aOptions @see ParseOptions
-     * @see ParseOptions
-     */
-    virtual ItemSequence_t
-    parseXML(std::istream& aStream, ParseOptions& aOptions) const = 0;
-
-    /** \brief Parse an XML document and return a sequence of nodes.
-     *
-     * This function parses the given input stream and returns the result
-     * as a sequence of nodes. If external entity processing is disabled
-     * the result will be a singleton sequence consisting of one document
-     * node. Otherwise, the result is the sequence of the external entity
-     * nodes.
-     *
-     * @param aStream the input stream whose content should be parsed
-     * @param aBaseURI the base URI which will be used as the base URI
-     *                 of the document. This serves both as the base URI
-     *                 used by the XML parser to resolve relative entity
-     *                 references within the document, and as the base URI
-     *                 of the document node that is returned.
-     * @param aOptions @see ParseOptions
-     * @see ParseOptions
-     */
-    virtual ItemSequence_t
-    parseXML(
-        std::istream& aStream,
-        const String& aBaseURI,
-        ParseOptions& aOptions) const = 0;
-
-    /** \brief Fetches an resource refered to by the given URI.
-     *
-     * @deprecated this function has been replaced by StaticContext::fetch.
-     */
-    virtual Item
-    fetch(const String& aURI) const = 0;
-
-    /** \brief Register a DiagnosticHandler to which errors occuring during the
-     * management of documents and collections are reported.
-     *
-     * If no DiagnosticHandler has been set using this function then
-     * subclasses of the ZorbaException class are thrown to report
-     * errors.
-     *
-     *  @param aDiagnosticHandler DiagnosticHandler to which errors
-     *         are reported. The caller retains ownership over the
-     *         DiagnosticHandler passed as parameter.
-     */
-    virtual void
-    registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler) = 0;
+    ParseOptions()
+      :
+      theDtdValidation(false),
+      theExternalEntityProcessing(false)
+    {
+    }
+
+    ~ParseOptions() {}
+
+    /**
+     * Set the property enableDtd, which specifies whether the
+     * document should be validated against its associated DTD (if
+     * any).
+     */
+    void setDtdValidation(bool aEnable)
+    {
+      theDtdValidation = aEnable;
+    }
+    
+    /**
+     * Returns true if dtd validation is enabled, false otherwise.
+     */
+    bool isDtdValidationEnabled() const
+    {
+      return theDtdValidation;
+    }
+    
+    /**
+     * Set the property to enable or disable processing of XML external entities. 
+     * If the option is enabled, the input must conform to the syntax
+     * _extParsedEnt_ (production [78] in XML 1.0); and since there is no DTD,
+     * the content must include no entity references. The result of the
+     * function call is a sequence of nodes.
+     */
+    void setExternalEntityProcessing(bool aEnable)
+    {
+      theExternalEntityProcessing = aEnable;
+    }
+    
+    /**
+     * Returns true if external entity processig is enabled,
+     * false otherwise.
+     */
+    bool isExternalEntityProcessingEnabled() const
+    {
+      return theExternalEntityProcessing;
+    }
+  };
+
+  virtual DocumentManager*
+  getDocumentManager() const = 0;
+
+  /** \brief Returns a CollectionManager responsible for all collections.
+   * 
+   * The collection manager provides a set of functions for managing
+   * collections identified by a QName and their contents.
+   *
+   * Please note that the resulting manager is only responsible for
+   * dynamic collections identified by a QName, i.e. those that are
+   * not declared in the prolog of a module or identified by a URI.
+   *
+   * @return The collection manager responsible for managing
+   *   collections.
+   *
+   */
+  virtual CollectionManager*
+  getCollectionManager() const = 0;
+
+  /** \brief Returns a CollectionManager responsible for collections
+   * identified by a URI.
+   * 
+   * The collection manager provides a set of functions for managing
+   * collections identified by a URI and their contents.
+   *
+   * Please note that the resulting manager is only responsible for
+   * dynamic collections identified by a URI, i.e. those that are
+   * not declared in the prolog of a module or identified by a QName.
+   *
+   * @return The collection manager responsible for managing
+   *   collections.
+   *
+   */
+  virtual CollectionManager*
+  getW3CCollectionManager() const = 0;
+  
+  /** \brief Parse an XML document and return an Item.
+   *
+   */
+  virtual Item
+  parseXML(std::istream& aStream) const = 0;
+
+  /** \brief Parse an XML document and return an Item.
+   *
+   * @param aStream the input stream whose content should be parsed
+   * @param aBaseURI the base URI which will be used as the base URI
+   *                 of the document. This serves both as the base URI
+   *                 used by the XML parser to resolve relative entity
+   *                 references within the document, and as the base URI
+   *                 of the document node that is returned.
+   */
+  virtual Item
+  parseXML(std::istream& aStream, const String& aBaseURI) const = 0;
+  
+  /** \brief Parse an XML document and return a sequence of nodes.
+   *
+   * This function parses the given input stream and returns the result
+   * as a sequence of nodes. If external entity processing is disabled
+   * the result will be a singleton sequence consisting of one document
+   * node. Otherwise, the result is the sequence of the external entity
+   * nodes.
+   *
+   * @param aStream the input stream whose content should be parsed
+   * @param aOptions @see ParseOptions
+   * @see ParseOptions
+   */
+  virtual ItemSequence_t
+  parseXML(std::istream& aStream, ParseOptions& aOptions) const = 0;
+
+  /** \brief Parse an XML document and return a sequence of nodes.
+   *
+   * This function parses the given input stream and returns the result
+   * as a sequence of nodes. If external entity processing is disabled
+   * the result will be a singleton sequence consisting of one document
+   * node. Otherwise, the result is the sequence of the external entity
+   * nodes.
+   *
+   * @param aStream the input stream whose content should be parsed
+   * @param aBaseURI the base URI which will be used as the base URI
+   *                 of the document. This serves both as the base URI
+   *                 used by the XML parser to resolve relative entity
+   *                 references within the document, and as the base URI
+   *                 of the document node that is returned.
+   * @param aOptions @see ParseOptions
+   * @see ParseOptions
+   */
+  virtual ItemSequence_t
+  parseXML(
+      std::istream& aStream,
+      const String& aBaseURI,
+      ParseOptions& aOptions) const = 0;
+  
+  /** \brief Fetches an resource refered to by the given URI.
+   *
+   * @deprecated this function has been replaced by StaticContext::fetch.
+   */
+  virtual Item
+  fetch(const String& aURI) const = 0;
+
+  /** \brief Register a DiagnosticHandler to which errors occuring during the
+   * management of documents and collections are reported.
+   *
+   * If no DiagnosticHandler has been set using this function then
+   * subclasses of the ZorbaException class are thrown to report
+   * errors.
+   *
+   *  @param aDiagnosticHandler DiagnosticHandler to which errors
+   *         are reported. The caller retains ownership over the
+   *         DiagnosticHandler passed as parameter.
+   */
+  virtual void
+  registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler) = 0;
 
 #ifndef ZORBA_NO_FULL_TEXT
-    /**
-     * Registers a StemmerProvider to use for stemming of text content in order
-     * to perform queries involving full-text.
-     *
-     * If no StemmerProvider has been set using this function, then the default
-     * StemmerProvider will be used.
-     *
-     * @param provider If not NULL, sets the StemmerProvider to use; if NULL,
-     * removes any previously registered StemmerProvider.
-     */
-    virtual void
-    registerStemmerProvider(StemmerProvider const *provider) = 0;
+  /**
+   * Registers a StemmerProvider to use for stemming of text content in order
+   * to perform queries involving full-text.
+   *
+   * If no StemmerProvider has been set using this function, then the default
+   * StemmerProvider will be used.
+   *
+   * @param provider If not NULL, sets the StemmerProvider to use; if NULL,
+   * removes any previously registered StemmerProvider.
+   */
+  virtual void
+  registerStemmerProvider(StemmerProvider const *provider) = 0;
 
-    /**
-     * Registers a TokenizerProvider to use for toknenization of text content
-     * in order to perform queries involving full-text.
-     *
-     * If no TokenizerProvider has been set using this function, then the
-     * default TokenizerProvider will be used.
-     *
-     * @param provider If not NULL, sets the TokenizerProvider to use; if NULL,
-     * removes any previously registered TokenizerProvider.
-     */
-    virtual void
-    registerTokenizerProvider(TokenizerProvider const *provider) = 0;
+  /**
+   * Registers a TokenizerProvider to use for toknenization of text content
+   * in order to perform queries involving full-text.
+   *
+   * If no TokenizerProvider has been set using this function, then the
+   * default TokenizerProvider will be used.
+   *
+   * @param provider If not NULL, sets the TokenizerProvider to use; if NULL,
+   * removes any previously registered TokenizerProvider.
+   */
+  virtual void
+  registerTokenizerProvider(TokenizerProvider const *provider) = 0;
 #endif /* ZORBA_NO_FULL_TEXT */
 
-    protected:
-    /** \brief Destructor
-     */
-    virtual ~XmlDataManager() {}
-
-  }; /* class XmlDataManager */
+ protected:
+  /** \brief Destructor
+   */
+  virtual ~XmlDataManager() {}
+  
+}; /* class XmlDataManager */
 
 } // namespace zorba
 #endif /* ZORBA_XMLDATAMANAGER_API_H */

=== modified file 'include/zorba/zorba.h'
--- include/zorba/zorba.h	2013-02-07 17:24:36 +0000
+++ include/zorba/zorba.h	2013-07-31 16:13:34 +0000
@@ -305,6 +305,13 @@
   virtual StaticContext_t
   createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0) = 0;
 
+  /** \brief Creates a new XmlDataManager object.
+   *
+   * @return XmlDataManager a new XmlDataManager.
+   */
+  virtual XmlDataManager_t
+  createXmlDataManager() = 0;
+
   /** \brief Gets the singleton instance of the ItemFactory.
    *
    * @return ItemFactory the singleton instance of the ItemFactory.
@@ -312,13 +319,6 @@
   virtual ItemFactory*
   getItemFactory() = 0;
 
-  /** \brief Gets the singleton instance of the XmlDataManager object.
-   *
-   * @return XmlDataManager the singleton instance of the XmlDataManager.
-   */
-  virtual XmlDataManager*
-  getXmlDataManager() = 0;
-
   /** \brief Gets the singleton instance of Zorba's audit provider object.
    *
    * @return audit::Provider the singeleton instance of Zorba's audit provider.

=== modified file 'modules/org/expath/ns/file.xq.src/file.cpp'
--- modules/org/expath/ns/file.xq.src/file.cpp	2013-06-13 18:12:45 +0000
+++ modules/org/expath/ns/file.xq.src/file.cpp	2013-07-31 16:13:34 +0000
@@ -77,16 +77,22 @@
 
   fs::type const fs_type = fs::get_type( path );
   if ( !fs_type )
+  {
     try {
       fs::mkdir( path, true );
     }
     catch ( std::exception const &e ) {
       throw raiseFileError( "FOFL9999", e.what(), path );
     }
+  }
   else if ( fs_type != fs::directory )
+  {
     raiseFileError( "FOFL0002", "file already exists", path );
+  }
   else
+  {
     /* directory already exists: do nothing */;
+  }
 
   return ItemSequence_t( new EmptySequence() );
 }

=== modified file 'src/annotations/annotations.cpp'
--- src/annotations/annotations.cpp	2013-07-06 06:59:32 +0000
+++ src/annotations/annotations.cpp	2013-07-31 16:13:34 +0000
@@ -257,8 +257,8 @@
 
 ********************************************************************************/
 AnnotationInternal::AnnotationInternal(
-  const store::Item_t& qname,
-  std::vector<store::Item_t>& literals)
+    const store::Item_t& qname,
+    std::vector<store::Item_t>& literals)
   :
   theId(zann_end),
   theQName(qname)

=== modified file 'src/api/documentmanagerimpl.h'
--- src/api/documentmanagerimpl.h	2013-02-07 17:24:36 +0000
+++ src/api/documentmanagerimpl.h	2013-07-31 16:13:34 +0000
@@ -23,49 +23,42 @@
 
   class DiagnosticHandler;
 
-  /** \brief 
-   *
-   */
-  class DocumentManagerImpl : public DocumentManager
-  {
-  protected:
-    StaticContext_t          theContext;
-    ItemFactory*             theFactory;
-    static std::string       theDocNamespace;
-
-    DiagnosticHandler      * theDiagnosticHandler;
-
-  public:
-    void
-    put(const String& aURI, const Item& aDoc);
-
-    void
-    remove(const String& aURI);
-
-    Item
-    document(const String& aURI) const;
-
-    ItemSequence_t
-    availableDocuments() const;
-
-    bool
-    isAvailableDocument(const String& aURI) const;
-
-    virtual ~DocumentManagerImpl();
-
-  protected:
-    friend class XmlDataManagerImpl;
-    DocumentManagerImpl(
+/** \brief 
+ *
+ */
+class DocumentManagerImpl : public DocumentManager
+{
+protected:
+  StaticContext_t          theContext;
+  ItemFactory*             theFactory;
+  static std::string       theDocNamespace;
+
+  DiagnosticHandler      * theDiagnosticHandler;
+
+public:
+  void put(const String& aURI, const Item& aDoc);
+
+  void remove(const String& aURI);
+
+  Item document(const String& aURI) const;
+
+  ItemSequence_t availableDocuments() const;
+
+  bool isAvailableDocument(const String& aURI) const;
+
+  virtual ~DocumentManagerImpl();
+
+protected:
+  friend class XmlDataManagerImpl;
+
+  DocumentManagerImpl(
       const StaticContext_t& aSctx,
       ItemFactory* aFactory);
 
-    void
-    initStaticContext();
-
-    void
-    registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler);
-
-  }; /* class DocumentManagerImpl */
+  void initStaticContext();
+
+  void registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler);
+};
 
 } /* namespace zorba */
 #endif

=== modified file 'src/api/xmldatamanagerimpl.cpp'
--- src/api/xmldatamanagerimpl.cpp	2013-07-01 18:59:06 +0000
+++ src/api/xmldatamanagerimpl.cpp	2013-07-31 16:13:34 +0000
@@ -80,8 +80,10 @@
   , theStemmerProviderWrapper(0)
 #endif /* ZORBA_NO_FULL_TEXT */
 {
+  Zorba* lZorba = Zorba::getInstance(0);
+  theFactory = lZorba->getItemFactory();
+
   initStaticContext();
-  initializeItemFactory();
 
   theDiagnosticHandler = new DiagnosticHandler();
   theUserDiagnosticHandler = false;
@@ -97,21 +99,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-void
-XmlDataManagerImpl::initializeItemFactory()
-{
-  // assumption: Zorba is already initialized
-  // otherwise there was no chance for the user to get this data manager
-  Zorba* lZorba = Zorba::getInstance(0);
-  theFactory = lZorba->getItemFactory();
-}
-
-
-/*******************************************************************************
-
-********************************************************************************/
-void
-XmlDataManagerImpl::initStaticContext(DiagnosticHandler* aDiagnosticHandler)
+void XmlDataManagerImpl::initStaticContext(DiagnosticHandler* aDiagnosticHandler)
 {
   // assumption: Zorba is already initialized
   // otherwise there was no chance for the user to get this data manager
@@ -147,8 +135,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-DocumentManager*
-XmlDataManagerImpl::getDocumentManager() const
+DocumentManager* XmlDataManagerImpl::getDocumentManager() const
 {
   if (!theDocManager)
   {
@@ -162,8 +149,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-CollectionManager*
-XmlDataManagerImpl::getCollectionManager() const
+CollectionManager* XmlDataManagerImpl::getCollectionManager() const
 {
   if (!theColManager)
   {
@@ -181,8 +167,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-CollectionManager*
-XmlDataManagerImpl::getW3CCollectionManager() const
+CollectionManager* XmlDataManagerImpl::getW3CCollectionManager() const
 {
   if (!theW3CColManager)
   {
@@ -200,8 +185,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-static void
-streamReleaser(std::istream* stream)
+static void streamReleaser(std::istream* stream)
 {
   // it's the user's responsibility to manage the lifetime
 }
@@ -210,8 +194,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-Item
-XmlDataManagerImpl::parseXML(std::istream& aStream) const
+Item XmlDataManagerImpl::parseXML(std::istream& aStream) const
 {
   ZORBA_DM_TRY
   {
@@ -238,8 +221,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-Item
-XmlDataManagerImpl::parseXML(
+Item XmlDataManagerImpl::parseXML(
     std::istream& aStream,
     const String& aBaseURI) const
 {
@@ -271,8 +253,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-ItemSequence_t
-XmlDataManagerImpl::parseXML(
+ItemSequence_t XmlDataManagerImpl::parseXML(
     std::istream& aStream,
     XmlDataManager::ParseOptions& aOptions) const
 {
@@ -319,8 +300,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-ItemSequence_t
-XmlDataManagerImpl::parseXML(
+ItemSequence_t XmlDataManagerImpl::parseXML(
     std::istream& aStream,
     const String& aBaseURI,
     ParseOptions& aOptions) const
@@ -375,8 +355,7 @@
 /*******************************************************************************
 
 ********************************************************************************/
-Item
-XmlDataManagerImpl::fetch(const String& aURI) const
+Item XmlDataManagerImpl::fetch(const String& aURI) const
 {
   ZORBA_DM_TRY
   {
@@ -405,8 +384,6 @@
 ********************************************************************************/
 void XmlDataManagerImpl::registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler)
 {
-  SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);)
-
   theContext = new StaticContextImpl(aDiagnosticHandler);
   if (!theUserDiagnosticHandler)
     delete theDiagnosticHandler;
@@ -434,7 +411,6 @@
 ********************************************************************************/
 void XmlDataManagerImpl::registerStemmerProvider(StemmerProvider const *p)
 {
-  SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);)
   if ( theStemmerProviderWrapper )
   {
     if ( theStemmerProviderWrapper->get_provider() == p )
@@ -455,7 +431,6 @@
 ********************************************************************************/
 void XmlDataManagerImpl::registerTokenizerProvider(TokenizerProvider const *p)
 {
-  SYNC_CODE(AutoLatch lock(theLatch, Latch::WRITE);)
   theStore->setTokenizerProvider( p );
 }
 #endif /* ZORBA_NO_FULL_TEXT */

=== modified file 'src/api/xmldatamanagerimpl.h'
--- src/api/xmldatamanagerimpl.h	2013-02-07 17:24:36 +0000
+++ src/api/xmldatamanagerimpl.h	2013-07-31 16:13:34 +0000
@@ -37,74 +37,57 @@
 class DocumentManagerImpl;
 class CollectionManagerImpl;
 
-namespace store {
-    class Store;
+namespace store
+{
+  class Store;
 }
 
 
 class XmlDataManagerImpl : public XmlDataManager
 {
-private:
-  friend struct Loki::CreateUsingNew<XmlDataManagerImpl>;
+  friend class ZorbaImpl;
 
 protected:
-  store::Store           * theStore;
-
-  DiagnosticHandler      * theDiagnosticHandler;
-
-  bool                     theUserDiagnosticHandler;
-
-  SYNC_CODE(Latch          theLatch;)
-
-  StaticContext_t          theContext;
-  ItemFactory*             theFactory;
+  store::Store                     * theStore;
+
+  DiagnosticHandler                * theDiagnosticHandler;
+
+  bool                               theUserDiagnosticHandler;
+
+  StaticContext_t                    theContext;
+
+  ItemFactory                      * theFactory;
 
   // allow for lazy creation
-  mutable DocumentManagerImpl*   theDocManager;
-  mutable CollectionManagerImpl* theColManager;
-  mutable CollectionManagerImpl* theW3CColManager;
+  mutable DocumentManagerImpl      * theDocManager;
+  mutable CollectionManagerImpl    * theColManager;
+  mutable CollectionManagerImpl    * theW3CColManager;
 
 #ifndef ZORBA_NO_FULL_TEXT
   internal::StemmerProviderWrapper * theStemmerProviderWrapper;
 #endif /* ZORBA_NO_FULL_TEXT */
 
-protected:
-  void
-  initStaticContext(DiagnosticHandler* aDiagnosticHandler = 0);
-
-  void
-  initializeItemFactory();
-
 public:
-  DocumentManager*
-  getDocumentManager() const;
-
-  CollectionManager*
-  getCollectionManager() const;
-
-  CollectionManager*
-  getW3CCollectionManager() const;
-
-  Item
-  parseXML(std::istream& aStream) const;
-
-  Item
-  parseXML(std::istream& aStream, const String& aBaseURI) const;
-
-  ItemSequence_t
-  parseXML(std::istream& aStream, ParseOptions& aOptions) const;
-
-  ItemSequence_t
-  parseXML(
+  DocumentManager* getDocumentManager() const;
+
+  CollectionManager* getCollectionManager() const;
+
+  CollectionManager* getW3CCollectionManager() const;
+
+  Item parseXML(std::istream& aStream) const;
+
+  Item parseXML(std::istream& aStream, const String& aBaseURI) const;
+
+  ItemSequence_t parseXML(std::istream& aStream, ParseOptions& aOptions) const;
+
+  ItemSequence_t parseXML(
       std::istream& aStream,
       const String& aBaseURI,
       ParseOptions& aOptions) const;
 
-  Item
-  fetch(const String& aURI) const;
+  Item fetch(const String& aURI) const;
 
-  void
-  registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler);
+  void registerDiagnosticHandler(DiagnosticHandler* aDiagnosticHandler);
 
 #ifndef ZORBA_NO_FULL_TEXT
   void registerStemmerProvider(StemmerProvider const *provider);
@@ -115,14 +98,11 @@
   XmlDataManagerImpl();
 
   virtual ~XmlDataManagerImpl();
+
+  void initStaticContext(DiagnosticHandler* aDiagnosticHandler = 0);
 };
 
 
-typedef
-Loki::SingletonHolder<XmlDataManagerImpl,
-                      Loki::CreateUsingNew,
-                      Loki::DeletableSingleton> XmlDataManagerSingleton;
-
 } // namespace zorba
 
 #endif /* ZORBA_XMLDATAMANAGER_IMPL_H */

=== modified file 'src/api/zorbaimpl.cpp'
--- src/api/zorbaimpl.cpp	2013-06-27 15:54:27 +0000
+++ src/api/zorbaimpl.cpp	2013-07-31 16:13:34 +0000
@@ -261,9 +261,9 @@
 /*******************************************************************************
 
 ********************************************************************************/
-XmlDataManager* ZorbaImpl::getXmlDataManager()
+XmlDataManager_t ZorbaImpl::createXmlDataManager()
 {
-  return &XmlDataManagerSingleton::Instance();
+  return new XmlDataManagerImpl();
 }
 
 

=== modified file 'src/api/zorbaimpl.h'
--- src/api/zorbaimpl.h	2013-06-27 15:54:27 +0000
+++ src/api/zorbaimpl.h	2013-07-31 16:13:34 +0000
@@ -130,10 +130,10 @@
 
   StaticContext_t createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0);
 
+  XmlDataManager_t createXmlDataManager();
+
   ItemFactory* getItemFactory();
 
-  XmlDataManager* getXmlDataManager();
-
   audit::Provider* getAuditProvider();
 
   PropertiesGlobal* getPropertiesGlobal();

=== modified file 'src/capi/cimplementation.cpp'
--- src/capi/cimplementation.cpp	2013-02-07 17:24:36 +0000
+++ src/capi/cimplementation.cpp	2013-07-31 16:13:34 +0000
@@ -367,7 +367,7 @@
 
   XQC_Error
   CImplementation::parse_istream(std::istream& aStream, XQC_Sequence** seq) {
-    XmlDataManager* lXdm = theZorba->getXmlDataManager();
+    XmlDataManager_t lXdm = theZorba->createXmlDataManager();
     Item lDoc = lXdm->parseXML(aStream);
     if (lDoc.isNull()) {
       // XmlDataManager doesn't throw exceptions, just passes them

=== modified file 'src/runtime/parsing_and_serializing/parse_fragment_impl.cpp'
--- src/runtime/parsing_and_serializing/parse_fragment_impl.cpp	2013-04-16 21:12:12 +0000
+++ src/runtime/parsing_and_serializing/parse_fragment_impl.cpp	2013-07-31 16:13:34 +0000
@@ -54,6 +54,7 @@
   return attr;
 }
 
+
 void processOptions(store::Item_t item, store::LoadProperties& props, static_context* theSctx, const QueryLoc& loc)
 {
   URI lValidatedBaseUri;
@@ -178,6 +179,7 @@
   }
 }
 
+
 void FnZorbaParseXmlFragmentIteratorState::reset(PlanState& planState)
 {
   PlanIteratorState::reset(planState);
@@ -188,7 +190,10 @@
   docUri = "";
 }
 
-bool FnZorbaParseXmlFragmentIterator::nextImpl(store::Item_t& result, PlanState& planState) const
+
+bool FnZorbaParseXmlFragmentIterator::nextImpl(
+    store::Item_t& result,
+    PlanState& planState) const
 {
   store::Store& lStore = GENV.getStore();
   zstring docString;
@@ -330,6 +335,7 @@
   STACK_END(state);
 }
 
+
 /*******************************************************************************
   14.9.1.1 fn-zorba-xml:canonicalize
 ********************************************************************************/
@@ -402,10 +408,13 @@
   theProperties.setStoreDocument(false);
 }
 
+
 /*******************************************************************************
   14.9.2 fn:parse-xml-fragment
 ********************************************************************************/
-bool FnParseXmlFragmentIterator::nextImpl(store::Item_t& result, PlanState& planState) const
+bool FnParseXmlFragmentIterator::nextImpl(
+    store::Item_t& result,
+    PlanState& planState) const
 {
   zstring docString;
 
@@ -426,23 +435,30 @@
     }
 
     state->theProperties.setBaseUri(theSctx->get_base_uri());
+    state->theProperties.setParseExternalParsedEntity(true);
+    state->theProperties.setStoreDocument(false);
+
     state->baseUri = state->theProperties.getBaseUri();    
-    state->theProperties.setParseExternalParsedEntity(true);
-    state->theFragmentStream.only_one_doc_node = 1; // create only one document node holding all fragment nodes
+
+    // create only one document node holding all fragment nodes
+    state->theFragmentStream.only_one_doc_node = 1;
        
-    try {
-      state->theProperties.setStoreDocument(false);
-      result = GENV.getStore().loadDocument(state->baseUri, state->docUri, state->theFragmentStream, state->theProperties);
+    try
+    {
+      result = GENV.getStore().loadDocument(state->baseUri,
+                                            state->docUri,
+                                            state->theFragmentStream,
+                                            state->theProperties);
     }
-    catch ( ZorbaException const &e ) {
-      if ( !state->theProperties.getNoError() ) {
+    catch ( ZorbaException const &e )
+    {
+      if ( !state->theProperties.getNoError() )
+      {
         XQueryException xe(
-          XQUERY_EXCEPTION(
-            err::FODC0006,
-            ERROR_PARAMS( "fn:parse-xml-fragment()", e.what() ),
-            ERROR_LOC( loc )
-          )
-        );
+          XQUERY_EXCEPTION(err::FODC0006,
+          ERROR_PARAMS( "fn:parse-xml-fragment()", e.what() ),
+          ERROR_LOC( loc )));
+
         set_data( xe, e );
         throw xe;
       }
@@ -456,6 +472,7 @@
   STACK_END(state);
 }
 
+
 void FnParseXmlFragmentIteratorState::reset(PlanState& planState)
 {
   PlanIteratorState::reset(planState);

=== modified file 'src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp'
--- src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp	2013-05-03 23:19:41 +0000
+++ src/runtime/parsing_and_serializing/parsing_and_serializing_impl.cpp	2013-07-31 16:13:34 +0000
@@ -53,7 +53,7 @@
   URI lValidatedBaseUri;
   zstring docUri;
   std::auto_ptr<std::istringstream> iss;
-  std::istream *is;
+  std::istream* is;
 
   PlanIteratorState* state;
   DEFAULT_STACK_INIT(PlanIteratorState, state, planState);

=== modified file 'src/unit_tests/test_stemmer.cpp'
--- src/unit_tests/test_stemmer.cpp	2013-02-07 17:24:36 +0000
+++ src/unit_tests/test_stemmer.cpp	2013-07-31 16:13:34 +0000
@@ -96,7 +96,8 @@
       "return $x contains text \"foo\" using stemming";
 
     TestStemmerProvider provider;
-    zorba->getXmlDataManager()->registerStemmerProvider( &provider );
+    XmlDataManager_t xmlDataMgr = zorba->createXmlDataManager();
+    xmlDataMgr->registerStemmerProvider( &provider );
 
     StaticContext_t sctx = zorba->createStaticContext();
     XQuery_t xquery = zorba->compileQuery( query_src, sctx );

=== modified file 'src/unit_tests/test_tokenizer.cpp'
--- src/unit_tests/test_tokenizer.cpp	2013-02-07 17:24:36 +0000
+++ src/unit_tests/test_tokenizer.cpp	2013-07-31 16:13:34 +0000
@@ -387,7 +387,8 @@
       "return $x contains text \"times\"";
 
     TestTokenizerProvider provider;
-    zorba->getXmlDataManager()->registerTokenizerProvider( &provider );
+    XmlDataManager_t xmlDataMgr = zorba->createXmlDataManager();
+    xmlDataMgr->registerTokenizerProvider( &provider );
 
     StaticContext_t sctx = zorba->createStaticContext();
     XQuery_t xquery = zorba->compileQuery( query_src, sctx );

=== modified file 'swig/XmlDataManager.h'
--- swig/XmlDataManager.h	2013-02-07 17:24:36 +0000
+++ swig/XmlDataManager.h	2013-07-31 16:13:34 +0000
@@ -28,11 +28,12 @@
 class XmlDataManager
 {
 private:
-  zorba::XmlDataManager* theManager;
+  zorba::XmlDataManager_t theManager;
 
 public:
   XmlDataManager(const XmlDataManager& aMgr) : theManager(aMgr.theManager) {}
-  XmlDataManager(zorba::XmlDataManager* aMgr) : theManager(aMgr) {}
+
+  XmlDataManager(zorba::XmlDataManager_t aMgr) : theManager(aMgr) {}
 
     /** \brief Returns a DocumentManager
      * 
@@ -90,4 +91,4 @@
   Item parseXMLtoItem(ZorbaIOStream & aStream);
 
 };
-#endif
\ No newline at end of file
+#endif

=== modified file 'swig/XmlDataManager.i'
--- swig/XmlDataManager.i	2013-02-07 17:24:36 +0000
+++ swig/XmlDataManager.i	2013-07-31 16:13:34 +0000
@@ -20,10 +20,12 @@
   {
     return DocumentManager(theManager->getDocumentManager()); 
   }
+
   CollectionManager XmlDataManager::getCollectionManager()
   {
     return CollectionManager(theManager->getCollectionManager()); 
   }
+
   CollectionManager XmlDataManager::getW3CCollectionManager()
   {
     return CollectionManager(theManager->getW3CCollectionManager()); 

=== modified file 'swig/Zorba.h'
--- swig/Zorba.h	2013-02-07 17:24:36 +0000
+++ swig/Zorba.h	2013-07-31 16:13:34 +0000
@@ -59,6 +59,12 @@
    */
   StaticContext createStaticContext();
 
+  /** \brief Creates a new XmlDataManager
+   *
+   * @return XmlDataManager the new XmlDataManager.
+   */
+  XmlDataManager createXmlDataManager();
+
   /** \brief Creates an XQuery object.
    *
    * This methods creates an XQuery object without implicitliy assigning it
@@ -151,12 +157,6 @@
                       DiagnosticHandler* aDiagnosticHandler);
 
 
-  /** \brief Gets the singleton instance of the XmlDataManager object.
-   *
-   * @return XmlDataManager the singleton instance of the XmlDataManager.
-   */
-  XmlDataManager getXmlDataManager();
-
   /** \brief Releases all resources aquired by the Zorba %XQuery Engine.
    *
    * Also releases resources aquired by the libraries used (i.e. icu,

=== modified file 'swig/Zorba.i'
--- swig/Zorba.i	2013-02-07 17:24:36 +0000
+++ swig/Zorba.i	2013-07-31 16:13:34 +0000
@@ -31,6 +31,11 @@
     return StaticContext(theZorba->createStaticContext());
   }
   
+  XmlDataManager Zorba::createXmlDataManager()
+  {
+    return XmlDataManager(theZorba->createXmlDataManager());
+  }
+
   XQuery Zorba::createQuery() 
   {
     return XQuery(theZorba->createQuery());
@@ -88,11 +93,6 @@
     );
   }
 
-  XmlDataManager Zorba::getXmlDataManager()
-  {
-    return XmlDataManager(theZorba->getXmlDataManager());
-  }
-
   void Zorba::shutdown() 
   {
     theZorba->shutdown();

=== modified file 'test/driver/testdriver.cpp'
--- test/driver/testdriver.cpp	2013-06-15 02:57:08 +0000
+++ test/driver/testdriver.cpp	2013-07-31 16:13:34 +0000
@@ -125,8 +125,7 @@
   zorba::XQuery_t lQuery;
   TestDiagnosticHandler errHandler;
 
-  DriverContext driverContext;
-  driverContext.theEngine = engine;
+  DriverContext driverContext(engine);
   driverContext.theRbktSourceDir = rbkt_src_dir;
   driverContext.theRbktBinaryDir = rbkt_bin_dir;
   driverContext.theSpec = &lSpec;

=== modified file 'test/driver/testdriver_common.cpp'
--- test/driver/testdriver_common.cpp	2013-06-27 15:54:27 +0000
+++ test/driver/testdriver_common.cpp	2013-07-31 16:13:34 +0000
@@ -403,10 +403,7 @@
     std::cout << "Load xml " << val << std::endl;
 #endif
 
-    zorba::XmlDataManager* lXmlMgr =
-    zorba::Zorba::getInstance(NULL)->getXmlDataManager();
-
-    zorba::DocumentManager* lDocMgr = lXmlMgr->getDocumentManager();
+    zorba::DocumentManager* lDocMgr = driverCtx.theXmlDataMgr->getDocumentManager();
 
     zorba::Item lDoc;
     if (lDocMgr->isAvailableDocument(val)) 
@@ -432,7 +429,8 @@
 #else
       std::string file_scheme = "file:///";
 #endif
-      zorba::ItemSequence_t lSeq = lXmlMgr->parseXML(ifile, file_scheme + val, lOptions);
+      zorba::ItemSequence_t lSeq =
+      driverCtx.theXmlDataMgr->parseXML(ifile, file_scheme + val, lOptions);
 
       zorba::Iterator_t lIter = lSeq->getIterator();
       lIter->open();

=== modified file 'test/driver/testdriver_common.h'
--- test/driver/testdriver_common.h	2013-06-27 15:54:27 +0000
+++ test/driver/testdriver_common.h	2013-07-31 16:13:34 +0000
@@ -124,12 +124,23 @@
 class DriverContext
 {
 public:
-  zorba::Zorba  * theEngine;
-  Specification * theSpec;
-  std::string     theRbktSourceDir;
-  std::string     theRbktBinaryDir;
+  zorba::Zorba            * theEngine;
+  zorba::XmlDataManager_t   theXmlDataMgr;
+  Specification           * theSpec;
+  std::string               theRbktSourceDir;
+  std::string               theRbktBinaryDir;
   std::vector<zorba::URIMapper*>  theURIMappers;
   std::vector<zorba::URLResolver*>  theURLResolvers;
+
+public:
+  DriverContext(zorba::Zorba * zorba)
+    :
+    theEngine(zorba),
+    theSpec(NULL)
+  {
+    theXmlDataMgr = theEngine->createXmlDataMamager();
+  }
+
 };
 
 

=== modified file 'test/driver/testdriver_mt.cpp'
--- test/driver/testdriver_mt.cpp	2013-07-02 21:32:23 +0000
+++ test/driver/testdriver_mt.cpp	2013-07-31 16:13:34 +0000
@@ -428,8 +428,7 @@
 
     bool failure = false;
 
-    DriverContext driverContext;
-    driverContext.theEngine = zorba;
+    DriverContext driverContext(zorba);
     driverContext.theRbktSourceDir = rbkt_src_dir;
     driverContext.theRbktBinaryDir = rbkt_bin_dir;
     driverContext.theSpec = &querySpec;

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to