← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/module-schema-tools into lp:zorba

 

Cezar Andrei has proposed merging lp:~zorba-coders/zorba/module-schema-tools into lp:zorba.

Requested reviews:
  Chris Hillery (ceejatec)
  Matthias Brantner (matthias-brantner)
  Cezar Andrei (cezar-andrei)
Related bugs:
  Bug #931816 in Zorba: "New way of classpath and JVM Singleton handling"
  https://bugs.launchpad.net/zorba/+bug/931816
  Bug #933490 in Zorba: "Error ItemFactoryImpl::createBase64Binary with istream"
  https://bugs.launchpad.net/zorba/+bug/933490

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/module-schema-tools/+merge/96399

Add java classpath to zorbacmd and to Zorba API.
Fix dynamic libraries loading.

-- 
https://code.launchpad.net/~zorba-coders/zorba/module-schema-tools/+merge/96399
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/path_util.cpp'
--- bin/path_util.cpp	2011-10-21 08:07:43 +0000
+++ bin/path_util.cpp	2012-03-07 16:55:14 +0000
@@ -49,7 +49,7 @@
 }
 
 
-static void
+void
 tokenizePath(
   const std::string&    aPathStr,
   std::vector<String>&  aResult)
@@ -66,6 +66,23 @@
   }
 }
 
+
+String
+concatenatePaths( const std::vector<String>& aPathList)
+{
+  String delimiter(filesystem_path::get_path_separator());
+
+  String lResult;
+  for (std::vector<String>::const_iterator lIter = aPathList.begin();
+       lIter != aPathList.end(); ++lIter)
+  {
+    lResult += delimiter + *lIter;
+  }
+
+  return lResult;
+}
+
+
 void
 setPathsOnContext(
   const ZorbaCMDProperties& aProperties,
@@ -101,8 +118,8 @@
     // Compute and set lib path
     aProperties.getLibPath(lPathStr);
     tokenizePath(lPathStr, lPath);
+    lPath.push_back(lCWD.get_path());
     lEnvStr = getPathFromEnvironment("ZORBA_LIB_PATH");
-    lPath.push_back(lCWD.get_path());
     tokenizePath(lEnvStr, lPath);
     aStaticCtx->setLibPath(lPath);
   }

=== modified file 'bin/path_util.h'
--- bin/path_util.h	2011-10-21 08:07:43 +0000
+++ bin/path_util.h	2012-03-07 16:55:14 +0000
@@ -32,6 +32,12 @@
     setPathsOnContext(const ZorbaCMDProperties& aProperties,
                       zorba::StaticContext_t& aStaticCtx);
 
+    void
+    tokenizePath(const std::string& aPathStr, std::vector<String>&  aResult);
+
+
+    String
+    concatenatePaths( const std::vector<String>& aPathList);
 
   }
 } /* namespace zorba */

=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2012-02-28 20:45:43 +0000
+++ bin/zorbacmd.cpp	2012-03-07 16:55:14 +0000
@@ -786,6 +786,14 @@
     return 3;
   }
 
+  // Add command line --classpath option in front of config/env CLASSPATH
+  Properties* globalProperties = Properties::instance();
+  std::string cmdJvmClassPath;
+  lProperties.getJVMClassPath(cmdJvmClassPath);
+  std::string configJvmClassPath;
+  globalProperties->getJVMClassPath(configJvmClassPath);
+  globalProperties->setJVMClassPath(cmdJvmClassPath +
+      filesystem_path::get_path_separator() + configJvmClassPath);
 
   // Start the engine
 

=== modified file 'bin/zorbacmdproperties.cpp'
--- bin/zorbacmdproperties.cpp	2011-10-21 08:07:43 +0000
+++ bin/zorbacmdproperties.cpp	2012-03-07 16:55:14 +0000
@@ -181,6 +181,11 @@
   aPath = theLibPath;
 }
 
+void ZorbaCMDProperties::getJVMClassPath(std::string& aPath) const
+{
+  aPath = theClasspath;
+}
+
 std::vector<std::pair<std::string,std::string> > ZorbaCMDProperties::getSerializerParameters() const
 {
   std::vector<std::pair<std::string,std::string> > lResult;

=== modified file 'bin/zorbacmdproperties.h'
--- bin/zorbacmdproperties.h	2011-10-21 08:07:43 +0000
+++ bin/zorbacmdproperties.h	2012-03-07 16:55:14 +0000
@@ -92,6 +92,9 @@
   void
   getLibPath(std::string&) const;
 
+  void
+  getJVMClassPath(std::string&) const;
+
   bool isDebug(){ return theDebug; }
 
   bool hasNoLogo(){ return theNoLogo; }

=== modified file 'bin/zorbacmdproperties.txt'
--- bin/zorbacmdproperties.txt	2012-02-28 20:45:43 +0000
+++ bin/zorbacmdproperties.txt	2012-03-07 16:55:14 +0000
@@ -31,6 +31,7 @@
 ("uri-path", po::value<std::string>(), "URI path (list of directories) added to the built-in URI resolver, i.e. where to find modules/schemas to import.")
 ("lib-path", po::value<std::string>(), "Library path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.")
 ("module-path", po::value<std::string>(), "Path (list of directories) to add to both the URI and Library paths.")
+("classpath", po::value<std::string>(), "JVM classpath to be used by modules using Java implementations")
 ("option", po::value<std::vector<std::string> >(), "Set an XQuery option in the static context. The QName of the option is passed as a string in the notation by James Clark (i.e. {namespace}localname). For example, --option {http://www.zorba-xquery.com}option=value";).
 ("trailing-nl", "Output a trailing newline after the result of the query.")
 ("stop-words", po::value<std::vector<std::string> >(), "Mapping specifying a stop-words URI to another.")

=== modified file 'bin/zorbacmdproperties_base.h'
--- bin/zorbacmdproperties_base.h	2012-02-28 20:45:43 +0000
+++ bin/zorbacmdproperties_base.h	2012-03-07 16:55:14 +0000
@@ -34,7 +34,7 @@
 class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase {
 protected:
   const char **get_all_options () const {
-    static const char *result [] = { "--timing", "--output-file", "--serialization-parameter", "--serialize-html", "--serialize-text", "--indent", "--print-query", "--print-errors-as-xml", "--byte-order-mark", "--omit-xml-declaration", "--base-uri", "--boundary-space", "--default-collation", "--construction-mode", "--ordering-mode", "--multiple", "--query", "--as-files", "--external-variable", "--context-item", "--optimization-level", "--lib-module", "--parse-only", "--compile-only", "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo", "--timeout", "--uri-path", "--lib-path", "--module-path", "--option", "--trailing-nl", "--stop-words", "--thesaurus", "--compile-plan", "--execute-plan", NULL };
+    static const char *result [] = { "--timing", "--output-file", "--serialization-parameter", "--serialize-html", "--serialize-text", "--indent", "--print-query", "--print-errors-as-xml", "--byte-order-mark", "--omit-xml-declaration", "--base-uri", "--boundary-space", "--default-collation", "--construction-mode", "--ordering-mode", "--multiple", "--query", "--as-files", "--external-variable", "--context-item", "--optimization-level", "--lib-module", "--parse-only", "--compile-only", "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo", "--timeout", "--uri-path", "--lib-path", "--module-path", "--classpath", "--option", "--trailing-nl", "--stop-words", "--thesaurus", "--compile-plan", "--execute-plan", NULL };
     return result;
   }
   bool theTiming;
@@ -70,6 +70,7 @@
   std::string theUriPath;
   std::string theLibPath;
   std::string theModulePath;
+  std::string theClasspath;
   std::vector<std::string> theOption;
   bool theTrailingNl;
   std::vector<std::string> theStopWords;
@@ -136,6 +137,7 @@
   const std::string &uriPath () const { return theUriPath; }
   const std::string &libPath () const { return theLibPath; }
   const std::string &modulePath () const { return theModulePath; }
+  const std::string &classpath () const { return theClasspath; }
   const std::vector<std::string> &option () const { return theOption; }
   const bool &trailingNl () const { return theTrailingNl; }
   const std::vector<std::string> &stopWords () const { return theStopWords; }
@@ -287,6 +289,11 @@
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --module-path option"; break; }        init_val (*argv, theModulePath, d);
       }
+      else if (strcmp (*argv, "--classpath") == 0) {
+        int d = 2;
+        if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
+        if (*argv == NULL) { result = "No value given for --classpath option"; break; }        init_val (*argv, theClasspath, d);
+      }
       else if (strcmp (*argv, "--option") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
@@ -360,6 +367,7 @@
 "--uri-path\nURI path (list of directories) added to the built-in URI resolver, i.e. where to find modules/schemas to import.\n\n"
 "--lib-path\nLibrary path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.\n\n"
 "--module-path\nPath (list of directories) to add to both the URI and Library paths.\n\n"
+"--classpath\nJVM classpath to be used by modules using Java implementations\n\n"
 "--option\nSet an XQuery option in the static context. The QName of the option is passed as a string in the notation by James Clark (i.e. {namespace}localname). For example, --option {http://www.zorba-xquery.com}option=value\n\n";
 "--trailing-nl\nOutput a trailing newline after the result of the query.\n\n"
 "--stop-words\nMapping specifying a stop-words URI to another.\n\n"

=== modified file 'cmake_modules/ZorbaModule.cmake'
--- cmake_modules/ZorbaModule.cmake	2012-02-15 10:25:02 +0000
+++ cmake_modules/ZorbaModule.cmake	2012-03-07 16:55:14 +0000
@@ -140,7 +140,6 @@
   ENDIF (NOT IS_ABSOLUTE "${MODULE_FILE}")
   GET_FILENAME_COMPONENT (module_name "${MODULE_FILE}" NAME)
 
-
   MANGLE_URI (${MODULE_URI} ".xq" module_path module_filename)
 
   # Compute a CMake-symbol-safe version of the target URI, for storing
@@ -314,7 +313,7 @@
   ENDIF (MODULE_VERSION)
   FOREACH (version_infix "" ${version_infixes})
     ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${module_path}/${module_filename}"
-      "${version_infix}" "" "${MODULE_TEST_ONLY}")
+      "${version_infix}" "" 1 "${MODULE_TEST_ONLY}")
   ENDFOREACH (version_infix)
 
   # Also copy the dynamic library from the location it was built.
@@ -322,7 +321,7 @@
     GET_TARGET_PROPERTY (lib_location "${module_lib_target}" LOCATION)
     GET_FILENAME_COMPONENT (lib_filename "${lib_location}" NAME)
     ADD_COPY_RULE ("LIB" "${lib_location}" "${module_path}/${lib_filename}"
-      "" "${module_lib_target}" "${MODULE_TEST_ONLY}")
+      "" "${module_lib_target}" 0 "${MODULE_TEST_ONLY}")
   ENDIF (module_lib_target)
 
   # Last but not least, whip up a test case that ensures the module
@@ -375,7 +374,7 @@
   ENDIF (NOT SCHEMA_TEST_ONLY)
 
   ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${schema_path}/${schema_filename}"
-    "" "" "${SCHEMA_TEST_ONLY}")
+    "" "" 1 "${SCHEMA_TEST_ONLY}")
 
 ENDMACRO (DECLARE_ZORBA_SCHEMA)
 
@@ -407,25 +406,107 @@
   MANGLE_URI (${URI_FILE_URI} "" uri_file_path uri_file_filename)
 
   ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${uri_file_path}/${uri_file_filename}"
-    "" "" "${URI_FILE_TEST_ONLY}")
+    "" "" 1 "${URI_FILE_TEST_ONLY}")
 
 ENDMACRO (DECLARE_ZORBA_URI_FILE)
 
+# Inform Zorba of a .jar file that should be made available on the CLASSPATH
+# of the JVM, should the JVM be started. QQQ more doc needed
+#
+# Args: FILE - path to file (must be absolute)
+#       EXTERNAL - (optional) FILE specifies a path that should be added
+#              to CLASSPATH as-is
+#       TEST_ONLY - (optional) Jar file is for testcases only and should not
+#              be installed
+
+MACRO (DECLARE_ZORBA_JAR)
+  PARSE_ARGUMENTS (JAR "FILE" "" "TEST_ONLY;EXTERNAL" ${ARGN})
+  IF (NOT JAR_FILE)
+    MESSAGE (FATAL_ERROR "'FILE' argument is required for DECLARE_ZORBA_JAR")
+  ENDIF (NOT JAR_FILE)
+
+  # Initialize classpath file and set up copy rule (once per project)
+  SET (_CP_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-classpath.txt")
+  GET_PROPERTY (_known_project GLOBAL PROPERTY "${PROJECT_NAME}-jars")
+  IF (NOT _known_project)
+    FILE (REMOVE "${_CP_FILE}")
+    SET_PROPERTY (GLOBAL PROPERTY "${PROJECT_NAME}-jars" 1)
+    ADD_COPY_RULE ("LIB" "${_CP_FILE}" "jars/${PROJECT_NAME}-classpath.txt"
+      "" "" 1 "${JAR_TEST_ONLY}")
+  ENDIF (NOT _known_project)
+
+  # Iterate over all supplied jar files
+  FOREACH (_jar_file ${JAR_FILE})
+
+    IF (JAR_EXTERNAL)
+      # Put absolute path into classpath file
+      FILE (APPEND "${_CP_FILE}" "${_jar_file}\n")
+    ELSE (JAR_EXTERNAL)
+      # Copy jar to jars/ directory and add relative path to classpath file
+      GET_FILENAME_COMPONENT (_output_filename "${_jar_file}" NAME)
+      ADD_COPY_RULE ("LIB" "${_jar_file}" "jars/${_output_filename}" "" ""
+  1 "${JAR_TEST_ONLY}")
+      FILE (APPEND "${_CP_FILE}" "${_output_filename}\n")
+    ENDIF (JAR_EXTERNAL)
+
+  ENDFOREACH (_jar_file)
+ENDMACRO (DECLARE_ZORBA_JAR)
+
+# Inform Zorba of a .jar file that should be made available on the CLASSPATH
+# of the JVM, should the JVM be started. QQQ more doc needed
+#
+# Args: FILE - path to file (must be absolute)
+#       EXTERNAL - (optional) FILE specifies a path that should be added
+#              to CLASSPATH as-is
+#       TEST_ONLY - (optional) Jar file is for testcases only and should not
+#              be installed
+
+#MACRO (DECLARE_ZORBA_JAR)
+#  PARSE_ARGUMENTS (JAR "" "FILE" "TEST_ONLY;EXTERNAL" ${ARGN})
+#  IF (NOT JAR_FILE)
+#    MESSAGE (FATAL_ERROR "'JAR' argument is required for DECLARE_ZORBA_JAR")
+#  ENDIF (NOT JAR_FILE)
+#  IF (NOT IS_ABSOLUTE "${JAR_FILE}")
+#    SET (JAR_FILE "${CMAKE_CURRENT_BINARY_DIR}/${JAR_FILE}")
+#  ENDIF (NOT IS_ABSOLUTE "${JAR_FILE}")
+#
+#  SET (_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-classpath.txt")
+#  IF (JAR_EXTERNAL)
+#    # Remember whether we've seen external jars for this project yet
+#    GET_PROPERTY (_known_project GLOBAL PROPERTY "${PROJECT_NAME}-ext-jars")
+#    IF (NOT _known_project)
+#      FILE (REMOVE "${_LIST_FILE}")
+#      SET_PROPERTY (GLOBAL PROPERTY "${PROJECT_NAME}-ext-jars" 1)
+#      ADD_COPY_RULE ("LIB" "${_LIST_FILE}" "jars/${PROJECT_NAME}-classpath.txt"
+#  "" "" 1 0)
+#    ENDIF (NOT _known_project)
+#    FILE (APPEND "${_LIST_FILE}" "${JAR_FILE}\n")
+#  ELSE (JAR_EXTERNAL)
+#    GET_FILENAME_COMPONENT (_output_filename "${JAR_FILE}" NAME)
+#    ADD_COPY_RULE ("LIB" "${JAR_FILE}" "jars/${_output_filename}" "" ""
+#      1 "${JAR_TEST_ONLY}")
+#  ENDIF (JAR_EXTERNAL)
+#ENDMACRO (DECLARE_ZORBA_JAR)
+
+
+
 # Utility macro for setting up a build rule to copy a file to a
-# particular (possibly versioned) file in a shared directory if such a file has
-# not already been output.
+# particular (possibly versioned) file in a shared directory if such a
+# file has not already been output.
+#
 # FILE_TYPE: Either "URI" or "LIB"; will be used to determine which shared
-#    directory to place output in (URI_PATH or LIB_PATH). Also, "URI" files
-#    will have an INSTALL() directive to put them in the install image.
+#    directory to place output in (URI_PATH or LIB_PATH).
 # INPUT_FILE: Absolute path to file to copy.
 # OUTPUT_FILE: Relative path to output file (relative to URI_PATH).
 # VERSION_ARG: Version; may be "" for non-versioned files.
 # DEPEND_TARGET: A CMake target name upon which the copy rule should depend;
 #    may be "".
+# INSTALL: If 1, an INSTALL() directive will be executed to put the
+#    file into the install image.
 # TEST_ONLY: If 1, file is for testcases only; will be copied into
-#    TEST_URI_PATH/TEST_LIB_PATH and will not be installed
+#    TEST_URI_PATH/TEST_LIB_PATH and will not be installed.
 MACRO (ADD_COPY_RULE FILE_TYPE INPUT_FILE OUTPUT_FILE VERSION_ARG
-       DEPEND_TARGET TEST_ONLY)
+       DEPEND_TARGET INSTALL TEST_ONLY)
   # Choose output base directory
   IF (${TEST_ONLY} EQUAL 1)
     SET (_output_basedir "${CMAKE_BINARY_DIR}/TEST_${FILE_TYPE}_PATH")
@@ -470,13 +551,13 @@
     SET_PROPERTY (GLOBAL APPEND PROPERTY ZORBA_URI_FILES
       "${INPUT_FILE}" "${_output_file}" "${DEPEND_TARGET}" "${_is_core}")
 
-    # Also set up an INSTALL rule (unless TEST_ONLY or LIB).
-    IF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
+    # Also set up an INSTALL rule (unless TEST_ONLY).
+    IF ( (${INSTALL} EQUAL 1) AND (NOT ${TEST_ONLY} EQUAL 1) )
         
       IF(NOT _is_core)
         STRING(REPLACE "-" "_"  component_name ${PROJECT_NAME})   
         INSTALL (FILES "${INPUT_FILE}"
-          DESTINATION "${ZORBA_NONCORE_URI_DIR}/${_output_path}"
+          DESTINATION "${ZORBA_NONCORE_${FILE_TYPE}_DIR}/${_output_path}"
           RENAME "${_output_filename}"
           COMPONENT "${component_name}")
           
@@ -496,11 +577,11 @@
             
       ELSE(NOT _is_core)
         INSTALL (FILES "${INPUT_FILE}"
-          DESTINATION "${ZORBA_CORE_URI_DIR}/${_output_path}"
+          DESTINATION "${ZORBA_CORE_${FILE_TYPE}_DIR}/${_output_path}"
           RENAME "${_output_filename}")
       ENDIF(NOT _is_core)
           
-    ENDIF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
+    ENDIF ( (${INSTALL} EQUAL 1) AND (NOT ${TEST_ONLY} EQUAL 1) )
   ENDIF (file_found EQUAL -1)
 ENDMACRO (ADD_COPY_RULE)
 

=== modified file 'include/zorba/properties_base.h'
--- include/zorba/properties_base.h	2011-06-14 17:26:33 +0000
+++ include/zorba/properties_base.h	2012-03-07 16:55:14 +0000
@@ -101,8 +101,44 @@
     std::vector<std::string>& val,
     unsigned delta);
 
+/**
+ * \brief This class provides access to global properties.
+ *
+ * This class provides access to global properties set for Zorba in environment
+ * and configuration file.
+ * It is available using Zorba.getProperties() method.
+ * \see { Zorba::getProperties() }
+ */
+class ZORBA_DLL_PUBLIC PropertiesGlobal : public PropertiesBase
+{
+public:
+  virtual ~PropertiesGlobal() {}
+
+  /**
+   * \brief Get global JVM classpath property.
+   *
+   * Before the JVM is started this will return the classpath set by
+   * command line option, the CLASSPATH environment variable and in Zorba
+   * config file.
+   *
+   * After the JVM is started this will contain in addition the paths to jars
+   * used by modules that make use of the JVM.
+   */
+  virtual void getJVMClassPath(std::string & jvmClasspath) {}
+
+  /**
+   * \brief Set global JVM classpath property.
+   *
+   * This method should be used to set additional JVM classpath for modules
+   * that make use of JVM. This will overide the classpath set by CLASSPATH
+   * environment variable or Zorba config file.
+   *
+   * Once the JVM is started this method doesn't have any effect.
+   */
+  virtual void setJVMClassPath(const std::string & jvmClasspath) {}
+};
+
 }
-
 #endif  // ZORBA_PROPERTIES_BASE_H
 /*
  * Local variables:

=== modified file 'include/zorba/util/file.h'
--- include/zorba/util/file.h	2011-06-14 17:26:33 +0000
+++ include/zorba/util/file.h	2012-03-07 16:55:14 +0000
@@ -24,6 +24,7 @@
 #include <cstdio>
 #include <string>
 #include <time.h>
+#include <vector>
 
 #include <zorba/config.h>
 #include <zorba/file.h>
@@ -84,6 +85,7 @@
   void mkdir();
   void deep_mkdir();
   void rmdir(bool ignore = true);
+  void lsdir(std::vector<std::string> &list);
 #ifndef _WIN32_WCE
   void chdir();
 #endif

=== modified file 'include/zorba/zorba.h'
--- include/zorba/zorba.h	2011-12-21 14:40:33 +0000
+++ include/zorba/zorba.h	2012-03-07 16:55:14 +0000
@@ -34,14 +34,18 @@
 #include <zorba/xquery.h>
 #include <zorba/zorba_string.h>
 #include <zorba/iterator.h>
+#include <zorba/properties_base.h>
 
 namespace zorba {
 
 /**
  * The Zorba class is the single point of access to the %Zorba engine.
  * There exists one instance of the Zorba class per process.
- * It can be used to (1) create and compile queries, (2) create static contexts,
- * (3) provides access to the XmlDataManager, and (4) provides access to the ItemFactory.
+ * It can be used to (1) create and compile queries,
+ * (2) create static contexts,
+ * (3) provides access to the XmlDataManager,
+ * (4) provides access to the ItemFactory, and
+ * (5) provides access to the PropertiesGlobal.
  */
 class ZORBA_DLL_PUBLIC Zorba
 {
@@ -322,6 +326,12 @@
   virtual audit::Provider*
   getAuditProvider() = 0;
 
+  /** \brief Gets the singleton instance of Zorba's properties object.
+   *
+   * @return zorba::Properties the singelton instance of Zorba's properties object.
+   */
+  virtual PropertiesGlobal* getProperties() = 0;
+
 }; /* class Zorba */
 
 

=== modified file 'modules/ExternalModules.conf'
--- modules/ExternalModules.conf	2012-03-07 15:49:25 +0000
+++ modules/ExternalModules.conf	2012-03-07 16:55:14 +0000
@@ -40,3 +40,4 @@
 system          bzr  lp:zorba/system-module              zorba-2.1
 xqxq            bzr  lp:zorba/xqxq-module                1.0
 email           bzr  lp:zorba/email-module               zorba-2.1
+

=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h	2012-02-28 20:45:43 +0000
+++ src/api/staticcontextimpl.h	2012-03-07 16:55:14 +0000
@@ -281,6 +281,7 @@
   virtual void
   getFullLibPath(std::vector<String>& aLibPath) const;
 
+
 protected:
   String
   createInvokeQuery(const Function_t&, size_t aArity) const;

=== modified file 'src/api/zorbaimpl.cpp'
--- src/api/zorbaimpl.cpp	2012-01-20 13:37:12 +0000
+++ src/api/zorbaimpl.cpp	2012-03-07 16:55:14 +0000
@@ -35,6 +35,7 @@
 #include "diagnostics/xquery_diagnostics.h"
 
 #include "system/globalenv.h"
+#include "system/properties.h"
 
 #include "context/static_context.h"
 
@@ -269,6 +270,15 @@
 }
 
 
+/*******************************************************************************
+
+********************************************************************************/
+PropertiesGlobal* ZorbaImpl::getProperties()
+{
+  return Properties::instance();
+}
+
+
 void ZorbaImpl::notifyError( DiagnosticHandler *eh, ZorbaException const &ze ) {
   eh->error( ze );
 }

=== modified file 'src/api/zorbaimpl.h'
--- src/api/zorbaimpl.h	2011-06-15 12:33:45 +0000
+++ src/api/zorbaimpl.h	2012-03-07 16:55:14 +0000
@@ -134,6 +134,8 @@
 
   audit::Provider* getAuditProvider();
 
+  PropertiesGlobal* getProperties();
+
 protected:
   ZorbaImpl();
 

=== modified file 'src/context/dynamic_loader.cpp'
--- src/context/dynamic_loader.cpp	2012-01-11 17:30:25 +0000
+++ src/context/dynamic_loader.cpp	2012-03-07 16:55:14 +0000
@@ -132,9 +132,36 @@
 ExternalModule*
 DynamicLoader::loadModule(const zstring& aFile) const
 {
+  void* handle;
   // function pointer to create a module
   ExternalModule* (*createModule)() = NULL;
 
+  std::map<const zstring, void*>::const_iterator lIter = theLibraries.find(aFile);
+  if (lIter != theLibraries.end())
+  {
+    handle = lIter->second;
+
+#ifdef WIN32
+    createModule = (ExternalModule* (*)())GetProcAddress(handle, "createModule");
+    if (createModule == NULL)
+      throw ZORBA_EXCEPTION(
+        zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
+        ERROR_PARAMS( aFile, os_error::get_err_string() )
+      );
+#else
+    createModule = (ExternalModule* (*)()) dlsym(handle, "createModule");
+    if (createModule == NULL)
+    {
+      dlclose(handle);
+      throw ZORBA_EXCEPTION(
+        zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
+        ERROR_PARAMS( aFile, dlerror() )
+      );
+    }
+#endif
+    return createModule();
+  }
+
 #ifdef WIN32
   WCHAR wpath_str[1024];
   wpath_str[0] = 0;
@@ -146,7 +173,8 @@
                       0, aFile.c_str(), -1,
                       wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
   }
-  HMODULE handle = LoadLibraryW(wpath_str);
+
+  handle = LoadLibraryW(wpath_str);
   if (!handle)
     throw ZORBA_EXCEPTION(
       zerr::ZOSE0005_DLL_LOAD_FAILED,
@@ -161,7 +189,7 @@
     );
 
 #else
-  void* handle = dlopen(aFile.c_str(), RTLD_NOW);
+  handle = dlopen(aFile.c_str(), RTLD_NOW);
   if (!handle)
     throw ZORBA_EXCEPTION(
       zerr::ZOSE0005_DLL_LOAD_FAILED, ERROR_PARAMS( aFile, zstring(dlerror()) )
@@ -177,11 +205,8 @@
     );
   }
 #endif
-  if (theLibraries.find(handle) == theLibraries.end())
-  {
-    theLibraries.insert(handle);
-  }
 
+  theLibraries[aFile] = handle;
   return createModule();
 }
 
@@ -193,13 +218,13 @@
 
 DynamicLoader::~DynamicLoader()
 {
-  for (LibrarySet_t::const_iterator lIter = theLibraries.begin();
+  for (LibraryMap_t::const_iterator lIter = theLibraries.begin();
        lIter != theLibraries.end(); ++lIter)
   {
 #ifdef WIN32
-    FreeLibrary(*lIter);
+    FreeLibrary(lIter->second);
 #else
-    dlclose(*lIter);
+    dlclose(lIter->second);
 #endif
   }
 }

=== modified file 'src/context/dynamic_loader.h'
--- src/context/dynamic_loader.h	2011-12-21 14:40:33 +0000
+++ src/context/dynamic_loader.h	2012-03-07 16:55:14 +0000
@@ -18,7 +18,7 @@
 #define ZORBA_DYNAMIC_LOADER_H
 
 #include "common/common.h"
-#include <set>
+#include <map>
 #include "common/shared_types.h"
 
 namespace zorba {
@@ -45,10 +45,10 @@
 #ifdef WIN32
   typedef std::set<HMODULE> LibrarySet_t;
 #else
-  typedef std::set<void*> LibrarySet_t;
+  typedef std::map<const zstring, void*> LibraryMap_t;
 #endif
 
-  mutable LibrarySet_t theLibraries;
+  mutable LibraryMap_t theLibraries;
 };
 
 } /* namespace zorba */

=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp	2012-03-07 15:49:25 +0000
+++ src/context/static_context.cpp	2012-03-07 16:55:14 +0000
@@ -1693,6 +1693,43 @@
 }
 
 
+////////////////////////////////////////////////////////////////////////////////
+//                                                                            //
+//  JVM Classpath                                                             //
+//                                                                            //
+////////////////////////////////////////////////////////////////////////////////
+
+/*******************************************************************************
+
+********************************************************************************/
+void static_context::set_jvm_class_path(const std::vector<zstring>& path)
+{
+  theJVMClassPath = path;
+}
+
+
+/*******************************************************************************
+
+********************************************************************************/
+void static_context::get_jvm_class_path(std::vector<zstring>& path) const
+{
+  path.insert(path.end(), theJVMClassPath.begin(), theJVMClassPath.end());
+}
+
+/*******************************************************************************
+
+********************************************************************************/
+void static_context::get_full_jvm_class_path(std::vector<zstring>& path) const
+{
+  if (theParent != NULL)
+  {
+    theParent->get_full_jvm_class_path(path);
+  }
+
+  get_jvm_class_path(path);
+}
+
+
 /////////////////////////////////////////////////////////////////////////////////
 //                                                                             //
 //  Validating Items                                                           //

=== modified file 'src/context/static_context.h'
--- src/context/static_context.h	2012-03-07 15:49:25 +0000
+++ src/context/static_context.h	2012-03-07 16:55:14 +0000
@@ -509,6 +509,8 @@
 
   ExternalModuleMap                     * theExternalModulesMap;
 
+  checked_vector<zstring>                 theJVMClassPath;
+
   rchandle<TypeManager>                   theTypeManager;
 
   NamespaceBindings                     * theNamespaceBindings;
@@ -712,6 +714,15 @@
   void get_full_lib_path(std::vector<zstring>& oLibPath) const;
 
   //
+  // JVM classpath
+  //
+  void set_jvm_class_path(const std::vector<zstring>& aClassPath);
+
+  void get_jvm_class_path(std::vector<zstring>& oClassPath) const;
+
+  void get_full_jvm_class_path(std::vector<zstring>& path) const;
+
+	//
   // Validating Items
   //
   bool validate(

=== modified file 'src/store/naive/store_properties.h'
--- src/store/naive/store_properties.h	2012-02-28 20:57:22 +0000
+++ src/store/naive/store_properties.h	2012-03-07 16:55:14 +0000
@@ -23,65 +23,47 @@
 
 #ifndef ZORBA_STORE_STOREPROPERTIES
 #define ZORBA_STORE_STOREPROPERTIES
-namespace zorba 
-{ 
-namespace store 
-{
-
- 
-class StoreProperties : public ::zorba::PropertiesBase 
-{
+namespace zorba { namespace store { 
+class StoreProperties : public ::zorba::PropertiesBase {
 protected:
-  const char** get_all_options() const 
-  {
+  const char **get_all_options () const {
     static const char *result [] = { "--build-dataguide", "--store-trace-level", NULL };
     return result;
   }
-
   bool theBuildDataguide;
   long theStoreTraceLevel;
 
-  void initialize () 
-  {
+  void initialize () {
     theBuildDataguide = false;
     theStoreTraceLevel = 0;
   }
 public:
-  const bool& buildDataguide() const { return theBuildDataguide; }
-  const long& storeTraceLevel() const { return theStoreTraceLevel; }
+  const bool &buildDataguide () const { return theBuildDataguide; }
+  const long &storeTraceLevel () const { return theStoreTraceLevel; }
 
-  std::string load_argv(int argc, const char **argv) 
-  {
+  std::string load_argv (int argc, const char **argv) {
     if (argv == NULL) return "";
 
     std::string result;
-    for (++argv; *argv != NULL; ++argv) 
-    {
+    for (++argv; *argv != NULL; ++argv) {
       if (strcmp (*argv, "--help") == 0 || strcmp (*argv, "-h") == 0)
         return "!HELP";
       else if (strcmp (*argv, "--version") == 0)
         return "!VER";
-      else if (strcmp (*argv, "--build-dataguide") == 0) 
-      {
+      else if (strcmp (*argv, "--build-dataguide") == 0) {
         theBuildDataguide = true;
       }
-      else if (strcmp (*argv, "--store-trace-level") == 0) 
-      {
+      else if (strcmp (*argv, "--store-trace-level") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --store-trace-level option"; break; }        init_val (*argv, theStoreTraceLevel, d);
       }
-      else if (strcmp (*argv, "--") == 0) 
-      {
+      else if (strcmp (*argv, "--") == 0) {
         copy_args (++argv);
         break;
-      }
-      else if ((*argv) [0] == '-') 
-      {
+      } else if ((*argv) [0] == '-') {
         result = "unknown command line option "; result += *argv; break; 
-      }
-      else
-      {
+      } else {
         copy_args (argv);
         break;
       }
@@ -90,21 +72,20 @@
     return result;
   }
 
-  const char* get_help_msg () const 
-  {
+  const char *get_help_msg () const {
     return
 "--build-dataguide\nbuild-dataguide (true/false)\n\n"
 "--store-trace-level\nstore trace level (<= 0 : no tracing)\n\n"
 ;
   }
 
-  static const StoreProperties* instance() 
-  {
+  static const StoreProperties *instance () {
     static StoreProperties result;
     return &result;
   }
 
-  StoreProperties() { initialize(); }
+  StoreProperties () { initialize (); }
+  
 };
 
 } }   // namespaces

=== modified file 'src/system/properties.h'
--- src/system/properties.h	2011-06-14 17:26:33 +0000
+++ src/system/properties.h	2012-03-07 16:55:14 +0000
@@ -67,6 +67,27 @@
 
   std::ostream& debug_out() { return *debug_stream; }
 
+  /**
+    * Before the JVM is started this will return the classpath set by
+    * command line option, the CLASSPATH environment variable and in Zorba
+    * config file.
+    *
+    * After the JVM is started this will contain in addition the paths to jars
+    * used by modules that make use of the JVM.
+    */
+  void getJVMClassPath(std::string & jvmClasspath)
+  { jvmClasspath = theCLASSPATH ; }
+
+  /**
+    * This method should be used to set additional JVM classpath for modules
+    * that make use of JVM. This will overide the classpath set by CLASSPATH
+    * environment variable or Zorba config file.
+    *
+    * Once the JVM is started this method doesn't have any effect.
+    */
+  void setJVMClassPath(const std::string & jvmClasspath)
+  { theCLASSPATH = jvmClasspath; }
+
  protected:
   /**
    * Gets the Operation System folder where the properties of the current 

=== modified file 'src/system/zorba_properties.h'
--- src/system/zorba_properties.h	2012-02-28 20:57:22 +0000
+++ src/system/zorba_properties.h	2012-03-07 16:55:14 +0000
@@ -23,20 +23,13 @@
 
 #ifndef ZORBA_ZORBAPROPERTIES
 #define ZORBA_ZORBAPROPERTIES
-namespace zorba 
-{ 
-
-class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesBase 
-{
+namespace zorba { 
+class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesGlobal {
 protected:
-  const char** get_all_options() const 
-  {
-    static const char* result [] = 
-      { "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer", "--result-file", "--debug-file", "--abort", "--query", "--print-query", "--print-time", "--print-ast", "--print-xqdoc", "--print-translated", "--print-normalized", "--print-optimized", "--print-iterator-tree", "--print-item-flow", "--print-static-types", "--dump-lib", "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt", "--print-locations", "--force-gflwor", "--reorder-globals", "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting", "--infer-joins", "--no-copy-optim", "--serialize-only-query", "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug", "--compile-only", "--tz", "--external-var", "--serializer-param", "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth", NULL };
-
+  const char **get_all_options () const {
+    static const char *result [] = { "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer", "--result-file", "--debug-file", "--abort", "--query", "--print-query", "--print-time", "--print-ast", "--print-xqdoc", "--print-translated", "--print-normalized", "--print-optimized", "--print-iterator-tree", "--print-item-flow", "--print-static-types", "--dump-lib", "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt", "--print-locations", "--force-gflwor", "--reorder-globals", "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting", "--infer-joins", "--no-copy-optim", "--serialize-only-query", "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug", "--compile-only", "--tz", "--external-var", "--serializer-param", "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth", "--CLASSPATH", NULL };
     return result;
   }
-
   bool theTraceParsing;
   bool theTraceScanning;
   bool theUseSerializer;
@@ -68,7 +61,7 @@
   bool theLoopHoisting;
   bool theInferJoins;
   bool theNoCopyOptim;
-  int theSerializeOnlyQuery;
+  bool theSerializeOnlyQuery;
   bool theTraceTranslator;
   bool theTraceCodegen;
   bool theTraceFulltext;
@@ -80,9 +73,9 @@
   bool theIterPlanTest;
   std::string theDotPlanFile;
   uint32_t theMaxUdfCallDepth;
+  std::string theCLASSPATH;
 
-  void initialize() 
-  {
+  void initialize () {
     theTraceParsing = false;
     theTraceScanning = false;
     theUseSerializer = false;
@@ -111,7 +104,7 @@
     theLoopHoisting = true;
     theInferJoins = true;
     theNoCopyOptim = true;
-    theSerializeOnlyQuery = -1;
+    theSerializeOnlyQuery = false;
     theTraceTranslator = false;
     theTraceCodegen = false;
     theTraceFulltext = false;
@@ -120,7 +113,6 @@
     theIterPlanTest = false;
     theMaxUdfCallDepth = 1024;
   }
-
 public:
   const bool &traceParsing () const { return theTraceParsing; }
   const bool &traceScanning () const { return theTraceScanning; }
@@ -152,8 +144,8 @@
   const bool &inlineUdf () const { return theInlineUdf; }
   const bool &loopHoisting () const { return theLoopHoisting; }
   const bool &inferJoins () const { return theInferJoins; }
-  const bool &noCopyOptim() const { return theNoCopyOptim; }
-  const int& serializeOnlyQuery() const { return theSerializeOnlyQuery; }
+  const bool &noCopyOptim () const { return theNoCopyOptim; }
+  const bool &serializeOnlyQuery () const { return theSerializeOnlyQuery; }
   const bool &traceTranslator () const { return theTraceTranslator; }
   const bool &traceCodegen () const { return theTraceCodegen; }
   const bool &traceFulltext () const { return theTraceFulltext; }
@@ -165,9 +157,9 @@
   const bool &iterPlanTest () const { return theIterPlanTest; }
   const std::string &dotPlanFile () const { return theDotPlanFile; }
   const uint32_t &maxUdfCallDepth () const { return theMaxUdfCallDepth; }
+  const std::string &CLASSPATH () const { return theCLASSPATH; }
 
-  std::string load_argv (int argc, const char **argv) 
-  {
+  std::string load_argv (int argc, const char **argv) {
     if (argv == NULL) return "";
 
     std::string result;
@@ -188,14 +180,12 @@
       else if (strcmp (*argv, "--optimizer") == 0 || strncmp (*argv, "-O", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }
-        init_val (*argv, theOptimizer, d);
+        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }        init_val (*argv, theOptimizer, d);
       }
       else if (strcmp (*argv, "--result-file") == 0 || strncmp (*argv, "-o", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --result-file option"; break; }
-        init_val (*argv, theResultFile, d);
+        if (*argv == NULL) { result = "No value given for --result-file option"; break; }        init_val (*argv, theResultFile, d);
       }
       else if (strcmp (*argv, "--debug-file") == 0) {
         int d = 2;
@@ -290,20 +280,15 @@
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --infer-joins option"; break; }        init_val (*argv, theInferJoins, d);
       }
-      else if (strcmp (*argv, "--no-copy-optim") == 0)
-      {
+      else if (strcmp (*argv, "--no-copy-optim") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --no-copy-optim option"; break; }
-        init_val (*argv, theNoCopyOptim, d);
+        if (*argv == NULL) { result = "No value given for --no-copy-optim option"; break; }        init_val (*argv, theNoCopyOptim, d);
       }
-      else if (strcmp (*argv, "--serialize-only-query") == 0)
-      {
+      else if (strcmp (*argv, "--serialize-only-query") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL)
-        { result = "No value given for --serialize-only-query option"; break; }
-        init_val(*argv, theSerializeOnlyQuery, d);
+        if (*argv == NULL) { result = "No value given for --serialize-only-query option"; break; }        init_val (*argv, theSerializeOnlyQuery, d);
       }
 #ifndef NDEBUG
       else if (strcmp (*argv, "--trace-translator") == 0 || strncmp (*argv, "-l", 2) == 0) {
@@ -350,6 +335,11 @@
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --max-udf-call-depth option"; break; }        init_val (*argv, theMaxUdfCallDepth, d);
       }
+      else if (strcmp (*argv, "--CLASSPATH") == 0) {
+        int d = 2;
+        if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
+        if (*argv == NULL) { result = "No value given for --CLASSPATH option"; break; }        init_val (*argv, theCLASSPATH, d);
+      }
       else if (strcmp (*argv, "--") == 0) {
         copy_args (++argv);
         break;
@@ -364,9 +354,7 @@
     return result;
   }
 
-
-  const char* get_help_msg() const 
-  {
+  const char *get_help_msg () const {
     return
 "--trace-parsing, -p\ntrace parsing\n\n"
 "--trace-scanning, -s\ntrace scanning\n\n"
@@ -398,8 +386,8 @@
 "--inline-udf\ninline functions (1=enabled (default), 0=off)\n\n"
 "--loop-hoisting\nhoist expressions out of loops (1=enabled (default), 0=off)\n\n"
 "--infer-joins\ninfer joins (1=enabled (default), 0=off)\n\n"
-"--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n"
-"--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n"
+"--no-copy-optim\nno copy optim (1=enabled (default), 0=off)\n\n"
+"--serialize-only-query\nserialize-only query (1=true, 0=false (default))\n\n"
 #ifndef NDEBUG
 "--trace-translator, -l\ntrace the translator\n\n"
 "--trace-codegen, -c\ntrace the codegenerator\n\n"
@@ -413,19 +401,19 @@
 "--iter-plan-test\nrun as iterator plan test\n\n"
 "--dot-plan-file\ngenerate the dot iterator plan\n\n"
 "--max-udf-call-depth\nmaximum stack depth of udf function calls\n\n"
+"--CLASSPATH\nJVM classpath to be used by modules using Java implementations\n\n"
 ;
   }
 
-  static const ZorbaProperties* instance() 
-  {
+  static const ZorbaProperties *instance () {
     static ZorbaProperties result;
     return &result;
   }
 
-  ZorbaProperties() { initialize (); }
+  ZorbaProperties () { initialize (); }
+  
 };
 
-
 }   // namespaces
 
 #endif // ZORBA_ZORBAPROPERTIES

=== modified file 'src/system/zorba_properties.txt'
--- src/system/zorba_properties.txt	2012-02-28 20:57:22 +0000
+++ src/system/zorba_properties.txt	2012-03-07 16:55:14 +0000
@@ -43,3 +43,4 @@
       ("iter-plan-test", "run as iterator plan test")
       ("dot-plan-file", po::value<std::string>(), "generate the dot iterator plan")
       ("max-udf-call-depth", po::value<uint32_t>()->default_value(1024), "maximum stack depth of udf function calls")
+      ("CLASSPATH", po::value<std::string>(), "JVM classpath to be used by modules using Java implementations")
\ No newline at end of file

=== modified file 'src/util/file.cpp'
--- src/util/file.cpp	2011-06-14 17:26:33 +0000
+++ src/util/file.cpp	2012-03-07 16:55:14 +0000
@@ -277,6 +277,18 @@
 #endif
 }
 
+void file::lsdir(std::vector<std::string> &list) {
+#ifdef ZORBA_WITH_FILE_ACCESS
+  try {
+    fs::lsdir( c_str(), list );
+    set_filetype( type_directory );
+  }
+  catch ( fs::exception const &e ) {
+    throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
+  }
+#endif
+}
+
 void file::deep_mkdir() {
 #ifdef ZORBA_WITH_FILE_ACCESS
   vector<file> files;

=== modified file 'src/util/fs_util.cpp'
--- src/util/fs_util.cpp	2011-07-17 00:10:56 +0000
+++ src/util/fs_util.cpp	2012-03-07 16:55:14 +0000
@@ -277,6 +277,41 @@
 #endif
 }
 
+void lsdir( char const *path, std::vector<std::string> &list )
+{
+#ifndef WIN32
+  DIR *dir;
+  struct dirent *ent;
+
+  dir = opendir (path);
+  if (dir != NULL)
+  {
+    /* print all the files and directories within directory */
+    while ((ent = readdir (dir)) != NULL)
+    {
+      //printf ("%s\n", ent->d_name);
+      std::string item(ent->d_name);
+      list.push_back(item);
+    }
+    closedir (dir);
+  }
+  else
+  {
+    /* could not open directory */
+    throw fs::exception( "lsdir()", path );
+  }
+#else
+  WCHAR wpath[ MAX_PATH ];
+  win32::to_wchar( path, wpath );
+  //if ( !::CreateDirectory( wpath, NULL ) )
+    throw fs::exception( "LsDirectory() not implemented", path );
+  /* check FindFirstFile / FindNextFile / FindClose Win32 functions
+     http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
+     http://msdn.microsoft.com/en-us/library/aa365200%28v=vs.85%29.aspx
+   */
+#endif
+}
+
 bool remove( char const *path ) {
 #ifndef WIN32
   return ::remove( path ) == 0;

=== modified file 'src/util/fs_util.h'
--- src/util/fs_util.h	2011-07-17 20:05:49 +0000
+++ src/util/fs_util.h	2012-03-07 16:55:14 +0000
@@ -17,6 +17,9 @@
 #ifndef ZORBA_FS_UTIL_H
 #define ZORBA_FS_UTIL_H
 
+#include <vector>
+#include <dirent.h>
+
 #include <zorba/config.h>
 
 #include <stdexcept>
@@ -144,6 +147,26 @@
   mkdir( path.c_str() );
 }
 
+/**
+ * List files in dir
+ *
+ * @param path The full path of the directory to list.
+ * @throws fs::exception if the list fails.
+ */
+void lsdir( char const *path, std::vector<std::string> & list );
+
+/**
+ * List files in dir
+ *
+ * @tparam PathStringType The \a path string type.
+ * @param path The full path of the directory to list.
+ * @throws fs::exception if the list fails.
+ */
+template<class PathStringType> inline
+void lsdir( PathStringType const &path, std::vector<std::string> & list ) {
+  lsdir( path.c_str(), list );
+}
+
 #endif /* ZORBA_WITH_FILE_ACCESS */
 
 ////////// File creation //////////////////////////////////////////////////////

=== modified file 'swig/XQuery.i'
--- swig/XQuery.i	2011-10-17 22:42:10 +0000
+++ swig/XQuery.i	2012-03-07 16:55:14 +0000
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+
 %{  // start Implementation
 
 class Iterator 
@@ -67,6 +68,40 @@
 }; // class Iterator
 
 
+
+
+
+class IStream
+{
+private:
+  std::istream* theIStream;
+
+public:
+  IStream() {}
+  IStream(const IStream& anIStream) : theIStream(anIStream.theIStream) {}
+  IStream(std::istream& anIStream)   : theIStream(&anIStream) {}
+
+  std::string readToString()
+  {
+    std::stringstream lStream;
+
+    lStream << theIStream;
+    return lStream.str();
+  }
+
+
+  int read(char *BYTE, int LENGTH)
+  {
+    theIStream->read(BYTE, LENGTH);
+    //theIStream->read(byteArray, len);
+    int readLength = theIStream->gcount();
+    return readLength;
+  }
+
+
+}; // class IStream
+
+
 class Item 
 {
   friend class Iterator;
@@ -84,13 +119,10 @@
   Item(const Item& aItem) : theItem(aItem.theItem) {}
   Item(const zorba::Item& aZItem) : theItem(aZItem) {}
 
-  static Item createEmptyItem() 
+  static Item createEmptyItem()
   { return Item(); }
 
-  std::string getStringValue() const 
-  { return std::string(theItem.getStringValue().c_str()); }
-  
-  std::string serialize() const 
+  std::string serialize() const
   {
     std::stringstream lStream; 
     Zorba_SerializerOptions_t lOptions; 
@@ -100,6 +132,22 @@
     return lStream.str();
   }
   
+  void serializeToOutputStream(std::ostream &outStream) const
+  {
+    Zorba_SerializerOptions_t lOptions;
+    zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(lOptions);
+    zorba::SingletonItemSequence lSequence(theItem);
+    lSerializer->serialize(&lSequence, outStream);
+  }
+
+  IStream getStream()
+  {
+    return IStream(theItem.getStream());
+  }
+
+  std::string getStringValue() const
+  { return std::string(theItem.getStringValue().c_str()); }
+
   Iterator getAtomizationValue () const
   { return Iterator(theItem.getAtomizationValue()); }
   
@@ -274,11 +322,15 @@
 }
 
 
-%}  // end   Implementation
+
+%}          // end   Implementation
+
 
 
 // Interfaces
 
+
+
 class DynamicContext
 {
 public:
@@ -292,12 +344,25 @@
   setContextItem(Item);
 };
 
-class Item 
+
+class IStream
+{
+public:
+  std::string readToString();
+  int read(char * BYTE, long LENGTH);
+}; // class IStream
+
+
+class Item
 {
 public: 
   static Item createEmptyItem();
+
+  std::string serialize() const;
+  void serializeToOutputStream(std::ostream &outStream) const;
+  IStream getStream();
+
   std::string getStringValue() const;
-  std::string serialize() const;
   Iterator getAtomizationValue () const;
   Iterator getAttributes () const;
   bool getBooleanValue () const;
@@ -319,6 +384,7 @@
   bool isPosOrNegInf () const;
 }; // class Item
 
+
 class Iterator 
 {
 public:
@@ -328,6 +394,7 @@
   void destroy();
 }; // class Iterator
 
+
 class XQuery 
 {
 public:

=== modified file 'swig/java/CMakeLists.txt'
--- swig/java/CMakeLists.txt	2011-10-12 20:56:27 +0000
+++ swig/java/CMakeLists.txt	2012-03-07 16:55:14 +0000
@@ -21,7 +21,7 @@
   include (CMakeJavaInformation )
   MESSAGE(STATUS "SWIG Java: generating Java API")
 
-  # EXECUTE_PROCESS( COMMAND ${JAVA_RUNTIME} -version OUTPUT_VARIABLE JAVA_VERSION )
+  EXECUTE_PROCESS( COMMAND ${JAVA_RUNTIME} -version OUTPUT_VARIABLE JAVA_VERSION )
   MESSAGE(STATUS "SWIG Java: JNI found at: " ${JAVA_INCLUDE_PATH} )
 
   SET_SOURCE_FILES_PROPERTIES( zorba_api.i PROPERTIES CPLUSPLUS ON )
@@ -89,6 +89,9 @@
 		ENDIF(NOT WIN32)
   ENDIF ( APPLE )
 
+EXECUTE_PROCESS( COMMAND ${JAVA_RUNTIME} -version OUTPUT_VARIABLE JAVA_VERSION )
+# todo cezar compile and jar it up
+
 ELSE (JAVA_INCLUDE_PATH)
   MESSAGE ( STATUS "SWIG Java: not generating JAVA API because jni headers not found.")
 ENDIF (JAVA_INCLUDE_PATH)

=== added file 'swig/various.i'
--- swig/various.i	1970-01-01 00:00:00 +0000
+++ swig/various.i	2012-03-07 16:55:14 +0000
@@ -0,0 +1,184 @@
+/* This is from http://www.opensource.apple.com/source/swig/swig-6/swig/Lib/java/various.i?txt */
+
+/* -----------------------------------------------------------------------------
+ * See the LICENSE file for information on copyright, usage and redistribution
+ * of SWIG, and the README file for authors - http://www.swig.org/release.html.
+ *
+ * various.i
+ *
+ * SWIG Typemap library for Java.
+ * Various useful typemaps.
+ * ----------------------------------------------------------------------------- */
+
+#ifdef SWIGJAVA
+
+/*
+ * char **STRING_ARRAY typemaps.
+ * These typemaps are for C String arrays which are NULL terminated.
+ *   char *values[] = { "one", "two", "three", NULL }; // note NULL
+ * char ** is mapped to a Java String[].
+ *
+ * Example usage wrapping:
+ *   %apply char **STRING_ARRAY { char **input };
+ *   char ** foo(char **input);
+ *
+ * Java usage:
+ *   String numbers[] = { "one", "two", "three" };
+ *   String[] ret = modulename.foo( numbers };
+ */
+%typemap(jni) char **STRING_ARRAY "jobjectArray"
+%typemap(jtype) char **STRING_ARRAY "String[]"
+%typemap(jstype) char **STRING_ARRAY "String[]"
+%typemap(in) char **STRING_ARRAY (jint size) {
+    int i = 0;
+    size = JCALL1(GetArrayLength, jenv, $input);
+#ifdef __cplusplus
+    $1 = new char*[size+1];
+#else
+    $1 = (char **)calloc(size+1, sizeof(char *));
+#endif
+    for (i = 0; i<size; i++) {
+        jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
+        const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
+#ifdef __cplusplus
+        $1[i] = new char [strlen(c_string)+1];
+#else
+        $1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
+#endif
+        strcpy($1[i], c_string);
+        JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
+        JCALL1(DeleteLocalRef, jenv, j_string);
+    }
+    $1[i] = 0;
+}
+
+%typemap(freearg) char **STRING_ARRAY {
+    int i;
+    for (i=0; i<size$argnum-1; i++)
+#ifdef __cplusplus
+      delete[] $1[i];
+    delete[] $1;
+#else
+      free($1[i]);
+    free($1);
+#endif
+}
+
+%typemap(out) char **STRING_ARRAY {
+    int i;
+    int len=0;
+    jstring temp_string;
+    const jclass clazz = JCALL1(FindClass, jenv, "java/lang/String");
+
+    while ($1[len]) len++;
+    jresult = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
+    /* exception checking omitted */
+
+    for (i=0; i<len; i++) {
+      temp_string = JCALL1(NewStringUTF, jenv, *result++);
+      JCALL3(SetObjectArrayElement, jenv, jresult, i, temp_string);
+      JCALL1(DeleteLocalRef, jenv, temp_string);
+    }
+}
+
+%typemap(javain) char **STRING_ARRAY "$javainput"
+%typemap(javaout) char **STRING_ARRAY  {
+    return $jnicall;
+  }
+
+/*
+ * char **STRING_OUT typemaps.
+ * These are typemaps for returning strings when using a C char ** parameter type.
+ * The returned string appears in the 1st element of the passed in Java String array.
+ *
+ * Example usage wrapping:
+ *   void foo(char **string_out);
+ *
+ * Java usage:
+ *   String stringOutArray[] = { "" };
+ *   modulename.foo(stringOutArray);
+ *   System.out.println( stringOutArray[0] );
+ */
+%typemap(jni) char **STRING_OUT "jobjectArray"
+%typemap(jtype) char **STRING_OUT "String[]"
+%typemap(jstype) char **STRING_OUT "String[]"
+%typemap(javain) char **STRING_OUT "$javainput"
+
+%typemap(in) char **STRING_OUT($*1_ltype temp) {
+  if (!$input) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
+    return $null;
+  }
+  if (JCALL1(GetArrayLength, jenv, $input) == 0) {
+    SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
+    return $null;
+  }
+  $1 = &temp;
+}
+
+%typemap(argout) char **STRING_OUT {
+  jstring jnewstring = NULL;
+  if($1) {
+     jnewstring = JCALL1(NewStringUTF, jenv, *$1);
+  }
+  JCALL3(SetObjectArrayElement, jenv, $input, 0, jnewstring);
+}
+
+/*
+ * char *BYTE typemaps.
+ * These are input typemaps for mapping a Java byte[] array to a C char array.
+ * Note that as a Java array is used and thus passeed by reference, the C routine
+ * can return data to Java via the parameter.
+ *
+ * Example usage wrapping:
+ *   void foo(char *array);
+ *
+ * Java usage:
+ *   byte b[] = new byte[20];
+ *   modulename.foo(b);
+ */
+%typemap(jni) char *BYTE "jbyteArray"
+%typemap(jtype) char *BYTE "byte[]"
+%typemap(jstype) char *BYTE "byte[]"
+%typemap(in) char *BYTE {
+    $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
+}
+
+%typemap(argout) char *BYTE {
+    JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
+}
+
+%typemap(javain) char *BYTE "$javainput"
+
+/* Prevent default freearg typemap from being used */
+%typemap(freearg) char *BYTE ""
+
+#else
+
+#endif
+
+
+/*  %include "typemaps.i"
+
+#if defined(SWIGJAVA)
+
+%typemap(in)     (char * BYTE, int LENGTH)
+{
+    // Functions from jni.h
+    $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
+    $2 = (int)    JCALL1(GetArrayLength,       jenv, $input);
+}
+
+%typemap(jni)    (char * BYTE, int LENGTH) "jbyteArray"
+%typemap(jtype)  (char * BYTE, int LENGTH) "byte[]"
+%typemap(jstype) (char * BYTE, int LENGTH) "byte[]"
+%typemap(javain) (char * BYTE, int LENGTH) "$javainput"
+
+// Specify signature of method to handle
+%apply (char * BYTE, int LENGTH)   { (char * byteArray, long len) };
+
+#else
+%apply (char * BYTE, int LENGTH)   { (char * byteArray, long len) };
+#endif
+
+*/

=== modified file 'swig/zorba_api.i'
--- swig/zorba_api.i	2011-10-12 20:56:27 +0000
+++ swig/zorba_api.i	2012-03-07 16:55:14 +0000
@@ -14,7 +14,10 @@
  * limitations under the License.
  */
 
-%module zorba_api
+%module(directors="1") zorba_api
+
+/*%feature("director") IStream;*/
+
 %include "std_string.i"
 %include "exception.i"
 
@@ -34,6 +37,8 @@
   }
 }
 
+
+
 %{  // Implementations
 
 
@@ -52,6 +57,7 @@
   class Item;
   class Iterator;
   class XQuery;
+  class IStream;
   class Store;
   class Zorba;
 
@@ -70,6 +76,7 @@
 %}
 
 
+%include "various.i"
 
 %include "XQuery.i"
 %include "Store.i"

=== modified file 'test/rbkt/modules/CMakeLists.txt'
--- test/rbkt/modules/CMakeLists.txt	2012-02-15 10:25:02 +0000
+++ test/rbkt/modules/CMakeLists.txt	2012-03-07 16:55:14 +0000
@@ -58,3 +58,5 @@
 # This is as good a place as any to test this feature
 DECLARE_ZORBA_URI_FILE(FILE "random-file.txt"
   URI "http://www.zorba-xquery.com/random-file"; TEST_ONLY)
+
+ADD_SUBDIRECTORY(java)

=== added directory 'test/rbkt/modules/java'
=== added file 'test/rbkt/modules/java/CMakeLists.txt'
--- test/rbkt/modules/java/CMakeLists.txt	1970-01-01 00:00:00 +0000
+++ test/rbkt/modules/java/CMakeLists.txt	2012-03-07 16:55:14 +0000
@@ -0,0 +1,39 @@
+# Copyright 2006-2008 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.
+
+# For now we only test building a .jar that we want Zorba to make available
+# on the JVM claspath. This test scenario should be extended to include a
+# Zorba module using the .jar, etc.
+# We make use of the much-improved Java support added in CMake 2.8.6.
+COMPARE_VERSION_STRINGS (${CMAKE_VERSION} "2.8.6" RESULT)
+IF (${RESULT} GREATER -1)
+  FIND_PACKAGE (Java COMPONENTS Development)
+  IF (Java_Development_FOUND)
+    INCLUDE (UseJava)
+
+    # Declare two "different" jars, for testing
+    ADD_JAR (JavaTest Test.java)
+    ADD_JAR (JavaTest2 Test.java)
+
+    # Tell Zorba about the jars
+    GET_PROPERTY (JavaTest_JAR_FILE TARGET JavaTest PROPERTY JAR_FILE)
+    GET_PROPERTY (JavaTest2_JAR_FILE TARGET JavaTest2 PROPERTY JAR_FILE)
+    DECLARE_ZORBA_JAR(FILE ${JavaTest_JAR_FILE} ${JavaTest2_JAR_FILE} TEST_ONLY)
+
+    # Pretend to tell Zorba about some system jars
+    DECLARE_ZORBA_JAR(EXTERNAL FILE
+      "${PROJECT_SOURCE_DIR}/MyJar.jar" "${PROJECT_SOURCE_DIR}/MyJar2.jar")
+
+  ENDIF (Java_Development_FOUND)
+ENDIF (${RESULT} GREATER -1)

=== added file 'test/rbkt/modules/java/Test.java'
--- test/rbkt/modules/java/Test.java	1970-01-01 00:00:00 +0000
+++ test/rbkt/modules/java/Test.java	2012-03-07 16:55:14 +0000
@@ -0,0 +1,7 @@
+package org.zorbaxquery;
+
+public class Test {
+    public static void main(String[] args) {
+	System.out.println("Hello, world");
+    }
+}


Follow ups