throws ThreddsXmlParserException
{
try
{
XMLInputFactory factory = getFactory();
XMLEventReader eventReader = factory.createXMLEventReader( source );
ThreddsBuilderFactory catBuilderFac = new ThreddsBuilderFactoryImpl();
ThreddsBuilder threddsBuilder = null;
while ( eventReader.hasNext() )
{
XMLEvent event = eventReader.peek();
if ( event.isEndDocument())
{ // Done!
eventReader.next();
break;
}
else if ( event.isStartDocument())
{ // Don't need any info from StartDocument event.
eventReader.next();
}
else if ( event.isStartElement())
{
if ( this.catElemParserFactory.isEventMyStartElement( event.asStartElement() ))
{
CatalogElementParser catElemParser = this.catElemParserFactory.getNewParser( source.getSystemId(),
eventReader, catBuilderFac);
threddsBuilder = catElemParser.parse();
}
// ToDo Implement reading a document with "dataset" root element.
// ToDo Implement reading a document with "metadata" root element.
else
{
// ToDo Save the results in a ThreddsXmlParserIssue (Warning) and report.
StaxThreddsXmlParserUtils.consumeElementAndConvertToXmlString( eventReader );
log.warn( "readCatalogXML(): Unrecognized start element [" + event.asStartElement().getName() + "]." );
//eventReader.next();
}
}
else if ( event.isEndElement())
{
log.error( "readCatalogXML(): Unrecognized end element [" + event.asEndElement().getName() + "]." );
break;
}
else
{
log.debug( "readCatalogXML(): Unhandled event [" + event.getLocation() + "--" + event + "].");
eventReader.next();
continue;
}
}
eventReader.close();
if ( threddsBuilder == null )
return null;
return (CatalogBuilder) threddsBuilder;