Search in sources :

Example 56 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class _Private_IonWriterBase method pop_passed_symbol_table.

public final SymbolTable pop_passed_symbol_table() {
    if (_symbol_table_top <= 0) {
        return null;
    }
    _symbol_table_top--;
    SymbolTable symbols = _symbol_table_stack[_symbol_table_top];
    _symbol_table_stack[_symbol_table_top] = null;
    return symbols;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Example 57 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class _Private_IonWriterFactory method makeSystemWriter.

/**
 * @param container must not be null.
 */
public static IonWriter makeSystemWriter(IonContainer container) {
    IonSystem sys = container.getSystem();
    IonCatalog cat = sys.getCatalog();
    SymbolTable defaultSystemSymtab = sys.getSystemSymbolTable();
    IonWriter writer = new IonWriterSystemTree(defaultSystemSymtab, cat, container, null);
    return writer;
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter)

Example 58 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class _Private_IonWriterFactory method makeWriter.

/**
 * @param container must not be null.
 */
public static IonWriter makeWriter(IonCatalog catalog, IonContainer container) {
    IonSystem sys = container.getSystem();
    SymbolTable defaultSystemSymtab = sys.getSystemSymbolTable();
    // TODO the SUPPRESS here is a nasty discontinuity with other places
    // that create this kind of reader.  It prevents the Lite DG system
    // iterator from returning two IVMs at the start of the data.
    // The Span tests detect that problem.
    IonWriterSystemTree system_writer = new IonWriterSystemTree(defaultSystemSymtab, catalog, container, InitialIvmHandling.SUPPRESS);
    return new IonWriterUser(catalog, sys, system_writer);
}
Also used : IonSystem(com.amazon.ion.IonSystem) SymbolTable(com.amazon.ion.SymbolTable)

Example 59 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class IonSymbolLite method getSymbolId.

private int getSymbolId(SymbolTableProvider symbolTableProvider) throws NullValueException {
    validateThisNotNull();
    if (_sid != UNKNOWN_SYMBOL_ID || isReadOnly()) {
        return _sid;
    }
    SymbolTable symtab = symbolTableProvider != null ? symbolTableProvider.getSymbolTable() : getSymbolTable();
    if (symtab == null) {
        symtab = getSystem().getSystemSymbolTable();
    }
    assert (symtab != null);
    String name = _get_value();
    // TODO [amzn/ion-java/issues/27] - needs consistent handling, when to retain SID's vs ignore (here memoizing SID on read)
    if (!symtab.isLocalTable()) {
        setSID(symtab.findSymbol(name));
        if (_sid > 0 || isReadOnly()) {
            return _sid;
        }
    }
    SymbolToken tok = symtab.find(name);
    if (tok != null) {
        setSID(tok.getSid());
        // Use the interned instance of the text
        _set_value(tok.getText());
    }
    return _sid;
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable)

Example 60 with SymbolTable

use of com.amazon.ion.SymbolTable in project ion-java by amzn.

the class _Private_Utils method localSymtabExtends.

/**
 * Determines, for two local symbol tables, whether the passed-in {@code superset} symtab is an extension
 * of {@code subset}.  This works independent of implementation details--particularly in cases
 * where {@link LocalSymbolTable#symtabExtends(SymbolTable)} cannot be used.
 *
 * @see #symtabExtends(SymbolTable, SymbolTable)
 */
private static boolean localSymtabExtends(SymbolTable superset, SymbolTable subset) {
    if (subset.getMaxId() > superset.getMaxId()) {
        // the subset has more symbols
        return false;
    }
    // NB this API almost certainly requires cloning--symbol table's API doesn't give us a way to polymorphically
    // get this without materializing an array
    final SymbolTable[] supersetImports = superset.getImportedTables();
    final SymbolTable[] subsetImports = subset.getImportedTables();
    // TODO this is over-strict, but not as strict as LocalSymbolTable.symtabExtends()
    if (supersetImports.length != subsetImports.length) {
        return false;
    }
    // NB we cannot trust Arrays.equals--we don't know how an implementation will implement it...
    for (int i = 0; i < supersetImports.length; i++) {
        final SymbolTable supersetImport = supersetImports[i];
        final SymbolTable subsetImport = subsetImports[i];
        if (!supersetImport.getName().equals(subsetImport.getName()) || supersetImport.getVersion() != subsetImport.getVersion()) {
            // bad match on import
            return false;
        }
    }
    // all the imports lined up, lets make sure the locals line up too
    final Iterator<String> supersetIter = superset.iterateDeclaredSymbolNames();
    final Iterator<String> subsetIter = subset.iterateDeclaredSymbolNames();
    while (subsetIter.hasNext()) {
        final String nextSubsetSymbol = subsetIter.next();
        final String nextSupersetSymbol = supersetIter.next();
        if (!nextSubsetSymbol.equals(nextSupersetSymbol)) {
            // local symbol mismatch
            return false;
        }
    }
    // we made it this far--superset is really a superset of subset
    return true;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Aggregations

SymbolTable (com.amazon.ion.SymbolTable)177 Test (org.junit.Test)105 IonValue (com.amazon.ion.IonValue)21 IonDatagram (com.amazon.ion.IonDatagram)18 com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable (com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable)17 SymbolToken (com.amazon.ion.SymbolToken)14 IonStruct (com.amazon.ion.IonStruct)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IonWriter (com.amazon.ion.IonWriter)12 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)12 IonReader (com.amazon.ion.IonReader)11 IonSystem (com.amazon.ion.IonSystem)10 IOException (java.io.IOException)9 IonType (com.amazon.ion.IonType)8 ArrayList (java.util.ArrayList)7 IonException (com.amazon.ion.IonException)6 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)6 IonCatalog (com.amazon.ion.IonCatalog)5 IonList (com.amazon.ion.IonList)5