@Override
   public void handleEvent(IParserEvent event)
   {
      if (event.getType() == ParserEventType.DOCUMENT_END_EVENT)
      {
         flushEvents();
         event.fire(listener);
      }
      else
      {
         IParserEvent lastEvent = events.peekLast();
         if (lastEvent != null && lastEvent.getType() == ParserEventType.STRING_EVENT && event.getType() == ParserEventType.STRING_EVENT)
         {
            event = mergeStringEvents((StringEvent) event);
         }

         events.add(event);

         if (events.size() > MAX_EVENTS)
         {
            events.removeFirst().fire(listener);
         }
      }
   }