in src/com/amazon/ion/impl/LocalSymbolTable.java [665:770]
private static SymbolTable readOneImport(IonReader ionRep,
IonCatalog catalog)
{
assert (ionRep.getType() == IonType.STRUCT);
String name = null;
int version = -1;
int maxid = -1;
ionRep.stepIn();
IonType t;
while ((t = ionRep.next()) != null)
{
if (ionRep.isNullValue()) continue;
SymbolToken symTok = ionRep.getFieldNameSymbol();
int field_id = symTok.getSid();
if (field_id == UNKNOWN_SYMBOL_ID)
{
// this is a user defined reader or a pure DOM
// we fall back to text here
final String fieldName = ionRep.getFieldName();
field_id = getSidForSymbolTableField(fieldName);
}
switch(field_id)
{
case NAME_SID:
if (t == IonType.STRING)
{
name = ionRep.stringValue();
}
break;
case VERSION_SID:
if (t == IonType.INT)
{
version = ionRep.intValue();
}
break;
case MAX_ID_SID:
if (t == IonType.INT)
{
maxid = ionRep.intValue();
}
break;
default:
// we just ignore anything else as "open content"
break;
}
}
ionRep.stepOut();
// Ignore import clauses with malformed name field.
if (name == null || name.length() == 0 || name.equals(ION))
{
return null;
}
if (version < 1)
{
version = 1;
}
SymbolTable itab = null;
if (catalog != null)
{
itab = catalog.getTable(name, version);
}
if (maxid < 0)
{
if (itab == null || version != itab.getVersion())
{
String message =
"Import of shared table "
+ IonTextUtils.printString(name)
+ " lacks a valid max_id field, but an exact match was not"
+ " found in the catalog";
if (itab != null)
{
message += " (found version " + itab.getVersion() + ")";
}
// TODO custom exception
throw new IonException(message);
}
// Exact match is found, but max_id is undefined in import
// declaration, set max_id to largest sid of shared symtab
maxid = itab.getMaxId();
}
if (itab == null)
{
assert maxid >= 0;
// Construct substitute table with max_id undefined symbols
itab = new SubstituteSymbolTable(name, version, maxid);
}
else if (itab.getVersion() != version || itab.getMaxId() != maxid)
{
// A match was found BUT specs are not an exact match
// Construct a substitute with correct specs, containing the
// original import table that was found
itab = new SubstituteSymbolTable(itab, version, maxid);
}
return itab;
}