1 /* 2 * Copyright 2006-2008 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef ZORBA_SIMPLE_STORE_ITEM_FACTORY 17 #define ZORBA_SIMPLE_STORE_ITEM_FACTORY 18 19 #include <iostream> 20 21 #include "shared_types.h" 22 23 #include "store/api/item_factory.h" 24 //#include "store/api/tuples.h" 25 26 #include "zorbatypes/schema_types.h" 27 28 #include "tree_id.h" 29 30 namespace zorba 31 { 32 33 namespace store 34 { 35 class PUL; 36 } 37 38 39 namespace simplestore 40 { 41 42 class StringPool; 43 typedef StringPool UriPool; 44 class QNamePool; 45 class OrdPath; 46 47 48 class BasicItemFactory : public store::ItemFactory 49 { 50 protected: 51 UriPool * theUriPool; 52 QNamePool * theQNamePool; 53 54 // boolean items 55 // we don't need to create more than two, hence 56 // they are cached here. createBoolean always 57 // returns one of them 58 store::Item_t theTrueItem; 59 store::Item_t theFalseItem; 60 #ifdef ZORBA_WITH_JSON 61 store::Item_t theNullItem; 62 #endif 63 64 public: 65 BasicItemFactory(UriPool* uriPool, QNamePool* qnPool); 66 67 virtual ~BasicItemFactory(); 68 69 bool createUserTypedAtomicItem( 70 store::Item_t& result, 71 store::Item_t& baseItem, 72 store::Item_t& typeName); 73 74 bool createQName( 75 store::Item_t& result, 76 const zstring& ns, 77 const zstring& pre, 78 const zstring& local); 79 80 bool createQName( 81 store::Item_t& result, 82 const char* ns, 83 const char* pre, 84 const char* ln); 85 86 bool createNCName(store::Item_t& result, zstring& value); 87 88 89 bool createAnyURI(store::Item_t& result, zstring& value); 90 91 bool createAnyURI(store::Item_t& result, const char* value); 92 93 bool createStructuralAnyURI(store::Item_t& result, zstring& value); 94 95 bool createStructuralAnyURI( 96 store::Item_t& result, 97 ulong collectionId, 98 const TreeId& treeId, 99 store::StoreConsts::NodeKind nodeKind, 100 const OrdPath& ordPath); 101 102 bool createUntypedAtomic(store::Item_t& result, zstring& value); 103 104 bool createString(store::Item_t& result, zstring& value); 105 106 bool createStreamableString( 107 store::Item_t& result, 108 std::istream&, 109 StreamReleaser, 110 bool seekable = false); 111 112 bool createSharedStreamableString( 113 store::Item_t& result, 114 store::Item_t& streamable_dependent); 115 116 bool createBase64Binary(store::Item_t& result, xs_base64Binary value); 117 118 bool createBase64Binary( 119 store::Item_t& result, 120 const char* value, 121 size_t size, 122 bool encoded); 123 124 bool createStreamableBase64Binary( 125 store::Item_t& result, 126 std::istream&, 127 StreamReleaser, 128 bool seekable = false, 129 bool encoded = false); 130 131 bool createBoolean(store::Item_t& result, xs_boolean value); 132 133 134 bool createDouble(store::Item_t& result, const xs_double& value); 135 136 bool createFloat(store::Item_t& result, const xs_float& value); 137 138 bool createDecimal(store::Item_t& result, const xs_decimal& value); 139 140 bool createInteger(store::Item_t& result, const xs_integer& value); 141 142 bool createNonNegativeInteger(store::Item_t& result, const xs_nonNegativeInteger& value); 143 144 bool createPositiveInteger(store::Item_t& result, const xs_positiveInteger& value ); 145 146 bool createNonPositiveInteger(store::Item_t& result, const xs_integer& value); 147 148 bool createNegativeInteger(store::Item_t& result, const xs_integer& value); 149 150 bool createLong(store::Item_t& result, xs_long value); 151 152 bool createInt(store::Item_t& result, xs_int value); 153 154 bool createShort(store::Item_t& result, xs_short value); 155 156 bool createByte(store::Item_t& result, xs_byte value); 157 158 bool createUnsignedLong(store::Item_t& result, xs_unsignedLong value); 159 160 bool createUnsignedInt(store::Item_t& result, xs_unsignedInt value); 161 162 bool createUnsignedShort(store::Item_t& result, xs_unsignedShort value); 163 164 bool createUnsignedByte(store::Item_t& result, xs_unsignedByte value); 165 166 bool createDateTime(store::Item_t& result, const xs_date* date, const xs_time* time); 167 168 bool createDateTime(store::Item_t& result, const xs_dateTime* value); 169 170 bool createDateTime(store::Item_t& result, short year, short month, short day, short hour, short minute, double second); 171 172 bool createDateTime(store::Item_t& result, short year , short month, short day, short hour, short minute, double second, short timeZone_hours); 173 174 bool createDateTime(store::Item_t& result, const char* str, ulong strlen); 175 176 bool createDateTime(store::Item_t& result, const store::Item_t&, const store::Item_t&); 177 178 bool createDate(store::Item_t& result, const xs_date* value); 179 180 bool createDate(store::Item_t& result, short year, short month, short day); 181 182 bool createDate(store::Item_t& result, const char* str, ulong strlen); 183 184 bool createTime(store::Item_t& result, const xs_time* value); 185 186 bool createTime(store::Item_t& result, const char* str, ulong strlen); 187 188 bool createTime(store::Item_t& result, short hour, short minute, double second ); 189 190 bool createTime(store::Item_t& result, short hour, short minute, double second, short timeZone_hours); 191 192 bool createGDay(store::Item_t& result, const xs_gDay* value); 193 194 bool createGDay(store::Item_t& result, const char* str, ulong strlen); 195 196 bool createGDay(store::Item_t& result, short day); 197 198 bool createGMonth(store::Item_t& result, const xs_gMonth* value); 199 200 bool createGMonth(store::Item_t& result, const char* str, ulong strlen); 201 202 bool createGMonth(store::Item_t& result, short month); 203 204 bool createGMonthDay (store::Item_t& result, const xs_gMonthDay* value); 205 206 bool createGMonthDay (store::Item_t& result, const char* str, ulong strlen); 207 208 bool createGMonthDay (store::Item_t& result, short month, short day); 209 210 bool createGYear (store::Item_t& result, const xs_gYear* value); 211 212 bool createGYear (store::Item_t& result, const char* str, ulong strlen); 213 214 bool createGYear (store::Item_t& result, short year); 215 216 bool createGYearMonth (store::Item_t& result, const xs_gYearMonth* value); 217 218 bool createGYearMonth (store::Item_t& result, const char* str, ulong strlen); 219 220 bool createGYearMonth (store::Item_t& result, short year, short month); 221 222 bool createDuration(store::Item_t& result, xs_duration* value); 223 224 bool createDuration(store::Item_t& result, const char* str, ulong strlen); 225 226 bool createDuration(store::Item_t& result, short years, short months, short days, short hours, short minutes, double seconds); 227 228 bool createYearMonthDuration(store::Item_t& result, const char* str, ulong strlen ); 229 230 bool createYearMonthDuration(store::Item_t& result, xs_yearMonthDuration* value ); 231 232 bool createDayTimeDuration(store::Item_t& result, xs_dayTimeDuration* value ); 233 234 bool createDayTimeDuration(store::Item_t& result, const char* str, ulong strlen ); 235 236 bool createENTITIES(store::Item_t& result, zstring& value); 237 238 bool createENTITY(store::Item_t& result, zstring& value); 239 240 241 bool createHexBinary (store::Item_t& result, xs_hexBinary value ); 242 243 bool createID (store::Item_t& result, zstring& value ); 244 245 bool createIDREF (store::Item_t& result, zstring& value ); 246 247 bool createIDREFS (store::Item_t& result, zstring& value ); 248 249 bool createLanguage (store::Item_t& result, zstring& value ); 250 251 bool createNMTOKEN (store::Item_t& result, zstring& value ); 252 253 bool createNMTOKENS (store::Item_t& result, zstring& value ); 254 255 bool createNOTATION (store::Item_t& result, zstring& value ); 256 257 bool createNOTATION( 258 store::Item_t& result, 259 zstring& ns, 260 zstring& prefix, 261 zstring& local); 262 263 bool createNOTATION (store::Item_t& result, store::Item_t& qname ); 264 265 bool createName (store::Item_t& result, zstring& value ); 266 267 bool createNormalizedString(store::Item_t& result, zstring& value ); 268 269 bool createToken(store::Item_t& result, zstring& value); 270 271 272 273 bool createDocumentNode( 274 store::Item_t& result, 275 zstring& baseUri, 276 zstring& docUri); 277 278 bool createElementNode( 279 store::Item_t& result, 280 store::Item* parent, 281 store::Item_t& nodeName, 282 store::Item_t& typeName, 283 bool haveTypedValue, 284 bool haveEmptyValue, 285 const store::NsBindings& localBindings, 286 zstring& baseURI, 287 bool isInSubstitutionGroup = false); 288 289 bool createElementNode( 290 store::Item_t& result, 291 store::Item* parent, 292 ulong pos, 293 store::Item_t& nodeName, 294 store::Item_t& typeName, 295 bool haveTypedValue, 296 bool haveEmptyValue, 297 const store::NsBindings& localBindings, 298 zstring& baseURI, 299 bool isInSubstitutionGroup = false); 300 301 bool createAttributeNode( 302 store::Item_t& result, 303 store::Item* parent, 304 store::Item_t& nodeName, 305 store::Item_t& typeName, 306 store::Item_t& typedValue); 307 308 bool createAttributeNode( 309 store::Item_t& result, 310 store::Item* parent, 311 store::Item_t& nodeName, 312 store::Item_t& typeName, 313 std::vector<store::Item_t>& typedValueV); 314 315 316 bool createAttributeNode( 317 store::Item_t& result, 318 store::Item* parent, 319 ulong pos, 320 store::Item_t& nodeName, 321 store::Item_t& typeName, 322 store::Item_t& typedValue); 323 324 bool createAttributeNode( 325 store::Item_t& result, 326 store::Item* parent, 327 ulong pos, 328 store::Item_t& nodeName, 329 store::Item_t& typeName, 330 std::vector<store::Item_t>& typedValueV); 331 332 bool createTextNode( 333 store::Item_t& result, 334 store::Item* parent, 335 zstring& content); 336 337 bool createTextNode( 338 store::Item_t& result, 339 store::Item* parent, 340 ulong pos, 341 zstring& content); 342 343 bool createTextNode( 344 store::Item_t& result, 345 store::Item* parent, 346 store::Item_t& content); 347 348 bool createTextNode( 349 store::Item_t& result, 350 store::Item* parent, 351 std::vector<store::Item_t>& content); 352 353 bool createPiNode ( 354 store::Item_t& result, 355 store::Item* parent, 356 zstring& target, 357 zstring& content, 358 zstring& baseUri); 359 360 bool createPiNode ( 361 store::Item_t& result, 362 store::Item* parent, 363 ulong pos, 364 zstring& target, 365 zstring& content, 366 zstring& baseUri); 367 368 bool createCommentNode ( 369 store::Item_t& result, 370 store::Item* parent, 371 zstring& content); 372 373 bool createCommentNode ( 374 store::Item_t& result, 375 store::Item* parent, 376 ulong pos, 377 zstring& content); 378 379 380 store::PUL* createPendingUpdateList(); 381 382 bool createError( 383 store::Item_t& result, 384 ZorbaException* ze); 385 386 bool createFunction( 387 store::Item_t&, 388 const store::Item_t&, 389 const signature&, 390 const store::Iterator_t&); 391 392 bool createFunction( 393 store::Item_t&, 394 const std::vector<store::Iterator_t>&, 395 const signature&, 396 const store::Iterator_t&); 397 398 #ifdef ZORBA_WITH_JSON 399 bool createJSONNull(store::Item_t& result); 400 401 bool createJSONNumber( 402 store::Item_t& result, 403 store::Item_t& string); 404 405 bool createJSONNumber( 406 store::Item_t& result, 407 zstring& string); 408 409 bool createJSONArray( 410 store::Item_t& result, 411 const std::vector<store::Iterator_t>& sources, 412 const std::vector<store::CopyMode>& copyModes); 413 414 bool createJSONArray( 415 store::Item_t& result, 416 store::Item_t& item1, 417 store::Item_t& item2, 418 const store::Iterator_t& source, 419 const store::CopyMode& copyMode); 420 421 bool createJSONArray( 422 store::Item_t& result, 423 const std::vector<store::Item_t>& items); 424 425 bool createJSONObject( 426 store::Item_t& result, 427 const std::vector<store::Iterator_t>& sources, 428 const std::vector<store::CopyMode>& copyModes, 429 bool accumulate); 430 431 bool createJSONObject( 432 store::Item_t& result, 433 const std::vector<store::Item_t>& names, 434 const std::vector<store::Item_t>& values); 435 #endif 436 437 private: 438 void splitToAtomicTextValues( 439 zstring& textValue, 440 std::vector<zstring>& atomicTextValues); 441 }; 442 443 } // namespace simplestore 444 } // namespace zorba 445 446 #endif 447 448 /* 449 * Local variables: 450 * mode: c++ 451 * End: 452 */ 453 /* vim:set et sw=2 ts=2: */ 454