in uimaj-core/src/main/java/org/apache/uima/cas/impl/XmiCasSerializer.java [960:1109]
private List<XmlElementNameAndContents> encodeFeatures(TOP fs, AttributesImpl attrs,
boolean insideListNode) throws SAXException {
List<XmlElementNameAndContents> childElements = new ArrayList<>();
// int heapValue = cds.cas.getHeapValue(addr);
// int[] feats = cds.tsi.ll_getAppropriateFeatures(heapValue);
String attrValue;
// boolean isSofa = false;
// if (sofaTypeCode == heapValue)
// {
// // set isSofa flag to apply SofaID mapping and to store sofaNum->xmi:id mapping
// isSofa = true;
// }
for (final FeatureImpl fi : fs._getTypeImpl().getFeatureImpls()) {
if (cds.isFiltering) {
// skip features that aren't in the target type system
String fullFeatName = fi.getName();
if (cds.filterTypeSystem_inner.getFeatureByFullName(fullFeatName) == null) {
continue;
}
}
final String featName = fi.getShortName();
final int featureValueClass = fi.rangeTypeClass;
switch (featureValueClass) {
case LowLevelCAS.TYPE_CLASS_BYTE:
case LowLevelCAS.TYPE_CLASS_SHORT:
case LowLevelCAS.TYPE_CLASS_INT:
case LowLevelCAS.TYPE_CLASS_LONG:
case LowLevelCAS.TYPE_CLASS_FLOAT:
case LowLevelCAS.TYPE_CLASS_DOUBLE:
case LowLevelCAS.TYPE_CLASS_BOOLEAN:
attrValue = fs.getFeatureValueAsString(fi);
break;
case LowLevelCAS.TYPE_CLASS_STRING:
attrValue = fs.getFeatureValueAsString(fi);
break;
// Arrays
case LowLevelCAS.TYPE_CLASS_INTARRAY:
case LowLevelCAS.TYPE_CLASS_FLOATARRAY:
case LowLevelCAS.TYPE_CLASS_BOOLEANARRAY:
case LowLevelCAS.TYPE_CLASS_BYTEARRAY:
case LowLevelCAS.TYPE_CLASS_SHORTARRAY:
case LowLevelCAS.TYPE_CLASS_LONGARRAY:
case LowLevelCAS.TYPE_CLASS_DOUBLEARRAY:
case LowLevelCAS.TYPE_CLASS_FSARRAY:
if (cds.isStaticMultiRef(fi)) {
attrValue = cds.getXmiId(fs.getFeatureValue(fi));
} else {
attrValue = arrayToString(fs.getFeatureValue(fi), featureValueClass);
}
break;
// special case for StringArrays, which stored values as child elements rather
// than attributes.
case LowLevelCAS.TYPE_CLASS_STRINGARRAY:
StringArray stringArray = (StringArray) fs.getFeatureValue(fi);
if (cds.isStaticMultiRef(fi)) {
attrValue = cds.getXmiId(stringArray);
} else if (stringArray != null && stringArray.size() == 0) {
attrValue = ""; // https://issues.apache.org/jira/browse/UIMA-5558
} else {
stringArrayToElementList(featName, (StringArray) fs.getFeatureValue(fi),
childElements);
attrValue = null;
}
break;
// Lists
case CasSerializerSupport.TYPE_CLASS_INTLIST:
case CasSerializerSupport.TYPE_CLASS_FLOATLIST:
case CasSerializerSupport.TYPE_CLASS_FSLIST:
TOP startNode = fs.getFeatureValue(fi);
if (insideListNode || cds.isStaticMultiRef(fi)) {
// If the feature has multipleReferencesAllowed = true OR if we're already
// inside another list node (i.e. this is the "tail" feature), serialize as a normal
// FS.
// Otherwise, serialize as a multi-valued property.
// if (cds.isStaticMultRef(feats[i]) ||
// cds.embeddingNotAllowed.contains(featVal) ||
// insideListNode) {
attrValue = cds.getXmiId(startNode);
} else {
attrValue = listToString((CommonList) fs.getFeatureValue(fi));
}
break;
// special case for StringLists, which stored values as child elements rather
// than attributes.
case CasSerializerSupport.TYPE_CLASS_STRINGLIST:
if (insideListNode || cds.isStaticMultiRef(fi)) {
attrValue = cds.getXmiId(fs.getFeatureValue(fi));
} else {
// it is not safe to use a space-separated attribute, which would
// break for strings containing spaces. So use child elements instead.
StringList stringList = (StringList) fs.getFeatureValue(fi);
if (stringList == null) {
attrValue = null;
} else {
if (stringList instanceof EmptyStringList) {
attrValue = "";
} else {
List<String> listOfStrings = stringList.anyListToStringList(null, cds);
// if (array.length > 0 && !arrayAndListFSs.put(featVal, featVal)) {
// reportWarning("Warning: multiple references to a ListFS. Reference identity
// will not be preserved.");
// }
for (String string : listOfStrings) {
childElements.add(new XmlElementNameAndContents(
new XmlElementName("", featName, featName), string));
}
attrValue = null;
}
}
}
break;
default: // Anything that's not a primitive type, array, or list.
attrValue = cds.getXmiId(fs.getFeatureValue(fi));
break;
} // end of switch
if (attrValue != null && featName != null) {
addAttribute(attrs, featName, attrValue, "");
}
} // end of for loop over all features
// add out-of-typesystem features, if any
if (cds.sharedData != null) {
OotsElementData oed = cds.sharedData.getOutOfTypeSystemFeatures(fs);
if (oed != null) {
// attributes
Iterator<XmlAttribute> attrIter = oed.attributes.iterator();
while (attrIter.hasNext()) {
XmlAttribute attr = attrIter.next();
addAttribute(workAttrs, attr.name, attr.value);
}
// child elements
childElements.addAll(oed.childElements);
}
}
return childElements;
}