@Test public void testStartEndDocument() throws XMLStreamException { XMLStreamReader reader = createXmlStreamReader("<? xml ?>"); StartDocument startDocument = (StartDocument)eventAllocator.allocate(reader); verify(startDocument, XMLStreamConstants.START_DOCUMENT, "<?xml version=\"1.0\"?>"); Assert.assertEquals("UTF-8", startDocument.getCharacterEncodingScheme()); Assert.assertFalse(startDocument.encodingSet()); Assert.assertEquals("1.0", startDocument.getVersion()); Assert.assertFalse(startDocument.isStandalone()); Assert.assertFalse(startDocument.standaloneSet()); reader.next(); verify((EndDocument)eventAllocator.allocate(reader), XMLStreamConstants.END_DOCUMENT, ""); reader = createXmlStreamReader("<? xml version=\"1.1\" ?>"); startDocument = (StartDocument)eventAllocator.allocate(reader); Assert.assertEquals("1.1", startDocument.getVersion()); reader = createXmlStreamReader("<? xml encoding=\"UTF-16\"?>"); startDocument = (StartDocument)eventAllocator.allocate(reader); Assert.assertEquals("UTF-16", startDocument.getCharacterEncodingScheme()); Assert.assertTrue(startDocument.encodingSet()); }
@Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } } }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer); }
SimpleXMLEventAllocator implements XMLEventAllocator { @Override public XMLEvent allocate(XMLStreamReader reader) throws XMLStreamException { switch (reader.getEventType()) { case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: return new CharactersEvent(reader); case XMLStreamConstants.COMMENT: return new CommentEvent(reader); case XMLStreamConstants.DTD: throw new UnsupportedOperationException(); case XMLStreamConstants.END_DOCUMENT: return new EndDocumentEvent(reader); case XMLStreamConstants.END_ELEMENT: return new EndElementEvent(reader); case XMLStreamConstants.ENTITY_REFERENCE: return new EntityReferenceEvent(reader); case XMLStreamConstants.NOTATION_DECLARATION: throw new UnsupportedOperationException(); case XMLStreamConstants.PROCESSING_INSTRUCTION: return new ProcessingInstructionEvent(reader); case XMLStreamConstants.START_DOCUMENT: return new StartDocumentEvent(reader); case XMLStreamConstants.START_ELEMENT: return new StartElementEvent(reader); default: throw new XMLStreamException("Unexpected event type: " + reader.getEventType()); } }  @Override XMLEventAllocator newInstance(); @Override XMLEvent allocate(XMLStreamReader reader); @Override void allocate(XMLStreamReader reader, XMLEventConsumer consumer);  }