zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #06540
[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:
Matthias Brantner (matthias-brantner)
Chris Hillery (ceejatec)
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/98224
Add java classpath to zorbacmd and to Zorba API.
Fix dynamic libraries loading.
Tested it works on Windows with both xsl-fo and xmlbeans modules. All tests are passing.
Fixed ExternalModule integration, fixed comment and indentation of previously property generated files: src/system/zorba_properties.h and bin/zorbacmdproperties_base.h.
--
https://code.launchpad.net/~zorba-coders/zorba/module-schema-tools/+merge/98224
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'NOTICE.txt'
--- NOTICE.txt 2012-03-14 15:28:15 +0000
+++ NOTICE.txt 2012-03-19 16:19:41 +0000
@@ -459,6 +459,24 @@
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty.
+----------------------------------------------------
+
+src/util/win32/dirent.h
+
+Copyright: 2006 Toni Ronkko
+
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ ``Software''), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+
External libraries used by this project:
----------------------------------------------------
=== modified file 'NOTICE.xml'
--- NOTICE.xml 2012-01-11 15:56:57 +0000
+++ NOTICE.xml 2012-03-19 16:19:41 +0000
@@ -423,6 +423,22 @@
without express or implied warranty.
</foreign-notice>
</foreign-files>
+ <foreign-files>
+ <file>src/util/win32/dirent.h</file>
+ <copyright>2006 Toni Ronkko</copyright>
+ <foreign-notice>
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ ``Software''), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be included
+ in all copies or substantial portions of the Software.
+ </foreign-notice>
+ </foreign-files>
<external-lib mandatory="true">
<name>LIBXML2</name>
=== modified file 'bin/path_util.cpp'
--- bin/path_util.cpp 2012-01-11 15:56:57 +0000
+++ bin/path_util.cpp 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ bin/path_util.h 2012-03-19 16:19:41 +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-03-14 15:28:15 +0000
+++ bin/zorbacmd.cpp 2012-03-19 16:19:41 +0000
@@ -787,6 +787,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 2012-01-11 15:56:57 +0000
+++ bin/zorbacmdproperties.cpp 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ bin/zorbacmdproperties.h 2012-03-19 16:19:41 +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-29 11:10:30 +0000
+++ bin/zorbacmdproperties.txt 2012-03-19 16:19:41 +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-29 11:10:30 +0000
+++ bin/zorbacmdproperties_base.h 2012-03-19 16:19:41 +0000
@@ -15,13 +15,6 @@
*/
/* vim:set et sw=2 ts=2: */
-// ******************************************
-// * *
-// * THIS IS A GENERATED FILE. DO NOT EDIT! *
-// * SEE .txt FILE WITH SAME NAME *
-// * *
-// ******************************************
-
#include <string>
#include <sstream>
#include <zorba/config.h>
@@ -30,13 +23,29 @@
#ifndef ZORBACMD_ZORBACMDPROPERTIESBASE
#define ZORBACMD_ZORBACMDPROPERTIESBASE
-namespace zorbacmd {
-class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase {
+namespace zorbacmd
+{
+
+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 };
+ 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", "--classpath",
+ "--option", "--trailing-nl", "--stop-words", "--thesaurus",
+ "--compile-plan", "--execute-plan", NULL };
return result;
}
+
bool theTiming;
std::string theOutputFile;
std::vector<std::string> theSerializationParameter;
@@ -70,6 +79,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 +146,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; }
@@ -158,12 +169,16 @@
else if (strcmp (*argv, "--output-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 --output-file option"; break; } init_val (*argv, theOutputFile, d);
+ if (*argv == NULL) { result = "No value given for --output-file option"; break; }
+
+ init_val (*argv, theOutputFile, d);
}
else if (strcmp (*argv, "--serialization-parameter") == 0 || strncmp (*argv, "-z", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --serialization-parameter option"; break; } init_val (*argv, theSerializationParameter, d);
+ if (*argv == NULL) { result = "No value given for --serialization-parameter option"; break; }
+
+ init_val (*argv, theSerializationParameter, d);
}
else if (strcmp (*argv, "--serialize-html") == 0) {
theSerializeHtml = true;
@@ -189,37 +204,51 @@
else if (strcmp (*argv, "--base-uri") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --base-uri option"; break; } init_val (*argv, theBaseUri, d);
+ if (*argv == NULL) { result = "No value given for --base-uri option"; break; }
+
+ init_val (*argv, theBaseUri, d);
}
else if (strcmp (*argv, "--boundary-space") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --boundary-space option"; break; } init_val (*argv, theBoundarySpace, d);
+ if (*argv == NULL) { result = "No value given for --boundary-space option"; break; }
+
+ init_val (*argv, theBoundarySpace, d);
}
else if (strcmp (*argv, "--default-collation") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --default-collation option"; break; } init_val (*argv, theDefaultCollation, d);
+ if (*argv == NULL) { result = "No value given for --default-collation option"; break; }
+
+ init_val (*argv, theDefaultCollation, d);
}
else if (strcmp (*argv, "--construction-mode") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --construction-mode option"; break; } init_val (*argv, theConstructionMode, d);
+ if (*argv == NULL) { result = "No value given for --construction-mode option"; break; }
+
+ init_val (*argv, theConstructionMode, d);
}
else if (strcmp (*argv, "--ordering-mode") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --ordering-mode option"; break; } init_val (*argv, theOrderingMode, d);
+ if (*argv == NULL) { result = "No value given for --ordering-mode option"; break; }
+
+ init_val (*argv, theOrderingMode, d);
}
else if (strcmp (*argv, "--multiple") == 0 || strncmp (*argv, "-m", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --multiple option"; break; } init_val (*argv, theMultiple, d);
+ if (*argv == NULL) { result = "No value given for --multiple option"; break; }
+
+ init_val (*argv, theMultiple, d);
}
else if (strcmp (*argv, "--query") == 0 || strncmp (*argv, "-q", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --query option"; break; } init_val (*argv, theQueriesOrFiles, d);
+ if (*argv == NULL) { result = "No value given for --query option"; break; }
+
+ init_val (*argv, theQueriesOrFiles, d);
}
else if (strcmp (*argv, "--as-files") == 0 || strncmp (*argv, "-f", 2) == 0) {
theAsFiles = true;
@@ -227,17 +256,23 @@
else if (strcmp (*argv, "--external-variable") == 0 || strncmp (*argv, "-e", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --external-variable option"; break; } init_val (*argv, theExternalVariable, d);
+ if (*argv == NULL) { result = "No value given for --external-variable option"; break; }
+
+ init_val (*argv, theExternalVariable, d);
}
else if (strcmp (*argv, "--context-item") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --context-item option"; break; } init_val (*argv, theContextItem, d);
+ if (*argv == NULL) { result = "No value given for --context-item option"; break; }
+
+ init_val (*argv, theContextItem, d);
}
else if (strcmp (*argv, "--optimization-level") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --optimization-level option"; break; } init_val (*argv, theOptimizationLevel, d);
+ if (*argv == NULL) { result = "No value given for --optimization-level option"; break; }
+
+ init_val (*argv, theOptimizationLevel, d);
}
else if (strcmp (*argv, "--lib-module") == 0 || strncmp (*argv, "-l", 2) == 0) {
theLibModule = true;
@@ -257,12 +292,16 @@
else if (strcmp (*argv, "--debug-host") == 0 || strncmp (*argv, "-h", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --debug-host option"; break; } init_val (*argv, theDebugHost, d);
+ if (*argv == NULL) { result = "No value given for --debug-host option"; break; }
+
+ init_val (*argv, theDebugHost, d);
}
else if (strcmp (*argv, "--debug-port") == 0 || strncmp (*argv, "-p", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --debug-port option"; break; } init_val (*argv, theDebugPort, d);
+ if (*argv == NULL) { result = "No value given for --debug-port option"; break; }
+
+ init_val (*argv, theDebugPort, d);
}
else if (strcmp (*argv, "--no-logo") == 0) {
theNoLogo = true;
@@ -270,27 +309,44 @@
else if (strcmp (*argv, "--timeout") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --timeout option"; break; } init_val (*argv, theTimeout, d);
+ if (*argv == NULL) { result = "No value given for --timeout option"; break; }
+
+ init_val (*argv, theTimeout, d);
}
else if (strcmp (*argv, "--uri-path") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --uri-path option"; break; } init_val (*argv, theUriPath, d);
+ if (*argv == NULL) { result = "No value given for --uri-path option"; break; }
+
+ init_val (*argv, theUriPath, d);
}
else if (strcmp (*argv, "--lib-path") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --lib-path option"; break; } init_val (*argv, theLibPath, d);
+ if (*argv == NULL) { result = "No value given for --lib-path option"; break; }
+
+ init_val (*argv, theLibPath, d);
}
else if (strcmp (*argv, "--module-path") == 0) {
int d = 2;
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);
+ 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; }
- if (*argv == NULL) { result = "No value given for --option option"; break; } init_val (*argv, theOption, d);
+ if (*argv == NULL) { result = "No value given for --option option"; break; }
+
+ init_val (*argv, theOption, d);
}
else if (strcmp (*argv, "--trailing-nl") == 0) {
theTrailingNl = true;
@@ -298,12 +354,16 @@
else if (strcmp (*argv, "--stop-words") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --stop-words option"; break; } init_val (*argv, theStopWords, d);
+ if (*argv == NULL) { result = "No value given for --stop-words option"; break; }
+
+ init_val (*argv, theStopWords, d);
}
else if (strcmp (*argv, "--thesaurus") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --thesaurus option"; break; } init_val (*argv, theThesaurus, d);
+ if (*argv == NULL) { result = "No value given for --thesaurus option"; break; }
+
+ init_val (*argv, theThesaurus, d);
}
else if (strcmp (*argv, "--compile-plan") == 0 || strncmp (*argv, "-c", 2) == 0) {
theCompilePlan = true;
@@ -327,46 +387,47 @@
const char *get_help_msg () const {
return
-"--timing, -t\nPrint timing information. In case of multiple queries the timing information is provided per each query. Both wallclock time and user time (which excludes I/O, network delays and other kernel waits) are shown.\n\n"
-"--output-file, -o\nWrite the result to the given file.\n\n"
-"--serialization-parameter, -z\nSet serialization parameter in the form of a parameter=value pair (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g.: -z method=xhtml -z doctype-system=DTD/xhtml1-strict.dtd -z indent=yes).\n\n"
-"--serialize-html\nSerialize the result as HTML.\n\n"
-"--serialize-text\nSerialize the result as Text.\n\n"
-"--indent, -i\nIndent output.\n\n"
-"--print-query\nPrint the queries.\n\n"
-"--print-errors-as-xml, -x\nPrint the errors as XML.\n\n"
-"--byte-order-mark\nSet the byte-order-mark for the serializer.\n\n"
-"--omit-xml-declaration, -r\nOmit the XML declaration from the result.\n\n"
-"--base-uri\nSet the base URI property of the static context.\n\n"
-"--boundary-space\nSet the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
-"--default-collation\nAdd the given collation and set the value of the default collation in the static context to the given collation.\n\n"
-"--construction-mode\nSet the construction mode ('strip' or 'preserve') in the static context.\n\n"
-"--ordering-mode\nSet the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
-"--multiple, -m\nExecute the given queries multiple times.\n\n"
-"--query, -q\nQuery test or file URI (file://...)\n\n"
-"--as-files, -f\nTreat all -q arguments as file paths instead of URIs or inline queries.\n\n"
-"--external-variable, -e\nProvide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
-"--context-item\nSet the context item to the XML document in a given file.\n\n"
-"--optimization-level\nOptimization level for the query compiler (O0, O1 or O2 - default: O1)\n\n"
-"--lib-module, -l\nQuery compiler option to treat the query as a library module. If this is set --compile-only option is also set to true.\n\n"
-"--parse-only\nStop after parsing the query.\n\n"
-"--compile-only\nOnly compile (don't execute)\n\n"
-"--no-serializer\nDo not serialize (discard) result.\n\n"
-"--debug, -d\nLaunch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
-"--debug-host, -h\nThe host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
-"--debug-port, -p\nThe port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
-"--no-logo\nPrint no logo when starting.\n\n"
-"--timeout\nSpecify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
-"--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"
-"--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"
-"--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
-"--compile-plan, -c\nOutput the query plan as binary.\n\n"
-"--execute-plan\nTake a query plan as binary and execute it. Binary query plans can be generated using the --compile-plan option.\n\n"
-;
+ "--timing, -t\nPrint timing information. In case of multiple queries the timing information is provided per each query. Both wallclock time and user time (which excludes I/O, network delays and other kernel waits) are shown.\n\n"
+ "--output-file, -o\nWrite the result to the given file.\n\n"
+ "--serialization-parameter, -z\nSet serialization parameter in the form of a parameter=value pair (see http://www.w3.org/TR/xslt-xquery-serialization/#serparam, e.g.: -z method=xhtml -z doctype-system=DTD/xhtml1-strict.dtd -z indent=yes).\n\n"
+ "--serialize-html\nSerialize the result as HTML.\n\n"
+ "--serialize-text\nSerialize the result as Text.\n\n"
+ "--indent, -i\nIndent output.\n\n"
+ "--print-query\nPrint the queries.\n\n"
+ "--print-errors-as-xml, -x\nPrint the errors as XML.\n\n"
+ "--byte-order-mark\nSet the byte-order-mark for the serializer.\n\n"
+ "--omit-xml-declaration, -r\nOmit the XML declaration from the result.\n\n"
+ "--base-uri\nSet the base URI property of the static context.\n\n"
+ "--boundary-space\nSet the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
+ "--default-collation\nAdd the given collation and set the value of the default collation in the static context to the given collation.\n\n"
+ "--construction-mode\nSet the construction mode ('strip' or 'preserve') in the static context.\n\n"
+ "--ordering-mode\nSet the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
+ "--multiple, -m\nExecute the given queries multiple times.\n\n"
+ "--query, -q\nQuery test or file URI (file://...)\n\n"
+ "--as-files, -f\nTreat all -q arguments as file paths instead of URIs or inline queries.\n\n"
+ "--external-variable, -e\nProvide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
+ "--context-item\nSet the context item to the XML document in a given file.\n\n"
+ "--optimization-level\nOptimization level for the query compiler (O0, O1 or O2 - default: O1)\n\n"
+ "--lib-module, -l\nQuery compiler option to treat the query as a library module. If this is set --compile-only option is also set to true.\n\n"
+ "--parse-only\nStop after parsing the query.\n\n"
+ "--compile-only\nOnly compile (don't execute)\n\n"
+ "--no-serializer\nDo not serialize (discard) result.\n\n"
+ "--debug, -d\nLaunch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
+ "--debug-host, -h\nThe host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
+ "--debug-port, -p\nThe port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
+ "--no-logo\nPrint no logo when starting.\n\n"
+ "--timeout\nSpecify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
+ "--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"
+ "--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
+ "--compile-plan, -c\nOutput the query plan as binary.\n\n"
+ "--execute-plan\nTake a query plan as binary and execute it. Binary query plans can be generated using the --compile-plan option.\n\n"
+ ;
}
static const ZorbaCMDPropertiesBase *instance () {
=== modified file 'cmake_modules/ZorbaModule.cmake'
--- cmake_modules/ZorbaModule.cmake 2012-02-23 16:48:01 +0000
+++ cmake_modules/ZorbaModule.cmake 2012-03-19 16:19:41 +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,70 @@
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)
+
+
# 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 +514,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 +540,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 2012-01-11 15:56:57 +0000
+++ include/zorba/properties_base.h 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ include/zorba/util/file.h 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ include/zorba/zorba.h 2012-03-19 16:19:41 +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
{
@@ -301,7 +305,7 @@
virtual StaticContext_t
createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0) = 0;
- /** \brief Gets the singelton instance of the ItemFactory.
+ /** \brief Gets the singleton instance of the ItemFactory.
*
* @return ItemFactory the singleton instance of the ItemFactory.
*/
@@ -310,18 +314,24 @@
/** \brief Gets the singleton instance of the XmlDataManager object.
*
- * @return XmlDataManager the singelton instance of the XmlDataManager.
+ * @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 singelton instance of Zorba's audit provider.
+ * @return audit::Provider the singeleton instance of Zorba's audit provider.
*/
virtual audit::Provider*
getAuditProvider() = 0;
+ /** \brief Gets the singleton instance of Zorba's properties object.
+ *
+ * @return zorba::Properties the singleton instance of Zorba's properties object.
+ */
+ virtual PropertiesGlobal* getPropertiesGlobal() = 0;
+
}; /* class Zorba */
=== modified file 'src/api/staticcontextimpl.h'
--- src/api/staticcontextimpl.h 2012-02-29 11:10:30 +0000
+++ src/api/staticcontextimpl.h 2012-03-19 16:19:41 +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-31 19:47:57 +0000
+++ src/api/zorbaimpl.cpp 2012-03-19 16:19:41 +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::getPropertiesGlobal()
+{
+ return Properties::instance();
+}
+
+
void ZorbaImpl::notifyError( DiagnosticHandler *eh, ZorbaException const &ze ) {
eh->error( ze );
}
=== modified file 'src/api/zorbaimpl.h'
--- src/api/zorbaimpl.h 2012-01-11 15:56:57 +0000
+++ src/api/zorbaimpl.h 2012-03-19 16:19:41 +0000
@@ -134,6 +134,8 @@
audit::Provider* getAuditProvider();
+ PropertiesGlobal* getPropertiesGlobal();
+
protected:
ZorbaImpl();
=== modified file 'src/context/dynamic_loader.cpp'
--- src/context/dynamic_loader.cpp 2012-01-18 13:57:48 +0000
+++ src/context/dynamic_loader.cpp 2012-03-19 16:19:41 +0000
@@ -132,8 +132,15 @@
ExternalModule*
DynamicLoader::loadModule(const zstring& aFile) const
{
- // function pointer to create a module
- ExternalModule* (*createModule)() = NULL;
+ handle_t handle;
+ std::map<const zstring, handle_t>::const_iterator lIter;
+
+ lIter = theLibraries.find(aFile);
+ if (lIter != theLibraries.end())
+ {
+ handle = lIter->second;
+ return createModule(handle, aFile);
+ }
#ifdef WIN32
WCHAR wpath_str[1024];
@@ -146,43 +153,51 @@
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,
ERROR_PARAMS( aFile, os_error::get_err_string() )
);
-
+#else
+ handle = dlopen(aFile.c_str(), RTLD_NOW);
+ if (!handle)
+ throw ZORBA_EXCEPTION(
+ zerr::ZOSE0005_DLL_LOAD_FAILED, ERROR_PARAMS( aFile, zstring(dlerror()) )
+ );
+#endif
+
+ theLibraries[aFile] = handle;
+ return createModule(handle, aFile);
+}
+
+
+ExternalModule*
+DynamicLoader::createModule(handle_t handle, const zstring& aFile) const
+{
+ // function pointer to create a module
+ ExternalModule* (*createModuleFunction)() = NULL;
+
+#ifdef WIN32
createModule = (ExternalModule* (*)())GetProcAddress(handle, "createModule");
- if (createModule == NULL)
+ if (createModuleFunction == NULL)
throw ZORBA_EXCEPTION(
zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
ERROR_PARAMS( aFile, os_error::get_err_string() )
);
-
#else
- void* handle = dlopen(aFile.c_str(), RTLD_NOW);
- if (!handle)
- throw ZORBA_EXCEPTION(
- zerr::ZOSE0005_DLL_LOAD_FAILED, ERROR_PARAMS( aFile, zstring(dlerror()) )
- );
-
- createModule = (ExternalModule* (*)()) dlsym(handle, "createModule");
- if (createModule == NULL)
+ createModuleFunction = (ExternalModule* (*)()) dlsym(handle, "createModule");
+ if (createModuleFunction == NULL)
{
dlclose(handle);
throw ZORBA_EXCEPTION(
- zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
- ERROR_PARAMS( aFile, dlerror() )
- );
+ zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
+ ERROR_PARAMS( aFile, dlerror() )
+ );
}
#endif
- if (theLibraries.find(handle) == theLibraries.end())
- {
- theLibraries.insert(handle);
- }
-
- return createModule();
+ return createModuleFunction();
}
@@ -193,13 +208,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 2012-01-11 15:56:57 +0000
+++ src/context/dynamic_loader.h 2012-03-19 16:19:41 +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 {
@@ -40,15 +40,20 @@
~DynamicLoader();
- ExternalModule* loadModule(const zstring& aFile) const;
#ifdef WIN32
- typedef std::set<HMODULE> LibrarySet_t;
+ typedef HMODULE handle_t;
#else
- typedef std::set<void*> LibrarySet_t;
+ typedef void * handle_t;
#endif
- mutable LibrarySet_t theLibraries;
+ ExternalModule* loadModule(const zstring& aFile) const;
+ ExternalModule* createModule(handle_t handle, const zstring& aFile) const;
+
+
+ typedef std::map<const zstring, handle_t> LibraryMap_t;
+
+ mutable LibraryMap_t theLibraries;
};
} /* namespace zorba */
=== modified file 'src/context/static_context.cpp'
--- src/context/static_context.cpp 2012-03-15 15:27:46 +0000
+++ src/context/static_context.cpp 2012-03-19 16:19:41 +0000
@@ -1699,6 +1699,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-14 15:28:15 +0000
+++ src/context/static_context.h 2012-03-19 16:19:41 +0000
@@ -510,6 +510,8 @@
ExternalModuleMap * theExternalModulesMap;
+ checked_vector<zstring> theJVMClassPath;
+
rchandle<TypeManager> theTypeManager;
NamespaceBindings * theNamespaceBindings;
@@ -713,6 +715,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/precompiled/stdafx.h'
--- src/precompiled/stdafx.h 2012-03-15 15:30:19 +0000
+++ src/precompiled/stdafx.h 2012-03-19 16:19:41 +0000
@@ -80,7 +80,7 @@
// #include "compiler/expression/ft_expr.h"
// #include "compiler/expression/ftnode.h"
// #include "compiler/parser/query_loc.h"
- #include "util/cxx_util.h"
+// #include "util/cxx_util.h"
// #include "util/indent.h"
// #include "util/stl_util.h"
// #include "diagnostics/xquery_diagnostics.h"
@@ -166,7 +166,7 @@
// #include "compiler/api/compiler_api.h"
// #include "compiler/api/compiler_api_impl.h"
// #include "system/globalenv.h"
-// #include "system/properties.h"
+#include "system/properties.h"
// #include "system/zorba_properties.h"
// #include "context/decimal_format.h"
// #include "context/default_uri_mappers.h"
@@ -182,7 +182,7 @@
// #include "context/stemmer_wrappers.h"
// #include "context/uri_resolver.h"
// #include "context/uri_resolver_wrapper.h"
-#include "diagnostics/assert.h"
+// //#include "diagnostics/assert.h"
// #include "diagnostics/diagnostic.h"
// #include "diagnostics/dict.h"
// #include "diagnostics/dict_impl.h"
@@ -370,8 +370,7 @@
#include "zorba/diagnostic_handler.h"
#include "zorba/xquery_warning.h"
#include "runtime/full_text/ftcontains_visitor.h"
- #include "store/naive/naive_ft_token_iterator.h"
- #include "store/api/ft_token_iterator.h"
- #include "store/naive/ft_token_store.h"
+ #include "store/naive/node_items.h"
+
#endif
/* vim:set et sw=2 ts=2: */
=== modified file 'src/system/properties.h'
--- src/system/properties.h 2012-01-11 15:56:57 +0000
+++ src/system/properties.h 2012-03-19 16:19:41 +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-29 11:10:30 +0000
+++ src/system/zorba_properties.h 2012-03-19 16:19:41 +0000
@@ -26,13 +26,25 @@
namespace zorba
{
-class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesBase
+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 };
+ 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;
}
@@ -80,6 +92,7 @@
bool theIterPlanTest;
std::string theDotPlanFile;
uint32_t theMaxUdfCallDepth;
+ std::string theCLASSPATH;
void initialize()
{
@@ -165,6 +178,7 @@
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)
{
@@ -200,7 +214,9 @@
else if (strcmp (*argv, "--debug-file") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --debug-file option"; break; } init_val (*argv, theDebugFile, d);
+ if (*argv == NULL) { result = "No value given for --debug-file option"; break; }
+
+ init_val (*argv, theDebugFile, d);
}
else if (strcmp (*argv, "--abort") == 0) {
theAbort = true;
@@ -208,7 +224,9 @@
else if (strcmp (*argv, "--query") == 0 || strncmp (*argv, "-e", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --query option"; break; } init_val (*argv, theQuery, d);
+ if (*argv == NULL) { result = "No value given for --query option"; break; }
+
+ init_val (*argv, theQuery, d);
}
else if (strcmp (*argv, "--print-query") == 0 || strncmp (*argv, "-q", 2) == 0) {
thePrintQuery = true;
@@ -240,7 +258,9 @@
else if (strcmp (*argv, "--print-static-types") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --print-static-types option"; break; } init_val (*argv, thePrintStaticTypes, d);
+ if (*argv == NULL) { result = "No value given for --print-static-types option"; break; }
+
+ init_val (*argv, thePrintStaticTypes, d);
}
else if (strcmp (*argv, "--dump-lib") == 0) {
theDumpLib = true;
@@ -263,32 +283,44 @@
else if (strcmp (*argv, "--reorder-globals") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --reorder-globals option"; break; } init_val (*argv, theReorderGlobals, d);
+ if (*argv == NULL) { result = "No value given for --reorder-globals option"; break; }
+
+ init_val (*argv, theReorderGlobals, d);
}
else if (strcmp (*argv, "--specialize-num") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --specialize-num option"; break; } init_val (*argv, theSpecializeNum, d);
+ if (*argv == NULL) { result = "No value given for --specialize-num option"; break; }
+
+ init_val (*argv, theSpecializeNum, d);
}
else if (strcmp (*argv, "--specialize-cmp") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --specialize-cmp option"; break; } init_val (*argv, theSpecializeCmp, d);
+ if (*argv == NULL) { result = "No value given for --specialize-cmp option"; break; }
+
+ init_val (*argv, theSpecializeCmp, d);
}
else if (strcmp (*argv, "--inline-udf") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --inline-udf option"; break; } init_val (*argv, theInlineUdf, d);
+ if (*argv == NULL) { result = "No value given for --inline-udf option"; break; }
+
+ init_val (*argv, theInlineUdf, d);
}
else if (strcmp (*argv, "--loop-hoisting") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --loop-hoisting option"; break; } init_val (*argv, theLoopHoisting, d);
+ if (*argv == NULL) { result = "No value given for --loop-hoisting option"; break; }
+
+ init_val (*argv, theLoopHoisting, d);
}
else if (strcmp (*argv, "--infer-joins") == 0) {
int d = 2;
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);
+ 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)
{
@@ -325,17 +357,23 @@
else if (strcmp (*argv, "--tz") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --tz option"; break; } init_val (*argv, theTz, d);
+ if (*argv == NULL) { result = "No value given for --tz option"; break; }
+
+ init_val (*argv, theTz, d);
}
else if (strcmp (*argv, "--external-var") == 0 || strncmp (*argv, "-x", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --external-var option"; break; } init_val (*argv, theExternalVar, d);
+ if (*argv == NULL) { result = "No value given for --external-var option"; break; }
+
+ init_val (*argv, theExternalVar, d);
}
else if (strcmp (*argv, "--serializer-param") == 0 || strncmp (*argv, "-z", 2) == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --serializer-param option"; break; } init_val (*argv, theSerializerParam, d);
+ if (*argv == NULL) { result = "No value given for --serializer-param option"; break; }
+
+ init_val (*argv, theSerializerParam, d);
}
else if (strcmp (*argv, "--iter-plan-test") == 0) {
theIterPlanTest = true;
@@ -343,12 +381,23 @@
else if (strcmp (*argv, "--dot-plan-file") == 0) {
int d = 2;
if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
- if (*argv == NULL) { result = "No value given for --dot-plan-file option"; break; } init_val (*argv, theDotPlanFile, d);
+ if (*argv == NULL) { result = "No value given for --dot-plan-file option"; break; }
+
+ init_val (*argv, theDotPlanFile, d);
}
else if (strcmp (*argv, "--max-udf-call-depth") == 0) {
int d = 2;
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);
+ 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);
@@ -413,6 +462,7 @@
"--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"
;
}
=== modified file 'src/system/zorba_properties.txt'
--- src/system/zorba_properties.txt 2012-02-29 11:10:30 +0000
+++ src/system/zorba_properties.txt 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ src/util/file.cpp 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ src/util/fs_util.cpp 2012-03-19 16:19:41 +0000
@@ -277,6 +277,30 @@
#endif
}
+void lsdir( char const *path, std::vector<std::string> &list )
+{
+ 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 );
+ }
+}
+
bool remove( char const *path ) {
#ifndef WIN32
return ::remove( path ) == 0;
=== modified file 'src/util/fs_util.h'
--- src/util/fs_util.h 2012-01-11 15:56:57 +0000
+++ src/util/fs_util.h 2012-03-19 16:19:41 +0000
@@ -17,6 +17,14 @@
#ifndef ZORBA_FS_UTIL_H
#define ZORBA_FS_UTIL_H
+#include <vector>
+
+#ifdef WIN32
+# include "win32/dirent.h"
+#else
+# include <dirent.h> /* for implementing lsdir */
+#endif /* WIN32 */
+
#include <zorba/config.h>
#include <stdexcept>
@@ -144,6 +152,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 //////////////////////////////////////////////////////
=== added file 'src/util/win32/dirent.h'
--- src/util/win32/dirent.h 1970-01-01 00:00:00 +0000
+++ src/util/win32/dirent.h 2012-03-19 16:19:41 +0000
@@ -0,0 +1,372 @@
+/*****************************************************************************
+ * dirent.h - dirent API for Microsoft Visual Studio
+ *
+ * Copyright (C) 2006 Toni Ronkko
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * ``Software''), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Mar 15, 2011, Toni Ronkko
+ * Defined FILE_ATTRIBUTE_DEVICE for MSVC 6.0.
+ *
+ * Aug 11, 2010, Toni Ronkko
+ * Added d_type and d_namlen fields to dirent structure. The former is
+ * especially useful for determining whether directory entry represents a
+ * file or a directory. For more information, see
+ * http://www.delorie.com/gnu/docs/glibc/libc_270.html
+ *
+ * Aug 11, 2010, Toni Ronkko
+ * Improved conformance to the standards. For example, errno is now set
+ * properly on failure and assert() is never used. Thanks to Peter Brockam
+ * for suggestions.
+ *
+ * Aug 11, 2010, Toni Ronkko
+ * Fixed a bug in rewinddir(): when using relative directory names, change
+ * of working directory no longer causes rewinddir() to fail.
+ *
+ * Dec 15, 2009, John Cunningham
+ * Added rewinddir member function
+ *
+ * Jan 18, 2008, Toni Ronkko
+ * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
+ * between multi-byte and unicode representations. This makes the
+ * code simpler and also allows the code to be compiled under MingW. Thanks
+ * to Azriel Fasten for the suggestion.
+ *
+ * Mar 4, 2007, Toni Ronkko
+ * Bug fix: due to the strncpy_s() function this file only compiled in
+ * Visual Studio 2005. Using the new string functions only when the
+ * compiler version allows.
+ *
+ * Nov 2, 2006, Toni Ronkko
+ * Major update: removed support for Watcom C, MS-DOS and Turbo C to
+ * simplify the file, updated the code to compile cleanly on Visual
+ * Studio 2005 with both unicode and multi-byte character strings,
+ * removed rewinddir() as it had a bug.
+ *
+ * Aug 20, 2006, Toni Ronkko
+ * Removed all remarks about MSVC 1.0, which is antiqued now. Simplified
+ * comments by removing SGML tags.
+ *
+ * May 14 2002, Toni Ronkko
+ * Embedded the function definitions directly to the header so that no
+ * source modules need to be included in the Visual Studio project. Removed
+ * all the dependencies to other projects so that this very header can be
+ * used independently.
+ *
+ * May 28 1998, Toni Ronkko
+ * First version.
+ *****************************************************************************/
+#ifndef DIRENT_H
+#define DIRENT_H
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+
+/* Entries missing from MSVC 6.0 */
+#if !defined(FILE_ATTRIBUTE_DEVICE)
+# define FILE_ATTRIBUTE_DEVICE 0x40
+#endif
+
+/* File type and permission flags for stat() */
+#if defined(_MSC_VER) && !defined(S_IREAD)
+# define S_IFMT _S_IFMT /* file type mask */
+# define S_IFDIR _S_IFDIR /* directory */
+# define S_IFCHR _S_IFCHR /* character device */
+# define S_IFFIFO _S_IFFIFO /* pipe */
+# define S_IFREG _S_IFREG /* regular file */
+# define S_IREAD _S_IREAD /* read permission */
+# define S_IWRITE _S_IWRITE /* write permission */
+# define S_IEXEC _S_IEXEC /* execute permission */
+#endif
+#define S_IFBLK 0 /* block device */
+#define S_IFLNK 0 /* link */
+#define S_IFSOCK 0 /* socket */
+
+#if defined(_MSC_VER)
+# define S_IRUSR S_IREAD /* read, user */
+# define S_IWUSR S_IWRITE /* write, user */
+# define S_IXUSR 0 /* execute, user */
+# define S_IRGRP 0 /* read, group */
+# define S_IWGRP 0 /* write, group */
+# define S_IXGRP 0 /* execute, group */
+# define S_IROTH 0 /* read, others */
+# define S_IWOTH 0 /* write, others */
+# define S_IXOTH 0 /* execute, others */
+#endif
+
+/* Indicates that d_type field is available in dirent structure */
+#define _DIRENT_HAVE_D_TYPE
+
+/* File type flags for d_type */
+#define DT_UNKNOWN 0
+#define DT_REG S_IFREG
+#define DT_DIR S_IFDIR
+#define DT_FIFO S_IFFIFO
+#define DT_SOCK S_IFSOCK
+#define DT_CHR S_IFCHR
+#define DT_BLK S_IFBLK
+
+/* Macros for converting between st_mode and d_type */
+#define IFTODT(mode) ((mode) & S_IFMT)
+#define DTTOIF(type) (type)
+
+/*
+ * File type macros. Note that block devices, sockets and links cannot be
+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
+ * only defined for compatibility. These macros should always return false
+ * on Windows.
+ */
+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO)
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
+#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
+#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
+#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+typedef struct dirent
+{
+ char d_name[MAX_PATH + 1]; /* File name */
+ size_t d_namlen; /* Length of name without \0 */
+ int d_type; /* File type */
+} dirent;
+
+
+typedef struct DIR
+{
+ dirent curentry; /* Current directory entry */
+ WIN32_FIND_DATAA find_data; /* Private file data */
+ int cached; /* True if data is valid */
+ HANDLE search_handle; /* Win32 search handle */
+ char patt[MAX_PATH + 3]; /* Initial directory name */
+} DIR;
+
+
+/* Forward declarations */
+static DIR *opendir(const char *dirname);
+static struct dirent *readdir(DIR *dirp);
+static int closedir(DIR *dirp);
+static void rewinddir(DIR* dirp);
+
+
+/* Use the new safe string functions introduced in Visual Studio 2005 */
+#if defined(_MSC_VER) && _MSC_VER >= 1400
+# define DIRENT_STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
+#else
+# define DIRENT_STRNCPY(dest,src,size) strncpy((dest),(src),(size))
+#endif
+
+/* Set errno variable */
+#if defined(_MSC_VER)
+#define DIRENT_SET_ERRNO(x) _set_errno (x)
+#else
+#define DIRENT_SET_ERRNO(x) (errno = (x))
+#endif
+
+
+/*****************************************************************************
+ * Open directory stream DIRNAME for read and return a pointer to the
+ * internal working area that is used to retrieve individual directory
+ * entries.
+ */
+static DIR *opendir(const char *dirname)
+{
+ DIR *dirp;
+
+ /* ensure that the resulting search pattern will be a valid file name */
+ if (dirname == NULL) {
+ DIRENT_SET_ERRNO (ENOENT);
+ return NULL;
+ }
+ if (strlen (dirname) + 3 >= MAX_PATH) {
+ DIRENT_SET_ERRNO (ENAMETOOLONG);
+ return NULL;
+ }
+
+ /* construct new DIR structure */
+ dirp = (DIR*) malloc (sizeof (struct DIR));
+ if (dirp != NULL) {
+ int error;
+
+ /*
+ * Convert relative directory name to an absolute one. This
+ * allows rewinddir() to function correctly when the current working
+ * directory is changed between opendir() and rewinddir().
+ */
+ if (GetFullPathNameA (dirname, MAX_PATH, dirp->patt, NULL)) {
+ char *p;
+
+ /* append the search pattern "\\*\0" to the directory name */
+ p = strchr (dirp->patt, '\0');
+ if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
+ *p++ = '\\';
+ }
+ *p++ = '*';
+ *p = '\0';
+
+ /* open directory stream and retrieve the first entry */
+ dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+ /* a directory entry is now waiting in memory */
+ dirp->cached = 1;
+ error = 0;
+ } else {
+ /* search pattern is not a directory name? */
+ DIRENT_SET_ERRNO (ENOENT);
+ error = 1;
+ }
+ } else {
+ /* buffer too small */
+ DIRENT_SET_ERRNO (ENOMEM);
+ error = 1;
+ }
+
+ if (error) {
+ free (dirp);
+ dirp = NULL;
+ }
+ }
+
+ return dirp;
+}
+
+
+/*****************************************************************************
+ * Read a directory entry, and return a pointer to a dirent structure
+ * containing the name of the entry in d_name field. Individual directory
+ * entries returned by this very function include regular files,
+ * sub-directories, pseudo-directories "." and "..", but also volume labels,
+ * hidden files and system files may be returned.
+ */
+static struct dirent *readdir(DIR *dirp)
+{
+ DWORD attr;
+ if (dirp == NULL) {
+ /* directory stream did not open */
+ DIRENT_SET_ERRNO (EBADF);
+ return NULL;
+ }
+
+ /* get next directory entry */
+ if (dirp->cached != 0) {
+ /* a valid directory entry already in memory */
+ dirp->cached = 0;
+ } else {
+ /* get the next directory entry from stream */
+ if (dirp->search_handle == INVALID_HANDLE_VALUE) {
+ return NULL;
+ }
+ if (FindNextFileA (dirp->search_handle, &dirp->find_data) == FALSE) {
+ /* the very last entry has been processed or an error occured */
+ FindClose (dirp->search_handle);
+ dirp->search_handle = INVALID_HANDLE_VALUE;
+ return NULL;
+ }
+ }
+
+ /* copy as a multibyte character string */
+ DIRENT_STRNCPY ( dirp->curentry.d_name,
+ dirp->find_data.cFileName,
+ sizeof(dirp->curentry.d_name) );
+ dirp->curentry.d_name[MAX_PATH] = '\0';
+
+ /* compute the length of name */
+ dirp->curentry.d_namlen = strlen (dirp->curentry.d_name);
+
+ /* determine file type */
+ attr = dirp->find_data.dwFileAttributes;
+ if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
+ dirp->curentry.d_type = DT_CHR;
+ } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
+ dirp->curentry.d_type = DT_DIR;
+ } else {
+ dirp->curentry.d_type = DT_REG;
+ }
+ return &dirp->curentry;
+}
+
+
+/*****************************************************************************
+ * Close directory stream opened by opendir() function. Close of the
+ * directory stream invalidates the DIR structure as well as any previously
+ * read directory entry.
+ */
+static int closedir(DIR *dirp)
+{
+ if (dirp == NULL) {
+ /* invalid directory stream */
+ DIRENT_SET_ERRNO (EBADF);
+ return -1;
+ }
+
+ /* release search handle */
+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+ FindClose (dirp->search_handle);
+ dirp->search_handle = INVALID_HANDLE_VALUE;
+ }
+
+ /* release directory structure */
+ free (dirp);
+ return 0;
+}
+
+
+/*****************************************************************************
+ * Resets the position of the directory stream to which dirp refers to the
+ * beginning of the directory. It also causes the directory stream to refer
+ * to the current state of the corresponding directory, as a call to opendir()
+ * would have done. If dirp does not refer to a directory stream, the effect
+ * is undefined.
+ */
+static void rewinddir(DIR* dirp)
+{
+ if (dirp != NULL) {
+ /* release search handle */
+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+ FindClose (dirp->search_handle);
+ }
+
+ /* open new search handle and retrieve the first entry */
+ dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
+ /* a directory entry is now waiting in memory */
+ dirp->cached = 1;
+ } else {
+ /* failed to re-open directory: no directory entry in memory */
+ dirp->cached = 0;
+ }
+ }
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+#endif /*DIRENT_H*/
=== modified file 'swig/XQuery.i'
--- swig/XQuery.i 2012-01-11 15:56:57 +0000
+++ swig/XQuery.i 2012-03-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ swig/java/CMakeLists.txt 2012-03-19 16:19:41 +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,7 @@
ENDIF(NOT WIN32)
ENDIF ( APPLE )
+
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-19 16:19:41 +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 2012-01-11 15:56:57 +0000
+++ swig/zorba_api.i 2012-03-19 16:19:41 +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-23 16:48:01 +0000
+++ test/rbkt/modules/CMakeLists.txt 2012-03-19 16:19:41 +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-19 16:19:41 +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-19 16:19:41 +0000
@@ -0,0 +1,7 @@
+package org.zorbaxquery;
+
+public class Test {
+ public static void main(String[] args) {
+ System.out.println("Hello, world");
+ }
+}
Follow ups