in src/com/amazon/ion/impl/LocalSymbolTable.java [219:330]
protected static LocalSymbolTableImports readLocalSymbolTable(IonReader reader,
IonCatalog catalog,
boolean isOnStruct,
List<String> symbolsListOut,
SymbolTable currentSymbolTable)
{
if (! isOnStruct)
{
reader.next();
}
assert reader.getType() == IonType.STRUCT
: "invalid symbol table image passed in reader " +
reader.getType() + " encountered when a struct was expected";
assert ION_SYMBOL_TABLE.equals(reader.getTypeAnnotations()[0])
: "local symbol tables must be annotated by " + ION_SYMBOL_TABLE;
reader.stepIn();
List<SymbolTable> importsList = new ArrayList<SymbolTable>();
importsList.add(reader.getSymbolTable().getSystemSymbolTable());
IonType fieldType;
boolean foundImportList = false;
boolean foundLocalSymbolList = false;
boolean isAppend = false;
while ((fieldType = reader.next()) != null)
{
if (reader.isNullValue()) continue;
SymbolToken symTok = reader.getFieldNameSymbol();
int sid = symTok.getSid();
if (sid == SymbolTable.UNKNOWN_SYMBOL_ID)
{
// This is a user-defined IonReader or a pure DOM, fall
// back to text
final String fieldName = reader.getFieldName();
sid = getSidForSymbolTableField(fieldName);
}
// TODO amzn/ion-java/issues/36 Switching over SIDs doesn't cover the case
// where the relevant field names are defined by a prev LST;
// the prev LST could have 'symbols' defined locally with a
// different SID!
switch (sid)
{
case SYMBOLS_SID:
{
// As per the Spec, other field types are treated as
// empty lists
if(foundLocalSymbolList){
throw new IonException("Multiple symbol fields found within a single local symbol table.");
}
foundLocalSymbolList = true;
if (fieldType == IonType.LIST)
{
reader.stepIn();
IonType type;
while ((type = reader.next()) != null)
{
final String text;
if (type == IonType.STRING)
{
text = reader.stringValue();
}
else
{
text = null;
}
symbolsListOut.add(text);
}
reader.stepOut();
}
break;
}
case IMPORTS_SID:
{
if(foundImportList){
throw new IonException("Multiple imports fields found within a single local symbol table.");
}
foundImportList = true;
if (fieldType == IonType.LIST)
{
prepImportsList(importsList, reader, catalog);
}
else if (fieldType == IonType.SYMBOL && ION_SYMBOL_TABLE.equals(reader.stringValue()))
{
isAppend = true;
}
break;
}
default:
{
// As per the Spec, any other field is ignored
break;
}
}
}
reader.stepOut();
if (isAppend && currentSymbolTable.isLocalTable()) {
// Because the current symbol table is a local symbol table (i.e. not the system symbol table), it can
// be appended in-place.
LocalSymbolTable currentLocalSymbolTable = (LocalSymbolTable) currentSymbolTable;
for (String newSymbol : symbolsListOut) {
currentLocalSymbolTable.putSymbol(newSymbol);
}
return null;
}
return new LocalSymbolTableImports(importsList);
}