← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug-1158052 into lp:zorba

 

Paul J. Lucas has proposed merging lp:~zorba-coders/zorba/bug-1158052 into lp:zorba.

Commit message:
Cleaned up both public and internal API.

Requested reviews:
  Paul J. Lucas (paul-lucas)
Related bugs:
  Bug #1158052 in Zorba: "createBase64Binary() API too subtle"
  https://bugs.launchpad.net/zorba/+bug/1158052

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1158052/+merge/170725

Cleaned up both public and internal API.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1158052/+merge/170725
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'ChangeLog'
--- ChangeLog	2013-06-20 12:00:37 +0000
+++ ChangeLog	2013-06-21 01:08:30 +0000
@@ -29,10 +29,11 @@
   * Fixed bug #1190261 (relative paths bug in file module)
   * Fixed bug #1187537 (Eliminate (or at least reduce) use of MAX_PATH)
   * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
+  * Fixed bug #1158052 (createBase64Binary() API too subtle)
   * Fixed bug #1103115 (Timezone units as hours are wrong)
   * Fixed bug #1188280 (casting xs:id to xs:ncname)
   * Fixed bug in casting to xs:NCName
-  * Check that namespace uri used in default namespace declaration is a valid one
+  * Check that the namespace URI used in default namespace declaration is valid
   * Fixed bug in error conditions for computed PI constructor
   * Fixed implementation of fn:deep-equal according to latest W3C spec.
   * Must apply document ordering on the domain expression of a FOR clause, if

=== modified file 'include/zorba/item_factory.h'
--- include/zorba/item_factory.h	2013-06-18 23:53:59 +0000
+++ include/zorba/item_factory.h	2013-06-21 01:08:30 +0000
@@ -141,32 +141,26 @@
       /** \brief Creates a Base64Binary Item
        *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
        *
-       * @param aBinData a pointer to the base64 encoded data. The data is copied from aBinData.
-       * @param aLength the length of the base64 encoded data.
+       * @param aData a pointer to the data.
+       * @param aLength the length of the data (in bytes).
+       * @param aIsBase64 If \c true, \a aBinData is already Base-64 encoded;
+       * if \c false, \a aBinData is binary data that will first be Base-64
+       * encoded.
        * @return The Base64Binary Item.
        */
       virtual Item
-      createBase64Binary(const char* aBinData, size_t aLength) = 0;
+      createBase64Binary(const char* aData, size_t aLength, bool aIsBase64) = 0;
 
       /** \brief Creates a Base64Binary Item
        *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
        *
-       * @param aStream A stream containing the Base64 encoded data. The data is copied from aStream imediately.
+       * @param aStream A stream containing the Base64 encoded data.
+       * The data is copied from aStream immediately.
        * @return the Base64Binary Item.
        */
       virtual Item
       createBase64Binary(std::istream& aStream) = 0;
 
-      /** \brief Creates a Base64Binary Item
-       *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
-       *
-       * @param aBinData the data in binary form (not encoded). The data is copied from aBinData.
-       * @param aLength the length of the binary data
-       * @return the Base64Binary Item.
-       */
-      virtual Item
-      createBase64Binary(const unsigned char* aBinData, size_t aLength) = 0;
-
       /** \brief Creates a streamable Base64Binary Item
        *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
        *

=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp'
--- modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp	2013-06-12 04:55:14 +0000
+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp	2013-06-21 01:08:30 +0000
@@ -329,7 +329,7 @@
     // changed. This required a Base64 encoding stream since the item factory
     // work only builds base64binary and assumes the data is already encoded.
     String lEncoded = base64::encode(aStream);
-    return lFactory->createBase64Binary(lEncoded.data(), lEncoded.size());
+    return lFactory->createBase64Binary(lEncoded.data(), lEncoded.size(), true);
   }
 
   zorba::Item HttpResponseParser::createXmlItem( std::istream& aStream )

=== modified file 'src/api/itemfactoryimpl.cpp'
--- src/api/itemfactoryimpl.cpp	2013-06-18 23:53:59 +0000
+++ src/api/itemfactoryimpl.cpp	2013-06-21 01:08:30 +0000
@@ -1,12 +1,12 @@
 /*
  * 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.
@@ -45,25 +45,25 @@
 
 
 namespace zorba {
-  
+
 ItemFactoryImpl::ItemFactoryImpl()
 {
   theItemFactory = GENV_ITEMFACTORY;
 }
 
 
-ItemFactoryImpl::~ItemFactoryImpl() 
+ItemFactoryImpl::~ItemFactoryImpl()
 {
 }
 
 
 Item ItemFactoryImpl::createString(const String& aString)
 {
-  zstring lString = Unmarshaller::getInternalString(aString);  
+  zstring lString = Unmarshaller::getInternalString(aString);
   store::Item_t lItem;
-  
+
   theItemFactory->createString(lItem, lString);
-  
+
   return &*lItem;
 }
 
@@ -94,14 +94,14 @@
 Item ItemFactoryImpl::createAnyURI(const String& aURI)
 {
   zstring lString = Unmarshaller::getInternalString(aURI);
-  
+
   store::Item_t lItem;
   theItemFactory->createAnyURI(lItem, lString);
-  
+
   return &*lItem;
 }
 
-  
+
 Item ItemFactoryImpl::createDate( const String& aDateValue )
 {
   zstring const &lString = Unmarshaller::getInternalString( aDateValue );
@@ -133,19 +133,19 @@
   zstring const &lNamespace = Unmarshaller::getInternalString( aNamespace );
   zstring const &lPrefix = Unmarshaller::getInternalString( aPrefix );
   zstring const &lLocalname = Unmarshaller::getInternalString( aLocalname );
-  
+
   if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
   {
-    RAISE_ERROR_NO_LOC(err::FORG0001, 
+    RAISE_ERROR_NO_LOC(err::FORG0001,
     ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
   }
 
   if (lPrefix.size() && !GenericCast::instance()->castableToNCName(lPrefix.c_str()))
   {
-    RAISE_ERROR_NO_LOC(err::FORG0001, 
+    RAISE_ERROR_NO_LOC(err::FORG0001,
     ERROR_PARAMS(ZED(FORG0001_PrefixNotNCName_2), lPrefix));
   }
-  
+
   store::Item_t lItem;
   theItemFactory->createQName(lItem, lNamespace, lPrefix, lLocalname);
   return &*lItem;
@@ -161,15 +161,15 @@
 
   if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
   {
-    RAISE_ERROR_NO_LOC(err::FORG0001, 
+    RAISE_ERROR_NO_LOC(err::FORG0001,
     ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
   }
-  
+
   store::Item_t lItem;
   theItemFactory->createQName(lItem, lNamespace, zstring(), lLocalname);
   return &*lItem;
 }
-  
+
 
 Item
 ItemFactoryImpl::createQName(const String& aQNameString)
@@ -180,7 +180,7 @@
   size_t lOpen  = lQNameString.find("{");
   size_t lClose = lQNameString.find("}");
 
-  if (lOpen == 0 && lClose != std::string::npos) 
+  if (lOpen == 0 && lClose != std::string::npos)
   {
     zstring const &lNamespace = lQNameString.substr(1, lClose - 1);
     zstring const &lLocalname = lQNameString.substr(lClose+1);
@@ -188,7 +188,7 @@
 
     if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
     {
-      RAISE_ERROR_NO_LOC(err::FORG0001, 
+      RAISE_ERROR_NO_LOC(err::FORG0001,
       ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
     }
   }
@@ -205,45 +205,35 @@
     RAISE_ERROR_NO_LOC(err::FORG0001,
     ERROR_PARAMS(ZED(FORG0001_NameNotNCName_2), lString));
   }
-  
+
   store::Item_t lItem;
   theItemFactory->createNCName(lItem, lString);
   return &*lItem;
 }
 
-    
-Item ItemFactoryImpl::createBase64Binary(const char* aBinData, size_t aLength)
-{
-  store::Item_t lItem;
-  xs_base64Binary n;
-  std::string lMessage;
-  if (xs_base64Binary::parseString(aBinData, aLength, n, lMessage))
-  {
-    theItemFactory->createBase64Binary(lItem, n);
-  }
-  else
-  {
-    throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR, ERROR_PARAMS(lMessage));
-  }
-  return &*lItem;
-}
-
-
-Item ItemFactoryImpl::createBase64Binary(const unsigned char* aBinData, size_t aLength)
-{
-  store::Item_t lItem;
-  xs_base64Binary n;
-  std::string lMessage;
-  xs_base64Binary::encode(aBinData, aLength, n);
-  theItemFactory->createBase64Binary(lItem, n);
-  return &*lItem;
+
+Item ItemFactoryImpl::createBase64Binary(const char* aData, size_t aLength,
+                                         bool aIsBase64)
+{
+  try {
+    store::Item_t result;
+    xs_base64Binary b64( aData, aLength, aIsBase64 );
+    theItemFactory->createBase64Binary( result, b64 );
+    return &*result;
+  }
+  catch ( std::exception const &e ) {
+    throw ZORBA_EXCEPTION(
+      zerr::ZSTR0040_TYPE_ERROR, ERROR_PARAMS( e.what() )
+    );
+  }
 }
 
 
 Item ItemFactoryImpl::createBase64Binary(std::istream& aEncodedStream)
 {
+  // TODO: this code sucks
   std::stringstream lSs;
-  while (aEncodedStream.good()) 
+  while (aEncodedStream.good())
   {
     char c = aEncodedStream.get();
     if (aEncodedStream.good())
@@ -252,7 +242,7 @@
     }
   }
   std::string lContent = lSs.str();
-  return createBase64Binary(lContent.c_str(), lContent.size());
+  return createBase64Binary(lContent.c_str(), lContent.size(), true);
 }
 
 
@@ -265,8 +255,8 @@
 {
   store::Item_t lItem;
   theItemFactory->createStreamableBase64Binary(
-      lItem, stream, streamReleaser, seekable, encoded
-    );
+    lItem, stream, streamReleaser, seekable, encoded
+  );
   return &*lItem;
 }
 
@@ -281,8 +271,8 @@
 {
   store::Item_t lItem;
   theItemFactory->createStreamableBase64Binary(
-      lItem, stream, streamReleaser, uri, seekable, encoded
-    );
+    lItem, stream, streamReleaser, uri, seekable, encoded
+  );
   return &*lItem;
 }
 
@@ -293,8 +283,8 @@
   theItemFactory->createBoolean(lItem, aValue);
   return &*lItem;
 }
-    
-  
+
+
 Item ItemFactoryImpl::createDecimalFromLong (unsigned long aValue)
 {
   store::Item_t lItem;
@@ -302,8 +292,8 @@
   theItemFactory->createDecimal(lItem, lDecimal);
   return &*lItem;
 }
-    
-    
+
+
 Item ItemFactoryImpl::createDecimalFromDouble (double aValue)
 {
   store::Item_t lItem;
@@ -357,7 +347,7 @@
   }
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createLong ( long long aLong )
 {
@@ -366,7 +356,7 @@
   theItemFactory->createLong(lItem, aLong);
   return &*lItem;
 }
-    
+
 
 Item ItemFactoryImpl::createInt ( int aInt )
 {
@@ -378,7 +368,7 @@
 
   return &*lItem;
 }
-    
+
 
 Item ItemFactoryImpl::createShort ( short aShort )
 {
@@ -388,8 +378,8 @@
 
   return &*lItem;
 }
-    
-  
+
+
 Item ItemFactoryImpl::createByte ( char aValue )
 {
   store::Item_t lItem;
@@ -398,8 +388,8 @@
 
   return &*lItem;
 }
-    
-  
+
+
 Item ItemFactoryImpl::createDateTime(short aYear, short aMonth, short aDay,
                                   short aHour, short aMinute, double aSecond,
                                   int aTimezone)
@@ -468,7 +458,7 @@
   return &*lItem;
 }
 
-  
+
 Item ItemFactoryImpl::createDouble ( const String& aValue )
 {
   zstring lString = Unmarshaller::getInternalString( aValue );
@@ -498,17 +488,17 @@
 Item ItemFactoryImpl::createDuration(
     short aYears,
     short aMonths,
-    short aDays, 
+    short aDays,
     short aHours,
     short aMinutes,
     double aSeconds )
 {
   store::Item_t lItem;
-  
+
   theItemFactory->createDuration(lItem,
                                  aYears, aMonths, aDays,
                                  aHours, aMinutes, aSeconds);
-  
+
   return &*lItem;
 }
 
@@ -551,7 +541,7 @@
   try {
     xs_float const lFloat(lString);
     theItemFactory->createFloat(lItem, lFloat);
-  } 
+  }
   catch ( std::exception const& ) {
     // ignore
   }
@@ -567,7 +557,7 @@
   return &*lItem;
 }
 
-  
+
 Item ItemFactoryImpl::createHexBinary( const char* aHexData, size_t aSize,
                                        bool aIsEncoded )
 {
@@ -586,7 +576,7 @@
   }
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createNonNegativeInteger ( unsigned long long aValue )
 {
@@ -623,41 +613,41 @@
   store::Item_t lItem;
 
   theItemFactory->createGDay(lItem,  lString.c_str(), lString.size());
-  
+
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createGDay ( short aDay )
 {
   store::Item_t lItem;
 
   theItemFactory->createGDay(lItem,  aDay );
-  
+
   return &*lItem;
 }
-  
-  
+
+
 Item ItemFactoryImpl::createGMonth ( short aMonth )
 {
   store::Item_t lItem;
 
   theItemFactory->createGMonth(lItem,  aMonth );
-  
+
   return &*lItem;
 }
 
-  
+
 Item ItemFactoryImpl::createGMonth ( const String& aValue )
 {
   zstring lString = Unmarshaller::getInternalString(aValue);
   store::Item_t lItem;
-  
+
   theItemFactory->createGMonth(lItem,  lString.c_str(), lString.size());
-  
+
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createGMonthDay(const String& aValue)
 {
@@ -665,7 +655,7 @@
   store::Item_t lItem;
 
   theItemFactory->createGMonthDay(lItem,  lString.c_str(), lString.size());
-  
+
   return &*lItem;
 }
 
@@ -675,10 +665,10 @@
   store::Item_t lItem;
 
   theItemFactory->createGMonthDay(lItem,  aMonth, aDay );
-  
+
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createGYear(const String& aValue)
 {
@@ -686,7 +676,7 @@
   store::Item_t lItem;
 
   theItemFactory->createGYear(lItem,  lString.c_str(), lString.size() );
-  
+
   return &*lItem;
 }
 
@@ -696,10 +686,10 @@
   store::Item_t lItem;
 
   theItemFactory->createGYear(lItem,  aYear );
-  
+
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createGYearMonth ( const String& aValue )
 {
@@ -707,17 +697,17 @@
   store::Item_t lItem;
 
   theItemFactory->createGYearMonth(lItem, lString.c_str(), lString.size());
-  
+
   return &*lItem;
 }
 
-  
+
 Item ItemFactoryImpl::createGYearMonth ( short aYear, short aMonth )
 {
   store::Item_t lItem;
 
   theItemFactory->createGYearMonth(lItem,  aYear, aMonth );
-  
+
   return &*lItem;
 }
 
@@ -728,17 +718,17 @@
   store::Item_t lItem;
 
   theItemFactory->createTime(lItem,  lString.c_str(), lString.size() );
-  
+
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createTime ( short aHour, short aMinute, double aSecond )
 {
   store::Item_t lItem;
 
   theItemFactory->createTime(lItem,  aHour, aMinute, aSecond );
-  
+
   return &*lItem;
 }
 
@@ -753,7 +743,7 @@
   theItemFactory->createTime(lItem,  aHour, aMinute, aSecond, aTimezone );
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createUnsignedByte(const unsigned char aValue)
 {
@@ -761,19 +751,19 @@
   theItemFactory->createUnsignedByte(lItem, aValue);
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createUnsignedInt(unsigned int aValue)
 {
   store::Item_t lItem;
-  
+
   if ( aValue <= UINT32_MAX ) {
     theItemFactory->createUnsignedInt(lItem, aValue);
   }
 
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createUnsignedLong(unsigned long long aValue)
 {
@@ -781,7 +771,7 @@
   theItemFactory->createUnsignedLong(lItem, aValue);
   return &*lItem;
 }
-  
+
 
 Item ItemFactoryImpl::createUnsignedShort(unsigned short aValue)
 {
@@ -973,7 +963,7 @@
 
   std::vector<std::pair<Item, Item> >::iterator i = aPairs.begin();
   std::vector<std::pair<Item, Item> >::iterator end = aPairs.end();
-  for (; i != end; i++) 
+  for (; i != end; i++)
   {
     names.push_back(Unmarshaller::getInternalItem((*i).first));
     values.push_back(Unmarshaller::getInternalItem((*i).second));
@@ -1001,7 +991,7 @@
   items.reserve(numItems);
   std::vector<Item>::iterator ite = aItems.begin();
   std::vector<Item>::iterator end = aItems.end();
-  for (; ite != end; ++ite) 
+  for (; ite != end; ++ite)
   {
     items.push_back(Unmarshaller::getInternalItem(*ite));
   }

=== modified file 'src/api/itemfactoryimpl.h'
--- src/api/itemfactoryimpl.h	2013-06-18 23:53:59 +0000
+++ src/api/itemfactoryimpl.h	2013-06-21 01:08:30 +0000
@@ -67,14 +67,11 @@
       createNCName(const String& aValue);
     
       virtual Item 
-      createBase64Binary(const char* aBinData, size_t aLength);
+      createBase64Binary(const char* aBinData, size_t aLength, bool aIsBase64);
 
       virtual Item
       createBase64Binary(std::istream& aStream);
       
-      virtual Item 
-      createBase64Binary(const unsigned char* aBinData, size_t aLength);
-
       virtual Item
       createStreamableBase64Binary(
           std::istream &stream,

=== modified file 'src/store/naive/atomic_items.cpp'
--- src/store/naive/atomic_items.cpp	2013-06-18 23:53:59 +0000
+++ src/store/naive/atomic_items.cpp	2013-06-21 01:08:30 +0000
@@ -45,6 +45,7 @@
 #include "tree_id.h"
 
 #include "util/ascii_util.h"
+#include "util/base64_util.h"
 #include "util/mem_sizeof.h"
 #include "util/string_util.h"
 #include "util/utf8_util.h"
@@ -3516,8 +3517,7 @@
   else
   {
     std::vector<char> encoded;
-    encoded.reserve(theValue.size());
-    Base64::encode(theValue, encoded);
+    base64::encode( &theValue[0], theValue.size(), &encoded );
     buf.insert(buf.size(), &encoded[0], encoded.size());
   }
 }
@@ -3778,7 +3778,7 @@
     buf.insert(buf.size(), &theValue[0], theValue.size());
   else
   {
-    std::vector<char> encoded;
+    Base16::value_type encoded;
     Base16::encode(theValue, encoded);
     buf.insert(buf.size(), &encoded[0], encoded.size());
   }

=== modified file 'src/store/naive/simple_item_factory.cpp'
--- src/store/naive/simple_item_factory.cpp	2013-06-18 23:53:59 +0000
+++ src/store/naive/simple_item_factory.cpp	2013-06-21 01:08:30 +0000
@@ -1128,7 +1128,7 @@
     store::Item_t& result,
     xs_base64Binary const &value)
 {
-  const std::vector<char>& data = value.getData();
+  const std::vector<char>& data = value.data();
   result = new Base64BinaryItem(store::XS_BASE64BINARY,
                                 data.size() != 0 ? &data[0] : 0,
                                 data.size(),
@@ -1184,7 +1184,7 @@
 bool BasicItemFactory::createHexBinary(store::Item_t& result,
                                        xs_hexBinary const &value)
 {
-  std::vector<char> const &data = value.getData();
+  std::vector<char> const &data = value.data();
   result = new HexBinaryItem(
     store::XS_HEXBINARY, data.empty() ? 0 : &data[0], data.size(), true
   );

=== modified file 'src/types/casting.cpp'
--- src/types/casting.cpp	2013-06-19 22:18:54 +0000
+++ src/types/casting.cpp	2013-06-21 01:08:30 +0000
@@ -1539,12 +1539,8 @@
 T1_TO_T2(b64, hxB)
 {
   size_t s;
-  const char* c = aItem->getBase64BinaryValue(s);
-  xs_base64Binary tmp;
-  if (aItem->isEncoded())
-    xs_base64Binary::parseString(c, s, tmp);
-  else
-    xs_base64Binary::encode(c, s, tmp);
+  char const *const c = aItem->getBase64BinaryValue(s);
+  xs_base64Binary tmp( c, s, aItem->isEncoded() );
   aFactory->createHexBinary(result, xs_hexBinary(tmp));
 }
 
@@ -1567,11 +1563,7 @@
 {
   size_t s;
   char const *const c = aItem->getHexBinaryValue(s);
-  xs_hexBinary tmp;
-  if (aItem->isEncoded())
-    xs_hexBinary::parseString(c, s, tmp);
-  else
-    xs_hexBinary::encode(c, s, tmp);
+  xs_hexBinary tmp( c, s, aItem->isEncoded() );
   aFactory->createBase64Binary(result, xs_base64Binary(tmp));
 }
 

=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
--- src/zorbaserialization/serialize_zorba_types.cpp	2013-06-15 02:57:08 +0000
+++ src/zorbaserialization/serialize_zorba_types.cpp	2013-06-21 01:08:30 +0000
@@ -160,7 +160,7 @@
 ********************************************************************************/
 void operator&(Archiver& ar, Base64& obj)
 {
-  ar & obj.theData;
+  ar & obj.data_;
 }
 
 
@@ -169,7 +169,7 @@
 ********************************************************************************/
 void operator&(Archiver& ar, Base16& obj)
 {
-  ar & obj.theData;
+  ar & obj.data_;
 }
 
 
@@ -722,18 +722,8 @@
 
     size_t s;
     const char* c = obj->getHexBinaryValue(s);
-    if (obj->isEncoded())
-    {
-      Base16 tmp;
-      Base16::parseString(c, s, tmp);
-      ar & tmp;
-    }
-    else
-    {
-      Base16 tmp(c, s);
-      ar & tmp;
-    }
-    
+    Base16 tmp( c, s, obj->isEncoded() );
+    ar & tmp;
     ar.set_is_temp_field(false);
 
     break;
@@ -744,18 +734,8 @@
 
     size_t s;
     const char* c = obj->getBase64BinaryValue(s);
-    if (obj->isEncoded())
-    {
-      Base64 tmp;
-      Base64::parseString(c, s, tmp);
-      ar & tmp;
-    }
-    else
-    {
-      Base64 tmp(c, s);
-      ar & tmp;
-    }
-    
+    Base64 tmp( c, s, obj->isEncoded() );
+    ar & tmp;
     ar.set_is_temp_field(false);
 
     break;

=== modified file 'src/zorbatypes/binary.cpp'
--- src/zorbatypes/binary.cpp	2013-05-08 01:05:04 +0000
+++ src/zorbatypes/binary.cpp	2013-06-21 01:08:30 +0000
@@ -36,18 +36,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-#define CATCH_BASE64_EXCEPTION()                                        \
-  catch (const base64::exception& e)                                    \
-  {                                                                     \
-    throw XQUERY_EXCEPTION(err::FORG0001,                               \
-    ERROR_PARAMS(ZED(FORG0001_Base64BadChar_2), e.invalid_char()));     \
-  }                                                                     \
-  catch (const std::invalid_argument&)                                  \
-  {                                                                     \
-    throw XQUERY_EXCEPTION(err::FORG0001,                               \
-    ERROR_PARAMS(ZED(FORG0001_Base64Multiple4)));                       \
-  }
-
 static size_t copy_without_ws( char const *from, size_t from_len, char *to ) {
   char const *const to_orig = to;
   for ( char const *const from_end = from + from_len; from < from_end; ++from )
@@ -56,106 +44,26 @@
   return to - to_orig;
 }
 
-
-bool Base64::parseString(char const *s, size_t len, Base64& aBase64)
-{
-  if ( len ) {
-    try 
-    {
-      base64::validate( s, len, base64::dopt_ignore_ws );
-      aBase64.theData.resize( len );
-      aBase64.theData.resize(
-        copy_without_ws( s, len, &aBase64.theData[0] )
-      );
-    }
-    catch (...) 
-    {
-      return false;
-    }
-  } else
-    aBase64.theData.clear();
-  return true;
-}
-
-
-bool Base64::parseString( char const *s, size_t len, Base64 &aBase64, 
-                          string &lErrorMessage )
-{
-  if ( len ) {
-    try 
-    {
-      base64::validate( s, len, base64::dopt_ignore_ws );
-      aBase64.theData.resize( len );
-      aBase64.theData.resize(
-        copy_without_ws( s, len, &aBase64.theData[0] )
-      );
-    }
-    catch (ZorbaException const& e) 
-    {
-      lErrorMessage = e.what();
-      return false;
-    }
-  } else
-    aBase64.theData.clear();
-  return true;
-}
-
-
-void Base64::encode( zstring const &s, Base64 &to )
-{
-  base64::encode( s.data(), s.size(), &to.theData );
-}
-
-
-void Base64::encode( istream &is, Base64 &to )
-{
-  base64::encode( is, &to.theData );
-}
-
-
-zstring Base64::encode( istream &is )
-{
-  zstring result;
-  base64::encode( is, &result );
-  return result;
-}
-
-
-void Base64::encode( vector<char> const &from, vector<char> &to )
-{
-  if ( !from.empty() )
-    base64::encode( &from[0], from.size(), &to );
-}
-
-
-void Base64::encode( char const *from, size_t from_len, Base64 &to )
-{
-  base64::encode( from, from_len, &to.theData );
-}
-
-
-void Base64::decode( istream &is, zstring *to )
-{
+///////////////////////////////////////////////////////////////////////////////
+
+#define CATCH_BASE64_EXCEPTION()                                        \
+  catch ( base64::exception const &e ) {                                \
+    throw XQUERY_EXCEPTION( err::FORG0001,                              \
+    ERROR_PARAMS( ZED(FORG0001_Base64BadChar_2), e.invalid_char() ) );  \
+  }                                                                     \
+  catch ( std::invalid_argument const& ) {                              \
+    throw XQUERY_EXCEPTION( err::FORG0001,                              \
+    ERROR_PARAMS( ZED(FORG0001_Base64Multiple4) ) );                    \
+  }
+
+void Base64::decode( istream &is, zstring *to ) {
   try {
     base64::decode( is, to, base64::dopt_any_len | base64::dopt_ignore_ws );
   }
   CATCH_BASE64_EXCEPTION()
 }
 
-void Base64::decode(vector<char> const &from, vector<char> &to )
-{
-  if ( !from.empty() ) {
-    try {
-      base64::decode(
-        &from[0], from.size(), &to,
-        base64::dopt_any_len | base64::dopt_ignore_ws
-      );
-    }
-    CATCH_BASE64_EXCEPTION()
-  }
-}
-
-void Base64::decode( char const *from, size_t from_len, zstring *to ) {
+void Base64::decode( char const *from, size_type from_len, zstring *to ) {
   try {
     base64::decode(
       from, from_len, to, base64::dopt_any_len | base64::dopt_ignore_ws
@@ -164,150 +72,96 @@
   CATCH_BASE64_EXCEPTION()
 }
 
-
-Base64::Base64( Base16 const &aBase16 )
-{
-  vector<char> tmp;
-  Base16::decode( aBase16.getData(), tmp );
-  Base64::encode( tmp, theData );
+Base64::Base64( Base16 const &b16 ) {
+  value_type tmp;
+  hexbinary::decode( &b16.data()[0], b16.size(), &tmp );
+  base64::encode( &tmp[0], tmp.size(), &data_ );
 }
 
-
-Base64::Base64( char const *bin_data, size_t len )
-{
+Base64& Base64::assign( char const *data, size_type size, bool is_encoded ) {
   try {
-    base64::encode( bin_data, len, &theData );
+    if ( is_encoded ) {
+      base64::validate( data, size, base64::dopt_ignore_ws );
+      data_.resize( size );
+      data_.resize( copy_without_ws( data, size, &data_[0] ) );
+    } else
+      base64::encode( data, size, &data_ );
+    return *this;
   }
   CATCH_BASE64_EXCEPTION()
 }
 
-
-
-bool Base64::equal( Base64 const &aBase64 ) const
-{
-  if ( size() != aBase64.size() )
-    return false;
-  return ::strncmp( &theData[0], &aBase64.theData[0], size() ) == 0;
-}
-
-
-zstring Base64::str() const 
-{
-  zstring result;
-  if ( theData.size() )
-    result.assign( &theData[0], theData.size() );
-  return result;
-}
-
-
-zstring Base64::decode() const
-{
-  zstring result;
-  if ( !theData.empty() )
-    base64::decode( &theData[0], theData.size(), &result );
-  return result;
-}
-
-
-void Base64::decode( vector<char> &to )
-{
-  if ( !theData.empty() )
-    base64::decode( &theData[0], theData.size(), &to );
-}
-
-
-uint32_t Base64::hash() const
-{
-  return theData.size() ? ztd::hash_bytes( &theData[0], theData.size() ) : 0;
-}
-
-
-ostream& operator<<(ostream& os, const Base64& aBase64)
-{
-  if ( aBase64.size() )
-    os.write( &aBase64.getData()[0], aBase64.size() );
-  return os;
+uint32_t Base64::hash() const {
+  return data_.size() ? ztd::hash_bytes( &data_[0], data_.size() ) : 0;
+}
+
+bool Base64::parseString( char const *s, size_type size, Base64 &b64 ) {
+  if ( size ) {
+    try {
+      base64::validate( s, size, base64::dopt_ignore_ws );
+      b64.data_.resize( size );
+      b64.data_.resize( copy_without_ws( s, size, &b64.data_[0] ) );
+    }
+    catch ( std::exception const& ) {
+      return false;
+    }
+  } else
+    b64.data_.clear();
+  return true;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
 #define CATCH_HEXBINARY_EXCEPTION()                                     \
-  catch (const hexbinary::exception& e)                                 \
-  {                                                                     \
-    throw XQUERY_EXCEPTION(err::FORG0001,                               \
-    ERROR_PARAMS(ZED(FORG0001_BadHexDigit_2), e.invalid_char()));       \
+  catch ( hexbinary::exception const &e ) {                             \
+    throw XQUERY_EXCEPTION( err::FORG0001,                              \
+    ERROR_PARAMS( ZED(FORG0001_BadHexDigit_2), e.invalid_char() ) );    \
   }                                                                     \
-  catch (const std::invalid_argument&)                                  \
-  {                                                                     \
-    throw XQUERY_EXCEPTION(err::FORG0001,                               \
-    ERROR_PARAMS(ZED(FORG0001_HexBinaryMustBeEven)));                   \
-  }
-
-Base16::Base16( char const *bin_data, size_t len )
-{
-  try {
-    hexbinary::encode( bin_data, len, &theData );
-  }
-  CATCH_HEXBINARY_EXCEPTION()
-}
-
-Base16::Base16(Base64 const &aBase64)
-{
-  vector<char> lOrig;
-  Base64::decode(aBase64.getData(), lOrig);
-  Base16::encode(lOrig, theData);
-}
-
-
-bool Base16::parseString(char const *s, size_t len, Base16& aBase16)
-{
-  if ( len ) {
-    try 
-    {
-      hexbinary::validate( s, len, hexbinary::dopt_ignore_ws );
-      aBase16.theData.resize( len );
-      aBase16.theData.resize(
-        copy_without_ws( s, len, &aBase16.theData[0] )
-      );
-    }
-    catch (...)
-    {
+  catch ( std::invalid_argument const& ) {                              \
+    throw XQUERY_EXCEPTION( err::FORG0001,                              \
+    ERROR_PARAMS(ZED(FORG0001_HexBinaryMustBeEven) ) );                 \
+  }
+
+Base16::Base16( Base64 const &b64 ) {
+  value_type temp;
+  base64::decode( &b64.data()[0], b64.size(), &temp );
+  assign( &temp[0], temp.size(), false );
+}
+
+Base16& Base16::assign( char const *data, size_type size, bool is_encoded ) {
+  if ( !size )
+    data_.clear();
+  else {
+    try {
+      if ( is_encoded ) {
+        hexbinary::validate( data, size, hexbinary::dopt_ignore_ws );
+        data_.resize( size );
+        data_.resize( copy_without_ws( data, size, &data_[0] ) );
+      } else
+        hexbinary::encode( data, size, &data_ );
+    }
+    CATCH_HEXBINARY_EXCEPTION()
+  }
+  return *this;
+}
+
+bool Base16::parseString( char const *data, size_type size, Base16 &b16 ) {
+  if ( !size )
+    b16.data_.clear();
+  else {
+    try {
+      hexbinary::validate( data, size, hexbinary::dopt_ignore_ws );
+      b16.data_.resize( size );
+      b16.data_.resize( copy_without_ws( data, size, &b16.data_[0] ) );
+    }
+    catch ( std::exception const& ) {
       return false;
     }
-  } else
-    aBase16.theData.clear();
+  }
   return true;
 }
 
-
-void Base16::insertData(char const *s, size_t len)
-{
-  s = ascii::trim_space( s, &len );
-  try {
-    hexbinary::encode( s, len, &theData );
-  }
-  CATCH_HEXBINARY_EXCEPTION()
-}
-
-
-bool Base16::equal( Base16 const &other ) const
-{
-  if ( size() != other.size() )
-    return false;
-  return ::strncmp( &theData[0], &other.theData[0], theData.size() ) == 0;
-}
-
-
-zstring Base16::str() const 
-{
-  if ( size() )
-    return zstring( &theData[0], size() );
-  return zstring();
-}
-
-
-void Base16::encode( vector<char> const &from, vector<char> &to )
-{
+void Base16::encode( value_type const &from, value_type &to ) {
   if ( !from.empty() ) {
     try {
       hexbinary::encode( &from[0], from.size(), &to );
@@ -316,34 +170,8 @@
   }
 }
 
-void Base16::encode( char const *from, size_t from_len, Base16 &to )
-{
-  hexbinary::encode( from, from_len, &to.theData );
-}
-
-void Base16::decode( vector<char> const &from, vector<char> &to )
-{
-  if ( !from.empty() ) {
-    try {
-      hexbinary::decode(
-        &from[0], from.size(), &to, hexbinary::dopt_ignore_ws
-      );
-    }
-    CATCH_HEXBINARY_EXCEPTION()
-  }
-}
-
-uint32_t Base16::hash() const
-{
-  return theData.size() ? ztd::hash_bytes( &theData[0], theData.size() ) : 0;
-}
-
-
-ostream& operator<<( ostream &os, Base16 const &b16 )
-{
-  if ( b16.size() )
-    os.write( &b16.getData()[0], b16.size() );
-  return os;
+uint32_t Base16::hash() const {
+  return data_.size() ? ztd::hash_bytes( &data_[0], data_.size() ) : 0;
 }
 
 ///////////////////////////////////////////////////////////////////////////////

=== modified file 'src/zorbatypes/binary.h'
--- src/zorbatypes/binary.h	2013-03-17 04:02:46 +0000
+++ src/zorbatypes/binary.h	2013-06-21 01:08:30 +0000
@@ -26,160 +26,170 @@
 
 namespace zorba {
 
-
 class Base16;
 class Base64;
 
-namespace serialization 
-{
+namespace serialization {
   class Archiver;
-  void operator&(Archiver& ar, Base64& obj);
-  void operator&(Archiver& ar, Base16& obj);
+  void operator&( Archiver&, Base64& );
+  void operator&( Archiver&, Base16& );
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class Base64
-{
-  friend void serialization::operator&(serialization::Archiver&, Base64&);
-
-private:
-  std::vector<char> theData;            // stored encoded
-
+class Base64 {
 public:
-  static bool parseString( zstring const &s, Base64 &to )
-  {
+  typedef std::vector<char> value_type;
+  typedef value_type::size_type size_type;
+
+  static bool parseString( char const *data, size_type size, Base64 &to );
+
+  static bool parseString( zstring const &s, Base64 &to ) {
     return parseString( s.data(), s.size(), to );
   }
 
-  static bool parseString(char const *s, size_t aLength, Base64& to);
-
-  static bool parseString(
-        const char* aString, 
-        size_t aLength,
-        Base64& aBase64,
-        std::string& lErrorMessage);
-
-  static zstring encode(std::istream& aStream);
-
-  static void encode(std::istream& aStream, Base64& to);
-
-  static void encode(const zstring& aString, Base64&);
-
-  static void encode(const std::vector<char>&, std::vector<char>&);
-
-  static void encode(char const *from, size_t from_len, Base64 &to);
-
-  static void encode(unsigned char const *from, size_t from_len, Base64& to) {
-    return encode( (char const*)from, from_len, to );
-  }
-
-  static void decode(const std::vector<char>&, std::vector<char>&);
-
-  static void decode(std::istream& aStream, zstring*);
-
-  static void decode(char const*, size_t, zstring*);
+  static void decode( std::istream&, zstring* );
+
+  static void decode( char const*, size_type, zstring* );
 
 public:
-  Base64(const Base64& aBase64) 
-  {
-    theData = aBase64.theData;
-  }
-
-  explicit Base64(const Base16& aBase16);
-
-  Base64(char const *bin_data, size_t len);
-
-  Base64() { }
-
-  const std::vector<char>& getData() const { return theData; }
-
-  size_t size() const { return theData.size(); }
-
-  bool equal(const Base64& aBase64) const;
-
+  Base64();
+  Base64( Base64 const &b64 );
+  Base64( const char *data, size_type size, bool is_encoded );
+  explicit Base64( Base16 const &b16 );
+
+  size_t alloc_size() const;
+  Base64& assign( char const *data, size_type size, bool is_encoded );
+  value_type const& data() const;
+  uint32_t hash() const;
+  size_type size() const;
   zstring str() const;
 
-  zstring decode() const;
-
-  void decode(std::vector<char>&);
-
-  uint32_t hash() const;
-
-  size_t alloc_size() const {
-    return ztd::alloc_sizeof( theData );
-  }
+private:
+  value_type data_;                     // stored encoded
+
+  friend void serialization::operator&( serialization::Archiver&, Base64& );
 };
 
+///////////////////////////////////////////////////////////////////////////////
+
+inline Base64::Base64() {
+}
+
+inline Base64::Base64( Base64 const &b64 ) : data_( b64.data_ ) {
+}
+
+inline Base64::Base64( const char *data, size_type size, bool is_encoded ) {
+  assign( data, size, is_encoded );
+}
+
+inline size_t Base64::alloc_size() const {
+  return ztd::alloc_sizeof( data_ );
+}
+
+inline Base64::value_type const& Base64::data() const {
+  return data_;
+}
+
+inline Base64::size_type Base64::size() const {
+  return data_.size();
+}
+
+inline zstring Base64::str() const {
+  return size() ? zstring( &data_[0], size() ) : zstring();
+}
+
 inline bool operator==( Base64 const &a, Base64 const &b ) {
-  return a.equal( b );
+  return a.size() == b.size()
+      && std::strncmp( &a.data()[0], &b.data()[0], a.size() ) == 0;
 }
 
 inline bool operator!=( Base64 const &a, Base64 const &b ) {
   return !(a == b);
 }
 
-std::ostream& operator<<( std::ostream&, Base64 const& );
+inline std::ostream& operator<<( std::ostream &o, Base64 const &b64 ) {
+  if ( b64.size() )
+    o.write( &b64.data()[0], b64.size() );
+  return o;
+}
 
 ///////////////////////////////////////////////////////////////////////////////
 
-class Base16
-{
+class Base16 {
+public:
+  typedef std::vector<char> value_type;
+  typedef value_type::size_type size_type;
+
+  static bool parseString( char const *data, size_type size, Base16 &to );
+
+  static bool parseString( zstring const &s, Base16 &to ) {
+    return parseString( s.data(), s.size(), to );
+  }
+
+  static void encode( value_type const&, value_type& );
+
+public:
+  Base16();
+  Base16( Base16 const &from );
+  Base16( char const *data, size_type size, bool is_encoded );
+  explicit Base16( Base64 const& );
+  
+  size_t alloc_size() const;
+  Base16& assign( char const *data, size_type size, bool is_encoded );
+  value_type const& data() const;
+  uint32_t hash() const;
+  size_type size() const;
+  zstring str() const;
+
+private:
+  value_type data_;                     // stored encoded
+
   friend void serialization::operator&(serialization::Archiver&, Base16&);
-
-private:
-  std::vector<char> theData;            // stored encoded
-
-public:
-  static bool parseString( zstring const &s, Base16 &to )
-  {
-    return parseString( s.data(), s.size(), to );
-  }
-
-  static bool parseString( char const *from, size_t from_len, Base16 &to );
-
-  static void encode( std::vector<char> const&, std::vector<char>& );
-
-  static void encode( char const *from, size_t from_len, Base16 &to );
-
-  static void decode( std::vector<char> const&, std::vector<char>& );
-
-public:
-  Base16() { }
-  
-  Base16( Base16 const &from ) : theData( from.theData ) { }
-
-  Base16( char const *bin_data, size_t len );
-
-  explicit Base16( Base64 const& );
-  
-  const std::vector<char>& getData() const { return theData; }
-
-  size_t size() const { return theData.size(); }
-
-  bool equal( Base16 const& ) const;
-
-  zstring str() const;
-
-  uint32_t hash() const;
-
-  size_t alloc_size() const {
-    return ztd::alloc_sizeof( theData );
-  }
-
-private:
-  void insertData( char const *from, size_t len );
 };
 
+///////////////////////////////////////////////////////////////////////////////
+
+inline Base16::Base16() {
+}
+
+inline Base16::Base16( Base16 const &b16 ) : data_( b16.data_ ) {
+}
+
+inline Base16::Base16( char const *data, size_type size, bool is_encoded ) {
+  assign( data, size, is_encoded );
+}
+
+inline size_t Base16::alloc_size() const {
+  return ztd::alloc_sizeof( data_ );
+}
+
+inline Base16::value_type const& Base16::data() const {
+  return data_;
+}
+
+inline Base16::size_type Base16::size() const {
+  return data_.size();
+}
+
+inline zstring Base16::str() const {
+  return size() ? zstring( &data_[0], size() ) : zstring();
+}
+
 inline bool operator==( Base16 const &a, Base16 const &b ) {
-  return a.equal( b );
+  return a.size() == b.size()
+      && std::strncmp( &a.data()[0], &b.data()[0], a.size() ) == 0;
 }
 
 inline bool operator!=( Base16 const &a, Base16 const &b ) {
   return !(a == b);
 }
 
-std::ostream& operator<<(std::ostream&s, const Base16& );
+inline std::ostream& operator<<( std::ostream &o, Base16 const &b16 ) {
+  if ( b16.size() )
+    o.write( &b16.data()[0], b16.size() );
+  return o;
+}
 
 ///////////////////////////////////////////////////////////////////////////////
 

=== modified file 'swig/ItemFactory.h'
--- swig/ItemFactory.h	2013-06-18 23:53:59 +0000
+++ swig/ItemFactory.h	2013-06-21 01:08:30 +0000
@@ -64,11 +64,13 @@
       /** \brief Creates a Base64Binary Item
        *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
        *
-       * @param aBinData a pointer to the base64 binary data.
+       * @param aData a pointer to the base64 binary data.
        * @param aLength the length of the base64 binary data.
+       * @param aIsBase64 if \c true, \a aData is already Base-64 encoded; if
+       * \c false, \a aData is raw binary data to be encoded.
        * @return The Base64Binary Item.
        */
-    Item  createBase64Binary (const char *aBinData, size_t aLength);
+    Item  createBase64Binary (const char *aData, size_t aLength, bool aIsBase64);
 
       /** \brief Creates a Base64Binary Item
        *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
@@ -78,15 +80,6 @@
        */
     Item  createBase64Binary (std::istream &aStream);
 
-      /** \brief Creates a Base64Binary Item
-       *         see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
-       *
-       * @param aBinData the data in binary form. The data is copied from aBinData.
-       * @param aLength the length of the data
-       * @return the Base64Binary Item.
-       */
-    Item  createBase64Binary (const unsigned char *aBinData, size_t aLength);
-
       /** \brief Creates a Boolean Item
        *         see [http://www.w3.org/TR/xmlschema-2/#bool]
        *

=== modified file 'swig/ItemFactory.i'
--- swig/ItemFactory.i	2013-06-18 23:53:59 +0000
+++ swig/ItemFactory.i	2013-06-21 01:08:30 +0000
@@ -22,15 +22,12 @@
     return Item( theItemFactory->createAttributeNode (aParent.theItem, aNodeName.theItem, aTypeName.theItem, typedValue ));
   }
   
-  Item  ItemFactory::createBase64Binary (const char *aBinData, size_t aLength){
-    return Item( theItemFactory->createBase64Binary(aBinData, aLength));
+  Item  ItemFactory::createBase64Binary (const char *aData, size_t aLength, bool aIsBase64){
+    return Item( theItemFactory->createBase64Binary(aData, aLength, aIsBase64));
   }
   Item  ItemFactory::createBase64Binary (std::istream &aStream){
     return Item( theItemFactory->createBase64Binary(aStream));
   }
-  Item  ItemFactory::createBase64Binary (const unsigned char *aBinData, size_t aLength){
-    return Item( theItemFactory->createBase64Binary(aBinData, aLength));
-  }
   Item  ItemFactory::createBoolean (bool aValue){
     return Item( theItemFactory->createBoolean(aValue));
   }

=== modified file 'swig/xqj/ZorbaXQConnection.java'
--- swig/xqj/ZorbaXQConnection.java	2013-02-07 17:24:36 +0000
+++ swig/xqj/ZorbaXQConnection.java	2013-06-21 01:08:30 +0000
@@ -522,7 +522,7 @@
                 item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createAnyURI(value), type);
                 break;
             case XQItemType.XQBASETYPE_BASE64BINARY:
-                item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value, value.length()), type);
+                item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value, value.length(), true), type);
                 break;
             case XQItemType.XQBASETYPE_BYTE:
                 item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createByte(value.charAt(0)), type);
@@ -947,7 +947,7 @@
                         item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createAnyURI(value.toString()), type);
                         break;
                     case XQItemType.XQBASETYPE_BASE64BINARY:
-                        item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value.toString(), (value.toString()).length()), type);
+                        item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value.toString(), (value.toString()).length(), true), type);
                         break;
                     case XQItemType.XQBASETYPE_BYTE:
                         if (value instanceof Byte) {

=== modified file 'test/api/itemfactory.cpp'
--- test/api/itemfactory.cpp	2013-05-22 16:12:01 +0000
+++ test/api/itemfactory.cpp	2013-06-21 01:08:30 +0000
@@ -168,14 +168,14 @@
     CHECK_NOT_IMPLEMENTED (lItem, getBooleanValue() );
 
     /** Base64Binary */
-    lItem = lFactory->createBase64Binary("", 0);
+    lItem = lFactory->createBase64Binary("", 0, false);
     UNIT_ASSERT ( checkType(lItem.getType(), "base64Binary") );
     UNIT_ASSERT ( lItem.isAtomic() );
     UNIT_ASSERT ( lItem.getStringValue() == "" );
     UNIT_ASSERT ( lItem.getStringValue().length() == 0 );
     UNIT_ASSERT ( !lItem.getAtomizationValue().isNull() );
 
-    lItem = lFactory->createBase64Binary("cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q", 96);
+    lItem = lFactory->createBase64Binary("cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q", 96, true);
     UNIT_ASSERT ( checkType(lItem.getType(), "base64Binary") );
     UNIT_ASSERT ( lItem.isAtomic() );
     UNIT_ASSERT ( lItem.getStringValue() == "cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q" );


Follow ups