Matthias Brantner has proposed merging 
lp:~zorba-coders/zorba/feature-ModuleInfo into lp:zorba.

Commit message:
Added XQuery::parse(std::istream& aQuery, ModuleInfo_t& aResult) to allow 
retrieval
of a module's target namespace without compiling it.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Chris Hillery (ceejatec)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/feature-ModuleInfo/+merge/148616
-- 
https://code.launchpad.net/~zorba-coders/zorba/feature-ModuleInfo/+merge/148616
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-02-13 16:25:55 +0000
+++ ChangeLog	2013-02-15 06:13:25 +0000
@@ -9,6 +9,7 @@
   * New C++ and XQuery function (see module http://www.zorba-xquery.com/modules/item)
     to estimate the size an item allocates in memory.
   * Extended sequence types to include unions, as specified by XQuery v3.0
+  * Added XQuery::parse(std::istream& aQuery, ModuleInfo_t& aResult) function.
   * In store API, added ability to specify a stream's originating URI (file)
     for streamable strings and base64Binary.
   * Added millis-to-dateTime() function in datetime module.

=== modified file 'include/zorba/api_shared_types.h'
--- include/zorba/api_shared_types.h	2012-09-19 21:16:15 +0000
+++ include/zorba/api_shared_types.h	2013-02-15 06:13:25 +0000
@@ -45,6 +45,7 @@
   class File;
   class DirectoryIterator;
   class Serializer;
+  class ModuleInfo;
 
   class DiagnosticHandler;
   class QueryLocation;
@@ -67,6 +68,7 @@
   typedef zorba::SmartPtr<DirectoryIterator>       DirectoryIterator_t;
   typedef zorba::SmartPtr<Serializer>              Serializer_t;
   typedef zorba::SmartPtr<ItemSequence>            ItemSequence_t;
+  typedef zorba::SmartPtr<ModuleInfo>              ModuleInfo_t;
 
   // data handlers
   class Item;

=== added file 'include/zorba/module_info.h'
--- include/zorba/module_info.h	1970-01-01 00:00:00 +0000
+++ include/zorba/module_info.h	2013-02-15 06:13:25 +0000
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2013 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ZORBA_MODULE_INFO_H
+#define ZORBA_MODULE_INFO_H
+
+#include <zorba/config.h>
+#include <zorba/api_shared_types.h>
+
+namespace zorba {
+
+  /** \brief Information about a main or library module.
+   *
+   */
+  class ZORBA_DLL_PUBLIC ModuleInfo : public SmartObject
+  {
+    public:
+      virtual ~ModuleInfo() {}
+
+      /**
+       * Return the target namespace of the module.
+       *
+       * @return the target namespace or the empty
+       *   string if the module is a main module.
+       */
+      virtual zorba::String
+      getTargetNamespace() const = 0;
+
+      /**
+       * @return true if the module is a library module,
+       *   false otherwise.
+       */
+      virtual bool
+      isLibraryModule() const = 0;
+
+  }; /* class ModuleInfo */
+
+} // namespace zorba
+#endif /* ZORBA_MODULE_INFO_H */
+/* vim:set et sw=2 ts=2: */

=== modified file 'include/zorba/xquery.h'
--- include/zorba/xquery.h	2012-09-19 21:16:15 +0000
+++ include/zorba/xquery.h	2013-02-15 06:13:25 +0000
@@ -230,6 +230,19 @@
    */
   virtual void
   parse(std::istream& aQuery) = 0;
+
+  /** 
+   * \brief Parse the given module String.
+   * 
+   * This function parses the module string and returns some information
+   * about the module.
+   *
+   * @param aQuery the query file to parse.
+   * @param aResult some information about the module
+   * @throw ZorbaException if an error occurs while parsing the query.
+   */
+  virtual void
+  parse(std::istream& aQuery, ModuleInfo_t& aResult) = 0;
   
   /** 
    * \brief Compile a query given as a String.

=== modified file 'src/api/CMakeLists.txt'
--- src/api/CMakeLists.txt	2013-02-01 06:03:17 +0000
+++ src/api/CMakeLists.txt	2013-02-15 06:13:25 +0000
@@ -60,6 +60,7 @@
     streambuf.cpp
     transcode_streambuf.cpp
     uuid.cpp
+    module_info_impl.cpp
     )
 
 IF (ZORBA_WITH_FILE_ACCESS)

=== added file 'src/api/module_info_impl.cpp'
--- src/api/module_info_impl.cpp	1970-01-01 00:00:00 +0000
+++ src/api/module_info_impl.cpp	2013-02-15 06:13:25 +0000
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2013 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "api/module_info_impl.h"
+#include <zorba/zorba_string.h>
+#include "zorbatypes/zstring.h"
+#include "api/unmarshaller.h"
+
+namespace zorba {
+
+  ModuleInfoImpl::ModuleInfoImpl(const zstring& aTargetNamespace)
+    : theTargetNamespace(Unmarshaller::newString(aTargetNamespace))
+  {
+  }
+
+} // namespace zorba
+

=== added file 'src/api/module_info_impl.h'
--- src/api/module_info_impl.h	1970-01-01 00:00:00 +0000
+++ src/api/module_info_impl.h	2013-02-15 06:13:25 +0000
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2013 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef ZORBA_MODULE_INFO_IMPL_H
+#define ZORBA_MODULE_INFO_IMPL_H
+
+#include <zorba/module_info.h>
+#include <zorba/zorba_string.h>
+#include "common/shared_types.h"
+
+namespace zorba {
+
+  /** 
+   */
+  class ZORBA_DLL_PUBLIC ModuleInfoImpl : public ModuleInfo
+  {
+    protected:
+      String theTargetNamespace;
+
+    public:
+      ModuleInfoImpl(const zstring& aTargetNamespace);
+
+      virtual zorba::String
+      getTargetNamespace() const
+      {
+        return theTargetNamespace;
+      }
+
+      virtual bool
+      isLibraryModule() const
+      {
+        return theTargetNamespace.length() > 0;
+      }
+  }; /* class ModuleInfoImpl */
+
+} // namespace zorba
+#endif /* ZORBA_MODULE_INFO_IMPL_H */
+/* vim:set et sw=2 ts=2: */

=== modified file 'src/api/xqueryimpl.cpp'
--- src/api/xqueryimpl.cpp	2013-01-08 08:34:08 +0000
+++ src/api/xqueryimpl.cpp	2013-02-15 06:13:25 +0000
@@ -27,6 +27,7 @@
 #include <zorba/diagnostic_list.h>
 #include <zorba/sax2.h>
 #include <zorba/audit_scoped.h>
+#include <zorba/module_info.h>
 
 #include <zorbatypes/URI.h>
 
@@ -687,6 +688,41 @@
   QUERY_CATCH
 }
 
+/*******************************************************************************
+  Parse a query.
+********************************************************************************/
+void XQueryImpl::parse(std::istream& aQuery, ModuleInfo_t& aResult)
+{
+  SYNC_CODE(AutoMutex lock(&theMutex);)
+
+  try
+  {
+    checkNotClosed();
+    checkNotCompiled();
+
+    if ( ! theStaticContext )
+    {
+      // no context given => use the default one (i.e. a child of the root sctx)
+      theStaticContext = GENV.getRootStaticContext().create_child_context();
+    }
+    else
+    {
+      // otherwise create a child and we have ownership over that one
+      theStaticContext = theStaticContext->create_child_context();
+    }
+
+    zstring url;
+    URI::encode_file_URI(theFileName, url);
+
+    theStaticContext->set_entity_retrieval_uri(url);
+
+    theCompilerCB->theRootSctx = theStaticContext;
+
+    XQueryCompiler lCompiler(theCompilerCB);
+    aResult = lCompiler.parseInfo(aQuery, theFileName);
+  }
+  QUERY_CATCH
+}
 
 /*******************************************************************************
   A clone query shares its error handler and plan iterator tree with the original

=== modified file 'src/api/xqueryimpl.h'
--- src/api/xqueryimpl.h	2012-09-19 21:16:15 +0000
+++ src/api/xqueryimpl.h	2013-02-15 06:13:25 +0000
@@ -45,6 +45,7 @@
 class dynamic_context;
 class CompilerCB;
 class StaticCollectionManagerSetImpl;
+class ModuleInfo;
 
 
 /*******************************************************************************
@@ -282,6 +283,8 @@
 
   void parse(std::istream&);
 
+  void parse(std::istream& aQuery, ModuleInfo_t& aResult);
+
   const StaticContext* getStaticContext() const;
 
   void getExternalVariables(Iterator_t& aVarsIter) const;

=== modified file 'src/compiler/api/compiler_api.cpp'
--- src/compiler/api/compiler_api.cpp	2012-12-14 07:27:04 +0000
+++ src/compiler/api/compiler_api.cpp	2013-02-15 06:13:25 +0000
@@ -40,7 +40,6 @@
 
 #include "compiler/parser/xquery_driver.h"
 #include "compiler/parsetree/parsenodes.h"
-#include "compiler/parsetree/parsenodes.h"
 #include "compiler/parsetree/parsenode_print_xml_visitor.h"
 #include "compiler/parsetree/parsenode_print_xqdoc_visitor.h"
 
@@ -62,6 +61,7 @@
 #include "zorbatypes/URI.h"
 
 #include "api/auditimpl.h"
+#include "api/module_info_impl.h"
 #include <zorba/util/timer.h>
 
 
@@ -204,6 +204,34 @@
   return node;
 }
 
+/*******************************************************************************
+
+********************************************************************************/
+ModuleInfo* XQueryCompiler::parseInfo(
+    std::istream& aXQuery,
+    const zstring& aFileName)
+{
+  parsenode_t lParseNode = parse(aXQuery, aFileName);
+
+  if (typeid (*lParseNode) == typeid (ParseErrorNode))
+  {
+    ParseErrorNode* pen = static_cast<ParseErrorNode *>(lParseNode.getp());
+    throw XQUERY_EXCEPTION_VAR(pen->err, 
+    ERROR_PARAMS(pen->msg), ERROR_LOC(pen->get_location()));
+  }
+
+  LibraryModule* lLibModule = dynamic_cast<LibraryModule*>(lParseNode.getp());
+
+  zstring lTargetNamespace;
+
+  if (lLibModule)
+  {
+    ModuleDecl* lDecl = lLibModule->get_decl().getp();
+    lTargetNamespace = lDecl->get_target_namespace();
+  }
+
+  return new ModuleInfoImpl(lTargetNamespace);
+}
 
 /*******************************************************************************
 

=== modified file 'src/compiler/api/compiler_api.h'
--- src/compiler/api/compiler_api.h	2012-11-09 23:14:53 +0000
+++ src/compiler/api/compiler_api.h	2013-02-15 06:13:25 +0000
@@ -52,6 +52,10 @@
 
   parsenode_t parse(std::istream& aXQuery, const zstring& aFileName);
 
+  ModuleInfo* parseInfo(
+      std::istream& aXQuery,
+      const zstring& aFileName);
+
   PlanIter_t compile(
       std::istream& aXQuery,
       const zstring& aFileName,

=== modified file 'test/api/CMakeLists.txt'
--- test/api/CMakeLists.txt	2012-10-08 12:09:36 +0000
+++ test/api/CMakeLists.txt	2013-02-15 06:13:25 +0000
@@ -16,6 +16,7 @@
   APITests.cpp
   itemfactory.cpp
   xmldatamanager.cpp
+  xquery.cpp
   test_static_context.cpp
   test_dynamic_context.cpp
   serializer.cpp

-- 
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