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

Proposed by Cezar Andrei
Status: Superseded
Proposed branch: lp:~zorba-coders/zorba/module-schema-tools
Merge into: lp:zorba
Diff against target: 2855 lines (+1649/-285)
36 files modified
ChangeLog (+2/-0)
NOTICE.txt (+18/-0)
NOTICE.xml (+16/-0)
bin/path_util.cpp (+19/-2)
bin/path_util.h (+6/-0)
bin/zorbacmd.cpp (+8/-0)
bin/zorbacmdproperties.cpp (+5/-0)
bin/zorbacmdproperties.h (+3/-0)
bin/zorbacmdproperties.txt (+1/-0)
bin/zorbacmdproperties_base.h (+133/-72)
cmake_modules/ZorbaModule.cmake (+99/-44)
config/ExternalModuleConfig.cmake.in (+26/-9)
config/ZorbaUse.cmake (+0/-4)
include/zorba/properties_base.h (+37/-1)
include/zorba/util/file.h (+2/-0)
include/zorba/zorba.h (+15/-5)
modules/CMakeLists.txt (+113/-30)
modules/ExternalModules.conf (+2/-0)
src/api/zorbaimpl.cpp (+10/-0)
src/api/zorbaimpl.h (+2/-0)
src/context/dynamic_loader.cpp (+41/-26)
src/context/dynamic_loader.h (+10/-5)
src/system/properties.h (+21/-0)
src/system/zorba_properties.h (+67/-17)
src/system/zorba_properties.txt (+1/-0)
src/util/file.cpp (+12/-0)
src/util/fs_util.cpp (+24/-0)
src/util/fs_util.h (+28/-0)
src/util/win32/dirent.h (+372/-0)
swig/XQuery.i (+308/-26)
swig/java/CMakeLists.txt (+1/-0)
swig/various.i (+184/-0)
swig/zorba_api.i (+14/-44)
test/rbkt/modules/CMakeLists.txt (+2/-0)
test/rbkt/modules/java/CMakeLists.txt (+40/-0)
test/rbkt/modules/java/Test.java (+7/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/module-schema-tools
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Chris Hillery Approve
Cezar Andrei Approve
Review via email: mp+101796@code.launchpad.net

This proposal supersedes a proposal from 2012-04-11.

This proposal has been superseded by a proposal from 2012-04-14.

Commit message

Add java classpath to zorbacmd and to Zorba API.
Fix dynamic libraries loading.
All modules with Java dependency should use util-jvm module to the way schema-tools and data-formating modules are doing.

Description of the change

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.

Removed swig IStream class and references.

Added util-jvm module which implements the link to the jvm.

Solved merge conflict.

To post a comment you must log in.
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in modules/ExternalModules.conf

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

- In DynamicLoader::loadModule the code to create the Module is redundant and should be factorized
- Why is DECLARE_ZORBA_JAR in cmake_modules/ZorbaModule.cmake commented out? Should it be removed?
- Why did the file src/store/naive/store_properties.h change? I think Markos has disabled the generation in the trunk. We have to be careful that nothing is removed by this merge (same for all properties).
  For example,
88 -"--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n"
1089 -"--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n"
1090 +"--no-copy-optim\nno copy optim (1=enabled (default), 0=off)\n\n"
1091 +"--serialize-only-query\nserialize-only query (1=true, 0=false (default))\n\n"

causes the unknown option for the serialize-only-query param to disappear

- commit of src/util/win32/dirent.h should be mentioned in NOTICE.xml
- I don't really like the name serializeToOutputStream. Why can't it just be serialize with one parameter?
- there is a todo left "# todo cezar compile and jar it up"
- I didn't find a test for the new serializeToOutputStream or getStream functions? I think it would be good to have some tests.

review: Needs Fixing
Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

Agreed with Matthias's comments.

Regarding DECLARE_ZORBA_JAR(), it looks like the commented-out macro is an older version, and the newer version is not commented-out. The older one should just be deleted.

Couple more comments:

- Do we also need to mention the addition of swig/various.i in NOTICE.xml? It has a comment saying it's from the SWIG package directly.

- Wasn't the class name "IStream" causing a build conflict on Windows?

- The call to init_val() in zorbacmdproperties_base.h should be on a separate line. (I know it was cut-and-pasted from above, but ugh.)

- Why is the method for retrieving the PropertiesGlobal* called "getProperties()"? Shouldn't that be getProperiesGlobal()? (Or, IMHO, getGlobalProperties() and rename the class to GlobalProperties.)

- Similarly, why is the factory method for PropertiesGlobal "Properties::instance()"? (The Zorba Properties stuff has always seemed like a mishmash to me; this isn't helping.)

- Need to fix the conflict in ExternalModules.conf.

- Typo: "singelton" in zorba.h.

review: Needs Fixing
Revision history for this message
Cezar Andrei (cezar-andrei) wrote : Posted in a previous version of this proposal

I fixed all of the comments, execept:
- the ones related to swig:
    - the changes are not required, right now but they required for optimizing XQJ, to make swig play nice with streams it's quite a chlange, would be a petty to loose them
    - I don't think various.i should be specified in NOTICE.xml since we already have swig and various.i is part of swig.
- about Properties it's not really the most intuitive way of representing it but I do think PropertiesGlobal is a good name, many projects use kind after the base to explain what it is. I call Properties::instance() because that is the private instantiable implementation class that extends ZorbaProperties which is based on PropertiesGlobal.

Revision history for this message
Cezar Andrei (cezar-andrei) wrote : Posted in a previous version of this proposal

See my prevoius comment for fixes in this proposal.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job module-schema-tools-2012-03-16T20-15-10.551Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 3 Pending.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote : Posted in a previous version of this proposal

- I think you reverted the changes that have been made in modules/ExternalModules.conf.
- The file src/system/zorba_properties.h also contains changes that have been reverted. For example,

1058 -"--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n"
1059 -"--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n"
1060 +"--no-copy-optim\nno copy optim (1=enabled (default), 0=off)\n\n"
1061 +"--serialize-only-query\nserialize-only query (1=true, 0=false (default))\n\n"

review: Needs Fixing
Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

It looks like you didn't fix the indentation of calls to init_val() in zorbacmdproperties_base.h, and in fact it looks like you moved a number of other instances of calls to that method onto the ends of earlier lines of code in zorba_properties.h. It's just not good readability. To be clear, I'm talking about lines like this:

   if (*argv == NULL) { result = "No value given for --classpath option"; break; } init_val (*argv, theClasspath, d);

There's no reason to have that call to init_val() hanging out over there. I count 9 places where this is done, most of which were put that way with this change.

You also didn't rename the class "IStream". Rodolfo reported that that class name conflicted with a Windows class, making the code not compile on Windows. It's not clear to me if this is one of the changes for "optimizing XQJ" you mentioned, but if it actually causes a compilation failure it must be changed.

review: Needs Fixing
Revision history for this message
Cezar Andrei (cezar-andrei) wrote : Posted in a previous version of this proposal

> It looks like you didn't fix the indentation of calls to init_val() in
> zorbacmdproperties_base.h, and in fact it looks like you moved a number of
> other instances of calls to that method onto the ends of earlier lines of code
> in zorba_properties.h. It's just not good readability. To be clear, I'm
> talking about lines like this:
>
> if (*argv == NULL) { result = "No value given for --classpath option";
> break; } init_val (*argv, theClasspath, d);
>
> There's no reason to have that call to init_val() hanging out over there. I
> count 9 places where this is done, most of which were put that way with this
> change.

If you take a look at the file there are many places where this strange indentation occurs. Check out the top of the file: THIS IS A GENERATED FILE. DO NOT EDIT!

>
>
> You also didn't rename the class "IStream". Rodolfo reported that that class
> name conflicted with a Windows class, making the code not compile on Windows.
> It's not clear to me if this is one of the changes for "optimizing XQJ" you
> mentioned, but if it actually causes a compilation failure it must be changed.

Rodolfo, checked out the full build and tests on windows, there is no problem with it. I sent an email to clarify it.

Revision history for this message
Chris Hillery (ceejatec) wrote : Posted in a previous version of this proposal

> If you take a look at the file there are many places where this strange
> indentation occurs. Check out the top of the file: THIS IS A GENERATED FILE.
> DO NOT EDIT!

My understanding is that this isn't true anymore, though. Markos removed the script to generate this file, and said that in future changes should be made directly to it. If that's correct, clearly he should have removed the above comment as well.

Did you run a script to generate these files, Cezar? If so, that would explain Matthias's problem as well (about changes to the property descriptions that seem to have been reverted by you).

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Cezar Andrei (cezar-andrei) wrote : Posted in a previous version of this proposal

I didn't know Markos removed the scripts after I made the changes. But I removed the comment and I fixed the indentation of init_val lines.

I also fixed the ExternalModules.config wrong merge, and checked src/system/zorba_properties.h contains changes only related to CLASSPATH and indentation.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job module-schema-tools-2012-03-19T16-20-06.136Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 3 Pending.

Revision history for this message
Cezar Andrei (cezar-andrei) wrote : Posted in a previous version of this proposal

Removed IStream swig class and references.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Validation queue job module-schema-tools-2012-03-20T19-01-23.283Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : Posted in a previous version of this proposal

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 3 Pending.

Revision history for this message
Cezar Andrei (cezar-andrei) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Chris Hillery (ceejatec) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Cezar Andrei (cezar-andrei) :
review: Approve
Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Should the classpath in the static context be serialized? I forgot our decision, is this member needed at all?

review: Needs Information
Revision history for this message
Chris Hillery (ceejatec) wrote :

It looks like the classpath in static_context is orphaned; nothing sets it or references it. I'll take that out.

Revision history for this message
Chris Hillery (ceejatec) wrote :

Removed. Matthias, if that was your only comment, go ahead and vote Approve.

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Chris Hillery (ceejatec) wrote :

I'll need Cezar to set the commit message; I'm not sure if he just copied
the Description or not. Unfortunately if you go back to the previous
revision of the Proposal it doesn't show the commit message from that
version...

Revision history for this message
Cezar Andrei (cezar-andrei) wrote :

I've set the commit message, but build is not triggered, do I need to resubmit the proposal?

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Attempt to merge into lp:zorba failed due to conflicts:

text conflict in ChangeLog
text conflict in src/api/staticcontextimpl.h
text conflict in src/precompiled/stdafx.h

10657. By Chris Hillery

Merge from trunk.

10658. By Chris Hillery

Yet another crack at making the build dependencies for modules and zorba
completely consistent and correct.

10659. By Chris Hillery

Merge from trunk; remove erroneous swig merge.

10660. By Chris Hillery

Merge from trunk.

10661. By Chris Hillery

Merge from trunk.

10662. By Chris Hillery

Merge from trunk.

10663. By Chris Hillery

Unwanted file.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2012-04-14 06:12:29 +0000
3+++ ChangeLog 2012-04-14 07:09:19 +0000
4@@ -4,6 +4,7 @@
5
6 New Features:
7 * Extended API for Python, Java, PHP and Ruby.
8+ * Add jvm classpath to zorbacmd and to Zorba API. Tracked by #931816
9 * Added support for NO_ICU (to not use ICU for unicode processing)
10
11 Optimization:
12@@ -22,6 +23,7 @@
13 * Fixed bug #906494 (default compile with D_FILE_OFFSET_BITS=64)
14 * Fixed bug #912586, #912593 and #912722 (assertion failures with lax validation)
15 * Fixed bug #949910 (has-children may be invoked on all nodes). Internally, zorba::store::Item::getChildren() now returns NULL on node classes without offspring (instead of raising an error).
16+ * Fixed Bug #933490: Error ItemFactoryImpl::createBase64Binary with istream
17
18
19 version 2.2
20
21=== modified file 'NOTICE.txt'
22--- NOTICE.txt 2012-03-30 19:03:09 +0000
23+++ NOTICE.txt 2012-04-14 07:09:19 +0000
24@@ -459,6 +459,24 @@
25 suitability of this software for any purpose. It is provided "as is"
26 without express or implied warranty.
27
28+----------------------------------------------------
29+
30+src/util/win32/dirent.h
31+
32+Copyright: 2006 Toni Ronkko
33+
34+
35+ Permission is hereby granted, free of charge, to any person obtaining
36+ a copy of this software and associated documentation files (the
37+ ``Software''), to deal in the Software without restriction, including
38+ without limitation the rights to use, copy, modify, merge, publish,
39+ distribute, sublicense, and/or sell copies of the Software, and to
40+ permit persons to whom the Software is furnished to do so, subject to
41+ the following conditions:
42+
43+ The above copyright notice and this permission notice shall be included
44+ in all copies or substantial portions of the Software.
45+
46
47 External libraries used by this project:
48 ----------------------------------------------------
49
50=== modified file 'NOTICE.xml'
51--- NOTICE.xml 2012-03-30 19:03:09 +0000
52+++ NOTICE.xml 2012-04-14 07:09:19 +0000
53@@ -423,6 +423,22 @@
54 without express or implied warranty.
55 </foreign-notice>
56 </foreign-files>
57+ <foreign-files>
58+ <file>src/util/win32/dirent.h</file>
59+ <copyright>2006 Toni Ronkko</copyright>
60+ <foreign-notice>
61+ Permission is hereby granted, free of charge, to any person obtaining
62+ a copy of this software and associated documentation files (the
63+ ``Software''), to deal in the Software without restriction, including
64+ without limitation the rights to use, copy, modify, merge, publish,
65+ distribute, sublicense, and/or sell copies of the Software, and to
66+ permit persons to whom the Software is furnished to do so, subject to
67+ the following conditions:
68+
69+ The above copyright notice and this permission notice shall be included
70+ in all copies or substantial portions of the Software.
71+ </foreign-notice>
72+ </foreign-files>
73
74 <external-lib mandatory="true">
75 <name>LIBXML2</name>
76
77=== modified file 'bin/path_util.cpp'
78--- bin/path_util.cpp 2012-03-30 19:03:09 +0000
79+++ bin/path_util.cpp 2012-04-14 07:09:19 +0000
80@@ -49,7 +49,7 @@
81 }
82
83
84-static void
85+void
86 tokenizePath(
87 const std::string& aPathStr,
88 std::vector<String>& aResult)
89@@ -66,6 +66,23 @@
90 }
91 }
92
93+
94+String
95+concatenatePaths( const std::vector<String>& aPathList)
96+{
97+ String delimiter(filesystem_path::get_path_separator());
98+
99+ String lResult;
100+ for (std::vector<String>::const_iterator lIter = aPathList.begin();
101+ lIter != aPathList.end(); ++lIter)
102+ {
103+ lResult += delimiter + *lIter;
104+ }
105+
106+ return lResult;
107+}
108+
109+
110 void
111 setPathsOnContext(
112 const ZorbaCMDProperties& aProperties,
113@@ -101,8 +118,8 @@
114 // Compute and set lib path
115 aProperties.getLibPath(lPathStr);
116 tokenizePath(lPathStr, lPath);
117+ lPath.push_back(lCWD.get_path());
118 lEnvStr = getPathFromEnvironment("ZORBA_LIB_PATH");
119- lPath.push_back(lCWD.get_path());
120 tokenizePath(lEnvStr, lPath);
121 aStaticCtx->setLibPath(lPath);
122 }
123
124=== modified file 'bin/path_util.h'
125--- bin/path_util.h 2012-03-30 19:03:09 +0000
126+++ bin/path_util.h 2012-04-14 07:09:19 +0000
127@@ -32,6 +32,12 @@
128 setPathsOnContext(const ZorbaCMDProperties& aProperties,
129 zorba::StaticContext_t& aStaticCtx);
130
131+ void
132+ tokenizePath(const std::string& aPathStr, std::vector<String>& aResult);
133+
134+
135+ String
136+ concatenatePaths( const std::vector<String>& aPathList);
137
138 }
139 } /* namespace zorba */
140
141=== modified file 'bin/zorbacmd.cpp'
142--- bin/zorbacmd.cpp 2012-03-30 19:03:09 +0000
143+++ bin/zorbacmd.cpp 2012-04-14 07:09:19 +0000
144@@ -787,6 +787,14 @@
145 return 3;
146 }
147
148+ // Add command line --classpath option in front of config/env CLASSPATH
149+ Properties* globalProperties = Properties::instance();
150+ std::string cmdJvmClassPath;
151+ lProperties.getJVMClassPath(cmdJvmClassPath);
152+ std::string configJvmClassPath;
153+ globalProperties->getJVMClassPath(configJvmClassPath);
154+ globalProperties->setJVMClassPath(cmdJvmClassPath +
155+ filesystem_path::get_path_separator() + configJvmClassPath);
156
157 // Start the engine
158
159
160=== modified file 'bin/zorbacmdproperties.cpp'
161--- bin/zorbacmdproperties.cpp 2012-03-30 19:03:09 +0000
162+++ bin/zorbacmdproperties.cpp 2012-04-14 07:09:19 +0000
163@@ -181,6 +181,11 @@
164 aPath = theLibPath;
165 }
166
167+void ZorbaCMDProperties::getJVMClassPath(std::string& aPath) const
168+{
169+ aPath = theClasspath;
170+}
171+
172 std::vector<std::pair<std::string,std::string> > ZorbaCMDProperties::getSerializerParameters() const
173 {
174 std::vector<std::pair<std::string,std::string> > lResult;
175
176=== modified file 'bin/zorbacmdproperties.h'
177--- bin/zorbacmdproperties.h 2012-03-30 19:03:09 +0000
178+++ bin/zorbacmdproperties.h 2012-04-14 07:09:19 +0000
179@@ -92,6 +92,9 @@
180 void
181 getLibPath(std::string&) const;
182
183+ void
184+ getJVMClassPath(std::string&) const;
185+
186 bool isDebug(){ return theDebug; }
187
188 bool hasNoLogo(){ return theNoLogo; }
189
190=== modified file 'bin/zorbacmdproperties.txt'
191--- bin/zorbacmdproperties.txt 2012-03-30 19:03:09 +0000
192+++ bin/zorbacmdproperties.txt 2012-04-14 07:09:19 +0000
193@@ -31,6 +31,7 @@
194 ("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.")
195 ("lib-path", po::value<std::string>(), "Library path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.")
196 ("module-path", po::value<std::string>(), "Path (list of directories) to add to both the URI and Library paths.")
197+("classpath", po::value<std::string>(), "JVM classpath to be used by modules using Java implementations")
198 ("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").
199 ("trailing-nl", "Output a trailing newline after the result of the query.")
200 ("stop-words", po::value<std::vector<std::string> >(), "Mapping specifying a stop-words URI to another.")
201
202=== modified file 'bin/zorbacmdproperties_base.h'
203--- bin/zorbacmdproperties_base.h 2012-03-30 19:03:09 +0000
204+++ bin/zorbacmdproperties_base.h 2012-04-14 07:09:19 +0000
205@@ -15,13 +15,6 @@
206 */
207 /* vim:set et sw=2 ts=2: */
208
209-// ******************************************
210-// * *
211-// * THIS IS A GENERATED FILE. DO NOT EDIT! *
212-// * SEE .txt FILE WITH SAME NAME *
213-// * *
214-// ******************************************
215-
216 #include <string>
217 #include <sstream>
218 #include <zorba/config.h>
219@@ -30,13 +23,29 @@
220
221 #ifndef ZORBACMD_ZORBACMDPROPERTIESBASE
222 #define ZORBACMD_ZORBACMDPROPERTIESBASE
223-namespace zorbacmd {
224-class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase {
225+namespace zorbacmd
226+{
227+
228+class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase
229+{
230 protected:
231- const char **get_all_options () const {
232- 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 };
233+ const char **get_all_options () const
234+ {
235+ static const char *result [] = {
236+ "--timing", "--output-file", "--serialization-parameter",
237+ "--serialize-html", "--serialize-text", "--indent", "--print-query",
238+ "--print-errors-as-xml", "--byte-order-mark", "--omit-xml-declaration",
239+ "--base-uri", "--boundary-space", "--default-collation",
240+ "--construction-mode", "--ordering-mode", "--multiple", "--query",
241+ "--as-files", "--external-variable", "--context-item",
242+ "--optimization-level", "--lib-module", "--parse-only", "--compile-only",
243+ "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo",
244+ "--timeout", "--uri-path", "--lib-path", "--module-path", "--classpath",
245+ "--option", "--trailing-nl", "--stop-words", "--thesaurus",
246+ "--compile-plan", "--execute-plan", NULL };
247 return result;
248 }
249+
250 bool theTiming;
251 std::string theOutputFile;
252 std::vector<std::string> theSerializationParameter;
253@@ -70,6 +79,7 @@
254 std::string theUriPath;
255 std::string theLibPath;
256 std::string theModulePath;
257+ std::string theClasspath;
258 std::vector<std::string> theOption;
259 bool theTrailingNl;
260 std::vector<std::string> theStopWords;
261@@ -136,6 +146,7 @@
262 const std::string &uriPath () const { return theUriPath; }
263 const std::string &libPath () const { return theLibPath; }
264 const std::string &modulePath () const { return theModulePath; }
265+ const std::string &classpath () const { return theClasspath; }
266 const std::vector<std::string> &option () const { return theOption; }
267 const bool &trailingNl () const { return theTrailingNl; }
268 const std::vector<std::string> &stopWords () const { return theStopWords; }
269@@ -158,12 +169,16 @@
270 else if (strcmp (*argv, "--output-file") == 0 || strncmp (*argv, "-o", 2) == 0) {
271 int d = 2;
272 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
273- if (*argv == NULL) { result = "No value given for --output-file option"; break; } init_val (*argv, theOutputFile, d);
274+ if (*argv == NULL) { result = "No value given for --output-file option"; break; }
275+
276+ init_val (*argv, theOutputFile, d);
277 }
278 else if (strcmp (*argv, "--serialization-parameter") == 0 || strncmp (*argv, "-z", 2) == 0) {
279 int d = 2;
280 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
281- if (*argv == NULL) { result = "No value given for --serialization-parameter option"; break; } init_val (*argv, theSerializationParameter, d);
282+ if (*argv == NULL) { result = "No value given for --serialization-parameter option"; break; }
283+
284+ init_val (*argv, theSerializationParameter, d);
285 }
286 else if (strcmp (*argv, "--serialize-html") == 0) {
287 theSerializeHtml = true;
288@@ -189,37 +204,51 @@
289 else if (strcmp (*argv, "--base-uri") == 0) {
290 int d = 2;
291 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
292- if (*argv == NULL) { result = "No value given for --base-uri option"; break; } init_val (*argv, theBaseUri, d);
293+ if (*argv == NULL) { result = "No value given for --base-uri option"; break; }
294+
295+ init_val (*argv, theBaseUri, d);
296 }
297 else if (strcmp (*argv, "--boundary-space") == 0) {
298 int d = 2;
299 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
300- if (*argv == NULL) { result = "No value given for --boundary-space option"; break; } init_val (*argv, theBoundarySpace, d);
301+ if (*argv == NULL) { result = "No value given for --boundary-space option"; break; }
302+
303+ init_val (*argv, theBoundarySpace, d);
304 }
305 else if (strcmp (*argv, "--default-collation") == 0) {
306 int d = 2;
307 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
308- if (*argv == NULL) { result = "No value given for --default-collation option"; break; } init_val (*argv, theDefaultCollation, d);
309+ if (*argv == NULL) { result = "No value given for --default-collation option"; break; }
310+
311+ init_val (*argv, theDefaultCollation, d);
312 }
313 else if (strcmp (*argv, "--construction-mode") == 0) {
314 int d = 2;
315 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
316- if (*argv == NULL) { result = "No value given for --construction-mode option"; break; } init_val (*argv, theConstructionMode, d);
317+ if (*argv == NULL) { result = "No value given for --construction-mode option"; break; }
318+
319+ init_val (*argv, theConstructionMode, d);
320 }
321 else if (strcmp (*argv, "--ordering-mode") == 0) {
322 int d = 2;
323 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
324- if (*argv == NULL) { result = "No value given for --ordering-mode option"; break; } init_val (*argv, theOrderingMode, d);
325+ if (*argv == NULL) { result = "No value given for --ordering-mode option"; break; }
326+
327+ init_val (*argv, theOrderingMode, d);
328 }
329 else if (strcmp (*argv, "--multiple") == 0 || strncmp (*argv, "-m", 2) == 0) {
330 int d = 2;
331 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
332- if (*argv == NULL) { result = "No value given for --multiple option"; break; } init_val (*argv, theMultiple, d);
333+ if (*argv == NULL) { result = "No value given for --multiple option"; break; }
334+
335+ init_val (*argv, theMultiple, d);
336 }
337 else if (strcmp (*argv, "--query") == 0 || strncmp (*argv, "-q", 2) == 0) {
338 int d = 2;
339 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
340- if (*argv == NULL) { result = "No value given for --query option"; break; } init_val (*argv, theQueriesOrFiles, d);
341+ if (*argv == NULL) { result = "No value given for --query option"; break; }
342+
343+ init_val (*argv, theQueriesOrFiles, d);
344 }
345 else if (strcmp (*argv, "--as-files") == 0 || strncmp (*argv, "-f", 2) == 0) {
346 theAsFiles = true;
347@@ -227,17 +256,23 @@
348 else if (strcmp (*argv, "--external-variable") == 0 || strncmp (*argv, "-e", 2) == 0) {
349 int d = 2;
350 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
351- if (*argv == NULL) { result = "No value given for --external-variable option"; break; } init_val (*argv, theExternalVariable, d);
352+ if (*argv == NULL) { result = "No value given for --external-variable option"; break; }
353+
354+ init_val (*argv, theExternalVariable, d);
355 }
356 else if (strcmp (*argv, "--context-item") == 0) {
357 int d = 2;
358 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
359- if (*argv == NULL) { result = "No value given for --context-item option"; break; } init_val (*argv, theContextItem, d);
360+ if (*argv == NULL) { result = "No value given for --context-item option"; break; }
361+
362+ init_val (*argv, theContextItem, d);
363 }
364 else if (strcmp (*argv, "--optimization-level") == 0) {
365 int d = 2;
366 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
367- if (*argv == NULL) { result = "No value given for --optimization-level option"; break; } init_val (*argv, theOptimizationLevel, d);
368+ if (*argv == NULL) { result = "No value given for --optimization-level option"; break; }
369+
370+ init_val (*argv, theOptimizationLevel, d);
371 }
372 else if (strcmp (*argv, "--lib-module") == 0 || strncmp (*argv, "-l", 2) == 0) {
373 theLibModule = true;
374@@ -257,12 +292,16 @@
375 else if (strcmp (*argv, "--debug-host") == 0 || strncmp (*argv, "-h", 2) == 0) {
376 int d = 2;
377 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
378- if (*argv == NULL) { result = "No value given for --debug-host option"; break; } init_val (*argv, theDebugHost, d);
379+ if (*argv == NULL) { result = "No value given for --debug-host option"; break; }
380+
381+ init_val (*argv, theDebugHost, d);
382 }
383 else if (strcmp (*argv, "--debug-port") == 0 || strncmp (*argv, "-p", 2) == 0) {
384 int d = 2;
385 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
386- if (*argv == NULL) { result = "No value given for --debug-port option"; break; } init_val (*argv, theDebugPort, d);
387+ if (*argv == NULL) { result = "No value given for --debug-port option"; break; }
388+
389+ init_val (*argv, theDebugPort, d);
390 }
391 else if (strcmp (*argv, "--no-logo") == 0) {
392 theNoLogo = true;
393@@ -270,27 +309,44 @@
394 else if (strcmp (*argv, "--timeout") == 0) {
395 int d = 2;
396 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
397- if (*argv == NULL) { result = "No value given for --timeout option"; break; } init_val (*argv, theTimeout, d);
398+ if (*argv == NULL) { result = "No value given for --timeout option"; break; }
399+
400+ init_val (*argv, theTimeout, d);
401 }
402 else if (strcmp (*argv, "--uri-path") == 0) {
403 int d = 2;
404 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
405- if (*argv == NULL) { result = "No value given for --uri-path option"; break; } init_val (*argv, theUriPath, d);
406+ if (*argv == NULL) { result = "No value given for --uri-path option"; break; }
407+
408+ init_val (*argv, theUriPath, d);
409 }
410 else if (strcmp (*argv, "--lib-path") == 0) {
411 int d = 2;
412 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
413- if (*argv == NULL) { result = "No value given for --lib-path option"; break; } init_val (*argv, theLibPath, d);
414+ if (*argv == NULL) { result = "No value given for --lib-path option"; break; }
415+
416+ init_val (*argv, theLibPath, d);
417 }
418 else if (strcmp (*argv, "--module-path") == 0) {
419 int d = 2;
420 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
421- if (*argv == NULL) { result = "No value given for --module-path option"; break; } init_val (*argv, theModulePath, d);
422+ if (*argv == NULL) { result = "No value given for --module-path option"; break; }
423+
424+ init_val (*argv, theModulePath, d);
425+ }
426+ else if (strcmp (*argv, "--classpath") == 0) {
427+ int d = 2;
428+ if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
429+ if (*argv == NULL) { result = "No value given for --classpath option"; break; }
430+
431+ init_val (*argv, theClasspath, d);
432 }
433 else if (strcmp (*argv, "--option") == 0) {
434 int d = 2;
435 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
436- if (*argv == NULL) { result = "No value given for --option option"; break; } init_val (*argv, theOption, d);
437+ if (*argv == NULL) { result = "No value given for --option option"; break; }
438+
439+ init_val (*argv, theOption, d);
440 }
441 else if (strcmp (*argv, "--trailing-nl") == 0) {
442 theTrailingNl = true;
443@@ -298,12 +354,16 @@
444 else if (strcmp (*argv, "--stop-words") == 0) {
445 int d = 2;
446 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
447- if (*argv == NULL) { result = "No value given for --stop-words option"; break; } init_val (*argv, theStopWords, d);
448+ if (*argv == NULL) { result = "No value given for --stop-words option"; break; }
449+
450+ init_val (*argv, theStopWords, d);
451 }
452 else if (strcmp (*argv, "--thesaurus") == 0) {
453 int d = 2;
454 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
455- if (*argv == NULL) { result = "No value given for --thesaurus option"; break; } init_val (*argv, theThesaurus, d);
456+ if (*argv == NULL) { result = "No value given for --thesaurus option"; break; }
457+
458+ init_val (*argv, theThesaurus, d);
459 }
460 else if (strcmp (*argv, "--compile-plan") == 0 || strncmp (*argv, "-c", 2) == 0) {
461 theCompilePlan = true;
462@@ -327,46 +387,47 @@
463
464 const char *get_help_msg () const {
465 return
466-"--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"
467-"--output-file, -o\nWrite the result to the given file.\n\n"
468-"--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"
469-"--serialize-html\nSerialize the result as HTML.\n\n"
470-"--serialize-text\nSerialize the result as Text.\n\n"
471-"--indent, -i\nIndent output.\n\n"
472-"--print-query\nPrint the queries.\n\n"
473-"--print-errors-as-xml, -x\nPrint the errors as XML.\n\n"
474-"--byte-order-mark\nSet the byte-order-mark for the serializer.\n\n"
475-"--omit-xml-declaration, -r\nOmit the XML declaration from the result.\n\n"
476-"--base-uri\nSet the base URI property of the static context.\n\n"
477-"--boundary-space\nSet the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
478-"--default-collation\nAdd the given collation and set the value of the default collation in the static context to the given collation.\n\n"
479-"--construction-mode\nSet the construction mode ('strip' or 'preserve') in the static context.\n\n"
480-"--ordering-mode\nSet the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
481-"--multiple, -m\nExecute the given queries multiple times.\n\n"
482-"--query, -q\nQuery test or file URI (file://...)\n\n"
483-"--as-files, -f\nTreat all -q arguments as file paths instead of URIs or inline queries.\n\n"
484-"--external-variable, -e\nProvide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
485-"--context-item\nSet the context item to the XML document in a given file.\n\n"
486-"--optimization-level\nOptimization level for the query compiler (O0, O1 or O2 - default: O1)\n\n"
487-"--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"
488-"--parse-only\nStop after parsing the query.\n\n"
489-"--compile-only\nOnly compile (don't execute)\n\n"
490-"--no-serializer\nDo not serialize (discard) result.\n\n"
491-"--debug, -d\nLaunch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
492-"--debug-host, -h\nThe host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
493-"--debug-port, -p\nThe port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
494-"--no-logo\nPrint no logo when starting.\n\n"
495-"--timeout\nSpecify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
496-"--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"
497-"--lib-path\nLibrary path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.\n\n"
498-"--module-path\nPath (list of directories) to add to both the URI and Library paths.\n\n"
499-"--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"
500-"--trailing-nl\nOutput a trailing newline after the result of the query.\n\n"
501-"--stop-words\nMapping specifying a stop-words URI to another.\n\n"
502-"--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
503-"--compile-plan, -c\nOutput the query plan as binary.\n\n"
504-"--execute-plan\nTake a query plan as binary and execute it. Binary query plans can be generated using the --compile-plan option.\n\n"
505-;
506+ "--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"
507+ "--output-file, -o\nWrite the result to the given file.\n\n"
508+ "--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"
509+ "--serialize-html\nSerialize the result as HTML.\n\n"
510+ "--serialize-text\nSerialize the result as Text.\n\n"
511+ "--indent, -i\nIndent output.\n\n"
512+ "--print-query\nPrint the queries.\n\n"
513+ "--print-errors-as-xml, -x\nPrint the errors as XML.\n\n"
514+ "--byte-order-mark\nSet the byte-order-mark for the serializer.\n\n"
515+ "--omit-xml-declaration, -r\nOmit the XML declaration from the result.\n\n"
516+ "--base-uri\nSet the base URI property of the static context.\n\n"
517+ "--boundary-space\nSet the boundary-space policy ('strip' or 'preserve') in the static context.\n\n"
518+ "--default-collation\nAdd the given collation and set the value of the default collation in the static context to the given collation.\n\n"
519+ "--construction-mode\nSet the construction mode ('strip' or 'preserve') in the static context.\n\n"
520+ "--ordering-mode\nSet the ordering mode ('ordered' or 'unordered') in the static context.\n\n"
521+ "--multiple, -m\nExecute the given queries multiple times.\n\n"
522+ "--query, -q\nQuery test or file URI (file://...)\n\n"
523+ "--as-files, -f\nTreat all -q arguments as file paths instead of URIs or inline queries.\n\n"
524+ "--external-variable, -e\nProvide the value for a variable given a file (name=file) or a value (name:=value)\n\n"
525+ "--context-item\nSet the context item to the XML document in a given file.\n\n"
526+ "--optimization-level\nOptimization level for the query compiler (O0, O1 or O2 - default: O1)\n\n"
527+ "--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"
528+ "--parse-only\nStop after parsing the query.\n\n"
529+ "--compile-only\nOnly compile (don't execute)\n\n"
530+ "--no-serializer\nDo not serialize (discard) result.\n\n"
531+ "--debug, -d\nLaunch the Zorba debugger server and connect to a DBGP-enabled debugger client.\n\n"
532+ "--debug-host, -h\nThe host where the DBGP-enabled debugger client listens for connections. Defaults to: 127.0.0.1\n\n"
533+ "--debug-port, -p\nThe port on which the DBGP-enabled debugger client listens for connections. Defaults to: 28028\n\n"
534+ "--no-logo\nPrint no logo when starting.\n\n"
535+ "--timeout\nSpecify a timeout in seconds. After the specified time, the execution of the query will be aborted.\n\n"
536+ "--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"
537+ "--lib-path\nLibrary path (list of directories) where Zorba will look for dynamic libraries (e.g., module external function implementations.\n\n"
538+ "--module-path\nPath (list of directories) to add to both the URI and Library paths.\n\n"
539+ "--classpath\nJVM classpath to be used by modules using Java implementations\n\n"
540+ "--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"
541+ "--trailing-nl\nOutput a trailing newline after the result of the query.\n\n"
542+ "--stop-words\nMapping specifying a stop-words URI to another.\n\n"
543+ "--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
544+ "--compile-plan, -c\nOutput the query plan as binary.\n\n"
545+ "--execute-plan\nTake a query plan as binary and execute it. Binary query plans can be generated using the --compile-plan option.\n\n"
546+ ;
547 }
548
549 static const ZorbaCMDPropertiesBase *instance () {
550
551=== modified file 'cmake_modules/ZorbaModule.cmake'
552--- cmake_modules/ZorbaModule.cmake 2012-03-30 19:03:09 +0000
553+++ cmake_modules/ZorbaModule.cmake 2012-04-14 07:09:19 +0000
554@@ -140,7 +140,6 @@
555 ENDIF (NOT IS_ABSOLUTE "${MODULE_FILE}")
556 GET_FILENAME_COMPONENT (module_name "${MODULE_FILE}" NAME)
557
558-
559 MANGLE_URI (${MODULE_URI} ".xq" module_path module_filename)
560
561 # Compute a CMake-symbol-safe version of the target URI, for storing
562@@ -267,6 +266,13 @@
563 SET (module_filewe "${module_filewe}_${MODULE_VERSION}")
564 ENDIF (MODULE_VERSION)
565
566+ # Choose output base directory
567+ IF (${MODULE_TEST_ONLY} EQUAL 1)
568+ SET (_output_basedir "${CMAKE_BINARY_DIR}/TEST_LIB_PATH")
569+ ELSE (${MODULE_TEST_ONLY} EQUAL 1)
570+ SET (_output_basedir "${CMAKE_BINARY_DIR}/LIB_PATH")
571+ ENDIF (${MODULE_TEST_ONLY} EQUAL 1)
572+
573 # It seems like it would be nice to set the VERSION and/or
574 # SOVERSION target properties here. However: On Windows, it
575 # doesn't seem to do anything (the .rc file configured above
576@@ -278,12 +284,20 @@
577 # FOLDER is to group IDE projects into folders.
578 SET_TARGET_PROPERTIES (${module_lib_target} PROPERTIES
579 OUTPUT_NAME "${module_filewe}${SUFFIX}"
580- ${target_type}_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.src"
581+ ${target_type}_OUTPUT_DIRECTORY "${_output_basedir}/${module_path}"
582 FOLDER "Modules"
583 )
584 TARGET_LINK_LIBRARIES(${module_lib_target}
585 zorba_${ZORBA_STORE_NAME} ${MODULE_LINK_LIBRARIES})
586
587+ # While we're at it, remember this library for the auto-generated
588+ # module Config.cmake file. Need to use the LIB_PATH location
589+ # since that's what will be dlopen()'d by Zorba at runtime. QQQ
590+ # and what about the installed version?
591+ GET_TARGET_PROPERTY (_lib_location "${module_lib_target}" LOCATION)
592+ SET_PROPERTY (GLOBAL APPEND PROPERTY "${PROJECT_NAME}_LIBRARIES"
593+ "${_lib_location}")
594+
595 # Install the library, if it's not a TEST_ONLY module
596 IF (NOT MODULE_TEST_ONLY)
597 IF(NOT ${PROJECT_NAME} STREQUAL "zorba")
598@@ -314,17 +328,9 @@
599 ENDIF (MODULE_VERSION)
600 FOREACH (version_infix "" ${version_infixes})
601 ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${module_path}/${module_filename}"
602- "${version_infix}" "" "${MODULE_TEST_ONLY}")
603+ "${version_infix}" "" 1 "${MODULE_TEST_ONLY}")
604 ENDFOREACH (version_infix)
605
606- # Also copy the dynamic library from the location it was built.
607- IF (module_lib_target)
608- GET_TARGET_PROPERTY (lib_location "${module_lib_target}" LOCATION)
609- GET_FILENAME_COMPONENT (lib_filename "${lib_location}" NAME)
610- ADD_COPY_RULE ("LIB" "${lib_location}" "${module_path}/${lib_filename}"
611- "" "${module_lib_target}" "${MODULE_TEST_ONLY}")
612- ENDIF (module_lib_target)
613-
614 # Last but not least, whip up a test case that ensures the module
615 # can at least be compiled. Don't bother for test-only modules
616 # (presumably they're there to be tested!).
617@@ -375,7 +381,7 @@
618 ENDIF (NOT SCHEMA_TEST_ONLY)
619
620 ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${schema_path}/${schema_filename}"
621- "" "" "${SCHEMA_TEST_ONLY}")
622+ "" "" 1 "${SCHEMA_TEST_ONLY}")
623
624 ENDMACRO (DECLARE_ZORBA_SCHEMA)
625
626@@ -407,25 +413,74 @@
627 MANGLE_URI (${URI_FILE_URI} "" uri_file_path uri_file_filename)
628
629 ADD_COPY_RULE ("URI" "${SOURCE_FILE}" "${uri_file_path}/${uri_file_filename}"
630- "" "" "${URI_FILE_TEST_ONLY}")
631+ "" "" 1 "${URI_FILE_TEST_ONLY}")
632
633 ENDMACRO (DECLARE_ZORBA_URI_FILE)
634
635+
636+# Inform Zorba of a .jar file that should be made available on the CLASSPATH
637+# of the JVM, should the JVM be started. QQQ more doc needed
638+#
639+# Args: FILE - path to file(s) (must be absolute)
640+# TARGET - (optional) a CMake target that must be executed in order
641+# for FILEs to be generated
642+# EXTERNAL - (optional) FILE specifies a path that should be added
643+# to CLASSPATH as-is
644+# TEST_ONLY - (optional) Jar file is for testcases only and should not
645+# be installed
646+#
647+# Must supply at least one value to FILE or TARGET.
648+MACRO (DECLARE_ZORBA_JAR)
649+ PARSE_ARGUMENTS (JAR "FILE;TARGET" "TARGET" "TEST_ONLY;EXTERNAL" ${ARGN})
650+ IF (NOT JAR_FILE)
651+ MESSAGE (FATAL_ERROR "'FILE' argument is required for DECLARE_ZORBA_JAR")
652+ ENDIF (NOT JAR_FILE)
653+
654+ # Initialize classpath file and set up copy rule (once per project)
655+ SET (_CP_FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-classpath.txt")
656+ GET_PROPERTY (_known_project GLOBAL PROPERTY "${PROJECT_NAME}-jars")
657+ IF (NOT _known_project)
658+ FILE (REMOVE "${_CP_FILE}")
659+ SET_PROPERTY (GLOBAL PROPERTY "${PROJECT_NAME}-jars" 1)
660+ ADD_COPY_RULE ("LIB" "${_CP_FILE}" "jars/${PROJECT_NAME}-classpath.txt"
661+ "" "" 1 "${JAR_TEST_ONLY}")
662+ ENDIF (NOT _known_project)
663+
664+ # Iterate over all supplied jar files
665+ FOREACH (_jar_file ${JAR_FILE})
666+
667+ IF (JAR_EXTERNAL)
668+ # Put absolute path into classpath file
669+ FILE (APPEND "${_CP_FILE}" "${_jar_file}\n")
670+ ELSE (JAR_EXTERNAL)
671+ # Copy jar to jars/ directory and add relative path to classpath file
672+ GET_FILENAME_COMPONENT (_output_filename "${_jar_file}" NAME)
673+ ADD_COPY_RULE ("LIB" "${_jar_file}" "jars/${_output_filename}" ""
674+ "${JAR_TARGET}" 1 "${JAR_TEST_ONLY}")
675+ FILE (APPEND "${_CP_FILE}" "${_output_filename}\n")
676+ ENDIF (JAR_EXTERNAL)
677+
678+ ENDFOREACH (_jar_file)
679+ENDMACRO (DECLARE_ZORBA_JAR)
680+
681+
682 # Utility macro for setting up a build rule to copy a file to a
683-# particular (possibly versioned) file in a shared directory if such a file has
684-# not already been output.
685+# particular (possibly versioned) file in a shared directory if such a
686+# file has not already been output.
687+#
688 # FILE_TYPE: Either "URI" or "LIB"; will be used to determine which shared
689-# directory to place output in (URI_PATH or LIB_PATH). Also, "URI" files
690-# will have an INSTALL() directive to put them in the install image.
691+# directory to place output in (URI_PATH or LIB_PATH).
692 # INPUT_FILE: Absolute path to file to copy.
693 # OUTPUT_FILE: Relative path to output file (relative to URI_PATH).
694 # VERSION_ARG: Version; may be "" for non-versioned files.
695 # DEPEND_TARGET: A CMake target name upon which the copy rule should depend;
696 # may be "".
697+# INSTALL: If 1, an INSTALL() directive will be executed to put the
698+# file into the install image.
699 # TEST_ONLY: If 1, file is for testcases only; will be copied into
700-# TEST_URI_PATH/TEST_LIB_PATH and will not be installed
701+# TEST_URI_PATH/TEST_LIB_PATH and will not be installed.
702 MACRO (ADD_COPY_RULE FILE_TYPE INPUT_FILE OUTPUT_FILE VERSION_ARG
703- DEPEND_TARGET TEST_ONLY)
704+ DEPEND_TARGET INSTALL TEST_ONLY)
705 # Choose output base directory
706 IF (${TEST_ONLY} EQUAL 1)
707 SET (_output_basedir "${CMAKE_BINARY_DIR}/TEST_${FILE_TYPE}_PATH")
708@@ -470,13 +525,13 @@
709 SET_PROPERTY (GLOBAL APPEND PROPERTY ZORBA_URI_FILES
710 "${INPUT_FILE}" "${_output_file}" "${DEPEND_TARGET}" "${_is_core}")
711
712- # Also set up an INSTALL rule (unless TEST_ONLY or LIB).
713- IF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
714+ # Also set up an INSTALL rule (unless TEST_ONLY).
715+ IF ( (${INSTALL} EQUAL 1) AND (NOT ${TEST_ONLY} EQUAL 1) )
716
717 IF(NOT _is_core)
718 STRING(REPLACE "-" "_" component_name ${PROJECT_NAME})
719 INSTALL (FILES "${INPUT_FILE}"
720- DESTINATION "${ZORBA_NONCORE_URI_DIR}/${_output_path}"
721+ DESTINATION "${ZORBA_NONCORE_${FILE_TYPE}_DIR}/${_output_path}"
722 RENAME "${_output_filename}"
723 COMPONENT "${component_name}")
724
725@@ -496,11 +551,11 @@
726
727 ELSE(NOT _is_core)
728 INSTALL (FILES "${INPUT_FILE}"
729- DESTINATION "${ZORBA_CORE_URI_DIR}/${_output_path}"
730+ DESTINATION "${ZORBA_CORE_${FILE_TYPE}_DIR}/${_output_path}"
731 RENAME "${_output_filename}")
732 ENDIF(NOT _is_core)
733
734- ENDIF ( (NOT "${FILE_TYPE}" STREQUAL "LIB") AND (NOT ${TEST_ONLY} EQUAL 1) )
735+ ENDIF ( (${INSTALL} EQUAL 1) AND (NOT ${TEST_ONLY} EQUAL 1) )
736 ENDIF (file_found EQUAL -1)
737 ENDMACRO (ADD_COPY_RULE)
738
739@@ -535,6 +590,8 @@
740 # files to their corresponding output directories, with appropriate
741 # dependencies. This macro will only have any effect when called by
742 # the top-level project in a build.
743+# Also, this function automatically generates a CMake projectConfig.cmake
744+# file for the project, based on config/ExternalModuleConfig.cmake.in.
745 MACRO (DONE_DECLARING_ZORBA_URIS)
746 IF (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
747 # Close out the zorba modules and schemas manifests
748@@ -553,9 +610,10 @@
749 LIST (GET copy_rules 2 _depend_target)
750 LIST (GET copy_rules 3 _is_core)
751 LIST (REMOVE_AT copy_rules 0 1 2 3)
752- SET (_depends "${_input_file}")
753 IF (_depend_target)
754- LIST (APPEND _depends "${_depend_target}")
755+ SET (_depends "${_depend_target}")
756+ ELSE (_depend_target)
757+ SET (_depends "${_input_file}")
758 ENDIF (_depend_target)
759 ADD_CUSTOM_COMMAND (OUTPUT "${_output_file}"
760 COMMAND "${CMAKE_COMMAND}" -E copy
761@@ -591,6 +649,18 @@
762 #add 'xqdoc' and 'xqdoc-xml' targets
763 ADD_XQDOC_TARGETS()
764 ENDIF (PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
765+
766+ # Now, do things that should be done at the end of *any* project, not
767+ # just the top-level project.
768+
769+ # Generate project's projectConfig.cmake file.
770+ # QQQ need to create an installable version of this too, once we know
771+ # how installing a module package should work.
772+ GET_PROPERTY (ZORBA_PROJECT_LIBRARIES
773+ GLOBAL PROPERTY "${PROJECT_NAME}_LIBRARIES")
774+ CONFIGURE_FILE("${Zorba_EXTERNALMODULECONFIG_FILE}"
775+ "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" @ONLY)
776+
777 ENDMACRO (DONE_DECLARING_ZORBA_URIS)
778
779 # Initialize expected failures and zorba modules output files when
780@@ -648,14 +718,11 @@
781 FOREACH(TESTFILE ${TESTFILES})
782 SET(TESTNAME "${PROJECT_NAME}/${TESTFILE}")
783
784- IF(WIN32)
785- SET(PATH_SEP ",")
786- ELSE(WIN32)
787- SET(PATH_SEP ":")
788- ENDIF(WIN32)
789+ # DEPENDENCY_MODULE_PATH will always start with an appropriate
790+ # path separator
791 ADD_TEST(${TESTNAME} "${Zorba_TESTDRIVER}"
792 "--rbkt-src" "${TEST_DIR}"
793- "--module-path" "${CMAKE_BINARY_DIR}/URI_PATH/${PATH_SEP}${SECONDARY_MODULE_PATHS}"
794+ "--module-path" "${CMAKE_BINARY_DIR}/URI_PATH/${DEPENDENCY_MODULE_PATH}"
795 "${TESTFILE}")
796
797 MATH(EXPR TESTCOUNTER ${TESTCOUNTER}+1)
798@@ -667,18 +734,6 @@
799 MESSAGE(STATUS "Added ${TESTCOUNTER} tests in ${TEST_DIR}")
800 ENDMACRO (ADD_TEST_DIRECTORY)
801
802-# Macro to install a basic CMake config file for a module. Provide a
803-# source and binary directory. Result will be installed in binary
804-# directory. This is a macro because it is called from two different
805-# places: ZorbaUse.cmake, and Zorba's modules/CMakeLists.txt.
806-MACRO(CREATE_MODULE_CONFIG name src_dir bin_dir)
807- # Set variables referenced in ExternalModuleConfig.cmake.in
808- SET(MODULE_SOURCE_DIR ${src_dir})
809- SET(MODULE_BINARY_DIR ${bin_dir})
810- CONFIGURE_FILE("${Zorba_EXTERNALMODULECONFIG_FILE}"
811- "${MODULE_BINARY_DIR}/${name}Config.cmake" @ONLY)
812-ENDMACRO(CREATE_MODULE_CONFIG)
813-
814 # This macro easies the process of adding test for store dependent
815 # executables. It has the same naming convection for the target as the
816 # macro that is used to generated store dependent executables (thus,
817
818=== modified file 'config/ExternalModuleConfig.cmake.in'
819--- config/ExternalModuleConfig.cmake.in 2012-03-30 19:03:09 +0000
820+++ config/ExternalModuleConfig.cmake.in 2012-04-14 07:09:19 +0000
821@@ -12,12 +12,29 @@
822 # See the License for the specific language governing permissions and
823 # limitations under the License.
824
825-IF(WIN32)
826- SET(PATH_SEP ",")
827-ELSE(WIN32)
828- SET(PATH_SEP ":")
829-ENDIF(WIN32)
830-
831-# QQQ When all the module versioning and external-module work is
832-# complete, this should contain ONLY MODULE_BINARY_DIR/modules.
833-SET(SECONDARY_MODULE_PATHS "${SECONDARY_MODULE_PATHS}${PATH_SEP}@MODULE_SOURCE_DIR@/src/${PATH_SEP}@MODULE_BINARY_DIR@/src/${PATH_SEP}@MODULE_BINARY_DIR@/modules/")
834+IF (WIN32)
835+ SET (PATH_SEP ",")
836+ELSE (WIN32)
837+ SET (PATH_SEP ":")
838+ENDIF (WIN32)
839+
840+# Probably should have separate URI and LIB paths here someday; will
841+# require testdriver to accept --uri-path and --lib-path args
842+# Note that this path is meaningless if the module is installed; see
843+# bug 966999.
844+SET (DEPENDENCY_MODULE_PATH
845+ "${DEPENDENCY_MODULE_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/URI_PATH/${PATH_SEP}${DEPENDENCY_LIB_PATH}${PATH_SEP}@PROJECT_BINARY_DIR@/LIB_PATH/")
846+
847+# Dynamic libraries created by this project to link against
848+SET (@PROJECT_NAME@_LIBRARIES @ZORBA_PROJECT_LIBRARIES@)
849+
850+# Include directories exported by this project
851+SET (@PROJECT_NAME@_INCLUDE_DIRS @ZORBA_PROJECT_INCLUDE_DIRS@)
852+
853+# Offer a "use file" to the user of this module. For most module
854+# packages, this is unnecessary. However it can be utilized by
855+# advanced packages which wish to, for example, export a C++ header
856+# file to dependent packages. As above, note that this currently is
857+# non-functional if this module package is installed; this will only
858+# work from a project build directory.
859+SET (@PROJECT_NAME@_USE_FILE "@ZORBA_PROJECT_USE_FILE@")
860
861=== modified file 'config/ZorbaUse.cmake'
862--- config/ZorbaUse.cmake 2012-03-30 19:03:09 +0000
863+++ config/ZorbaUse.cmake 2012-04-14 07:09:19 +0000
864@@ -31,7 +31,3 @@
865 # Load Zorba module support macros.
866 INCLUDE("${Zorba_CMAKE_MODULES_DIR}/Windows/ProxyFindModule.cmake")
867 ENDIF(WIN32)
868-
869-# Generate project's projectConfig.cmake file.
870-CREATE_MODULE_CONFIG(${PROJECT_NAME} "${PROJECT_SOURCE_DIR}"
871- "${PROJECT_BINARY_DIR}")
872
873=== modified file 'include/zorba/properties_base.h'
874--- include/zorba/properties_base.h 2012-03-30 19:03:09 +0000
875+++ include/zorba/properties_base.h 2012-04-14 07:09:19 +0000
876@@ -101,8 +101,44 @@
877 std::vector<std::string>& val,
878 unsigned delta);
879
880+/**
881+ * \brief This class provides access to global properties.
882+ *
883+ * This class provides access to global properties set for Zorba in environment
884+ * and configuration file.
885+ * It is available using Zorba.getProperties() method.
886+ * \see { Zorba::getProperties() }
887+ */
888+class ZORBA_DLL_PUBLIC PropertiesGlobal : public PropertiesBase
889+{
890+public:
891+ virtual ~PropertiesGlobal() {}
892+
893+ /**
894+ * \brief Get global JVM classpath property.
895+ *
896+ * Before the JVM is started this will return the classpath set by
897+ * command line option, the CLASSPATH environment variable and in Zorba
898+ * config file.
899+ *
900+ * After the JVM is started this will contain in addition the paths to jars
901+ * used by modules that make use of the JVM.
902+ */
903+ virtual void getJVMClassPath(std::string & jvmClasspath) {}
904+
905+ /**
906+ * \brief Set global JVM classpath property.
907+ *
908+ * This method should be used to set additional JVM classpath for modules
909+ * that make use of JVM. This will overide the classpath set by CLASSPATH
910+ * environment variable or Zorba config file.
911+ *
912+ * Once the JVM is started this method doesn't have any effect.
913+ */
914+ virtual void setJVMClassPath(const std::string & jvmClasspath) {}
915+};
916+
917 }
918-
919 #endif // ZORBA_PROPERTIES_BASE_H
920 /*
921 * Local variables:
922
923=== modified file 'include/zorba/util/file.h'
924--- include/zorba/util/file.h 2012-03-30 19:03:09 +0000
925+++ include/zorba/util/file.h 2012-04-14 07:09:19 +0000
926@@ -24,6 +24,7 @@
927 #include <cstdio>
928 #include <string>
929 #include <time.h>
930+#include <vector>
931
932 #include <zorba/config.h>
933 #include <zorba/file.h>
934@@ -84,6 +85,7 @@
935 void mkdir();
936 void deep_mkdir();
937 void rmdir(bool ignore = true);
938+ void lsdir(std::vector<std::string> &list);
939 #ifndef _WIN32_WCE
940 void chdir();
941 #endif
942
943=== modified file 'include/zorba/zorba.h'
944--- include/zorba/zorba.h 2012-03-30 19:03:09 +0000
945+++ include/zorba/zorba.h 2012-04-14 07:09:19 +0000
946@@ -34,14 +34,18 @@
947 #include <zorba/xquery.h>
948 #include <zorba/zorba_string.h>
949 #include <zorba/iterator.h>
950+#include <zorba/properties_base.h>
951
952 namespace zorba {
953
954 /**
955 * The Zorba class is the single point of access to the %Zorba engine.
956 * There exists one instance of the Zorba class per process.
957- * It can be used to (1) create and compile queries, (2) create static contexts,
958- * (3) provides access to the XmlDataManager, and (4) provides access to the ItemFactory.
959+ * It can be used to (1) create and compile queries,
960+ * (2) create static contexts,
961+ * (3) provides access to the XmlDataManager,
962+ * (4) provides access to the ItemFactory, and
963+ * (5) provides access to the PropertiesGlobal.
964 */
965 class ZORBA_DLL_PUBLIC Zorba
966 {
967@@ -301,7 +305,7 @@
968 virtual StaticContext_t
969 createStaticContext(DiagnosticHandler* aDiagnosticHandler = 0) = 0;
970
971- /** \brief Gets the singelton instance of the ItemFactory.
972+ /** \brief Gets the singleton instance of the ItemFactory.
973 *
974 * @return ItemFactory the singleton instance of the ItemFactory.
975 */
976@@ -310,18 +314,24 @@
977
978 /** \brief Gets the singleton instance of the XmlDataManager object.
979 *
980- * @return XmlDataManager the singelton instance of the XmlDataManager.
981+ * @return XmlDataManager the singleton instance of the XmlDataManager.
982 */
983 virtual XmlDataManager*
984 getXmlDataManager() = 0;
985
986 /** \brief Gets the singleton instance of Zorba's audit provider object.
987 *
988- * @return audit::Provider the singelton instance of Zorba's audit provider.
989+ * @return audit::Provider the singeleton instance of Zorba's audit provider.
990 */
991 virtual audit::Provider*
992 getAuditProvider() = 0;
993
994+ /** \brief Gets the singleton instance of Zorba's properties object.
995+ *
996+ * @return zorba::Properties the singleton instance of Zorba's properties object.
997+ */
998+ virtual PropertiesGlobal* getPropertiesGlobal() = 0;
999+
1000 }; /* class Zorba */
1001
1002
1003
1004=== modified file 'modules/CMakeLists.txt'
1005--- modules/CMakeLists.txt 2012-03-30 19:03:09 +0000
1006+++ modules/CMakeLists.txt 2012-04-14 07:09:19 +0000
1007@@ -21,13 +21,19 @@
1008 # named "zorba_modules" as a sibling to the main Zorba source
1009 # directory.
1010
1011-# First, configure the moduleConfig.cmake file for each module
1012-# project. We must do this "manually" before doing any
1013-# ADD_SUBDIRECTORY()s, so that all the config files are built and
1014-# ready for other modules' FIND_PACKAGE() calls. We also add all
1015-# module build dirs to CMAKE_PREFIX_PATH for the same reason.
1016-SET (project_regex "[Pp][Rr][Oo][Jj][Ee][Cc][Tt]")
1017-FILE (GLOB modules_dir_items RELATIVE "${ZORBA_MODULES_DIR}" "${ZORBA_MODULES_DIR}/[a-zA-Z0-9]*")
1018+# This is complicated and more than a little hacky. We need to add all
1019+# the module subdirectories, but some may depend on others so we can't
1020+# simply add them alphabetically. Here we determine their project
1021+# names and dependencies by manually reading their CMakeLists.txt
1022+# files (as text files). We form a directed graph (which isn't easy in
1023+# CMake) then produce a topological sort to load the modules in
1024+# order. Note that this will not work if there are cyclical
1025+# dependencies between modules; if we ever need that ability, this
1026+# will get more complicated.
1027+
1028+FILE (GLOB modules_dir_items
1029+ RELATIVE "${ZORBA_MODULES_DIR}"
1030+ "${ZORBA_MODULES_DIR}/[a-zA-Z0-9]*")
1031
1032 # Filter out non-directories
1033 SET (module_dirs)
1034@@ -37,19 +43,27 @@
1035 ENDIF (IS_DIRECTORY "${ZORBA_MODULES_DIR}/${module_dir}")
1036 ENDFOREACH (module_dir)
1037
1038+# First, form a simple list of all known module projects in the
1039+# variable "module_projects". Also, for each project, set a variable
1040+# named eg. "zorba-email-module_DIR" with the path to that project's
1041+# directory, relative to ZORBA_MODULES_DIR.
1042+SET (project_regex "[Pp][Rr][Oo][Jj][Ee][Cc][Tt] *\\( *([^ )]*)")
1043+SET (module_projects)
1044 FOREACH (module_dir ${module_dirs})
1045- # This is really kind of hacky, but I don't know a better solution without
1046- # introducing some sort of inter-module dependency tracking and requiring
1047- # consistent directory naming for external modules. What we do here is
1048- # read the module's CMakeLists.txt (as a text file), searching for the
1049- # PROJECT() declaration, so we can extract the name of the CMake project.
1050 SET (module_project)
1051- SET (cmakelists)
1052- FILE (STRINGS "${ZORBA_MODULES_DIR}/${module_dir}/CMakeLists.txt" cmakelists
1053- REGEX ${project_regex})
1054+ SET (cmakelists_file "${ZORBA_MODULES_DIR}/${module_dir}/CMakeLists.txt")
1055+ FILE (STRINGS "${cmakelists_file}" cmakelists REGEX "${project_regex}")
1056 FOREACH (line ${cmakelists})
1057- IF (line MATCHES "${project_regex} *\\(([^)]*)\\)")
1058- SET (module_project ${CMAKE_MATCH_1})
1059+
1060+ IF (line MATCHES "${project_regex}")
1061+ IF (NOT "${module_project}" STREQUAL "")
1062+ MESSAGE (FATAL_ERROR
1063+ "${cmakelists_file} contains duplicate PROJECT() statements - "
1064+ "cannot parse!")
1065+ ENDIF (NOT "${module_project}" STREQUAL "")
1066+ SET (module_project "${CMAKE_MATCH_1}")
1067+ LIST (APPEND module_projects "${module_project}")
1068+ SET ("${module_project}_DIR" "${module_dir}")
1069
1070 # Print the found module name
1071 SET (status "Found module project ${module_project}")
1072@@ -63,8 +77,7 @@
1073 MESSAGE (STATUS "${status}")
1074 MESSAGE (STATUS "${border}")
1075
1076- BREAK ()
1077- ENDIF (line MATCHES "${project_regex} *\\(([^)]*)\\)")
1078+ ENDIF (line MATCHES "${project_regex}")
1079 ENDFOREACH (line)
1080
1081 IF (NOT module_project)
1082@@ -72,14 +85,77 @@
1083 "does not contain a recognizable CMake project.")
1084 ENDIF (NOT module_project)
1085
1086- SET (module_builddir "${CMAKE_BINARY_DIR}/zorba_modules/${module_project}")
1087- FILE (MAKE_DIRECTORY "${module_builddir}")
1088- CREATE_MODULE_CONFIG (${module_project} "${ZORBA_MODULES_DIR}/${module_dir}"
1089- "${module_builddir}")
1090- LIST (APPEND CMAKE_PREFIX_PATH "${module_builddir}")
1091- #SET (ZORBA_EXTERNAL_MODULES_SRCS ${ZORBA_EXTERNAL_MODULES_SRCS} ${ZORBA_MODULES_DIR}/${module_dir}/src)
1092-ENDFOREACH (module_dir)
1093-#SET (ZORBA_EXTERNAL_MODULES_SRCS ${ZORBA_EXTERNAL_MODULES_SRCS} PARENT_SCOPE)
1094+ENDFOREACH (module_dir)
1095+
1096+# Next, form the DAG. This comprises one list containing only those
1097+# module projects that some other module project depends on
1098+# (dep_module_projects), and a series of CMake variables named
1099+# eg. "zorba-email-module_DEPS" containing the module projects that
1100+# the named project depends on. Doing this unfortunately requires us
1101+# to read through all CMakeLists.txt files again.
1102+SET (find_package_regex
1103+ "[Ff][Ii][Nn][Dd]_[Pp][Aa][Cc][Kk][Aa][Gg][Ee] *\\( *([^ )]*)")
1104+SET (dep_module_projects)
1105+FOREACH (module_dir ${module_dirs})
1106+ SET (module_project)
1107+ SET (cmakelists_file "${ZORBA_MODULES_DIR}/${module_dir}/CMakeLists.txt")
1108+ FILE (STRINGS "${cmakelists_file}" cmakelists
1109+ REGEX "${project_regex}|${find_package_regex}")
1110+ FOREACH (line ${cmakelists})
1111+ IF (line MATCHES "${project_regex}")
1112+ # Don't have to do error checking here; was done in last pass.
1113+ SET (module_project "${CMAKE_MATCH_1}")
1114+ ELSEIF (line MATCHES "${find_package_regex}")
1115+ SET (dependee ${CMAKE_MATCH_1})
1116+ # Ensure this dependency is a known module project, and not some
1117+ # other dependency like "Zorba" - don't want those in the DAG.
1118+ LIST (FIND module_projects "${dependee}" is_known)
1119+ IF (is_known GREATER -1)
1120+ message (STATUS "${module_project} depends on ${dependee}")
1121+ # Save the dependency in a variable based on the current project
1122+ LIST (APPEND "${module_project}_DEPS" ${dependee})
1123+ # Also add this dependee to dep_module_projects
1124+ LIST (APPEND dep_module_projects ${dependee})
1125+ ENDIF (is_known GREATER -1)
1126+ ENDIF (line MATCHES "${project_regex}")
1127+ ENDFOREACH (line)
1128+
1129+ENDFOREACH (module_dir)
1130+
1131+
1132+# Now, transform the DAG into a dependency-ordered list. See
1133+# http://en.wikipedia.org/wiki/Topological_sorting .
1134+SET (no_deps)
1135+SET (visited)
1136+SET (ordered_modules)
1137+MACRO (VISIT mod_name)
1138+ LIST (FIND visited "${mod_name}" is_visited)
1139+ IF (is_visited EQUAL -1)
1140+ # Haven't seen this module before; iterate through modules that depend on it
1141+ LIST (APPEND visited "${mod_name}")
1142+ FOREACH (depender ${${mod_name}_DEPS})
1143+ VISIT ("${depender}")
1144+ ENDFOREACH (depender)
1145+ # Now that all modules that depend on it have been added, add this one
1146+ LIST (APPEND ordered_modules "${mod_name}")
1147+ ELSE (is_visited EQUAL -1)
1148+ ENDIF (is_visited EQUAL -1)
1149+ENDMACRO (VISIT)
1150+# Annoying - LIST(REMOVE_DUPLICATES) dies if the list is empty.
1151+LIST (LENGTH dep_module_projects num_deps)
1152+IF (num_deps GREATER 0)
1153+ LIST (REMOVE_DUPLICATES dep_module_projects)
1154+ENDIF (num_deps GREATER 0)
1155+FOREACH (module_project ${module_projects})
1156+ # Only initially visit those modules projects that do NOT have any
1157+ # module projects depending on them; that is, only visit those module
1158+ # projects that are NOT in dep_module_projects.
1159+ LIST (FIND dep_module_projects "${module_project}" is_dep)
1160+ IF (is_dep EQUAL -1)
1161+ VISIT (${module_project})
1162+ ENDIF (is_dep EQUAL -1)
1163+
1164+ENDFOREACH (module_project)
1165
1166 # Each of these projects will also want to be able to
1167 # FIND_PACKAGE(Zorba), so add our own build dir to the CMake module
1168@@ -89,9 +165,16 @@
1169 # Now, iterate through all the module projects again and actually add
1170 # them to this Zorba project. Create a binary directory for them
1171 # inside our own.
1172-FOREACH (module_dir ${module_dirs})
1173+FOREACH (module_project ${ordered_modules})
1174+ # Create the module binary directory and add it to CMAKE_PREFIX_PATH
1175+ # so other modules can find it. Then, add the module project
1176+ # directory.
1177+ SET (module_dir "${${module_project}_DIR}")
1178+ SET (module_builddir "${CMAKE_BINARY_DIR}/zorba_modules/${module_project}")
1179+ FILE (MAKE_DIRECTORY "${module_builddir}")
1180+ LIST (APPEND CMAKE_PREFIX_PATH "${module_builddir}")
1181 ADD_SUBDIRECTORY("${ZORBA_MODULES_DIR}/${module_dir}"
1182- "${CMAKE_BINARY_DIR}/zorba_modules/zorba_${module_dir}_module")
1183-ENDFOREACH (module_dir)
1184+ "${CMAKE_BINARY_DIR}/zorba_modules/${module_project}")
1185+ENDFOREACH (module_project)
1186
1187 MESSAGE(STATUS "End modules")
1188
1189=== modified file 'modules/ExternalModules.conf'
1190--- modules/ExternalModules.conf 2012-03-30 19:03:09 +0000
1191+++ modules/ExternalModules.conf 2012-04-14 07:09:19 +0000
1192@@ -40,3 +40,5 @@
1193 system bzr lp:zorba/system-module zorba-2.2
1194 xqxq bzr lp:zorba/xqxq-module zorba-2.2
1195 email bzr lp:zorba/email-module zorba-2.2
1196+util-jvm bzr lp:zorba/util-jvm-module
1197+schema-tools bzr lp:zorba/schema-tools-module
1198
1199=== modified file 'src/api/zorbaimpl.cpp'
1200--- src/api/zorbaimpl.cpp 2012-03-30 19:03:09 +0000
1201+++ src/api/zorbaimpl.cpp 2012-04-14 07:09:19 +0000
1202@@ -35,6 +35,7 @@
1203 #include "diagnostics/xquery_diagnostics.h"
1204
1205 #include "system/globalenv.h"
1206+#include "system/properties.h"
1207
1208 #include "context/static_context.h"
1209
1210@@ -269,6 +270,15 @@
1211 }
1212
1213
1214+/*******************************************************************************
1215+
1216+********************************************************************************/
1217+PropertiesGlobal* ZorbaImpl::getPropertiesGlobal()
1218+{
1219+ return Properties::instance();
1220+}
1221+
1222+
1223 void ZorbaImpl::notifyError( DiagnosticHandler *eh, ZorbaException const &ze ) {
1224 eh->error( ze );
1225 }
1226
1227=== modified file 'src/api/zorbaimpl.h'
1228--- src/api/zorbaimpl.h 2012-03-30 19:03:09 +0000
1229+++ src/api/zorbaimpl.h 2012-04-14 07:09:19 +0000
1230@@ -134,6 +134,8 @@
1231
1232 audit::Provider* getAuditProvider();
1233
1234+ PropertiesGlobal* getPropertiesGlobal();
1235+
1236 protected:
1237 ZorbaImpl();
1238
1239
1240=== modified file 'src/context/dynamic_loader.cpp'
1241--- src/context/dynamic_loader.cpp 2012-03-30 19:03:09 +0000
1242+++ src/context/dynamic_loader.cpp 2012-04-14 07:09:19 +0000
1243@@ -132,8 +132,15 @@
1244 ExternalModule*
1245 DynamicLoader::loadModule(const zstring& aFile) const
1246 {
1247- // function pointer to create a module
1248- ExternalModule* (*createModule)() = NULL;
1249+ handle_t handle;
1250+ std::map<const zstring, handle_t>::const_iterator lIter;
1251+
1252+ lIter = theLibraries.find(aFile);
1253+ if (lIter != theLibraries.end())
1254+ {
1255+ handle = lIter->second;
1256+ return createModule(handle, aFile);
1257+ }
1258
1259 #ifdef WIN32
1260 WCHAR wpath_str[1024];
1261@@ -146,43 +153,51 @@
1262 0, aFile.c_str(), -1,
1263 wpath_str, sizeof(wpath_str)/sizeof(WCHAR));
1264 }
1265- HMODULE handle = LoadLibraryW(wpath_str);
1266+
1267+ handle = LoadLibraryW(wpath_str);
1268 if (!handle)
1269 throw ZORBA_EXCEPTION(
1270 zerr::ZOSE0005_DLL_LOAD_FAILED,
1271 ERROR_PARAMS( aFile, os_error::get_err_string() )
1272 );
1273-
1274+#else
1275+ handle = dlopen(aFile.c_str(), RTLD_NOW);
1276+ if (!handle)
1277+ throw ZORBA_EXCEPTION(
1278+ zerr::ZOSE0005_DLL_LOAD_FAILED, ERROR_PARAMS( aFile, zstring(dlerror()) )
1279+ );
1280+#endif
1281+
1282+ theLibraries[aFile] = handle;
1283+ return createModule(handle, aFile);
1284+}
1285+
1286+
1287+ExternalModule*
1288+DynamicLoader::createModule(handle_t handle, const zstring& aFile) const
1289+{
1290+ // function pointer to create a module
1291+ ExternalModule* (*createModuleFunction)() = NULL;
1292+
1293+#ifdef WIN32
1294 createModule = (ExternalModule* (*)())GetProcAddress(handle, "createModule");
1295- if (createModule == NULL)
1296+ if (createModuleFunction == NULL)
1297 throw ZORBA_EXCEPTION(
1298 zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
1299 ERROR_PARAMS( aFile, os_error::get_err_string() )
1300 );
1301-
1302 #else
1303- void* handle = dlopen(aFile.c_str(), RTLD_NOW);
1304- if (!handle)
1305- throw ZORBA_EXCEPTION(
1306- zerr::ZOSE0005_DLL_LOAD_FAILED, ERROR_PARAMS( aFile, zstring(dlerror()) )
1307- );
1308-
1309- createModule = (ExternalModule* (*)()) dlsym(handle, "createModule");
1310- if (createModule == NULL)
1311+ createModuleFunction = (ExternalModule* (*)()) dlsym(handle, "createModule");
1312+ if (createModuleFunction == NULL)
1313 {
1314 dlclose(handle);
1315 throw ZORBA_EXCEPTION(
1316- zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
1317- ERROR_PARAMS( aFile, dlerror() )
1318- );
1319+ zerr::ZAPI0015_CREATEMODULE_NOT_FOUND,
1320+ ERROR_PARAMS( aFile, dlerror() )
1321+ );
1322 }
1323 #endif
1324- if (theLibraries.find(handle) == theLibraries.end())
1325- {
1326- theLibraries.insert(handle);
1327- }
1328-
1329- return createModule();
1330+ return createModuleFunction();
1331 }
1332
1333
1334@@ -193,13 +208,13 @@
1335
1336 DynamicLoader::~DynamicLoader()
1337 {
1338- for (LibrarySet_t::const_iterator lIter = theLibraries.begin();
1339+ for (LibraryMap_t::const_iterator lIter = theLibraries.begin();
1340 lIter != theLibraries.end(); ++lIter)
1341 {
1342 #ifdef WIN32
1343- FreeLibrary(*lIter);
1344+ FreeLibrary(lIter->second);
1345 #else
1346- dlclose(*lIter);
1347+ dlclose(lIter->second);
1348 #endif
1349 }
1350 }
1351
1352=== modified file 'src/context/dynamic_loader.h'
1353--- src/context/dynamic_loader.h 2012-03-30 19:03:09 +0000
1354+++ src/context/dynamic_loader.h 2012-04-14 07:09:19 +0000
1355@@ -18,7 +18,7 @@
1356 #define ZORBA_DYNAMIC_LOADER_H
1357
1358 #include "common/common.h"
1359-#include <set>
1360+#include <map>
1361 #include "common/shared_types.h"
1362
1363 namespace zorba {
1364@@ -40,15 +40,20 @@
1365
1366 ~DynamicLoader();
1367
1368- ExternalModule* loadModule(const zstring& aFile) const;
1369
1370 #ifdef WIN32
1371- typedef std::set<HMODULE> LibrarySet_t;
1372+ typedef HMODULE handle_t;
1373 #else
1374- typedef std::set<void*> LibrarySet_t;
1375+ typedef void * handle_t;
1376 #endif
1377
1378- mutable LibrarySet_t theLibraries;
1379+ ExternalModule* loadModule(const zstring& aFile) const;
1380+ ExternalModule* createModule(handle_t handle, const zstring& aFile) const;
1381+
1382+
1383+ typedef std::map<const zstring, handle_t> LibraryMap_t;
1384+
1385+ mutable LibraryMap_t theLibraries;
1386 };
1387
1388 } /* namespace zorba */
1389
1390=== modified file 'src/system/properties.h'
1391--- src/system/properties.h 2012-03-30 19:03:09 +0000
1392+++ src/system/properties.h 2012-04-14 07:09:19 +0000
1393@@ -67,6 +67,27 @@
1394
1395 std::ostream& debug_out() { return *debug_stream; }
1396
1397+ /**
1398+ * Before the JVM is started this will return the classpath set by
1399+ * command line option, the CLASSPATH environment variable and in Zorba
1400+ * config file.
1401+ *
1402+ * After the JVM is started this will contain in addition the paths to jars
1403+ * used by modules that make use of the JVM.
1404+ */
1405+ void getJVMClassPath(std::string & jvmClasspath)
1406+ { jvmClasspath = theCLASSPATH ; }
1407+
1408+ /**
1409+ * This method should be used to set additional JVM classpath for modules
1410+ * that make use of JVM. This will overide the classpath set by CLASSPATH
1411+ * environment variable or Zorba config file.
1412+ *
1413+ * Once the JVM is started this method doesn't have any effect.
1414+ */
1415+ void setJVMClassPath(const std::string & jvmClasspath)
1416+ { theCLASSPATH = jvmClasspath; }
1417+
1418 protected:
1419 /**
1420 * Gets the Operation System folder where the properties of the current
1421
1422=== modified file 'src/system/zorba_properties.h'
1423--- src/system/zorba_properties.h 2012-03-30 19:03:09 +0000
1424+++ src/system/zorba_properties.h 2012-04-14 07:09:19 +0000
1425@@ -26,13 +26,25 @@
1426 namespace zorba
1427 {
1428
1429-class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesBase
1430+class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesGlobal
1431 {
1432 protected:
1433 const char** get_all_options() const
1434 {
1435- static const char* result [] =
1436- { "--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 };
1437+ static const char* result [] = {
1438+ "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer",
1439+ "--result-file", "--debug-file", "--abort", "--query", "--print-query",
1440+ "--print-time", "--print-ast", "--print-xqdoc", "--print-translated",
1441+ "--print-normalized", "--print-optimized", "--print-iterator-tree",
1442+ "--print-item-flow", "--print-static-types", "--dump-lib",
1443+ "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt",
1444+ "--print-locations", "--force-gflwor", "--reorder-globals",
1445+ "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting",
1446+ "--infer-joins", "--no-copy-optim", "--serialize-only-query",
1447+ "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug",
1448+ "--compile-only", "--tz", "--external-var", "--serializer-param",
1449+ "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth",
1450+ "--CLASSPATH", NULL };
1451
1452 return result;
1453 }
1454@@ -80,6 +92,7 @@
1455 bool theIterPlanTest;
1456 std::string theDotPlanFile;
1457 uint32_t theMaxUdfCallDepth;
1458+ std::string theCLASSPATH;
1459
1460 void initialize()
1461 {
1462@@ -165,6 +178,7 @@
1463 const bool &iterPlanTest () const { return theIterPlanTest; }
1464 const std::string &dotPlanFile () const { return theDotPlanFile; }
1465 const uint32_t &maxUdfCallDepth () const { return theMaxUdfCallDepth; }
1466+ const std::string &CLASSPATH () const { return theCLASSPATH; }
1467
1468 std::string load_argv (int argc, const char **argv)
1469 {
1470@@ -200,7 +214,9 @@
1471 else if (strcmp (*argv, "--debug-file") == 0) {
1472 int d = 2;
1473 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1474- if (*argv == NULL) { result = "No value given for --debug-file option"; break; } init_val (*argv, theDebugFile, d);
1475+ if (*argv == NULL) { result = "No value given for --debug-file option"; break; }
1476+
1477+ init_val (*argv, theDebugFile, d);
1478 }
1479 else if (strcmp (*argv, "--abort") == 0) {
1480 theAbort = true;
1481@@ -208,7 +224,9 @@
1482 else if (strcmp (*argv, "--query") == 0 || strncmp (*argv, "-e", 2) == 0) {
1483 int d = 2;
1484 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1485- if (*argv == NULL) { result = "No value given for --query option"; break; } init_val (*argv, theQuery, d);
1486+ if (*argv == NULL) { result = "No value given for --query option"; break; }
1487+
1488+ init_val (*argv, theQuery, d);
1489 }
1490 else if (strcmp (*argv, "--print-query") == 0 || strncmp (*argv, "-q", 2) == 0) {
1491 thePrintQuery = true;
1492@@ -240,7 +258,9 @@
1493 else if (strcmp (*argv, "--print-static-types") == 0) {
1494 int d = 2;
1495 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1496- if (*argv == NULL) { result = "No value given for --print-static-types option"; break; } init_val (*argv, thePrintStaticTypes, d);
1497+ if (*argv == NULL) { result = "No value given for --print-static-types option"; break; }
1498+
1499+ init_val (*argv, thePrintStaticTypes, d);
1500 }
1501 else if (strcmp (*argv, "--dump-lib") == 0) {
1502 theDumpLib = true;
1503@@ -263,32 +283,44 @@
1504 else if (strcmp (*argv, "--reorder-globals") == 0) {
1505 int d = 2;
1506 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1507- if (*argv == NULL) { result = "No value given for --reorder-globals option"; break; } init_val (*argv, theReorderGlobals, d);
1508+ if (*argv == NULL) { result = "No value given for --reorder-globals option"; break; }
1509+
1510+ init_val (*argv, theReorderGlobals, d);
1511 }
1512 else if (strcmp (*argv, "--specialize-num") == 0) {
1513 int d = 2;
1514 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1515- if (*argv == NULL) { result = "No value given for --specialize-num option"; break; } init_val (*argv, theSpecializeNum, d);
1516+ if (*argv == NULL) { result = "No value given for --specialize-num option"; break; }
1517+
1518+ init_val (*argv, theSpecializeNum, d);
1519 }
1520 else if (strcmp (*argv, "--specialize-cmp") == 0) {
1521 int d = 2;
1522 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1523- if (*argv == NULL) { result = "No value given for --specialize-cmp option"; break; } init_val (*argv, theSpecializeCmp, d);
1524+ if (*argv == NULL) { result = "No value given for --specialize-cmp option"; break; }
1525+
1526+ init_val (*argv, theSpecializeCmp, d);
1527 }
1528 else if (strcmp (*argv, "--inline-udf") == 0) {
1529 int d = 2;
1530 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1531- if (*argv == NULL) { result = "No value given for --inline-udf option"; break; } init_val (*argv, theInlineUdf, d);
1532+ if (*argv == NULL) { result = "No value given for --inline-udf option"; break; }
1533+
1534+ init_val (*argv, theInlineUdf, d);
1535 }
1536 else if (strcmp (*argv, "--loop-hoisting") == 0) {
1537 int d = 2;
1538 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1539- if (*argv == NULL) { result = "No value given for --loop-hoisting option"; break; } init_val (*argv, theLoopHoisting, d);
1540+ if (*argv == NULL) { result = "No value given for --loop-hoisting option"; break; }
1541+
1542+ init_val (*argv, theLoopHoisting, d);
1543 }
1544 else if (strcmp (*argv, "--infer-joins") == 0) {
1545 int d = 2;
1546 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1547- if (*argv == NULL) { result = "No value given for --infer-joins option"; break; } init_val (*argv, theInferJoins, d);
1548+ if (*argv == NULL) { result = "No value given for --infer-joins option"; break; }
1549+
1550+ init_val (*argv, theInferJoins, d);
1551 }
1552 else if (strcmp (*argv, "--no-copy-optim") == 0)
1553 {
1554@@ -325,17 +357,23 @@
1555 else if (strcmp (*argv, "--tz") == 0) {
1556 int d = 2;
1557 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1558- if (*argv == NULL) { result = "No value given for --tz option"; break; } init_val (*argv, theTz, d);
1559+ if (*argv == NULL) { result = "No value given for --tz option"; break; }
1560+
1561+ init_val (*argv, theTz, d);
1562 }
1563 else if (strcmp (*argv, "--external-var") == 0 || strncmp (*argv, "-x", 2) == 0) {
1564 int d = 2;
1565 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1566- if (*argv == NULL) { result = "No value given for --external-var option"; break; } init_val (*argv, theExternalVar, d);
1567+ if (*argv == NULL) { result = "No value given for --external-var option"; break; }
1568+
1569+ init_val (*argv, theExternalVar, d);
1570 }
1571 else if (strcmp (*argv, "--serializer-param") == 0 || strncmp (*argv, "-z", 2) == 0) {
1572 int d = 2;
1573 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1574- if (*argv == NULL) { result = "No value given for --serializer-param option"; break; } init_val (*argv, theSerializerParam, d);
1575+ if (*argv == NULL) { result = "No value given for --serializer-param option"; break; }
1576+
1577+ init_val (*argv, theSerializerParam, d);
1578 }
1579 else if (strcmp (*argv, "--iter-plan-test") == 0) {
1580 theIterPlanTest = true;
1581@@ -343,12 +381,23 @@
1582 else if (strcmp (*argv, "--dot-plan-file") == 0) {
1583 int d = 2;
1584 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1585- if (*argv == NULL) { result = "No value given for --dot-plan-file option"; break; } init_val (*argv, theDotPlanFile, d);
1586+ if (*argv == NULL) { result = "No value given for --dot-plan-file option"; break; }
1587+
1588+ init_val (*argv, theDotPlanFile, d);
1589 }
1590 else if (strcmp (*argv, "--max-udf-call-depth") == 0) {
1591 int d = 2;
1592 if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1593- if (*argv == NULL) { result = "No value given for --max-udf-call-depth option"; break; } init_val (*argv, theMaxUdfCallDepth, d);
1594+ if (*argv == NULL) { result = "No value given for --max-udf-call-depth option"; break; }
1595+
1596+ init_val (*argv, theMaxUdfCallDepth, d);
1597+ }
1598+ else if (strcmp (*argv, "--CLASSPATH") == 0) {
1599+ int d = 2;
1600+ if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
1601+ if (*argv == NULL) { result = "No value given for --CLASSPATH option"; break; }
1602+
1603+ init_val (*argv, theCLASSPATH, d);
1604 }
1605 else if (strcmp (*argv, "--") == 0) {
1606 copy_args (++argv);
1607@@ -413,6 +462,7 @@
1608 "--iter-plan-test\nrun as iterator plan test\n\n"
1609 "--dot-plan-file\ngenerate the dot iterator plan\n\n"
1610 "--max-udf-call-depth\nmaximum stack depth of udf function calls\n\n"
1611+"--CLASSPATH\nJVM classpath to be used by modules using Java implementations\n\n"
1612 ;
1613 }
1614
1615
1616=== modified file 'src/system/zorba_properties.txt'
1617--- src/system/zorba_properties.txt 2012-03-30 19:03:09 +0000
1618+++ src/system/zorba_properties.txt 2012-04-14 07:09:19 +0000
1619@@ -43,3 +43,4 @@
1620 ("iter-plan-test", "run as iterator plan test")
1621 ("dot-plan-file", po::value<std::string>(), "generate the dot iterator plan")
1622 ("max-udf-call-depth", po::value<uint32_t>()->default_value(1024), "maximum stack depth of udf function calls")
1623+ ("CLASSPATH", po::value<std::string>(), "JVM classpath to be used by modules using Java implementations")
1624\ No newline at end of file
1625
1626=== modified file 'src/util/file.cpp'
1627--- src/util/file.cpp 2012-03-30 19:03:09 +0000
1628+++ src/util/file.cpp 2012-04-14 07:09:19 +0000
1629@@ -277,6 +277,18 @@
1630 #endif
1631 }
1632
1633+void file::lsdir(std::vector<std::string> &list) {
1634+#ifdef ZORBA_WITH_FILE_ACCESS
1635+ try {
1636+ fs::lsdir( c_str(), list );
1637+ set_filetype( type_directory );
1638+ }
1639+ catch ( fs::exception const &e ) {
1640+ throw ZORBA_IO_EXCEPTION( e.function(), e.path() );
1641+ }
1642+#endif
1643+}
1644+
1645 void file::deep_mkdir() {
1646 #ifdef ZORBA_WITH_FILE_ACCESS
1647 vector<file> files;
1648
1649=== modified file 'src/util/fs_util.cpp'
1650--- src/util/fs_util.cpp 2012-03-30 19:03:09 +0000
1651+++ src/util/fs_util.cpp 2012-04-14 07:09:19 +0000
1652@@ -277,6 +277,30 @@
1653 #endif
1654 }
1655
1656+void lsdir( char const *path, std::vector<std::string> &list )
1657+{
1658+ DIR *dir;
1659+ struct dirent *ent;
1660+
1661+ dir = opendir (path);
1662+ if (dir != NULL)
1663+ {
1664+ /* print all the files and directories within directory */
1665+ while ((ent = readdir (dir)) != NULL)
1666+ {
1667+ //printf ("%s\n", ent->d_name);
1668+ std::string item(ent->d_name);
1669+ list.push_back(item);
1670+ }
1671+ closedir (dir);
1672+ }
1673+ else
1674+ {
1675+ /* could not open directory */
1676+ throw fs::exception( "lsdir()", path );
1677+ }
1678+}
1679+
1680 bool remove( char const *path ) {
1681 #ifndef WIN32
1682 return ::remove( path ) == 0;
1683
1684=== modified file 'src/util/fs_util.h'
1685--- src/util/fs_util.h 2012-03-30 19:03:09 +0000
1686+++ src/util/fs_util.h 2012-04-14 07:09:19 +0000
1687@@ -17,6 +17,14 @@
1688 #ifndef ZORBA_FS_UTIL_H
1689 #define ZORBA_FS_UTIL_H
1690
1691+#include <vector>
1692+
1693+#ifdef WIN32
1694+# include "win32/dirent.h"
1695+#else
1696+# include <dirent.h> /* for implementing lsdir */
1697+#endif /* WIN32 */
1698+
1699 #include <zorba/config.h>
1700
1701 #include <stdexcept>
1702@@ -144,6 +152,26 @@
1703 mkdir( path.c_str() );
1704 }
1705
1706+/**
1707+ * List files in dir
1708+ *
1709+ * @param path The full path of the directory to list.
1710+ * @throws fs::exception if the list fails.
1711+ */
1712+void lsdir( char const *path, std::vector<std::string> & list );
1713+
1714+/**
1715+ * List files in dir
1716+ *
1717+ * @tparam PathStringType The \a path string type.
1718+ * @param path The full path of the directory to list.
1719+ * @throws fs::exception if the list fails.
1720+ */
1721+template<class PathStringType> inline
1722+void lsdir( PathStringType const &path, std::vector<std::string> & list ) {
1723+ lsdir( path.c_str(), list );
1724+}
1725+
1726 #endif /* ZORBA_WITH_FILE_ACCESS */
1727
1728 ////////// File creation //////////////////////////////////////////////////////
1729
1730=== added file 'src/util/win32/dirent.h'
1731--- src/util/win32/dirent.h 1970-01-01 00:00:00 +0000
1732+++ src/util/win32/dirent.h 2012-04-14 07:09:19 +0000
1733@@ -0,0 +1,372 @@
1734+/*****************************************************************************
1735+ * dirent.h - dirent API for Microsoft Visual Studio
1736+ *
1737+ * Copyright (C) 2006 Toni Ronkko
1738+ *
1739+ * Permission is hereby granted, free of charge, to any person obtaining
1740+ * a copy of this software and associated documentation files (the
1741+ * ``Software''), to deal in the Software without restriction, including
1742+ * without limitation the rights to use, copy, modify, merge, publish,
1743+ * distribute, sublicense, and/or sell copies of the Software, and to
1744+ * permit persons to whom the Software is furnished to do so, subject to
1745+ * the following conditions:
1746+ *
1747+ * The above copyright notice and this permission notice shall be included
1748+ * in all copies or substantial portions of the Software.
1749+ *
1750+ * THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
1751+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1752+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
1753+ * IN NO EVENT SHALL TONI RONKKO BE LIABLE FOR ANY CLAIM, DAMAGES OR
1754+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1755+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
1756+ * OTHER DEALINGS IN THE SOFTWARE.
1757+ *
1758+ * Mar 15, 2011, Toni Ronkko
1759+ * Defined FILE_ATTRIBUTE_DEVICE for MSVC 6.0.
1760+ *
1761+ * Aug 11, 2010, Toni Ronkko
1762+ * Added d_type and d_namlen fields to dirent structure. The former is
1763+ * especially useful for determining whether directory entry represents a
1764+ * file or a directory. For more information, see
1765+ * http://www.delorie.com/gnu/docs/glibc/libc_270.html
1766+ *
1767+ * Aug 11, 2010, Toni Ronkko
1768+ * Improved conformance to the standards. For example, errno is now set
1769+ * properly on failure and assert() is never used. Thanks to Peter Brockam
1770+ * for suggestions.
1771+ *
1772+ * Aug 11, 2010, Toni Ronkko
1773+ * Fixed a bug in rewinddir(): when using relative directory names, change
1774+ * of working directory no longer causes rewinddir() to fail.
1775+ *
1776+ * Dec 15, 2009, John Cunningham
1777+ * Added rewinddir member function
1778+ *
1779+ * Jan 18, 2008, Toni Ronkko
1780+ * Using FindFirstFileA and WIN32_FIND_DATAA to avoid converting string
1781+ * between multi-byte and unicode representations. This makes the
1782+ * code simpler and also allows the code to be compiled under MingW. Thanks
1783+ * to Azriel Fasten for the suggestion.
1784+ *
1785+ * Mar 4, 2007, Toni Ronkko
1786+ * Bug fix: due to the strncpy_s() function this file only compiled in
1787+ * Visual Studio 2005. Using the new string functions only when the
1788+ * compiler version allows.
1789+ *
1790+ * Nov 2, 2006, Toni Ronkko
1791+ * Major update: removed support for Watcom C, MS-DOS and Turbo C to
1792+ * simplify the file, updated the code to compile cleanly on Visual
1793+ * Studio 2005 with both unicode and multi-byte character strings,
1794+ * removed rewinddir() as it had a bug.
1795+ *
1796+ * Aug 20, 2006, Toni Ronkko
1797+ * Removed all remarks about MSVC 1.0, which is antiqued now. Simplified
1798+ * comments by removing SGML tags.
1799+ *
1800+ * May 14 2002, Toni Ronkko
1801+ * Embedded the function definitions directly to the header so that no
1802+ * source modules need to be included in the Visual Studio project. Removed
1803+ * all the dependencies to other projects so that this very header can be
1804+ * used independently.
1805+ *
1806+ * May 28 1998, Toni Ronkko
1807+ * First version.
1808+ *****************************************************************************/
1809+#ifndef DIRENT_H
1810+#define DIRENT_H
1811+
1812+#define WIN32_LEAN_AND_MEAN
1813+#include <windows.h>
1814+#include <string.h>
1815+#include <stdlib.h>
1816+#include <sys/types.h>
1817+#include <sys/stat.h>
1818+#include <errno.h>
1819+
1820+/* Entries missing from MSVC 6.0 */
1821+#if !defined(FILE_ATTRIBUTE_DEVICE)
1822+# define FILE_ATTRIBUTE_DEVICE 0x40
1823+#endif
1824+
1825+/* File type and permission flags for stat() */
1826+#if defined(_MSC_VER) && !defined(S_IREAD)
1827+# define S_IFMT _S_IFMT /* file type mask */
1828+# define S_IFDIR _S_IFDIR /* directory */
1829+# define S_IFCHR _S_IFCHR /* character device */
1830+# define S_IFFIFO _S_IFFIFO /* pipe */
1831+# define S_IFREG _S_IFREG /* regular file */
1832+# define S_IREAD _S_IREAD /* read permission */
1833+# define S_IWRITE _S_IWRITE /* write permission */
1834+# define S_IEXEC _S_IEXEC /* execute permission */
1835+#endif
1836+#define S_IFBLK 0 /* block device */
1837+#define S_IFLNK 0 /* link */
1838+#define S_IFSOCK 0 /* socket */
1839+
1840+#if defined(_MSC_VER)
1841+# define S_IRUSR S_IREAD /* read, user */
1842+# define S_IWUSR S_IWRITE /* write, user */
1843+# define S_IXUSR 0 /* execute, user */
1844+# define S_IRGRP 0 /* read, group */
1845+# define S_IWGRP 0 /* write, group */
1846+# define S_IXGRP 0 /* execute, group */
1847+# define S_IROTH 0 /* read, others */
1848+# define S_IWOTH 0 /* write, others */
1849+# define S_IXOTH 0 /* execute, others */
1850+#endif
1851+
1852+/* Indicates that d_type field is available in dirent structure */
1853+#define _DIRENT_HAVE_D_TYPE
1854+
1855+/* File type flags for d_type */
1856+#define DT_UNKNOWN 0
1857+#define DT_REG S_IFREG
1858+#define DT_DIR S_IFDIR
1859+#define DT_FIFO S_IFFIFO
1860+#define DT_SOCK S_IFSOCK
1861+#define DT_CHR S_IFCHR
1862+#define DT_BLK S_IFBLK
1863+
1864+/* Macros for converting between st_mode and d_type */
1865+#define IFTODT(mode) ((mode) & S_IFMT)
1866+#define DTTOIF(type) (type)
1867+
1868+/*
1869+ * File type macros. Note that block devices, sockets and links cannot be
1870+ * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
1871+ * only defined for compatibility. These macros should always return false
1872+ * on Windows.
1873+ */
1874+#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFFIFO)
1875+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
1876+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
1877+#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
1878+#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
1879+#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
1880+#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
1881+
1882+#ifdef __cplusplus
1883+extern "C" {
1884+#endif
1885+
1886+
1887+typedef struct dirent
1888+{
1889+ char d_name[MAX_PATH + 1]; /* File name */
1890+ size_t d_namlen; /* Length of name without \0 */
1891+ int d_type; /* File type */
1892+} dirent;
1893+
1894+
1895+typedef struct DIR
1896+{
1897+ dirent curentry; /* Current directory entry */
1898+ WIN32_FIND_DATAA find_data; /* Private file data */
1899+ int cached; /* True if data is valid */
1900+ HANDLE search_handle; /* Win32 search handle */
1901+ char patt[MAX_PATH + 3]; /* Initial directory name */
1902+} DIR;
1903+
1904+
1905+/* Forward declarations */
1906+static DIR *opendir(const char *dirname);
1907+static struct dirent *readdir(DIR *dirp);
1908+static int closedir(DIR *dirp);
1909+static void rewinddir(DIR* dirp);
1910+
1911+
1912+/* Use the new safe string functions introduced in Visual Studio 2005 */
1913+#if defined(_MSC_VER) && _MSC_VER >= 1400
1914+# define DIRENT_STRNCPY(dest,src,size) strncpy_s((dest),(size),(src),_TRUNCATE)
1915+#else
1916+# define DIRENT_STRNCPY(dest,src,size) strncpy((dest),(src),(size))
1917+#endif
1918+
1919+/* Set errno variable */
1920+#if defined(_MSC_VER)
1921+#define DIRENT_SET_ERRNO(x) _set_errno (x)
1922+#else
1923+#define DIRENT_SET_ERRNO(x) (errno = (x))
1924+#endif
1925+
1926+
1927+/*****************************************************************************
1928+ * Open directory stream DIRNAME for read and return a pointer to the
1929+ * internal working area that is used to retrieve individual directory
1930+ * entries.
1931+ */
1932+static DIR *opendir(const char *dirname)
1933+{
1934+ DIR *dirp;
1935+
1936+ /* ensure that the resulting search pattern will be a valid file name */
1937+ if (dirname == NULL) {
1938+ DIRENT_SET_ERRNO (ENOENT);
1939+ return NULL;
1940+ }
1941+ if (strlen (dirname) + 3 >= MAX_PATH) {
1942+ DIRENT_SET_ERRNO (ENAMETOOLONG);
1943+ return NULL;
1944+ }
1945+
1946+ /* construct new DIR structure */
1947+ dirp = (DIR*) malloc (sizeof (struct DIR));
1948+ if (dirp != NULL) {
1949+ int error;
1950+
1951+ /*
1952+ * Convert relative directory name to an absolute one. This
1953+ * allows rewinddir() to function correctly when the current working
1954+ * directory is changed between opendir() and rewinddir().
1955+ */
1956+ if (GetFullPathNameA (dirname, MAX_PATH, dirp->patt, NULL)) {
1957+ char *p;
1958+
1959+ /* append the search pattern "\\*\0" to the directory name */
1960+ p = strchr (dirp->patt, '\0');
1961+ if (dirp->patt < p && *(p-1) != '\\' && *(p-1) != ':') {
1962+ *p++ = '\\';
1963+ }
1964+ *p++ = '*';
1965+ *p = '\0';
1966+
1967+ /* open directory stream and retrieve the first entry */
1968+ dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
1969+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
1970+ /* a directory entry is now waiting in memory */
1971+ dirp->cached = 1;
1972+ error = 0;
1973+ } else {
1974+ /* search pattern is not a directory name? */
1975+ DIRENT_SET_ERRNO (ENOENT);
1976+ error = 1;
1977+ }
1978+ } else {
1979+ /* buffer too small */
1980+ DIRENT_SET_ERRNO (ENOMEM);
1981+ error = 1;
1982+ }
1983+
1984+ if (error) {
1985+ free (dirp);
1986+ dirp = NULL;
1987+ }
1988+ }
1989+
1990+ return dirp;
1991+}
1992+
1993+
1994+/*****************************************************************************
1995+ * Read a directory entry, and return a pointer to a dirent structure
1996+ * containing the name of the entry in d_name field. Individual directory
1997+ * entries returned by this very function include regular files,
1998+ * sub-directories, pseudo-directories "." and "..", but also volume labels,
1999+ * hidden files and system files may be returned.
2000+ */
2001+static struct dirent *readdir(DIR *dirp)
2002+{
2003+ DWORD attr;
2004+ if (dirp == NULL) {
2005+ /* directory stream did not open */
2006+ DIRENT_SET_ERRNO (EBADF);
2007+ return NULL;
2008+ }
2009+
2010+ /* get next directory entry */
2011+ if (dirp->cached != 0) {
2012+ /* a valid directory entry already in memory */
2013+ dirp->cached = 0;
2014+ } else {
2015+ /* get the next directory entry from stream */
2016+ if (dirp->search_handle == INVALID_HANDLE_VALUE) {
2017+ return NULL;
2018+ }
2019+ if (FindNextFileA (dirp->search_handle, &dirp->find_data) == FALSE) {
2020+ /* the very last entry has been processed or an error occured */
2021+ FindClose (dirp->search_handle);
2022+ dirp->search_handle = INVALID_HANDLE_VALUE;
2023+ return NULL;
2024+ }
2025+ }
2026+
2027+ /* copy as a multibyte character string */
2028+ DIRENT_STRNCPY ( dirp->curentry.d_name,
2029+ dirp->find_data.cFileName,
2030+ sizeof(dirp->curentry.d_name) );
2031+ dirp->curentry.d_name[MAX_PATH] = '\0';
2032+
2033+ /* compute the length of name */
2034+ dirp->curentry.d_namlen = strlen (dirp->curentry.d_name);
2035+
2036+ /* determine file type */
2037+ attr = dirp->find_data.dwFileAttributes;
2038+ if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
2039+ dirp->curentry.d_type = DT_CHR;
2040+ } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
2041+ dirp->curentry.d_type = DT_DIR;
2042+ } else {
2043+ dirp->curentry.d_type = DT_REG;
2044+ }
2045+ return &dirp->curentry;
2046+}
2047+
2048+
2049+/*****************************************************************************
2050+ * Close directory stream opened by opendir() function. Close of the
2051+ * directory stream invalidates the DIR structure as well as any previously
2052+ * read directory entry.
2053+ */
2054+static int closedir(DIR *dirp)
2055+{
2056+ if (dirp == NULL) {
2057+ /* invalid directory stream */
2058+ DIRENT_SET_ERRNO (EBADF);
2059+ return -1;
2060+ }
2061+
2062+ /* release search handle */
2063+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
2064+ FindClose (dirp->search_handle);
2065+ dirp->search_handle = INVALID_HANDLE_VALUE;
2066+ }
2067+
2068+ /* release directory structure */
2069+ free (dirp);
2070+ return 0;
2071+}
2072+
2073+
2074+/*****************************************************************************
2075+ * Resets the position of the directory stream to which dirp refers to the
2076+ * beginning of the directory. It also causes the directory stream to refer
2077+ * to the current state of the corresponding directory, as a call to opendir()
2078+ * would have done. If dirp does not refer to a directory stream, the effect
2079+ * is undefined.
2080+ */
2081+static void rewinddir(DIR* dirp)
2082+{
2083+ if (dirp != NULL) {
2084+ /* release search handle */
2085+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
2086+ FindClose (dirp->search_handle);
2087+ }
2088+
2089+ /* open new search handle and retrieve the first entry */
2090+ dirp->search_handle = FindFirstFileA (dirp->patt, &dirp->find_data);
2091+ if (dirp->search_handle != INVALID_HANDLE_VALUE) {
2092+ /* a directory entry is now waiting in memory */
2093+ dirp->cached = 1;
2094+ } else {
2095+ /* failed to re-open directory: no directory entry in memory */
2096+ dirp->cached = 0;
2097+ }
2098+ }
2099+}
2100+
2101+
2102+#ifdef __cplusplus
2103+}
2104+#endif
2105+#endif /*DIRENT_H*/
2106
2107=== modified file 'swig/XQuery.i'
2108--- swig/XQuery.i 2012-03-30 19:03:09 +0000
2109+++ swig/XQuery.i 2012-04-14 07:09:19 +0000
2110@@ -14,62 +14,344 @@
2111 * limitations under the License.
2112 */
2113
2114+
2115 %{ // start Implementation
2116
2117- std::string XQuery::execute()
2118+class Iterator
2119+{
2120+protected:
2121+ friend class DynamicContext;
2122+ zorba::Iterator_t theIterator;
2123+ zorba::Item theItem;
2124+ bool theConsumed;
2125+
2126+public:
2127+ Iterator() {}
2128+ Iterator(const Iterator& anIterator)
2129+ : theIterator(anIterator.theIterator),
2130+ theItem(anIterator.theItem),
2131+ theConsumed(false)
2132+ {}
2133+
2134+ Iterator(zorba::Iterator_t anIterator)
2135+ : theIterator(anIterator),
2136+ theConsumed(false)
2137+ {}
2138+
2139+ Iterator(zorba::Item& aItem)
2140+ : theIterator(0),
2141+ theItem(aItem),
2142+ theConsumed(false)
2143+ {}
2144+
2145+ void open()
2146+ {
2147+ if (theIterator)
2148+ theIterator->open();
2149+ theConsumed = false;
2150+ }
2151+
2152+ bool next(Item& aItem);
2153+
2154+ void close()
2155+ {
2156+ if (theIterator)
2157+ theIterator->close();
2158+ theConsumed = true;
2159+ }
2160+
2161+ void destroy()
2162+ {
2163+ theIterator = 0;
2164+ }
2165+
2166+}; // class Iterator
2167+
2168+
2169+
2170+class Item
2171+{
2172+ friend class Iterator;
2173+ friend class StaticContext;
2174+ friend class DocumentManager;
2175+ friend class SingletonIterator;
2176+ friend class DynamicContext;
2177+ friend class ItemFactory;
2178+
2179+private:
2180+ zorba::Item theItem;
2181+
2182+public:
2183+ Item() {}
2184+ Item(const Item& aItem) : theItem(aItem.theItem) {}
2185+ Item(const zorba::Item& aZItem) : theItem(aZItem) {}
2186+
2187+ static Item createEmptyItem()
2188+ { return Item(); }
2189+
2190+ std::string getStringValue() const
2191+ { return std::string(theItem.getStringValue().c_str()); }
2192+
2193+ std::string serialize() const
2194+ {
2195+ std::stringstream lStream;
2196+ Zorba_SerializerOptions_t lOptions;
2197+ zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(lOptions);
2198+ zorba::SingletonItemSequence lSequence(theItem);
2199+ lSerializer->serialize(&lSequence, lStream);
2200+ return lStream.str();
2201+ }
2202+
2203+ Iterator getAtomizationValue () const
2204+ { return Iterator(theItem.getAtomizationValue()); }
2205+
2206+ Iterator getAttributes () const
2207+ { return Iterator(theItem.getAttributes()); }
2208+
2209+ bool getBooleanValue () const
2210+ { return theItem.getBooleanValue(); }
2211+
2212+ Iterator getChildren () const
2213+ { return Iterator(theItem.getChildren()); }
2214+
2215+ Item getEBV () const
2216+ { return Item(theItem.getEBV()); }
2217+
2218+ int getIntValue () const
2219+ { return theItem.getIntValue(); }
2220+
2221+ std::string getLocalName () const
2222+ { return std::string(theItem.getLocalName().c_str()); }
2223+
2224+ std::string getNamespace () const
2225+ { return std::string(theItem.getNamespace().c_str()); }
2226+
2227+ bool getNodeName (Item &aNodeName) const
2228+ { return theItem.getNodeName( aNodeName.theItem ); }
2229+
2230+ std::string getPrefix () const
2231+ { return std::string(theItem.getPrefix().c_str()); }
2232+
2233+ Item getType () const
2234+ { return Item( theItem.getType() ); }
2235+
2236+ unsigned int getUnsignedIntValue () const
2237+ { return theItem.getUnsignedIntValue(); }
2238+
2239+ bool isAtomic () const
2240+ { return theItem.isAtomic(); }
2241+
2242+ bool isNaN () const
2243+ { return theItem.isNaN(); }
2244+
2245+ bool isNode () const
2246+ { return theItem.isNode(); }
2247+
2248+ bool isNull () const
2249+ { return theItem.isNull(); }
2250+
2251+ bool isPosOrNegInf () const
2252+ { return theItem.isPosOrNegInf(); }
2253+
2254+ int getNodeKind () const
2255+ { return theItem.getNodeKind(); }
2256+
2257+}; // class Item
2258+
2259+class DynamicContext
2260+{
2261+private:
2262+ zorba::DynamicContext* theContext;
2263+
2264+public:
2265+ DynamicContext()
2266+ : theContext(0)
2267+ {
2268+ }
2269+
2270+ DynamicContext(const DynamicContext& aCtx)
2271+ : theContext(aCtx.theContext)
2272+ {
2273+ }
2274+
2275+ DynamicContext(zorba::DynamicContext* aCtx)
2276+ : theContext(aCtx)
2277+ {
2278+ }
2279+
2280+ void
2281+ setVariable(
2282+ const std::string& aNamespace,
2283+ const std::string& aLocalname,
2284+ Iterator aIter)
2285+ {
2286+ theContext->setVariable(aNamespace, aLocalname, aIter.theIterator);
2287+ }
2288+
2289+ void
2290+ setContextItem(Item aItem)
2291+ {
2292+ theContext->setContextItem(aItem.theItem);
2293+ }
2294+};
2295+
2296+class XQuery
2297+{
2298+private:
2299+ zorba::XQuery_t theQuery;
2300+
2301+public:
2302+ XQuery() {}
2303+ XQuery(const XQuery& aXQuery) : theQuery(aXQuery.theQuery) {}
2304+ XQuery(zorba::XQuery_t aQuery) : theQuery(aQuery) {}
2305+
2306+ std::string execute()
2307 {
2308 std::stringstream lStream;
2309 lStream << theQuery;
2310- std::string str = lStream.str();
2311- return str;
2312+ return lStream.str();
2313 }
2314-
2315- void XQuery::compile (const std::string &aQuery)
2316+
2317+ void compile (const std::string &aQuery)
2318 {
2319 theQuery->compile(aQuery);
2320 }
2321
2322- void XQuery::compile (const std::string &aQuery, StaticContext &aStaticContext )
2323+ void compile (const std::string &aQuery, StaticContext &aStaticContext )
2324 {
2325 Zorba_CompilerHints_t hints;
2326 theQuery->compile(aQuery, aStaticContext.theStaticContext, hints);
2327 }
2328-
2329- std::string XQuery::printPlanAsXML()
2330+
2331+ std::string printPlanAsXML()
2332 {
2333 std::ostringstream lStream;
2334 theQuery->printPlan(lStream);
2335 return lStream.str();
2336 }
2337
2338- std::string XQuery::printPlanAsDOT()
2339+ std::string printPlanAsDOT()
2340 {
2341 std::ostringstream lStream;
2342 theQuery->printPlan(lStream, true);
2343 return lStream.str();
2344 }
2345-
2346- DynamicContext XQuery::getDynamicContext()
2347+
2348+ DynamicContext
2349+ getDynamicContext()
2350 {
2351 return DynamicContext(theQuery->getDynamicContext());
2352 }
2353
2354- StaticContext XQuery::getStaticContext()
2355- {
2356- return StaticContext( zorba::StaticContext_t( const_cast<zorba::StaticContext *>(theQuery->getStaticContext()) ) );
2357- }
2358-
2359- void XQuery::getExternalVariables(Iterator& vars) const
2360- { theQuery->getExternalVariables( vars.theIterator ); }
2361-
2362 #ifdef SWIGPYTHON
2363- void XQuery::executeSAX(SAX2ContentHandlerProxy* contentHandlerProxy)
2364+ void executeSAX(SAX2ContentHandlerProxy* contentHandlerProxy)
2365 { theQuery->executeSAX(contentHandlerProxy); }
2366 #endif
2367
2368- void XQuery::destroy() { theQuery = 0; }
2369- Iterator XQuery::iterator() { return Iterator(theQuery->iterator()); }
2370-
2371-%} // end Implementation
2372-
2373-%include "XQuery.h"
2374\ No newline at end of file
2375+ void destroy() { theQuery = 0; }
2376+ Iterator iterator() { return Iterator(theQuery->iterator()); }
2377+}; // class XQuery
2378+
2379+
2380+// remaining method definitions from Iterator
2381+bool
2382+Iterator::next(Item& aItem)
2383+{
2384+ if (theIterator)
2385+ {
2386+ return theIterator->next(aItem.theItem);
2387+ }
2388+ else
2389+ {
2390+ if (!theConsumed)
2391+ {
2392+ aItem = theItem;
2393+ return true;
2394+ }
2395+ else
2396+ {
2397+ return false;
2398+ }
2399+ }
2400+}
2401+
2402+
2403+
2404+%} // end Implementation
2405+
2406+
2407+
2408+// Interfaces
2409+
2410+
2411+
2412+class DynamicContext
2413+{
2414+public:
2415+ void
2416+ setVariable(
2417+ const std::string& aNamespace,
2418+ const std::string& aLocalname,
2419+ Iterator);
2420+
2421+ void
2422+ setContextItem(Item);
2423+};
2424+
2425+
2426+class Item
2427+{
2428+public:
2429+ static Item createEmptyItem();
2430+
2431+ std::string serialize() const;
2432+ std::string getStringValue() const;
2433+ Iterator getAtomizationValue () const;
2434+ Iterator getAttributes () const;
2435+ bool getBooleanValue () const;
2436+ Iterator getChildren () const;
2437+ Item getEBV () const;
2438+ int getIntValue () const;
2439+ std::string getLocalName () const;
2440+ std::string getNamespace () const;
2441+ bool getNodeName (Item &aNodeName) const;
2442+ std::string getPrefix () const;
2443+ Item getType () const;
2444+ unsigned int getUnsignedIntValue () const;
2445+
2446+ int getNodeKind() const;
2447+ bool isAtomic () const;
2448+ bool isNaN () const;
2449+ bool isNode () const;
2450+ bool isNull () const;
2451+ bool isPosOrNegInf () const;
2452+}; // class Item
2453+
2454+
2455+class Iterator
2456+{
2457+public:
2458+ void open();
2459+ bool next(Item&);
2460+ void close();
2461+ void destroy();
2462+}; // class Iterator
2463+
2464+
2465+class XQuery
2466+{
2467+public:
2468+ std::string execute();
2469+ std::string printPlanAsXML();
2470+ std::string printPlanAsDOT();
2471+ void compile (const std::string &aQuery);
2472+ void compile (const std::string &aQuery, StaticContext &aStaticContext);
2473+
2474+#ifdef SWIGPYTHON
2475+ void executeSAX(SAX2ContentHandlerProxy* contentHandlerProxy);
2476+#endif
2477+
2478+ void destroy();
2479+ Iterator iterator();
2480+ DynamicContext getDynamicContext();
2481+}; // class XQuery
2482
2483=== modified file 'swig/java/CMakeLists.txt'
2484--- swig/java/CMakeLists.txt 2012-03-30 19:03:09 +0000
2485+++ swig/java/CMakeLists.txt 2012-04-14 07:09:19 +0000
2486@@ -102,6 +102,7 @@
2487 ENDIF(NOT WIN32)
2488 ENDIF ( APPLE )
2489
2490+
2491 ELSE (JAVA_INCLUDE_PATH)
2492 MESSAGE ( STATUS "SWIG Java: not generating JAVA API because jni headers not found.")
2493 ENDIF (JAVA_INCLUDE_PATH)
2494
2495=== added file 'swig/various.i'
2496--- swig/various.i 1970-01-01 00:00:00 +0000
2497+++ swig/various.i 2012-04-14 07:09:19 +0000
2498@@ -0,0 +1,184 @@
2499+/* This is from http://www.opensource.apple.com/source/swig/swig-6/swig/Lib/java/various.i?txt */
2500+
2501+/* -----------------------------------------------------------------------------
2502+ * See the LICENSE file for information on copyright, usage and redistribution
2503+ * of SWIG, and the README file for authors - http://www.swig.org/release.html.
2504+ *
2505+ * various.i
2506+ *
2507+ * SWIG Typemap library for Java.
2508+ * Various useful typemaps.
2509+ * ----------------------------------------------------------------------------- */
2510+
2511+#ifdef SWIGJAVA
2512+
2513+/*
2514+ * char **STRING_ARRAY typemaps.
2515+ * These typemaps are for C String arrays which are NULL terminated.
2516+ * char *values[] = { "one", "two", "three", NULL }; // note NULL
2517+ * char ** is mapped to a Java String[].
2518+ *
2519+ * Example usage wrapping:
2520+ * %apply char **STRING_ARRAY { char **input };
2521+ * char ** foo(char **input);
2522+ *
2523+ * Java usage:
2524+ * String numbers[] = { "one", "two", "three" };
2525+ * String[] ret = modulename.foo( numbers };
2526+ */
2527+%typemap(jni) char **STRING_ARRAY "jobjectArray"
2528+%typemap(jtype) char **STRING_ARRAY "String[]"
2529+%typemap(jstype) char **STRING_ARRAY "String[]"
2530+%typemap(in) char **STRING_ARRAY (jint size) {
2531+ int i = 0;
2532+ size = JCALL1(GetArrayLength, jenv, $input);
2533+#ifdef __cplusplus
2534+ $1 = new char*[size+1];
2535+#else
2536+ $1 = (char **)calloc(size+1, sizeof(char *));
2537+#endif
2538+ for (i = 0; i<size; i++) {
2539+ jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
2540+ const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
2541+#ifdef __cplusplus
2542+ $1[i] = new char [strlen(c_string)+1];
2543+#else
2544+ $1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
2545+#endif
2546+ strcpy($1[i], c_string);
2547+ JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
2548+ JCALL1(DeleteLocalRef, jenv, j_string);
2549+ }
2550+ $1[i] = 0;
2551+}
2552+
2553+%typemap(freearg) char **STRING_ARRAY {
2554+ int i;
2555+ for (i=0; i<size$argnum-1; i++)
2556+#ifdef __cplusplus
2557+ delete[] $1[i];
2558+ delete[] $1;
2559+#else
2560+ free($1[i]);
2561+ free($1);
2562+#endif
2563+}
2564+
2565+%typemap(out) char **STRING_ARRAY {
2566+ int i;
2567+ int len=0;
2568+ jstring temp_string;
2569+ const jclass clazz = JCALL1(FindClass, jenv, "java/lang/String");
2570+
2571+ while ($1[len]) len++;
2572+ jresult = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
2573+ /* exception checking omitted */
2574+
2575+ for (i=0; i<len; i++) {
2576+ temp_string = JCALL1(NewStringUTF, jenv, *result++);
2577+ JCALL3(SetObjectArrayElement, jenv, jresult, i, temp_string);
2578+ JCALL1(DeleteLocalRef, jenv, temp_string);
2579+ }
2580+}
2581+
2582+%typemap(javain) char **STRING_ARRAY "$javainput"
2583+%typemap(javaout) char **STRING_ARRAY {
2584+ return $jnicall;
2585+ }
2586+
2587+/*
2588+ * char **STRING_OUT typemaps.
2589+ * These are typemaps for returning strings when using a C char ** parameter type.
2590+ * The returned string appears in the 1st element of the passed in Java String array.
2591+ *
2592+ * Example usage wrapping:
2593+ * void foo(char **string_out);
2594+ *
2595+ * Java usage:
2596+ * String stringOutArray[] = { "" };
2597+ * modulename.foo(stringOutArray);
2598+ * System.out.println( stringOutArray[0] );
2599+ */
2600+%typemap(jni) char **STRING_OUT "jobjectArray"
2601+%typemap(jtype) char **STRING_OUT "String[]"
2602+%typemap(jstype) char **STRING_OUT "String[]"
2603+%typemap(javain) char **STRING_OUT "$javainput"
2604+
2605+%typemap(in) char **STRING_OUT($*1_ltype temp) {
2606+ if (!$input) {
2607+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
2608+ return $null;
2609+ }
2610+ if (JCALL1(GetArrayLength, jenv, $input) == 0) {
2611+ SWIG_JavaThrowException(jenv, SWIG_JavaIndexOutOfBoundsException, "Array must contain at least 1 element");
2612+ return $null;
2613+ }
2614+ $1 = &temp;
2615+}
2616+
2617+%typemap(argout) char **STRING_OUT {
2618+ jstring jnewstring = NULL;
2619+ if($1) {
2620+ jnewstring = JCALL1(NewStringUTF, jenv, *$1);
2621+ }
2622+ JCALL3(SetObjectArrayElement, jenv, $input, 0, jnewstring);
2623+}
2624+
2625+/*
2626+ * char *BYTE typemaps.
2627+ * These are input typemaps for mapping a Java byte[] array to a C char array.
2628+ * Note that as a Java array is used and thus passeed by reference, the C routine
2629+ * can return data to Java via the parameter.
2630+ *
2631+ * Example usage wrapping:
2632+ * void foo(char *array);
2633+ *
2634+ * Java usage:
2635+ * byte b[] = new byte[20];
2636+ * modulename.foo(b);
2637+ */
2638+%typemap(jni) char *BYTE "jbyteArray"
2639+%typemap(jtype) char *BYTE "byte[]"
2640+%typemap(jstype) char *BYTE "byte[]"
2641+%typemap(in) char *BYTE {
2642+ $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
2643+}
2644+
2645+%typemap(argout) char *BYTE {
2646+ JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
2647+}
2648+
2649+%typemap(javain) char *BYTE "$javainput"
2650+
2651+/* Prevent default freearg typemap from being used */
2652+%typemap(freearg) char *BYTE ""
2653+
2654+#else
2655+
2656+#endif
2657+
2658+
2659+/* %include "typemaps.i"
2660+
2661+#if defined(SWIGJAVA)
2662+
2663+%typemap(in) (char * BYTE, int LENGTH)
2664+{
2665+ // Functions from jni.h
2666+ $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
2667+ $2 = (int) JCALL1(GetArrayLength, jenv, $input);
2668+}
2669+
2670+%typemap(jni) (char * BYTE, int LENGTH) "jbyteArray"
2671+%typemap(jtype) (char * BYTE, int LENGTH) "byte[]"
2672+%typemap(jstype) (char * BYTE, int LENGTH) "byte[]"
2673+%typemap(javain) (char * BYTE, int LENGTH) "$javainput"
2674+
2675+// Specify signature of method to handle
2676+%apply (char * BYTE, int LENGTH) { (char * byteArray, long len) };
2677+
2678+#else
2679+%apply (char * BYTE, int LENGTH) { (char * byteArray, long len) };
2680+#endif
2681+
2682+*/
2683
2684=== modified file 'swig/zorba_api.i'
2685--- swig/zorba_api.i 2012-03-30 19:03:09 +0000
2686+++ swig/zorba_api.i 2012-04-14 07:09:19 +0000
2687@@ -15,14 +15,11 @@
2688 */
2689
2690 %module zorba_api
2691+
2692+
2693 %include "std_string.i"
2694-%include "std_pair.i"
2695 %include "exception.i"
2696
2697-#ifndef SWIGRUBY
2698-%include "std_vector.i"
2699-#endif
2700-
2701 %exception {
2702 try {
2703 $action
2704@@ -39,13 +36,7 @@
2705 }
2706 }
2707
2708-#ifndef SWIGRUBY
2709-namespace std {
2710- %template(StringPairVector) vector< pair<string, string> >;
2711- %template(StringPair) pair<string, string>;
2712- %template(StringVector) vector< string >;
2713-}
2714-#endif
2715+
2716
2717 %{ // Implementations
2718
2719@@ -62,12 +53,13 @@
2720
2721 class CompilerHints;
2722 //class DiagnosticHandler;
2723+ class Item;
2724+ class Iterator;
2725+ class XQuery;
2726 class Store;
2727 class Zorba;
2728- class Iterator;
2729
2730 class DynamicException;
2731- class DocumentManager;
2732 class XQueryException;
2733 class SerializationException;
2734 class StaticException;
2735@@ -76,44 +68,22 @@
2736 class UserException;
2737 class ZorbaException;
2738
2739- #include "SerializationOptions.h"
2740- #include "TypeIdentifier.h"
2741- #include "Item.h"
2742- #include "Iterator.h"
2743- #include "DynamicContext.h"
2744 #include "StaticContext.h"
2745- #include "XQuery.h"
2746 #include "ItemFactory.h"
2747- #include "ItemSequence.h"
2748- #include "Collection.h"
2749- #include "CollectionManager.h"
2750- #include "DocumentManager.h"
2751- #include "XmlDataManager.h"
2752+
2753 %}
2754
2755-#ifndef SWIGRUBY
2756-namespace std {
2757- %template(ItemVector) vector<Item>;
2758-}
2759-#endif
2760-
2761-//%include "ZorbaStreamProxy.i"
2762-%include "SerializationOptions.i"
2763-%include "TypeIdentifier.i"
2764-%include "Item.i"
2765-%include "Iterator.i"
2766-%include "DynamicContext.i"
2767-%include "CompilerHints.i"
2768-%include "StaticContext.i"
2769+
2770+/* %include "various.i" */
2771+
2772 %include "XQuery.i"
2773 %include "Store.i"
2774+%include "XmlDataManager.i"
2775 %include "Exceptions.i"
2776 //%include "DiagnosticHandler.i"
2777+%include "CompilerHints.i"
2778+%include "StaticContext.i"
2779 %include "Zorba.i"
2780 %include "ItemFactory.i"
2781-%include "ItemSequence.i"
2782-%include "Collection.i"
2783-%include "CollectionManager.i"
2784-%include "DocumentManager.i"
2785-%include "XmlDataManager.i"
2786+
2787
2788
2789=== modified file 'test/rbkt/modules/CMakeLists.txt'
2790--- test/rbkt/modules/CMakeLists.txt 2012-03-30 19:03:09 +0000
2791+++ test/rbkt/modules/CMakeLists.txt 2012-04-14 07:09:19 +0000
2792@@ -58,3 +58,5 @@
2793 # This is as good a place as any to test this feature
2794 DECLARE_ZORBA_URI_FILE(FILE "random-file.txt"
2795 URI "http://www.zorba-xquery.com/random-file" TEST_ONLY)
2796+
2797+ADD_SUBDIRECTORY(java)
2798
2799=== added directory 'test/rbkt/modules/java'
2800=== added file 'test/rbkt/modules/java/CMakeLists.txt'
2801--- test/rbkt/modules/java/CMakeLists.txt 1970-01-01 00:00:00 +0000
2802+++ test/rbkt/modules/java/CMakeLists.txt 2012-04-14 07:09:19 +0000
2803@@ -0,0 +1,40 @@
2804+# Copyright 2006-2008 The FLWOR Foundation.
2805+#
2806+# Licensed under the Apache License, Version 2.0 (the "License")
2807+# you may not use this file except in compliance with the License.
2808+# You may obtain a copy of the License at
2809+#
2810+# http://www.apache.org/licenses/LICENSE-2.0
2811+#
2812+# Unless required by applicable law or agreed to in writing, software
2813+# distributed under the License is distributed on an "AS IS" BASIS,
2814+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2815+# See the License for the specific language governing permissions and
2816+# limitations under the License.
2817+
2818+# For now we only test building a .jar that we want Zorba to make available
2819+# on the JVM claspath. This test scenario should be extended to include a
2820+# Zorba module using the .jar, etc.
2821+# We make use of the much-improved Java support added in CMake 2.8.6.
2822+COMPARE_VERSION_STRINGS (${CMAKE_VERSION} "2.8.6" RESULT)
2823+IF (${RESULT} GREATER -1)
2824+ FIND_PACKAGE (Java COMPONENTS Development)
2825+ IF (Java_Development_FOUND)
2826+ INCLUDE (UseJava)
2827+
2828+ # Declare two "different" jars, for testing
2829+ ADD_JAR (JavaTest Test.java)
2830+ ADD_JAR (JavaTest2 Test.java)
2831+
2832+ # Tell Zorba about the jars
2833+ GET_PROPERTY (JavaTest_JAR_FILE TARGET JavaTest PROPERTY JAR_FILE)
2834+ GET_PROPERTY (JavaTest2_JAR_FILE TARGET JavaTest2 PROPERTY JAR_FILE)
2835+ DECLARE_ZORBA_JAR(FILE ${JavaTest_JAR_FILE} TARGET JavaTest TEST_ONLY)
2836+ DECLARE_ZORBA_JAR(FILE ${JavaTest2_JAR_FILE} TARGET JavaTest2 TEST_ONLY)
2837+
2838+ # Pretend to tell Zorba about some system jars
2839+ DECLARE_ZORBA_JAR(EXTERNAL FILE
2840+ "${PROJECT_SOURCE_DIR}/MyJar.jar" "${PROJECT_SOURCE_DIR}/MyJar2.jar")
2841+
2842+ ENDIF (Java_Development_FOUND)
2843+ENDIF (${RESULT} GREATER -1)
2844
2845=== added file 'test/rbkt/modules/java/Test.java'
2846--- test/rbkt/modules/java/Test.java 1970-01-01 00:00:00 +0000
2847+++ test/rbkt/modules/java/Test.java 2012-04-14 07:09:19 +0000
2848@@ -0,0 +1,7 @@
2849+package org.zorbaxquery;
2850+
2851+public class Test {
2852+ public static void main(String[] args) {
2853+ System.out.println("Hello, world");
2854+ }
2855+}

Subscribers

People subscribed via source and target branches