IndentedLineBuffer buff = new IndentedLineBuffer() ;
query.serialize(buff, query.getSyntax()) ;
String tmp = buff.toString() ;
Query query2 = null ;
try {
String baseURI = null ;
if ( ! query.explicitlySetBaseURI() )
// Not in query - use the same one (e.g. file read from) .
baseURI = query.getBaseURI() ;
query2 = QueryFactory.create(tmp, baseURI, query.getSyntax()) ;
if ( query2 == null )
return ;
} catch (UnsupportedOperationException ex)
{
// No parser after all.
return ;
}
catch (QueryException ex)
{
System.err.println(tmp) ;
throw new QueryCheckException("could not parse output query", ex) ;
}
if ( query.hashCode() != query2.hashCode() )
throw new QueryCheckException("reparsed query hashCode does not equal parsed input query \nQuery (hashCode: " + query.hashCode() + ")=\n" + query + "\n\nQuery2 (hashCode: " + query2.hashCode() + ")=\n" + query2) ;
if ( ! query.equals(query2) )
throw new QueryCheckException("reparsed output does not equal parsed input") ;
}