ItemFactory.h
Go to the documentation of this file.
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 
17 #ifndef API_ITEM_FACTORY_H
18 #define API_ITEM_FACTORY_H
19 
20  /** \brief ItemFactory to create Items.
21  *
22  * An instance of this class can be obtained by calling getItemFactory on the Zorba object.
23  *
24  * Each createXXX function of this class creates an Item of an XML Schema item.
25  * If an isNull() call on an Item created by one of these functions returns true the
26  * Item could not be created.
27  */
29 {
30 
31  private:
32  zorba::ItemFactory* theItemFactory;
33  public:
34  ItemFactory(zorba::ItemFactory* aItemFactory) : theItemFactory(aItemFactory) {}
35  ItemFactory(const ItemFactory& aItemFactory) : theItemFactory(aItemFactory.theItemFactory) {}
36 
37  /** \brief Creates an AnyURI Item
38  * see [http://www.w3.org/TR/xmlschema-2/#anyURI]
39  *
40  * @param aURI String representation of the AnyURI.
41  * @return The AnyURI Item.
42  */
43  Item createAnyURI (const std::string &aURI);
44 
45  /**
46  * Create a new attribute node N and place it among the
47  * attributes of a given parent node. If no parent is given, N becomes the
48  * root (and single node) of a new XML tree.
49  *
50  * @param aParent The parent P of the new node; may be NULL.
51  * @param aNodeName The fully qualified name of the new node. The nemaspace
52  * binding implied by this name will be added to the namespaces
53  * of P. If the name prefix is "xml" and the local name is
54  * "base", then the base-uri property of P will be set or
55  * updated accordingly.
56  * @param aTypeName The fully qualified name of the new node's type.
57  * @param aTypedValue The typed value of the new node.
58  * @return The new node N created by this method
59  */
60  Item createAttributeNode (Item& aParent, Item& aNodeName, Item& aTypeName, Item& aTypedValue);
61 #ifndef SWIGRUBY
62  Item createAttributeNode (Item& aParent, Item& aNodeName, Item& aTypeName, std::vector< Item > aTypedValue);
63 #endif
64 
65  /** \brief Creates a Base64Binary Item
66  * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
67  *
68  * @param aBinData a pointer to the base64 binary data.
69  * @param aLength the length of the base64 binary data.
70  * @return The Base64Binary Item.
71  */
72  Item createBase64Binary (const char *aBinData, size_t aLength);
73 
74  /** \brief Creates a Base64Binary Item
75  * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
76  *
77  * @param aStream A stream containing the Base64 encoded data.
78  * @return the Base64Binary Item.
79  */
80  Item createBase64Binary (std::istream &aStream);
81 
82  /** \brief Creates a Base64Binary Item
83  * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
84  *
85  * @param aBinData the data in binary form. The data is copied from aBinData.
86  * @param aLength the length of the data
87  * @return the Base64Binary Item.
88  */
89  Item createBase64Binary (const unsigned char *aBinData, size_t aLength);
90 
91  /** \brief Creates a Boolean Item
92  * see [http://www.w3.org/TR/xmlschema-2/#bool]
93  *
94  * @param aValue bool representation of the Boolean.
95  * @return The Boolean Item.
96  */
97  Item createBoolean (bool aValue);
98 
99  /** \brief Creates a Byte Item
100  * see [http://www.w3.org/TR/xmlschema-2/#byte]
101  *
102  * @param aByte char representation of the Byte.
103  * @return The Byte Item.
104  */
105  Item createByte (char aByte);
106 
107  /**
108  * Create a new comment node N and place it as the last child of a given
109  * parent node. If no parent is given, N becomes the root (and single node)
110  * of a new XML tree.
111  *
112  * @param aParent The parent P of the new node; may be NULL.
113  * @param aContent The content of the new node.
114  * @return The new node N created by this method
115  */
116  Item createCommentNode (Item &aParent, const std::string &aContent);
117 
118  /** \brief Creates a Date Item
119  * see [http://www.w3.org/TR/xmlschema-2/#date]
120  *
121  * @param aDate String representation of the Date (e.g. 2002-10-10).
122  * @return The Date Item.
123  */
124  Item createDate (const std::string &aDate);
125 
126  /** \brief Creates a Date Item
127  * see [http://www.w3.org/TR/xmlschema-2/#date]
128  *
129  * @param aYear short-valued representation of the year.
130  * @param aMonth short-valued representation of the month.
131  * @param aDay short-valued representation of the day.
132  * @return The Date Item.
133  */
134  Item createDate (short aYear, short aMonth, short aDay);
135 
136  /** \brief Creates a DateTime Item
137  * see [http://www.w3.org/TR/xmlschema-2/#dateTime]
138  *
139  * @param aDateTimeValue String representation of the datetime value
140  * (for example, 2002-10-10T12:00:00-05:00).
141  * @return The DateTime Item.
142  */
143  Item createDateTime (const std::string &aDateTimeValue);
144 
145  /** \brief Creates a DateTime Item
146  * see [http://www.w3.org/TR/xmlschema-2/#dateTime]
147  *
148  * @param aYear short-valued representation of the year.
149  * @param aMonth short-valued representation of the month.
150  * @param aDay short-valued representation of the day.
151  * @param aHour short-valued representation of the hour.
152  * @param aMinute short-valued representation of the minute.
153  * @param aSecond double-valued representation of the seconds and fractional seconds.
154  * @param aTimeZone_hours short-valued representation of the difference in hours to UTC.
155  * @return The DateTime Item.
156  */
157  Item createDateTime (short aYear, short aMonth, short aDay, short aHour, short aMinute, double aSecond, short aTimeZone_hours);
158 
159  /** \brief Creates a Decimal Item
160  * see [http://www.w3.org/TR/xmlschema-2/#decimal]
161  *
162  * @param aValue String representation of the Decimal (e.g. 12678967.543233).
163  * @return The Decimal Item.
164  */
165  Item createDecimal (const std::string &aValue);
166 
167  /** \brief Creates a Decimal Item
168  * see [http://www.w3.org/TR/xmlschema-2/#decimal]
169  *
170  * @param aValue double representation of the Decimal.
171  * @return The Decimal Item.
172  */
173  Item createDecimalFromDouble (double aValue);
174 
175  /** \brief Creates a Decimal Item
176  * see [http://www.w3.org/TR/xmlschema-2/#decimal]
177  *
178  * @param aValue unsigned long representation of the Decimal.
179  * @return The Decimal Item.
180  */
181  Item createDecimalFromLong (unsigned long aValue);
182 
183  /** \brief Creates a Double Item
184  * see [http://www.w3.org/TR/xmlschema-2/#double]
185  *
186  * @param aValue String representation of the Double.
187  * @return The Double Item.
188  */
189  Item createDouble (const std::string &aValue);
190 
191  /** \brief Creates a Double Item
192  * see [http://www.w3.org/TR/xmlschema-2/#double]
193  *
194  * @param aValue double representation of the Double.
195  * @return The Double Item.
196  */
197  Item createDouble (double aValue);
198 
199  /** \brief Creates a Duration Item
200  * see [http://www.w3.org/TR/xmlschema-2/#duration]
201  *
202  * @param aValue String representation of the NCName.
203  * @return The Duration Item.
204  */
205  Item createDuration (const std::string &aValue);
206 
207  /** \brief Creates a Duration Item
208  * see [http://www.w3.org/TR/xmlschema-2/#duration]
209  *
210  * @param aYear short-valued representation of the years.
211  * @param aMonths short-valued representation of the months.
212  * @param aDays short-valued representation of the days.
213  * @param aHours short-valued representation of the hours.
214  * @param aMinutes short-valued representation of the minutes.
215  * @param aSeconds double-valued representation of the seconds and fractional seconds.
216  * @return The Duration Item.
217  */
218  Item createDuration (short aYear, short aMonths, short aDays, short aHours, short aMinutes, double aSeconds);
219 
220  /** \brief Creates a dayTimeDuration Item
221  * see [http://www.w3.org/TR/xpath-functions/#duration-subtypes]
222  *
223  * @param aValue String lexical representation of the duration.
224  * @return the dayTimeDuration Item.
225  */
226  Item createDayTimeDuration (const std::string &aValue);
227 
228  /** \brief Creates a yearMonthDuration Item
229  * see [http://www.w3.org/TR/xpath-functions/#duration-subtypes]
230  *
231  * @param aValue String lexical representation of the duration.
232  * @return the yearMonthDuration Item.
233  */
234  Item createYearMonthDuration (const std::string &aValue);
235 
236  /** \brief Creates a documentNode Item
237  * see [http://www.w3.org/TR/xpath-functions/#duration-subtypes]
238  *
239  * @param aBaseUri String representation of the Base URI.
240  * @param aDocUri String representation of the Document URI.
241  * @return the documentNode Item.
242  */
243  Item createDocumentNode (const std::string &aBaseUri, const std::string &aDocUri);
244 #ifndef SWIGRUBY
245  /**
246  * @brief Creates a new element node.
247  *
248  * Create a new element node N and place it at the end among the
249  * children of a given parent node. If no parent is given, N becomes the
250  * root (and single node) of a new XML tree.
251  *
252  * @param aParent The parent P of the new node; may be NULL.
253  * @param aNodeName The fully qualified name of the new node.
254  * @param aTypeName The fully qualified name of the new node's type.
255  * Not allowed to be NULL, use xsd:untyped instead.
256  * @param aHasTypedValue Whether the node has a typed value or not (element
257  * nodes with complex type and element-only content do
258  * not have typed value).
259  * @param aHasEmptyValue True if the typed value of the node is the empty
260  * sequence. This is the case if the element has a
261  * complex type with empty content.
262  * @param aNsBindings A set of namespace bindings. The namespaces property
263  * of N will be the union of this set and the namespaces
264  * property of P.
265  * @return The new node N created by this method
266  */
267  Item createElementNode (Item &aParent, Item &aNodeName, Item &aTypeName, bool aHasTypedValue, bool aHasEmptyValue, std::vector< std::pair< std::string, std::string > > aNsBindings);
268 #endif
269 
270  /**
271  * @brief Creates a new element node.
272  *
273  * Create a new element node N and place it at the end among the
274  * children of a given parent node. If no parent is given, N becomes the
275  * root (and single node) of a new XML tree.
276  *
277  * @param aParent The parent P of the new node; may be NULL.
278  * @param aNodeName The fully qualified name of the new node.
279  * @param aTypeName The fully qualified name of the new node's type.
280  * Not allowed to be NULL, use xsd:untyped instead.
281  * @param aHasTypedValue Whether the node has a typed value or not (element
282  * nodes with complex type and element-only content do
283  * not have typed value).
284  * @param aHasEmptyValue True if the typed value of the node is the empty
285  * sequence. This is the case if the element has a
286  * complex type with empty content.
287  * @return The new node N created by this method
288  */
289  Item createElementNode (Item &aParent, Item &aNodeName, Item &aTypeName, bool aHasTypedValue, bool aHasEmptyValue);
290 
291  /** \brief creates a float item
292  * see [http://www.w3.org/tr/xmlschema-2/#float]
293  *
294  * @param aValue string representation of the float.
295  * @return the float item.
296  */
297  Item createFloat (const std::string &aValue);
298 
299  /** \brief creates a float item
300  * see [http://www.w3.org/tr/xmlschema-2/#float]
301  *
302  * @param aValue float representation of the float.
303  * @return the float item.
304  */
305  Item createFloat (float aValue);
306 
307  /** \brief Creates a gDay Item
308  * see [http://www.w3.org/TR/xmlschema-2/#gDay]
309  *
310  * @param aValue String representation of the gDay.
311  * @return The gDay Item.
312  */
313  Item createGDay (const std::string &aValue);
314 
315  /** \brief Creates a gDay Item
316  * see [http://www.w3.org/TR/xmlschema-2/#gDay]
317  *
318  * @param aDay short representation of the gDay.
319  * @return The gDay Item.
320  */
321  Item createGDay (short aDay);
322 
323  /** \brief Creates a gMonth Item
324  * see [http://www.w3.org/TR/xmlschema-2/#gMonth]
325  *
326  * @param aValue String representation of the gMonth.
327  * @return The gMonth Item.
328  */
329  Item createGMonth (const std::string &aValue);
330 
331  /** \brief Creates a gMonth Item
332  * see [http://www.w3.org/TR/xmlschema-2/#gMonth]
333  *
334  * @param aMonth short representation of the gMonth.
335  * @return The gMonth Item.
336  */
337  Item createGMonth (short aMonth);
338 
339  /** \brief Creates a gMonthDay Item
340  * see [http://www.w3.org/TR/xmlschema-2/#gMonthDay]
341  *
342  * @param aValue String representation of the gMonthDay.
343  * @return The gMonthDay Item.
344  */
345  Item createGMonthDay (const std::string &aValue);
346 
347  /** \brief Creates a gMonthDay Item
348  * see [http://www.w3.org/TR/xmlschema-2/#gMonthDay]
349  *
350  * @param aMonth short representation of the month.
351  * @param aDay short representation of the day.
352  * @return The gMonthDay Item.
353  */
354  Item createGMonthDay (short aMonth, short aDay);
355 
356  /** \brief Creates a gYear Item
357  * see [http://www.w3.org/TR/xmlschema-2/#gYear]
358  *
359  * @param aYear short representation of the gYear.
360  * @return The gYear Item.
361  */
362  Item createGYear (short aYear);
363 
364  /** \brief Creates a gYear Item
365  * see [http://www.w3.org/TR/xmlschema-2/#gYear]
366  *
367  * @param aValue String representation of the gYear.
368  * @return The gYear Item.
369  */
370  Item createGYear (const std::string &aValue);
371 
372  /** \brief Creates a gYearMonth Item
373  * see [http://www.w3.org/TR/xmlschema-2/#gYearMonth]
374  *
375  * @param aValue String representation of the gYearMonth.
376  * @return The gYearMonth Item.
377  */
378  Item createGYearMonth (const std::string &aValue);
379 
380  /** \brief Creates a gYearMonth Item
381  * see [http://www.w3.org/TR/xmlschema-2/#gYearMonth]
382  *
383  * @param aYear short representation of the year.
384  * @param aMonth short representation of the month.
385  * @return The gYearMonth Item.
386  */
387  Item createGYearMonth (short aYear, short aMonth);
388 
389  /** \brief Creates a HexBinary Item
390  * see [http://www.w3.org/TR/xmlschema-2/#hexBinary]
391  *
392  * @param aHexData pointer to the hexdata.
393  * @param aSize size of the hexdata.
394  * @return The HexBinary Item.
395  */
396  Item createHexBinary (const char *aHexData, size_t aSize);
397 
398  /** \brief Creates a Int Item
399  * see [http://www.w3.org/TR/xmlschema-2/#int]
400  *
401  * @param aInt int representation of the Int.
402  * @return The NCName Item.
403  */
404  Item createInt (int aInt);
405 
406  /** \brief Creates an Integer Item
407  * see [http://www.w3.org/TR/xmlschema-2/#integer]
408  *
409  * @param aInteger String representation of the Integer.
410  * @return The Integer Item.
411  */
412  Item createInteger (const std::string &aInteger);
413 
414  /** \brief Creates an Integer Item
415  * see [http://www.w3.org/TR/xmlschema-2/#integer]
416  *
417  * @param aInteger unsigned long representation of the Integer.
418  * @return The Integer Item.
419  */
420  Item createInteger (long long aInteger);
421 
422  /** \brief Creates a Long Item
423  * see [http://www.w3.org/TR/xmlschema-2/#long]
424  *
425  * @param aLong long long representation of the Long.
426  * @return The Long Item.
427  */
428  Item createLong (long long aLong);
429 
430  /** \brief Creates a NCName Item
431  * see [http://www.w3.org/TR/xmlschema-2/#NCName]
432  *
433  * @param aValue String representation of the NCName.
434  * @return The NCName Item.
435  */
436  Item createNCName (const std::string &aValue);
437 
438  /** \brief Creates a negativeInteger Item
439  * see [http://www.w3.org/TR/xmlschema-2/#negativeInteger]
440  *
441  * @param aValue long long representation of the negativeInteger.
442  * @return The negativeInteger Item.
443  */
444  Item createNegativeInteger (long long aValue);
445 
446  /** \brief Creates a nonNegativeInteger Item
447  * see [http://www.w3.org/TR/xmlschema-2/#nonNegativeInteger]
448  *
449  * @param aValue unsigned long representation of the nonNegativeInteger.
450  * @return The nonNegativeInteger Item.
451  */
452  Item createNonNegativeInteger (unsigned long long aValue);
453 
454  /** \brief Creates a nonPositiveInteger Item
455  * see [http://www.w3.org/TR/xmlschema-2/#nonPositiveInteger]
456  *
457  * @param aValue long long representation of the NCName.
458  * @return The nonPositiveInteger Item.
459  */
460  Item createNonPositiveInteger (long long aValue);
461 
462  /**
463  * Create a new Processing Instruction node N and place it among the
464  * children of a given parent node. If no parent is given, N becomes the
465  * root (and single node) of a new XML tree.
466  *
467  * @param aParent The parent P of the new node; may be NULL.
468  * @param aTarget The Target of the new node.
469  * @param aContent The Content of the new node.
470  * @param aBaseUri The Base URI of the new node, may be NULL.
471  * @return The new node N created by this method
472  */
473  Item createPiNode (Item &aParent, const std::string &aTarget, const std::string &aContent, const std::string &aBaseUri);
474 
475  /** \brief Creates a positiveInteger\ Item
476  * see [http://www.w3.org/TR/xmlschema-2/#positiveInteger]
477  *
478  * @param aValue unsigned long representation of the positiveInteger.
479  * @return The positiveInteger Item.
480  */
481  Item createPositiveInteger (unsigned long long aValue);
482 
483  /** \brief Creates a QName Item
484  * see [http://www.w3.org/TR/xmlschema-2/#QName]
485  *
486  * @param aNamespace String representation of the namespace.
487  * @param aPrefix String representation of the prefix.
488  * @param aLocalname String representation of the localname.
489  *
490  * @return The QName Item.
491  */
492  Item createQName (const std::string &aNamespace, const std::string &aPrefix, const std::string &aLocalname);
493 
494  /** \brief Creates a QName Item
495  * see [http://www.w3.org/TR/xmlschema-2/#QName]
496  *
497  * @param aNamespace String representation of the namespace.
498  * @param aLocalname String representation of the localname. *
499  * @return The QName Item.
500  */
501  Item createQName (const std::string &aNamespace, const std::string &aLocalname);
502 
503  /** \brief Creates a QName Item
504  * see [http://www.w3.org/TR/xmlschema-2/#QName]
505  *
506  * The QName is constructed by parsing the string using the notation
507  * invented by James Clark (i.e. {namespace}localname).
508  *
509  * @param aQNameString String in the QName notation by James Clark.
510  * @return The QName Item.
511  */
512  Item createQName (const std::string &aQNameString);
513 
514  /** \brief Creates a Short Item
515  * see [http://www.w3.org/TR/xmlschema-2/#short]
516  *
517  * @param aShort short representation of the Short.
518  * @return The Short Item.
519  */
520  Item createShort (short aShort);
521  //Item createStreamableString (std::istream &stream, StreamReleaser streamReleaser, bool seekable=false);
522 
523  /** \brief Creates a String Item
524  * see [http://www.w3.org/TR/xmlschema-2/#string]
525  *
526  * @param aString String representation of the String Item.
527  * @return The String Item
528  */
529  Item createString (const std::string &aString);
530 
531  /**
532  * Create a new text node N and place it among the
533  * children of a given parent node. If no parent is given, N becomes the
534  * root (and single node) of a new XML tree.
535  *
536  * @param aParent The parent P of the new node; may be NULL.
537  * @param aContent The content of the new node.
538  * @return The new node N created by this method
539  */
540  Item createTextNode (Item &aParent, const std::string &aContent);
541 
542  /** \brief Creates a Time Item
543  * see [http://www.w3.org/TR/xmlschema-2/#time]
544  *
545  * @param aHour short representation of the hour.
546  * @param aMinute short representation of the minute.
547  * @param aSecond double representation of the seconds and fractional seconds.
548  * @param aTimeZone_hours short representation of the timezone difference in hours to UTC.
549  * @return The Time Item.
550  */
551  Item createTime (short aHour, short aMinute, double aSecond, short aTimeZone_hours);
552 
553  /** \brief Creates a Time Item
554  * see [http://www.w3.org/TR/xmlschema-2/#time]
555  *
556  * @param aHour short representation of the hour.
557  * @param aMinute short representation of the minute.
558  * @param aSecond double representation of the seconds and fractional seconds.
559  * @return The Time Item.
560  */
561  Item createTime (short aHour, short aMinute, double aSecond);
562 
563  /** \brief Creates a Time Item
564  * see [http://www.w3.org/TR/xmlschema-2/#time]
565  *
566  * @param aValue String representation of the Time.
567  * @return The Time Item
568  */
569  Item createTime (const std::string &aValue);
570 
571  /** \brief Creates an Unsigned Byte Item
572  * see [http://www.w3.org/TR/xmlschema-2/#unsignedByte]
573  *
574  * @param aValue unsignedByte unsigned char representation of the unsigned byte.
575  * @return The Unsigned Byte Item.
576  */
577  Item createUnsignedByte (const unsigned char aValue);
578 
579  /** \brief Creates an unsigned int Item
580  * see [http://www.w3.org/TR/xmlschema-2/#unsignedInt]
581  *
582  * @param aValue unsigned int representation of the unsignedInt.
583  * @return The unsignedInt Item.
584  */
585  Item createUnsignedInt (unsigned int aValue);
586 
587  /** \brief Creates an unsignedLong Item
588  * see [http://www.w3.org/TR/xmlschema-2/#unsignedLong]
589  *
590  * @param aValue unsignedLong long long representation of the unsignedLong.
591  * @return The unsignedLong Item.
592  */
593  Item createUnsignedLong (unsigned long long aValue);
594 
595  /** \brief Creates a unsignedShort Item
596  * see [http://www.w3.org/TR/xmlschema-2/#unsignedShort]
597  *
598  * @param aValue unsigned short representation of the unsignedShort.
599  * @return The unsignedShort Item.
600  */
601  Item createUnsignedShort (unsigned short aValue);
602 }; // class ItemFactory
603 
604 #endif
blog comments powered by Disqus