Repository navigation
ISOMsg: strict path readers, dataset element writers, dataset-aware clone - #792
Merged
Merged
Conversation
…lone Add findValue(String) and findDatasetElements(String). Both validate the whole path before reading (decimal or 0x-prefixed hex segments in 0..Integer.MAX_VALUE; anything else throws IllegalArgumentException), return empty for absent or broken hierarchies, and descend into dataset fields: 55.0x9F26 (no envelope) and 104.0x71.0x01 (envelope). The field packager's hasDatasetEnvelope() decides the layout when available; otherwise it is inferred from the remaining segment count. findDatasetElements collects every occurrence across all datasets with the addressed identifier; findValue returns the first. Add setDatasetElement/withDatasetElement/unsetDatasetElement, which take the dataset coordinates as ints and build dataset fields without a packager. setDatasetPath/unsetDatasetPath share the same helpers. clone(String...) now copies dataset element paths, keeping dataset identifiers, formats and constructed flags. Behavior changes: - With a dataset field packager, set/unset with a dataset path whose segment count does not match the envelope now throw. Previously set silently replaced the dataset field with a plain sub-message. - Datasets created for envelope-less fields are always TLV; fields numbered above 0x70 used to get DBM. - TLV elements written by path record the constructed flag. - Dataset paths remove an element from every dataset carrying the identifier, not only the first. - clone(String...) throws IllegalArgumentException for malformed paths. Refs #790
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second PR for #790, following the implementation plan. PR #791 was the first. Closes #790.
New API (
ISOMsg)Optional<Object> findValue(String fpath) throws ISOExceptionList<DatasetElement> findDatasetElements(String fpath) throws ISOExceptionsetDatasetElement(fpath, elementId, value)/setDatasetElement(fpath, datasetId, elementId, value), pluswithDatasetElementandunsetDatasetElementcounterpartsDatasetElement.isConstructedTag(int), replacing private copies inDatasetPackagerandXMLPackager(separate commit)Behavior
Path grammar (new methods and
clone(String...)only; the existingset/unset/hasField/getValue/getString/getComponent(String)stay lenient): segments are[0-9]+or0x[0-9a-fA-F]+, in the range0..Integer.MAX_VALUE. Empty segments, signs, whitespace,0Xand out-of-range values throwIllegalArgumentExceptionnaming the path and the bad segment, whatever the message contains.Readers
ISOMsg. An absent field, or a path through a leaf, returns empty.DatasetFieldPackager,hasDatasetEnvelope()decides the layout, and a mismatched path returns empty. Otherwise the layout is inferred from the remaining segments (1 = no envelope, 2 = envelope, more = empty). Nested dataset fields use the sub-message's packager.findDatasetElementscollects matches from every dataset with the addressed id.findValuereturns the first, sofindValue(p).isPresent()⇔!findDatasetElements(p).isEmpty().byte[]; the Javadoc points toTLVListfor decoding children.Writers
setDatasetElementneeds no packager and creates intermediate composites. Ints carry the dataset coordinates, because a single string path is ambiguous when there's nothing to walk yet.0x70, DBM above. Elements are replaced (putElement). TLV elements record the constructed flag. Anullvalue removes the element.ISOException. The value type is checked before anything is created.clone(String...): copies every occurrence of a dataset element path, deep-copied, keeping dataset id, format andconstructed. Elements appear in path order. Overlapping paths replace rather than duplicate. Same-id datasets stay apart, matched by position.Behavior changes (for the ChangeLog)
setDatasetPathreturnfalse. The plain path code then replaced the field: onmain,set("104.0xDF02", …)afterset("104.0x01.0xDF01", …)withcmfv3.xmlturns DE 104 into anISOMsg, andpack()fails witherror packing field 104(reproduced locally).set/unsetnow throw (IllegalArgumentException, orISOExceptionfromset(String, ISOComponent)).0x70got DBM datasets fromset(...); they now get TLV.constructed. This is metadata only; TLV packing doesn't use it.clone(String...)throwsIllegalArgumentExceptionfor malformed paths instead of an incidentalNumberFormatException/NoSuchElementException.Testing
ISOMsgPathTest(49 tests): the grammar cases, strict walk, dataset descent with and without a packager (cmfv3.xml), mismatched layouts, nested127.55.xwith and without a sub-message packager,XMLPackagerround-trip,set()without a packager producing a plain composite, repeated tags (issuer scripts decoded withTLVList) and repeated datasets, the writers including pack/unpack withcmfv3.xml, the mismatch regression, the TLV format fix, andclonewith dataset paths.ISOMsgTest.testCloneFPathBrokenHierarchy(from ISOMsg: return null from getComponent(String) on a broken hierarchy #791) no longer asserts thatclone("55.0x9F26")skips DE 55, since that path is now cloned. The leaf case is still covered.:jpostest suite: 4,766 tests, 0 failures, 0 errors, 69 skipped (local run, macOS).:jpos:javadocreports no warnings.