← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug938320b into lp:zorba

 

Rodolfo Ochoa has proposed merging lp:~zorba-coders/zorba/bug938320b into lp:zorba.

Requested reviews:
  Zorba Coders (zorba-coders)

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

Testing in RQ
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug938320b/+merge/123356
Your team Zorba Coders is requested to review the proposed merge of lp:~zorba-coders/zorba/bug938320b into lp:zorba.
=== modified file 'include/zorba/dynamic_context.h'
--- include/zorba/dynamic_context.h	2012-08-30 13:45:43 +0000
+++ include/zorba/dynamic_context.h	2012-09-07 20:02:32 +0000
@@ -280,6 +280,7 @@
   /** \brief Destructor
    */
   virtual ~DynamicContext( ) {}
+ 
 };
 
 } /* namespace zorba */

=== modified file 'swig/CMakeLists.txt'
--- swig/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -13,6 +13,9 @@
 # limitations under the License.
 
 IF (SWIG_FOUND)
+
+  SET (ZORBA_STREAM_BUFFER_SIZE 10240) # 10k default buffer size
+  
   IF (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
     SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
     SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")

=== added file 'swig/Config.h'
--- swig/Config.h	1970-01-01 00:00:00 +0000
+++ swig/Config.h	2012-09-07 20:02:32 +0000
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2006-2008 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef API_CONFIG_H
+#define API_CONFIG_H
+
+#define ZORBA_STREAM_BUFFER_SIZE @ZORBA_STREAM_BUFFER_SIZE@
+
+
+#endif
\ No newline at end of file

=== modified file 'swig/DiagnosticHandler.h'
--- swig/DiagnosticHandler.h	2012-08-30 13:45:43 +0000
+++ swig/DiagnosticHandler.h	2012-09-07 20:02:32 +0000
@@ -27,6 +27,7 @@
   void error (const zorba::ZorbaException &ze);
   void warning (const zorba::XQueryException &xw);
  public:
+  DiagnosticHandler() {};
   virtual ~DiagnosticHandler();
 
   /**

=== modified file 'swig/Item.h'
--- swig/Item.h	2012-08-30 13:45:43 +0000
+++ swig/Item.h	2012-09-07 20:02:32 +0000
@@ -199,7 +199,7 @@
    * Note that this function is only available for node Items.
    *
    * @return bool if the name of the node was retrieved successfully
-   * @return aNodeName the name of the node
+   * @param aNodeName the name of the node
    * @throw ZorbaException if an error occured (e.g. the Item is not of type node).
    */
   bool getNodeName (Item &aNodeName) const;
@@ -298,6 +298,26 @@
    * Also note that this function is available for all types of Items.
    */
   void close();
+  
+  /** \brief Serializes the object
+   *
+   * Put the serialized object into the specified stream.
+   *
+   * @param aStream The stream to write the value of the Item.
+   * @throw ZorbaException if an error occured.
+   */
+  void serializeToStream(ZorbaIOStream & aStream) const;
+
+  /** \brief Serializes the object
+   *
+   * Put the serialized object into the specified stream.
+   *
+   * @param aStream The stream to write the value of the Item.
+   * @param serOptions The serialization options for this Item
+   * @throw ZorbaException if an error occured.
+   */
+  void serializeToStream(ZorbaIOStream & aStream, SerializationOptions serOptions) const;
+ 
 }; // class Item
 
 #endif

=== modified file 'swig/Item.i'
--- swig/Item.i	2012-08-30 13:45:43 +0000
+++ swig/Item.i	2012-09-07 20:02:32 +0000
@@ -122,6 +122,31 @@
   void Item::close()
   { theItem.close(); }
 
+  void Item::serializeToStream(ZorbaIOStream & aStream) const 
+  {
+    ZorbaStreamBuffer buffer(aStream);
+    std::ostream lStream(&buffer);
+
+    Zorba_SerializerOptions_t lOptions;
+    lOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+    zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(lOptions);
+    zorba::SingletonItemSequence lSequence(theItem);
+    lSerializer->serialize(&lSequence, lStream);
+    return;
+  }
+  void Item::serializeToStream(ZorbaIOStream & aStream, SerializationOptions serOptions) const 
+  {
+    ZorbaStreamBuffer buffer(aStream);
+    std::ostream lStream(&buffer);
+
+    Zorba_SerializerOptions_t lOptions;
+    serOptions.lOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+    zorba::Serializer_t lSerializer = zorba::Serializer::createSerializer(serOptions.lOptions);
+    zorba::SingletonItemSequence lSequence(theItem);
+    lSerializer->serialize(&lSequence, lStream);
+    return;
+  }
+
 %}  // end   Implementation
 
 

=== modified file 'swig/SerializationOptions.h'
--- swig/SerializationOptions.h	2012-08-30 13:45:43 +0000
+++ swig/SerializationOptions.h	2012-09-07 20:02:32 +0000
@@ -34,6 +34,7 @@
 class SerializationOptions
 {
 friend class Item;
+friend class XQuery;
 
 public:
   typedef enum 

=== modified file 'swig/XQuery.h'
--- swig/XQuery.h	2012-08-30 13:45:43 +0000
+++ swig/XQuery.h	2012-09-07 20:02:32 +0000
@@ -36,8 +36,8 @@
   XQuery(zorba::XQuery_t aQuery) : theQuery(aQuery), closed(false) {}
 
   /**
-   * \brief Execute the (updating) query. The query can be executed with this
-   * function only if it is an updating query.
+   * \brief Execute the query. The query can be executed with this function.
+   *  The query only has a result if it's a non-updating query.
    *
    * @throw ZorbaException if an error occurs (e.g. the query is closed or has
    *        not been compiled or is not updating)
@@ -156,6 +156,32 @@
    * @throw ZorbaException if an error occured.
    */
   void getExternalVariables(Iterator& vars) const;
+  
+  /** \brief Execute the query and write the result to the given output stream.
+   *  The query only has a result if it's a non-updating query.
+   *
+   * @param stream The output stream on which the result is written.
+   */
+  void execute( ZorbaIOStream & stream );
+
+  /** \brief Execute the query and write the result to the given output stream.
+   *  The query only has a result if it's a non-updating query.
+   *
+   * @param stream The output stream on which the result is written.
+   * @param serOptions The serialization options for this Query result
+   */
+  void execute( ZorbaIOStream & stream, SerializationOptions & serOptions );
+  
+  /**
+   * \brief Execute the query. The query can be executed with this function.
+   *  The query only has a result if it's a non-updating query.
+   *
+   * @param serOptions The serialization options for this Query result
+   * @throw ZorbaException if an error occurs (e.g. the query is closed or has
+   *        not been compiled or is not updating)
+   */
+  std::string execute( SerializationOptions & serOptions );
+
 }; // class XQuery
 
 #endif
\ No newline at end of file

=== modified file 'swig/XQuery.i'
--- swig/XQuery.i	2012-08-30 13:45:43 +0000
+++ swig/XQuery.i	2012-09-07 20:02:32 +0000
@@ -15,16 +15,15 @@
  */
 
 %{  // start Implementation
-
+  
   std::string XQuery::execute()
   {
     Zorba_SerializerOptions_t lSerOptions;
     lSerOptions.indent = ZORBA_INDENT_YES;
-    lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+    lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_NO;
     std::stringstream lStream;
-    lStream << theQuery;
-    std::string str = lStream.str();
-    return str;
+    theQuery->execute(lStream, &lSerOptions);
+    return lStream.str();
   }
   
   void XQuery::compile (const std::string &aQuery)
@@ -78,6 +77,32 @@
   void XQuery::destroy() { theQuery = 0; }
   Iterator XQuery::iterator() { return Iterator(theQuery->iterator()); }
 
+  void XQuery::execute( ZorbaIOStream & stream )
+  {
+    Zorba_SerializerOptions_t lSerOptions;
+    lSerOptions.indent = ZORBA_INDENT_NO;
+    lSerOptions.omit_xml_declaration = ZORBA_OMIT_XML_DECLARATION_YES;
+    ZorbaStreamBuffer buffer(stream);
+    std::ostream lStream(&buffer);
+    theQuery->execute(lStream, &lSerOptions);
+    return;
+  }
+
+  void XQuery::execute( ZorbaIOStream & stream, SerializationOptions & serOptions )
+  {
+    ZorbaStreamBuffer buffer(stream);
+    std::ostream lStream(&buffer);
+    theQuery->execute(lStream, &serOptions.lOptions);
+  }
+
+  std::string XQuery::execute( SerializationOptions & serOptions )
+  {
+    std::stringstream lStream;
+    theQuery->execute(lStream, &serOptions.lOptions);
+    return lStream.str();
+  }
+  
+  
 %}  // end   Implementation
 
 %include "XQuery.h"

=== modified file 'swig/XmlDataManager.h'
--- swig/XmlDataManager.h	2012-08-30 13:45:43 +0000
+++ swig/XmlDataManager.h	2012-09-07 20:02:32 +0000
@@ -66,8 +66,7 @@
      * dynamic collections identified by a URI, i.e. those that are
      * not declared in the prolog of a module or identified by a QName.
      *
-     * @return The collection manager responsible for managing
-     *   collections.
+     * @return The collection manager responsible for managing collections.
      *
      */
   CollectionManager getW3CCollectionManager();
@@ -84,5 +83,11 @@
      */
   Item parseXMLtoItem(const std::string& aDoc);
 
+  /** \brief Parse an XML stream and return an Item.
+     *
+     * @param aStream the input string whose content should be parsed
+     */
+  Item parseXMLtoItem(ZorbaIOStream & aStream);
+
 };
 #endif
\ No newline at end of file

=== modified file 'swig/XmlDataManager.i'
--- swig/XmlDataManager.i	2012-08-30 13:45:43 +0000
+++ swig/XmlDataManager.i	2012-09-07 20:02:32 +0000
@@ -45,6 +45,13 @@
     return Item(lItem);
   }
 
+  Item XmlDataManager::parseXMLtoItem(ZorbaIOStream & aStream)
+  {
+    ZorbaStreamBuffer streamBuffer(aStream);
+    std::istream stream(&streamBuffer);
+    zorba::Item lItem = theManager->parseXML(stream);
+    return Item(lItem);
+  }
 
 %}  // end   Implementation
 

=== modified file 'swig/Zorba.h'
--- swig/Zorba.h	2012-08-30 13:45:43 +0000
+++ swig/Zorba.h	2012-09-07 20:02:32 +0000
@@ -202,6 +202,28 @@
    */
   bool isXQueryXSupported();
 
+  /** \brief Creates and compiles an XQuery object.
+   *
+   * This methods creates an XQuery object and compiles the query string
+   * passed to this method.
+   *
+   * @param stream the query stream, this object is an extension to stream data accross the API.
+   * @return XQuery the newly created and compiled XQuery object.
+   */
+  XQuery compileQuery(ZorbaIOStream & stream);
+
+  /** \brief Creates and compiles an XQuery object using a StaticContext.
+   *
+   * This methods creates an XQuery object and compiles the query string
+   * passed to this method. Compilation is done using the information
+   * contained in the StaticContext that is passed as parameter.
+   *
+   * @param stream the query stream, this object is an extension to stream data accross the API.
+   * @param aStaticContext the StaticContext that contains information used for compiling the query.
+   * @return XQuery the newly created and compiled XQuery object.
+   */
+  XQuery compileQuery(ZorbaIOStream & stream, StaticContext &aStaticContext );
+
 }; // class Zorba
 
 #endif

=== modified file 'swig/Zorba.i'
--- swig/Zorba.i	2012-08-30 13:45:43 +0000
+++ swig/Zorba.i	2012-09-07 20:02:32 +0000
@@ -53,21 +53,6 @@
     );
   }
 
-  // XQuery Zorba::compileQuery(const ZIStreamHelper& aZorbaStream)
-  // {
-    // zorbabuffer *buffer = new zorbabuffer(&const_cast<ZIStreamHelper &> (aZorbaStream));
-    // std::istream stream = std::istream(buffer);
-    // zistream stream = zistream(buffer);
-    // return XQuery(theZorba->compileQuery(stream));
-  // }
-
-  // XQuery Zorba::compileQuery(const ZIStreamHelper& aZorbaStream, StaticContext &aStaticContext )
-  // { 
-    // zorbabuffer *buffer = new zorbabuffer(&const_cast<ZIStreamHelper &> (aZorbaStream));
-    // std::istream stream = std::istream(buffer);
-    // return XQuery(theZorba->compileQuery(stream, aStaticContext.theStaticContext));
-  // }
-  
   XQuery Zorba::compileQuery(
     const std::string& aStr,
     DiagnosticHandler* aDiagnosticHandler
@@ -132,6 +117,20 @@
     #endif //ZORBA_XQUERYX
   }
 
+  XQuery Zorba::compileQuery(ZorbaIOStream & aStream)
+  {
+    ZorbaStreamBuffer streamBuffer(aStream);
+    std::istream stream(&streamBuffer);
+    return XQuery(theZorba->compileQuery(stream));
+  }
+
+  XQuery Zorba::compileQuery(ZorbaIOStream & aStream, StaticContext &aStaticContext )
+  { 
+    ZorbaStreamBuffer streamBuffer(aStream);
+    std::istream stream(&streamBuffer);
+    return XQuery(theZorba->compileQuery(stream, aStaticContext.theStaticContext));
+  }
+
 %}  // end Implementation
 
 %include "Zorba.h"

=== added file 'swig/ZorbaIOStream.h'
--- swig/ZorbaIOStream.h	1970-01-01 00:00:00 +0000
+++ swig/ZorbaIOStream.h	2012-09-07 20:02:32 +0000
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef API_ZORBA_IO_STREAM_H
+#define API_ZORBA_IO_STREAM_H
+
+#include <streambuf>
+#include <cstdio>
+#include <cstdlib>
+#include <vector>
+
+class ZorbaIOStream
+{
+public:
+  ZorbaIOStream() {};
+  virtual ~ZorbaIOStream() {};
+
+  //STREAM TO ZORBA
+  virtual void fillStreamCallback();
+  void setStream(const char *BYTE, size_t aLen);
+  void setStream(const char *aStream, size_t aLen, int aBufferLength);
+  char * getStream();
+  int getLen();
+  
+  //STREAM FROM ZORBA
+  virtual void write(const char *BYTE, size_t aLen);
+  
+private:
+  //FOR STREAM TO ZORBA
+  char buffer[ZORBA_STREAM_BUFFER_SIZE];
+  int len;
+
+  // Copy contructor and assignment not allowed
+  ZorbaIOStream (const ZorbaIOStream &);
+  ZorbaIOStream &operator= (const ZorbaIOStream &);
+
+};
+
+#endif

=== added file 'swig/ZorbaIOStream.i'
--- swig/ZorbaIOStream.i	1970-01-01 00:00:00 +0000
+++ swig/ZorbaIOStream.i	2012-09-07 20:02:32 +0000
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%feature("director") ZorbaIOStream;
+
+%{  // start Implementation
+
+#include "ZorbaIOStream.h"
+#include <cassert>
+#include <iostream>
+#include <ios>
+
+void ZorbaIOStream::fillStreamCallback()
+{
+  // Local fill buffer EXAMPLE
+  int len = ZORBA_STREAM_BUFFER_SIZE;
+  char *buffer = (char*) malloc(sizeof(char)*(len));
+  char* p=buffer;
+  for (int i=0; i<(len); i++, *p++ = 'Z')
+    ;
+  setStream(buffer, len);
+  return;
+}
+
+void ZorbaIOStream::setStream(const char *aStream, size_t aLen, int aBufferLength)
+{
+  if (aBufferLength<0) aBufferLength=0;
+  if (aBufferLength > 0)
+    memcpy(buffer, aStream, aBufferLength*sizeof(char));
+  len = aBufferLength;
+  return;
+}
+
+void ZorbaIOStream::setStream(const char *BYTE, size_t aLen)
+{
+  if (aLen<0) aLen=0;
+  if (aLen > 0)
+    memcpy(buffer, BYTE, aLen*sizeof(char));
+  len = aLen;
+  return;
+}
+
+char * ZorbaIOStream::getStream()
+{
+  return buffer;
+}
+
+int ZorbaIOStream::getLen()
+{
+  return len;
+}
+
+void ZorbaIOStream::write(const char *BYTE, size_t aLen)
+{
+  return;
+}
+
+%}  // end   Implementation
+
+
+%include "ZorbaIOStream.h"
\ No newline at end of file

=== added file 'swig/ZorbaStreamBuffer.h'
--- swig/ZorbaStreamBuffer.h	1970-01-01 00:00:00 +0000
+++ swig/ZorbaStreamBuffer.h	2012-09-07 20:02:32 +0000
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef API_ZORBA_STREAM_BUFFER_H
+#define API_ZORBA_STREAM_BUFFER_H
+
+#include <streambuf>
+#include <cstdio>
+#include <cstdlib>
+#include <vector>
+#include "ZorbaStreamBuffer.h"
+
+
+class ZorbaStreamBuffer :
+  public std::streambuf
+{
+public:
+  ZorbaStreamBuffer(ZorbaIOStream &aStreamWrapper): bBegin(0), bEnd(0), bCurrent(0), buffer(0), streamWrapper(&aStreamWrapper) {};
+  virtual ~ZorbaStreamBuffer() {};
+
+  // HELPER
+  // Function to return EOF character from other languages
+  static int getEOF();
+
+  // INPUT
+  // Get character in the case of underflow
+  int underflow();
+  // Get character in the case of underflow and advance get pointer
+  int uflow();
+  // Put character back in the case of backup underflow
+  int pbackfail(int ch);
+  // Get number of characters available in the sequence
+  std::streamsize showmanyc();
+
+  // OUTPUT
+  // Write sequence of characters <Inherited>
+  virtual std::streamsize xsputn ( const char * BYTE, std::streamsize len );
+  // Write character in the case of overflow
+  virtual int overflow ( int c = EOF );
+  
+  
+  
+
+private:
+  void checkBuffer();
+  // Copy contructor and assignment not allowed
+  ZorbaStreamBuffer(const ZorbaStreamBuffer &);
+  ZorbaStreamBuffer &operator= (const ZorbaStreamBuffer &);
+
+  //BUFFER
+  char * buffer;
+  char * bBegin;
+  char * bEnd;
+  char * bCurrent;
+  ZorbaIOStream *streamWrapper;
+
+  char * cBuffer;
+};
+
+#endif

=== added file 'swig/ZorbaStreamBuffer.i'
--- swig/ZorbaStreamBuffer.i	1970-01-01 00:00:00 +0000
+++ swig/ZorbaStreamBuffer.i	2012-09-07 20:02:32 +0000
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+%feature("director") ZorbaStreamBuffer;
+
+%{  // start Implementation
+
+#include "ZorbaStreamBuffer.h"
+#include <cassert>
+#include <iostream>
+
+void ZorbaStreamBuffer::checkBuffer()
+{
+  if (buffer==0)
+  {
+    streamWrapper->fillStreamCallback();
+    if (streamWrapper->getLen() > 0) {
+      bBegin = bCurrent = buffer = streamWrapper->getStream();
+      bEnd = bBegin + streamWrapper->getLen();
+    }
+  } else if (bCurrent == bEnd)
+  {
+    if (streamWrapper->getLen()==ZORBA_STREAM_BUFFER_SIZE)
+    {
+      streamWrapper->fillStreamCallback();
+      if (streamWrapper->getLen() > 0) {
+        bBegin = bCurrent = buffer = streamWrapper->getStream();
+        bEnd = bBegin + streamWrapper->getLen();
+      }
+    }
+  }
+  
+}
+int ZorbaStreamBuffer::getEOF()
+{
+  return traits_type::eof();
+}
+
+int ZorbaStreamBuffer::underflow()
+{
+  checkBuffer();
+  if ((bCurrent == bEnd) || (buffer==0))
+    return traits_type::eof();
+  return traits_type::to_int_type(*bCurrent);
+}
+
+int ZorbaStreamBuffer::uflow()
+{
+  checkBuffer();
+  if ((bCurrent == bEnd) || (buffer==0))
+    return traits_type::eof();
+  return traits_type::to_int_type(*bCurrent++);
+}
+
+int ZorbaStreamBuffer::pbackfail(int ch)
+{
+  checkBuffer();
+  if (bCurrent == bBegin || (ch != traits_type::eof() && ch != bCurrent[-1]) || (buffer==0))
+    return traits_type::eof();
+
+  return traits_type::to_int_type(*--bCurrent);
+}
+
+std::streamsize ZorbaStreamBuffer::showmanyc()
+{
+  checkBuffer();
+  return bEnd - bCurrent;
+}
+
+std::streamsize ZorbaStreamBuffer::xsputn ( const char * BYTE, std::streamsize len ) {
+  // Wrapping to virtual function
+  streamWrapper->write(BYTE, len);
+  return len;
+}
+
+int ZorbaStreamBuffer::overflow ( int c )
+{
+  streamWrapper->write((const char*)&c, 1);
+  return c;
+}
+
+
+%}  // end   Implementation
+
+%include "ZorbaStreamBuffer.h"
\ No newline at end of file

=== modified file 'swig/java/CMakeLists.txt'
--- swig/java/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/java/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -51,15 +51,21 @@
 
   FILE(GLOB ZORBA_API_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.h")
   FOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
-    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}" COPYONLY)
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}")
   ENDFOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
+
+  #STREAM WRAPPER
+  FILE(GLOB ZORBA_JAVA_EXTRAS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/" "${CMAKE_CURRENT_SOURCE_DIR}/*.java")
+  FOREACH(ZORBA_JAVA_EXTRA ${ZORBA_JAVA_EXTRAS})
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/${ZORBA_JAVA_EXTRA}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_JAVA_EXTRA}")
+  ENDFOREACH(ZORBA_JAVA_EXTRA ${ZORBA_JAVA_EXTRAS})
   
   ADD_CUSTOM_COMMAND(TARGET lib_zorba_java_api
                  POST_BUILD
                  COMMAND cmake -E echo "Compiling Java files..."
                  COMMAND ${Java_JAVAC_EXECUTABLE} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
                  COMMAND cmake -E echo "Creating jar file..."
-                 COMMAND ${Java_JAR_EXECUTABLE} cvf zorba_api.jar org
+                 COMMAND ${Java_JAR_EXECUTABLE} cf zorba_api.jar org
   )
 
   # ---  Install

=== added file 'swig/java/ZorbaInputWrapper.java'
--- swig/java/ZorbaInputWrapper.java	1970-01-01 00:00:00 +0000
+++ swig/java/ZorbaInputWrapper.java	2012-09-07 20:02:32 +0000
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class ZorbaInputWrapper extends org.zorbaxquery.api.ZorbaIOStream {
+
+  private static final int BUFFER_SIZE = @ZORBA_STREAM_BUFFER_SIZE@;
+  private InputStream input;
+  private byte[] b = new byte[BUFFER_SIZE];;
+  
+  public ZorbaInputWrapper(InputStream aInput) {
+      input= aInput;
+  }
+  
+  @Override
+  public void fillStreamCallback() {
+      int total = 0;
+      try {
+        total = input.read(b, 0, BUFFER_SIZE);
+        setStream(b, total);
+      } catch (IOException ex) {
+        System.err.println("Unexpected exception trying to get bytes from ZorbaInputWrapper: " + ex.getLocalizedMessage());
+        ex.printStackTrace();
+      }
+  }
+}

=== added file 'swig/java/ZorbaOutputWrapper.java'
--- swig/java/ZorbaOutputWrapper.java	1970-01-01 00:00:00 +0000
+++ swig/java/ZorbaOutputWrapper.java	2012-09-07 20:02:32 +0000
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class ZorbaOutputWrapper extends ZorbaIOStream {
+  private OutputStream output;
+  
+  public ZorbaOutputWrapper(OutputStream aOutput) {
+      output = aOutput;
+  }
+  
+  @Override
+  public void write(byte[] stream, long aLen){
+        try {
+            output.write(stream);
+        } catch (IOException ex) {
+            System.err.println("Error writing on output stream" + ex.getLocalizedMessage());
+        }
+      
+  }
+  
+}

=== added file 'swig/java/ZorbaReaderWrapper.java'
--- swig/java/ZorbaReaderWrapper.java	1970-01-01 00:00:00 +0000
+++ swig/java/ZorbaReaderWrapper.java	2012-09-07 20:02:32 +0000
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.zorbaxquery.api;
+
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+
+public class ZorbaReaderWrapper extends org.zorbaxquery.api.ZorbaIOStream {
+
+  private static final int BUFFER_SIZE = @ZORBA_STREAM_BUFFER_SIZE@;
+  private static CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
+  private Reader reader;
+  private char[] charsReaded = new char[BUFFER_SIZE];
+  private byte[] bytesEncoded = new byte[BUFFER_SIZE];
+  CharBuffer charBuffer;
+  ByteBuffer byteBuffer;
+  
+  public ZorbaReaderWrapper(Reader aReader) {
+      charBuffer = CharBuffer.allocate(BUFFER_SIZE);
+      byteBuffer = ByteBuffer.allocate(BUFFER_SIZE*2);
+      reader= aReader;
+  }
+  
+  private int encode(char[] initialBuffer, int initialIndex, int initialLength, 
+                     byte[] result,        int resultIndex,  int resultLength) {
+      charBuffer = CharBuffer.wrap(initialBuffer, initialIndex, initialLength);
+      byteBuffer.clear();
+      encoder.encode(charBuffer, byteBuffer, false);
+      byteBuffer.flip();
+      resultLength = byteBuffer.limit()-byteBuffer.position();
+      byteBuffer.get(result, resultIndex, resultLength);
+      return resultLength;
+  }
+
+  @Override
+  public void fillStreamCallback() {
+      int total;
+      try {
+        total = reader.read(charsReaded, 0, BUFFER_SIZE);
+        total = encode(charsReaded, 0, total, bytesEncoded, 0, total);
+        setStream(bytesEncoded, total);
+      } catch (Exception ex) {
+        System.err.println("Unexpected exception trying to get bytes from ZorbaReaderWrapper: " + ex.getLocalizedMessage());
+        ex.printStackTrace();
+      }
+  }
+}

=== added file 'swig/java/ZorbaWriterWrapper.java'
--- swig/java/ZorbaWriterWrapper.java	1970-01-01 00:00:00 +0000
+++ swig/java/ZorbaWriterWrapper.java	2012-09-07 20:02:32 +0000
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.zorbaxquery.api;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+
+public class ZorbaWriterWrapper extends org.zorbaxquery.api.ZorbaIOStream {
+
+  private static final int BUFFER_SIZE = @ZORBA_STREAM_BUFFER_SIZE@;
+  private Writer writer;
+  CharBuffer charBuffer;
+  ByteBuffer byteBuffer;
+  CharsetDecoder decoder;
+  
+  public ZorbaWriterWrapper(Writer aWriter) {
+      writer = aWriter;
+      charBuffer = CharBuffer.allocate(BUFFER_SIZE);
+      byteBuffer = ByteBuffer.allocate(BUFFER_SIZE*2);
+      decoder = Charset.forName("UTF-8").newDecoder();
+  }
+
+  @Override
+  public void write(byte[] stream, long aLen){
+        try {
+            int offset = 0;
+            int bufferLength = 0;
+            while (stream.length>offset) {
+                byteBuffer.clear();
+                bufferLength = BUFFER_SIZE;
+                if ((offset+BUFFER_SIZE)>stream.length) {
+                    bufferLength = stream.length-offset;
+                }
+                offset += BUFFER_SIZE;
+                byteBuffer.put(stream, 0, bufferLength);
+                byteBuffer.flip();
+                charBuffer.clear();
+                decoder.decode(byteBuffer, charBuffer, false);
+                charBuffer.flip();
+                writer.append(charBuffer);
+            }
+        } catch (IOException ex) {
+            System.err.println("Error writing on output stream" + ex.getLocalizedMessage());
+        }
+      
+  }
+  
+}

=== modified file 'swig/java/zorba_api.i'
--- swig/java/zorba_api.i	2012-08-30 13:45:43 +0000
+++ swig/java/zorba_api.i	2012-09-07 20:02:32 +0000
@@ -16,10 +16,39 @@
 // Generate Java 1.5 proper enums
 //include "enums.swg"
 %include "enumtypeunsafe.swg"
+%include "std_string.i"
 
 // don't do a JNI call for constants and enums.
 %javaconst(1);
 
-
+%typemap(jni)     char *BYTE "jbyteArray"
+%typemap(jtype)   char *BYTE "byte[]"
+%typemap(jstype)  char *BYTE "byte[]"
+%typemap(javain)  char *BYTE "$javainput"
+%typemap(freearg) char *BYTE ""
+%typemap(in)      char *BYTE {
+    $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
+}
+%typemap(argout)  char *BYTE {
+    JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
+}
+
+%typemap(directorin, descriptor="[B") char *BYTE {
+    jbyteArray jb = (jenv)->NewByteArray(strlen($1));
+    (jenv)->SetByteArrayRegion(jb, 0, strlen($1), (jbyte*)$1);
+    $input = jb;
+}
+%typemap(directorout) char *BYTE {
+    $1 = 0;
+    if($input){
+        $result = (char *) jenv->GetByteArrayElements($input, 0); 
+        if(!$1) 
+            return $null;
+        jenv->ReleaseByteArrayElements($input, $result, 0);
+    }
+}
+
+%typemap(javadirectorin) char *BYTE "$jniinput"
+%typemap(javadirectorout) char *BYTE "$javacall"
 
 %include ../zorba_api.i

=== modified file 'swig/php/CMakeLists.txt'
--- swig/php/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/php/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -46,7 +46,7 @@
 
   FILE(GLOB ZORBA_API_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.h")
   FOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
-    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}" COPYONLY)
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}")
   ENDFOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
 
   # The following fix was added because of the changes in CMake 2.8, which have the

=== modified file 'swig/php/tests/test11.php'
--- swig/php/tests/test11.php	2012-03-27 00:56:11 +0000
+++ swig/php/tests/test11.php	2012-09-07 20:02:32 +0000
@@ -15,38 +15,34 @@
  * limitations under the License.
  */
 
-//require '@phpPath@/Zorba/zorba_api_wrapper.php';
-require 'C:/dev/zapi/build/swig/php/Zorba/zorba_api_wrapper.php';
-
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler): 
-  def error(self, *args):
-    print "Error args: ", args
-
-def test(zorba):
-  #Read and write result
-  print 'Executing: compilerHints.xq'
-  f = open('compilerHints.xq', 'r')
-  lines = f.read()
-  f.close()
+require '@phpPath@/Zorba/zorba_api_wrapper.php';
+
+class MyDiagnosticHandler(DiagnosticHandler handler) {
+  funtion error(self, *args) {
+    print "Error args: ", args;
+  }
+}
+
+function test(Zorba $aZorba)
+{
   diagnosticHandler = MyDiagnosticHandler()
-  compilerHints = zorba_api.CompilerHints()
-  compilerHints.setOptimizationLevel(0)
-  xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-  
-  result = xquery.execute()
-  print result
+  try {
+    xquery = zorba.compileQuery("1 div 0", diagnosticHandler);
+    print xquery.execute()
+  } catch (Exception e) {
+    print "Caught error: ";
+  }
   return
-
-
-store = zorba_api.InMemoryStore_getInstance()
-zorba = zorba_api.Zorba_getInstance(store)
-
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
-print "Success"
-
-
-zorba.shutdown()
-zorba_api.InMemoryStore_shutdown(store)
+}
+
+$store = InMemoryStore::getInstance();
+$zorba = Zorba::getInstance($store);
+
+print "Running: Compile query string using Diagnostic Handler"
+test($zorba);
+print "Success";
+
+$zorba->shutdown();
+InMemoryStore::shutdown($store);
 
 ?>
\ No newline at end of file

=== modified file 'swig/php/zorba_api.i'
--- swig/php/zorba_api.i	2012-08-30 13:45:43 +0000
+++ swig/php/zorba_api.i	2012-09-07 20:02:32 +0000
@@ -31,6 +31,7 @@
 
 %}
 
+%include "std_string.i"
 
 %{
 #include "zend_exceptions.h"

=== modified file 'swig/python/CMakeLists.txt'
--- swig/python/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/python/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -36,7 +36,7 @@
    
   FILE(GLOB ZORBA_API_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.h")
   FOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
-    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}" COPYONLY)
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}")
   ENDFOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
 
   SET (PYTHON_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/share/python")

=== modified file 'swig/python/tests/CMakeLists.txt'
--- swig/python/tests/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/python/tests/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -60,9 +60,9 @@
 ADD_TEST("python_test10" ${PYTHON_EXECUTABLE} test10.py)
 SET_TESTS_PROPERTIES("python_test10" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.py.in ${CMAKE_CURRENT_BINARY_DIR}/test11.py)
-#ADD_TEST("python_test11" ${PYTHON_EXECUTABLE} test11.py)
-#SET_TESTS_PROPERTIES("python_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.py.in ${CMAKE_CURRENT_BINARY_DIR}/test11.py)
+ADD_TEST("python_test11" ${PYTHON_EXECUTABLE} test11.py)
+SET_TESTS_PROPERTIES("python_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
 #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test12.py.in ${CMAKE_CURRENT_BINARY_DIR}/test12.py)
 #ADD_TEST("python_test12" ${PYTHON_EXECUTABLE} test12.py)

=== modified file 'swig/python/tests/test11.py.in'
--- swig/python/tests/test11.py.in	2012-08-30 13:45:43 +0000
+++ swig/python/tests/test11.py.in	2012-09-07 20:02:32 +0000
@@ -16,31 +16,24 @@
 sys.path.insert(0, '@pythonPath@')
 import zorba_api
 
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler): 
-  def error(self, *args):
-    print "Error args: ", args
-
-def test(zorba):
-  #Read and write result
-  print 'Executing: compilerHints.xq'
-  f = open('compilerHints.xq', 'r')
-  lines = f.read()
-  f.close()
-  diagnosticHandler = MyDiagnosticHandler()
-  compilerHints = zorba_api.CompilerHints()
-  compilerHints.setOptimizationLevel(0)
-  xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-  
-  result = xquery.execute()
-  print result
-  return
-
-
 store = zorba_api.InMemoryStore_getInstance()
 zorba = zorba_api.Zorba_getInstance(store)
 
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
+print "Running: CompileQuery CollectionManager"
+
+xmlManager = zorba.getXmlDataManager()
+collectionManager = xmlManager.getCollectionManager()
+itemFactory = zorba.getItemFactory()
+name = itemFactory.createQName("http://www.zorba-xquery.com/";, "aaa")
+collectionManager.createCollection(name)
+isAdded = collectionManager.isAvailableCollection(name)
+
+if isAdded :
+  collection = collectionManager.getCollection(name);
+  data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
+  itemSequence = zorba_api.ItemSequence(data)
+  collection.insertNodesLast(itemSequence)
+
 print "Success"
 
 

=== modified file 'swig/python/zorba_api.i'
--- swig/python/zorba_api.i	2012-08-30 13:45:43 +0000
+++ swig/python/zorba_api.i	2012-09-07 20:02:32 +0000
@@ -23,6 +23,7 @@
 #include <zorba/singleton_item_sequence.h>
 #include <zorba/serializer.h>
 %}
+%include "std_string.i"
 
 %{
 

=== modified file 'swig/ruby/CMakeLists.txt'
--- swig/ruby/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/ruby/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -53,7 +53,7 @@
 
   FILE(GLOB ZORBA_API_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.h")
   FOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
-    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}" COPYONLY)
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/../${ZORBA_API_HEADER}"  "${CMAKE_CURRENT_BINARY_DIR}/${ZORBA_API_HEADER}")
   ENDFOREACH(ZORBA_API_HEADER ${ZORBA_API_HEADERS})
 
   SET (RUBY_SITEARCH_DIR "${CMAKE_INSTALL_PREFIX}/share/ruby")

=== modified file 'swig/ruby/tests/CMakeLists.txt'
--- swig/ruby/tests/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/ruby/tests/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -29,9 +29,9 @@
 ADD_TEST("ruby_test02" ${RUBY_EXECUTABLE} test02.rb)
 SET_TESTS_PROPERTIES("ruby_test02" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test03.rb ${CMAKE_CURRENT_BINARY_DIR}/test03.rb)
-#ADD_TEST("ruby_test03" ${RUBY_EXECUTABLE} test03.rb)
-#SET_TESTS_PROPERTIES("ruby_test03" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test03.rb ${CMAKE_CURRENT_BINARY_DIR}/test03.rb)
+ADD_TEST("ruby_test03" ${RUBY_EXECUTABLE} test03.rb)
+SET_TESTS_PROPERTIES("ruby_test03" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test04.rb ${CMAKE_CURRENT_BINARY_DIR}/test04.rb)
 ADD_TEST("ruby_test04" ${RUBY_EXECUTABLE} test04.rb)
@@ -64,9 +64,9 @@
 ADD_TEST("ruby_test10" ${RUBY_EXECUTABLE} test10.rb)
 SET_TESTS_PROPERTIES("ruby_test10" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.rb ${CMAKE_CURRENT_BINARY_DIR}/test11.rb)
-#ADD_TEST("ruby_test11" ${RUBY_EXECUTABLE} test11.rb)
-#SET_TESTS_PROPERTIES("ruby_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
+CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test11.rb ${CMAKE_CURRENT_BINARY_DIR}/test11.rb)
+ADD_TEST("ruby_test11" ${RUBY_EXECUTABLE} test11.rb)
+SET_TESTS_PROPERTIES("ruby_test11" PROPERTIES PASS_REGULAR_EXPRESSION "Success")
 
 #CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/test12.rb ${CMAKE_CURRENT_BINARY_DIR}/test12.rb)
 #ADD_TEST("ruby_test12" ${RUBY_EXECUTABLE} test12.rb)

=== modified file 'swig/ruby/tests/test03.rb'
--- swig/ruby/tests/test03.rb	2012-03-27 00:56:11 +0000
+++ swig/ruby/tests/test03.rb	2012-09-07 20:02:32 +0000
@@ -14,13 +14,13 @@
 
 require '@rubyPath@/zorba_api'
 
-class MyDiagnosticHandler < Zorba_api.DiagnosticHandler
-  def error(self, *args)
-    print "Error args: " + args
+class MyDiagnosticHandler < Zorba_api::DiagnosticHandler
+  def error(args)
+    print "Error args: " + args.getDescription() + "\n"
   end
 end
 
-def test(zorba):
+def test(zorba)
   diagnosticHandler = MyDiagnosticHandler.new
   begin
     xquery = zorba.compileQuery("1 div 0", diagnosticHandler)
@@ -35,9 +35,9 @@
 store = Zorba_api::InMemoryStore.getInstance()
 zorba = Zorba_api::Zorba.getInstance(store)
 
-print "Running: Capturing error with DiagnosticHandler"
+print "Running: Capturing error with DiagnosticHandler\n"
 test(zorba)
 print "Success"
 
 zorba.shutdown()
-Zorba_api::InMemoryStore.shutdown(store)
+Zorba_api::InMemoryStore.shutdown(store)
\ No newline at end of file

=== modified file 'swig/ruby/tests/test11.rb'
--- swig/ruby/tests/test11.rb	2012-03-27 00:56:11 +0000
+++ swig/ruby/tests/test11.rb	2012-09-07 20:02:32 +0000
@@ -12,38 +12,28 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import sys
-sys.path.insert(0, '@pythonPath@')
-import zorba_api
-
-class MyDiagnosticHandler(zorba_api.DiagnosticHandler): 
-  def error(self, *args):
-    print "Error args: ", args
-
-def test(zorba):
-  #Read and write result
-  print 'Executing: compilerHints.xq'
-  f = open('compilerHints.xq', 'r')
-  lines = f.read()
-  f.close()
-  diagnosticHandler = MyDiagnosticHandler()
-  compilerHints = zorba_api.CompilerHints()
-  compilerHints.setOptimizationLevel(0)
-  xquery = zorba.compileQuery(lines, compilerHints, diagnosticHandler)
-  
-  result = xquery.execute()
-  print result
-  return
-
-
-store = zorba_api.InMemoryStore_getInstance()
-zorba = zorba_api.Zorba_getInstance(store)
-
-print "Running: CompileQuery string + Dignostinc handler + CompilerHint - with optimization 0"
-test(zorba)
+require '@rubyPath@/zorba_api'
+
+store = Zorba_api::InMemoryStore.getInstance()
+zorba = Zorba_api::Zorba.getInstance(store)
+
+print "Running: CompileQuery CollectionManager\n"
+
+xmlManager = zorba.getXmlDataManager()
+collectionManager = xmlManager.getCollectionManager()
+itemFactory = zorba.getItemFactory()
+name = itemFactory.createQName("http://www.zorba-xquery.com/";, "aaa")
+collectionManager.createCollection(name)
+isAdded = collectionManager.isAvailableCollection(name)
+
+if isAdded :
+  collection = collectionManager.getCollection(name)
+  data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>")
+  itemSequence = Zorba_api::ItemSequence.new(data)
+  collection.insertNodesLast(itemSequence)
+end
+
 print "Success"
 
-
 zorba.shutdown()
-zorba_api.InMemoryStore_shutdown(store)
-
+Zorba_api::InMemoryStore.shutdown(store)

=== modified file 'swig/xqj/CMakeLists.txt'
--- swig/xqj/CMakeLists.txt	2012-08-30 13:45:43 +0000
+++ swig/xqj/CMakeLists.txt	2012-09-07 20:02:32 +0000
@@ -29,6 +29,12 @@
   #SWIG Java: Generating XQJ Tests
   FILE(GLOB ZORBA_XQJ_TESTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/managers/" "${CMAKE_CURRENT_SOURCE_DIR}/managers/*.*")
   FOREACH(ZORBA_XQJ_TEST ${ZORBA_XQJ_TESTS})
+    CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/managers/${ZORBA_XQJ_TEST}"  "${CMAKE_CURRENT_BINARY_DIR}/managers/${ZORBA_XQJ_TEST}" COPYONLY)
+  ENDFOREACH(ZORBA_XQJ_TEST ${ZORBA_API_HEADERS})
+
+  #SWIG Java: Processing XQ
+  FILE(GLOB ZORBA_XQJ_TESTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/managers/" "${CMAKE_CURRENT_SOURCE_DIR}/managers/*.xq")
+  FOREACH(ZORBA_XQJ_TEST ${ZORBA_XQJ_TESTS})
     CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/managers/${ZORBA_XQJ_TEST}"  "${CMAKE_CURRENT_BINARY_DIR}/managers/${ZORBA_XQJ_TEST}")
   ENDFOREACH(ZORBA_XQJ_TEST ${ZORBA_API_HEADERS})
   
@@ -100,7 +106,7 @@
                      COMMAND cmake -E echo "Compiling XQJ files..."
                      COMMAND ${Java_JAVAC_EXECUTABLE} -cp ${XQJ_CLASSPATH} *.java -d ${CMAKE_CURRENT_BINARY_DIR}
                      COMMAND cmake -E echo "Creating jar file..."
-                     COMMAND ${Java_JAR_EXECUTABLE} cvf zorba_xqj.jar org
+                     COMMAND ${Java_JAR_EXECUTABLE} cf zorba_xqj.jar org
     )
   ENDIF (${RESULT} GREATER -1)
 

=== modified file 'swig/xqj/ZorbaXQConnection.java'
--- swig/xqj/ZorbaXQConnection.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/ZorbaXQConnection.java	2012-09-07 20:02:32 +0000
@@ -333,26 +333,11 @@
         isClosedXQException();
         isNullXQException(reader);
         
-        StringBuffer string = new StringBuffer();
-        CharBuffer buffer = CharBuffer.allocate(1024);
-        Writer writer = new StringWriter();
-        
-        try {
-            while( reader.read(buffer) >= 0 ) {
-                buffer.flip();
-                writer.append(buffer);
-                buffer.clear();
-            }
-            reader.close();
-        } catch (Exception ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
-        }
-        
         XQPreparedExpression expression;
         if (lStaticContext == null) {
-            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString());
+            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader);
         } else {
-            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString(), lStaticContext);
+            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader, lStaticContext);
         }
         cPreparedExpression.add(expression);
         return expression;
@@ -372,21 +357,8 @@
         isClosedXQException();
         isNullXQException(reader);
         isNullXQException(xqsc);
-        StringBuffer string = new StringBuffer();
-        CharBuffer buffer = CharBuffer.allocate(1024);
-        Writer writer = new StringWriter();
-        try {
-            while( reader.read(buffer) >= 0 ) {
-                buffer.flip();
-                writer.append(buffer);
-                buffer.clear();
-            }
-            reader.close();
-        } catch (Exception ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
-        }
-        
-        XQPreparedExpression expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, writer.toString(), xqsc);
+
+        XQPreparedExpression expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, reader, xqsc);
         
         cPreparedExpression.add(expression);
         return expression;
@@ -404,21 +376,12 @@
     public XQPreparedExpression prepareExpression(InputStream in) throws XQException {
         isClosedXQException();
         isNullXQException(in);
-        StringBuffer  out = new StringBuffer ();
-        try {
-            byte[] b = new byte[4096];
-            for (int n; (n = in.read(b)) != -1;) {
-                out.append(new String(b, 0, n));
-            }
-        } catch (Exception ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
-        }
-        
+
         XQPreparedExpression expression;
         if (lStaticContext == null) {
-            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString());
+            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in);
         } else {
-            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString(), lStaticContext);
+            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in, lStaticContext);
         }
         try {
             cPreparedExpression.add(expression);
@@ -443,19 +406,10 @@
         isClosedXQException();
         isNullXQException(in);
         isNullXQException(xqsc);
-        StringBuffer  out = new StringBuffer ();
-        try {
-            byte[] b = new byte[4096];
-            for (int n; (n = in.read(b)) != -1;) {
-                out.append(new String(b, 0, n));
-            }
-        } catch (IOException ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
-        }
         
         XQPreparedExpression expression = null;
         try {
-            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, out.toString(), xqsc);
+            expression = new org.zorbaxquery.api.xqj.ZorbaXQPreparedExpression(this, in, xqsc);
             cPreparedExpression.add(expression);
         } catch (Exception ex) {
             throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
@@ -726,11 +680,7 @@
         try {
             dm = zorba.getXmlDataManager();
             doc = new Item();
-            org.zorbaxquery.api.Iterator iterator =  dm.parseXML(value);
-            iterator.open();
-            iterator.next(doc);
-            iterator.close();
-            iterator.delete();
+            doc =  dm.parseXMLtoItem(value);
             item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
         } catch (Exception e) {
             throw new XQException("Error creating Item" + e.getLocalizedMessage());
@@ -756,23 +706,26 @@
     public XQItem createItemFromDocument(Reader value, String baseURI, XQItemType type) throws XQException {
         isClosedXQException();
         isNullXQException(value);
-        
-        StringBuffer string = new StringBuffer();
-        CharBuffer buffer = CharBuffer.allocate(1024);
-        Writer writer = new StringWriter();
-        
+        if (type!=null) {
+            if ( ! ((type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_ELEMENT)||(type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT)) ) {
+                throw new XQException("Invalid type");
+            }
+        } else {
+            type =  this.createElementType(null, XQItemType.XQBASETYPE_UNTYPED);
+        }
+        
+        XmlDataManager dm = null;
+        Item doc = null;
+        XQItem item = null;
         try {
-            while( value.read(buffer) >= 0 ) {
-                buffer.flip();
-                writer.append(buffer);
-                buffer.clear();
-            }
-            value.close();
-        } catch (Exception ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
+            dm = zorba.getXmlDataManager();
+            doc = new Item();
+            ZorbaReaderWrapper stream = new ZorbaReaderWrapper(value);
+            doc =  dm.parseXMLtoItem(stream);
+            item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
+        } catch (Exception e) {
+            throw new XQException("Error creating Item" + e.getLocalizedMessage());
         }
-        
-        XQItem item = createItemFromDocument(writer.toString(), baseURI, type);
         return item;
     }
 
@@ -794,17 +747,26 @@
     public XQItem createItemFromDocument(InputStream value, String baseURI, XQItemType type) throws XQException {
         isClosedXQException();
         isNullXQException(value);
-        // TODO: Rodolfo: optimize this, not good to have a string
-        StringBuffer out = new StringBuffer ();
+        if (type!=null) {
+            if ( ! ((type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_ELEMENT)||(type.getItemKind()== XQItemType.XQITEMKIND_DOCUMENT_SCHEMA_ELEMENT)) ) {
+                throw new XQException("Invalid type");
+            }
+        } else {
+            type =  this.createElementType(null, XQItemType.XQBASETYPE_UNTYPED);
+        }
+        
+        XmlDataManager dm = null;
+        Item doc = null;
+        XQItem item = null;
         try {
-            byte[] b = new byte[4096];
-            for (int n; (n = value.read(b)) != -1;) {
-                out.append(new String(b, 0, n));
-            }
-        } catch (Exception ex) {
-            throw new XQException("Error preparing expression" + ex.getLocalizedMessage());
+            dm = zorba.getXmlDataManager();
+            doc = new Item();
+            ZorbaInputWrapper stream = new ZorbaInputWrapper(value);
+            doc =  dm.parseXMLtoItem(stream);
+            item = new org.zorbaxquery.api.xqj.ZorbaXQItem(doc);
+        } catch (Exception e) {
+            throw new XQException("Error creating Item" + e.getLocalizedMessage());
         }
-        XQItem item = createItemFromDocument(out.toString(), baseURI, type);
         return item;
     }
 
@@ -1203,11 +1165,7 @@
                         Item tmpItem = new Item();
                         if (xmlString.length()>0) {
                             XmlDataManager dataManager = zorba.getXmlDataManager();
-                            org.zorbaxquery.api.Iterator iter = dataManager.parseXML(xmlString);
-                            iter.open();
-                            iter.next(tmpItem);
-                            iter.close();
-                            iter.delete();
+                            tmpItem = dataManager.parseXMLtoItem(xmlString);
                         } else {
                             tmpItem = itemFactory.createDocumentNode("", "");
                         }

=== modified file 'swig/xqj/ZorbaXQItem.java'
--- swig/xqj/ZorbaXQItem.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/ZorbaXQItem.java	2012-09-07 20:02:32 +0000
@@ -699,7 +699,8 @@
                     opts.setSerializerOption(key, value);
                 }
             }
-            out.write(item.serialize(opts).getBytes());
+            ZorbaOutputWrapper OStream = new ZorbaOutputWrapper(out);
+            item.serializeToStream(OStream);
         } catch (Exception ex) {
             throw new XQException("Error writing on stream: " + ex.getLocalizedMessage());
         }
@@ -727,6 +728,8 @@
                     opts.setSerializerOption(key, value);
                 }
             }
+            ZorbaWriterWrapper OStream = new ZorbaWriterWrapper(writer);
+            item.serializeToStream(OStream);
             writer.write(item.serialize(opts));
         } catch (Exception ex) {
             throw new XQException("Error sending to writer: " + ex.getLocalizedMessage());

=== modified file 'swig/xqj/ZorbaXQPreparedExpression.java'
--- swig/xqj/ZorbaXQPreparedExpression.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/ZorbaXQPreparedExpression.java	2012-09-07 20:02:32 +0000
@@ -15,10 +15,7 @@
  */
 package org.zorbaxquery.api.xqj;
 
-import java.io.InputStream;
-import java.io.Reader;
-import java.io.StringWriter;
-import java.io.Writer;
+import java.io.*;
 import java.nio.CharBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -112,6 +109,43 @@
         
         }
     }
+
+    public ZorbaXQPreparedExpression (XQConnection conn, Reader reader) throws XQException {
+        if (conn.isClosed()) {
+            throw new XQException ("Connection is closed");
+        }
+        closed = false;
+        connection = conn;
+        Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance(); 
+        try {
+            ZorbaReaderWrapper stream = new ZorbaReaderWrapper(reader);
+            query =  zorba.compileQuery(stream);
+            dynamicContext = query.getDynamicContext();
+            xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+        } catch (Exception e) {
+            throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+        
+        }
+    }
+
+    public ZorbaXQPreparedExpression (XQConnection conn, InputStream input) throws XQException {
+        if (conn.isClosed()) {
+            throw new XQException ("Connection is closed");
+        }
+        closed = false;
+        connection = conn;
+        Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance(); 
+        try {
+            ZorbaInputWrapper stream = new ZorbaInputWrapper(input);
+            query =  zorba.compileQuery(stream);
+            dynamicContext = query.getDynamicContext();
+            xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+        } catch (Exception e) {
+            throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+        
+        }
+    }
+
     public ZorbaXQPreparedExpression (XQConnection conn, String string, XQStaticContext sc) throws XQException {
         if (conn.isClosed()) {
             throw new XQException ("Connection is closed");
@@ -129,6 +163,42 @@
         }
     }
 
+    public ZorbaXQPreparedExpression (XQConnection conn, Reader reader, XQStaticContext sc) throws XQException {
+        if (conn.isClosed()) {
+            throw new XQException ("Connection is closed");
+        }
+        closed = false;
+        connection = conn;
+        Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance(); 
+        try {
+            ZorbaReaderWrapper stream = new ZorbaReaderWrapper(reader);
+            query =  zorba.compileQuery(stream, ((org.zorbaxquery.api.xqj.ZorbaXQStaticContext)sc).getZorbaStaticContext());
+            dynamicContext = query.getDynamicContext();
+            xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+        } catch (Exception e) {
+            throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+        
+        }
+    }
+
+    public ZorbaXQPreparedExpression (XQConnection conn, InputStream input, XQStaticContext sc) throws XQException {
+        if (conn.isClosed()) {
+            throw new XQException ("Connection is closed");
+        }
+        closed = false;
+        connection = conn;
+        Zorba zorba = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance(); 
+        try {
+            ZorbaInputWrapper stream = new ZorbaInputWrapper(input);
+            query =  zorba.compileQuery(stream, ((org.zorbaxquery.api.xqj.ZorbaXQStaticContext)sc).getZorbaStaticContext());
+            dynamicContext = query.getDynamicContext();
+            xmlDataManager = ((org.zorbaxquery.api.xqj.ZorbaXQConnection)connection).getZorbaInstance().getXmlDataManager();
+        } catch (Exception e) {
+            throw new XQException ("Error creating new Prepared expression with static context: " + e.getLocalizedMessage());
+        
+        }
+    }
+
   /** \brief Attempts to cancel the execution if both the XQuery engine and XQJ driver support aborting the execution of an ZorbaXQPreparedExpression.
    * 
    * This method can be used by one thread to cancel an ZorbaXQPreparedExpression, that is being executed in another thread. If cancellation is not supported or the attempt to cancel the execution was not successful, the method returns without any error. If the cancellation is successful, an XQException is thrown, to indicate that it has been aborted, by executeQuery, executeCommand or any method accessing the ZorbaXQResultSequence returned by executeQuery. If applicable, any open ZorbaXQResultSequence and XQResultItem objects will also be implicitly closed in this case.
@@ -445,9 +515,8 @@
             throw new XQException ("Variable not found in context.");
         }
         try {
-            Iterator iter = xmlDataManager.parseXML(value);
             Item item = new Item();
-            iter.next(item);
+            item = xmlDataManager.parseXMLtoItem(value);
             dynamicContext.setVariable(varName.getLocalPart(), item);
             itemsBounded.add(varName.getLocalPart());
         } catch (Exception e) {

=== modified file 'swig/xqj/ZorbaXQResultSequence.java'
--- swig/xqj/ZorbaXQResultSequence.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/ZorbaXQResultSequence.java	2012-09-07 20:02:32 +0000
@@ -35,6 +35,7 @@
 import org.xml.sax.ContentHandler;
 import org.zorbaxquery.api.Item;
 import org.zorbaxquery.api.Iterator;
+import org.zorbaxquery.api.SerializationOptions;
 
  /**
    * This class represents a sequence of items obtained as a result of evaluation XQuery expressions. The result sequence is tied to the XQconnection object on which the expression was evaluated.
@@ -309,21 +310,20 @@
         isConsumedXQException();
         String result = null;
         try {
-        /*
-        if (item.isNode() && item.getNodeKind()==3) { //attribute node
-            resultString = resultString.concat(item.getStringValue()).concat(" ");
-        } else {
-            resultString = resultString.concat(item.serialize().replace("&gt;", ">").replace("&lt;", "<")).concat(" ");
-        }
-         * 
-         */
+            SerializationOptions opts = new SerializationOptions();
+            if ((prprts!=null) && prprts.size()>0) {
+                for(String key : prprts.stringPropertyNames()) {
+                    String value = prprts.getProperty(key);
+                    opts.setSerializerOption(key, value);
+                }
+            }
             if (iter.isOpen()) {
                 iter.close();
                 iter.delete();
             }
             iterDeleted = true;
             consumedItem = true;
-            result = lQuery.execute().replace("&gt;", ">").replace("&lt;", "<");
+            result = lQuery.execute(opts).replace("&gt;", ">").replace("&lt;", "<");
         } catch (Exception e) {
             throw new XQException("Error getting stream: " + e.getLocalizedMessage());
         } finally {

=== modified file 'swig/xqj/ZorbaXQSequence.java'
--- swig/xqj/ZorbaXQSequence.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/ZorbaXQSequence.java	2012-09-07 20:02:32 +0000
@@ -359,7 +359,7 @@
         isItemGetXQException();
         StringBuffer sb = new StringBuffer();
         for (XQItem item: content) {
-            sb.append(item.getItemAsString(null));
+            sb.append(item.getItemAsString(prprts));
         }
         return sb.toString();
     }

=== modified file 'swig/xqj/managers/Api_test.java'
--- swig/xqj/managers/Api_test.java	2012-08-30 13:45:43 +0000
+++ swig/xqj/managers/Api_test.java	2012-09-07 20:02:32 +0000
@@ -16,285 +16,63 @@
 package api_test;
 
 
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.net.URI;
-import java.net.URISyntaxException;
-import javax.xml.namespace.QName;
-import javax.xml.xquery.*;
-import org.zorbaxquery.api.*;
-import org.zorbaxquery.api.xqj.*;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Locale;
 
 public class Api_test {
-
-  static 
-  {
-    System.loadLibrary ( "zorba_api" );
-  }
-
-  static boolean example_1() throws XQException
-  {
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      XQConnection xqc = xqds.getConnection();
-      XQExpression xqe = xqc.createExpression();
-      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery("1,2,3");
-      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
-      xqc.close();
-      xqc.close();
-      return true;
-  }
-
-  static boolean example_2 () throws XQException
-  {
-      StringBuilder strBuilder = new StringBuilder();
-      try {
-            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
-            String str;
-            while ((str = in.readLine()) != null) {
-                strBuilder.append(str);
-            }
-            in.close();
-      } catch (Exception e) {
-          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
-      }
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      XQConnection xqc = xqds.getConnection();
-      XQExpression xqe = xqc.createExpression();
-      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery(strBuilder.toString());
-      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
-      boolean resultAdding = false;
-      boolean resultDeleting = true;
-      URI uri;
-      QName qname;
-      XQItemType type = null;
-        try {
-          uri = new URI("http://www.mod2.com/";);
-          qname = new QName("http://www.mod2.com/";, "coll");
-          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
-        } catch (URISyntaxException e) {
-            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
-        }
-      XQItem colName = xqc.createItemFromString("coll",  type);
-      colManager.createCollection(colName);
-      resultAdding = colManager.isAvailableCollection(colName);
-      colManager.deleteCollection(colName);
-      resultDeleting = !colManager.isAvailableCollection(colName);
-      xqc.close();
-      return resultAdding && resultDeleting;
-  }
-  
-  static boolean example_3a() throws XQException
-  {
-      StringBuilder strBuilder = new StringBuilder();
-      try {
-            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
-            String str;
-            while ((str = in.readLine()) != null) {
-                strBuilder.append(str);
-            }
-            in.close();
-      } catch (Exception e) {
-          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
-      }
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
-      XQExpression xqe = xqc.createExpression();
-      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery(strBuilder.toString());
-      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
-      URI uri;
-      QName qname;
-      XQItemType type = null;
-        try {
-          uri = new URI("http://www.mod2.com/";);
-          qname = new QName("http://www.mod2.com/";, "coll");
-          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
-        } catch (URISyntaxException e) {
-            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
-        }
-      XQItem colName = xqc.createItemFromString("coll",  type);
-      colManager.createCollection(colName);
-      ZorbaXQCollection collection = colManager.getCollection(colName);
-      
-      ZorbaXQXmlDataManager manager = xqc.getXmlDataManager();
-      XQSequence data = manager.parseXML("<books><book>Book 1</book><book>Book 2</book></books>");
-      collection.insertNodesFirst(data);
-      
-      colManager.deleteCollection(colName);
-      boolean resultDeleting = !colManager.isAvailableCollection(colName);
-      xqc.close();
-      return resultDeleting;
-  }
-
-  static boolean example_3b() throws XQException
-  {
-      StringBuilder strBuilder = new StringBuilder();
-      try {
-            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
-            String str;
-            while ((str = in.readLine()) != null) {
-                strBuilder.append(str);
-            }
-            in.close();
-      } catch (Exception e) {
-          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
-      }
-    InMemoryStore store = InMemoryStore.getInstance();
-    Zorba zorba = Zorba.getInstance ( store );
-    XQuery query = zorba.compileQuery(strBuilder.toString());
-    StaticCollectionManager manager = query.getStaticCollectionManager();
-    
-    
-    ItemFactory factory = zorba.getItemFactory();
-    Item name = factory.createQName("http://www.mod2.com/";, "coll");
-    
-    manager.createCollection(name);
-    Collection collection = manager.getCollection(name);
-
-    XmlDataManager xmlManager = zorba.getXmlDataManager();
-    Item data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
-    ItemSequence sequence = new ItemSequence(data);
-    collection.insertNodesLast(sequence);
-    
-    zorba.shutdown();
-    InMemoryStore.shutdown ( store );
-
-    return true;
-  }
-
-  static boolean example_4() throws XQException
-  {
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
-      XQExpression xqe = xqc.createExpression();
-      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
-      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
-      xqc.close();
-      xqc.close();
-      return true;
-  }
-
-  static boolean example_5() throws XQException
-  {
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
-      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
-      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
-      boolean resultAdding = false;
-      boolean resultDeleting = true;
-      URI uri;
-      QName qname;
-      XQItemType type = null;
-        try {
-          uri = new URI("http://www.mod2.com/";);
-          qname = new QName("http://www.mod2.com/";, "col2");
-          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
-        } catch (URISyntaxException e) {
-            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
-        }
-      XQItem colName = xqc.createItemFromString("col2",  type);
-      colManager.createCollection(colName);
-      resultAdding = colManager.isAvailableCollection(colName);
-      colManager.deleteCollection(colName);
-      resultDeleting = !colManager.isAvailableCollection(colName);
-      xqc.close();
-      return resultAdding && resultDeleting;
-  }
-  static boolean example_6a() throws XQException
-  {
-    InMemoryStore store = InMemoryStore.getInstance();
-    Zorba zorba = Zorba.getInstance ( store );
-    XmlDataManager xmlManager = new XmlDataManager(zorba.getXmlDataManager());
-    CollectionManager manager = new CollectionManager(xmlManager.getCollectionManager());
-
-    ItemFactory factory = zorba.getItemFactory();
-    Item name = factory.createQName("http://www.zorba-xquery.com/";, "aaa");
-    manager.createCollection(name);
-    boolean resultAdding = manager.isAvailableCollection(name);
-    Collection collection = null;
-    //Item data = new Item();
-    if (resultAdding) {
-      collection = manager.getCollection(name);
-      Item data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
-      collection.insertNodesLast(new ItemSequence(data));
+    static 
+    {
+        System.loadLibrary ( "zorba_api" );
     }
-    collection.delete();
-    
-    zorba.shutdown();
-    InMemoryStore.shutdown ( store );
-    return true;
-  }
-
-  static boolean example_6b() throws XQException
-  {
-      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
-      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
-      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
-      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
-      URI uri;
-      QName qname;
-      XQItemType type = null;
+
+
+    public static void main ( String... args )
+    {
         try {
-          uri = new URI("http://www.mod2.com/";);
-          qname = new QName("http://www.mod2.com/";, "col2");
-          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
-        } catch (URISyntaxException e) {
-            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
+          Class<?> c = Class.forName("api_test.Tests");
+          Object t = c.newInstance();
+
+          Method[] allMethods = c.getDeclaredMethods();
+          for (Method m : allMethods) {
+              String mname = m.getName();
+              if (!mname.startsWith("test")
+                  || (m.getGenericReturnType() != boolean.class)) {
+                  continue;
+              }
+              Type[] pType = m.getGenericParameterTypes();
+              if ((pType.length != 1)
+                  || Locale.class.isAssignableFrom(pType[0].getClass())) {
+                  //continue;
+              }
+
+              System.out.format("invoking %s()%n", mname);
+              try {
+                  m.setAccessible(true);
+                  Object o = m.invoke(t);
+                  System.out.format("%s() returned %b%n", mname, (Boolean) o);
+                  if ((Boolean) o) {
+                    System.out.println("Success");
+                  } else {
+                    System.out.println("Failed");
+                    System.exit (1);
+                  }
+
+              // Handle any exceptions thrown by method to be invoked.
+              } catch (InvocationTargetException x) {
+                  Throwable cause = x.getCause();
+                  System.err.format("invocation of %s failed: %s%n",
+                       mname, cause.getMessage());
+              }
+          }
+
+            // production code should handle these exceptions more gracefully
+        } catch (Exception e) {
+          System.out.println("Failed");
+          System.out.println("Exception caught. " + e.getLocalizedMessage());
+          e.printStackTrace();
         }
-      XQItem colName = xqc.createItemFromString("col2",  type);
-      colManager.createCollection(colName);
-      ZorbaXQCollection collection = colManager.getCollection(colName);
-      colName.close();
-      XQSequence data = xmlManager.parseXML("<books><book>Book 1</book><book>Book 2</book></books>");
-      collection.insertNodesLast(data);
-      xqc.close();
-      return true;
-  }
-
-  public static void main ( String argv[] ) throws XQException
-  {
-    boolean res = false;
-
-    System.out.println ("executing test 1" );
-    res = example_1( );
-    if ( !res ) 
-      System.exit ( 1 ); 
-
-    System.out.println ( "executing test 2" );
-    res = example_2 ( );
-    if (!res) 
-      System.exit ( 1 ); 
-  
-    System.out.println ( "executing test 3a" );
-    res = example_3a ( );
-    if (!res) 
-      System.exit ( 1 ); 
-  
-    System.out.println ( "executing test 3b" );
-    res = example_3b ( );
-    if (!res) 
-      System.exit ( 1 ); 
-    
-    System.out.println ( "executing test 4" );
-    res = example_4 ( );
-    if (!res) 
-      System.exit ( 1 ); 
-
-    System.out.println ( "executing test 5" );
-    res = example_5 ( );
-    if (!res) 
-      System.exit ( 1 ); 
-    System.out.println ( "executing test 6a" );
-    res = example_6a ( );
-    if (!res) 
-      System.exit ( 1 ); 
-
-    System.out.println ( "executing test 6b" );
-    res = example_6b ( );
-    if (!res) 
-      System.exit ( 1 ); 
-    System.out.println ( "done." );
-
-  } // main
+    } // main
 
 } // class Test_Zorba
-

=== added file 'swig/xqj/managers/Tests.java'
--- swig/xqj/managers/Tests.java	1970-01-01 00:00:00 +0000
+++ swig/xqj/managers/Tests.java	2012-09-07 20:02:32 +0000
@@ -0,0 +1,383 @@
+/*
+ * Copyright 2006-2012 The FLWOR Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package api_test;
+
+
+import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Properties;
+import javax.xml.namespace.QName;
+import javax.xml.xquery.*;
+import org.zorbaxquery.api.*;
+import org.zorbaxquery.api.xqj.*;
+
+public class Tests {
+
+  static 
+  {
+    System.loadLibrary ( "zorba_api" );
+  }
+
+  static String getFile(String filename) throws FileNotFoundException, IOException {
+    File file = new File(filename);
+    FileInputStream fileStream = new FileInputStream(file);
+    InputStreamReader reader = new InputStreamReader( fileStream, "UTF8" );
+    BufferedReader    buffer = new BufferedReader( reader );
+    String line;
+    StringBuilder builder = new StringBuilder();
+    while ( (line = buffer.readLine()) != null ) 
+    {
+      builder.append(line);
+    }
+    return builder.toString();
+  }
+
+  static boolean checkResult(String expected, String result) {
+    System.out.println("Result:");
+    System.out.println(result);
+    System.out.println("Expected:");
+    System.out.println(expected);
+    return expected.equals(result);
+  }
+
+  static boolean test_1() throws XQException
+  {
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      XQConnection xqc = xqds.getConnection();
+      XQExpression xqe = xqc.createExpression();
+      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery("1,2,3");
+      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
+      xqc.close();
+      xqc.close();
+      return true;
+  }
+
+
+  static boolean test_2 () throws XQException
+  {
+      StringBuilder strBuilder = new StringBuilder();
+      try {
+            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
+            String str;
+            while ((str = in.readLine()) != null) {
+                strBuilder.append(str);
+            }
+            in.close();
+      } catch (Exception e) {
+          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
+      }
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      XQConnection xqc = xqds.getConnection();
+      XQExpression xqe = xqc.createExpression();
+      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery(strBuilder.toString());
+      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
+      boolean resultAdding = false;
+      boolean resultDeleting = true;
+      URI uri;
+      QName qname;
+      XQItemType type = null;
+        try {
+          uri = new URI("http://www.mod2.com/";);
+          qname = new QName("http://www.mod2.com/";, "coll");
+          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
+        } catch (URISyntaxException e) {
+            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
+        }
+      XQItem colName = xqc.createItemFromString("coll",  type);
+      colManager.createCollection(colName);
+      resultAdding = colManager.isAvailableCollection(colName);
+      colManager.deleteCollection(colName);
+      resultDeleting = !colManager.isAvailableCollection(colName);
+      xqc.close();
+      return resultAdding && resultDeleting;
+  }
+  
+  static boolean test_3a() throws XQException
+  {
+      StringBuilder strBuilder = new StringBuilder();
+      try {
+            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
+            String str;
+            while ((str = in.readLine()) != null) {
+                strBuilder.append(str);
+            }
+            in.close();
+      } catch (Exception e) {
+          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
+      }
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
+      XQExpression xqe = xqc.createExpression();
+      org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery(strBuilder.toString());
+      ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
+      URI uri;
+      QName qname;
+      XQItemType type = null;
+        try {
+          uri = new URI("http://www.mod2.com/";);
+          qname = new QName("http://www.mod2.com/";, "coll");
+          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
+        } catch (URISyntaxException e) {
+            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
+        }
+      XQItem colName = xqc.createItemFromString("coll",  type);
+      colManager.createCollection(colName);
+      ZorbaXQCollection collection = colManager.getCollection(colName);
+      
+      ZorbaXQXmlDataManager manager = xqc.getXmlDataManager();
+      XQSequence data = manager.parseXML("<books><book>Book 1</book><book>Book 2</book></books>");
+      collection.insertNodesFirst(data);
+      
+      colManager.deleteCollection(colName);
+      boolean resultDeleting = !colManager.isAvailableCollection(colName);
+      xqc.close();
+      return resultDeleting;
+  }
+
+  static boolean test_3b() throws XQException
+  {
+      StringBuilder strBuilder = new StringBuilder();
+      try {
+            BufferedReader in = new BufferedReader(new FileReader("managers/module1.xq"));
+            String str;
+            while ((str = in.readLine()) != null) {
+                strBuilder.append(str);
+            }
+            in.close();
+      } catch (Exception e) {
+          throw new XQException("Error reading file for test: " + e.getLocalizedMessage());
+      }
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    XQuery query = zorba.compileQuery(strBuilder.toString());
+    StaticCollectionManager manager = query.getStaticCollectionManager();
+    
+    
+    ItemFactory factory = zorba.getItemFactory();
+    Item name = factory.createQName("http://www.mod2.com/";, "coll");
+    
+    manager.createCollection(name);
+    Collection collection = manager.getCollection(name);
+
+    XmlDataManager xmlManager = zorba.getXmlDataManager();
+    Item data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
+    ItemSequence sequence = new ItemSequence(data);
+    collection.insertNodesLast(sequence);
+    
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+
+    return true;
+  }
+
+  static boolean test_4() throws XQException
+  {
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
+      XQExpression xqe = xqc.createExpression();
+      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
+      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
+      xqc.close();
+      xqc.close();
+      return true;
+  }
+
+  static boolean test_5() throws XQException
+  {
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
+      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
+      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
+      boolean resultAdding = false;
+      boolean resultDeleting = true;
+      URI uri;
+      QName qname;
+      XQItemType type = null;
+        try {
+          uri = new URI("http://www.mod2.com/";);
+          qname = new QName("http://www.mod2.com/";, "col2");
+          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
+        } catch (URISyntaxException e) {
+            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
+        }
+      XQItem colName = xqc.createItemFromString("col2",  type);
+      colManager.createCollection(colName);
+      resultAdding = colManager.isAvailableCollection(colName);
+      colManager.deleteCollection(colName);
+      resultDeleting = !colManager.isAvailableCollection(colName);
+      xqc.close();
+      return resultAdding && resultDeleting;
+  }
+  static boolean test_6a() throws XQException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    XmlDataManager xmlManager = new XmlDataManager(zorba.getXmlDataManager());
+    CollectionManager manager = new CollectionManager(xmlManager.getCollectionManager());
+    ItemFactory factory = zorba.getItemFactory();
+    Item name = factory.createQName("http://www.zorba-xquery.com/";, "aaa");
+    manager.createCollection(name);
+    boolean resultAdding = manager.isAvailableCollection(name);
+    Collection collection = null;
+    //Item data = new Item();
+    if (resultAdding) {
+      collection = manager.getCollection(name);
+      Item data = xmlManager.parseXMLtoItem("<books><book>Book 1</book><book>Book 2</book></books>");
+      collection.insertNodesLast(new ItemSequence(data));
+    }
+    collection.delete();
+    
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return true;
+  }
+
+  static boolean test_6b() throws XQException
+  {
+      ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+      org.zorbaxquery.api.xqj.ZorbaXQConnection xqc = (org.zorbaxquery.api.xqj.ZorbaXQConnection) xqds.getConnection();
+      ZorbaXQXmlDataManager xmlManager = xqc.getXmlDataManager();
+      ZorbaXQCollectionManager colManager =  xmlManager.getCollectionManager();
+      URI uri;
+      QName qname;
+      XQItemType type = null;
+        try {
+          uri = new URI("http://www.mod2.com/";);
+          qname = new QName("http://www.mod2.com/";, "col2");
+          type = xqc.createAtomicType( XQItemType.XQBASETYPE_QNAME, qname, uri);
+        } catch (URISyntaxException e) {
+            throw new XQException("Error creating QName: " + e.getLocalizedMessage());
+        }
+      XQItem colName = xqc.createItemFromString("col2",  type);
+      colManager.createCollection(colName);
+      ZorbaXQCollection collection = colManager.getCollection(colName);
+      colName.close();
+      XQSequence data = xmlManager.parseXML("<books><book>Book 1</book><book>Book 2</book></books>");
+      collection.insertNodesLast(data);
+      xqc.close();
+      return true;
+  }
+
+  static boolean test_7() throws XQException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    String test = "Hello world!";
+    ZorbaReaderWrapper stream = new ZorbaReaderWrapper(new StringReader("'"+test+"'"));
+    XQuery query = zorba.compileQuery(stream);
+    SerializationOptions opts = new SerializationOptions();
+    opts.setOmitXMLDeclaration(SerializationOptions.OmitXMLDeclaration.ZORBA_API_OMIT_XML_DECLARATION_YES);
+    String queryResult = query.execute(opts);
+    boolean result = checkResult(test, queryResult);
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return result;
+  }
+
+  static boolean test_8() throws XQException, UnsupportedEncodingException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    StringBuilder test = new StringBuilder();
+    for (int i=0; i<20; i++) {
+      test.append("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); // 100 chars
+    }
+    String queryString = "'" + test.toString() + "'";
+    ZorbaInputWrapper stream = new ZorbaInputWrapper(new ByteArrayInputStream(queryString.getBytes("UTF-8")));
+    XQuery query = zorba.compileQuery(stream);
+    SerializationOptions opts = new SerializationOptions();
+    opts.setOmitXMLDeclaration(SerializationOptions.OmitXMLDeclaration.ZORBA_API_OMIT_XML_DECLARATION_YES);
+    String queryResult = query.execute(opts);
+    boolean result = checkResult(test.toString(), queryResult);
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return result;
+  }
+
+  static boolean test_9() throws XQException, UnsupportedEncodingException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    String test = "<Hello><ab/><ax/>World</Hello>";
+    ZorbaInputWrapper stream = new ZorbaInputWrapper(new ByteArrayInputStream(test.getBytes("UTF-8")));
+    SerializationOptions opts = new SerializationOptions();
+    opts.setIndent(SerializationOptions.Indent.ZORBA_API_INDENT_NO);
+    opts.setOmitXMLDeclaration(SerializationOptions.OmitXMLDeclaration.ZORBA_API_OMIT_XML_DECLARATION_YES);
+    XQuery query = zorba.compileQuery(stream);
+    String queryResult = query.execute(opts);
+    boolean result = checkResult(test, queryResult);
+    query.destroy();
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return result;
+  }
+
+  static boolean test_10() throws XQException, UnsupportedEncodingException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    String test = "<Hello><ab/><ax/>World</Hello>";
+    ZorbaInputWrapper stream = new ZorbaInputWrapper(new ByteArrayInputStream(test.getBytes("UTF-8")));
+    XQuery query = zorba.compileQuery(stream);
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    ZorbaOutputWrapper OStream = new ZorbaOutputWrapper(out);
+    SerializationOptions opts = new SerializationOptions();
+    opts.setIndent(SerializationOptions.Indent.ZORBA_API_INDENT_NO);
+    opts.setOmitXMLDeclaration(SerializationOptions.OmitXMLDeclaration.ZORBA_API_OMIT_XML_DECLARATION_YES);
+    query.execute(OStream, opts);
+    boolean result = checkResult(test, out.toString());
+    query.destroy();
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return result;
+  }
+
+  static boolean test_11a() throws XQException, FileNotFoundException, IOException
+  {
+    InMemoryStore store = InMemoryStore.getInstance();
+    Zorba zorba = Zorba.getInstance ( store );
+    String test = getFile("managers/utf.txt");
+    org.zorbaxquery.api.ZorbaReaderWrapper stream = new org.zorbaxquery.api.ZorbaReaderWrapper(new StringReader("'"+test+"'"));
+    XQuery query = zorba.compileQuery(stream);
+    SerializationOptions opts = new SerializationOptions();
+    opts.setOmitXMLDeclaration(SerializationOptions.OmitXMLDeclaration.ZORBA_API_OMIT_XML_DECLARATION_YES);
+    String queryResult = query.execute(opts);
+    boolean result = checkResult(test, queryResult);
+    zorba.shutdown();
+    InMemoryStore.shutdown ( store );
+    return result;
+  }
+
+  static boolean test_11b() throws XQException, FileNotFoundException, IOException
+  {
+    String test = getFile("managers/utf.txt");
+    ZorbaXQDataSource xqds = new ZorbaXQDataSource();
+    XQConnection xqc = xqds.getConnection();
+    XQExpression xqe = xqc.createExpression();
+    org.zorbaxquery.api.xqj.ZorbaXQResultSequence xqs = (org.zorbaxquery.api.xqj.ZorbaXQResultSequence) xqe.executeQuery("'"+test+"'");
+    ZorbaXQStaticCollectionManager colManager =  xqs.getStaticCollectionManager();
+    Properties prpts = new Properties();
+    prpts.setProperty("omit-xml-declaration", "yes");
+    String queryResult =xqs.getSequenceAsString(prpts);
+    boolean result = checkResult(test, queryResult);
+    xqc.close();
+    xqc.close();
+    return result;
+  }
+
+} // class Test_Zorba
+

=== added file 'swig/xqj/managers/utf.txt'
--- swig/xqj/managers/utf.txt	1970-01-01 00:00:00 +0000
+++ swig/xqj/managers/utf.txt	2012-09-07 20:02:32 +0000
@@ -0,0 +1,1 @@
+abcdefghijklmnopqrstuvwxyz ñÑuD407áéíó´súiïöठ学퐇ﺔﺖﺚﻀﺺﮚ
\ No newline at end of file

=== modified file 'swig/xqj/tck/xqj_test.bat.in'
--- swig/xqj/tck/xqj_test.bat.in	2012-08-30 13:45:43 +0000
+++ swig/xqj/tck/xqj_test.bat.in	2012-09-07 20:02:32 +0000
@@ -18,6 +18,7 @@
 SET JAVA_LOAD_PATH=@JAVA_LOAD_PATH@
 SET XQJ_LOAD_PATH=@XQJ_LOAD_PATH@
 SET PATH=%PATH%;@XQJ_LOAD_PATH@;@JAVA_DLL_PATH@;@ZORBA_SIMPLE_STORE@;
+SET JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
 
 ECHO "xqj_test.bat: Deleting old Java API if found..."
 RD /S /Q "%XQJ_LOAD_PATH%\tck\org"
@@ -42,7 +43,7 @@
 RD /S /Q "%XQJ_LOAD_PATH%\tck\org"
 
 ECHO "xqj_test.bat: Compiling Managers Tests..."
-"@Java_JAVAC_EXECUTABLE@" -source 1.6 -target 1.6 -cp tck\xqjapi.jar;tck\zorba_api.jar;tck\zorba_xqj.jar -d managers "managers\Api_test.java"
+"@Java_JAVAC_EXECUTABLE@" -source 1.6 -target 1.6 -cp tck\xqjapi.jar;tck\zorba_api.jar;tck\zorba_xqj.jar -d managers "managers\*.java"
 
 ECHO "xqj_test.bat: Executing XQJ TCK ..."
 "@Java_JAVA_EXECUTABLE@" -cp tck\xqjapi.jar;tck\xqjtck.jar;tck\junit-4.9.jar;tck\zorba_api.jar;tck\zorba_xqj.jar -Dcom.oracle.xqj.tck.datasource=tck\zorba.properties com.oracle.xqj.tck.AllTests

=== modified file 'swig/xqj/tck/xqj_test.sh.in'
--- swig/xqj/tck/xqj_test.sh.in	2012-08-30 13:45:43 +0000
+++ swig/xqj/tck/xqj_test.sh.in	2012-09-07 20:02:32 +0000
@@ -24,6 +24,7 @@
 export CLASSPATH="tck:$XQJ_LOAD_PATH"
 CURRENT_D=$PWD
 cd $XQJ_LOAD_PATH
+export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
 
 echo "xqj_test.sh: Deleting old Java API if found..."
 if [ -d "$XQJ_LOAD_PATH/tck/org" ]
@@ -55,7 +56,7 @@
 rm -r "$XQJ_LOAD_PATH/tck/org"
 
 echo "xqj_test.sh: Compiling Managers Tests..."
-"@Java_JAVAC_EXECUTABLE@" -source 1.6 -target 1.6 -cp tck/xqjapi.jar:tck/zorba_api.jar:tck/zorba_xqj.jar -d managers "managers/Api_test.java"
+"@Java_JAVAC_EXECUTABLE@" -source 1.6 -target 1.6 -cp tck/xqjapi.jar:tck/zorba_api.jar:tck/zorba_xqj.jar -Dfile.encoding=UTF8 -d managers "managers/*.java"
 
 echo "java_test.sh: Executing XQJ TCK ..."
 "@Java_JAVA_EXECUTABLE@" -cp tck/xqjapi.jar:tck/xqjtck.jar:tck/junit-4.9.jar:tck/zorba_api.jar:tck/zorba_xqj.jar -Dcom.oracle.xqj.tck.datasource=tck/zorba.properties com.oracle.xqj.tck.AllTests

=== modified file 'swig/zorba_api.i'
--- swig/zorba_api.i	2012-08-30 13:45:43 +0000
+++ swig/zorba_api.i	2012-09-07 20:02:32 +0000
@@ -18,11 +18,14 @@
 %module(directors="1") zorba_api
 
 
-TSRMLS_FETCH(); 
+TSRMLS_FETCH();
 
-%include "std_string.i"
+//%include "std_string.i"
 %include "std_pair.i"
 %include "exception.i"
+%include "carrays.i"
+%apply (char *STRING, size_t LENGTH) { (const char aStream[], size_t aLen) }
+%rename(opEquals) operator=;
 
 #ifndef SWIGRUBY
 %include "std_vector.i"
@@ -54,6 +57,7 @@
 
 %{  // Implementations
 
+#include "Config.h"
 
 #include <string>
 #include <sstream>
@@ -86,6 +90,8 @@
   class Store;
   class InMemoryStore;
 
+  #include "ZorbaIOStream.h"
+  #include "ZorbaStreamBuffer.h"
   #include "SerializationOptions.h"
   #include "TypeIdentifier.h"
   #include "Item.h"
@@ -114,7 +120,8 @@
 
 /* %include "various.i" required for mapping to Java byte[]*/
 
-//%include "ZorbaStreamProxy.i"
+%include "ZorbaIOStream.i"
+%include "ZorbaStreamBuffer.i"
 %include "SerializationOptions.i"
 %include "TypeIdentifier.i"
 %include "Item.i"


Follow ups