AcknowledgementData.Builder ackDataBuilder = AcknowledgementData.getBuilder();
AckRequestedElement ackRequestedElement = readHeaderAsUnderstood(rmVersion.protocolVersion.protocolNamespaceUri, "AckRequested", jaxwsMessage);
if (ackRequestedElement != null) {
ackDataBuilder.ackReqestedSequenceId(ackRequestedElement.getId());
}
SequenceAcknowledgementElement ackElement = readHeaderAsUnderstood(rmVersion.protocolVersion.protocolNamespaceUri, "SequenceAcknowledgement", jaxwsMessage);
if (ackElement != null) {
List<Sequence.AckRange> ranges = new LinkedList<Sequence.AckRange>();
if (!ackElement.getNack().isEmpty()) {
List<BigInteger> nacks = new ArrayList<BigInteger>(ackElement.getNack());
Collections.sort(nacks);
long lastLowerBound = 1;
for (BigInteger nackId : nacks) {
if (lastLowerBound == nackId.longValue()) {
lastLowerBound++;
} else {
ranges.add(new Sequence.AckRange(lastLowerBound, nackId.longValue() - 1));
lastLowerBound = nackId.longValue() + 1;
}
}
long lastMessageId = rc.sequenceManager().getSequence(ackElement.getId()).getLastMessageNumber();
if (lastLowerBound <= lastMessageId) {
ranges.add(new Sequence.AckRange(lastLowerBound, lastMessageId));
}
} else if (ackElement.getAcknowledgementRange() != null && !ackElement.getAcknowledgementRange().isEmpty()) {
for (SequenceAcknowledgementElement.AcknowledgementRange rangeElement : ackElement.getAcknowledgementRange()) {
ranges.add(new Sequence.AckRange(rangeElement.getLower().longValue(), rangeElement.getUpper().longValue()));
}
}
// TODO handle final and remaining buffer in the header
// ackElement.getBufferRemaining();
ackDataBuilder.acknowledgements(ackElement.getId(), ranges, false);
}
return ackDataBuilder.build();
}