src/com/sun/xml/internal/stream/XMLEventReaderImpl.java

Print this page




 231                 eventType = event.getEventType();
 232             }
 233 
 234             if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
 235                 throw new XMLStreamException("expected start or end tag", event.getLocation());
 236             }
 237             return event;
 238         }
 239 
 240         //if there is no peeked event -- delegate the work of getting next event to fXMLReader
 241         fXMLReader.nextTag();
 242         return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
 243     }
 244 
 245     public Object next() {
 246         Object object = null;
 247         try{
 248             object = nextEvent();
 249         }catch(XMLStreamException streamException){
 250             fLastEvent = null ;
 251             //xxx: what should be done in this case ?
 252             throw new NoSuchElementException();


 253         }
 254         return object;
 255     }
 256 
 257     public XMLEvent peek() throws XMLStreamException{
 258         //if someone call peek() two times we should just return the peeked event
 259         //this is reset if we call next() or nextEvent()
 260         if(fPeekedEvent != null) return fPeekedEvent;
 261 
 262         if(hasNext()){
 263             //revisit: we can implement peek() by calling underlying reader to advance
 264             // the stream and returning the event without the knowledge of the user
 265             // that the stream was advanced but the point is we are advancing the stream
 266             //here. -- nb.
 267 
 268             // Is there any application that relies on this behavior ?
 269             //Can it be an application knows that there is particularly very large 'comment' section
 270             //or character data which it doesn't want to read or to be returned as event
 271             //But as of now we are creating every event but it can be optimized not to create
 272             // the event.


 231                 eventType = event.getEventType();
 232             }
 233 
 234             if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
 235                 throw new XMLStreamException("expected start or end tag", event.getLocation());
 236             }
 237             return event;
 238         }
 239 
 240         //if there is no peeked event -- delegate the work of getting next event to fXMLReader
 241         fXMLReader.nextTag();
 242         return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
 243     }
 244 
 245     public Object next() {
 246         Object object = null;
 247         try{
 248             object = nextEvent();
 249         }catch(XMLStreamException streamException){
 250             fLastEvent = null ;
 251             //don't swallow the cause
 252             NoSuchElementException e = new NoSuchElementException(streamException.getMessage());
 253             e.initCause(streamException.getCause());
 254             throw e;
 255         }
 256         return object;
 257     }
 258 
 259     public XMLEvent peek() throws XMLStreamException{
 260         //if someone call peek() two times we should just return the peeked event
 261         //this is reset if we call next() or nextEvent()
 262         if(fPeekedEvent != null) return fPeekedEvent;
 263 
 264         if(hasNext()){
 265             //revisit: we can implement peek() by calling underlying reader to advance
 266             // the stream and returning the event without the knowledge of the user
 267             // that the stream was advanced but the point is we are advancing the stream
 268             //here. -- nb.
 269 
 270             // Is there any application that relies on this behavior ?
 271             //Can it be an application knows that there is particularly very large 'comment' section
 272             //or character data which it doesn't want to read or to be returned as event
 273             //But as of now we are creating every event but it can be optimized not to create
 274             // the event.