public void testOutOfTypeSystemListElement() throws Exception {
//add to type system an annotation type that has an FSList feature
TypeDescription testAnnotTypeDesc = typeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList");
//populate a CAS with such an list
CAS cas = CasCreationUtils.createCas(typeSystem, null, null);
Type testAnnotType = cas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
Type orgType = cas.getTypeSystem().getType(
"org.apache.uima.testTypeSystem.Organization");
AnnotationFS orgAnnot1 = cas.createAnnotation(orgType, 0, 10);
cas.addFsToIndexes(orgAnnot1);
AnnotationFS orgAnnot2 = cas.createAnnotation(orgType, 10, 20);
cas.addFsToIndexes(orgAnnot2);
AnnotationFS testAnnot = cas.createAnnotation(testAnnotType, 0, 20);
cas.addFsToIndexes(testAnnot);
Type nonEmptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
Type emptyFsListType = cas.getTypeSystem().getType(CAS.TYPE_NAME_EMPTY_FS_LIST);
Feature headFeat = nonEmptyFsListType.getFeatureByBaseName("head");
Feature tailFeat = nonEmptyFsListType.getFeatureByBaseName("tail");
FeatureStructure emptyNode = cas.createFS(emptyFsListType);
FeatureStructure secondNode = cas.createFS(nonEmptyFsListType);
secondNode.setFeatureValue(headFeat, orgAnnot2);
secondNode.setFeatureValue(tailFeat, emptyNode);
FeatureStructure firstNode = cas.createFS(nonEmptyFsListType);
firstNode.setFeatureValue(headFeat, orgAnnot1);
firstNode.setFeatureValue(tailFeat, secondNode);
Feature listFeat = testAnnotType.getFeatureByBaseName("listFeat");
testAnnot.setFeatureValue(listFeat, firstNode);
//serialize to XMI
String xmiStr = serialize(cas, null);
System.out.println(xmiStr);
//deserialize into a CAS that's missing the Organization type
File partialTypeSystemFile = JUnitExtension.getFile("ExampleCas/partialTestTypeSystem.xml");
TypeSystemDescription partialTypeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription(
new XMLInputSource(partialTypeSystemFile));
testAnnotTypeDesc = partialTypeSystem.addType("org.apache.uima.testTypeSystem.TestAnnotation", "", "uima.tcas.Annotation");
testAnnotTypeDesc.addFeature("listFeat", "", "uima.cas.FSList");
CAS partialTsCas = CasCreationUtils.createCas(partialTypeSystem, null, null);
XmiSerializationSharedData sharedData = new XmiSerializationSharedData();
deserialize(xmiStr, partialTsCas, sharedData, true, -1);
//check out of type system data
Type testAnnotType2 = partialTsCas.getTypeSystem().getType("org.apache.uima.testTypeSystem.TestAnnotation");
FeatureStructure testAnnot2 = partialTsCas.getAnnotationIndex(testAnnotType2).iterator().get();
Feature listFeat2 = testAnnotType2.getFeatureByBaseName("listFeat");
FeatureStructure listFs = testAnnot2.getFeatureValue(listFeat2);
List ootsElems = sharedData.getOutOfTypeSystemElements();
assertEquals(2, ootsElems.size());
OotsElementData oed = sharedData.getOutOfTypeSystemFeatures(listFs.hashCode());
XmlAttribute attr = (XmlAttribute)oed.attributes.get(0);
assertNotNull(attr);
assertEquals(CAS.FEATURE_BASE_NAME_HEAD, attr.name);
assertEquals(attr.value, ((OotsElementData)ootsElems.get(0)).xmiId);
//reserialize along with out of type system data
String xmiStr2 = serialize(partialTsCas, sharedData);
System.out.println(xmiStr2);
//deserialize into a new CAS and compare
CAS cas2 = CasCreationUtils.createCas(typeSystem, null, null);
deserialize(xmiStr2, cas2, null, false, -1);
CasComparer.assertEquals(cas, cas2);
}