final Sofa sofa = cds.getSofa(viewNbr); if (sofa == null && fssInView.size() == 0) { continue; // skip non-existent initial view with no sofa and no elements cds.encodeFS(fs); cds.encodeQueued(); if (startedReferencedFSs) {
nsUri = cds.getUniqueString(new String(sb)); shortName = cds.getUniqueString(shortName); String prefix = cds.getNameSpacePrefix(uimaTypeName, nsUri, lastDotIndex); return new XmlElementName(nsUri, shortName, cds.getUniqueString(prefix + ':' + shortName));
jg.writeFieldName(cds.getXmiId(fs));
String xmiId = cds.getXmiId(heapValue); if (cds.isFiltering) { // return as null any references to types not in target TS String typeName = cds.tsi.ll_getTypeForCode(cds.cas.getHeapValue(addr)).getName();
final int featAddr = addr + cds.cas.getFeatureOffset(featCode); final int featValRaw = cds.cas.getHeapValue(featAddr); final int featureValueClass = cds.classifyType(cds.tsi.range(featCode)); case LowLevelCAS.TYPE_CLASS_DOUBLEARRAY: case LowLevelCAS.TYPE_CLASS_FSARRAY: if (cds.isStaticMultiRef(featCode)) { attrValue = cds.getXmiId(featValRaw); } else { attrValue = arrayToString(featValRaw, featureValueClass); if (cds.isStaticMultiRef(featCode)) { attrValue = cds.getXmiId(featValRaw); } else if (featValRaw != CASImpl.NULL && cds.cas.ll_getArraySize(featValRaw) == 0) { attrValue = ""; //https://issues.apache.org/jira/browse/UIMA-5558 case CasSerializerSupport.TYPE_CLASS_FLOATLIST: case CasSerializerSupport.TYPE_CLASS_FSLIST: if (insideListNode || cds.isStaticMultiRef(featCode)) { attrValue = cds.getXmiId(featValRaw); } else { attrValue = listToString(featValRaw); if (insideListNode || cds.isStaticMultiRef(featCode)) { attrValue = cds.getXmiId(featValRaw); } else { attrValue = cds.getXmiId(featValRaw);
boolean multiRefAllowed = isStaticMultiRef(featCode) || isListNode; if (!multiRefAllowed) { if ((isListFeat && isListElementsMultiplyReferenced(featVal, featCode)) || (!isListFeat && alreadyVisited)) { reportMultiRefWarning(featCode); } else {
ser.cds.serialize(); } catch (Exception e) { if (e instanceof SAXException) {
workAttrs.clear(); String sofaXmiId = cds.getXmiId(sofaAddr); if (sofaXmiId != null && sofaXmiId.length() > 0) { addAttribute(workAttrs, "sofa", sofaXmiId);
/** * Converts a UIMA-style dotted type name to the element name that should be used in the * serialization. The XMI element name consists of three parts - the Namespace URI, the Local * Name, and the QName (qualified name). * * @param uimaTypeName * a UIMA-style dotted type name * @return a data structure holding the three components of the XML element name */ @Override protected XmlElementName uimaTypeName2XmiElementName(String uimaTypeName) { // split uima type name into namespace and short name String shortName; final int lastDotIndex = uimaTypeName.lastIndexOf('.'); if (lastDotIndex == -1) { // no namespace shortName = uimaTypeName; } else { shortName = uimaTypeName.substring(lastDotIndex + 1); } // convert short name to shared string, without interning, reduce GCs shortName = cds.getUniqueString(shortName); return new XmlElementName(uimaTypeName, shortName, shortName); // use short name for qname until namespaces needed }
private boolean writeViewMembers(StringBuilder sb, int[] members) throws SAXException { boolean isPastFirstElement = false; int nextBreak = (((sb.length() - 1) / CasSerializerSupport.PP_LINE_LENGTH) + 1) * CasSerializerSupport.PP_LINE_LENGTH; for (int member : members) { int xmiId = cds.getXmiIdAsInt(member); if (xmiId != 0) { // to catch filtered FS if (isPastFirstElement) { sb.append(' '); } else { isPastFirstElement = true; } sb.append(xmiId); if (cds.isFormattedOutput && (sb.length() > nextBreak)) { sb.append(SYSTEM_LINE_FEED); nextBreak += CasSerializerSupport.PP_LINE_LENGTH; } } } return isPastFirstElement; }
/** * for arrays and lists, * recursively write one FS, * as actual FS, * if dynamic embedding and single ref * OR, just write the reference id * If trying to write the null FS (due to filtering for instance), write 0 * @param addr * @throws IOException */ private void writeFsOrRef(TOP fs) throws IOException { if (fs == null || !cds.isDynamicMultiRef || cds.multiRefFSs.contains(fs)) { jg.writeNumber(cds.getXmiIdAsInt(fs)); } else { isEmbeddedFromFsFeature = false; writeEmbeddedFs(fs); } }
public void encodeQueued() throws Exception { int[] queueArray = queue.toArray(); for (int addr : queueArray) { // for some serializers, things could be enqueued multiple times in the ref queue // so check if already written, and if so, skip // Case where this happens: JSON serialization with dynamically determined single ref embedding // - have to enqueue to check if multiple refs, even if embedding eventually if (visited_not_yet_written.contains(addr)) { // skip if JSON dynamically computing whether or not to embed things and there's only one item - it will be embedded instead if (isDynamicMultiRef && !multiRefFSs.contains(addr)) { continue; // skip writing embeddable item (for JSON dynamic embedding) from Q; will be written from reference } encodeFS(addr); } } }
private void writeFsOrRef(TOP fs, FeatureImpl fi) throws IOException { if (fs == null || !cds.isDynamicMultiRef || cds.multiRefFSs.contains(fs)) { jg.writeFieldName(getShortFeatureName(fi)); jg.writeNumber(cds.getXmiIdAsInt(fs)); } else { jch.writeNlJustBeforeNext(); jg.writeFieldName(getShortFeatureName(fi)); isEmbeddedFromFsFeature = true; // Use cases: can write embed, which has embed, which has non-embed // once hit non-embed, this flag would be turned off, // But it's only tested at the beginning of writeEmbeddedFs, so subsequent fields reset this // This flag only used to control new lines for embedded case writeEmbeddedFs(fs); isEmbeddedFromFsFeature = false; // restore default } }
private void writeViewMembers(Collection<TOP> members) throws IOException { int nextBreak = CasSerializerSupport.PP_ELEMENTS; int i = 0; for (TOP member : members) { int xmiId = cds.getXmiIdAsInt(member); if (xmiId == 0) { continue; } if (i++ > nextBreak) { jch.writeNlJustBeforeNext(); nextBreak += CasSerializerSupport.PP_ELEMENTS; } jg.writeNumber(xmiId); } }
/** * Called to generate a new namespace prefix and add it to this element - due to a collision * @param xmlElementName */ @Override protected void addNameSpace(XmlElementName xmlElementName) { if (xmlElementName.qName.equals(xmlElementName.localName)) { // may have already had namespace added // split uima type name into namespace and short name String uimaTypeName = xmlElementName.nsUri; String shortName = xmlElementName.localName; final int lastDotIndex = uimaTypeName.lastIndexOf('.'); // determine what namespace prefix to use String prefix = cds.getNameSpacePrefix(uimaTypeName, uimaTypeName, lastDotIndex); xmlElementName.qName = cds.getUniqueString(prefix + ':' + shortName); } }
@Override protected void writeView(int sofaAddr, int[] added, int[] deleted, int[] reindexed) throws SAXException { String sofaXmiId = cds.getXmiId(sofaAddr); workAttrs.clear(); if (sofaXmiId != null && sofaXmiId.length() > 0) { addAttribute(workAttrs, "sofa", sofaXmiId); } writeViewForDeltas("added_members", added); writeViewForDeltas("deleted_members", deleted); writeViewForDeltas("reindexed_members", reindexed); XmlElementName elemName = uimaTypeName2XmiElementName("uima.cas.View"); startElement(elemName, workAttrs, 0); endElement(elemName); }
@Override protected void writeFeatureStructures(int iElementCount) throws Exception { workAttrs.clear(); computeNamespaceDeclarationAttrs(workAttrs); workAttrs.addAttribute(XMI_NS_URI, XMI_VERSION_LOCAL_NAME, XMI_VERSION_QNAME, "CDATA", XMI_VERSION_VALUE); startElement(XMI_TAG, workAttrs, iElementCount); writeNullObject(); // encodes 1 element cds.encodeIndexed(); // encodes indexedFSs.size() element cds.encodeQueued(); // encodes queue.size() elements if (!cds.isDelta) { // if delta, the out-of-type-system elements, are guaranteed not to be modified serializeOutOfTypeSystemElements(); //encodes sharedData.getOutOfTypeSystemElements().size() elements } }
@Override protected void writeView(Sofa sofa, Collection<TOP> members) throws IOException { jch.writeNlJustBeforeNext(); String sofaXmiId = (null == sofa) ? "0" : cds.getXmiId(sofa); jg.writeArrayFieldStart(sofaXmiId); writeViewMembers(members); //check for out-of-typesystem members if (cds.sharedData != null) { List<String> ootsMembers = cds.sharedData.getOutOfTypeSystemViewMembers(sofaXmiId); jch.writeNlJustBeforeNext(); writeViewMembers(ootsMembers); } jg.writeEndArray(); }
private XmiDocSerializer(ContentHandler ch, CASImpl cas, XmiSerializationSharedData sharedData, MarkerImpl marker) { cds = css.new CasDocSerializer(ch, cas, sharedData, marker, this); this.ch = ch; }
@Override protected void writeFsRef(TOP fs) throws Exception { jg.writeNumber(cds.getXmiIdAsInt(fs)); }