16 package org.zorbaxquery.api.xqj;
18 import java.io.OutputStream;
19 import java.io.Reader;
20 import java.io.StringReader;
21 import java.io.Writer;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Properties;
26 import javax.xml.stream.XMLInputFactory;
27 import javax.xml.stream.XMLStreamException;
28 import javax.xml.stream.XMLStreamReader;
29 import javax.xml.transform.Result;
30 import javax.xml.xquery.*;
31 import org.w3c.dom.Node;
32 import org.xml.sax.ContentHandler;
33 import org.zorbaxquery.api.Item;
34 import org.zorbaxquery.api.Iterator;
75 private boolean closed =
false;
76 private boolean forwardOnly =
false;
77 private boolean currentItemGet =
false;
78 private Collection<XQResultItem> content =
new ArrayList<XQResultItem>();
79 private int position = 0;
81 private XQConnection connection = null;
82 private boolean preparedExpression;
83 private org.zorbaxquery.api.XQuery lQuery;
88 iter = query.iterator();
90 Item item =
new Item();
91 while (iter.next(item)) {
97 size = content.size();
99 preparedExpression = prepared;
121 public boolean absolute(
int i)
throws XQException {
122 isClosedXQException();
123 boolean result =
false;
149 isClosedXQException();
159 isClosedXQException();
170 public void close() throws XQException {
172 for (XQItem item: content) {
175 if (lStaticCollectionManager!=null) {
176 lStaticCollectionManager.close();
195 public int count() throws XQException {
196 isClosedXQException();
210 isClosedXQException();
223 isClosedXQException();
224 return (position>0) && (position<(content.size()+1));
234 isClosedXQException();
246 public boolean first() throws XQException {
247 isClosedXQException();
248 boolean result =
false;
249 if (content.size()>0) {
267 isClosedXQException();
268 isItemGetXQException();
269 return (XQItem)content.toArray()[position-1];
281 isClosedXQException();
282 isItemGetXQException();
283 StringBuffer sb =
new StringBuffer();
284 for (XQItem item: content) {
285 sb.append(item.getItemAsString(null));
287 XMLInputFactory fac = XMLInputFactory.newInstance();
288 Reader read =
new StringReader(sb.toString());
289 XMLStreamReader result = null;
291 result = fac.createXMLStreamReader(read);
292 }
catch (XMLStreamException ex) {
293 throw new XQException(
"Problem reading the stream: " + sb +
" - with error: " + ex.getLocalizedMessage());
308 isClosedXQException();
309 isItemGetXQException();
310 StringBuffer sb =
new StringBuffer();
311 for (XQItem item: content) {
312 sb.append(item.getItemAsString(null));
314 return sb.toString();
326 isClosedXQException();
327 boolean result =
false;
329 result = position==size+1;
343 isClosedXQException();
344 boolean result =
false;
345 if (content.size()>0) {
346 result = position==0;
360 isClosedXQException();
361 boolean result =
false;
362 if (content.size()>0) {
363 result = position==1;
376 public boolean isLast() throws XQException {
377 isClosedXQException();
378 boolean result =
false;
380 result = position==size;
393 public boolean last() throws XQException {
394 isClosedXQException();
395 boolean result =
false;
411 public boolean next() throws XQException {
412 isClosedXQException();
413 boolean result =
false;
414 if ((position<=size) && (size>0)) {
415 result = (position<size);
430 isClosedXQException();
431 boolean result =
false;
432 if ((position>0) && (size>0)) {
433 result = (position>1);
449 public boolean relative(
int i)
throws XQException {
450 isClosedXQException();
451 boolean result =
false;
452 if ((i!=0) && (size>0)) {
453 position = position + i;
456 }
else if (position>size) {
474 public void writeSequence(OutputStream out, Properties prprts)
throws XQException {
475 isClosedXQException();
476 isNullXQException(out);
478 getItem().writeItem(out, prprts);
481 getItem().writeItem(out, prprts);
498 public void writeSequence(Writer writer, Properties prprts)
throws XQException {
499 isClosedXQException();
500 isNullXQException(writer);
502 getItem().writeItem(writer, prprts);
505 getItem().writeItem(writer, prprts);
518 isClosedXQException();
519 isNullXQException(ch);
541 isClosedXQException();
542 isNullXQException(result);
544 getItem().writeItemToResult(result);
547 getItem().writeItemToResult(result);
560 isClosedXQException();
573 isClosedXQException();
586 isClosedXQException();
599 isClosedXQException();
612 isClosedXQException();
625 isClosedXQException();
626 return getItem().getItemType();
638 isClosedXQException();
639 return getItem().getAtomicValue();
651 isClosedXQException();
664 isClosedXQException();
678 isClosedXQException();
691 isClosedXQException();
704 isClosedXQException();
705 return getItem().getItemAsStream();
718 return getItem().getItemAsString(prprts);
730 isClosedXQException();
763 public boolean instanceOf(XQItemType xqit)
throws XQException {
764 isClosedXQException();
765 isNullXQException(xqit);
766 return getItem().instanceOf(xqit);
778 public void writeItem(OutputStream out, Properties prprts)
throws XQException {
779 isClosedXQException();
780 isNullXQException(out);
781 getItem().writeItem(out, prprts);
794 public void writeItem(Writer writer, Properties prprts)
throws XQException {
795 isClosedXQException();
796 isNullXQException(writer);
797 getItem().writeItem(writer, prprts);
809 isClosedXQException();
810 isNullXQException(ch);
827 isClosedXQException();
828 isNullXQException(result);
829 getItem().writeItemToResult(result);
841 isClosedXQException();
842 if (lStaticCollectionManager==null) {
845 return lStaticCollectionManager;
848 private void isClosedXQException() throws XQException {
850 throw new XQException(
"This sequence is closed");
853 private void isItemGetXQException() throws XQException {
854 if (forwardOnly && currentItemGet) {
855 throw new XQException(
"Item already consumed on a forward-only sequence");
858 private void isNullXQException(Object value)
throws XQException {
860 throw new XQException(
"Parameter shouldn't be null");
872 throw new UnsupportedOperationException(
"Not supported yet.");
Using the ZorbaXQStaticCollectionManager one can retrieve information about statically declared colle...
This class represents an immutable item object obtained from an XQResultSequence using the getItem me...