package sh.calaba.org.codehaus.jackson.util; import java.io.IOException; import java.util.*; import sh.calaba.org.codehaus.jackson.*; /** * Helper class that can be used to sequence multiple physical * {@link JsonParser}s to create a single logical sequence of * tokens, as a single {@link JsonParser}. *
* Fairly simple use of {@link JsonParserDelegate}: only need
* to override {@link #nextToken} to handle transition
*
* @author tatu
* @since 1.5
*/
public class JsonParserSequence extends JsonParserDelegate
{
/**
* Parsers other than the first one (which is initially assigned
* as delegate)
*/
protected final JsonParser[] _parsers;
/**
* Index of the next parser in {@link #_parsers}.
*/
protected int _nextParser;
/*
*******************************************************
* Construction
*******************************************************
*/
protected JsonParserSequence(JsonParser[] parsers)
{
super(parsers[0]);
_parsers = parsers;
_nextParser = 1;
}
/**
* Method that will construct a parser (possibly a sequence) that
* contains all given sub-parsers.
* All parsers given are checked to see if they are sequences: and
* if so, they will be "flattened", that is, contained parsers are
* directly added in a new sequence instead of adding sequences
* within sequences. This is done to minimize delegation depth,
* ideally only having just a single level of delegation.
*/
public static JsonParserSequence createFlattened(JsonParser first, JsonParser second)
{
if (!(first instanceof JsonParserSequence || second instanceof JsonParserSequence)) {
// simple:
return new JsonParserSequence(new JsonParser[] { first, second });
}
ArrayList