use of com.amazon.ion.UnknownSymbolException in project ion-java by amzn.
the class SIDPresentLifecycleTest method testPropagationAcrossGraph.
@Test
public void testPropagationAcrossGraph() {
IonStructLite struct = (IonStructLite) system().newEmptyStruct();
assertFalse(struct._isSymbolIdPresent());
// 1. test addition of child by field WITHOUT SID causes no propagation
IonStringLite keyValue1 = (IonStringLite) system().newString("Foo");
struct.add(_Private_Utils.newSymbolToken("field_1", -1), keyValue1);
assertFalse(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
// 2. test addition of child by field WITH SID but also with field text causes no propagation
// (struct only takes field name if present and strips SID)
IonStringLite keyValue2 = (IonStringLite) system().newString("Bar");
struct.add(_Private_Utils.newSymbolToken("field_2", 87), keyValue2);
assertFalse(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
// 3. test addition of child by field with SID ONLY causes propagation due to retention of field SID
IonStringLite keyValue3 = (IonStringLite) system().newString("Car");
struct.add(_Private_Utils.newSymbolToken(76), keyValue3);
assertTrue(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
assertTrue(keyValue3._isSymbolIdPresent());
// 4. test explicitly annotating a field propagates
IonStructLite struct2 = (IonStructLite) system().newEmptyStruct();
IonStringLite keyValue4 = (IonStringLite) system().newString("But");
struct2.add("field_1", keyValue4);
keyValue4.setTypeAnnotationSymbols(_Private_Utils.newSymbolToken("Lah", 13));
assertTrue(struct2._isSymbolIdPresent());
// 5. test clone propagates clearing of status. NOTE - clone with an unresolvable SID for a field ID fails
try {
struct.clone();
fail("clone was expected NOT to succeed due to behavior at time of writing where unresolvable SID's fail");
} catch (UnknownSymbolException use) {
// this is expected??! until someone fixed the TO DO in IonValueLite#getFieldName
}
// remove the field without SID such that the clone can be enacted.
struct.remove_child(2);
IonStructLite clonedStruct = struct.clone();
assertFalse(clonedStruct._isSymbolIdPresent());
for (IonValue value : clonedStruct) {
assertFalse(((IonValueLite) value)._isSymbolIdPresent());
}
// 6. ensure clearing symbols propogates from root to impacted leaves
// add back in field ID (SID) only child before clearing to test SID retained
struct.add(_Private_Utils.newSymbolToken(76), keyValue3);
struct.clearSymbolIDValues();
assertTrue(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
assertTrue(keyValue3._isSymbolIdPresent());
// 7. ensure that nested SID-only annotation clone behavior propogates to cloned root.
IonStructLite outer = (IonStructLite) system().newEmptyStruct();
IonListLite middle = (IonListLite) system().newEmptyList();
IonIntLite inner = (IonIntLite) system().newInt(10);
middle.add(inner);
outer.put("foo", middle);
// now add a SID only annotation to inner
inner.setTypeAnnotationSymbols(_Private_Utils.newSymbolToken(99));
// verify that all components are signaling SID present
assertTrue(outer._isSymbolIdPresent());
assertTrue(middle._isSymbolIdPresent());
assertTrue(inner._isSymbolIdPresent());
// conduct a clone and verify all cloned components have retained SID
IonStructLite clonedOuter = outer.clone();
assertTrue(clonedOuter._isSymbolIdPresent());
IonListLite clonedMiddle = (IonListLite) outer.get("foo");
assertTrue(clonedMiddle._isSymbolIdPresent());
assertTrue(clonedMiddle.get_child(0)._isSymbolIdPresent());
}
use of com.amazon.ion.UnknownSymbolException in project ion-java by amzn.
the class IonStructLite method get.
public IonValue get(String fieldName) {
int field_idx = find_field_helper(fieldName);
IonValue field;
if (field_idx < 0) {
if (hasNullFieldName)
throw new UnknownSymbolException("Unable to determine whether the field exists because the struct contains field names with unknown text.");
field = null;
} else {
field = get_child(field_idx);
}
return field;
}
use of com.amazon.ion.UnknownSymbolException in project ion-java by amzn.
the class _Private_Utils method toStrings.
/**
* Extracts the non-null text from a list of symbol tokens.
*
* @return not null.
*
* @throws UnknownSymbolException if any token is missing text.
*/
public static String[] toStrings(SymbolToken[] symbols, int count) {
if (count == 0)
return _Private_Utils.EMPTY_STRING_ARRAY;
String[] annotations = new String[count];
for (int i = 0; i < count; i++) {
SymbolToken tok = symbols[i];
String text = tok.getText();
if (text == null) {
throw new UnknownSymbolException(tok.getSid());
}
annotations[i] = text;
}
return annotations;
}
use of com.amazon.ion.UnknownSymbolException in project ion-java by amzn.
the class IonReaderTextSystemX method getFieldName.
@Override
public final String getFieldName() {
// Superclass handles hoisting logic
String text = getRawFieldName();
if (text == null) {
int id = getFieldId();
if (id != SymbolTable.UNKNOWN_SYMBOL_ID) {
SymbolTable symbols = getSymbolTable();
text = symbols.findKnownSymbol(id);
if (text == null) {
throw new UnknownSymbolException(id);
}
}
}
return text;
}
use of com.amazon.ion.UnknownSymbolException in project ion-java by amzn.
the class IonReaderBinaryIncremental method getTypeAnnotations.
@Override
public String[] getTypeAnnotations() {
if (hasAnnotations) {
IntList annotationSids = getAnnotationSids();
String[] annotationArray = new String[annotationSids.size()];
for (int i = 0; i < annotationArray.length; i++) {
String symbol = getSymbol(annotationSids.get(i));
if (symbol == null) {
throw new UnknownSymbolException(annotationSids.get(i));
}
annotationArray[i] = symbol;
}
return annotationArray;
}
return _Private_Utils.EMPTY_STRING_ARRAY;
}
Aggregations